disable the unrecognized nls and x flags
[AROS-Contrib.git] / bgui / MakeProtoANSI.c
blobce662b2d439bafb161aa3cd885e2166c085045fb
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 1.1 2000/05/28 21:46:40 stegerg
15 * *** empty log message ***
17 * Revision 42.0 2000/05/09 22:08:04 mlemos
18 * Bumped to revision 42.0 before handing BGUI to AROS team
20 * Revision 41.11 2000/05/09 19:53:37 mlemos
21 * Merged with the branch Manuel_Lemos_fixes.
23 * Revision 41.10.2.1 1998/10/01 23:04:17 mlemos
24 * Fixed problems with dangling pointers to missing command line arguments.
26 * Revision 41.10 1998/02/25 21:11:24 mlemos
27 * Bumping to 41.10
29 * Revision 1.1 1998/02/25 17:07:10 mlemos
30 * Ian sources
36 * Source is provided for demonstration and learning purposes only;
37 * derivative products are a violation of international copyright.
40 #include <stdio.h>
41 #include <string.h>
42 #include <ctype.h>
44 typedef short BOOL;
45 #define TRUE 1
46 #define FALSE 0
49 * MakeProtoANSI HEADER SOURCE1 [SOURCE2] [SOURCE3] [...]
51 * HEADER: The destination file to create, containing the prototype information.
52 * Include this file in all of your programs that need the global functions,
53 * the best place would be the main header file for your project.
55 * SOURCE: The file(s) to create prototype information for. These files will be
56 * scanned for the "makeproto" keyword, which is case-sensitive, and will
57 * be defined to do nothing in the final compilation (this is done in the
58 * generated header file).
60 * Unlike some other similar proto-building utilities, this one can handle
61 * split lines, to make large function declarations easier. Also, there is
62 * no need to change the prototype in more than one place, you can use the
63 * "makeproto" keyword right in the definition.
66 void killcomments(char *buffer)
68 char *dest = buffer, c;
70 int c_comment = 0, cpp_comment = 0;
72 while (c = *buffer++)
74 switch (c)
76 case '/':
77 switch (*buffer)
79 case '/':
80 buffer++;
81 cpp_comment++;
82 break;
83 case '*':
84 buffer++;
85 c_comment++;
86 break;
88 case '*':
89 if ((*buffer == '/') && (c_comment > 0))
91 buffer++;
92 c_comment--;
93 *dest++ = ' ';
95 break;
96 case 10:
97 case 13:
98 cpp_comment = 0;
99 break;
101 if (!(c_comment || cpp_comment)) *dest++ = c;
103 *dest = 0;
106 void makeproto(FILE *hf, char *buffer)
108 BOOL protomade = FALSE, function;
109 char c;
110 char *brace, *equals, *semi, *start, *end, *comma;
112 killcomments(buffer);
114 while (buffer = strstr(buffer + 1, "makeproto"))
116 if ((buffer[-1] == ';') || (buffer[-1] == '*')) buffer[-1] = ' ';
118 if (isspace(buffer[-1]) && isspace(buffer[9]))
120 start = stpblk(buffer + 9);
121 brace = strchr(start, '{');
122 equals = strchr(start, '=');
123 semi = strchr(start, ';');
125 function = brace && (!semi || (brace < semi)) && (!equals || (brace < equals));
127 if (!function)
129 if (equals && (equals < semi))
131 *equals = 0;
133 else
135 *semi = 0;
137 buffer = semi;
139 strrev(start);
140 while (isspace(*start)) start++;
141 strrev(start);
143 else
145 *brace = 0;
146 buffer = brace;
148 comma = start;
150 while (*comma)
152 if (end = strchr(comma, ','))
154 comma = end;
156 else
158 comma = strchr(comma, ')');
159 if (comma)
161 while (end = strchr(comma + 1, ')'))
163 comma = end;
168 if (!comma) return;
169 c = *comma;
170 *comma = 0;
172 strrev(start);
173 while (isspace(*start)) start++;
175 #if 0
176 if (strnicmp(start, "diov", 4))
178 while (iscsym(*start)) start++;
179 while (isspace(*start)) start++;
181 strrev(start);
183 *comma++ = c;
185 if (c == ')')
187 *comma = 0;
189 else
191 end = comma;
192 while (isspace(*comma)) comma++;
193 if (comma != end)
195 *end++ = ' ';
196 if (comma != end) strcpy(end, comma);
201 protomade = TRUE;
202 FPrintf(hf, "extern %s;\n", start);
205 if (!protomade) FPrintf(hf, "/* No external prototypes defined. */\n");
208 int makeprotos(BPTR hf, char **sources)
210 struct AnchorPath *ap;
212 char *source, *buffer;
213 BPTR sf;
215 if (ap = AllocVec(sizeof(struct AnchorPath) + 512, MEMF_CLEAR))
217 ap->ap_Strlen = 511;
219 FPrintf(hf, " * Generated by MakeProto\n * ©1996 Ian J. Einman.\n */\n");
221 while (source = *sources++)
223 if (!MatchFirst(source, ap))
227 if (sf = Open(ap->ap_Buf, MODE_OLDFILE))
229 if (buffer = AllocVec(ap->ap_Info.fib_Size + 1, MEMF_CLEAR))
231 Read(sf, buffer, ap->ap_Info.fib_Size);
233 Close(sf);
234 if (buffer)
236 FPrintf(hf, "\n/* %-42s */\n\n", ap->ap_Info.fib_FileName);
237 makeproto(hf, buffer);
238 FreeVec(buffer);
241 } while (!MatchNext(ap));
243 MatchEnd(ap);
245 FreeVec(ap);
247 FPrintf(hf, "\n#define makeproto\n");
249 else
251 return 20;
253 return 0;
256 int main(void)
258 int rc = 0;
260 struct Args
262 char *Header;
263 char **Source;
264 } args;
266 struct RDArgs *ra;
267 BPTR hf;
269 args.Header=NULL;
270 args.Source=NULL;
271 if (ra = ReadArgs("HEADER/K,SOURCE/M", (LONG *)&args, NULL))
273 if(args.Source)
275 if (args.Header
276 && (hf = Open(args.Header, MODE_NEWFILE)))
278 FPrintf(hf, "/*\n * %s\n *\n", args.Header);
279 rc = makeprotos(hf, args.Source);
280 Close(hf);
282 else if ((hf = Output()))
284 FPrintf(hf, "/*\n");
285 rc = makeprotos(hf, args.Source);
287 else
289 rc = 20;
292 else
294 rc = 20;
296 FreeArgs(ra);
298 return rc;