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 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
26 * Revision 1.1 1998/02/25 17:07:10 mlemos
33 * Source is provided for demonstration and learning purposes only;
34 * derivative products are a violation of international copyright.
37 #include <proto/dos.h>
39 #include <dos/dosextens.h>
40 #include <proto/exec.h>
41 #include <exec/memory.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;
86 if ((*buffer
== '/') && (c_comment
> 0))
98 if (!(c_comment
|| cpp_comment
)) *dest
++ = c
;
103 void makeproto(BPTR hf
, char *buffer
)
105 BOOL protomade
= FALSE
, function
;
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
));
126 if (equals
&& (equals
< semi
))
137 while (isspace(*start
)) start
++;
149 if (CheckSignal(SIGBREAKF_CTRL_C
)) return;
151 if (end
= strchr(comma
, ','))
157 comma
= strchr(comma
, ')');
160 while (end
= strchr(comma
+ 1, ')'))
172 while (isspace(*start
)) start
++;
173 if (strnicmp(start
, "diov", 4))
175 while (iscsym(*start
)) start
++;
176 while (isspace(*start
)) start
++;
189 while (isspace(*comma
)) comma
++;
193 if (comma
!= end
) strcpy(end
, comma
);
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
;
212 if (ap
= AllocVec(sizeof(struct AnchorPath
) + 512, MEMF_CLEAR
))
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
);
233 FPrintf(hf
, "\n/* %-42s */\n\n", ap
->ap_Info
.fib_FileName
);
234 makeproto(hf
, buffer
);
238 } while (!MatchNext(ap
));
244 FPrintf(hf
, "\n#define makeproto\n");
268 if (ra
= ReadArgs("HEADER/K,SOURCE/M", (LONG
*)&args
, NULL
))
273 && (hf
= Open(args
.Header
, MODE_NEWFILE
)))
275 FPrintf(hf
, "/*\n * %s\n *\n", args
.Header
);
276 rc
= makeprotos(hf
, args
.Source
);
279 else if ((hf
= Output()))
282 rc
= makeprotos(hf
, args
.Source
);