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.
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
29 * Revision 1.1 1998/02/25 17:07:10 mlemos
36 * Source is provided for demonstration and learning purposes only;
37 * derivative products are a violation of international copyright.
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;
89 if ((*buffer
== '/') && (c_comment
> 0))
101 if (!(c_comment
|| cpp_comment
)) *dest
++ = c
;
106 void makeproto(FILE *hf
, char *buffer
)
108 BOOL protomade
= FALSE
, function
;
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
));
129 if (equals
&& (equals
< semi
))
140 while (isspace(*start
)) start
++;
152 if (end
= strchr(comma
, ','))
158 comma
= strchr(comma
, ')');
161 while (end
= strchr(comma
+ 1, ')'))
173 while (isspace(*start
)) start
++;
176 if (strnicmp(start
, "diov", 4))
178 while (iscsym(*start
)) start
++;
179 while (isspace(*start
)) start
++;
192 while (isspace(*comma
)) comma
++;
196 if (comma
!= end
) strcpy(end
, comma
);
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
;
215 if (ap
= AllocVec(sizeof(struct AnchorPath
) + 512, MEMF_CLEAR
))
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
);
236 FPrintf(hf
, "\n/* %-42s */\n\n", ap
->ap_Info
.fib_FileName
);
237 makeproto(hf
, buffer
);
241 } while (!MatchNext(ap
));
247 FPrintf(hf
, "\n#define makeproto\n");
271 if (ra
= ReadArgs("HEADER/K,SOURCE/M", (LONG
*)&args
, NULL
))
276 && (hf
= Open(args
.Header
, MODE_NEWFILE
)))
278 FPrintf(hf
, "/*\n * %s\n *\n", args
.Header
);
279 rc
= makeprotos(hf
, args
.Source
);
282 else if ((hf
= Output()))
285 rc
= makeprotos(hf
, args
.Source
);