home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / theos215.zip / uncomm.the < prev   
Text File  |  1993-10-21  |  5KB  |  110 lines

  1. /*
  2. $Header: C:\THE\RCS\uncomm.the 1.4 1993/09/01 16:27:20 MH Interim MH $
  3. */
  4. /***********************************************************************/
  5. /* Description: REXX macro to uncomment lines.                         */
  6. /* Syntax:      uncomm [target]                                        */
  7. /* Notes:       This macro will uncomment 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 defualt */
  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 uncomm' 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. Select
  45.   When ftype.1 = 'c' Then Do
  46.                      first_comment = '/*'
  47.                      last_comment = '*/'
  48.                      End
  49.   When ftype.1 = 'h' Then Do
  50.                      first_comment = '/*'
  51.                      last_comment = '*/'
  52.                      End
  53.   When ftype.1 = 'rex' Then Do
  54.                      first_comment = '/*'
  55.                      last_comment = '*/'
  56.                      End
  57.   When ftype.1 = 'rexx' Then Do
  58.                      first_comment = '/*'
  59.                      last_comment = '*/'
  60.                      End
  61.   When ftype.1 = 'pas' Then Do
  62.                      first_comment = '(*'
  63.                      last_comment = '*)'
  64.                      End
  65.   When ftype.1 = 'asm' Then Do
  66.                      first_comment = ';'
  67.                      last_comment = ''
  68.                      End
  69.   When ftype.1 = 'asm' Then Do
  70.                      first_comment = 'rem '
  71.                      last_comment = ''
  72.                      End
  73.   When fname.1 = 'makefile' Then Do
  74.                      first_comment = '#'
  75.                      last_comment = ''
  76.                      End
  77.   When fname.1 = 'Makefile' Then Do
  78.                      first_comment = '#'
  79.                      last_comment = ''
  80.                      End
  81.   Otherwise Do
  82.                      first_comment = '/*'
  83.                      last_comment = '*/'
  84.                      End
  85. End
  86. Do nolines
  87.    start = 0; end = 0
  88.    'EXTRACT/CURLINE/'
  89.    linelength = Length(curline.3)
  90.    If linelength == 0 Then                       /* ignore blank lines */
  91.       Iterate
  92.    len1 = Length(first_comment)
  93.    len2 = Length(last_comment)
  94.    If Substr(curline.3,1,len1) = first_comment Then start = 1
  95.    newlength = linelength - len2 + 1
  96.    If Substr(curline.3,newlength,len2) = last_comment Then end = 1
  97.    If start = 1 & end = 1 Then Do
  98.       newlength = linelength - (len1 + len2)
  99.       newline = Substr(curline.3,len1+1,newlength)
  100.       'REPLACE' newline
  101.       totlines = totlines + 1
  102.    End
  103.    If forward = 1 Then 'N'
  104.    Else 'U'
  105.    If rc \= 0 Then Leave
  106. End
  107. 'EMSG' totlines 'lines uncommented'
  108. If stay.1 = 'ON' Then ':'||current_line
  109. Return
  110.