Author: tkreuzer Date: Fri Nov 19 15:27:58 2010 New Revision: 49632 URL: http://svn.reactos.org/svn/reactos?rev=49632&view=rev Log: [SPEC2DEF] rename spec2pdef to spec2def
Added: branches/cmake-bringup/tools/spec2def/ - copied from r49615, branches/cmake-bringup/tools/spec2pdef/ branches/cmake-bringup/tools/spec2def/spec2def.c - copied unchanged from r49625, branches/cmake-bringup/tools/spec2pdef/spec2pdef.c Removed: branches/cmake-bringup/tools/spec2def/spec2pdef.c branches/cmake-bringup/tools/spec2pdef/ Modified: branches/cmake-bringup/CMakeLists.txt branches/cmake-bringup/tools/CMakeLists.txt branches/cmake-bringup/tools/spec2def/CMakeLists.txt Modified: branches/cmake-bringup/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/CMakeLists.txt?rev=49632&r1=49631&r2=49632&view=diff ============================================================================== --- branches/cmake-bringup/CMakeLists.txt [iso-8859-1] (original) +++ branches/cmake-bringup/CMakeLists.txt [iso-8859-1] Fri Nov 19 15:27:58 2010 @@ -43,7 +43,7 @@ if(NOT MSVC) export(TARGETS widl winebuild nci buildno gendib cabman cdmake mkhive spec2pdef geninc FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) else() -export(TARGETS winebuild nci buildno gendib cabman cdmake mkhive spec2pdef geninc FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) +export(TARGETS winebuild nci buildno gendib cabman cdmake mkhive spec2def geninc FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) endif() else() Modified: branches/cmake-bringup/tools/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/CMakeLists.txt?rev=49632&r1=49631&r2=49632&view=diff ============================================================================== --- branches/cmake-bringup/tools/CMakeLists.txt [iso-8859-1] (original) +++ branches/cmake-bringup/tools/CMakeLists.txt [iso-8859-1] Fri Nov 19 15:27:58 2010 @@ -10,7 +10,7 @@ add_subdirectory(geninc) add_subdirectory(mkhive) add_subdirectory(nci) -add_subdirectory(spec2pdef) +add_subdirectory(spec2def) add_subdirectory(unicode) add_subdirectory(winebuild) if(NOT MSVC) Modified: branches/cmake-bringup/tools/spec2def/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/spec2def/CMakeLists.txt?rev=49632&r1=49615&r2=49632&view=diff ============================================================================== --- branches/cmake-bringup/tools/spec2def/CMakeLists.txt [iso-8859-1] (original) +++ branches/cmake-bringup/tools/spec2def/CMakeLists.txt [iso-8859-1] Fri Nov 19 15:27:58 2010 @@ -1,1 +1,1 @@ -add_executable(spec2pdef spec2pdef.c) +add_executable(spec2def spec2def.c) Removed: branches/cmake-bringup/tools/spec2def/spec2pdef.c URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/spec2pdef/spec2pdef.c?rev=49615&view=auto ============================================================================== --- branches/cmake-bringup/tools/spec2def/spec2pdef.c [iso-8859-1] (original) +++ branches/cmake-bringup/tools/spec2def/spec2pdef.c (removed) @@ -1,578 +1,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <string.h> - -typedef struct -{ - char *pcName; - int nNameLength; - char *pcRedirection; - int nRedirectionLength; - int nCallingConvention; - int nOrdinal; - int nStackBytes; -} EXPORT; - -int (*OutputLine)(FILE *, EXPORT *); -void (*OutputHeader)(FILE *, char *); -int no_decoration = 0; -int no_redirections = 0; -char *pszArchString = "i386"; - -enum -{ - CC_STDCALL, - CC_CDECL, - CC_FASTCALL, - CC_EXTERN, -}; - -char* astrCallingConventions[] = -{ - "STDCALL", - "CDECL", - "FASTCALL", - "EXTERN" -}; - -static -int -IsSeparator(char chr) -{ - return ((chr <= '*' && chr != '$') || - (chr >= ':' && chr <= '?') ); -} - -int -CompareToken(const char *token, const char *comparand) -{ - while (*comparand) - { - if (*token != *comparand) return 0; - token++; - comparand++; - } - if (!IsSeparator(*token)) return 0; - return 1; -} - -char * -NextLine(char *pc) -{ - while (*pc != 0) - { - if (pc[0] == '\n' && pc[1] == '\r') return pc + 2; - else if (pc[0] == '\n') return pc + 1; - pc++; - } - return pc; -} - -int -TokenLength(char *pc) -{ - int length = 0; - - while (!IsSeparator(*pc++)) length++; - - return length; -} - -char * -NextToken(char *pc) -{ - /* Skip token */ - while (!IsSeparator(*pc)) pc++; - - /* Skip white spaces */ - while (*pc == ' ' || *pc == '\t') pc++; - - /* Check for end of line */ - if (*pc == '\n' || *pc == '\r' || *pc == 0) return 0; - - /* Check for comment */ - if (*pc == '#' || *pc == ';') return 0; - - return pc; -} - -void -OutputHeader_stub(FILE *file, char *libname) -{ - fprintf(file, "; File generated automatically, do not edit! \n\n" - ".586\n.model flat\n.code\n"); -} - -int -OutputLine_stub(FILE *fileDest, EXPORT *pexp) -{ - if (pexp->nCallingConvention == CC_STDCALL) - { - fprintf(fileDest, "PUBLIC _%...@%d\n_%.*s@%d: nop\n", - pexp->nNameLength, pexp->pcName, pexp->nStackBytes, - pexp->nNameLength, pexp->pcName, pexp->nStackBytes); - } - else if (pexp->nCallingConvention == CC_FASTCALL) - { - fprintf(fileDest, "PUBLIC @%...@%d\n@%...@%d: nop\n", - pexp->nNameLength, pexp->pcName, pexp->nStackBytes, - pexp->nNameLength, pexp->pcName, pexp->nStackBytes); - } - else if (pexp->nCallingConvention == CC_CDECL) - { - fprintf(fileDest, "PUBLIC _%.*s\n_%.*s: nop\n", - pexp->nNameLength, pexp->pcName, - pexp->nNameLength, pexp->pcName); - } - else if (pexp->nCallingConvention == CC_EXTERN) - { - fprintf(fileDest, "PUBLIC _%.*s\n_%.*s:\n", - pexp->nNameLength, pexp->pcName, - pexp->nNameLength, pexp->pcName); - } - - return 1; -} - -void -OutputHeader_def(FILE *file, char *libname) -{ - fprintf(file, - "; File generated automatically, do not edit!\n\n" - "LIBRARY %s\n\n" - "EXPORTS\n", - libname); -} - -int -OutputLine_def(FILE *fileDest, EXPORT *exp) -{ - fprintf(fileDest, " "); - if (exp->nCallingConvention == CC_FASTCALL && !no_decoration) - { - fprintf(fileDest, "@"); - } - - fprintf(fileDest, "%.*s", exp->nNameLength, exp->pcName); - - if ((exp->nCallingConvention == CC_STDCALL || - exp->nCallingConvention == CC_FASTCALL) && !no_decoration) - { - fprintf(fileDest, "@%d", exp->nStackBytes); - } - - if (exp->pcRedirection && !no_redirections) - { - if (exp->nCallingConvention == CC_FASTCALL && !no_decoration) - { - fprintf(fileDest, "@"); - } - fprintf(fileDest, "=%.*s", exp->nRedirectionLength, exp->pcRedirection); - if ((exp->nCallingConvention == CC_STDCALL || - exp->nCallingConvention == CC_FASTCALL) && !no_decoration) - { - fprintf(fileDest, "@%d", exp->nStackBytes); - } - } - - if (exp->nOrdinal != -1) - { - fprintf(fileDest, " @%d", exp->nOrdinal); - } - - if (exp->nCallingConvention == CC_EXTERN) - { - fprintf(fileDest, " DATA"); - } - - fprintf(fileDest, "\n"); - - return 1; -} - -void -OutputHeader_pdef(FILE *file, char *libname) -{ - fprintf(file, - "; File generated automatically, do not edit!\n\n" - "LIBRARY %s\n\n" - "EXPORTS\n" - "#define FOOL(x) x\n" - "#if defined(__GNUC__) && defined(_X86_)\n" - "#define _NAME_STDCALL(name, stackbytes) FOOL(name)@stackbytes\n" - "#define _NAME_FASTCALL(name, stackbytes) FOOL(@)FOOL(name)@stackbytes\n" - "#define _NAME_CDECL(name, stackbytes) FOOL(name)\n" - "#else\n" - "#define _NAME_STDCALL(name, stackbytes) name\n" - "#define _NAME_FASTCALL(name, stackbytes) name\n" - "#define _NAME_CDECL(name, stackbytes) name\n" - "#endif\n" - "#define _NAME_EXTERN(name, stackbytes) name\n" - "#define _NAME(name, cc, stackbytes) _NAME_##cc(name, stackbytes)\n", - libname); -} - -int -OutputLine_pdef(FILE *fileDest, EXPORT *exp) -{ - fprintf(fileDest, "_NAME(%.*s,%s,%d)", - exp->nNameLength, exp->pcName, - astrCallingConventions[exp->nCallingConvention], - exp->nStackBytes); - - if (exp->pcRedirection) - { - fprintf(fileDest, "= _NAME(%.*s,%s,%d)", - exp->nRedirectionLength, exp->pcRedirection, - astrCallingConventions[exp->nCallingConvention], - exp->nStackBytes); - } - - if (exp->nOrdinal != -1) - { - fprintf(fileDest, " @%d", exp->nOrdinal); - } - - if (exp->nCallingConvention == CC_EXTERN) - { - fprintf(fileDest, " DATA"); - } - - fprintf(fileDest, "\n"); - - return 1; -} - -int -ParseFile(char* pcStart, FILE *fileDest) -{ - char *pc, *pcLine; - int nLine; - EXPORT exp; - int included; - - //fprintf(stderr, "info: line %d, pcStart:'%.30s'\n", nLine, pcStart); - - /* Loop all lines */ - nLine = 1; - for (pcLine = pcStart; *pcLine; pcLine = NextLine(pcLine), nLine++) - { - pc = pcLine; - - //fprintf(stderr, "info: line %d, token:'%d, %.20s'\n", - // nLine, TokenLength(pcLine), pcLine); - - /* Skip white spaces */ - while (*pc == ' ' || *pc == '\t') pc++; - - /* Skip empty lines, stop at EOF */ - if (*pc == ';' || *pc <= '#') continue; - if (*pc == 0) return 0; - - //fprintf(stderr, "info: line %d, token:'%.*s'\n", - // nLine, TokenLength(pc), pc); - - /* Now we should get either an ordinal or @ */ - if (*pc == '@') exp.nOrdinal = -1; - else exp.nOrdinal = atol(pc); - - /* Go to next token (type) */ - if (!(pc = NextToken(pc))) - { - fprintf(stderr, "error: line %d, unexpected end of line\n", nLine); - return -10; - } - - //fprintf(stderr, "info: Token:'%.10s'\n", pc); - - /* Now we should get the type */ - if (CompareToken(pc, "stdcall")) - { - exp.nCallingConvention = CC_STDCALL; - } - else if (CompareToken(pc, "cdecl") || - CompareToken(pc, "varargs")) - { - exp.nCallingConvention = CC_CDECL; - } - else if (CompareToken(pc, "fastcall") || - CompareToken(pc, "FASTCALL")) - { - exp.nCallingConvention = CC_FASTCALL; - } - else if (CompareToken(pc, "extern") || - CompareToken(pc, "stub")) - { - exp.nCallingConvention = CC_EXTERN; - } - else - { - fprintf(stderr, "error: line %d, expected type, got '%.*s' %d\n", - nLine, TokenLength(pc), pc, *pc); - return -11; - } - - //fprintf(stderr, "info: nCallingConvention: %d\n", exp.nCallingConvention); - - /* Go to next token (options or name) */ - if (!(pc = NextToken(pc))) - { - fprintf(stderr, "fail2\n"); - return -12; - } - - /* Handle options */ - included = 1; - while (*pc == '-') - { - if (CompareToken(pc, "-arch")) - { - /* Default to not included */ - included = 0; - pc += 5; - - /* Look if we are included */ - while (*pc == '=' || *pc == ',') - { - pc++; - if (CompareToken(pc, pszArchString)) - { - included = 1; - break; - } - - /* Skip to next arch or end */ - while (*pc > ',') pc++; - } - } - else - { - fprintf(stderr, "info: ignored option: '%.10s'\n", pc); - } - - /* Go to next token */ - pc = NextToken(pc); - } - - //fprintf(stderr, "info: Name:'%.10s'\n", pc); - - /* If arch didn't match ours, skip this entry */ - if (!included) continue; - - /* Get name */ - exp.pcName = pc; - exp.nNameLength = TokenLength(pc); - - /* Handle parameters */ - exp.nStackBytes = 0; - if (exp.nCallingConvention != CC_EXTERN) - { - //fprintf(stderr, "info: options:'%.10s'\n", pc); - /* Go to next token */ - if (!(pc = NextToken(pc))) - { - fprintf(stderr, "fail4\n"); - return -13; - } - - /* Verify syntax */ - if (*pc++ != '(') - { - fprintf(stderr, "error: line %d, expected '('\n", nLine); - return -14; - } - - /* Skip whitespaces */ - while (*pc == ' ' || *pc == '\t') pc++; - - exp.nStackBytes = 0; - while (*pc >= '0') - { - if (CompareToken(pc, "long")) - exp.nStackBytes += 4; - else if (CompareToken(pc, "double")) - exp.nStackBytes += 8; - else if (CompareToken(pc, "ptr") || - CompareToken(pc, "str") || - CompareToken(pc, "wstr")) - exp.nStackBytes += sizeof(void*); - else - fprintf(stderr, "error: line %d, expected type, got: %.10s\n", nLine, pc); - - /* Go to next parameter */ - if (!(pc = NextToken(pc))) - { - fprintf(stderr, "fail5\n"); - return -15; - } - } - - /* Check syntax */ - if (*pc++ != ')') - { - fprintf(stderr, "error: line %d, expected ')'\n", nLine); - return -16; - } - } - - /* Get optional redirection */ - if ((pc = NextToken(pc))) - { - exp.pcRedirection = pc; - exp.nRedirectionLength = TokenLength(pc); - - /* Check syntax (end of line) */ - if (NextToken(pc)) - { - fprintf(stderr, "error: line %d, additional tokens after ')'\n", nLine); - return -17; - } - } - else - { - exp.pcRedirection = 0; - exp.nRedirectionLength = 0; - } - - OutputLine(fileDest, &exp); - } - -printf("done\n"); - - return 0; -} - - -void usage(void) -{ - printf("syntax: spec2pdef [<options> ...] <source file> <dest file>\n" - "Possible options:\n" - " -d=<file> --dll=<file> names the dll\n" - " -h --help prints this screen\n" - " -s --stubs generates an asm lib stub\n" - " -n --no-decoration removes @xx decorations from def file\n"); -} - -int main(int argc, char *argv[]) -{ - size_t nFileSize; - char *pszSource, *pszDllName = 0; - char achDllName[40]; - FILE *file; - int result, i; - - if (argc < 2) - { - usage(); - return -1; - } - - /* Default to def file */ - OutputLine = OutputLine_def; - OutputHeader = OutputHeader_def; - - /* Read options */ - for (i = 1; i < argc && *argv[i] == '-'; i++) - { - if ((_stricmp(argv[i], "--help") == 0) || - (_stricmp(argv[i], "-h") == 0)) - { - usage(); - return 0; - } - else if ((_stricmp(argv[i], "--stublib") == 0) || - (_stricmp(argv[i], "-s") == 0)) - { - OutputLine = OutputLine_stub; - OutputHeader = OutputHeader_stub; - } - else if ((_stricmp(argv[i], "--dll") == 0) || - (_stricmp(argv[i], "-d") == 0)) - { - pszDllName = argv[i + 1]; - i++; - } - else if ((_stricmp(argv[i], "--no-decoration") == 0) || - (_stricmp(argv[i], "-n") == 0)) - { - no_decoration = 1; - } - else if ((_stricmp(argv[i], "--no-redirection") == 0) || - (_stricmp(argv[i], "-r") == 0)) - { - no_redirections = 1; - } - else - { - fprintf(stderr, "Unrecognized option: %s\n", argv[i]); - return -1; - } - } - - /* Set a default dll name */ - if (!pszDllName) - { - char *p1, *p2; - int len; - - p1 = strrchr(argv[i], '\\'); - if (!p1) p1 = strrchr(argv[i], '/'); - p2 = p1 = p1 ? p1 + 1 : argv[i]; - - /* walk up to '.' */ - while (*p2 != '.' && *p2 != 0) p2++; - len = p2 - p1; - if (len >= sizeof(achDllName) - 5) - { - fprintf(stderr, "name too long: %s\n", p1); - return -2; - } - - strncpy(achDllName, p1, len); - strncpy(achDllName + len, ".dll", sizeof(achDllName) - len); - pszDllName = achDllName; - } - - /* Open input file argv[1] */ - file = fopen(argv[i], "r"); - if (!file) - { - fprintf(stderr, "error: could not open file %s ", argv[i]); - return -3; - } - - /* Get file size */ - fseek(file, 0, SEEK_END); - nFileSize = ftell(file); - rewind(file); - - /* Allocate memory buffer */ - pszSource = malloc(nFileSize + 1); - if (!pszSource) return -4; - - /* Load input file into memory */ - nFileSize = fread(pszSource, 1, nFileSize, file); - fclose(file); - - /* Zero terminate the source */ - pszSource[nFileSize] = '\0'; - - /* Open output file */ - file = fopen(argv[i + 1], "w"); - if (!file) - { - fprintf(stderr, "error: could not open output file %s ", argv[i + 1]); - return -5; - } - - OutputHeader(file, pszDllName); - - result = ParseFile(pszSource, file); - - if (OutputHeader == OutputHeader_stub) fprintf(file, "\nEND\n"); - - fclose(file); - - return result; -}