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");
264 else if (giArch
== ARCH_ARM
)
266 fprintf(file
, "#include <kxarm.h>\n TEXTAREA\n");
269 fprintf(file
, ".code\n");
273 OutputLine_asmstub(FILE *fileDest
, EXPORT
*pexp
)
275 /* Handle autoname */
276 if (pexp
->strName
.len
== 1 && pexp
->strName
.buf
[0] == '@')
278 fprintf(fileDest
, "PUBLIC %sordinal%d\n%sordinal%d: nop\n",
279 gpszUnderscore
, pexp
->nOrdinal
, gpszUnderscore
, pexp
->nOrdinal
);
281 else if (giArch
!= ARCH_X86
)
283 fprintf(fileDest
, "PUBLIC _stub_%.*s\n_stub_%.*s: nop\n",
284 pexp
->strName
.len
, pexp
->strName
.buf
,
285 pexp
->strName
.len
, pexp
->strName
.buf
);
287 else if (pexp
->nCallingConvention
== CC_STDCALL
)
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_FASTCALL
)
295 fprintf(fileDest
, "PUBLIC @_stub_%.*s@%d\n@_stub_%.*s@%d: nop\n",
296 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
,
297 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->nStackBytes
);
299 else if (pexp
->nCallingConvention
== CC_CDECL
||
300 pexp
->nCallingConvention
== CC_STUB
)
302 fprintf(fileDest
, "PUBLIC __stub_%.*s\n__stub_%.*s: nop\n",
303 pexp
->strName
.len
, pexp
->strName
.buf
,
304 pexp
->strName
.len
, pexp
->strName
.buf
);
306 else if (pexp
->nCallingConvention
== CC_EXTERN
)
308 fprintf(fileDest
, "PUBLIC __stub_%.*s\n__stub_%.*s:\n",
309 pexp
->strName
.len
, pexp
->strName
.buf
,
310 pexp
->strName
.len
, pexp
->strName
.buf
);
317 OutputHeader_def(FILE *file
, char *libname
)
320 "; File generated automatically, do not edit!\n\n"
327 PrintName(FILE *fileDest
, EXPORT
*pexp
, PSTRING pstr
, int fDeco
)
329 const char *pcName
= pstr
->buf
;
330 int nNameLength
= pstr
->len
;
331 const char* pcDot
, *pcAt
;
333 /* Check for non-x86 first */
334 if (giArch
!= ARCH_X86
)
336 /* Does the string already have stdcall decoration? */
337 pcAt
= ScanToken(pcName
, '@');
338 if (pcAt
&& (pcAt
< (pcName
+ nNameLength
)) && (pcName
[0] == '_'))
340 /* Skip leading underscore and remove trailing decoration */
342 nNameLength
= pcAt
- pcName
;
345 /* Print the undecorated function name */
346 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
349 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
350 (pexp
->nCallingConvention
== CC_FASTCALL
)))
352 /* Scan for a dll forwarding dot */
353 pcDot
= ScanToken(pcName
, '.');
356 /* First print the dll name, followed by a dot */
357 nNameLength
= pcDot
- pcName
;
358 fprintf(fileDest
, "%.*s.", nNameLength
, pcName
);
360 /* Now the actual function name */
362 nNameLength
= pexp
->strTarget
.len
- nNameLength
- 1;
365 /* Does the string already have decoration? */
366 pcAt
= ScanToken(pcName
, '@');
367 if (pcAt
&& (pcAt
< (pcName
+ nNameLength
)))
369 /* On GCC, we need to remove the leading stdcall underscore */
370 if (!gbMSComp
&& (pexp
->nCallingConvention
== CC_STDCALL
))
376 /* Print the already decorated function name */
377 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
381 /* Print the prefix, but skip it for (GCC && stdcall) */
382 if (gbMSComp
|| (pexp
->nCallingConvention
!= CC_STDCALL
))
384 fprintf(fileDest
, "%c", pexp
->nCallingConvention
== CC_FASTCALL
? '@' : '_');
387 /* Print the name with trailing decoration */
388 fprintf(fileDest
, "%.*s@%d", nNameLength
, pcName
, pexp
->nStackBytes
);
393 /* Print the undecorated function name */
394 fprintf(fileDest
, "%.*s", nNameLength
, pcName
);
399 OutputLine_def_MS(FILE *fileDest
, EXPORT
*pexp
)
401 PrintName(fileDest
, pexp
, &pexp
->strName
, 0);
405 /* Redirect to a stub function, to get the right decoration in the lib */
406 fprintf(fileDest
, "=_stub_%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
408 else if (pexp
->strTarget
.buf
)
410 if (pexp
->strName
.buf
[0] == '?')
412 fprintf(stderr
, "warning: ignoring C++ redirection %.*s -> %.*s\n",
413 pexp
->strName
.len
, pexp
->strName
.buf
, pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
417 fprintf(fileDest
, "=");
419 /* If the original name was decorated, use decoration in the forwarder as well */
420 if ((giArch
== ARCH_X86
) && ScanToken(pexp
->strName
.buf
, '@') &&
421 !ScanToken(pexp
->strTarget
.buf
, '@') &&
422 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
423 (pexp
->nCallingConvention
== CC_FASTCALL
)) )
425 PrintName(fileDest
, pexp
, &pexp
->strTarget
, 1);
429 /* Write the undecorated redirection name */
430 fprintf(fileDest
, "%.*s", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
434 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
435 (pexp
->strName
.buf
[0] == '?'))
437 /* C++ stubs are forwarded to C stubs */
438 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
443 OutputLine_def_GCC(FILE *fileDest
, EXPORT
*pexp
)
445 /* Print the function name, with decoration for export libs */
446 PrintName(fileDest
, pexp
, &pexp
->strName
, gbImportLib
);
447 DbgPrint("Generating def line for '%.*s'\n", pexp
->strName
.len
, pexp
->strName
.buf
);
449 /* Check if this is a forwarded export */
450 if (pexp
->strTarget
.buf
)
452 int fIsExternal
= !!ScanToken(pexp
->strTarget
.buf
, '.');
453 DbgPrint("Got redirect '%.*s'\n", pexp
->strTarget
.len
, pexp
->strTarget
.buf
);
455 /* print the target name, don't decorate if it is external */
456 fprintf(fileDest
, "=");
457 PrintName(fileDest
, pexp
, &pexp
->strTarget
, !fIsExternal
);
459 else if (((pexp
->uFlags
& FL_STUB
) || (pexp
->nCallingConvention
== CC_STUB
)) &&
460 (pexp
->strName
.buf
[0] == '?'))
462 /* C++ stubs are forwarded to C stubs */
463 fprintf(fileDest
, "=stub_function%d", pexp
->nNumber
);
466 /* Special handling for stdcall and fastcall */
467 if ((giArch
== ARCH_X86
) &&
468 ((pexp
->nCallingConvention
== CC_STDCALL
) ||
469 (pexp
->nCallingConvention
== CC_FASTCALL
)))
471 /* Is this the import lib? */
474 /* Is the name in the spec file decorated? */
475 const char* pcDeco
= ScanToken(pexp
->strName
.buf
, '@');
476 if (pcDeco
&& (pcDeco
< pexp
->strName
.buf
+ pexp
->strName
.len
))
478 /* Write the name including the leading @ */
479 fprintf(fileDest
, "==%.*s", pexp
->strName
.len
, pexp
->strName
.buf
);
482 else if (!pexp
->strTarget
.buf
)
484 /* Write a forwarder to the actual decorated symbol */
485 fprintf(fileDest
, "=");
486 PrintName(fileDest
, pexp
, &pexp
->strName
, 1);
492 OutputLine_def(FILE *fileDest
, EXPORT
*pexp
)
494 DbgPrint("OutputLine_def: '%.*s'...\n", pexp
->strName
.len
, pexp
->strName
.buf
);
495 fprintf(fileDest
, " ");
498 OutputLine_def_MS(fileDest
, pexp
);
500 OutputLine_def_GCC(fileDest
, pexp
);
502 if (pexp
->uFlags
& FL_ORDINAL
)
504 fprintf(fileDest
, " @%d", pexp
->nOrdinal
);
507 if (pexp
->uFlags
& FL_NONAME
)
509 fprintf(fileDest
, " NONAME");
512 if (pexp
->uFlags
& FL_PRIVATE
)
514 fprintf(fileDest
, " PRIVATE");
517 if (pexp
->nCallingConvention
== CC_EXTERN
)
519 fprintf(fileDest
, " DATA");
522 fprintf(fileDest
, "\n");
528 ParseFile(char* pcStart
, FILE *fileDest
, PFNOUTLINE OutputLine
)
536 //fprintf(stderr, "info: line %d, pcStart:'%.30s'\n", nLine, pcStart);
541 for (pcLine
= pcStart
; *pcLine
; pcLine
= NextLine(pcLine
), nLine
++)
550 //if (!strncmp(pcLine, "22 stdcall @(long) MPR_Alloc",28))
553 //fprintf(stderr, "info: line %d, token:'%d, %.20s'\n",
554 // nLine, TokenLength(pcLine), pcLine);
556 /* Skip white spaces */
557 while (*pc
== ' ' || *pc
== '\t') pc
++;
559 /* Skip empty lines, stop at EOF */
560 if (*pc
== ';' || *pc
<= '#') continue;
561 if (*pc
== 0) return 0;
563 //fprintf(stderr, "info: line %d, token:'%.*s'\n",
564 // nLine, TokenLength(pc), pc);
566 /* Now we should get either an ordinal or @ */
571 exp
.nOrdinal
= atol(pc
);
572 /* The import lib should contain the ordinal only if -ordinal was specified */
574 exp
.uFlags
|= FL_ORDINAL
;
577 /* Go to next token (type) */
578 if (!(pc
= NextToken(pc
)))
580 fprintf(stderr
, "error: line %d, unexpected end of line\n", nLine
);
584 //fprintf(stderr, "info: Token:'%.*s'\n", TokenLength(pc), pc);
586 /* Now we should get the type */
587 if (CompareToken(pc
, "stdcall"))
589 exp
.nCallingConvention
= CC_STDCALL
;
591 else if (CompareToken(pc
, "cdecl") ||
592 CompareToken(pc
, "varargs"))
594 exp
.nCallingConvention
= CC_CDECL
;
596 else if (CompareToken(pc
, "fastcall"))
598 exp
.nCallingConvention
= CC_FASTCALL
;
600 else if (CompareToken(pc
, "thiscall"))
602 exp
.nCallingConvention
= CC_THISCALL
;
604 else if (CompareToken(pc
, "extern"))
606 exp
.nCallingConvention
= CC_EXTERN
;
608 else if (CompareToken(pc
, "stub"))
610 exp
.nCallingConvention
= CC_STUB
;
614 fprintf(stderr
, "error: line %d, expected callconv, got '%.*s' %d\n",
615 nLine
, TokenLength(pc
), pc
, *pc
);
619 //fprintf(stderr, "info: nCallingConvention: %d\n", exp.nCallingConvention);
621 /* Go to next token (options or name) */
622 if (!(pc
= NextToken(pc
)))
624 fprintf(stderr
, "fail2\n");
632 if (CompareToken(pc
, "-arch"))
634 /* Default to not included */
638 /* Look if we are included */
639 while (*pc
== '=' || *pc
== ',')
642 if (CompareToken(pc
, pszArchString
) ||
643 CompareToken(pc
, pszArchString2
))
648 /* Skip to next arch or end */
649 while (*pc
> ',') pc
++;
652 else if (CompareToken(pc
, "-i386"))
654 if (giArch
!= ARCH_X86
) included
= 0;
656 else if (CompareToken(pc
, "-private"))
658 exp
.uFlags
|= FL_PRIVATE
;
660 else if (CompareToken(pc
, "-noname"))
662 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
664 else if (CompareToken(pc
, "-ordinal"))
666 exp
.uFlags
|= FL_ORDINAL
;
668 else if (CompareToken(pc
, "-stub"))
670 exp
.uFlags
|= FL_STUB
;
672 else if (CompareToken(pc
, "-norelay") ||
673 CompareToken(pc
, "-register") ||
674 CompareToken(pc
, "-ret64"))
676 /* silently ignore these */
680 fprintf(stderr
, "info: ignored option: '%.*s'\n",
681 TokenLength(pc
), pc
);
684 /* Go to next token */
688 //fprintf(stderr, "info: Name:'%.10s'\n", pc);
690 /* If arch didn't match ours, skip this entry */
691 if (!included
) continue;
694 exp
.strName
.buf
= pc
;
695 exp
.strName
.len
= TokenLength(pc
);
696 DbgPrint("Got name: '%.*s'\n", exp
.strName
.len
, exp
.strName
.buf
);
698 /* Check for autoname */
699 if ((exp
.strName
.len
== 1) && (exp
.strName
.buf
[0] == '@'))
701 sprintf(namebuffer
, "ordinal%d", exp
.nOrdinal
);
702 exp
.strName
.len
= strlen(namebuffer
);
703 exp
.strName
.buf
= namebuffer
;
704 exp
.uFlags
|= FL_ORDINAL
| FL_NONAME
;
707 /* Handle parameters */
709 if (exp
.nCallingConvention
!= CC_EXTERN
&&
710 exp
.nCallingConvention
!= CC_STUB
)
712 /* Go to next token */
713 if (!(pc
= NextToken(pc
)))
715 fprintf(stderr
, "fail4\n");
722 fprintf(stderr
, "error: line %d, expected '('\n", nLine
);
726 /* Skip whitespaces */
727 while (*pc
== ' ' || *pc
== '\t') pc
++;
732 if (CompareToken(pc
, "long"))
734 exp
.nStackBytes
+= 4;
735 exp
.anArgs
[exp
.nArgCount
] = ARG_LONG
;
737 else if (CompareToken(pc
, "double"))
739 exp
.nStackBytes
+= 8;
740 exp
.anArgs
[exp
.nArgCount
] = ARG_DBL
;
742 else if (CompareToken(pc
, "ptr") ||
743 CompareToken(pc
, "str") ||
744 CompareToken(pc
, "wstr"))
746 exp
.nStackBytes
+= 4; // sizeof(void*) on x86
747 exp
.anArgs
[exp
.nArgCount
] = ARG_PTR
; // FIXME: handle strings
749 else if (CompareToken(pc
, "int64"))
751 exp
.nStackBytes
+= 8;
752 exp
.anArgs
[exp
.nArgCount
] = ARG_INT64
;
754 else if (CompareToken(pc
, "int128"))
756 exp
.nStackBytes
+= 16;
757 exp
.anArgs
[exp
.nArgCount
] = ARG_INT128
;
759 else if (CompareToken(pc
, "float"))
761 exp
.nStackBytes
+= 4;
762 exp
.anArgs
[exp
.nArgCount
] = ARG_FLOAT
;
765 fprintf(stderr
, "error: line %d, expected type, got: %.10s\n", nLine
, pc
);
769 /* Go to next parameter */
770 if (!(pc
= NextToken(pc
)))
772 fprintf(stderr
, "fail5\n");
780 fprintf(stderr
, "error: line %d, expected ')'\n", nLine
);
785 /* Handle special stub cases */
786 if (exp
.nCallingConvention
== CC_STUB
)
788 /* Check for c++ mangled name */
791 //printf("Found c++ mangled name...\n");
796 /* Check for stdcall name */
797 const char *p
= ScanToken(pc
, '@');
798 if (p
&& (p
- pc
< exp
.strName
.len
))
802 /* Truncate the name to before the @ */
803 exp
.strName
.len
= (int)(p
- pc
);
804 if (exp
.strName
.len
< 1)
806 fprintf(stderr
, "error, @ in line %d\n", nLine
);
809 exp
.nStackBytes
= atoi(p
+ 1);
810 exp
.nArgCount
= exp
.nStackBytes
/ 4;
811 exp
.nCallingConvention
= CC_STDCALL
;
812 exp
.uFlags
|= FL_STUB
;
813 for (i
= 0; i
< exp
.nArgCount
; i
++)
814 exp
.anArgs
[i
] = ARG_LONG
;
819 /* Get optional redirection */
823 exp
.strTarget
.buf
= pc
;
824 exp
.strTarget
.len
= TokenLength(pc
);
826 /* Check syntax (end of line) */
829 fprintf(stderr
, "error: line %d, additional tokens after ')'\n", nLine
);
835 exp
.strTarget
.buf
= 0;
836 exp
.strTarget
.len
= 0;
839 /* Check for no-name without ordinal */
840 if ((exp
.uFlags
& FL_ORDINAL
) && (exp
.nOrdinal
== -1))
842 fprintf(stderr
, "error: line %d, ordinal export without ordinal!\n", nLine
);
846 OutputLine(fileDest
, &exp
);
856 printf("syntax: spec2pdef [<options> ...] <spec file>\n"
857 "Possible options:\n"
858 " -h --help prints this screen\n"
859 " -l=<file> generates an asm lib stub\n"
860 " -d=<file> generates a def file\n"
861 " -s=<file> generates a stub file\n"
862 " --ms msvc compatibility\n"
863 " -n=<name> name of the dll\n"
864 " --implib generate a def file for an import library\n"
865 " -a=<arch> Set architecture to <arch>. (i386, x86_64, arm)\n");
868 int main(int argc
, char *argv
[])
871 char *pszSource
, *pszDefFileName
= 0, *pszStubFileName
= 0, *pszLibStubName
= 0;
883 for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
885 if ((strcasecmp(argv
[i
], "--help") == 0) ||
886 (strcasecmp(argv
[i
], "-h") == 0))
891 else if (argv
[i
][1] == 'd' && argv
[i
][2] == '=')
893 pszDefFileName
= argv
[i
] + 3;
895 else if (argv
[i
][1] == 'l' && argv
[i
][2] == '=')
897 pszLibStubName
= argv
[i
] + 3;
899 else if (argv
[i
][1] == 's' && argv
[i
][2] == '=')
901 pszStubFileName
= argv
[i
] + 3;
903 else if (argv
[i
][1] == 'n' && argv
[i
][2] == '=')
905 pszDllName
= argv
[i
] + 3;
907 else if ((strcasecmp(argv
[i
], "--implib") == 0))
911 else if ((strcasecmp(argv
[i
], "--ms") == 0))
915 else if (argv
[i
][1] == 'a' && argv
[i
][2] == '=')
917 pszArchString
= argv
[i
] + 3;
921 fprintf(stderr
, "Unrecognized option: %s\n", argv
[i
]);
926 if (strcasecmp(pszArchString
, "i386") == 0)
929 gpszUnderscore
= "_";
931 else if (strcasecmp(pszArchString
, "x86_64") == 0) giArch
= ARCH_AMD64
;
932 else if (strcasecmp(pszArchString
, "ia64") == 0) giArch
= ARCH_IA64
;
933 else if (strcasecmp(pszArchString
, "arm") == 0) giArch
= ARCH_ARM
;
934 else if (strcasecmp(pszArchString
, "ppc") == 0) giArch
= ARCH_PPC
;
936 if ((giArch
== ARCH_AMD64
) || (giArch
== ARCH_IA64
))
938 pszArchString2
= "win64";
941 pszArchString2
= "win32";
943 /* Set a default dll name */
949 p1
= strrchr(argv
[i
], '\\');
950 if (!p1
) p1
= strrchr(argv
[i
], '/');
951 p2
= p1
= p1
? p1
+ 1 : argv
[i
];
954 while (*p2
!= '.' && *p2
!= 0) p2
++;
956 if (len
>= sizeof(achDllName
) - 5)
958 fprintf(stderr
, "name too long: %s\n", p1
);
962 strncpy(achDllName
, p1
, len
);
963 strncpy(achDllName
+ len
, ".dll", sizeof(achDllName
) - len
);
964 pszDllName
= achDllName
;
967 /* Open input file argv[1] */
968 file
= fopen(argv
[i
], "r");
971 fprintf(stderr
, "error: could not open file %s ", argv
[i
]);
976 fseek(file
, 0, SEEK_END
);
977 nFileSize
= ftell(file
);
980 /* Allocate memory buffer */
981 pszSource
= malloc(nFileSize
+ 1);
988 /* Load input file into memory */
989 nFileSize
= fread(pszSource
, 1, nFileSize
, file
);
992 /* Zero terminate the source */
993 pszSource
[nFileSize
] = '\0';
997 /* Open output file */
998 file
= fopen(pszDefFileName
, "w");
1001 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1005 OutputHeader_def(file
, pszDllName
);
1006 result
= ParseFile(pszSource
, file
, OutputLine_def
);
1010 if (pszStubFileName
)
1012 /* Open output file */
1013 file
= fopen(pszStubFileName
, "w");
1016 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1020 OutputHeader_stub(file
);
1021 result
= ParseFile(pszSource
, file
, OutputLine_stub
);
1027 /* Open output file */
1028 file
= fopen(pszLibStubName
, "w");
1031 fprintf(stderr
, "error: could not open output file %s ", argv
[i
+ 1]);
1035 OutputHeader_asmstub(file
, pszDllName
);
1036 result
= ParseFile(pszSource
, file
, OutputLine_asmstub
);
1037 fprintf(file
, "\nEND\n");