home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / thesrc15.zip / comm.the < prev    next >
Text File  |  1993-10-12  |  4KB  |  67 lines

  1. /*
  2. $Header: C:\THE\RCS\comm.the 1.4 1993/09/01 16:27:20 MH Interim MH $
  3. */
  4. /***********************************************************************/
  5. /* Description: REXX macro to comment lines.                           */
  6. /* Syntax:      comm [target]                                          */
  7. /* Notes:       This macro will comment lines based on the file        */
  8. /*              type or file name as per below:                        */
  9. /*               .c       - /* */                                      */
  10. /*               .h       - /* */                                      */
  11. /*               .rex     - /* */                                      */
  12. /*               .rexx    - /* */                                      */
  13. /*               .pas     - (* *)                                      */
  14. /*               .asm     - ;                                          */
  15. /*               makefile - #                                          */
  16. /*               Makefile - #                                          */
  17. /*              Full XEDIT/KEDIT/THE targets are supported.            */
  18. /***********************************************************************/
  19. trace o
  20. arg1 = Arg(1)
  21. noargs = Arg()
  22. If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
  23. forward = 1                  /* assume direction is forward by default */
  24. 'EXTRACT /LINE/TOF/EOF/SIZE/STAY/FTYPE/FNAME/'    /* get various stuff */
  25. current_line = line.1                   /* save current line for later */
  26. If tof.1 = 'ON' Then 'N'       /* if on 'top of file' move down 1 line */
  27. If eof.1 = 'ON' Then 'U'    /* if on 'bottom of file' move down 1 line */
  28. nolines = valid_target(arg1)               /* validate supplied target */
  29. If nolines = 0 Then Do            /* invalid target or target no found */
  30.    'CMSG comm' arg1                               /* redisplay command */
  31.    'EMSG Invalid target specified:' arg1           /* say its an error */
  32.    ':'||current_line                           /* restore current line */
  33.    Exit                                              /* go back to THE */
  34. End
  35. If nolines = 'ALL' Then Do                         /* if target is ALL */
  36.    ':1'                                              /* move to line 1 */
  37.    nolines = size.1                  /* nolines to act on - whole file */
  38. End
  39. If nolines < 0 Then Do                /* if target before current line */
  40.    forward = 0                    /* indicate direction to be backward */
  41.    nolines = nolines * -1                     /* make nolines positive */
  42. End
  43. totlines = 0                             /* reset changed line counter */
  44. Do nolines                              /* for each line to target ... */
  45.    'EXTRACT/CURLINE/'                     /* get current line contents */
  46.    Select                    /* add comment characters to current line */
  47.      When ftype.1 = 'c' Then 'REPLACE' '/*'||curline.3||'*/'
  48.      When ftype.1 = 'h' Then 'REPLACE' '/*'||curline.3||'*/'
  49.      When ftype.1 = 'rex' Then 'REPLACE' '/*'||curline.3||'*/'
  50.      When ftype.1 = 'rexx' Then 'REPLACE' '/*'||curline.3||'*/'
  51.      When ftype.1 = 'pas' Then 'REPLACE' '(*'||curline.3||'*)'
  52.      When ftype.1 = 'asm' Then 'REPLACE' ';'||curline.3
  53.      When ftype.1 = 'sql' Then 'REPLACE' 'rem '||curline.3
  54.      When ftype.1 = 'for' Then 'REPLACE' 'C '||curline.3
  55.      When fname.1 = 'makefile' Then 'REPLACE' '#'||curline.3
  56.      When fname.1 = 'Makefile' Then 'REPLACE' '#'||curline.3
  57.      Otherwise 'REPLACE' '/*'||curline.3||'*/'
  58.    End
  59.    totlines = totlines + 1
  60.    If forward = 1 Then 'N'         /* if going forward, get next line */
  61.    Else 'U'                  /* if going backwards, get previous line */
  62.    If rc \= 0 Then Leave                        /* shouldn't get here */
  63. End
  64. 'EMSG' totlines 'lines commented'       /* say how many lines changed */
  65. If stay.1 = 'ON' Then ':'||current_line 
  66. Return                                              /* go back to THE */
  67.