static void genModule(int tab, int expand, token_t * e1, char *mname) { FILE *fp = stdout; if(EiC_lexan() == INT) MULTIPLEX = token->Val.ival; else retractlexan(); if(EiC_lexan() == STR) { fp = fopen(token->Val.p.p,"w"); EiC_formatMessage("redirecting to [%s]\n",(char*)token->Val.p.p); if(!fp) { EiC_warningerror("Failed to open file %s\n", token->Val.p.p); fp = stdout; } } else retractlexan(); genHeader(mname,fp); genFunctions(tab, expand, e1, mname, EiC_IsFunc,fp); genInterface(tab, expand, e1, mname,fp); if(fp != stdout) fclose(fp); }
int main(int argc, char* argv[]) { int i; const char *inputFilename = NULL; const char *outputFilename = NULL; const char *baseName = NULL; FILE *inputFile; FILE *outputFile; for(i=0; i<argc; i++) { if(!strcmp(argv[i], "-i") && (i+1 < argc)) { inputFilename = argv[++i]; } else if(!strcmp(argv[i], "-o") && (i+1 < argc)) { outputFilename = argv[++i]; } else if(!strcmp(argv[i], "-n") && (i+1 < argc)) { baseName = argv[++i]; } } if(!inputFilename || !outputFilename || !baseName) { printf("Syntax: genHeader -i [input binary filename] -o [output header filename] -n [namespace identifier to use]\n"); return -1; } inputFile = fopen(inputFilename, "rb"); if(!inputFile) { printf("genHeader ERROR: Can't open '%s' for read.\n", inputFilename); return -1; } outputFile = fopen(outputFilename, "wb"); if(!outputFile) { fclose(inputFile); printf("genHeader ERROR: Can't open '%s' for write.\n", outputFilename); return -1; } genHeader(inputFile, outputFile, baseName); fclose(inputFile); fclose(outputFile); return 0; }
int joinDir(const char *sourceDir, const char *extName) { stJAndSHeader *joinHdr = NULL; FILE *fileHdl = NULL; char destName[_MAX_DIR], tempName[_MAX_DIR]; char outmode[] = "wb6 "; short nErr; // Clear any outstanding errors errno = EZERO; // Get memory for the join header structure if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL) { // Populate the header with all the match files if (genHeader (sourceDir, "", extName, joinHdr, 1)) //@3 directory { // Clear any outstanding errors errno = EZERO; // Generate the destination name sprintf (destName, "%s%s", sourceDir, extName); // Open the join file... if ((fileHdl = fopen (destName, "wb")) != NULL) { // ... and join in all the files. writeHeader ( joinHdr, fileHdl); concatFiles ( sourceDir, joinHdr, fileHdl); fclose (fileHdl); // Rename file as a temporary file sprintf (tempName, "%s%s", sourceDir, ".CAT"); rename (destName, tempName); String strDir(sourceDir); size_t pos = strDir.find_last_of ( '\\' ); if ( String::npos == pos ) pos = strDir.find_last_of ( '/' ); String strFolderName = strDir.substr ( pos + 1 ); String strParentDir = strDir.substr(0, pos); // Compress the file @2 if ( ( nErr = file_compress ( strParentDir.c_str(), strFolderName.c_str(), ".CAT", extName, outmode ) ) != 0 ) { free(joinHdr); String msg = String("Failed to compress ") + tempName; throw std::exception ( msg.c_str() ); return nErr; } } } free(joinHdr); joinHdr = NULL; } else throw std::exception("Insufficient memory"); // For debugging only #ifdef DEBUG_MODE printHeader (stdout,joinHdr); #endif return errno; }
/* ======================================================================== PURPOSE : */ int joinFiles (const char *sourceDir, const char *sourceName, const char *extName) { stJAndSHeader *joinHdr = NULL; FILE *fileHdl = NULL; char destName[_MAX_DIR], tempName[_MAX_DIR]; char outmode[] = "wb6 "; short nErr; // Clear any outstanding errors errno = EZERO; // Get memory for the join header structure if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL) { // Populate the header with all the match files if (genHeader (sourceDir, sourceName, extName, joinHdr, 0)) //@3 files { // Clear any outstanding errors errno = EZERO; // Generate the destination name if (strlen(sourceDir)) sprintf (destName, "%s\\%s%s", sourceDir, sourceName, extName); else sprintf (destName, ".\\%s%s", sourceName, extName); // Open the join file... if ((fileHdl = fopen (destName, "wb")) != NULL) { // ... and join in all the files. writeHeader ( joinHdr, fileHdl); concatFiles ( sourceDir, joinHdr, fileHdl); fclose (fileHdl); // Rename file as a temporary file if (strlen(sourceDir)) sprintf (tempName, "%s\\%s%s", sourceDir, sourceName, ".CAT"); else sprintf (tempName, ".\\%s%s", sourceName, ".CAT"); rename (destName, tempName); // Compress the file @2 if ((nErr = file_compress (sourceDir, sourceName, ".CAT", extName, outmode)) != 0) { free(joinHdr); String msg = String("Failed to compress ") + sourceName; throw std::exception ( msg.c_str() ); return nErr; } } } free(joinHdr); joinHdr = NULL; } else throw std::exception( "Insufficient memory" ); // For debugging only #ifdef DEBUG_MODE printHeader (stdout,joinHdr); #endif return errno; }