Repository navigation
Expand file tree
/
Copy pathMakeProto.c
More file actions
296 lines (266 loc) · 7 KB
/
Copy pathMakeProto.c
File metadata and controls
296 lines (266 loc) · 7 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
* @(#) $Header$
*
* BGUI library
* makeproto.c
*
* (C) Copyright 1998 Manuel Lemos.
* (C) Copyright 1996-1997 Ian J. Einman.
* (C) Copyright 1993-1996 Jaba Development.
* (C) Copyright 1993-1996 Jan van den Baard.
* All Rights Reserved.
*
* $Log$
* Revision 42.0 2000/05/09 22:08:04 mlemos
* Bumped to revision 42.0 before handing BGUI to AROS team
*
* Revision 41.11 2000/05/09 19:53:37 mlemos
* Merged with the branch Manuel_Lemos_fixes.
*
* Revision 41.10.2.1 1998/10/01 23:04:17 mlemos
* Fixed problems with dangling pointers to missing command line arguments.
*
* Revision 41.10 1998/02/25 21:11:24 mlemos
* Bumping to 41.10
*
* Revision 1.1 1998/02/25 17:07:10 mlemos
* Ian sources
*
*
*/
/*
* Source is provided for demonstration and learning purposes only;
* derivative products are a violation of international copyright.
*/
#include <proto/dos.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <proto/exec.h>
#include <exec/memory.h>
#include <string.h>
#include <ctype.h>
/*
* MakeProto HEADER/K,SOURCE/M
*
* HEADER: The destination file to create, containing the prototype information.
* Include this file in all of your programs that need the global functions,
* the best place would be the main header file for your project.
*
* SOURCE: The file(s) to create prototype information for. These files will be
* scanned for the "makeproto" keyword, which is case-sensitive, and will
* be defined to do nothing in the final compilation (this is done in the
* generated header file).
*
* Unlike some other similar proto-building utilities, this one can handle
* split lines, to make large function declarations easier. Also, there is
* no need to change the prototype in more than one place, you can use the
* "makeproto" keyword right in the definition.
*/
void killcomments(char *buffer)
{
char *dest = buffer, c;
int c_comment = 0, cpp_comment = 0;
while (c = *buffer++)
{
switch (c)
{
case '/':
switch (*buffer)
{
case '/':
buffer++;
cpp_comment++;
break;
case '*':
buffer++;
c_comment++;
break;
};
case '*':
if ((*buffer == '/') && (c_comment > 0))
{
buffer++;
c_comment--;
*dest++ = ' ';
};
break;
case 10:
case 13:
cpp_comment = 0;
break;
};
if (!(c_comment || cpp_comment)) *dest++ = c;
};
*dest = 0;
}
void makeproto(BPTR hf, char *buffer)
{
BOOL protomade = FALSE, function;
char c;
char *brace, *equals, *semi, *start, *end, *comma;
killcomments(buffer);
while (buffer = strstr(buffer + 1, "makeproto"))
{
if ((buffer[-1] == ';') || (buffer[-1] == '*')) buffer[-1] = ' ';
if (isspace(buffer[-1]) && isspace(buffer[9]))
{
start = stpblk(buffer + 9);
brace = strchr(start, '{');
equals = strchr(start, '=');
semi = strchr(start, ';');
function = brace && (!semi || (brace < semi)) && (!equals || (brace < equals));
if (!function)
{
if (equals && (equals < semi))
{
*equals = 0;
}
else
{
*semi = 0;
};
buffer = semi;
strrev(start);
while (isspace(*start)) start++;
strrev(start);
}
else
{
*brace = 0;
buffer = brace;
comma = start;
while (*comma)
{
if (CheckSignal(SIGBREAKF_CTRL_C)) return;
if (end = strchr(comma, ','))
{
comma = end;
}
else
{
comma = strchr(comma, ')');
if (comma)
{
while (end = strchr(comma + 1, ')'))
{
comma = end;
};
};
};
if (!comma) return;
c = *comma;
*comma = 0;
strrev(start);
while (isspace(*start)) start++;
if (strnicmp(start, "diov", 4))
{
while (iscsym(*start)) start++;
while (isspace(*start)) start++;
};
strrev(start);
*comma++ = c;
if (c == ')')
{
*comma = 0;
}
else
{
end = comma;
while (isspace(*comma)) comma++;
if (comma != end)
{
*end++ = ' ';
if (comma != end) strcpy(end, comma);
};
};
};
};
protomade = TRUE;
FPrintf(hf, "extern %s;\n", start);
};
};
if (!protomade) FPrintf(hf, "/* No external prototypes defined. */\n");
}
int makeprotos(BPTR hf, char **sources)
{
struct AnchorPath *ap;
char *source, *buffer;
BPTR sf;
if (ap = AllocVec(sizeof(struct AnchorPath) + 512, MEMF_CLEAR))
{
ap->ap_Strlen = 511;
FPrintf(hf, " * Generated by MakeProto\n * ©1996 Ian J. Einman.\n */\n");
while (source = *sources++)
{
if (!MatchFirst(source, ap))
{
do
{
if (sf = Open(ap->ap_Buf, MODE_OLDFILE))
{
if (buffer = AllocVec(ap->ap_Info.fib_Size + 1, MEMF_CLEAR))
{
Read(sf, buffer, ap->ap_Info.fib_Size);
};
Close(sf);
if (buffer)
{
FPrintf(hf, "\n/* %-42s */\n\n", ap->ap_Info.fib_FileName);
makeproto(hf, buffer);
FreeVec(buffer);
};
};
} while (!MatchNext(ap));
};
MatchEnd(ap);
}
FreeVec(ap);
FPrintf(hf, "\n#define makeproto\n");
}
else
{
return 20;
};
return 0;
}
int main(void)
{
int rc = 0;
struct Args
{
char *Header;
char **Source;
} args;
struct RDArgs *ra;
BPTR hf;
args.Header=NULL;
args.Source=NULL;
if (ra = ReadArgs("HEADER/K,SOURCE/M", (LONG *)&args, NULL))
{
if(args.Source)
{
if (args.Header
&& (hf = Open(args.Header, MODE_NEWFILE)))
{
FPrintf(hf, "/*\n * %s\n *\n", args.Header);
rc = makeprotos(hf, args.Source);
Close(hf);
}
else if ((hf = Output()))
{
FPrintf(hf, "/*\n");
rc = makeprotos(hf, args.Source);
}
else
{
rc = 20;
};
}
else
{
rc = 20;
};
FreeArgs(ra);
};
return rc;
}