Icons for Radium and Shellplayer.
[AROS-Contrib.git] / bgui / MakeProto.c
blobebea9a62619f3aa407dcb2b834f9070bf6d39cd8
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * makeproto.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.0 2000/05/09 22:08:04 mlemos
15 * Bumped to revision 42.0 before handing BGUI to AROS team
17 * Revision 41.11 2000/05/09 19:53:37 mlemos
18 * Merged with the branch Manuel_Lemos_fixes.
20 * Revision 41.10.2.1 1998/10/01 23:04:17 mlemos
21 * Fixed problems with dangling pointers to missing command line arguments.
23 * Revision 41.10 1998/02/25 21:11:24 mlemos
24 * Bumping to 41.10
26 * Revision 1.1 1998/02/25 17:07:10 mlemos
27 * Ian sources
33 * Source is provided for demonstration and learning purposes only;
34 * derivative products are a violation of international copyright.
37 #include <proto/dos.h>
38 #include <dos/dos.h>
39 #include <dos/dosextens.h>
40 #include <proto/exec.h>
41 #include <exec/memory.h>
42 #include <string.h>
43 #include <ctype.h>
46 * MakeProto HEADER/K,SOURCE/M
48 * HEADER: The destination file to create, containing the prototype information.
49 * Include this file in all of your programs that need the global functions,
50 * the best place would be the main header file for your project.
52 * SOURCE: The file(s) to create prototype information for. These files will be
53 * scanned for the "makeproto" keyword, which is case-sensitive, and will
54 * be defined to do nothing in the final compilation (this is done in the
55 * generated header file).
57 * Unlike some other similar proto-building utilities, this one can handle
58 * split lines, to make large function declarations easier. Also, there is
59 * no need to change the prototype in more than one place, you can use the
60 * "makeproto" keyword right in the definition.
63 void killcomments(char *buffer)
65 char *dest = buffer, c;
67 int c_comment = 0, cpp_comment = 0;
69 while (c = *buffer++)
71 switch (c)
73 case '/':
74 switch (*buffer)
76 case '/':
77 buffer++;
78 cpp_comment++;
79 break;
80 case '*':
81 buffer++;
82 c_comment++;
83 break;
85 case '*':
86 if ((*buffer == '/') && (c_comment > 0))
88 buffer++;
89 c_comment--;
90 *dest++ = ' ';
92 break;
93 case 10:
94 case 13:
95 cpp_comment = 0;
96 break;
98 if (!(c_comment || cpp_comment)) *dest++ = c;
100 *dest = 0;
103 void makeproto(BPTR hf, char *buffer)
105 BOOL protomade = FALSE, function;
106 char c;
107 char *brace, *equals, *semi, *start, *end, *comma;
109 killcomments(buffer);
111 while (buffer = strstr(buffer + 1, "makeproto"))
113 if ((buffer[-1] == ';') || (buffer[-1] == '*')) buffer[-1] = ' ';
115 if (isspace(buffer[-1]) && isspace(buffer[9]))
117 start = stpblk(buffer + 9);
118 brace = strchr(start, '{');
119 equals = strchr(start, '=');
120 semi = strchr(start, ';');
122 function = brace && (!semi || (brace < semi)) && (!equals || (brace < equals));
124 if (!function)
126 if (equals && (equals < semi))
128 *equals = 0;
130 else
132 *semi = 0;
134 buffer = semi;
136 strrev(start);
137 while (isspace(*start)) start++;
138 strrev(start);
140 else
142 *brace = 0;
143 buffer = brace;
145 comma = start;
147 while (*comma)
149 if (CheckSignal(SIGBREAKF_CTRL_C)) return;
151 if (end = strchr(comma, ','))
153 comma = end;
155 else
157 comma = strchr(comma, ')');
158 if (comma)
160 while (end = strchr(comma + 1, ')'))
162 comma = end;
167 if (!comma) return;
168 c = *comma;
169 *comma = 0;
171 strrev(start);
172 while (isspace(*start)) start++;
173 if (strnicmp(start, "diov", 4))
175 while (iscsym(*start)) start++;
176 while (isspace(*start)) start++;
178 strrev(start);
180 *comma++ = c;
182 if (c == ')')
184 *comma = 0;
186 else
188 end = comma;
189 while (isspace(*comma)) comma++;
190 if (comma != end)
192 *end++ = ' ';
193 if (comma != end) strcpy(end, comma);
198 protomade = TRUE;
199 FPrintf(hf, "extern %s;\n", start);
202 if (!protomade) FPrintf(hf, "/* No external prototypes defined. */\n");
205 int makeprotos(BPTR hf, char **sources)
207 struct AnchorPath *ap;
209 char *source, *buffer;
210 BPTR sf;
212 if (ap = AllocVec(sizeof(struct AnchorPath) + 512, MEMF_CLEAR))
214 ap->ap_Strlen = 511;
216 FPrintf(hf, " * Generated by MakeProto\n * ©1996 Ian J. Einman.\n */\n");
218 while (source = *sources++)
220 if (!MatchFirst(source, ap))
224 if (sf = Open(ap->ap_Buf, MODE_OLDFILE))
226 if (buffer = AllocVec(ap->ap_Info.fib_Size + 1, MEMF_CLEAR))
228 Read(sf, buffer, ap->ap_Info.fib_Size);
230 Close(sf);
231 if (buffer)
233 FPrintf(hf, "\n/* %-42s */\n\n", ap->ap_Info.fib_FileName);
234 makeproto(hf, buffer);
235 FreeVec(buffer);
238 } while (!MatchNext(ap));
240 MatchEnd(ap);
242 FreeVec(ap);
244 FPrintf(hf, "\n#define makeproto\n");
246 else
248 return 20;
250 return 0;
253 int main(void)
255 int rc = 0;
257 struct Args
259 char *Header;
260 char **Source;
261 } args;
263 struct RDArgs *ra;
264 BPTR hf;
266 args.Header=NULL;
267 args.Source=NULL;
268 if (ra = ReadArgs("HEADER/K,SOURCE/M", (LONG *)&args, NULL))
270 if(args.Source)
272 if (args.Header
273 && (hf = Open(args.Header, MODE_NEWFILE)))
275 FPrintf(hf, "/*\n * %s\n *\n", args.Header);
276 rc = makeprotos(hf, args.Source);
277 Close(hf);
279 else if ((hf = Output()))
281 FPrintf(hf, "/*\n");
282 rc = makeprotos(hf, args.Source);
284 else
286 rc = 20;
289 else
291 rc = 20;
293 FreeArgs(ra);
295 return rc;