home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / the25O_w32.zip / uncomm.the < prev    next >
Text File  |  1997-09-12  |  5KB  |  125 lines

  1. /*
  2. $Id: uncomm.the 2.1 1995/06/24 16:31:36 MH Rel 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. /*               .htm     - <!-- -->                                   */
  16. /*               .html    - <!-- -->                                   */
  17. /*               makefile - #                                          */
  18. /*               Makefile - #                                          */
  19. /*              Full XEDIT/KEDIT/THE targets are supported.            */
  20. /***********************************************************************/
  21. Trace o
  22. arg1 = Arg(1)
  23. noargs = Arg()
  24. forward = 1                  /* assume direction is forward by defualt */
  25. If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
  26. 'EXTRACT /LINE/SIZE/STAY/FTYPE/FNAME/LINEND'      /* get various stuff */
  27. current_line = line.1                   /* save current line for later */
  28. reply = valid_target(arg1)                 /* validate supplied target */
  29. If reply = 'ERROR' Then
  30.    Do
  31.      'EMSG Error: 17 Invalid target' arg1
  32.      Exit
  33.    End
  34. If reply = 'NOTFOUND' Then
  35.    Do
  36.      'EMSG Error: 17 Target not found' arg1
  37.      Exit
  38.    End
  39. 'preserve'
  40. start_line = Word(reply,1)                        /* get starting line */
  41. nolines = Word(reply,2)                         /* get number of lines */
  42. If nolines < 0 Then Do                /* if target before current line */
  43.    forward = 0                    /* indicate direction to be backward */
  44.    nolines = nolines * -1                     /* make nolines positive */
  45. End
  46. ':'||start_line                                    /* go to first line */
  47. totlines = 0                             /* reset changed line counter */
  48. Select
  49.   When ftype.1 = 'c' Then Do
  50.                      first_comment = '/*'
  51.                      last_comment = '*/'
  52.                      End
  53.   When ftype.1 = 'h' Then Do
  54.                      first_comment = '/*'
  55.                      last_comment = '*/'
  56.                      End
  57.   When ftype.1 = 'rex' Then Do
  58.                      first_comment = '/*'
  59.                      last_comment = '*/'
  60.                      End
  61.   When ftype.1 = 'rexx' Then Do
  62.                      first_comment = '/*'
  63.                      last_comment = '*/'
  64.                      End
  65.   When ftype.1 = 'pas' Then Do
  66.                      first_comment = '(*'
  67.                      last_comment = '*)'
  68.                      End
  69.   When ftype.1 = 'htm' | ftype.1 = 'html' Then Do
  70.                      first_comment = '<!--'
  71.                      last_comment = '-->'
  72.                      End
  73.   When ftype.1 = 'asm' Then Do
  74.                      first_comment = ';'
  75.                      last_comment = ''
  76.                      End
  77.   When ftype.1 = 'asm' Then Do
  78.                      first_comment = 'rem '
  79.                      last_comment = ''
  80.                      End
  81.   When fname.1 = 'makefile' Then Do
  82.                      first_comment = '#'
  83.                      last_comment = ''
  84.                      End
  85.   When fname.1 = 'Makefile' Then Do
  86.                      first_comment = '#'
  87.                      last_comment = ''
  88.                      End
  89.   Otherwise Do
  90.                      first_comment = '/*'
  91.                      last_comment = '*/'
  92.                      End
  93. End
  94. If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND OFF'
  95. Do nolines
  96.    start = 0; end = 0
  97.    'EXTRACT /CURLINE/TOF/EOF/'       /* get current line contents, etc.*/
  98.    If tof.1 = 'ON',                    /* ignore line if on TOF or EOF */
  99.    |  eof.1 = 'ON' Then nop
  100.    Else
  101.       Do
  102.         linelength = Length(curline.3)
  103.         len1 = Length(first_comment)
  104.         len2 = Length(last_comment)
  105.         If Substr(curline.3,1,len1) = first_comment Then start = 1
  106.         newlength = linelength - len2 + 1
  107.         If Substr(curline.3,newlength,len2) = last_comment Then end = 1
  108.         If start = 1 & end = 1 Then 
  109.            Do
  110.              newlength = linelength - (len1 + len2)
  111.              newline = Substr(curline.3,len1+1,newlength)
  112.              'REPLACE' newline
  113.              totlines = totlines + 1
  114.            End
  115.       End
  116.    If forward = 1 Then 'N'
  117.    Else 'U'
  118.    If rc \= 0 Then Leave
  119. End
  120. If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND' linend.1 linend.2
  121. 'EMSG' totlines 'lines uncommented'      /* say how many lines changed */
  122. If stay.1 = 'ON' Then ':'||current_line
  123. 'restore'
  124. Return                                               /* go back to THE */
  125.