home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / h / msg2dot_h.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  4.4 KB  |  157 lines

  1. BEGIN {
  2.    #{{{}}}
  3. #   {{{  init filenames
  4.    dotout=".origamimsg"
  5.    hout="getmsg.h"
  6.    rcout="rc_comp_str.h"
  7. #   }}}
  8. #   {{{  init awk constants
  9.    FS="@"
  10.    doublequote=sprintf("%c",34)
  11. #   }}}
  12. #   {{{  init message data
  13.    MSG_LEN=80
  14.    msg_check=0
  15.    test_base=32
  16.    test_size=95
  17.    strs=""
  18.    defines=""
  19.    msgs="#ifdef MESSAGES_C"
  20. #   }}}
  21. #   {{{  init reference compression data
  22.    reference_limiter=" "
  23. #   }}}
  24. #   {{{  print auto-gen-mark
  25.    printf("%-"MSG_LEN"s|\n","ATTENTION:line must contain as many chars as this one (automatic generated file)") >dotout
  26.    print("/* This file is generated automatically by awk -f msg2dot_h.awk */\n/* containing string definitions */") >hout
  27.    print("/* generated automatically by msg2dot_h.awk, containing rc string compression data */\n") >rcout
  28. #   }}}
  29. #   {{{  print length data
  30.    print("/*{{{  length data*/") >hout
  31.    print("#ifdef GETMSG_C") >hout
  32.    print("#  ifdef CR_LF_MSG") >hout
  33.    print("#    define MSG_ADDITIONAL 3") >hout
  34.    print("#  else") >hout
  35.    print("#    define MSG_ADDITIONAL 2") >hout
  36.    print("#  endif") >hout
  37.    print("#endif") >hout
  38.    print("") >hout
  39.    print("#define MSG_LENGTH "MSG_LEN) >hout
  40.    print("/*}}}*/") >hout
  41. #   }}}
  42. #   {{{  print head of msgtype
  43.    print("/*{{{  msgtyp*/") >hout
  44.    print("typedef enum {") >hout
  45.    print("  M_BASE_FORMAT=0,") >hout
  46.    printf("  ATTENTION") >hout
  47. #   }}}
  48. }
  49. #{{{  # -> comment
  50. /^#/ { next }
  51. #}}}
  52. #{{{  handle rc file compression word list
  53. #{{{  RC-COMPRESSION-DATA -> start data
  54. /^ *RC-COMPRESSION-DATA *$/ {
  55.    rc_comp_data=1
  56.    next
  57. }
  58. #}}}
  59. #{{{  line with words
  60. rc_comp_data==1 && $0~/^ *[abcdefghijklmnopqrstuvwxyz]+( +[abcdefghijklmnopqrstuvwxy]+)* *$/ {
  61.    for (w=$0" ";w!="";) {
  62.       if (substr(w,1,1)==" ") {
  63.          w=substr(w,2)
  64.       } else {
  65.          for (l=1;substr(w,l+1,1)!=" ";l++);
  66.          rc_comp_words=rc_comp_words doublequote substr(w,1,l) doublequote ","
  67.          w=substr(w,l+1)
  68.       }
  69.    }
  70. }
  71. rc_comp_data==1 {
  72.    next
  73. }
  74. #}}}
  75. #}}}
  76. #{{{  starting with I, handle msg_check
  77. $1 ~ /^I_.*/ { msg_check+=1 }
  78. #}}}
  79. #{{{  starting with D, handle msg_check
  80. $1 ~ /^D_.*/ { msg_check+=2 }
  81. #}}}
  82. #{{{  starting with F, handle msg_check
  83. $1 ~ /^F_.*/ { msg_check+=3 }
  84. #}}}
  85. #{{{  not starting with #,STR,MSG,RC_COMP, so print it to dot and h as msg
  86. $1 !~ /^((#)|(RC_COMP)|((STR)|(MSG)_)).*/ && $2 !~ /^([^%]|(%[%cdosx]))*$/ {
  87.    print("print format in message "$1" is not supported!")
  88.    print($2)
  89.    exit
  90. }
  91. $1 !~ /^((#)|(RC_COMP)|((STR)|(MSG)_)).*/ {
  92.    if (length($2)>MSG_LEN)
  93.       print("cutting msg "$1" '"$2"'")
  94.    printf("%-"MSG_LEN"s|\n",substr($2,1,MSG_LEN)) >dotout
  95.    name=$1
  96.    while ((name!="") && (substr(name,length(name),1)==" "))
  97.       name=substr(name,1,length(name)-1)
  98.    printf(",\n  "name) >hout
  99.    msg_check++
  100. }
  101. #}}}
  102. #{{{  starts with I,D, so first char needed for inputs
  103. $1 ~ /^[DI]_.*/ {
  104.    defines=defines "\n#define MSG_" $1 " '" substr($2,1,1) "'"
  105. }
  106. #}}}
  107. #{{{  starts with MSG, so c-code constant, for messages.c only
  108. $1 ~ /^MSG_.*/  {
  109.    msgs=msgs "\n#  define " $1 " " doublequote $2 doublequote
  110. }
  111. #}}}
  112. #{{{  starts with STR, so general c-code constant
  113. $1 ~ /^STR_.*/  {
  114.    strs=strs "\n#define " $1 " " doublequote $2 doublequote
  115. }
  116. #}}}
  117. END {
  118. #  {{{  handle msg_check overflow
  119.   { msg_check=msg_check%test_size }
  120. #  }}}
  121. #  {{{  print rest of msgtype
  122. #  {{{  end of type definition
  123.   print(",") >hout
  124.   print("  T_TEST,") >hout
  125.   print("  NUM_MESSAGES") >hout
  126.   print("} msgtyp;") >hout
  127.   print("") >hout
  128.   print("#define MSG_ARG_FORMAT NUM_MESSAGES") >hout
  129. #  }}}
  130. #  {{{  test data
  131.   printf("#define MSG_TEST_CHAR '%c'\n",(msg_check%test_size)+test_base) >hout
  132.   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
  133. #  }}}
  134.   print("/*}}}*/") >hout
  135. #  }}}
  136. #  {{{  end define lists
  137.   defines=defines "\n"
  138.   strs=strs "\n"
  139.   msgs=msgs "\n#endif\n"
  140. #  }}}
  141. #  {{{  print define lists
  142.   printf("/*{{{  inputs*/%s/*}}}*/\n",defines) >hout
  143.   printf("/*{{{  strs*/%s/*}}}*/\n",strs) >hout
  144.   printf("/*{{{  msg*/\n%s/*}}}*/\n",msgs) >hout
  145. #  }}}
  146. #  {{{  print rc compressions data
  147. #  {{{  stuff, needed for the library
  148.   print("#ifdef LIB_COMPILE") >rcout
  149.   print("#  define REF_INIT_WORD_LIST { "rc_comp_words"0 }") >rcout
  150.   print("#endif") >rcout
  151. #  }}}
  152.   print("#define REF_LIM_TXT "doublequote reference_limiter doublequote) >rcout
  153.   print("#define REF_LIM_QUOTED_TXT "doublequote"\\\\"reference_limiter doublequote) >rcout
  154.   print("#define REF_LIM_CHAR '"reference_limiter"'") >rcout
  155. #  }}}
  156. }
  157.