File: uncomm.the

package info (click to toggle)
the 3.3~rc1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 5,492 kB
  • ctags: 5,888
  • sloc: ansic: 73,773; sh: 2,904; makefile: 790
file content (124 lines) | stat: -rw-r--r-- 5,185 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
$Id: uncomm.the,v 1.2 2001/01/04 09:42:28 mark Exp $
*/
/***********************************************************************/
/* Description: REXX macro to uncomment lines.                         */
/* Syntax:      uncomm [target]                                        */
/* Notes:       This macro will uncomment lines based on the file      */
/*              type or file name as per below:                        */
/*               .c       - /* */                                      */
/*               .h       - /* */                                      */
/*               .rex     - /* */                                      */
/*               .rexx    - /* */                                      */
/*               .pas     - (* *)                                      */
/*               .asm     - ;                                          */
/*               .htm     - <!-- -->                                   */
/*               .html    - <!-- -->                                   */
/*               makefile - #                                          */
/*               Makefile - #                                          */
/*              Full XEDIT/KEDIT/THE targets are supported.            */
/***********************************************************************/
Trace o
arg1 = Arg(1)
noargs = Arg()
forward = 1                  /* assume direction is forward by defualt */
If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
'EXTRACT /LINE/SIZE/STAY/FTYPE/FNAME/LINEND'      /* get various stuff */
current_line = line.1                   /* save current line for later */
reply = valid_target(arg1)                 /* validate supplied target */
If reply = 'ERROR' Then
   Do
     'EMSG Error: 17 Invalid target' arg1
     Exit
   End
If reply = 'NOTFOUND' Then
   Do
     'EMSG Error: 17 Target not found' arg1
     Exit
   End
'preserve'
start_line = Word(reply,1)                        /* get starting line */
nolines = Word(reply,2)                         /* get number of lines */
If nolines < 0 Then Do                /* if target before current line */
   forward = 0                    /* indicate direction to be backward */
   nolines = nolines * -1                     /* make nolines positive */
End
':'||start_line                                    /* go to first line */
totlines = 0                             /* reset changed line counter */
Select
  When ftype.1 = 'c' Then Do
                     first_comment = '/*'
                     last_comment = '*/'
                     End
  When ftype.1 = 'h' Then Do
                     first_comment = '/*'
                     last_comment = '*/'
                     End
  When ftype.1 = 'rex' Then Do
                     first_comment = '/*'
                     last_comment = '*/'
                     End
  When ftype.1 = 'rexx' Then Do
                     first_comment = '/*'
                     last_comment = '*/'
                     End
  When ftype.1 = 'pas' Then Do
                     first_comment = '(*'
                     last_comment = '*)'
                     End
  When ftype.1 = 'htm' | ftype.1 = 'html' Then Do
                     first_comment = '<!--'
                     last_comment = '-->'
                     End
  When ftype.1 = 'asm' Then Do
                     first_comment = ';'
                     last_comment = ''
                     End
  When ftype.1 = 'asm' Then Do
                     first_comment = 'rem '
                     last_comment = ''
                     End
  When fname.1 = 'makefile' Then Do
                     first_comment = '#'
                     last_comment = ''
                     End
  When fname.1 = 'Makefile' Then Do
                     first_comment = '#'
                     last_comment = ''
                     End
  Otherwise Do
                     first_comment = '/*'
                     last_comment = '*/'
                     End
End
If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND OFF'
Do nolines
   start = 0; end = 0
   'EXTRACT /CURLINE/'                    /* get current line contents, etc.*/
   If focustof(),                           /* ignore line if on TOF or EOF */
   |  focuseof() Then nop
   Else
      Do
        linelength = Length(curline.3)
        len1 = Length(first_comment)
        len2 = Length(last_comment)
        If Substr(curline.3,1,len1) = first_comment Then start = 1
        newlength = linelength - len2 + 1
        If Substr(curline.3,newlength,len2) = last_comment Then end = 1
        If start = 1 & end = 1 Then 
           Do
             newlength = linelength - (len1 + len2)
             newline = Substr(curline.3,len1+1,newlength)
             'REPLACE' newline
             totlines = totlines + 1
           End
      End
   If forward = 1 Then 'N'
   Else 'U'
   If rc \= 0 Then Leave
End
If fname.1 = 'makefile' |  fname.1 = 'Makefile' Then 'SET LINEND' linend.1 linend.2
'EMSG' totlines 'lines uncommented'      /* say how many lines changed */
If stay.1 = 'ON' Then ':'||current_line
'restore'
Return                                               /* go back to THE */