-
Notifications
You must be signed in to change notification settings - Fork 0
/
afterlint.c
208 lines (179 loc) · 5.04 KB
/
afterlint.c
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* CHK=0xC2C5 */
char *rev = "1.20";
/*+-------------------------------------------------------------------------
afterlint.c -- process MSC -Zg output (for *some* MSC versions)
This works for ecu but maybe not other code collections;
returning a typedefed but unnamed structure (or pointer)
will, for instance, produce bad output.
Use with zgcc.
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
/*:01-24-1997-02:36-wht@yuriatin-SOURCE RELEASE 4.00 */
/*:09-11-1996-19:59-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
/*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
/*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
/*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
/*:01-21-1992-03:03-wht@n4hgf-better handling of commented items with UNNAMED */
/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
/*:01-09-1991-22:31-wht@n4hgf-ISC port */
/*:11-18-1990-21:15-wht@n4hgf-clobber 'extern ' in prototypes */
/*:07-13-1988-19:50-wht-creation */
#include <stdio.h>
#include <sys/types.h>
#ifdef BSD
#include <sys/time.h>
#define strchr index
#define strrchr rindex
char *index();
char *rindex();
/*************************/
#else /* assuming SYSV */
/*************************/
#include <time.h>
char *strchr();
char *strrchr();
#endif /* system dependencies */
struct tm *localtime();
/*+-------------------------------------------------------------------------
emit_editnote(fp)
--------------------------------------------------------------------------*/
void
emit_editnote(fp)
FILE *fp;
{
struct tm *ltime;
long cur_time;
time(&cur_time);
ltime = localtime(&cur_time);
fputs("/*+:EDITS:*/\n", fp);
fprintf(fp, "/*:%02d-%02d-%04d-%02d:%02d-afterlint %s-creation */\n",
ltime->tm_mon + 1, ltime->tm_mday, ltime->tm_year + 1900,
ltime->tm_hour, ltime->tm_min, rev);
} /* end of emit_editnote */
/*+-------------------------------------------------------------------------
instr(str1,str2) - is str2 contained in str1?
return 1 if so, else 0
--------------------------------------------------------------------------*/
int
instr(str1, str2)
char *str1; /* the (target) string to search */
char *str2; /* the (comparand) string to search for */
{
int lstr2 = strlen(str2);
if (lstr2 > strlen(str1))
return (0);
while (*str1)
{
if (*str1 == *str2)
{
if (!strncmp(str1, str2, lstr2))
return (1);
}
++str1;
}
return (0);
} /* end of instr */
/*+-------------------------------------------------------------------------
main(argc,argv,envp)
--------------------------------------------------------------------------*/
main(argc, argv, envp)
int argc;
char **argv;
char **envp;
{
char *cp;
FILE *fpin;
FILE *fpout;
char buf[256];
char *basename;
if (argc < 2)
{
fprintf(stderr, "usage: afterlint <infile> [<outfile>]\n");
fprintf(stderr, "if outfile not supplied, output is to stdout\n");
exit(1);
}
if (!(fpin = fopen(argv[1], "r")))
{
perror(argv[1]);
exit(1);
}
if (argc > 2)
{
if (!(fpout = fopen(argv[2], "w")))
{
perror(argv[2]);
exit(1);
}
basename = argv[2];
}
else
fpout = stdout;
fprintf(fpout,
"/*+-----------------------------------------------------------------------\n");
if (argc > 2)
fprintf(fpout, "\t%s\n", basename);
else
fprintf(fpout, "\tfunction declarations\n", basename);
fprintf(fpout,
"------------------------------------------------------------------------*/\n");
emit_editnote(fpout);
fprintf(fpout, "\n");
fprintf(fpout, "#ifndef BUILDING_PROTOTYPES\n");
fprintf(fpout, "\n/* the following should catch only SCO MSC */\n");
fprintf(fpout,
"#if defined(M_SYSV) && !defined(__GNUC__) && !defined(GNUC)\n\n");
while (fgets(buf, sizeof(buf), fpin))
{
cp = buf;
if (instr(buf, "UNNAMED"))
{
cp += 3;
if (strchr(cp, '('))
{
while (*cp != '(')
fputc(*cp++, fpout);
fputs("(); /* no proto (struct UNNAMED param) */\n", fpout);
}
continue;
}
if (!strncmp(buf, "/*global*/ ", 12))
cp += 12;
else if (!strncmp(buf, "extern ", 8))
cp += 8;
else if (!strncmp(buf, "static ", 8))
cp += 8;
fputs(cp, fpout);
}
fprintf(fpout, "\n#else\t\t/* compiler doesn't know prototyping */\n\n");
fclose(fpin);
fpin = fopen(argv[1], "r");
while (fgets(buf, sizeof(buf), fpin))
{
cp = buf;
if (instr(buf, "UNNAMED"))
cp += 3;
else if (!strncmp(buf, "/*global*/ ", 12))
cp += 12;
else if (!strncmp(buf, "extern ", 8))
cp += 8;
else if (!strncmp(buf, "static ", 8))
cp += 8;
if (strchr(cp, '('))
{
while (*cp != '(')
fputc(*cp++, fpout);
fputs("();\n", fpout);
}
}
fprintf(fpout, "\n#endif /* MSC considerations */\n");
fprintf(fpout, "#endif /* BUILDING_PROTOTYPES */\n");
fprintf(fpout, "\n/* end of %s */\n",
(argc > 2) ? basename : "function declarations");
fclose(fpin);
fclose(fpout);
exit(0);
} /* end of main */
/* vi: set tabstop=4 shiftwidth=4: */