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