vector<string> DCppTemplate::GetFileList() { vector<string> result; if (!m_HaveFileNameFlag) return result; //no file name! for (auto fileStc : FindFileName()) { if (fileStc.Contain.length() > 0) result.push_back(fileStc.Contain); } return result; }
//----------------------------------------------------------------------------- // Purpose: // Input : *pFileName - // Output : FileNameHandle_t //----------------------------------------------------------------------------- FileNameHandle_t CUtlFilenameSymbolTable::FindOrAddFileName( const char *pFileName ) { if ( !pFileName ) { return NULL; } // find first FileNameHandle_t hFileName = FindFileName( pFileName ); if ( hFileName ) { return hFileName; } // Fix slashes+dotslashes and make lower case first.. char fn[ MAX_PATH ]; Q_strncpy( fn, pFileName, sizeof( fn ) ); Q_RemoveDotSlashes( fn ); #ifdef _WIN32 strlwr( fn ); #endif // Split the filename into constituent parts char basepath[ MAX_PATH ]; Q_ExtractFilePath( fn, basepath, sizeof( basepath ) ); char filename[ MAX_PATH ]; Q_strncpy( filename, fn + Q_strlen( basepath ), sizeof( filename ) ); // not found, lock and look again FileNameHandleInternal_t handle; m_lock.LockForWrite(); handle.path = m_StringPool.FindStringHandle( basepath ); handle.file = m_StringPool.FindStringHandle( filename ); if ( handle.path && handle.file ) { // found m_lock.UnlockWrite(); return *( FileNameHandle_t * )( &handle ); } // safely add it handle.path = m_StringPool.ReferenceStringHandle( basepath ); handle.file = m_StringPool.ReferenceStringHandle( filename ); m_lock.UnlockWrite(); return *( FileNameHandle_t * )( &handle ); }
int Tab(Node *resultHead, const char *info,\ const char *path, int ti,\ char *cmd) { int mode = 0; int i = 0; int len = 0; int times = 2; int flag = -1; int pos = -1; char tmp[BUFFSIZE] = {0}; struct stat buf = {0}; char child[BUFFSIZE] = {0}; const char *s = NULL; assert(NULL != resultHead); assert(NULL != path); strcpy(tmp, path); if('\0' == *tmp) { strcpy(tmp, "."); } //The path is exist or not exist? while((times--)\ && (-1 == (flag = lstat(tmp, &buf)))) { if(ENOENT != errno) { return -1; } if(times > 0) { s = GetTail(tmp, '/'); //If string tmp is not equal to it's //tail string s(is a part of string tmp //which contain the last '/' int tmp), //delete the tail(string s) of string //tmp (maybe the new string tmp[the old //string tmp delete tail s] is exist). //But if string tmp is equal to string s //means the string tmp(as same as string // path) doesn't contain a '/'(break). if(strcmp(tmp, s)) { tmp[strlen(tmp) - strlen(s)] = '\0'; } else { break; } } } //Get string child from the tail of //string path. strcpy(child, GetTail(path, '/')); //If 'times = 1', means the path isn't //contain '/' or the path is exist. /////And in this section string path is //equal to string tmp. //Else if 'times = -1', means the string //tmp is a part of string path. Maybe tmp //is exist or not exist. if(1 == times) { //If 'flag = -1', maybe the path is //a part of file name in current //directory. //Else if 'flag = 0', means the path //is exist. if(-1 == flag) { strcpy(tmp, "."); } else { if(! S_ISDIR(buf.st_mode)) { write(STDOUT_FILENO, " ", 1); strcat(cmd, " "); } else { if( ('\0' != path[0]) && ('/' != path[strlen(path) - 1]) && (('.' != path[strlen(path) - 1]) || ('.') == path[strlen(path) - 2])) { write(STDOUT_FILENO, "/", 1); strcat(cmd, "/"); } } s = GetTail(tmp, '/'); if( strcmp(path, ".") && ( ('.' != path[strlen(path) - 1]) || ('.') == path[strlen(path) - 2])) { //Because path is exist so click button //'Tab' means to get other file name of //the specified directory(name of 'path' //is also included in this directory). strcpy(child, "\0"); } //If path is not a directory. //If string path isn't equal to string //s(is tail of string path), means the //s(file) is exist in 'path-s'. //Else string path is a file exist in //current directory. if(! S_ISDIR(buf.st_mode)) { if(0 != strcmp(tmp, s)) { tmp[strlen(path) - strlen(s)] = '\0'; } else { strcpy(tmp, "."); } } } } else { //If 'flag = -1', the path and tmp //is not exist. //Else the tmp(delete the tail of path) //is exist. if(-1 == flag) { return -1; } } if( -1 == (flag = FindFileName(resultHead, tmp, child)) ) { return -1; } if((len = GetLen(resultHead)) > 0) { if(len > 1) { if(ti > 0) { if(-1 == ShowResult(resultHead, NULL,\ 1, cmd)) { return -1; } write(STDOUT_FILENO, info, strlen(info)); write(STDOUT_FILENO, cmd, strlen(cmd)); } } else { strcpy(tmp, GetVal(resultHead, 1)); flag = ( flag ? 0 : ('/' != tmp[strlen(tmp) - 1]) ); if( -1 == ShowResult(resultHead, child, flag, cmd) ) { return -1; } } } return 0; }
/**************************************************************************** * Function : main * Description: This is the main function for this program, it validates * the command line input and, if valid, it will either * encode a file using the LZSS algorithm or decode a * file encoded with the LZSS algorithm. * Parameters : argc - number of parameters * argv - parameter list * Effects : Encodes/Decodes input file * Returned : 0 for success, -1 for failure. errno will be set in the * event of a failure. ****************************************************************************/ int main(int argc, char *argv[]) { option_t *optList; option_t *thisOpt; FILE *fpIn; /* pointer to open input file */ FILE *fpOut; /* pointer to open output file */ modes_t mode; /* initialize data */ fpIn = NULL; fpOut = NULL; mode = ENCODE; /* parse command line */ optList = GetOptList(argc, argv, "cdi:o:h?"); thisOpt = optList; while (thisOpt != NULL) { switch(thisOpt->option) { case 'c': /* compression mode */ mode = ENCODE; break; case 'd': /* decompression mode */ mode = DECODE; break; case 'i': /* input file name */ if (fpIn != NULL) { fprintf(stderr, "Multiple input files not allowed.\n"); fclose(fpIn); if (fpOut != NULL) { fclose(fpOut); } FreeOptList(optList); return -1; } /* open input file as binary */ fpIn = fopen(thisOpt->argument, "rb"); if (fpIn == NULL) { perror("Opening input file"); if (fpOut != NULL) { fclose(fpOut); } FreeOptList(optList); return -1; } break; case 'o': /* output file name */ if (fpOut != NULL) { fprintf(stderr, "Multiple output files not allowed.\n"); fclose(fpOut); if (fpIn != NULL) { fclose(fpIn); } FreeOptList(optList); return -1; } /* open output file as binary */ fpOut = fopen(thisOpt->argument, "wb"); if (fpOut == NULL) { perror("Opening output file"); if (fpIn != NULL) { fclose(fpIn); } FreeOptList(optList); return -1; } break; case 'h': case '?': printf("Usage: %s <options>\n\n", FindFileName(argv[0])); printf("options:\n"); printf(" -c : Encode input file to output file.\n"); printf(" -d : Decode input file to output file.\n"); printf(" -i <filename> : Name of input file.\n"); printf(" -o <filename> : Name of output file.\n"); printf(" -h | ? : Print out command line options.\n\n"); printf("Default: %s -c -i stdin -o stdout\n", FindFileName(argv[0])); FreeOptList(optList); return 0; } optList = thisOpt->next; free(thisOpt); thisOpt = optList; } /* use stdin/out if no files are provided */ if (fpIn == NULL) { fpIn = stdin; } if (fpOut == NULL) { fpOut = stdout; } /* we have valid parameters encode or decode */ if (mode == ENCODE) { EncodeLZSS(fpIn, fpOut); } else { DecodeLZSS(fpIn, fpOut); } /* remember to close files */ fclose(fpIn); fclose(fpOut); return 0; }
int main(int argc, char **argv) { struct abl pl32; #if defined(EMSCRIPTEN) COMPILER sc32 = (COMPILER)Compile32; #else # if defined(__linux__) HINSTANCE lib = NULL; if (FileExists("./amxxpc32.so")) lib = dlmount("./amxxpc32.so"); else lib = dlmount("amxxpc32.so"); # elif defined(__APPLE__) HINSTANCE lib = dlmount("amxxpc32.dylib"); # else HINSTANCE lib = dlmount("amxxpc32.dll"); # endif if (!lib) { # if defined(__linux__) || defined(__APPLE__) printf("compiler failed to instantiate: %s\n", dlerror()); # else printf("compiler failed to instantiate: %d\n", GetLastError()); # endif exit(0); } COMPILER sc32 = (COMPILER)dlsym(lib, "Compile32"); pc_printf = (PRINTF)dlsym(lib, "pc_printf"); #endif //EMSCRIPTEN if (!sc32 || !pc_printf) { #if defined(__linux__) || defined(__APPLE__) printf("compiler failed to link: %p.\n",sc32); #else printf("compiler failed to link: %d.\n", GetLastError()); #endif exit(0); } pc_printf("AMX Mod X Compiler %s\n", AMXX_VERSION); pc_printf("Copyright (c) 1997-2006 ITB CompuPhase\n"); pc_printf("Copyright (c) 2004-2013 AMX Mod X Team\n\n"); if (argc < 2) { pc_printf("Usage: <file.sma> [options]\n"); pc_printf("Use -? or --help to see full options\n\n"); getchar(); exit(0); } if (!strcmp(argv[1], "-?") || !strcmp(argv[1], "--help")) { show_help(); pc_printf("Press any key to continue.\n"); getchar(); exit(0); } sc32(argc, argv); char *file = FindFileName(argc, argv); if (file == NULL) { pc_printf("Could not locate the output file.\n"); exit(0); } else if (strstr(file, ".asm")) { pc_printf("Assembler output succeeded.\n"); exit(0); } else { FILE *fp = fopen(file, "rb"); if (fp == NULL) { pc_printf("Could not locate output file %s (compile failed).\n", file); exit(0); } ReadFileIntoPl(&pl32, fp); pl32.cellsize = 4; fclose(fp); } unlink(file); ///////////// // COMPRSSION ///////////// CompressPl(&pl32); char *newfile = new char[strlen(file)+3]; strcpy(newfile, file); if (!strstr(file, ".amxx") && !strstr(file, ".AMXX")) strcat(newfile, "x"); FILE *fp = fopen(newfile, "wb"); if (!fp) { pc_printf("Error trying to write file %s.\n", newfile); exit(0); } BinPlugin bh32; Pl2Bh(&pl32, &bh32); try { static const int kEntries = 1; //entry is 4 ints and a byte static const int kEntrySize = (sizeof(int32_t) * 4) + sizeof(int8_t); BinaryWriter bw(fp); bw.WriteUInt32(MAGIC_HEADER2); bw.WriteUInt16(MAGIC_VERSION); bw.WriteUInt8(kEntries); //base header int baseaddr = sizeof(int32_t) + sizeof(int16_t) + sizeof(int8_t); //extend this by the entries we have baseaddr += kEntrySize * kEntries; bh32.offs = baseaddr; WriteBh(&bw, &bh32); bw.WriteChars(pl32.cmp, pl32.cmpsize); } catch (...) { fclose(fp); unlink(file); pc_printf("Error, failed to write binary\n"); #if !defined EMSCRIPTEN dlclose(lib); #endif exit(0); } fclose(fp); unlink(file); /* Without "Done" message "Compile and start Half-Life" and "Compile and upload" buttons in AMXX-Studio doesn't work. */ pc_printf("Done.\n"); #if !defined EMSCRIPTEN dlclose(lib); #endif exit(0); }