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
)
262 fprintf(file
, ".586\n.model flat\n.code\n");
264 else if (giArch
== ARCH_AMD64
)
266 fprintf(file
, ".code\n");
268 else if (giArch
== ARCH_ARM
)
271 " AREA |.text|,ALIGN=2,CODE,READONLY\n\n");
276 Output_symbol(FILE *fileDest
, char* pszSymbolName
)
278 if (giArch
== ARCH_ARM
)
281 " EXPORT %s [FUNC]\n%s\n",
288 "PUBLIC %s\n%s: nop\n",
295 OutputLine_asmstub(FILE *fileDest
, EXPORT
*pexp
)
297 char szNameBuffer
[128];
299 /* Handle autoname */
300 if (pexp
->strName
.len
== 1 && pexp
->strName
.buf
[0] == '@')
302 sprintf(szNameBuffer
, "%sordinal%d\n%sordinal%d: nop\n",
303 gpszUnderscore
, pexp
->nOrdinal
, gpszUnderscore
, pexp
->nOrdinal
);
305 else if (giArch
!= ARCH_X86
)
307 sprintf(szNameBuffer
, "_stub_%.*s",
308 pexp
->strName
.len
, pexp
->strName
.buf
,
309 pexp
->strName
.len
, pexp
->strName
.buf
);
311 else if (pexp
->nCallingConvention
== CC_STDCALL
)
313 sprintf(szNameBuffer
, "__stub_%.*s@%d",
314 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
,
315 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
);
317 else if (pexp
->nCallingConvention
== CC_FASTCALL
)
319 sprintf(szNameBuffer
, "@_stub_%.*s@%d",
320 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
,
321 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
);
323 else if (pexp
->nCallingConvention
== CC_CDECL
||
324 pexp
->nCallingConvention
== CC_STUB
)
326 sprintf(szNameBuffer
, "__stub_%.*s",
327 pexp
->strName
.len
, pexp
->strName
.buf
,
328 pexp
->strName
.len
, pexp
->strName
.buf
);
330 else if (pexp
->nCallingConvention
== CC_EXTERN
)
332 sprintf(szNameBuffer
, "__stub_%.*s",
333 pexp
->strName
.len
, pexp
->strName
.buf
,
334 pexp
->strName
.len
, pexp
->strName
.buf
);
337 Output_symbol(fileDest
, szNameBuffer
);
343 OutputHeader_def(FILE *file
, char *libname
)
346 "; File generated automatically, do not edit!\n\n"
353 PrintName(FILE *fileDest
, EXPORT
*pexp
, PSTRING pstr
, int fDeco
)
355 const char *pcName
= pstr
->buf
;
356 int nNameLength
= pstr
->len
;
357 const char* pcDot
, *pcAt
;
359 /* Check for non-x86 first */
360 if (giArch
!= ARCH_X86
)
362 /* Does the string already have stdcall decoration? */
363 pcAt
= ScanToken(pcName
, '@');
364 if (pcAt
&& (pcAt
< (pcName
+ nNameLength
)) && (pcName
[0] == '_'))
366 /* Skip leading underscore and remove trailing decoration */
368 nNameLength
= pcAt
- pcName
;
371 /* Print the undecorated function name */
372 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
375 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
376 (pexp
->nCallingConvention
== CC_FASTCALL
)))
378 /* Scan for a dll forwarding dot */
379 pcDot
= ScanToken(pcName
, '.');
382 /* First print the dll name, followed by a dot */
383 nNameLength
= pcDot
- pcName
;
384 fprintf(fileDest
, "%.*s.", nNameLength
, pcName
);
386 /* Now the actual function name */
388 nNameLength
= pexp
->strTarget
.len
- nNameLength
- 1;
391 /* Does the string already have decoration? */
392 pcAt
= ScanToken(pcName
, '@');
393 if (pcAt
&& (pcAt
< (pcName
+ nNameLength
)))
395 /* On GCC, we need to remove the leading stdcall underscore */
396 if (!gbMSComp
&& (pexp
->nCallingConvention
== CC_STDCALL
))
402 /* Print the already decorated function name */
403 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
407 /* Print the prefix, but skip it for (GCC && stdcall) */
408 if (gbMSComp
|| (pexp
->nCallingConvention
!= CC_STDCALL
))
410 fprintf(fileDest
, "%c", pexp
->nCallingConvention
== CC_FASTCALL
? '@' : '_');
413 /* Print the name with trailing decoration */
414 fprintf(fileDest
, "%.*s@%d", nNameLength
, pcName
, pexp
->nStackBytes
);
419 /* Print the undecorated function name */
420 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
425 OutputLine_def_MS(FILE *fileDest
, EXPORT
*pexp
)
427 PrintName(fileDest
, pexp
, &pexp
->strName
, 0);
431 /* Redirect to a stub function, to get the right decoration in the lib */
432 fprintf(fileDest
, "=_stub_%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
434 else if (pexp
->strTarget
.buf
)
436 if (pexp
->strName
.buf
[0] == '?')
438 fprintf(stderr
, "warning: ignoring C++ redirection %.*s -> %.*s\n",
439 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
443 fprintf(fileDest
, "=");
445 /* If the original name was decorated, use decoration in the forwarder as well */
446 if ((giArch
== ARCH_X86
) && ScanToken(pexp
->strName
.buf
, '@') &&
447 !ScanToken(pexp
->strTarget
.buf
, '@') &&
448 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
449 (pexp
->nCallingConvention
== CC_FASTCALL
)) )
451 PrintName(fileDest
, pexp
, &pexp
->strTarget
, 1);
455 /* Write the undecorated redirection name */
456 fprintf(fileDest
, "%.*s", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
460 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
461 (pexp
->strName
.buf
[0] == '?'))
463 /* C++ stubs are forwarded to C stubs */
464 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
469 OutputLine_def_GCC(FILE *fileDest
, EXPORT
*pexp
)
471 /* Print the function name, with decoration for export libs */
472 PrintName(fileDest
, pexp
, &pexp
->strName
, gbImportLib
);
473 DbgPrint("Generating def line for '%.*s'\n", pexp
->strName
.len
, pexp
->strName
.buf
);
475 /* Check if this is a forwarded export */
476 if (pexp
->strTarget
.buf
)
478 int fIsExternal
= !!ScanToken(pexp
->strTarget
.buf
, '.');
479 DbgPrint("Got redirect '%.*s'\n", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
481 /* print the target name, don't decorate if it is external */
482 fprintf(fileDest
, "=");
483 PrintName(fileDest
, pexp
, &pexp
->strTarget
, !fIsExternal
);
485 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
486 (pexp
->strName
.buf
[0] == '?'))
488 /* C++ stubs are forwarded to C stubs */
489 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
492 /* Special handling for stdcall and fastcall */
493 if ((giArch
== ARCH_X86
) &&
494 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
495 (pexp
->nCallingConvention
== CC_FASTCALL
)))
497 /* Is this the import lib? */
500 /* Is the name in the spec file decorated? */
501 const char* pcDeco
= ScanToken(pexp
->strName
.buf
, '@');
502 if (pcDeco
&& (pcDeco
< pexp
->strName
.buf
+ pexp
->strName
.len
))
504 /* Write the name including the leading @ */
505 fprintf(fileDest
, "==%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
508 else if (!pexp
->strTarget
.buf
)
510 /* Write a forwarder to the actual decorated symbol */
511 fprintf(fileDest
, "=");
512 PrintName(fileDest
, pexp
, &pexp
->strName
, 1);
518 OutputLine_def(FILE *fileDest
, EXPORT
*pexp
)
520 DbgPrint("OutputLine_def: '%.*s'...\n", pexp
->strName
.len
, pexp
->strName
.buf
);
521 fprintf(fileDest
, " ");
524 OutputLine_def_MS(fileDest
, pexp
);
526 OutputLine_def_GCC(fileDest
, pexp
);
528 if (pexp
->uFlags
& FL_ORDINAL
)
530 fprintf(fileDest
, " @%d", pexp
->nOrdinal
);
533 if (pexp
->uFlags
& FL_NONAME
)
535 fprintf(fileDest
, " NONAME");
538 if (pexp
->uFlags
& FL_PRIVATE
)
540 fprintf(fileDest
, " PRIVATE");
543 if (pexp
->nCallingConvention
== CC_EXTERN
)
545 fprintf(fileDest
, " DATA");
548 fprintf(fileDest
, "\n");
554 ParseFile(char* pcStart
, FILE *fileDest
, PFNOUTLINE OutputLine
)
562 //fprintf(stderr, "info: line %d, pcStart:'%.30s'\n", nLine, pcStart);
567 for (pcLine
= pcStart
; *pcLine
; pcLine
= NextLine(pcLine
), nLine
++)
576 //if (!strncmp(pcLine, "22 stdcall @(long) MPR_Alloc",28))
579 //fprintf(stderr, "info: line %d, token:'%d, %.20s'\n",
580 // nLine, TokenLength(pcLine), pcLine);
582 /* Skip white spaces */
583 while (*pc
== ' ' || *pc
== '\t') pc
++;
585 /* Skip empty lines, stop at EOF */
586 if (*pc
== ';' || *pc
<= '#') continue;
587 if (*pc
== 0) return 0;
589 //fprintf(stderr, "info: line %d, token:'%.*s'\n",
590 // nLine, TokenLength(pc), pc);
592 /* Now we should get either an ordinal or @ */
597 exp
.nOrdinal
= atol(pc
);
598 /* The import lib should contain the ordinal only if -ordinal was specified */
600 exp
.uFlags
|= FL_ORDINAL
;
603 /* Go to next token (type) */
604 if (!(pc
= NextToken(pc
)))
606 fprintf(stderr
, "error: line %d, unexpected end of line\n", nLine
);
610 //fprintf(stderr, "info: Token:'%.*s'\n", TokenLength(pc), pc);
612 /* Now we should get the type */
613 if (CompareToken(pc
, "stdcall"))
615 exp
.nCallingConvention
= CC_STDCALL
;
617 else if (CompareToken(pc
, "cdecl") ||
618 CompareToken(pc
, "varargs"))
620 exp
.nCallingConvention
= CC_CDECL
;
622 else if (CompareToken(pc
, "fastcall"))
624 exp
.nCallingConvention
= CC_FASTCALL
;
626 else if (CompareToken(pc
, "thiscall"))
628 exp
.nCallingConvention
= CC_THISCALL
;
630 else if (CompareToken(pc
, "extern"))
632 exp
.nCallingConvention
= CC_EXTERN
;
634 else if (CompareToken(pc
, "stub"))
636 exp
.nCallingConvention
= CC_STUB
;
640 fprintf(stderr
, "error: line %d, expected callconv, got '%.*s' %d\n",
641 nLine
, TokenLength(pc
), pc
, *pc
);
645 //fprintf(stderr, "info: nCallingConvention: %d\n", exp.nCallingConvention);
647 /* Go to next token (options or name) */
648 if (!(pc
= NextToken(pc
)))
650 fprintf(stderr
, "fail2\n");
658 if (CompareToken(pc
, "-arch"))
660 /* Default to not included */
664 /* Look if we are included */
665 while (*pc
== '=' || *pc
== ',')
668 if (CompareToken(pc
, pszArchString
) ||
669 CompareToken(pc
, pszArchString2
))
674 /* Skip to next arch or end */
675 while (*pc
> ',') pc
++;
678 else if (CompareToken(pc
, "-i386"))
680 if (giArch
!= ARCH_X86
) included
= 0;
682 else if (CompareToken(pc
, "-private"))
684 exp
.uFlags
|= FL_PRIVATE
;
686 else if (CompareToken(pc
, "-noname"))
688 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
690 else if (CompareToken(pc
, "-ordinal"))
692 exp
.uFlags
|= FL_ORDINAL
;
693 /* GCC doesn't automatically import by ordinal if an ordinal
694 * is found in the def file. Force it. */
695 if (gbImportLib
&& !gbMSComp
)
696 exp
.uFlags
|= FL_NONAME
;
698 else if (CompareToken(pc
, "-stub"))
700 exp
.uFlags
|= FL_STUB
;
702 else if (CompareToken(pc
, "-norelay") ||
703 CompareToken(pc
, "-register") ||
704 CompareToken(pc
, "-ret64"))
706 /* silently ignore these */
710 fprintf(stderr
, "info: ignored option: '%.*s'\n",
711 TokenLength(pc
), pc
);
714 /* Go to next token */
718 //fprintf(stderr, "info: Name:'%.10s'\n", pc);
720 /* If arch didn't match ours, skip this entry */
721 if (!included
) continue;
724 exp
.strName
.buf
= pc
;
725 exp
.strName
.len
= TokenLength(pc
);
726 DbgPrint("Got name: '%.*s'\n", exp
.strName
.len
, exp
.strName
.buf
);
728 /* Check for autoname */
729 if ((exp
.strName
.len
== 1) && (exp
.strName
.buf
[0] == '@'))
731 sprintf(namebuffer
, "ordinal%d", exp
.nOrdinal
);
732 exp
.strName
.len
= strlen(namebuffer
);
733 exp
.strName
.buf
= namebuffer
;
734 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
737 /* Handle parameters */
739 if (exp
.nCallingConvention
!= CC_EXTERN
&&
740 exp
.nCallingConvention
!= CC_STUB
)
742 /* Go to next token */
743 if (!(pc
= NextToken(pc
)))
745 fprintf(stderr
, "fail4\n");
752 fprintf(stderr
, "error: line %d, expected '('\n", nLine
);
756 /* Skip whitespaces */
757 while (*pc
== ' ' || *pc
== '\t') pc
++;
762 if (CompareToken(pc
, "long"))
764 exp
.nStackBytes
+= 4;
765 exp
.anArgs
[exp
.nArgCount
] = ARG_LONG
;
767 else if (CompareToken(pc
, "double"))
769 exp
.nStackBytes
+= 8;
770 exp
.anArgs
[exp
.nArgCount
] = ARG_DBL
;
772 else if (CompareToken(pc
, "ptr") ||
773 CompareToken(pc
, "str") ||
774 CompareToken(pc
, "wstr"))
776 exp
.nStackBytes
+= 4; // sizeof(void*) on x86
777 exp
.anArgs
[exp
.nArgCount
] = ARG_PTR
; // FIXME: handle strings
779 else if (CompareToken(pc
, "int64"))
781 exp
.nStackBytes
+= 8;
782 exp
.anArgs
[exp
.nArgCount
] = ARG_INT64
;
784 else if (CompareToken(pc
, "int128"))
786 exp
.nStackBytes
+= 16;
787 exp
.anArgs
[exp
.nArgCount
] = ARG_INT128
;
789 else if (CompareToken(pc
, "float"))
791 exp
.nStackBytes
+= 4;
792 exp
.anArgs
[exp
.nArgCount
] = ARG_FLOAT
;
795 fprintf(stderr
, "error: line %d, expected type, got: %.10s\n", nLine
, pc
);
799 /* Go to next parameter */
800 if (!(pc
= NextToken(pc
)))
802 fprintf(stderr
, "fail5\n");
810 fprintf(stderr
, "error: line %d, expected ')'\n", nLine
);
815 /* Handle special stub cases */
816 if (exp
.nCallingConvention
== CC_STUB
)
818 /* Check for c++ mangled name */
821 //printf("Found c++ mangled name...\n");
826 /* Check for stdcall name */
827 const char *p
= ScanToken(pc
, '@');
828 if (p
&& (p
- pc
< exp
.strName
.len
))
832 /* Truncate the name to before the @ */
833 exp
.strName
.len
= (int)(p
- pc
);
834 if (exp
.strName
.len
< 1)
836 fprintf(stderr
, "error, @ in line %d\n", nLine
);
839 exp
.nStackBytes
= atoi(p
+ 1);
840 exp
.nArgCount
= exp
.nStackBytes
/ 4;
841 exp
.nCallingConvention
= CC_STDCALL
;
842 exp
.uFlags
|= FL_STUB
;
843 for (i
= 0; i
< exp
.nArgCount
; i
++)
844 exp
.anArgs
[i
] = ARG_LONG
;
849 /* Get optional redirection */
853 exp
.strTarget
.buf
= pc
;
854 exp
.strTarget
.len
= TokenLength(pc
);
856 /* Check syntax (end of line) */
859 fprintf(stderr
, "error: line %d, additional tokens after ')'\n", nLine
);
865 exp
.strTarget
.buf
= 0;
866 exp
.strTarget
.len
= 0;
869 /* Check for no-name without ordinal */
870 if ((exp
.uFlags
& FL_ORDINAL
) && (exp
.nOrdinal
== -1))
872 fprintf(stderr
, "error: line %d, ordinal export without ordinal!\n", nLine
);
876 OutputLine(fileDest
, &exp
);
886 printf("syntax: spec2pdef [<options> ...] <spec file>\n"
887 "Possible options:\n"
888 " -h --help prints this screen\n"
889 " -l=<file> generates an asm lib stub\n"
890 " -d=<file> generates a def file\n"
891 " -s=<file> generates a stub file\n"
892 " --ms msvc compatibility\n"
893 " -n=<name> name of the dll\n"
894 " --implib generate a def file for an import library\n"
895 " -a=<arch> Set architecture to <arch>. (i386, x86_64, arm)\n");
898 int main(int argc
, char *argv
[])
901 char *pszSource
, *pszDefFileName
= 0, *pszStubFileName
= 0, *pszLibStubName
= 0;
913 for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
915 if ((strcasecmp(argv
[i
], "--help") == 0) ||
916 (strcasecmp(argv
[i
], "-h") == 0))
921 else if (argv
[i
][1] == 'd' && argv
[i
][2] == '=')
923 pszDefFileName
= argv
[i
] + 3;
925 else if (argv
[i
][1] == 'l' && argv
[i
][2] == '=')
927 pszLibStubName
= argv
[i
] + 3;
929 else if (argv
[i
][1] == 's' && argv
[i
][2] == '=')
931 pszStubFileName
= argv
[i
] + 3;
933 else if (argv
[i
][1] == 'n' && argv
[i
][2] == '=')
935 pszDllName
= argv
[i
] + 3;
937 else if ((strcasecmp(argv
[i
], "--implib") == 0))
941 else if ((strcasecmp(argv
[i
], "--ms") == 0))
945 else if (argv
[i
][1] == 'a' && argv
[i
][2] == '=')
947 pszArchString
= argv
[i
] + 3;
951 fprintf(stderr
, "Unrecognized option: %s\n", argv
[i
]);
956 if (strcasecmp(pszArchString
, "i386") == 0)
959 gpszUnderscore
= "_";
961 else if (strcasecmp(pszArchString
, "x86_64") == 0) giArch
= ARCH_AMD64
;
962 else if (strcasecmp(pszArchString
, "ia64") == 0) giArch
= ARCH_IA64
;
963 else if (strcasecmp(pszArchString
, "arm") == 0) giArch
= ARCH_ARM
;
964 else if (strcasecmp(pszArchString
, "ppc") == 0) giArch
= ARCH_PPC
;
966 if ((giArch
== ARCH_AMD64
) || (giArch
== ARCH_IA64
))
968 pszArchString2
= "win64";
971 pszArchString2
= "win32";
973 /* Set a default dll name */
979 p1
= strrchr(argv
[i
], '\\');
980 if (!p1
) p1
= strrchr(argv
[i
], '/');
981 p2
= p1
= p1
? p1
+ 1 : argv
[i
];
984 while (*p2
!= '.' && *p2
!= 0) p2
++;
986 if (len
>= sizeof(achDllName
) - 5)
988 fprintf(stderr
, "name too long: %s\n", p1
);
992 strncpy(achDllName
, p1
, len
);
993 strncpy(achDllName
+ len
, ".dll", sizeof(achDllName
) - len
);
994 pszDllName
= achDllName
;
997 /* Open input file argv[1] */
998 file
= fopen(argv
[i
], "r");
1001 fprintf(stderr
, "error: could not open file %s ", argv
[i
]);
1006 fseek(file
, 0, SEEK_END
);
1007 nFileSize
= ftell(file
);
1010 /* Allocate memory buffer */
1011 pszSource
= malloc(nFileSize
+ 1);
1018 /* Load input file into memory */
1019 nFileSize
= fread(pszSource
, 1, nFileSize
, file
);
1022 /* Zero terminate the source */
1023 pszSource
[nFileSize
] = '\0';
1027 /* Open output file */
1028 file
= fopen(pszDefFileName
, "w");
1031 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1035 OutputHeader_def(file
, pszDllName
);
1036 result
= ParseFile(pszSource
, file
, OutputLine_def
);
1040 if (pszStubFileName
)
1042 /* Open output file */
1043 file
= fopen(pszStubFileName
, "w");
1046 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1050 OutputHeader_stub(file
);
1051 result
= ParseFile(pszSource
, file
, OutputLine_stub
);
1057 /* Open output file */
1058 file
= fopen(pszLibStubName
, "w");
1061 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1065 OutputHeader_asmstub(file
, pszDllName
);
1066 result
= ParseFile(pszSource
, file
, OutputLine_asmstub
);
1067 fprintf(file
, "\n END\n");