home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / memacs32.zip / cpage.cmd < prev    next >
OS/2 REXX Batch file  |  1993-08-07  |  8KB  |  352 lines

  1. ;    CPAGE.CMD:    C language MENU Page
  2. ;            for MicroEMACS 3.9e and above
  3. ;            (C)opyright 1988 by Daniel Lawrence
  4. ;
  5.  
  6. ; set up the "clean" procedure
  7. store-procedure clean
  8.     delete-buffer "[Macro 10]"
  9.     delete-buffer "[Macro 11]"
  10.     delete-buffer "[Macro 12]"
  11.     delete-buffer "[Macro 13]"
  12.     delete-buffer "[Macro 14]"
  13.     delete-buffer "[Macro 15]"
  14.     delete-buffer "[Macro 16]"
  15.     delete-buffer "[Macro 17]"
  16.     delete-buffer "[Macro 18]"
  17.     delete-buffer "[Macro 19]"
  18.     delete-buffer "[drawbox]"
  19.     delete-buffer "[setpoints]"
  20.     delete-buffer "[findcom]"
  21.     set $cmode %oldmode
  22.     set $gmode %oldgmode
  23. !endm
  24.  
  25. ; make sure the function key window is up
  26.     set %rcfkeys FALSE
  27.     toggle-fkeys
  28.     write-message "Loading..."
  29.  
  30. ; Write out the page instructions
  31.     save-window
  32.     1 next-window
  33.     beginning-of-file
  34.     set $curcol 25
  35.     overwrite-string " F1 PROCEDURE             F2 function           "
  36.     next-line
  37.     set $curcol 25
  38.     overwrite-string " F3 if then else          F4 while              "
  39.     next-line
  40.     set $curcol 25
  41.     overwrite-string " F5 REPEAT                F6 switch             "
  42.     next-line
  43.     set $curcol 18
  44.     overwrite-string "C   "
  45.     set $curcol 25
  46.     overwrite-string " F7 VALUE                 F8 Reserved words UP  "
  47.     next-line
  48.     set $curcol 25
  49.     overwrite-string " F9 chk comment matching F10 Comment block      "
  50.     unmark-buffer
  51.     beginning-of-file
  52.     !force restore-window
  53.     update-screen
  54.  
  55. ;
  56.  
  57. 10    store-macro
  58. ;    set $debug TRUE
  59.         set %proc @"Procedure Name: "
  60.         insert-string &cat &cat "Procedure " %proc "~n"
  61.         insert-string "   ( VAR ~n"
  62.         insert-string "   );~n"
  63.         insert-string "~n"
  64.         insert-string &cat &cat "{ (* " %proc " *)~n"
  65.         insert-string &cat &cat "};  (* " %proc " *)~n"
  66.     previous-line
  67.         open-line
  68.         insert-string "   "
  69.     !force set $debug FALSE
  70. !endm
  71. bind-to-key execute-macro-10 S-FN1
  72.  
  73. ;    Function
  74. 11    store-macro
  75.         set %func @"Function Name: "
  76.         set %type @"Return type: "
  77.     insert-string %type
  78.     !if ¬ &sequal &right %type 1 "*"
  79.         insert-string " "
  80.     !endif                            
  81.         insert-string &cat %func "()~n~n{~n    ~n}~n"
  82.         3 backward-character
  83.     !force set $debug FALSE
  84. !endm
  85. bind-to-key execute-macro-11 S-FN2
  86.  
  87. ;
  88.  
  89. 12    store-macro
  90.         set %cond @"Condition Expr: "
  91.         insert-string &cat &cat "if (" %cond ") {"
  92.     newline-and-indent
  93.     newline-and-indent
  94.         insert-string "} else {"
  95.     newline-and-indent
  96.     newline-and-indent
  97.            insert-string &cat &cat "}  /* if (" %cond ") */"
  98.     1 previous-line
  99.         end-of-line
  100.         handle-tab
  101.     2 previous-line
  102.         end-of-line
  103.         handle-tab
  104. !endm
  105. bind-to-key execute-macro-12 S-FN3
  106.  
  107. ;
  108.  
  109. 13    store-macro
  110.         set %cond @"Condition Expr: "
  111.     ;set $debug TRUE
  112.         insert-string &cat &cat "while (" %cond ") {"
  113.     newline-and-indent
  114.     newline-and-indent
  115.         insert-string &cat &cat "}  /* while (" %cond ") */"
  116.     1 previous-line
  117.         end-of-line
  118.     handle-tab
  119. !endm
  120. bind-to-key execute-macro-13 S-FN4
  121.  
  122. 14    store-macro
  123.         set %cond @"Condition Expr: "
  124.     ;set $debug TRUE
  125.         set %curcol $curcol
  126.         insert-string &cat &cat "REPEAT~n"
  127.         %curcol insert-string " "
  128.         set $curcol %curcol
  129.         !if &EQUal  %curcol 3
  130.             insert-string &cat &cat "UNTIL " %cond ";"
  131.     !else
  132.             insert-string &cat      "UNTIL " %cond 
  133.     !endif
  134.         beginning-of-line
  135.         open-line
  136.         %curcol insert-string " "
  137.         insert-string "   "
  138.     !force set $debug FALSE
  139. !endm
  140. bind-to-key execute-macro-14 S-FN5
  141.  
  142. 15    store-macro
  143.         set %expr @"Switch Expr: "
  144.     ;set $debug TRUE
  145.         set %curcol $curcol
  146.         insert-string &cat &cat "switch (" %expr ") {"
  147.     newline-and-indent
  148.     insert-string "}"
  149.     previous-line
  150.     end-of-line
  151.     newline-and-indent
  152.     handle-tab
  153.     insert-string "case "
  154.     !force set $debug FALSE
  155. !endm
  156. bind-to-key execute-macro-15 S-FN6
  157.  
  158. 16    store-macro
  159. ;    set $debug TRUE
  160.         set %curcol $curcol
  161.         set %value @"Value: "
  162.         insert-string &cat %value " : {~n"
  163.         %curcol insert-string " "
  164.         insert-string "    };~n"
  165.         %curcol insert-string " "
  166.     previous-line
  167.         beginning-of-line
  168.         open-line
  169.         %curcol insert-string " "
  170.         insert-string "       "
  171.     !force set $debug FALSE
  172. !endm
  173. bind-to-key execute-macro-16 S-FN7
  174.  
  175. 17    store-macro
  176. ;    set $debug TRUE
  177.         set %curcol $curcol
  178.     ;save-file
  179.         set-mark
  180.     beginning-of-file
  181.         write-message "[Replacing 'begin']
  182.     replace-string "begin" "BEGIN"
  183.  
  184.     beginning-of-file
  185.         write-message "[Replacing 'end']
  186.     replace-string "end" "END"
  187.  
  188.     beginning-of-file
  189.         write-message "[Replacing ' if']
  190.     replace-string " if" " IF"
  191.  
  192.     beginning-of-file
  193.         write-message "[Replacing ' else']
  194.     replace-string " else" " ELSE"
  195.  
  196.     beginning-of-file
  197.         write-message "[Replacing ' repeat']
  198.     replace-string " repeat" " REPEAT"
  199.  
  200.     beginning-of-file
  201.         write-message "[Replacing ' while']
  202.     replace-string " while" " WHILE"
  203.  
  204.         exchange-point-and-mark
  205.     !force set $debug FALSE
  206. !endm
  207. bind-to-key execute-macro-17 S-FN8
  208.  
  209. 18    store-macro
  210.     beginning-of-file
  211.     run findcom
  212. !endm
  213. bind-to-key execute-macro-18 S-FN9
  214.  
  215. store-procedure    findcom
  216. ;    This hunts down mismatched comment problems in C
  217.  
  218. ;    start from the current position in the file
  219.  
  220.     !force search-forward "/*"
  221.     !if &seq $status FALSE
  222.         !goto nend
  223.     !endif
  224.  
  225. *nxtopen
  226.     ;record the position of the open comment
  227.     update-screen
  228.     set %oline $curline
  229.     set %opos $curcol
  230.  
  231.     ;find the first close comment
  232.     !force search-forward "*/"
  233.     !if &seq $status FALSE
  234.         write-message "%%No close to this open comment"
  235.         !return
  236.     !endif
  237.  
  238.     ;record the position of the close comment
  239.     set %cline $curline
  240.     set %cpos $curcol
  241.  
  242.     ;go back to the open and find the next open
  243.     set $curline %oline
  244.     set $curcol %opos
  245.  
  246.     ;and now find the next open
  247.     !force search-forward "/*"
  248.     !if &seq $status FALSE
  249.         write-message "No errors"
  250.         !return
  251.     !endif
  252.     set %nline $curline
  253.     set %npos $curcol
  254.  
  255.     ;compare the close to the next open
  256.     !if &less %cline %nline
  257.         !goto getnext
  258.     !endif
  259.     !if &and &equ %cline %nline &less %cpos %npos
  260.         !goto getnext
  261.     !endif
  262.  
  263.     ;report a mismatch
  264.     set $curline %oline
  265.     set $curcol %opos
  266.     write-message "%%This comment does not terminate properly"
  267.     !return
  268.  
  269. *getnext
  270.     set $curline %nline
  271.     set $curcol %npos
  272.     !goto nxtopen 
  273. !endm
  274.  
  275. 19    store-macro
  276.     set %c1 "/"
  277.     set %c2 "*"
  278.     set %c3 "\"
  279.     set %c4 "\"
  280.     set %c5 "/"
  281.     set %c6 "*"
  282.     run drawbox    
  283. !endm
  284. bind-to-key execute-macro-19 S-FN0
  285. bind-to-key execute-macro-19 A-FN0
  286.  
  287. store-procedure drawbox
  288.     run setpoints
  289.     set $curline %mline
  290.     set $curcol %mcol
  291. ;draw top horizontal line
  292.     insert-string %c1
  293.     set %width &add 2 &sub %pcol %mcol
  294.     %width insert-string %c2
  295.      insert-string %c3
  296.     newline-and-indent
  297. ;draw bottom horizontal line
  298.     %pline goto-line
  299.     next-line
  300.     end-of-line
  301.        newline
  302.     %mcol insert-string " "
  303.     insert-string %c4
  304.     %width insert-string %c2
  305.     insert-string %c5
  306. ;bump pline 
  307.     set %pline &add %pline 1
  308. ;draw verticals -- go to top and work our way down
  309.     %mline goto-line
  310.     !while &less $curline %pline
  311.         next-line
  312.         end-of-line
  313.         !if &less $curcol %pcol
  314.             &sub %pcol $curcol insert-string " "
  315.         !endif
  316.         set $curcol %pcol
  317.         insert-string " "
  318.         insert-string %c6
  319.         set $curcol %mcol
  320.         insert-string %c6
  321.         insert-string " "
  322.     !endwhile
  323. ;return to point
  324.     %pline goto-line
  325.     next-line
  326.     beginning-of-line
  327.     &add 6 %width forward-character
  328. !endm
  329.  
  330. store-procedure setpoints
  331. ; procedure will set pcol, pline, mcol and mline. currently at point
  332. ; it will also detab the region
  333.     set %pcol $curcol
  334.     set %pline $curline
  335.     exchange-point-and-mark
  336.     set %mcol $curcol
  337.     set %mline $curline
  338.     exchange-point-and-mark
  339.     detab-region
  340.     set $curline %pline
  341.     set $curcol %pcol
  342. !endm
  343. bind-to-key execute-macro-19 S-FN0
  344.  
  345. ; Set up CMODE
  346.     set %oldmode $cmode
  347.     set %oldgmode $gmode
  348.     add-mode CMODE
  349.     add-global-mode CMODE
  350.  
  351. write-message "[C MENU page loaded]"
  352.