home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / tools / translat.awk < prev   
Text File  |  1994-10-28  |  8KB  |  233 lines

  1.  
  2.  
  3.  
  4. #/*
  5. # *
  6. # *          Copyright (C) 1994, M. A. Sridhar
  7. # *  
  8. # *
  9. # *     This software is Copyright M. A. Sridhar, 1994. You are free
  10. # *     to copy, modify or distribute this software  as you see fit,
  11. # *     and to use  it  for  any  purpose, provided   this copyright
  12. # *     notice and the following   disclaimer are included  with all
  13. # *     copies.
  14. # *
  15. # *                        DISCLAIMER
  16. # *
  17. # *     The author makes no warranties, either expressed or implied,
  18. # *     with respect  to  this  software, its  quality, performance,
  19. # *     merchantability, or fitness for any particular purpose. This
  20. # *     software is distributed  AS IS.  The  user of this  software
  21. # *     assumes all risks  as to its quality  and performance. In no
  22. # *     event shall the author be liable for any direct, indirect or
  23. # *     consequential damages, even if the  author has been  advised
  24. # *     as to the possibility of such damages.
  25. # *
  26. # */
  27.  
  28.  
  29.  
  30.  
  31. #
  32. # An awk script for reading a .RC file (output from a resource editor)
  33. # and creating a C file containing a series of initializations of
  34. # an array of UI_ViewDescriptor structures. 
  35. #
  36. # Invoke with:
  37. #
  38. #        awk -f winbuild.awk incl=includefilename rcfilename
  39. #
  40. # where includefilename is the name of the file containing symbol
  41. # definitions for the RC file, without surrounding quotes.
  42. #
  43. # When translating button groups, this script assumes that:
  44. #    * The GROUPBOX is specified first, with attribute WS_GROUP but
  45. #      not WS_TABSTOP
  46. #    * All the buttons in the group follow, with the first button in
  47. #      the group having a WS_TABSTOP attribute set. No other buttons in
  48. #      the group must have WS_TABSTOP set.
  49. # This arrangement ensures proper tabbing behavior of the dialog.
  50. #    Also, the input RC file must have CONTROL statements for all
  51. # controls (set this option in the Resource Editor's Options menu).
  52. #
  53.  
  54. BEGIN {
  55.     n = split(ARGV[1], a, "=")
  56.     HeaderFile = a[2]       # Name of file containing definitions of
  57.                             # dialog symbols
  58.     print " "
  59.     print "/* C++ code file for creating control objects, generated via */"
  60.     print "/* AWK script translat.awk. Must be used with the UI_Composite */"
  61.     print "/* class. */ "
  62.     print  "\n\n#include \"ui/composit.h\"\n"
  63.     if (length(HeaderFile) > 0) printf "#include \"%s\"\n\n", HeaderFile
  64.     # We need to scale the sizes:
  65.     XFactor = 2.5
  66.     YFactor = 2.2
  67. }
  68.  
  69.  
  70.  
  71.  
  72. # {printf "%d: ", NR } # DEBUG
  73.  
  74. #
  75. # Process include directives
  76. #
  77. /^# *include/ {print; next}
  78.  
  79.  
  80. #
  81. # Target 0: look for the DIALOG specification
  82. #
  83.     if ($2 == "DIALOG") {
  84.         dialog_name = $1
  85.         rectn  = split($0, array, ", ")
  86.         dialog_shape = XFactor*$(NF-3) ", " YFactor*$(NF-2) ", " 
  87.         dialog_shape = dialog_shape XFactor*$(NF-1) ", " YFactor*$NF
  88.         next
  89.     }
  90. }
  91.  
  92. #
  93. # Target 1: match the BEGIN that starts a dialog spec
  94. #
  95. $1 ~ /BEGIN/        {
  96.     nBtnGroups = 0
  97.     if (length (dialog_name) > 0) {
  98.         # So that we don't process things inside menus
  99.         inside = 1   # We're now processing a dialog
  100.         inGroup = 0
  101.         dialogDesc = ""
  102.         ncontrols = 0
  103.  
  104.         map["LISTBOX"]       = "View_StringView"
  105.         map["EDITTEXT"]      = "View_StringEditor"
  106.         map["STATIC"]        = "View_Label"
  107.         map["LTEXT"]         = "View_Label"
  108.         map["RTEXT"]         = "View_Label"
  109.         map["CTEXT"]         = "View_Label"
  110.         map["PUSHBUTTON"]    = "View_PushButton"
  111.         map["DEFPUSHBUTTON"] = "View_PushButton"
  112.         map["RADIOBUTTON"]   = "View_ExOrToggleButton"
  113.         map["CHECKBOX"]      = "View_ToggleButton"
  114.         map["SCROLLBAR"]     = "View_ScrollBar"
  115.         map["GROUPBOX"]      = "View_ButtonGroup"
  116.  
  117.         next
  118.     }
  119.  
  120. }
  121.  
  122. $1 ~ /END/        {
  123.     if (length (dialog_name) > 0) {
  124.         for (s in buttonGroup) {
  125.             print "UI_ViewDescriptor FAR DLG_" dialog_name "_group" s "[] = {"
  126.             printf "%s",  buttonGroup[s]
  127.             print "{View_None, 0, 0}\n};\n\n"
  128.             delete buttonGroup[s]
  129.         }
  130.               
  131.         print "UI_RectangleStruct FAR  DLG_" dialog_name "_Shape = {"
  132.         print dialog_shape "\n};"
  133.         print "UI_ViewDescriptor FAR DLG_" dialog_name "_Item [] = {" 
  134.         printf "%s", dialogDesc
  135.         print "View_None, 0, 0\n}; \n"
  136.         inside = 0
  137.         dialog_name = ""
  138.         next
  139.     }
  140. }
  141.         
  142. #
  143. # Other targets: process the control statements
  144. #
  145. $1 ~ /LTEXT|CTEXT|RTEXT|CHECKBOX|PUSHBUTTON|RADIOBUTTON/   {
  146.     if (inside) {
  147.         # pos = match ($0, $1)
  148.         # m = RSTART + RLENGTH - 1
  149.         # print $1 ", " substr($0,m+1,length($0)-m) ", 0,"
  150.  
  151.         # Extract the type of control and its id number
  152.         nfields = split ($0, fld, ",")
  153.         nf = split (fld[1], f2, " ")
  154.         tabstop = ($1 ~ /TEXT/) ? "FALSE" : "TRUE"
  155.         AddEntry(map[$1], fld[2], fld[3], fld[4], fld[5], fld[6], tabstop,
  156.                    "TRUE",  f2[2], "NULL")
  157.         next
  158.     }
  159. }
  160.  
  161. $1 ~ /LISTBOX|EDITTEXT|SCROLLBAR/ {
  162.         nfields = split ($0, fld, ",")
  163.         nf = split (fld[1], f2, " ")
  164.         tabstop = ($1 ~ /SCROLLBAR/) ? "FALSE" : "TRUE"
  165.         AddEntry(map[f2[1]], f2[2], fld[2], fld[3], 
  166.                    tabstop, "TRUE", fld[4], fld[5], "NULL")
  167.         next
  168. }
  169.  
  170.  
  171. $1 ~ /CONTROL/    {
  172.     if (inside) {
  173.         nfields = split ($0, fld, ",")
  174.         label = fld[3]
  175.         gsub (/"/, "", label)
  176.         gsub (/ /, "", label)
  177.         if (label ~ /EDIT/) label = "EDITTEXT"
  178.         if (fld[4] ~ /RADIOBUTTON/) label = "RADIOBUTTON"
  179.         if (fld[4] ~ /CHECKBOX/) label = "CHECKBOX"
  180.         if (fld[4] ~ /PUSHBUTTON/) label = "PUSHBUTTON"
  181.         if (label  ~ /BorCheck/) label = "CHECKBOX"
  182.         if (label  ~ /BorRadio/) label = "RADIOBUTTON"
  183.         if (label  ~ /BorShade/) label = "GROUPBOX"
  184.         if (label == "button") label = "BUTTON"
  185.         if (label != "RADIOBUTTON" && label !=  "CHECKBOX") {
  186.             inGroup = 0
  187.         }
  188.         if (fld[4] ~ /GROUPBOX/) {
  189.             label = "GROUPBOX"
  190.         }
  191.         if (label in map) {
  192.             n = split (fld[1], f2, "\"")
  193.             tabstop = (fld[4] ~ /TABSTOP/) ? "TRUE" : "FALSE"
  194.             visible = (fld[4] ~ /VISIBLE/) ? "TRUE" : "FALSE"
  195.             if (label == "GROUPBOX") {
  196.                 children = "DLG_" dialog_name "_group" nBtnGroups+1
  197.             }
  198.             else children =  "NULL"
  199.             AddEntry(map[label], fld[2], fld[5], fld[6],
  200.                         fld[7], fld[8], tabstop, visible, f2[2], children)
  201.         } else {
  202.            print "Warning: Line " NR ": unrecognized control: " label
  203.         }
  204.         if (label == "GROUPBOX") {
  205.             nBtnGroups++
  206.             groupX = fld[5]
  207.             groupY = fld[6]
  208.             inGroup = 1
  209.         }
  210.         next
  211.     }
  212. }
  213.  
  214.                 
  215.  
  216. function AddEntry(type, id, x, y, w, h, tabst, vis, title, enclosed       ,s) {
  217.     entryFmt = "{%-16s, %s, %d, %d, %d, %d, %-5s,  \"%s\", %s},\n"
  218.     if (inGroup) {
  219.         s = sprintf(entryFmt, type, id, XFactor*(x-groupX), YFactor*(y-groupY),
  220.                     XFactor*w, YFactor*h, tabst,  title, enclosed)
  221.         s = buttonGroup[nBtnGroups] s
  222.         buttonGroup[nBtnGroups] = s
  223.     }
  224.     else {
  225.         s = sprintf(entryFmt, type, id, XFactor*x, YFactor*y,
  226.                     XFactor*w, YFactor*h, tabst,  title, enclosed)
  227.         dialogDesc = dialogDesc s
  228.     }
  229. }
  230.  
  231.