7 #define strcasecmp _stricmp
10 typedef struct _STRING
20 int nCallingConvention
;
38 typedef int (*PFNOUTLINE
)(FILE *, EXPORT
*);
41 int giArch
= ARCH_X86
;
42 char *pszArchString
= "i386";
45 char *gpszUnderscore
= "";
47 #define DbgPrint(...) (!gbDebug || fprintf(stderr, __VA_ARGS__))
79 char* astrCallingConventions
[] =
92 return ((chr
<= ',' && chr
!= '$') ||
93 (chr
>= ':' && chr
< '?') );
97 CompareToken(const char *token
, const char *comparand
)
101 if (*token
!= *comparand
) return 0;
105 if (!IsSeparator(*token
)) return 0;
110 ScanToken(const char *token
, char chr
)
112 while (!IsSeparator(*token
))
114 if (*token
== chr
) return token
;
125 if (pc
[0] == '\n' && pc
[1] == '\r') return pc
+ 2;
126 else if (pc
[0] == '\n') return pc
+ 1;
133 TokenLength(char *pc
)
137 while (!IsSeparator(*pc
++)) length
++;
146 while (!IsSeparator(*pc
)) pc
++;
148 /* Skip white spaces */
149 while (*pc
== ' ' || *pc
== '\t') pc
++;
151 /* Check for end of line */
152 if (*pc
== '\n' || *pc
== '\r' || *pc
== 0) return 0;
154 /* Check for comment */
155 if (*pc
== '#' || *pc
== ';') return 0;
161 OutputHeader_stub(FILE *file
)
163 fprintf(file
, "/* This file is autogenerated, do not edit. */\n\n"
164 "#include <stubs.h>\n\n");
168 OutputLine_stub(FILE *file
, EXPORT
*pexp
)
172 if (pexp
->nCallingConvention
!= CC_STUB
&&
173 (pexp
->uFlags
& FL_STUB
) == 0) return 0;
175 fprintf(file
, "int ");
176 if ((giArch
== ARCH_X86
) &&
177 pexp
->nCallingConvention
== CC_STDCALL
)
179 fprintf(file
, "__stdcall ");
183 if (pexp
->strName
.buf
[0] == '?')
185 fprintf(file
, "stub_function%d(", pexp
->nNumber
);
189 fprintf(file
, "%.*s(", pexp
->strName
.len
, pexp
->strName
.buf
);
192 for (i
= 0; i
< pexp
->nArgCount
; i
++)
194 if (i
!= 0) fprintf(file
, ", ");
195 switch (pexp
->anArgs
[i
])
197 case ARG_LONG
: fprintf(file
, "long"); break;
198 case ARG_PTR
: fprintf(file
, "void*"); break;
199 case ARG_STR
: fprintf(file
, "char*"); break;
200 case ARG_WSTR
: fprintf(file
, "wchar_t*"); break;
202 case ARG_INT64
: fprintf(file
, "__int64"); break;
203 case ARG_INT128
: fprintf(file
, "__int128"); break;
204 case ARG_FLOAT
: fprintf(file
, "float"); break;
206 fprintf(file
, " a%d", i
);
208 fprintf(file
, ")\n{\n\tDbgPrint(\"WARNING: calling stub %.*s(",
209 pexp
->strName
.len
, pexp
->strName
.buf
);
211 for (i
= 0; i
< pexp
->nArgCount
; i
++)
213 if (i
!= 0) fprintf(file
, ",");
214 switch (pexp
->anArgs
[i
])
216 case ARG_LONG
: fprintf(file
, "0x%%lx"); break;
217 case ARG_PTR
: fprintf(file
, "0x%%p"); break;
218 case ARG_STR
: fprintf(file
, "'%%s'"); break;
219 case ARG_WSTR
: fprintf(file
, "'%%ws'"); break;
220 case ARG_DBL
: fprintf(file
, "%%f"); break;
221 case ARG_INT64
: fprintf(file
, "%%\"PRix64\""); break;
222 case ARG_INT128
: fprintf(file
, "%%\"PRix128\""); break;
223 case ARG_FLOAT
: fprintf(file
, "%%f"); break;
226 fprintf(file
, ")\\n\"");
228 for (i
= 0; i
< pexp
->nArgCount
; i
++)
231 switch (pexp
->anArgs
[i
])
233 case ARG_LONG
: fprintf(file
, "(long)a%d", i
); break;
234 case ARG_PTR
: fprintf(file
, "(void*)a%d", i
); break;
235 case ARG_STR
: fprintf(file
, "(char*)a%d", i
); break;
236 case ARG_WSTR
: fprintf(file
, "(wchar_t*)a%d", i
); break;
237 case ARG_DBL
: fprintf(file
, "(double)a%d", i
); break;
238 case ARG_INT64
: fprintf(file
, "(__int64)a%d", i
); break;
239 case ARG_INT128
: fprintf(file
, "(__int128)a%d", i
); break;
240 case ARG_FLOAT
: fprintf(file
, "(float)a%d", i
); break;
243 fprintf(file
, ");\n");
245 if (pexp
->nCallingConvention
== CC_STUB
)
247 fprintf(file
, "\t__wine_spec_unimplemented_stub(\"%s\", __FUNCTION__);\n", pszDllName
);
250 fprintf(file
, "\treturn 0;\n}\n\n");
256 OutputHeader_asmstub(FILE *file
, char *libname
)
258 fprintf(file
, "; File generated automatically, do not edit! \n\n");
260 if (giArch
== ARCH_X86
)
261 fprintf(file
, ".586\n.model flat\n");
263 fprintf(file
, ".code\n");
267 OutputLine_asmstub(FILE *fileDest
, EXPORT
*pexp
)
269 /* Handle autoname */
270 if (pexp
->strName
.len
== 1 && pexp
->strName
.buf
[0] == '@')
272 fprintf(fileDest
, "PUBLIC %sordinal%d\n%sordinal%d: nop\n",
273 gpszUnderscore
, pexp
->nOrdinal
, gpszUnderscore
, pexp
->nOrdinal
);
275 else if (giArch
!= ARCH_X86
)
277 fprintf(fileDest
, "PUBLIC _stub_%.*s\n_stub_%.*s: nop\n",
278 pexp
->strName
.len
, pexp
->strName
.buf
,
279 pexp
->strName
.len
, pexp
->strName
.buf
);
281 else if (pexp
->nCallingConvention
== CC_STDCALL
)
283 fprintf(fileDest
, "PUBLIC __stub_%.*s@%d\n__stub_%.*s@%d: nop\n",
284 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
,
285 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
);
287 else if (pexp
->nCallingConvention
== CC_FASTCALL
)
289 fprintf(fileDest
, "PUBLIC @_stub_%.*s@%d\n@_stub_%.*s@%d: nop\n",
290 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
,
291 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
);
293 else if (pexp
->nCallingConvention
== CC_CDECL
||
294 pexp
->nCallingConvention
== CC_STUB
)
296 fprintf(fileDest
, "PUBLIC __stub_%.*s\n__stub_%.*s: nop\n",
297 pexp
->strName
.len
, pexp
->strName
.buf
,
298 pexp
->strName
.len
, pexp
->strName
.buf
);
300 else if (pexp
->nCallingConvention
== CC_EXTERN
)
302 fprintf(fileDest
, "PUBLIC __stub_%.*s\n__stub_%.*s:\n",
303 pexp
->strName
.len
, pexp
->strName
.buf
,
304 pexp
->strName
.len
, pexp
->strName
.buf
);
311 OutputHeader_def(FILE *file
, char *libname
)
314 "; File generated automatically, do not edit!\n\n"
321 PrintName(FILE *fileDest
, EXPORT
*pexp
, PSTRING pstr
, int fDeco
)
323 const char *pcName
= pstr
->buf
;
324 int nNameLength
= pstr
->len
;
325 const char* pcDot
, *pcAt
;
327 if ((giArch
== ARCH_X86
) && fDeco
&&
328 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
329 (pexp
->nCallingConvention
== CC_FASTCALL
)))
331 /* Scan for a dll forwarding dot */
332 pcDot
= ScanToken(pcName
, '.');
335 /* First print the dll name, followed by a dot */
336 nNameLength
= pcDot
- pcName
;
337 fprintf(fileDest
, "%.*s.", nNameLength
, pcName
);
339 /* Now the actual function name */
341 nNameLength
= pexp
->strTarget
.len
- nNameLength
- 1;
344 /* Does the string already have decoration? */
345 pcAt
= ScanToken(pcName
, '@');
346 if (pcAt
&& (pcAt
< (pcName
+ nNameLength
)))
348 /* On GCC, we need to remove the leading stdcall underscore */
349 if (!gbMSComp
&& (pexp
->nCallingConvention
== CC_STDCALL
))
355 /* Print the already decorated function name */
356 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
360 /* Print the prefix, but skip it for (GCC && stdcall) */
361 if (gbMSComp
|| (pexp
->nCallingConvention
!= CC_STDCALL
))
363 fprintf(fileDest
, "%c", pexp
->nCallingConvention
== CC_FASTCALL
? '@' : '_');
366 /* Print the name with trailing decoration */
367 fprintf(fileDest
, "%.*s@%d", nNameLength
, pcName
, pexp
->nStackBytes
);
372 /* Print the undecorated function name */
373 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
378 OutputLine_def_MS(FILE *fileDest
, EXPORT
*pexp
)
380 PrintName(fileDest
, pexp
, &pexp
->strName
, 0);
384 /* Redirect to a stub function, to get the right decoration in the lib */
385 fprintf(fileDest
, "=_stub_%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
387 else if (pexp
->strTarget
.buf
)
389 if (pexp
->strName
.buf
[0] == '?')
391 fprintf(stderr
, "warning: ignoring C++ redirection %.*s -> %.*s\n",
392 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
396 fprintf(fileDest
, "=");
398 /* If the original name was decorated, use decoration in the forwarder as well */
399 if ((giArch
== ARCH_X86
) && ScanToken(pexp
->strName
.buf
, '@') &&
400 !ScanToken(pexp
->strTarget
.buf
, '@') &&
401 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
402 (pexp
->nCallingConvention
== CC_FASTCALL
)) )
404 PrintName(fileDest
, pexp
, &pexp
->strTarget
, 1);
408 /* Write the undecorated redirection name */
409 fprintf(fileDest
, "%.*s", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
413 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
414 (pexp
->strName
.buf
[0] == '?'))
416 /* C++ stubs are forwarded to C stubs */
417 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
422 OutputLine_def_GCC(FILE *fileDest
, EXPORT
*pexp
)
424 /* Print the function name, with decoration for export libs */
425 PrintName(fileDest
, pexp
, &pexp
->strName
, gbImportLib
);
426 DbgPrint("Generating def line for '%.*s'\n", pexp
->strName
.len
, pexp
->strName
.buf
);
428 /* Check if this is a forwarded export */
429 if (pexp
->strTarget
.buf
)
431 int fIsExternal
= !!ScanToken(pexp
->strTarget
.buf
, '.');
432 DbgPrint("Got redirect '%.*s'\n", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
434 /* print the target name, don't decorate if it is external */
435 fprintf(fileDest
, "=");
436 PrintName(fileDest
, pexp
, &pexp
->strTarget
, !fIsExternal
);
438 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
439 (pexp
->strName
.buf
[0] == '?'))
441 /* C++ stubs are forwarded to C stubs */
442 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
445 /* Special handling for stdcall and fastcall */
446 if ((giArch
== ARCH_X86
) &&
447 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
448 (pexp
->nCallingConvention
== CC_FASTCALL
)))
450 /* Is this the import lib? */
453 /* Is the name in the spec file decorated? */
454 const char* pcDeco
= ScanToken(pexp
->strName
.buf
, '@');
455 if (pcDeco
&& (pcDeco
< pexp
->strName
.buf
+ pexp
->strName
.len
))
457 /* Write the name including the leading @ */
458 fprintf(fileDest
, "==%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
461 else if (!pexp
->strTarget
.buf
)
463 /* Write a forwarder to the actual decorated symbol */
464 fprintf(fileDest
, "=");
465 PrintName(fileDest
, pexp
, &pexp
->strName
, 1);
471 OutputLine_def(FILE *fileDest
, EXPORT
*pexp
)
473 fprintf(fileDest
, " ");
476 OutputLine_def_MS(fileDest
, pexp
);
478 OutputLine_def_GCC(fileDest
, pexp
);
480 if (pexp
->uFlags
& FL_ORDINAL
)
482 fprintf(fileDest
, " @%d", pexp
->nOrdinal
);
485 if (pexp
->uFlags
& FL_NONAME
)
487 fprintf(fileDest
, " NONAME");
490 if (pexp
->uFlags
& FL_PRIVATE
)
492 fprintf(fileDest
, " PRIVATE");
495 if (pexp
->nCallingConvention
== CC_EXTERN
)
497 fprintf(fileDest
, " DATA");
500 fprintf(fileDest
, "\n");
506 ParseFile(char* pcStart
, FILE *fileDest
, PFNOUTLINE OutputLine
)
514 //fprintf(stderr, "info: line %d, pcStart:'%.30s'\n", nLine, pcStart);
519 for (pcLine
= pcStart
; *pcLine
; pcLine
= NextLine(pcLine
), nLine
++)
528 //if (!strncmp(pcLine, "22 stdcall @(long) MPR_Alloc",28))
531 //fprintf(stderr, "info: line %d, token:'%d, %.20s'\n",
532 // nLine, TokenLength(pcLine), pcLine);
534 /* Skip white spaces */
535 while (*pc
== ' ' || *pc
== '\t') pc
++;
537 /* Skip empty lines, stop at EOF */
538 if (*pc
== ';' || *pc
<= '#') continue;
539 if (*pc
== 0) return 0;
541 //fprintf(stderr, "info: line %d, token:'%.*s'\n",
542 // nLine, TokenLength(pc), pc);
544 /* Now we should get either an ordinal or @ */
549 exp
.nOrdinal
= atol(pc
);
550 exp
.uFlags
|= FL_ORDINAL
;
553 /* Go to next token (type) */
554 if (!(pc
= NextToken(pc
)))
556 fprintf(stderr
, "error: line %d, unexpected end of line\n", nLine
);
560 //fprintf(stderr, "info: Token:'%.*s'\n", TokenLength(pc), pc);
562 /* Now we should get the type */
563 if (CompareToken(pc
, "stdcall"))
565 exp
.nCallingConvention
= CC_STDCALL
;
567 else if (CompareToken(pc
, "cdecl") ||
568 CompareToken(pc
, "varargs"))
570 exp
.nCallingConvention
= CC_CDECL
;
572 else if (CompareToken(pc
, "fastcall"))
574 exp
.nCallingConvention
= CC_FASTCALL
;
576 else if (CompareToken(pc
, "thiscall"))
578 exp
.nCallingConvention
= CC_THISCALL
;
580 else if (CompareToken(pc
, "extern"))
582 exp
.nCallingConvention
= CC_EXTERN
;
584 else if (CompareToken(pc
, "stub"))
586 exp
.nCallingConvention
= CC_STUB
;
590 fprintf(stderr
, "error: line %d, expected callconv, got '%.*s' %d\n",
591 nLine
, TokenLength(pc
), pc
, *pc
);
595 //fprintf(stderr, "info: nCallingConvention: %d\n", exp.nCallingConvention);
597 /* Go to next token (options or name) */
598 if (!(pc
= NextToken(pc
)))
600 fprintf(stderr
, "fail2\n");
608 if (CompareToken(pc
, "-arch"))
610 /* Default to not included */
614 /* Look if we are included */
615 while (*pc
== '=' || *pc
== ',')
618 if (CompareToken(pc
, pszArchString
) ||
619 CompareToken(pc
, pszArchString2
))
624 /* Skip to next arch or end */
625 while (*pc
> ',') pc
++;
628 else if (CompareToken(pc
, "-i386"))
630 if (giArch
!= ARCH_X86
) included
= 0;
632 else if (CompareToken(pc
, "-private"))
634 exp
.uFlags
|= FL_PRIVATE
;
636 else if (CompareToken(pc
, "-noname"))
638 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
640 else if (CompareToken(pc
, "-ordinal"))
642 exp
.uFlags
|= FL_ORDINAL
;
644 else if (CompareToken(pc
, "-stub"))
646 exp
.uFlags
|= FL_STUB
;
648 else if (CompareToken(pc
, "-norelay") ||
649 CompareToken(pc
, "-register") ||
650 CompareToken(pc
, "-ret64"))
652 /* silently ignore these */
656 fprintf(stderr
, "info: ignored option: '%.*s'\n",
657 TokenLength(pc
), pc
);
660 /* Go to next token */
664 //fprintf(stderr, "info: Name:'%.10s'\n", pc);
666 /* If arch didn't match ours, skip this entry */
667 if (!included
) continue;
670 exp
.strName
.buf
= pc
;
671 exp
.strName
.len
= TokenLength(pc
);
673 /* Check for autoname */
674 if ((exp
.strName
.len
== 1) && (exp
.strName
.buf
[0] == '@'))
676 sprintf(namebuffer
, "ordinal%d", exp
.nOrdinal
);
677 exp
.strName
.len
= strlen(namebuffer
);
678 exp
.strName
.buf
= namebuffer
;
679 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
682 /* Handle parameters */
684 if (exp
.nCallingConvention
!= CC_EXTERN
&&
685 exp
.nCallingConvention
!= CC_STUB
)
687 //fprintf(stderr, "info: options:'%.10s'\n", pc);
688 /* Go to next token */
689 if (!(pc
= NextToken(pc
)))
691 fprintf(stderr
, "fail4\n");
698 fprintf(stderr
, "error: line %d, expected '('\n", nLine
);
702 /* Skip whitespaces */
703 while (*pc
== ' ' || *pc
== '\t') pc
++;
708 if (CompareToken(pc
, "long"))
710 exp
.nStackBytes
+= 4;
711 exp
.anArgs
[exp
.nArgCount
] = ARG_LONG
;
713 else if (CompareToken(pc
, "double"))
715 exp
.nStackBytes
+= 8;
716 exp
.anArgs
[exp
.nArgCount
] = ARG_DBL
;
718 else if (CompareToken(pc
, "ptr") ||
719 CompareToken(pc
, "str") ||
720 CompareToken(pc
, "wstr"))
722 exp
.nStackBytes
+= 4; // sizeof(void*) on x86
723 exp
.anArgs
[exp
.nArgCount
] = ARG_PTR
; // FIXME: handle strings
725 else if (CompareToken(pc
, "int64"))
727 exp
.nStackBytes
+= 8;
728 exp
.anArgs
[exp
.nArgCount
] = ARG_INT64
;
730 else if (CompareToken(pc
, "int128"))
732 exp
.nStackBytes
+= 16;
733 exp
.anArgs
[exp
.nArgCount
] = ARG_INT128
;
735 else if (CompareToken(pc
, "float"))
737 exp
.nStackBytes
+= 4;
738 exp
.anArgs
[exp
.nArgCount
] = ARG_FLOAT
;
741 fprintf(stderr
, "error: line %d, expected type, got: %.10s\n", nLine
, pc
);
745 /* Go to next parameter */
746 if (!(pc
= NextToken(pc
)))
748 fprintf(stderr
, "fail5\n");
756 fprintf(stderr
, "error: line %d, expected ')'\n", nLine
);
761 /* Handle special stub cases */
762 if (exp
.nCallingConvention
== CC_STUB
)
764 /* Check for c++ mangled name */
767 //printf("Found c++ mangled name...\n");
772 /* Check for stdcall name */
773 const char *p
= ScanToken(pc
, '@');
774 if (p
&& (p
- pc
< exp
.strName
.len
))
778 /* Truncate the name to before the @ */
779 exp
.strName
.len
= (int)(p
- pc
);
780 if (exp
.strName
.len
< 1)
782 fprintf(stderr
, "error, @ in line %d\n", nLine
);
785 exp
.nStackBytes
= atoi(p
+ 1);
786 exp
.nArgCount
= exp
.nStackBytes
/ 4;
787 exp
.nCallingConvention
= CC_STDCALL
;
788 exp
.uFlags
|= FL_STUB
;
789 for (i
= 0; i
< exp
.nArgCount
; i
++)
790 exp
.anArgs
[i
] = ARG_LONG
;
795 /* Get optional redirection */
799 exp
.strTarget
.buf
= pc
;
800 exp
.strTarget
.len
= TokenLength(pc
);
802 /* Check syntax (end of line) */
805 fprintf(stderr
, "error: line %d, additional tokens after ')'\n", nLine
);
811 exp
.strTarget
.buf
= 0;
812 exp
.strTarget
.len
= 0;
815 /* Check for no-name without ordinal */
816 if ((exp
.uFlags
& FL_ORDINAL
) && (exp
.nOrdinal
== -1))
818 fprintf(stderr
, "error: line %d, ordinal export without ordinal!\n", nLine
);
822 OutputLine(fileDest
, &exp
);
832 printf("syntax: spec2pdef [<options> ...] <spec file>\n"
833 "Possible options:\n"
834 " -h --help prints this screen\n"
835 " -l=<file> generates an asm lib stub\n"
836 " -d=<file> generates a def file\n"
837 " -s=<file> generates a stub file\n"
838 " --ms msvc compatibility\n"
839 " -n=<name> name of the dll\n"
840 " --implib generate a def file for an import library\n"
841 " -a=<arch> Set architecture to <arch>. (i386, x86_64, arm)\n");
844 int main(int argc
, char *argv
[])
847 char *pszSource
, *pszDefFileName
= 0, *pszStubFileName
= 0, *pszLibStubName
= 0;
859 for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
861 if ((strcasecmp(argv
[i
], "--help") == 0) ||
862 (strcasecmp(argv
[i
], "-h") == 0))
867 else if (argv
[i
][1] == 'd' && argv
[i
][2] == '=')
869 pszDefFileName
= argv
[i
] + 3;
871 else if (argv
[i
][1] == 'l' && argv
[i
][2] == '=')
873 pszLibStubName
= argv
[i
] + 3;
875 else if (argv
[i
][1] == 's' && argv
[i
][2] == '=')
877 pszStubFileName
= argv
[i
] + 3;
879 else if (argv
[i
][1] == 'n' && argv
[i
][2] == '=')
881 pszDllName
= argv
[i
] + 3;
883 else if ((strcasecmp(argv
[i
], "--implib") == 0))
887 else if ((strcasecmp(argv
[i
], "--ms") == 0))
891 else if (argv
[i
][1] == 'a' && argv
[i
][2] == '=')
893 pszArchString
= argv
[i
] + 3;
897 fprintf(stderr
, "Unrecognized option: %s\n", argv
[i
]);
902 if (strcasecmp(pszArchString
, "i386") == 0)
905 gpszUnderscore
= "_";
907 else if (strcasecmp(pszArchString
, "x86_64") == 0) giArch
= ARCH_AMD64
;
908 else if (strcasecmp(pszArchString
, "ia64") == 0) giArch
= ARCH_IA64
;
909 else if (strcasecmp(pszArchString
, "arm") == 0) giArch
= ARCH_ARM
;
910 else if (strcasecmp(pszArchString
, "ppc") == 0) giArch
= ARCH_PPC
;
912 if ((giArch
== ARCH_AMD64
) || (giArch
== ARCH_IA64
))
914 pszArchString2
= "win64";
917 pszArchString2
= "win32";
919 /* Set a default dll name */
925 p1
= strrchr(argv
[i
], '\\');
926 if (!p1
) p1
= strrchr(argv
[i
], '/');
927 p2
= p1
= p1
? p1
+ 1 : argv
[i
];
930 while (*p2
!= '.' && *p2
!= 0) p2
++;
932 if (len
>= sizeof(achDllName
) - 5)
934 fprintf(stderr
, "name too long: %s\n", p1
);
938 strncpy(achDllName
, p1
, len
);
939 strncpy(achDllName
+ len
, ".dll", sizeof(achDllName
) - len
);
940 pszDllName
= achDllName
;
943 /* Open input file argv[1] */
944 file
= fopen(argv
[i
], "r");
947 fprintf(stderr
, "error: could not open file %s ", argv
[i
]);
952 fseek(file
, 0, SEEK_END
);
953 nFileSize
= ftell(file
);
956 /* Allocate memory buffer */
957 pszSource
= malloc(nFileSize
+ 1);
964 /* Load input file into memory */
965 nFileSize
= fread(pszSource
, 1, nFileSize
, file
);
968 /* Zero terminate the source */
969 pszSource
[nFileSize
] = '\0';
973 /* Open output file */
974 file
= fopen(pszDefFileName
, "w");
977 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
981 OutputHeader_def(file
, pszDllName
);
982 result
= ParseFile(pszSource
, file
, OutputLine_def
);
988 /* Open output file */
989 file
= fopen(pszStubFileName
, "w");
992 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
996 OutputHeader_stub(file
);
997 result
= ParseFile(pszSource
, file
, OutputLine_stub
);
1003 /* Open output file */
1004 file
= fopen(pszLibStubName
, "w");
1007 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1011 OutputHeader_asmstub(file
, pszDllName
);
1012 result
= ParseFile(pszSource
, file
, OutputLine_asmstub
);
1013 fprintf(file
, "\nEND\n");