BEGIN { #{{{}}} # {{{ init filenames dotout=".origamimsg" hout="getmsg.h" rcout="rc_comp_str.h" # }}} # {{{ init awk constants FS="@" doublequote=sprintf("%c",34) # }}} # {{{ init message data MSG_LEN=80 msg_check=0 test_base=32 test_size=95 strs="" defines="" msgs="#ifdef MESSAGES_C" # }}} # {{{ init reference compression data reference_limiter=" " # }}} # {{{ print auto-gen-mark printf("%-"MSG_LEN"s|\n","ATTENTION:line must contain as many chars as this one (automatic generated file)") >dotout print("/* This file is generated automatically by awk -f msg2dot_h.awk */\n/* containing string definitions */") >hout print("/* generated automatically by msg2dot_h.awk, containing rc string compression data */\n") >rcout # }}} # {{{ print length data print("/*{{{ length data*/") >hout print("#ifdef GETMSG_C") >hout print("# ifdef CR_LF_MSG") >hout print("# define MSG_ADDITIONAL 3") >hout print("# else") >hout print("# define MSG_ADDITIONAL 2") >hout print("# endif") >hout print("#endif") >hout print("") >hout print("#define MSG_LENGTH "MSG_LEN) >hout print("/*}}}*/") >hout # }}} # {{{ print head of msgtype print("/*{{{ msgtyp*/") >hout print("typedef enum {") >hout print(" M_BASE_FORMAT=0,") >hout printf(" ATTENTION") >hout # }}} } #{{{ # -> comment /^#/ { next } #}}} #{{{ handle rc file compression word list #{{{ RC-COMPRESSION-DATA -> start data /^ *RC-COMPRESSION-DATA *$/ { rc_comp_data=1 next } #}}} #{{{ line with words rc_comp_data==1 && $0~/^ *[abcdefghijklmnopqrstuvwxyz]+( +[abcdefghijklmnopqrstuvwxy]+)* *$/ { for (w=$0" ";w!="";) { if (substr(w,1,1)==" ") { w=substr(w,2) } else { for (l=1;substr(w,l+1,1)!=" ";l++); rc_comp_words=rc_comp_words doublequote substr(w,1,l) doublequote "," w=substr(w,l+1) } } } rc_comp_data==1 { next } #}}} #}}} #{{{ starting with I, handle msg_check $1 ~ /^I_.*/ { msg_check+=1 } #}}} #{{{ starting with D, handle msg_check $1 ~ /^D_.*/ { msg_check+=2 } #}}} #{{{ starting with F, handle msg_check $1 ~ /^F_.*/ { msg_check+=3 } #}}} #{{{ not starting with #,STR,MSG,RC_COMP, so print it to dot and h as msg $1 !~ /^((#)|(RC_COMP)|((STR)|(MSG)_)).*/ && $2 !~ /^([^%]|(%[%cdosx]))*$/ { print("print format in message "$1" is not supported!") print($2) exit } $1 !~ /^((#)|(RC_COMP)|((STR)|(MSG)_)).*/ { if (length($2)>MSG_LEN) print("cutting msg "$1" '"$2"'") printf("%-"MSG_LEN"s|\n",substr($2,1,MSG_LEN)) >dotout name=$1 while ((name!="") && (substr(name,length(name),1)==" ")) name=substr(name,1,length(name)-1) printf(",\n "name) >hout msg_check++ } #}}} #{{{ starts with I,D, so first char needed for inputs $1 ~ /^[DI]_.*/ { defines=defines "\n#define MSG_" $1 " '" substr($2,1,1) "'" } #}}} #{{{ starts with MSG, so c-code constant, for messages.c only $1 ~ /^MSG_.*/ { msgs=msgs "\n# define " $1 " " doublequote $2 doublequote } #}}} #{{{ starts with STR, so general c-code constant $1 ~ /^STR_.*/ { strs=strs "\n#define " $1 " " doublequote $2 doublequote } #}}} END { # {{{ handle msg_check overflow { msg_check=msg_check%test_size } # }}} # {{{ print rest of msgtype # {{{ end of type definition print(",") >hout print(" T_TEST,") >hout print(" NUM_MESSAGES") >hout print("} msgtyp;") >hout print("") >hout print("#define MSG_ARG_FORMAT NUM_MESSAGES") >hout # }}} # {{{ test data printf("#define MSG_TEST_CHAR '%c'\n",(msg_check%test_size)+test_base) >hout printf("%c%-"MSG_LEN-1"s|\n",(msg_check%test_size)+test_base,"<- don't change this entry, it's used to test the msg-file!") >dotout # }}} print("/*}}}*/") >hout # }}} # {{{ end define lists defines=defines "\n" strs=strs "\n" msgs=msgs "\n#endif\n" # }}} # {{{ print define lists printf("/*{{{ inputs*/%s/*}}}*/\n",defines) >hout printf("/*{{{ strs*/%s/*}}}*/\n",strs) >hout printf("/*{{{ msg*/\n%s/*}}}*/\n",msgs) >hout # }}} # {{{ print rc compressions data # {{{ stuff, needed for the library print("#ifdef LIB_COMPILE") >rcout print("# define REF_INIT_WORD_LIST { "rc_comp_words"0 }") >rcout print("#endif") >rcout # }}} print("#define REF_LIM_TXT "doublequote reference_limiter doublequote) >rcout print("#define REF_LIM_QUOTED_TXT "doublequote"\\\\"reference_limiter doublequote) >rcout print("#define REF_LIM_CHAR '"reference_limiter"'") >rcout # }}} }