int _CRTAPI1 rc_main( int argc, char**argv ) { PCHAR r; PCHAR x; PCHAR s1, s2, s3; int n; PCHAR pchIncludeT; ULONG cchIncludeMax; int fInclude = TRUE; /* by default, search INCLUDE */ int fIncludeCurrentFirst = TRUE; /* by default, add current dir to start of includes */ int cDefine = 0; int cUnDefine = 0; PCHAR pszDefine[cDefineMax]; PCHAR pszUnDefine[cDefineMax]; CHAR szDrive[_MAX_DRIVE]; CHAR szDir[_MAX_DIR]; CHAR szFName[_MAX_FNAME]; CHAR szExt[_MAX_EXT]; CHAR szFullPath[_MAX_PATH]; CHAR szIncPath[_MAX_PATH]; CHAR buf[10]; CHAR *szRC; PCHAR *ppargv; int rcpp_argc; /* Set up for this run of RC */ if (_setjmp(jb)) { return Nerrors; } hHeap = RCInit(); if (hHeap == NULL) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1120), 0x01000000); quit(Msg_Text); } pchInclude = pchIncludeT = MyAlloc(_MAX_PATH*2); cchIncludeMax = _MAX_PATH*2; szRC = argv[0]; /* process the command line switches */ while ((argc > 1) && (IsSwitchChar(*argv[1]))) { switch (toupper(argv[1][1])) { case '?': case 'H': /* print out help, and quit */ SendError("\n"); SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(10001), VER_PRODUCTVERSION_STR, VER_PRODUCTBUILD); SendError(Msg_Text); SendError(GET_MSG(20001)); SendError("\n"); return 0; /* can just return - nothing to cleanup, yet. */ case 'B': if (toupper(argv[1][2]) == 'R') { /* base resource id */ unsigned long id; if (isdigit(argv[1][3])) argv[1] += 3; else if (argv[1][3] == ':') argv[1] += 4; else { argc--; argv++; if (argc <= 1) goto BadId; } if (*(argv[1]) == 0) goto BadId; id = atoi(argv[1]); if (id < 1 || id > 32767) quit(GET_MSG(1210)); idBase = (WORD)id; break; BadId: quit(GET_MSG(1209)); } break; case 'C': /* Check for the existence of CodePage Number */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } /* Now argv point to first digit of CodePage */ if (!argv[1]) quit(GET_MSG(1204)); uiCodePage = atoi(argv[1]); if (uiCodePage == 0) quit(GET_MSG(1205)); /* Check if uiCodePage exist in registry. */ if (!IsValidCodePage (uiCodePage)) quit(GET_MSG(1206)); break; case 'D': /* if not attached to switch, skip to next */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } /* remember pointer to string */ pszDefine[cDefine++] = argv[1]; if (cDefine > cDefineMax) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1105), argv[1]); quit(Msg_Text); } break; case 'F': switch (toupper(argv[1][2])) { case 'O': if (argv[1][3]) argv[1] += 3; else { argc--; argv++; } if (argc > 1) strcpy(resname, argv[1]); else quit(GET_MSG(1101)); break; default: SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1103), argv[1]); quit(Msg_Text); } break; case 'I': /* add string to directories to search */ /* note: format is <path>\0<path>\0\0 */ /* if not attached to switch, skip to next */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } if (!argv[1]) quit(GET_MSG(1201)); if ((strlen(argv[1]) + 1 + strlen(pchInclude)) >= cchIncludeMax) { cchIncludeMax = strlen(pchInclude) + strlen(argv[1]) + _MAX_PATH*2; pchIncludeT = MyAlloc(cchIncludeMax); strcpy(pchIncludeT, pchInclude); MyFree(pchInclude); pchInclude = pchIncludeT; pchIncludeT = pchInclude + strlen(pchIncludeT) + 1; } /* if not first switch, write over terminator with semicolon */ if (pchInclude != pchIncludeT) pchIncludeT[-1] = ';'; /* copy the path */ while ((*pchIncludeT++ = *argv[1]++) != 0) ; break; case 'L': /* if not attached to switch, skip to next */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } if (!argv[1]) quit(GET_MSG(1202)); if (sscanf( argv[1], "%x", &language ) != 1) quit(GET_MSG(1203)); while (*argv[1]++ != 0) ; break; case 'M': fMacRsrcs = TRUE; goto MaybeMore; case 'N': fAppendNull = TRUE; goto MaybeMore; case 'P': fPreprocessOnly = TRUE; break; case 'R': goto MaybeMore; case 'S': // find out from BRAD what -S does fAFXSymbols = TRUE; break; case 'U': /* if not attached to switch, skip to next */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } /* remember pointer to string */ pszUnDefine[cUnDefine++] = argv[1]; if (cUnDefine > cDefineMax) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1104), argv[1]); quit(Msg_Text); } break; case 'V': fVerbose = TRUE; // AFX doesn't set this goto MaybeMore; case 'X': /* remember not to add INCLUDE path */ fInclude = FALSE; // VC seems to feel the current dir s/b added first no matter what... // If -X! is specified, don't do that. if (argv[1][2] == '!') { fIncludeCurrentFirst = FALSE; argv[1]++; } MaybeMore: /* check to see if multiple switches, like -xrv */ if (argv[1][2]) { argv[1][1] = '-'; argv[1]++; continue; } break; case 'Z': /* if not attached to switch, skip to next */ if (argv[1][2]) argv[1] += 2; else { argc--; argv++; } if (!argv[1]) quit(GET_MSG(1211)); s3 = strchr(argv[1], '/'); if (s3 == NULL) quit(GET_MSG(1212)); *s3 = '\0'; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s3+1, -1, szSubstituteFontName, MAXTOKSTR); s1 = argv[1]; do { s2 = strchr(s1, ','); if (s2 != NULL) *s2 = '\0'; if (strlen(s1)) { if (nBogusFontNames >= 16) quit(GET_MSG(1213)); pszBogusFontNames[nBogusFontNames] = MyAlloc((strlen(s1)+1) * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s1, -1, pszBogusFontNames[nBogusFontNames], MAXTOKSTR); nBogusFontNames += 1; } if (s2 != NULL) *s2++ = ','; } while (s1 = s2); *s3 = '/'; while (*argv[1]++ != 0) ; break; default: SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1106), argv[1]); quit(Msg_Text); } /* get next argument or switch */ argc--; argv++; } /* make sure we have at least one file name to work with */ if (argc != 2 || *argv[1] == '\0') quit(GET_MSG(1107)); if (fVerbose) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(10001), VER_PRODUCTVERSION_STR, VER_PRODUCTBUILD); printf(Msg_Text); printf("%s\n", GET_MSG(10002)); } // Support Multi Code Page // If user did NOT indicate code in command line, we have to set Default // for NLS Conversion if (uiCodePage == 0) { CHAR *pchCodePageString; /* At first, search ENVIRONMENT VALUE */ if ((pchCodePageString = getenv("RCCODEPAGE")) != NULL) { uiCodePage = atoi(pchCodePageString); if (uiCodePage == 0 || !IsValidCodePage(uiCodePage)) quit(GET_MSG(1207)); } else { /* We use System ANSI Code page (ACP) */ uiCodePage = GetACP(); } } uiDefaultCodePage = uiCodePage; if (fVerbose) printf("Using codepage %d as default\n", uiDefaultCodePage); /* If we have no extension, assumer .rc */ /* If .res extension, make sure we have -fo set, or error */ /* Otherwise, just assume file is .rc and output .res (or resname) */ // // We have to be careful upper casing this, because the codepage // of the filename might be in something other than current codepage. // MultiByteToWideChar(uiCodePage, MB_PRECOMPOSED, argv[1], -1, tokenbuf, MAXSTR+1); if (CharUpperBuff(tokenbuf, wcslen(tokenbuf)) == 0) _wcsupr(tokenbuf); WideCharToMultiByte(uiCodePage, 0, tokenbuf, -1, argv[1], strlen(argv[1]), NULL, NULL); _splitpath(argv[1], szDrive, szDir, szFName, szExt); if (!(*szDir || *szDrive)) { strcpy(szIncPath, ".;"); } else { strcpy(szIncPath, szDrive); strcat(szIncPath, szDir); strcat(szIncPath, ";.;"); } if ((strlen(szIncPath) + 1 + strlen(pchInclude)) >= cchIncludeMax) { cchIncludeMax = strlen(pchInclude) + strlen(szIncPath) + _MAX_PATH*2; pchIncludeT = MyAlloc(cchIncludeMax); strcpy(pchIncludeT, pchInclude); MyFree(pchInclude); pchInclude = pchIncludeT; pchIncludeT = pchInclude + strlen(pchIncludeT) + 1; } pchIncludeT = MyAlloc(cchIncludeMax); if (fIncludeCurrentFirst) { strcpy(pchIncludeT, szIncPath); strcat(pchIncludeT, pchInclude); } else { strcpy(pchIncludeT, pchInclude); strcat(pchIncludeT, ";"); strcat(pchIncludeT, szIncPath); } MyFree(pchInclude); pchInclude = pchIncludeT; pchIncludeT = pchInclude + strlen(pchIncludeT) + 1; if (!szExt[0]) { strcpy(szExt, ".RC"); } else if (strcmp (szExt, ".RES") == 0) { quit (GET_MSG(1208)); } _makepath(inname, szDrive, szDir, szFName, szExt); if (fPreprocessOnly) { _makepath(szPreProcessName, NULL, NULL, szFName, ".rcpp"); } /* Create the name of the .RES file */ if (resname[0] == 0) { // if building a Mac resource file, we use .rsc to match mrc's output _makepath(resname, szDrive, szDir, szFName, fMacRsrcs ? ".RSC" : ".RES"); } /* create the temporary file names */ szTempFileName = MyAlloc(_MAX_PATH); _fullpath(szFullPath, resname, _MAX_PATH); _splitpath(szFullPath, szDrive, szDir, NULL, NULL); _makepath(szTempFileName, szDrive, szDir, "RCXXXXXX", ""); _mktemp (szTempFileName); szTempFileName2 = MyAlloc(_MAX_PATH); _makepath(szTempFileName2, szDrive, szDir, "RDXXXXXX", ""); _mktemp (szTempFileName2); ppargv = szRCPP; *ppargv++ = "RCPP"; rcpp_argc = 1; /* Open the .RES file (deleting any old versions which exist). */ if ((fhBin = fopen(resname, "w+b")) == NULL) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(1109), resname); quit(Msg_Text); } else { if (fMacRsrcs) MySeek(fhBin, MACDATAOFFSET, 0); if (fVerbose) { SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(10102), resname); printf(Msg_Text); } /* Set up for RCPP. This constructs the command line for it. */ *ppargv = _strdup("-CP"); rcpp_argc++ ; ppargv++; _itoa(uiCodePage, buf, 10); *ppargv = buf; rcpp_argc++ ; ppargv++; *ppargv = _strdup("-f"); rcpp_argc++ ; ppargv++; *ppargv = _strdup(szTempFileName); rcpp_argc++ ; ppargv++; *ppargv = _strdup("-g"); rcpp_argc++ ; ppargv++; if (fPreprocessOnly) { *ppargv = _strdup(szPreProcessName); } else { *ppargv = _strdup(szTempFileName2); } rcpp_argc++ ; ppargv++; *ppargv = _strdup("-DRC_INVOKED"); rcpp_argc++ ; ppargv++; if (fAFXSymbols) { *ppargv = _strdup("-DAPSTUDIO_INVOKED"); rcpp_argc++ ; ppargv++; } if (fMacRsrcs) { *ppargv = _strdup("-D_MAC"); rcpp_argc++ ; ppargv++; } *ppargv = _strdup("-D_WIN32"); /* to be compatible with C9/VC++ */ rcpp_argc++ ; ppargv++; *ppargv = _strdup("-pc\\:/"); rcpp_argc++ ; ppargv++; *ppargv = _strdup("-E"); rcpp_argc++ ; ppargv++; /* Parse the INCLUDE environment variable */ if (fInclude) { *ppargv = _strdup("-I."); rcpp_argc++ ; ppargv++; /* add seperator if any -I switches */ if (pchInclude != pchIncludeT) pchIncludeT[-1] = ';'; /* read 'em */ x = getenv("INCLUDE"); if (x == (PCHAR)NULL) *pchIncludeT = '\000'; else { if (strlen(pchInclude) + strlen(x) + 1 >= cchIncludeMax) { cchIncludeMax = strlen(pchInclude) + strlen(x) + _MAX_PATH*2; pchIncludeT = MyAlloc(cchIncludeMax); strcpy(pchIncludeT, pchInclude); MyFree(pchInclude); pchInclude = pchIncludeT; } strcat(pchInclude, x); pchIncludeT = pchInclude + strlen(pchInclude); } } /* now put includes on the RCPP command line */ for (x = pchInclude ; *x ; ) { r = x; while (*x && *x != ';') x = CharNextA(x); /* mark if semicolon */ if (*x) *x-- = 0; if (*r != '\0' && /* empty include path? */ *r != '%' /* check for un-expanded stuff */ // && strchr(r, ' ') == NULL /* check for whitespace */ ) { /* add switch */ *ppargv = _strdup("-I"); rcpp_argc++ ; ppargv++; *ppargv = _strdup(r); rcpp_argc++ ; ppargv++; } /* was semicolon, need to fix for searchenv() */ if (*x) { *++x = ';'; x++; } } /* include defines */ for (n = 0; n < cDefine; n++) { *ppargv = _strdup("-D"); rcpp_argc++ ; ppargv++; *ppargv = pszDefine[n]; rcpp_argc++ ; ppargv++; } /* include undefine */ for (n = 0; n < cUnDefine; n++) { *ppargv = _strdup("-U"); rcpp_argc++ ; ppargv++; *ppargv = pszUnDefine[n]; rcpp_argc++ ; ppargv++; } if (rcpp_argc > MAX_CMD) { quit(GET_MSG(1102)); } if (fVerbose) { /* echo the preprocessor command */ printf("RC:"); for (n = 0 ; n < rcpp_argc ; n++) { wsprintfA(Msg_Text, " %s", szRCPP[n]); printf(Msg_Text); } printf("\n"); } /* Add .rc with rcincludes into szTempFileName */ if (!RC_PreProcess(inname)) quit(Msg_Text); /* Run the Preprocessor. */ if (RCPP(rcpp_argc, szRCPP, NULL) != 0) quit(GET_MSG(1116)); } if (fPreprocessOnly) { sprintf(szBuf, "Preprocessed File Created in: %s\n", szPreProcessName); quit(szBuf); } if (fVerbose) printf("\n%s", inname); if ((fhInput = fopen(szTempFileName2, "rb")) == NULL_FILE) quit(GET_MSG(2180)); if (!InitSymbolInfo()) quit(GET_MSG(22103)); LexInit (fhInput); uiCodePage = uiDefaultCodePage; ReadRF(); /* create .RES from .RC */ if (!TermSymbolInfo(fhBin)) quit(GET_MSG(22204)); if (!fMacRsrcs) MyAlign(fhBin); // Pad end of file so that we can concatenate files CleanUpFiles(); HeapDestroy(hHeap); return Nerrors; // return success, not quitting. }
BOOL WINAPI Handler(DWORD fdwCtrlType) { if (fdwCtrlType == CTRL_C_EVENT) { SendError("\n"); SET_MSG(Msg_Text, sizeof(Msg_Text), GET_MSG(20101)); SendError(Msg_Text); CleanUpFiles(); HeapDestroy(hHeap); /* delete output file */ if (resname) remove(resname); return(FALSE); } return(FALSE); }
VOID quit(PSTR str) { /* print out the error message */ if (str) { SendError("\n"); SendError(str); SendError("\n"); } CleanUpFiles(); /* delete output file */ if (resname) remove(resname); HeapDestroy(hHeap); Nerrors++; longjmp(jb, Nerrors); }
int __cdecl main(int argc, char **argv) { int i; BOOL bFailed = FALSE; DWORD result; char * NormalDirectoryName = "normal_test_directory"; char * ReadOnlyDirectoryName = "ro_test_directory"; char * ReadWriteDirectoryName = "rw_directory"; char * HiddenDirectoryName = ".hidden_directory"; char * HiddenReadOnlyDirectoryName = ".hidden_ro_directory"; char * NoDirectoryName = "no_directory"; char * NormalFileName = "normal_test_file"; char * ReadOnlyFileName = "ro_test_file"; char * ReadWriteFileName = "rw_file"; char * HiddenFileName = ".hidden_file"; char * HiddenReadOnlyFileName = ".hidden_ro_file"; char * NotReallyAFileName = "not_really_a_file"; WCHAR *WStr; /* Tests on directory */ gfaTestsDir[0].name = NormalDirectoryName; gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; gfaTestsDir[0].isFile = TYPE_DIR; gfaTestsDir[1].name = ReadOnlyDirectoryName; gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY; gfaTestsDir[1].isFile = TYPE_DIR; gfaTestsDir[2].name = ReadWriteDirectoryName; gfaTestsDir[2].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; gfaTestsDir[2].isFile = TYPE_DIR; gfaTestsDir[3].name = HiddenDirectoryName; gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //| //FILE_ATTRIBUTE_HIDDEN; gfaTestsDir[3].isFile = TYPE_DIR; gfaTestsDir[4].name = HiddenReadOnlyDirectoryName; gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY; //| //FILE_ATTRIBUTE_HIDDEN; gfaTestsDir[4].isFile = TYPE_DIR; gfaTestsDir[5].name = NoDirectoryName; gfaTestsDir[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; gfaTestsDir[5].isFile = TYPE_DIR; /* Tests on file */ gfaTestsFile[0].name = NormalFileName; gfaTestsFile[0].expectedAttribs = FILE_ATTRIBUTE_NORMAL; gfaTestsFile[0].isFile = TYPE_FILE; gfaTestsFile[1].name = ReadOnlyFileName; gfaTestsFile[1].expectedAttribs = FILE_ATTRIBUTE_READONLY; gfaTestsFile[1].isFile = TYPE_FILE; gfaTestsFile[2].name = ReadWriteFileName; gfaTestsFile[2].expectedAttribs = FILE_ATTRIBUTE_NORMAL; gfaTestsFile[2].isFile = TYPE_FILE; gfaTestsFile[3].name = HiddenFileName; gfaTestsFile[3].expectedAttribs = FILE_ATTRIBUTE_NORMAL; //FILE_ATTRIBUTE_HIDDEN; gfaTestsFile[3].isFile = TYPE_FILE; gfaTestsFile[4].name = HiddenReadOnlyFileName; gfaTestsFile[4].expectedAttribs = FILE_ATTRIBUTE_READONLY; //| //FILE_ATTRIBUTE_HIDDEN; gfaTestsFile[4].isFile = TYPE_FILE; gfaTestsFile[5].name = NotReallyAFileName; gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; gfaTestsFile[5].isFile = TYPE_FILE; /* Initialize PAL environment */ if (0 != PAL_Initialize(argc,argv)) { return FAIL; } if(!CleanUpFiles()) { Fail("GetFileAttributesW: Pre-Clean Up Files Failed\n"); } if(0 == SetUpFiles()) { Fail("GetFileAttributesW: SetUp Files Failed\n"); } if(!CleanUpDirs()) { Fail("GetFileAttributesW: Pre-Clean Up Directories Failed\n"); } if(!SetUpDirs()) { Fail("GetFileAttributesW: SetUp Directories Failed\n"); } /* * Go through all the test cases above, * call GetFileAttributesW on the name and * make sure the return value is the one expected */ for( i = 0; i < numFileTests; i++ ) { WStr = convert(gfaTestsFile[i].name); result = GetFileAttributesW(WStr); if( result != gfaTestsFile[i].expectedAttribs ) { bFailed = TRUE; Trace("ERROR: GetFileAttributesW Test#%u on %s " "returned %u instead of %u. \n", i, gfaTestsFile[i].name, result, gfaTestsFile[i].expectedAttribs); } free(WStr); } for( i = 0; i < numDirTests; i++ ) { WStr = convert(gfaTestsDir[i].name); result = GetFileAttributesW(WStr); if( result != gfaTestsDir[i].expectedAttribs ) { bFailed = TRUE; Trace("ERROR: GetFileAttributesW on Directories Test#%u on %s " "returned %u instead of %u. \n", i, gfaTestsDir[i].name, result, gfaTestsDir[i].expectedAttribs); } free(WStr); } if(!CleanUpFiles()) { Fail("GetFileAttributesW: Post-Clean Up Files Failed\n"); } if(!CleanUpDirs()) { Fail("GetFileAttributesW: Post-Clean Up Directories Failed\n"); } /* If any errors, just call Fail() */ if( bFailed ) { Fail(""); } PAL_Terminate(); return PASS; }