]>
git.saurik.com Git - apple/boot.git/blob - i386/util/sig.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1993 NeXT Computer, Inc.
26 * All rights reserved.
30 * Standalone Interface Generator
32 * Input file format: a series of lines of the form:
36 * <function declaration> <arg list> ;
39 * void *malloc(int len) len;
41 * Lines starting with '#' are passed through unchanged.
42 * Lines starting with '/' are ignored.
54 typedef enum {NO
=0, YES
=1} BOOL
;
55 #define strdup(str) ((char *)strcpy(malloc(strlen(str)+1),str))
74 int lineNumber
, outputNumber
;
78 char *stringToLower(char *string
)
80 char *new = strdup(string
);
88 char *stringToUpper(char *string
)
90 char *new = strdup(string
);
101 if (isalnum(c
) || c
== '_')
108 outputLine(char *decl
, char *function
, char *args
, char *arglist
)
110 if (which
== table
) {
111 static int struct_started
;
112 if (struct_started
== 0) {
113 fprintf(ofile
, "unsigned long (*%s_functions[])() = {\n",
117 fprintf(ofile
, "(unsigned long (*)())_%s,\t\t/* %d */\n", function
, outputNumber
);
121 fprintf(ofile
, "#define %s _%s\n",function
,function
);
124 if (which
== internal
) {
125 fprintf(ofile
, "extern %s _%s(%s);\n", decl
, function
, args
);
128 if (which
== external
) {
129 fprintf(ofile
, "#define %s_%s_FN %d\n",
130 moduleNameCaps
, function
, outputNumber
);
132 "static inline %s %s ( %s ) {\n", decl
, function
, args
);
134 "\treturn (%s)(*%s_FN[%d])(%s);\n",
135 decl
, moduleNameCaps
, outputNumber
, arglist
);
136 fprintf(ofile
, "}\n");
142 parseLine(char *line
)
144 char *paren
, *parenEnd
;
145 char *ident
, *identEnd
;
146 char *arglist
, *arglistEnd
;
149 paren
= strchr(line
, '(');
152 for (identEnd
= paren
- 1; !isIdentifier(*identEnd
); identEnd
--)
154 for (ident
= identEnd
; isIdentifier(*ident
); ident
--)
159 parenEnd
= strchr(paren
, ')');
160 if (parenEnd
== NULL
)
164 arglist
= parenEnd
+ 1;
165 while (isspace(*arglist
))
167 arglistEnd
= strchr(arglist
, ';');
168 if (arglistEnd
== NULL
)
172 function
= strdup(ident
);
174 outputLine(line
, function
, paren
, arglist
);
179 fprintf(stderr
, "Syntax error at line %d\n",lineNumber
);
184 getLineThru(FILE *file
, char *linebuf
, char stop
, int len
)
190 while (((c
= fgetc(file
)) != EOF
) && len
) {
194 if (c
== '\n') lineNumber
++;
211 skipWhitespace(FILE *file
)
215 while ((c
= fgetc(file
)) != EOF
&& isspace(c
))
216 if (c
== '\n') ++lineNumber
;
221 parseFile(FILE *file
)
226 line
= malloc(MAXLINE
+1);
229 skipWhitespace(file
);
231 while (!feof(file
)) {
233 if (c
== '#' || c
== '/') {
234 len
= getLineThru(file
, line
, '\n', MAXLINE
);
236 fprintf(ofile
, line
);
238 len
= getLineThru(file
, line
, ';', MAXLINE
);
241 skipWhitespace(file
);
247 main(int argc
, char **argv
)
253 char ofilename
[MAXPATHLEN
];
254 char *ifile
, *odir
= ".";
256 while ((c
= getopt(argc
, argv
, "d:n:")) != EOF
)
263 moduleNameCaps
= stringToUpper(moduleName
);
271 if ((ifile
= argv
[optind
]) != NULL
) {
272 file
= fopen(argv
[optind
], "r");
278 fprintf(stderr
,"No input file specified\n");
282 if (moduleName
== NULL
) {
285 newName
= strchr(ifile
, '/');
288 dot
= strchr(newName
, '.');
290 dot
= &newName
[strlen(newName
)];
292 moduleName
= (char *)malloc(len
+ 1);
293 strncpy(moduleName
, newName
, len
);
294 moduleName
[len
] = '\0';
295 moduleNameCaps
= stringToUpper(moduleName
);
298 for (which
= external
; which
<= defs
; which
++) {
302 sprintf(ofilename
, "%s/%s%s", odir
, moduleName
, osuffix
[which
]);
303 ofile
= fopen((const char *)ofilename
, "w");
305 fprintf(stderr
,"error opening output file %s\n",ofilename
);
309 if (which
== table
) {
310 fprintf(ofile
, "#define %s_TABLE 1\n", moduleNameCaps
);
311 fprintf(ofile
, "#import \"%s_internal.h\"\n",moduleName
);
314 if (which
== internal
) {
315 fprintf(ofile
, "#define %s_INTERNAL 1\n", moduleNameCaps
);
319 fprintf(ofile
, "#define %s_DEFS 1\n", moduleNameCaps
);
322 if (which
== external
) {
323 fprintf(ofile
, "#import \"memory.h\"\n");
324 fprintf(ofile
, "#define %s_EXTERNAL 1\n", moduleNameCaps
);
326 "#define %s_FN (*(unsigned long (***)())%s_TABLE_POINTER)\n\n",
327 moduleNameCaps
, moduleNameCaps
);
331 if (which
== table
) {
332 fprintf(ofile
, "};\n\n");