boolean_t get_full_path(char *orig_fn, unsigned int orig_len, char *full_fn, unsigned int *full_len, int max_len, uint4 *status) { char *cptr, *c1; char cwdbuf[MAX_FN_LEN + 1]; int cwd_len; int i, length; char *getcwd_res; error_def(ERR_FILENAMETOOLONG); if ('/' == *orig_fn) { /* The original path is already complete */ length = orig_len; memcpy(full_fn, orig_fn, length); } else { if (NULL == GETCWD(cwdbuf, sizeof(cwdbuf), getcwd_res)) { *status = errno; return FALSE; } cwd_len = strlen(cwdbuf); cptr = orig_fn; if (('.' == *cptr) && ('.' == *(cptr + 1))) { for (i = 1; ; ++i) { cptr += 2; if (('.' != *(cptr + 1)) || ('.' != *(cptr + 2))) break; ++cptr; } for (c1 = &cwdbuf[cwd_len - 1]; i > 0; --i) while ('/' != *c1) --c1; if ((length = (c1 - cwdbuf) + orig_len - (cptr - orig_fn)) + 1 > max_len) { *status = ERR_FILENAMETOOLONG; return FALSE; } memcpy(full_fn, cwdbuf, c1 - cwdbuf); memcpy(full_fn + (c1 - cwdbuf), cptr, orig_len - (cptr - orig_fn)); } else { if ('.' == *cptr && '/' == (*(cptr + 1))) cptr += 2; if ((length = cwd_len + 1 + orig_len - (cptr - orig_fn)) + 1 > max_len) { *status = ERR_FILENAMETOOLONG; return FALSE; } strcpy(full_fn, cwdbuf); full_fn[cwd_len] = '/'; memcpy(full_fn + cwd_len + 1, cptr, orig_len - (cptr - orig_fn)); } } *full_len = length; full_fn[length] = '\0'; return TRUE; }
QString QDir::canonicalPath() const { QString r; char cur[PATH_MAX]; char tmp[PATH_MAX]; GETCWD( cur, PATH_MAX ); if ( CHDIR(QFile::encodeName(dPath)) >= 0 ) { GETCWD( tmp, PATH_MAX ); r = QFile::decodeName(tmp); } CHDIR( cur ); slashify( r ); return r; }
/** Function to create a given directory. @internalComponent @released @param aSrcPath - path of the directory that needs to be created. @param aDelimiter - delimiter. */ void ImageReader::CreateSpecifiedDir(char* aSrcPath,const char* aDelimiter) { char* currWorkingDir = new char[_MAX_BUFFER_SIZE_]; string origPath; origPath.assign(aSrcPath); // get the current working directory and store in buffer. if( GETCWD(currWorkingDir,_MAX_BUFFER_SIZE_) == NULL ) { // throw an exception if unable to get current working directory information. throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "Failed to get the current working directory"); } else { char* cPtr = strtok(aSrcPath,aDelimiter); // check whether cPtr is a drive or a directory. if(IsDrive(cPtr)) { // if yes, then change the directory to cPtr. string changeToDrive ; changeToDrive.assign(cPtr); changeToDrive.append(aDelimiter); // change the current working directory to the specified directory. if( CHDIR(changeToDrive.c_str()) ) { // throw an exception if unable to change the directory specified. throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "Failed to change to the directory specified"); } } else { // if not,then create a cPtr directory. MKDIR(cPtr); // change the current working directory to cPtr. int r = CHDIR(cPtr); (void)r; } // repeat till cPtr is NULL. while (cPtr!=NULL) { if ((cPtr = strtok(NULL,aDelimiter)) != NULL) { // create the directory. MKDIR(cPtr); // change current working directory. int r = CHDIR(cPtr); (void)r; } } // revert back the working directory. int r = CHDIR(currWorkingDir); (void)r; // replace the source path with the original path information. strcpy(aSrcPath,origPath.c_str()); delete[] currWorkingDir; } }
/** * getCurrentDir * Get current directory * @return string */ static std::string getCurrentDir() { const size_t pathSize = 4096; char currentDir[pathSize]; // Check if we received the path if (GETCWD(currentDir, pathSize) != NULL) { return std::string(currentDir); } return std::string(""); }
std::string getCurrentDirectory() { std::string dir;// = ""; char path[1024+1]; GETCWD(path, 1024);//+path; dir = makePathNice(path); char c = dir[ dir.size() - 1 ]; if( c != '/' ) dir += "/"; return dir; }
mrb_value mrb_file__getwd(mrb_state *mrb, mrb_value klass) { mrb_value path; path = mrb_str_buf_new(mrb, MAXPATHLEN); if (GETCWD(RSTRING_PTR(path), MAXPATHLEN) == NULL) { mrb_sys_fail(mrb, "getcwd(2)"); } mrb_str_resize(mrb, path, strlen(RSTRING_PTR(path))); return path; }
mrb_value mrb_file__getwd(mrb_state *mrb, mrb_value klass) { mrb_value path; char buf[MAXPATHLEN], *utf8; if (GETCWD(buf, MAXPATHLEN) == NULL) { mrb_sys_fail(mrb, "getcwd(2)"); } utf8 = mrb_utf8_from_locale(buf, -1); path = mrb_str_new_cstr(mrb, utf8); mrb_utf8_free(utf8); return path; }
std::string FileSystemAbstraction::GetCwd() { std::string cwd = ""; #ifndef _WIN32 #define GETCWD getcwd #else #define GETCWD _getcwd #endif const size_t path_maxSize = 1024; char path[path_maxSize]; if (GETCWD(path, path_maxSize) != NULL) { cwd = path; } return cwd; }
/*--------------------------------------------------------------------------*/ wchar_t * scigetcwdW(int *err) { wchar_t *wcCurrentDir = NULL; #ifndef _MSC_VER char currentDir[PATH_MAX + 1]; if (GETCWD(currentDir, PATH_MAX) == NULL) { if ( getWarningMode() ) { sciprint(_("Can't get current directory.\n")); } *err = 1; } else { wcCurrentDir = to_wide_string(currentDir); *err = 0; } #else wchar_t wcdir[PATH_MAX + 1]; if ( _wgetcwd(wcdir, PATH_MAX) == NULL ) { if ( getWarningMode() ) { sciprint(_("Can't get current directory.\n")); } *err = 1; } else { wcCurrentDir = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(wcdir) + 1)); if (wcCurrentDir) { wcscpy(wcCurrentDir, wcdir); *err = 0; } } #endif return wcCurrentDir; }
QString QDir::currentDirPath() { QString result; STATBUF st; if ( STAT( ".", &st ) == 0 ) { char currentName[PATH_MAX]; if ( GETCWD( currentName, PATH_MAX ) != 0 ) result = QFile::decodeName(currentName); #if defined(DEBUG) if ( result.isNull() ) qWarning( "QDir::currentDirPath: getcwd() failed" ); #endif } else { #if defined(DEBUG) qWarning( "QDir::currentDirPath: stat(\".\") failed" ); #endif } slashify( result ); return result; }
void setzdir(mval *newdir, mval *full_path_of_newdir) { /* newdir is the directory to change to; NULL to set full_path_of_newdir to current working directory. * If full_path_of_newdir is non NULL, return the full path of the new directory in full_path_of_newdir. * NOTE : the full path of directory is stored in a static buffer which might get overwritten by the next call to setzdir. * Callers should save return value if needed. */ char directory[GTM_MAX_DIR_LEN], *getcwd_res, *err_str; uint4 length, status; assert(NULL != newdir || NULL != full_path_of_newdir); if (NULL != newdir) { MV_FORCE_STR(newdir); assert(SIZEOF(directory) > newdir->str.len); memcpy(directory, newdir->str.addr, newdir->str.len); directory[newdir->str.len] = '\0'; if (-1 == CHDIR(directory)) { /* On VMS, chdir(directory, 0) [actually, any non 1 value] is supposed to restore the process startup cwd at * exit (see help cc run). We've noticed that it doesn't behave the way it has been documented in the mumps * executable. Vinaya, 08/22/2001. */ err_str = STRERROR(errno); rts_error(VARLSTCNT(8) ERR_SETZDIR, 2, newdir->str.len, newdir->str.addr, ERR_TEXT, 2, LEN_AND_STR(err_str)); } } /* We need to find the full path of the current working directory because newdir might be a relative path, in which case * $ZDIR will show up as a relative path. */ if (NULL != full_path_of_newdir) { GETCWD(directory_buffer, SIZEOF(directory_buffer), getcwd_res); if (NULL != getcwd_res) { length = USTRLEN(directory_buffer); UNIX_ONLY(directory_buffer[length++] = '/';) } else
boolean TxCache::save(const wchar_t *path, const wchar_t *filename, int config) { if (!_cache.empty()) { /* dump cache to disk */ char cbuf[MAX_PATH]; boost::filesystem::wpath cachepath(path); boost::filesystem::create_directory(cachepath); /* Ugly hack to enable fopen/gzopen in Win9x */ #ifdef BOOST_WINDOWS_API wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(cachepath.wstring().c_str()); #else char curpath[MAX_PATH]; wcstombs(cbuf, cachepath.wstring().c_str(), MAX_PATH); GETCWD(MAX_PATH, curpath); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "wb1"); DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); if (gzfp) { /* write header to determine config match */ gzwrite(gzfp, &config, 4); std::map<uint64, TXCACHE*>::iterator itMap = _cache.begin(); while (itMap != _cache.end()) { uint8 *dest = (*itMap).second->info.data; uint32 destLen = (*itMap).second->size; uint16 format = (*itMap).second->info.format; /* to keep things simple, we save the texture data in a zlib uncompressed state. */ /* sigh... for those who cannot wait the extra few seconds. changed to keep * texture data in a zlib compressed state. if the GZ_TEXCACHE or GZ_HIRESTEXCACHE * option is toggled, the cache will need to be rebuilt. */ /*if (format & GR_TEXFMT_GZ) { dest = _gzdest0; destLen = _gzdestLen; if (dest && destLen) { if (uncompress(dest, &destLen, (*itMap).second->info.data, (*itMap).second->size) != Z_OK) { dest = NULL; destLen = 0; } format &= ~GR_TEXFMT_GZ; } }*/ if (dest && destLen) { /* texture checksum */ gzwrite(gzfp, &((*itMap).first), 8); /* other texture info */ gzwrite(gzfp, &((*itMap).second->info.width), 4); gzwrite(gzfp, &((*itMap).second->info.height), 4); gzwrite(gzfp, &format, 2); gzwrite(gzfp, &((*itMap).second->info.smallLodLog2), 4); gzwrite(gzfp, &((*itMap).second->info.largeLodLog2), 4); gzwrite(gzfp, &((*itMap).second->info.aspectRatioLog2), 4); gzwrite(gzfp, &((*itMap).second->info.tiles), 4); gzwrite(gzfp, &((*itMap).second->info.untiled_width), 4); gzwrite(gzfp, &((*itMap).second->info.untiled_height), 4); gzwrite(gzfp, &((*itMap).second->info.is_hires_tex), 1); gzwrite(gzfp, &destLen, 4); gzwrite(gzfp, dest, destLen); } itMap++; /* not ready yet */ /*if (_callback) (*_callback)(L"Total textures saved to HDD: %d\n", std::distance(itMap, _cache.begin()));*/ } gzclose(gzfp); } CHDIR(curpath); } return _cache.empty(); }
/* Gets the full path name for a given file name. Prepends the CWD, even if the file does not exist. */ boolean_t get_full_path(char *orig_fn, unsigned int orig_len, char *full_fn, unsigned int *full_len, int max_len, uint4 *status) { char *cptr, *c1; char cwdbuf[GTM_PATH_MAX]; int cwd_len; int i, length; char *getcwd_res; if ('/' == *orig_fn) { /* The original path is already complete */ if (max_len < orig_len) { *status = ERR_FILENAMETOOLONG; return FALSE; } length = orig_len; memcpy(full_fn, orig_fn, length); } else { GETCWD(cwdbuf, SIZEOF(cwdbuf), getcwd_res); if (NULL == getcwd_res) { *status = errno; return FALSE; } cwd_len = STRLEN(cwdbuf); cptr = orig_fn; if (('.' == *cptr) && ('.' == *(cptr + 1))) { for (i = 1; ; ++i) { cptr += 2; if (('.' != *(cptr + 1)) || ('.' != *(cptr + 2))) break; ++cptr; } for (c1 = &cwdbuf[cwd_len - 1]; i > 0; --i) while ('/' != *c1) --c1; if ((length = (int)((c1 - cwdbuf) + orig_len - (cptr - orig_fn))) + 1 > max_len) /* Warning - assignment */ { *status = ERR_FILENAMETOOLONG; return FALSE; } memcpy(full_fn, cwdbuf, c1 - cwdbuf); memcpy(full_fn + (c1 - cwdbuf), cptr, orig_len - (cptr - orig_fn)); } else { if ('.' == *cptr && '/' == (*(cptr + 1))) cptr += 2; if ((length = (int)(cwd_len + 1 + orig_len - (cptr - orig_fn))) + 1 > max_len) /* Warning - assignment */ { *status = ERR_FILENAMETOOLONG; return FALSE; } strcpy(full_fn, cwdbuf); full_fn[cwd_len] = '/'; memcpy(full_fn + cwd_len + 1, cptr, orig_len - (cptr - orig_fn)); } } *full_len = length; full_fn[length] = '\0'; return TRUE; }
int main(int argc, char *argv[]) { char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for(i = 1; i < argc; i++) { if (argv[i] == NULL) { continue; } if (argv[i][0] == '-') { if (strstr(argv[i], "-s")) { processSubs = 0; } else if (strstr(argv[i], "-e")) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11")) { useHttp11 = 1; } else if (strstr(argv[i], "-nossi")) { supportSsi = 0; } else if (strstr(argv[i], "-c")) { precalcChksum = 1; } else if((argv[i][1] == 'f') && (argv[i][2] == ':')) { strncpy(targetfile, &argv[i][3], sizeof(targetfile) - 1); targetfile[sizeof(targetfile) - 1] = 0; printf("Writing to file \"%s\"\n", targetfile); } else if ((strstr(argv[i], "-?")) || (strstr(argv[i], "-h"))) { print_usage(); exit(0); } } else if ((argv[i][0] == '/') && (argv[i][1] == '?') && (argv[i][2] == 0)) { print_usage(); exit(0); } else { strncpy(path, argv[i], sizeof(path)-1); path[sizeof(path)-1] = 0; } } if(!check_path(path, sizeof(path))) { printf("Invalid path: \"%s\"." NEWLINE, path); exit(-1); } GETCWD(appPath, MAX_PATH_LEN); /* if command line param or subdir named 'fs' not found spout usage verbiage */ if (!CHDIR_SUCCEEDED(CHDIR(path))) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); print_usage(); exit(-1); } CHDIR(appPath); printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); fclose(data_file); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"lwip/apps/fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ if (remove("fsdata.tmp") != 0) { printf("Warning: failed to delete fsdata.tmp\n"); } if (remove("fshdr.tmp") != 0) { printf("Warning: failed to delete fshdr.tmp\n"); } printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed); while (first_file != NULL) { struct file_entry* fe = first_file; first_file = fe->next; free(fe); } return 0; }
// ------------------------------------------------------ // Load the configuration file void LoadConfig(void) { FILE *in; int i; int Real_Palette_Idx; char FileName[MAX_PATH]; char KeyboardName[MAX_PATH]; signed char phony = -1; char Win_Coords[64]; SDL_Surface *Desktop = NULL; #ifdef __linux__ sprintf(FileName, "%s/.ptk.cfg", getenv("HOME")); #else sprintf(FileName, "%s"SLASH"ptk.cfg", ExePath); #endif memset(KeyboardName, 0, sizeof(KeyboardName)); in = fopen(FileName, "rb"); if(in != NULL) { // Reading and checking extension... char extension[10]; Read_Data(extension, sizeof(char), 9, in); if(strcmp(extension, "PROTCFGF") == 0) { Read_Data_Swap(&Current_Edit_Steps, sizeof(Current_Edit_Steps), 1, in); Read_Data_Swap(&patt_highlight, sizeof(patt_highlight), 1, in); Read_Data_Swap(&AUDIO_Milliseconds, sizeof(AUDIO_Milliseconds), 1, in); #if defined(__NO_MIDI__) Read_Data(&phony, sizeof(phony), 1, in); #else Read_Data(&c_midiin, sizeof(c_midiin), 1, in); #endif #if defined(__NO_MIDI__) Read_Data(&phony, sizeof(phony), 1, in); #else Read_Data(&c_midiout, sizeof(c_midiout), 1, in); #endif Read_Data_Swap(&MouseWheel_Multiplier, sizeof(MouseWheel_Multiplier), 1, in); Read_Data(&Rows_Decimal, sizeof(Rows_Decimal), 1, in); Read_Data(&FullScreen, sizeof(FullScreen), 1, in); for(i = 0; i < NUMBER_COLORS; i++) { Real_Palette_Idx = Idx_Palette[i]; Read_Data(&Ptk_Palette[Real_Palette_Idx].r, sizeof(char), 1, in); Read_Data(&Ptk_Palette[Real_Palette_Idx].g, sizeof(char), 1, in); Read_Data(&Ptk_Palette[Real_Palette_Idx].b, sizeof(char), 1, in); Ptk_Palette[Real_Palette_Idx].unused = 0; } Read_Data(&See_Prev_Next_Pattern, sizeof(See_Prev_Next_Pattern), 1, in); Read_Data_Swap(&Beveled, sizeof(Beveled), 1, in); Read_Data_Swap(&Continuous_Scroll, sizeof(Continuous_Scroll), 1, in); Read_Data(&AutoSave, sizeof(AutoSave), 1, in); Read_Data(&AutoBackup, sizeof(AutoBackup), 1, in); Read_Data(&Dir_Mods, sizeof(Dir_Mods), 1, in); Read_Data(&Dir_Instrs, sizeof(Dir_Instrs), 1, in); Read_Data(&Dir_Presets, sizeof(Dir_Presets), 1, in); Read_Data(&Dir_Reverbs, sizeof(Dir_Reverbs), 1, in); Read_Data(&Dir_MidiCfg, sizeof(Dir_MidiCfg), 1, in); Read_Data(&Dir_Patterns, sizeof(Dir_Patterns), 1, in); Read_Data(&Dir_Samples, sizeof(Dir_Samples), 1, in); Read_Data(KeyboardName, MAX_PATH, 1, in); Read_Data(&rawrender_32float, sizeof(char), 1, in); Read_Data(&rawrender_multi, sizeof(char), 1, in); Read_Data(&rawrender_target, sizeof(char), 1, in); Read_Data(&Large_Patterns, sizeof(char), 1, in); Read_Data(&Scopish_LeftRight, sizeof(char), 1, in); Read_Data(&Paste_Across, sizeof(char), 1, in); Read_Data(&Jazz_Edit, sizeof(char), 1, in); Read_Data(&Accidental, sizeof(char), 1, in); Read_Data(&Use_Shadows, sizeof(char), 1, in); Read_Data(&Global_Patterns_Font, sizeof(char), 1, in); Read_Data(&metronome_magnify, sizeof(int), 1, in); if(Large_Patterns) { Set_Pattern_Size(); userscreen = USER_SCREEN_LARGE_PATTERN; curr_tab_highlight = USER_SCREEN_DISKIO_EDIT; } else { Set_Pattern_Size(); userscreen = USER_SCREEN_DISKIO_EDIT; curr_tab_highlight = USER_SCREEN_DISKIO_EDIT; } // Reload the compelte midi automation config Load_MidiCfg_Data(Read_Data, Read_Data_Swap, in); Read_Data_Swap(&Cur_Width, sizeof(int), 1, in); Read_Data_Swap(&Cur_Height, sizeof(int), 1, in); Read_Data_Swap(&Cur_Left, sizeof(int), 1, in); Read_Data_Swap(&Cur_Top, sizeof(int), 1, in); Desktop = SDL_SetVideoMode(0, 0, 0, 0); // Check if the coords are too big if(Cur_Width > SDL_GetVideoSurface()->w) { Cur_Left = 0; Cur_Width = SDL_GetVideoSurface()->w; } if(Cur_Height > SDL_GetVideoSurface()->h) { Cur_Top = 0; Cur_Height = SDL_GetVideoSurface()->h; } if(Cur_Left == -1 || Cur_Top == -1) { Cur_Left = SDL_GetVideoSurface()->w; Cur_Top = SDL_GetVideoSurface()->h; Cur_Left = (Cur_Left - Cur_Width) / 2; Cur_Top = (Cur_Top - Cur_Height) / 2; } SDL_FreeSurface(Desktop); sprintf(Win_Coords, "SDL_VIDEO_WINDOW_POS=%d,%d", Cur_Left, Cur_Top); SDL_putenv(Win_Coords); } fclose(in); } sprintf(Keyboard_Name, "%s", KeyboardName); // Set default dirs if nothing if(!strlen(Dir_Mods)) { GETCWD(Dir_Mods, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Mods, "\\modules"); #else strcat(Dir_Mods, "/modules"); #endif } if(!strlen(Dir_Instrs)) { GETCWD(Dir_Instrs, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Instrs, "\\instruments"); #else strcat(Dir_Instrs, "/instruments"); #endif } if(!strlen(Dir_Presets)) { GETCWD(Dir_Presets, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Presets, "\\presets"); #else strcat(Dir_Presets, "/presets"); #endif } if(!strlen(Dir_Reverbs)) { GETCWD(Dir_Reverbs, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Reverbs, "\\reverbs"); #else strcat(Dir_Reverbs, "/reverbs"); #endif } if(!strlen(Dir_MidiCfg)) { GETCWD(Dir_MidiCfg, MAX_PATH); #if defined(__WIN32__) strcat(Dir_MidiCfg, "\\midicfgs"); #else strcat(Dir_MidiCfg, "/midicfgs"); #endif } if(!strlen(Dir_Patterns)) { GETCWD(Dir_Patterns, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Patterns, "\\patterns"); #else strcat(Dir_Patterns, "/patterns"); #endif } if(!strlen(Dir_Samples)) { GETCWD(Dir_Samples, MAX_PATH); #if defined(__WIN32__) strcat(Dir_Samples, "\\samples"); #else strcat(Dir_Samples, "/samples"); #endif } cur_dir = Dir_Mods; }
const char* FindConfigFile(const char *name) { char buffer[4096]; #ifdef _WIN32 #define PATH_SEP ";" #define FILE_SEP '\\' #define EXE_NAME "vbam.exe" #else // ! _WIN32 #define PATH_SEP ":" #define FILE_SEP '/' #define EXE_NAME "vbam" #endif // ! _WIN32 if (GETCWD(buffer, 2048)) { } if (FileExists(name)) { return name; } if (homeDir) { sprintf(path, "%s%c%s%c%s", homeDir, FILE_SEP, DOT_DIR, FILE_SEP, name); if (FileExists(path)) { return path; } } #ifdef _WIN32 char *home = getenv("USERPROFILE"); if (home != NULL) { sprintf(path, "%s%c%s", home, FILE_SEP, name); if (FileExists(path)) { return path; } } if (!strchr(arg0, '/') && !strchr(arg0, '\\')) { char *path = getenv("PATH"); if (path != NULL) { strncpy(buffer, path, 4096); buffer[4095] = 0; char *tok = strtok(buffer, PATH_SEP); while (tok) { sprintf(path, "%s%c%s", tok, FILE_SEP, EXE_NAME); if (FileExists(path)) { char path2[2048]; sprintf(path2, "%s%c%s", tok, FILE_SEP, name); if (FileExists(path2)) { return path2; } } tok = strtok(NULL, PATH_SEP); } } } else { // executable is relative to some directory strcpy(buffer, arg0); char *p = strrchr(buffer, FILE_SEP); if (p) { *p = 0; sprintf(path, "%s%c%s", buffer, FILE_SEP, name); if (FileExists(path)) { return path; } } } #else // ! _WIN32 sprintf(path, "%s%c%s", PKGDATADIR, FILE_SEP, name); if (FileExists(path)) { return path; } sprintf(path, "%s%c%s", SYSCONFDIR, FILE_SEP, name); if (FileExists(path)) { return path; } #endif // ! _WIN32 return 0; }
extern "C" WIN32_EXPORT void initkconv(void) { //kconvの場所を調べる PyObject *ImpModule,*PythonPrefix,*FindModule; ImpModule = PyImport_ImportModule("imp"); FindModule = PyObject_GetAttrString(ImpModule,"find_module"); PythonPrefix = PyTuple_GetItem(PyEval_CallObject(FindModule,Py_BuildValue("(s)","kconv")),1); char *tmpprefix; PyArg_Parse(PythonPrefix,"s",&tmpprefix); char *dir = GETCWD(NULL,MAXPATHLEN+1); // printf("dir(%s),tmpprefix(%s)\n",dir,tmpprefix); #ifdef WIN32 # define SHARED_PREFIX ".pyd" # define PATHCHR '\\' #else // UNIX の SHARED_PREFIXはconfigure & Makefile で定義される # define PATHCHR '/' #endif char *firstpos = strchr(tmpprefix,PATHCHR); char *lastpos = strrchr(tmpprefix,PATHCHR); if( firstpos == tmpprefix ) sprintf(prefix,"%s",tmpprefix); else{ if(lastpos == NULL) sprintf(prefix,"%s%c",dir,PATHCHR); else sprintf(prefix,"%s%c%s",dir,PATHCHR,tmpprefix); } // printf("tmpprefix(%s) , prefix(%s)\n",tmpprefix,prefix); //sys moduleを呼出し、pathにkconvの場所を追加 PyObject *SysModule,*SysDict,*SysPath; SysModule = PyImport_ImportModule("sys"); SysDict = PyModule_GetDict(SysModule); SysPath = PyDict_GetItemString(SysDict,"path"); PyList_Append(SysPath,Py_BuildValue("s",prefix)); //Kconvで使用する定数を登録 PyObject *module,*dict; PyObject *tobject; //一時的に使い回すPyObject変数 module = Py_InitModule("kconv",KconvtypeMethods); dict = PyModule_GetDict(module); //version情報 if((tobject = PyString_FromString(version))){ PyDict_SetItemString(dict,"__version__",tobject); Py_XDECREF(tobject); } unsigned int ccc; //Temporary counter //inputerが使う定数 for(ccc = 0;ccc < sizeof(InputerTable)/sizeof(PInputer);ccc++){ Inputer *tobject2 = InputerTable[ccc](); //一時的に使い回すPyObject変数 ADDDICTS(tobject2->getCode(),(char *)tobject2->getName()); delete tobject2; }; //outputerが使う定数:いまのところ無駄 for(ccc = 0;ccc < sizeof(OutputerTable)/sizeof(POutputer)/2;ccc++){ Outputer *tobject2 = OutputerTable[ccc][0](_LF); //一時的に使い回すPyObject変数 ADDDICTS(tobject2->getCode(),(char *)tobject2->getName()); delete tobject2; }; //checkerが使う定数 for(ccc = 0;ccc < sizeof(CheckerTable)/sizeof(PChecker);ccc++){ Checker *tobject2 = CheckerTable[ccc](); //一時的に使い回すPyObject変数 ADDDICTS(tobject2->getCode(),(char *)tobject2->getName()); delete tobject2; }; ADDDICTS(_ZENKAKU,"ZENKAKU"); ADDDICTS(_HANKAKU,"HANKAKU"); ADDDICTS(_LINE,"LINE"); ADDDICTS(_WHOLE,"WHOLE"); ADDDICTS(_LF,"LF"); ADDDICTS(_AUTO,"AUTO"); ADDDICTS(_UNKNOWN,"UNKNOWN"); ADDDICTS(_CR,"CR"); ADDDICTS(_CL,"CL"); // printf("Loading Kconvtools\n"); //Kconvtoolsの読み込み PyObject *ToolsModule,*ToolsDict; ToolsModule = PyImport_ImportModule("kconvtools"); // printf("Module at %X\n",ToolsModule); if(!ToolsModule) exit(0); ToolsDict = PyModule_GetDict(ToolsModule); /* Py_XDECREF(ToolsModule); Py_XDECREF(ToolsDict); Py_XDECREF(ImpModule); Py_XDECREF(PythonPrefix); Py_XDECREF(FindModule); */ //I must not decref Sys // Py_XDECREF(SysDict); // Py_XDECREF(SysModule); ErrorObject = Py_BuildValue("s","kconv.error"); PyDict_SetItemString(dict,"error",ErrorObject); if (PyErr_Occurred()) Py_FatalError("can't initialize module kconv"); return; }
int handleclient(int conn) { char *basedir; char *clientdir; mp3entry *mp3buf; FILE *stream; if ((stream = fdopen(conn, "r+")) == NULL || !readrequest(stream)) { debug(1, "error while reading client request"); fclose(stream); return(EXIT_FAILURE); } debug(1, "requested path %s", conf.path); GETCWD(basedir); if(chdir(conf.path)) die("incorrect dir"); GETCWD(clientdir); debug(1, "doing security checks"); if(strncmp(basedir, clientdir, strlen(basedir) - 1)) { fclose(stream); debug(1, "basedir %s, clientdir %s", basedir, clientdir); die("client tried to break out of base directory"); } debug(1, "looking for mp3 files in subdirectory %s", conf.path); if(!MODE_ISSET(MODE_SINGLE)) { getfiles("."); } else if(validfile(conf.filename, clientdir, &mp3buf)) { addentry(&root, mp3buf); } if(!root) die("no files"); else debug(1, "%d MP3 file(s) found", countentries(root)); if(!MODE_ISSET(MODE_INDEX) && !conf.order) { debug(1, "shuffling mp3 files"); shuffleentries(); } if(conf.debuglevel > 2) { debug(1, "listing mp3 files"); dumpentries(); } if(MODE_ISSET(MODE_INDEX)) { debug(1, "entering HTTP mode"); fprintf(stream, HTTPSERVMSG, AMPLE_VERSION); fflush(stream); createhtml(stream,(clientdir + strlen(basedir)),(strlen(clientdir) + 1)); } else if(MODE_ISSET(MODE_SINGLE)) { debug(1, "entering MP3-Single mode"); fprintf(stream, SINGLESERVMSG, AMPLE_VERSION, root->filesize); fflush(stream); playfile(stream, root); } else if (MODE_ISSET(MODE_METADATA)) { debug(1, "entering MP3-Metadata mode"); fprintf(stream, SHOUTSERVMSG, AMPLE_VERSION, conf.servername, BYTESBETWEENMETA); fflush(stream); playlist(stream); } else { debug(1, "entering MP3-Basic mode"); fprintf(stream, BASICSERVMSG, AMPLE_VERSION); fflush(stream); playlist(stream); } fclose(stream); clearlist(root); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for (i = 1; i < argc; i++) { if (argv[i] == NULL) { continue; } if (argv[i][0] == '-') { if (strstr(argv[i], "-svr:") == argv[i]) { snprintf(serverIDBuffer, sizeof(serverIDBuffer), "Server: %s\r\n", &argv[i][5]); serverID = serverIDBuffer; printf("Using Server-ID: \"%s\"\n", serverID); } else if (strstr(argv[i], "-s") == argv[i]) { processSubs = 0; } else if (strstr(argv[i], "-e") == argv[i]) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11") == argv[i]) { useHttp11 = 1; } else if (strstr(argv[i], "-nossi") == argv[i]) { supportSsi = 0; } else if (strstr(argv[i], "-c") == argv[i]) { precalcChksum = 1; } else if (strstr(argv[i], "-f:") == argv[i]) { strncpy(targetfile, &argv[i][3], sizeof(targetfile) - 1); targetfile[sizeof(targetfile) - 1] = 0; printf("Writing to file \"%s\"\n", targetfile); } else if (strstr(argv[i], "-m") == argv[i]) { includeLastModified = 1; } else if (strstr(argv[i], "-defl") == argv[i]) { #if MAKEFS_SUPPORT_DEFLATE char* colon = strstr(argv[i], ":"); if (colon) { if (colon[1] != 0) { int defl_level = atoi(&colon[1]); if ((defl_level >= 0) && (defl_level <= 10)) { deflate_level = defl_level; } else { printf("ERROR: deflate level must be [0..10]" NEWLINE); exit(0); } } } deflateNonSsiFiles = 1; printf("Deflating all non-SSI files with level %d (but only if size is reduced)" NEWLINE, deflate_level); #else printf("WARNING: Deflate support is disabled\n"); #endif } else if ((strstr(argv[i], "-?")) || (strstr(argv[i], "-h"))) { print_usage(); exit(0); } } else if ((argv[i][0] == '/') && (argv[i][1] == '?') && (argv[i][2] == 0)) { print_usage(); exit(0); } else { strncpy(path, argv[i], sizeof(path)-1); path[sizeof(path)-1] = 0; } } if (!check_path(path, sizeof(path))) { printf("Invalid path: \"%s\"." NEWLINE, path); exit(-1); } GETCWD(appPath, MAX_PATH_LEN); /* if command line param or subdir named 'fs' not found spout usage verbiage */ if (!CHDIR_SUCCEEDED(CHDIR(path))) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); print_usage(); exit(-1); } CHDIR(appPath); printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); fclose(data_file); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"lwip/apps/fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); /* define FS_FILE_FLAGS_HEADER_INCLUDED to 1 if not defined (compatibility with older httpd/fs) */ fprintf(data_file, "#ifndef FS_FILE_FLAGS_HEADER_INCLUDED" NEWLINE "#define FS_FILE_FLAGS_HEADER_INCLUDED 1" NEWLINE "#endif" NEWLINE); /* define FS_FILE_FLAGS_HEADER_PERSISTENT to 0 if not defined (compatibility with older httpd/fs: wasn't supported back then) */ fprintf(data_file, "#ifndef FS_FILE_FLAGS_HEADER_PERSISTENT" NEWLINE "#define FS_FILE_FLAGS_HEADER_PERSISTENT 0" NEWLINE "#endif" NEWLINE); /* define alignment defines */ #if ALIGN_PAYLOAD fprintf(data_file, "/* FSDATA_FILE_ALIGNMENT: 0=off, 1=by variable, 2=by include */" NEWLINE "#ifndef FSDATA_FILE_ALIGNMENT" NEWLINE "#define FSDATA_FILE_ALIGNMENT 0" NEWLINE "#endif" NEWLINE); #endif fprintf(data_file, "#ifndef FSDATA_ALIGN_PRE" NEWLINE "#define FSDATA_ALIGN_PRE" NEWLINE "#endif" NEWLINE); fprintf(data_file, "#ifndef FSDATA_ALIGN_POST" NEWLINE "#define FSDATA_ALIGN_POST" NEWLINE "#endif" NEWLINE); #if ALIGN_PAYLOAD fprintf(data_file, "#if FSDATA_FILE_ALIGNMENT==2" NEWLINE "#include \"fsdata_alignment.h\"" NEWLINE "#endif" NEWLINE); #endif sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ if (remove("fsdata.tmp") != 0) { printf("Warning: failed to delete fsdata.tmp\n"); } if (remove("fshdr.tmp") != 0) { printf("Warning: failed to delete fshdr.tmp\n"); } printf(NEWLINE "Processed %d files - done." NEWLINE, filesProcessed); #if MAKEFS_SUPPORT_DEFLATE if (deflateNonSsiFiles) { printf("(Deflated total byte reduction: %d bytes -> %d bytes (%.02f%%)" NEWLINE, (int)overallDataBytes, (int)deflatedBytesReduced, (float)((deflatedBytesReduced*100.0)/overallDataBytes)); } #endif printf(NEWLINE); while (first_file != NULL) { struct file_entry* fe = first_file; first_file = fe->next; free(fe); } return 0; }
void Set_Current_Dir(void) { char filename[MAX_PATH]; #if defined(__AMIGAOS4__) || defined(__AROS__) char *tmp = Dir_Act[0] ? &Dir_Act[strlen(Dir_Act) - 1] : NULL; if (tmp && *tmp == '/') *tmp = 0; if (strrchr(Dir_Act, '/') == Dir_Act && !strcmp(Get_FileName(lt_curr[Scopish]), "..")) { switch(Scopish) { case SCOPE_ZONE_MOD_DIR: strcpy(Dir_Mods, "/"); break; case SCOPE_ZONE_INSTR_DIR: strcpy(Dir_Instrs, "/"); break; case SCOPE_ZONE_PRESET_DIR: strcpy(Dir_Presets, "/"); break; case SCOPE_ZONE_REVERB_DIR: strcpy(Dir_Reverbs, "/"); break; case SCOPE_ZONE_MIDICFG_DIR: strcpy(Dir_MidiCfg, "/"); break; case SCOPE_ZONE_PATTERN_DIR: strcpy(Dir_Patterns, "/"); break; case SCOPE_ZONE_SAMPLE_DIR: strcpy(Dir_Samples, "/"); break; } return; } if (tmp && *tmp == 0) { *tmp = '/'; } if (!strcmp(Dir_Act, "/")) { strcpy(filename, "/"); strcat(filename, Get_FileName(lt_curr[Scopish])); } else { strcpy(filename, Get_FileName(lt_curr[Scopish])); } #else strcpy(filename, Get_FileName(lt_curr[Scopish])); #endif switch(Scopish) { case SCOPE_ZONE_MOD_DIR: CHDIR(filename); GETCWD(Dir_Mods, MAX_PATH); break; case SCOPE_ZONE_INSTR_DIR: CHDIR(filename); GETCWD(Dir_Instrs, MAX_PATH); break; case SCOPE_ZONE_PRESET_DIR: CHDIR(filename); GETCWD(Dir_Presets, MAX_PATH); break; case SCOPE_ZONE_REVERB_DIR: CHDIR(filename); GETCWD(Dir_Reverbs, MAX_PATH); break; case SCOPE_ZONE_MIDICFG_DIR: CHDIR(filename); GETCWD(Dir_MidiCfg, MAX_PATH); break; case SCOPE_ZONE_PATTERN_DIR: CHDIR(filename); GETCWD(Dir_Patterns, MAX_PATH); break; case SCOPE_ZONE_SAMPLE_DIR: CHDIR(filename); GETCWD(Dir_Samples, MAX_PATH); break; } }
int main(int argc, char **argv) { char buf[1024], *usage = "usage: deepstripper-gtk [-d[ebug]] [-h[elp]] [-o[utput] <path>]\n" " [-dps12|-dps16 <path>] [-e[xtract] <project>]\n"; GtkWidget *vbox, *men, *paned, *note, *frame, *scroll; GtkItemFactory *fac; GtkAccelGroup *acc; int i, dps = -1; for (i=1; i<argc; i++) { if (strcmp(argv[i], "-d")==0) { g_dbg = g_dbg<<1 | 1; } else if (strncmp(argv[i], "-h", 2)==0) { g_print("%s", usage); return 0; } } gtk_init(&argc, &argv); g_main = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(g_main), 600, 400); set_title("?", GETCWD(buf, sizeof(buf)), ""); g_signal_connect(G_OBJECT(g_main), "delete_event", G_CALLBACK(quit), NULL); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(g_main), vbox); gtk_widget_show(vbox); acc = gtk_accel_group_new(); fac = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<deepstripper-main>", acc); gtk_item_factory_create_items(fac, MENU_SIZE, root_menu, 0); men = gtk_item_factory_get_widget(fac, "<deepstripper-main>"); gtk_box_pack_start(GTK_BOX(vbox), men, FALSE, FALSE, 0); gtk_window_add_accel_group(GTK_WINDOW(g_main), acc); gtk_widget_show(men); g_multi = gtk_item_factory_get_item(fac, "/Multi"); paned = gtk_hpaned_new(); gtk_container_set_border_width(GTK_CONTAINER(paned), 5); gtk_box_pack_start(GTK_BOX(vbox), paned, TRUE, TRUE, 0); gtk_widget_show(paned); note = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(note), GTK_POS_BOTTOM); gtk_notebook_set_show_border(GTK_NOTEBOOK(note), TRUE); gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(note), TRUE); gtk_widget_set_size_request(note, 150, 200); gtk_paned_pack1(GTK_PANED(paned), note, TRUE, FALSE); gtk_widget_show(note); for (i=0; i<N_TABS; i++) { GtkWidget *l = gtk_label_new(g_tabs[i].tab); gtk_widget_show(l); gtk_notebook_append_page(GTK_NOTEBOOK(note), make_list(g_tabs[i].data, i), l); } frame = gtk_frame_new("Item properties:"); gtk_widget_set_size_request(frame, 150, 200); gtk_paned_pack2(GTK_PANED(paned), frame, TRUE, FALSE); gtk_widget_show(frame); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(frame), scroll); gtk_widget_show(scroll); g_info = gtk_label_new(DEFAULT_INFO); gtk_label_set_justify(GTK_LABEL(g_info), GTK_JUSTIFY_LEFT); gtk_label_set_line_wrap(GTK_LABEL(g_info), FALSE); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), g_info); gtk_widget_show(g_info); g_stat = gtk_statusbar_new(); gtk_box_pack_end(GTK_BOX(vbox), g_stat, FALSE, FALSE, 0); gtk_widget_show(g_stat); set_status("status"); // Display everything gtk_widget_show(g_main); // Process all other command line switches for (i=1; i<argc; i++) { if (strncmp(argv[i], "-o", 2)==0) { if (chdir(argv[++i])) about_box("unable to change directory"); else set_title(NULL, GETCWD(buf, sizeof(buf)), NULL); } else if (strncmp(argv[i], "-dps", 4)==0) { open_backup(argv[i], argv[i+1]); if (strcmp(argv[i], "-dps12")==0) dps = AOSP_DPS12; else dps = AOSP_DPS16; ++i; } else if (strncmp(argv[i], "-e", 2)==0) { if (dps<0) about_box("No backup specified to extract from"); else { open_project(dps, akaiosdisk_project_byname(&g_disk, argv[++i])); select_tracks(MID_SELNOE); extract_tracks(); } } else if (strncmp(argv[i], "-d", 2)==0 || strncmp(argv[i], "-h", 2)==0) { ; // Skip earlier opts } else { about_box(usage); } } // Run message pump.. gtk_main(); return 0; }
int main(int argc, char **argv) { char * base = uninit; char * bp = uninit; char * cp = uninit; char * cwd = 0; char * group = 0; char * linkname = 0; char * linkprefix = 0; char * name = uninit; char * owner = 0; char * todir = uninit; char * toname = uninit; int bnlen = -1; int cc = 0; int dodir = 0; int dolink = 0; int dorelsymlink = 0; int dotimes = 0; int exists = 0; int fromfd = -1; int len = -1; int lplen = 0; int onlydir = 0; int opt = -1; int tdlen = -1; int tofd = -1; int wc = -1; mode_t mode = 0755; uid_t uid = -1; gid_t gid = -1; struct stat sb; struct stat tosb; struct utimbuf utb; char buf[BUFSIZ]; program = strrchr(argv[0], '/'); if (!program) program = strrchr(argv[0], '\\'); program = program ? program+1 : argv[0]; while ((opt = getopt(argc, argv, "C:DdlL:Rm:o:g:t")) != EOF) { switch (opt) { case 'C': cwd = optarg; break; case 'D': onlydir = 1; break; case 'd': dodir = 1; break; case 'l': dolink = 1; break; case 'L': linkprefix = optarg; lplen = strlen(linkprefix); dolink = 1; break; case 'R': dolink = dorelsymlink = 1; break; case 'm': mode = strtoul(optarg, &cp, 8); if (mode == 0 && cp == optarg) usage(); break; case 'o': owner = optarg; break; case 'g': group = optarg; break; case 't': dotimes = 1; break; default: usage(); } } argc -= optind; argv += optind; if (argc < 2 - onlydir) usage(); todir = argv[argc-1]; if ((stat(todir, &sb) < 0 || !S_ISDIR(sb.st_mode)) && mkdirs(todir, 0777) < 0) { fail("cannot mkdir -p %s", todir); } if (onlydir) return 0; if (!cwd) { cwd = GETCWD(0, PATH_MAX); if (!cwd) fail("could not get CWD"); } /* make sure we can get into todir. */ xchdir(todir); todir = GETCWD(0, PATH_MAX); if (!todir) fail("could not get CWD in todir"); tdlen = strlen(todir); /* back to original directory. */ xchdir(cwd); uid = owner ? touid(owner) : -1; gid = group ? togid(group) : -1; while (--argc > 0) { name = *argv++; len = strlen(name); base = xbasename(name); bnlen = strlen(base); toname = (char*)xmalloc(tdlen + 1 + bnlen + 1); sprintf(toname, "%s/%s", todir, base); retry: exists = (lstat(toname, &tosb) == 0); if (dodir) { /* -d means create a directory, always */ if (exists && !S_ISDIR(tosb.st_mode)) { int rv = unlink(toname); if (rv) fail("cannot unlink %s", toname); exists = 0; } if (!exists && mkdir(toname, mode) < 0) { /* we probably have two nsinstall programs in a race here. */ if (errno == EEXIST && !stat(toname, &sb) && S_ISDIR(sb.st_mode)) { fprintf(stderr, "directory creation race: %s\n", toname); goto retry; } fail("cannot make directory %s", toname); } if ((owner || group) && chown(toname, uid, gid) < 0) fail("cannot change owner of %s", toname); } else if (dolink) { if (*name == '/') { /* source is absolute pathname, link to it directly */ linkname = 0; } else { if (linkprefix) { /* -L implies -l and prefixes names with a $cwd arg. */ len += lplen + 1; linkname = (char*)xmalloc(len + 1); sprintf(linkname, "%s/%s", linkprefix, name); } else if (dorelsymlink) { /* Symlink the relative path from todir to source name. */ linkname = (char*)xmalloc(PATH_MAX); if (*todir == '/') { /* todir is absolute: skip over common prefix. */ lplen = relatepaths(todir, cwd, linkname); strcpy(linkname + lplen, name); } else { /* todir is named by a relative path: reverse it. */ reversepath(todir, name, len, linkname); xchdir(cwd); } len = strlen(linkname); } name = linkname; } /* Check for a pre-existing symlink with identical content. */ if (exists && (!S_ISLNK(tosb.st_mode) || readlink(toname, buf, sizeof buf) != len || strncmp(buf, name, len) != 0)) { int rmrv; rmrv = (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname); if (rmrv < 0) { fail("destination exists, cannot remove %s", toname); } exists = 0; } if (!exists && symlink(name, toname) < 0) { if (errno == EEXIST) { fprintf(stderr, "symlink creation race: %s\n", toname); fail("symlink was attempted in working directory %s " "from %s to %s.\n", cwd, name, toname); goto retry; } diagnosePath(toname); fail("cannot make symbolic link %s", toname); } #ifdef HAVE_LCHOWN if ((owner || group) && lchown(toname, uid, gid) < 0) fail("cannot change owner of %s", toname); #endif if (linkname) { free(linkname); linkname = 0; } } else { /* Copy from name to toname, which might be the same file. */ fromfd = open(name, O_RDONLY); if (fromfd < 0 || fstat(fromfd, &sb) < 0) fail("cannot access %s", name); if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0)) { int rmrv; rmrv = (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname); if (rmrv < 0) { fail("destination exists, cannot remove %s", toname); } } tofd = open(toname, O_CREAT | O_WRONLY, 0666); if (tofd < 0) fail("cannot create %s", toname); bp = buf; while ((cc = read(fromfd, bp, sizeof buf)) > 0) { while ((wc = write(tofd, bp, cc)) > 0) { if ((cc -= wc) == 0) break; bp += wc; } if (wc < 0) fail("cannot write to %s", toname); } if (cc < 0) fail("cannot read from %s", name); if (ftruncate(tofd, sb.st_size) < 0) fail("cannot truncate %s", toname); /* ** On OpenVMS we can't chmod() until the file is closed, and we ** have to utime() last since fchown/chmod alter the timestamps. */ #ifndef VMS if (dotimes) { utb.actime = sb.st_atime; utb.modtime = sb.st_mtime; if (utime(toname, &utb) < 0) fail("cannot set times of %s", toname); } #ifdef HAVE_FCHMOD if (fchmod(tofd, mode) < 0) #else if (chmod(toname, mode) < 0) #endif fail("cannot change mode of %s", toname); #endif if ((owner || group) && fchown(tofd, uid, gid) < 0) fail("cannot change owner of %s", toname); /* Must check for delayed (NFS) write errors on close. */ if (close(tofd) < 0) fail("close reports write error on %s", toname); close(fromfd); #ifdef VMS if (chmod(toname, mode) < 0) fail("cannot change mode of %s", toname); if (dotimes) { utb.actime = sb.st_atime; utb.modtime = sb.st_mtime; if (utime(toname, &utb) < 0) fail("cannot set times of %s", toname); } #endif } free(toname); } free(cwd); free(todir); return 0; }
boolean TxCache::load(const wchar_t *path, const wchar_t *filename, int config) { /* find it on disk */ char cbuf[MAX_PATH]; boost::filesystem::wpath cachepath(path); #ifdef BOOST_WINDOWS_API wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(cachepath.wstring().c_str()); #else char curpath[MAX_PATH]; wcstombs(cbuf, cachepath.wstring().c_str(), MAX_PATH); GETCWD(MAX_PATH, curpath); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "rb"); DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); if (gzfp) { /* yep, we have it. load it into memory cache. */ int dataSize; uint64 checksum; GHQTexInfo tmpInfo; int tmpconfig; /* read header to determine config match */ gzread(gzfp, &tmpconfig, 4); if (tmpconfig == config) { do { memset(&tmpInfo, 0, sizeof(GHQTexInfo)); gzread(gzfp, &checksum, 8); gzread(gzfp, &tmpInfo.width, 4); gzread(gzfp, &tmpInfo.height, 4); gzread(gzfp, &tmpInfo.format, 2); gzread(gzfp, &tmpInfo.smallLodLog2, 4); gzread(gzfp, &tmpInfo.largeLodLog2, 4); gzread(gzfp, &tmpInfo.aspectRatioLog2, 4); gzread(gzfp, &tmpInfo.tiles, 4); gzread(gzfp, &tmpInfo.untiled_width, 4); gzread(gzfp, &tmpInfo.untiled_height, 4); gzread(gzfp, &tmpInfo.is_hires_tex, 1); gzread(gzfp, &dataSize, 4); tmpInfo.data = (uint8*)malloc(dataSize); if (tmpInfo.data) { gzread(gzfp, tmpInfo.data, dataSize); /* add to memory cache */ add(checksum, &tmpInfo, (tmpInfo.format & GR_TEXFMT_GZ) ? dataSize : 0); free(tmpInfo.data); } else { gzseek(gzfp, dataSize, SEEK_CUR); } /* skip in between to prevent the loop from being tied down to vsync */ if (_callback && (!(_cache.size() % 100) || gzeof(gzfp))) (*_callback)(L"[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize/1000000, filename); } while (!gzeof(gzfp)); gzclose(gzfp); } else { if ((tmpconfig & HIRESTEXTURES_MASK) != (config & HIRESTEXTURES_MASK)) { const char *conf_str; if ((tmpconfig & HIRESTEXTURES_MASK) == NO_HIRESTEXTURES) conf_str = "0"; else if ((tmpconfig & HIRESTEXTURES_MASK) == RICE_HIRESTEXTURES) conf_str = "1"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs must be %s", conf_str); } if ((tmpconfig & COMPRESS_HIRESTEX) != (config & COMPRESS_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_cmpr must be %s", (tmpconfig & COMPRESS_HIRESTEX) ? "True" : "False"); if ((tmpconfig & COMPRESSION_MASK) != (config & COMPRESSION_MASK) && (tmpconfig & COMPRESS_HIRESTEX)) { const char *conf_str; if ((tmpconfig & COMPRESSION_MASK) == FXT1_COMPRESSION) conf_str = "1"; else if ((tmpconfig & COMPRESSION_MASK) == S3TC_COMPRESSION) conf_str = "0"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_cmpr must be %s", conf_str); } if ((tmpconfig & TILE_HIRESTEX) != (config & TILE_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_tile must be %s", (tmpconfig & TILE_HIRESTEX) ? "True" : "False"); if ((tmpconfig & FORCE16BPP_HIRESTEX) != (config & FORCE16BPP_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_f16bpp must be %s", (tmpconfig & FORCE16BPP_HIRESTEX) ? "True" : "False"); if ((tmpconfig & GZ_HIRESTEXCACHE) != (config & GZ_HIRESTEXCACHE)) WriteLog(M64MSG_WARNING, "ghq_hirs_gz must be %s", (tmpconfig & GZ_HIRESTEXCACHE) ? "True" : "False"); if ((tmpconfig & LET_TEXARTISTS_FLY) != (config & LET_TEXARTISTS_FLY)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_let_texartists_fly must be %s", (tmpconfig & LET_TEXARTISTS_FLY) ? "True" : "False"); if ((tmpconfig & FILTER_MASK) != (config & FILTER_MASK)) { const char *conf_str; if ((tmpconfig & FILTER_MASK) == NO_FILTER) conf_str = "0"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_1) conf_str = "1"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_2) conf_str = "2"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_3) conf_str = "3"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_4) conf_str = "4"; else if ((tmpconfig & FILTER_MASK) == SHARP_FILTER_1) conf_str = "5"; else if ((tmpconfig & FILTER_MASK) == SHARP_FILTER_2) conf_str = "6"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_fltr must be %s", conf_str); } if ((tmpconfig & ENHANCEMENT_MASK) != (config & ENHANCEMENT_MASK)) { const char *conf_str; if ((tmpconfig & ENHANCEMENT_MASK) == NO_ENHANCEMENT) conf_str = "0"; else if ((tmpconfig & ENHANCEMENT_MASK) == X2_ENHANCEMENT) conf_str = "2"; else if ((tmpconfig & ENHANCEMENT_MASK) == X2SAI_ENHANCEMENT) conf_str = "3"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ2X_ENHANCEMENT) conf_str = "4"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ2XS_ENHANCEMENT) conf_str = "5"; else if ((tmpconfig & ENHANCEMENT_MASK) == LQ2X_ENHANCEMENT) conf_str = "6"; else if ((tmpconfig & ENHANCEMENT_MASK) == LQ2XS_ENHANCEMENT) conf_str = "7"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ4X_ENHANCEMENT) conf_str = "8"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht must be %s", conf_str); } if ((tmpconfig & COMPRESS_TEX) != (config & COMPRESS_TEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_cmpr must be %s", (tmpconfig & COMPRESS_TEX) ? "True" : "False"); if ((tmpconfig & FORCE16BPP_TEX) != (config & FORCE16BPP_TEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_f16bpp must be %s", (tmpconfig & FORCE16BPP_TEX) ? "True" : "False"); if ((tmpconfig & GZ_TEXCACHE) != (config & GZ_TEXCACHE)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_gz must be %s", (tmpconfig & GZ_TEXCACHE) ? "True" : "False"); } } CHDIR(curpath); return !_cache.empty(); }
boolean TxCache::load(const wchar_t *path, const wchar_t *filename, int config) { /* find it on disk */ char cbuf[MAX_PATH]; #ifdef OS_WINDOWS wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(path); #else char curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); wcstombs(cbuf, path, MAX_PATH); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "rb"); DBG_INFO(80, wst("gzfp:%x file:%ls\n"), gzfp, filename); if (gzfp) { /* yep, we have it. load it into memory cache. */ int dataSize; uint64 checksum; int tmpconfig; /* read header to determine config match */ gzread(gzfp, &tmpconfig, 4); if (tmpconfig == config) { do { GHQTexInfo tmpInfo; gzread(gzfp, &checksum, 8); gzread(gzfp, &tmpInfo.width, 4); gzread(gzfp, &tmpInfo.height, 4); gzread(gzfp, &tmpInfo.format, 4); gzread(gzfp, &tmpInfo.texture_format, 2); gzread(gzfp, &tmpInfo.pixel_type, 2); gzread(gzfp, &tmpInfo.is_hires_tex, 1); gzread(gzfp, &dataSize, 4); tmpInfo.data = (uint8*)malloc(dataSize); if (tmpInfo.data) { gzread(gzfp, tmpInfo.data, dataSize); /* add to memory cache */ add(checksum, &tmpInfo, (tmpInfo.format & GL_TEXFMT_GZ) ? dataSize : 0); free(tmpInfo.data); } else { gzseek(gzfp, dataSize, SEEK_CUR); } /* skip in between to prevent the loop from being tied down to vsync */ if (_callback && (!(_cache.size() % 100) || gzeof(gzfp))) (*_callback)(wst("[%d] total mem:%.02fmb - %ls\n"), _cache.size(), (float)_totalSize/1000000, filename); } while (!gzeof(gzfp)); gzclose(gzfp); } } CHDIR(curpath); return !_cache.empty(); }
int gtm_chk_dist(char *image) { char *ptr1; char pre_buff[MAX_FBUFF]; char *prefix; int prefix_len; mstr gtm_name; int status; char mbuff[MAX_FBUFF + 1]; parse_blk pblk; error_def(ERR_DISTPATHMAX); error_def(ERR_SYSCALL); error_def(ERR_GTMDISTUNDEF); error_def(ERR_FILEPARSE); error_def(ERR_MAXGTMPATH); error_def(ERR_IMAGENAME); if (NULL != (ptr1 = (char *)GETENV(GTM_DIST))) { assert((INVALID_IMAGE != image_type) && (n_image_types > image_type)); /* assert image_type is initialized */ if ((GTM_PATH_MAX - 2) <= (STRLEN(ptr1) + gtmImageNames[image_type].imageNameLen)) rts_error(VARLSTCNT(3) ERR_DISTPATHMAX, 1, GTM_PATH_MAX - gtmImageNames[image_type].imageNameLen - 2); } else rts_error(VARLSTCNT(1) ERR_GTMDISTUNDEF); memset(&pblk, 0, sizeof(pblk)); pblk.buffer = mbuff; pblk.buff_size = MAX_FBUFF; pblk.fop = F_SYNTAXO; gtm_name.addr = image; gtm_name.len = STRLEN(image); /* strings returned in pblk are not null terminated */ status = parse_file(>m_name, &pblk); if (!(status & 1)) rts_error(VARLSTCNT(5) ERR_FILEPARSE, 2, gtm_name.len, gtm_name.addr, status); assert(NULL != pblk.l_name); if ((!(pblk.fnb & F_HAS_DIR) && !pblk.b_dir) || (DIR_SEPARATOR != pblk.l_dir[0])) { if (NULL == GETCWD(pre_buff, MAX_FBUFF, prefix)) rts_error(VARLSTCNT(8) ERR_SYSCALL, 5, LEN_AND_LIT("getcwd"), CALLFROM, errno); prefix_len = STRLEN(prefix); if (MAX_FBUFF < prefix_len + pblk.b_esl + 1) rts_error(VARLSTCNT(3) ERR_MAXGTMPATH, 1, MAX_FBUFF - pblk.b_name); if (DIR_SEPARATOR != prefix[prefix_len - 1]) { prefix[prefix_len] = DIR_SEPARATOR; prefix[++prefix_len] = 0; } memcpy(prefix + prefix_len, pblk.l_dir, (int)pblk.b_dir); prefix[prefix_len + (int)pblk.b_dir] = 0; } else { prefix = pblk.l_dir; if (DIR_SEPARATOR == prefix[pblk.b_dir]) prefix[pblk.b_dir] = 0; } if ((GTM_IMAGE == image_type) && memcmp(pblk.l_name, GTM_IMAGE_NAME, GTM_IMAGE_NAMELEN)) rts_error(VARLSTCNT(6) ERR_IMAGENAME, 4, LEN_AND_LIT(GTM_IMAGE_NAME), pblk.b_name, pblk.l_name); if (GETENV("gtm_environment_init")) gtm_environment_init = TRUE; return 0; }
int main(int argc, char* argv[]) { float dummy = 1.1; /* force the compiler to load floating point support */ boolean bret = 0; int options = 0; /* Plugin path */ wchar_t path[MAX_PATH]; #ifdef WIN32 GETCWD(MAX_PATH, path); #else char cbuf[MAX_PATH]; GETCWD(MAX_PATH, cbuf); mbstowcs(path, cbuf, MAX_PATH); #endif /* ROM name */ wchar_t name[21] = L"DEFAULT"; printf("------------------------------------------------------------------\n"); printf(" GlideHQ Hires Texture Checker version 1.2\n"); printf(" Copyright (C) 2010 Hiroshi Morii All Rights Reserved\n"); printf(" email : koolsmoky(at)users.sourceforge.net\n"); printf(" website : http://www.3dfxzone.it/koolsmoky\n"); printf("\n"); printf(" Glide64 official website : http://glide64.emuxhaven.net\n"); printf("\n"); printf(" Usage: ghqchk.exe \"INTERNAL ROM NAME\"\n"); printf("------------------------------------------------------------------\n"); if (argc != 2) return 0; printf("Checking \"%s\"... ", argv[1]); mbstowcs(name, argv[1], 21); //options |= COMPRESS_TEX; //options |= COMPRESS_HIRESTEX; //options |= S3TC_COMPRESSION; //options |= TILE_HIRESTEX; //options |= FORCE16BPP_TEX; //options |= FORCE16BPP_HIRESTEX; //options |= GZ_TEXCACHE; options |= GZ_HIRESTEXCACHE; //options |= (DUMP_TEXCACHE|DUMP_HIRESTEXCACHE); options |= LET_TEXARTISTS_FLY; //options |= DUMP_TEX; options |= RICE_HIRESTEXTURES; bret = ext_ghq_init(1024, // max texture width supported by hardware 1024, // max texture height supported by hardware 32, // max texture bpp supported by hardware options, 0, // cache texture to system memory path, // plugin path name, // name of ROM. must be no longer than 256 characters DisplayLoadProgress); ext_ghq_shutdown(); printf("\bDone!\nLogged to ghqchk.txt\n"); return bret; }
int main(int argc, char *argv[]) { FIND_T fInfo; FIND_RET_T fret; char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for(i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (strstr(argv[i], "-s")) { processSubs = 0; } else if (strstr(argv[i], "-e")) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11")) { useHttp11 = 1; } else if (strstr(argv[i], "-c")) { precalcChksum = 1; } else if((argv[i][1] == 'f') && (argv[i][2] == ':')) { strcpy(targetfile, &argv[i][3]); printf("Writing to file \"%s\"\n", targetfile); } } else { strcpy(path, argv[i]); } } /* if command line param or subdir named 'fs' not found spout usage verbiage */ fret = FINDFIRST_DIR(path, &fInfo); if (!FINDFIRST_SUCCEEDED(fret)) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); printf(" Usage: htmlgen [targetdir] [-s] [-i] [-f:<filename>]" NEWLINE NEWLINE); printf(" targetdir: relative or absolute path to files to convert" NEWLINE); printf(" switch -s: toggle processing of subdirectories (default is on)" NEWLINE); printf(" switch -e: exclude HTTP header from file (header is created at runtime, default is off)" NEWLINE); printf(" switch -11: include HTTP 1.1 header (1.0 is default)" NEWLINE); printf(" switch -c: precalculate checksums for all pages (default is off)" NEWLINE); printf(" switch -f: target filename (default is \"fsdata.c\")" NEWLINE); printf(" if targetdir not specified, htmlgen will attempt to" NEWLINE); printf(" process files in subdirectory 'fs'" NEWLINE); exit(-1); } printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } GETCWD(appPath, MAX_PATH_LEN); data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ remove("fsdata.tmp"); remove("fshdr.tmp"); printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed); return 0; }
static char* GetCurrDir() { // GETCWD MALLOCS A BUFFER. REMEMBER TO FREE IT. return GETCWD(0,0);; }
boolean TxCache::save(const wchar_t *path, const wchar_t *filename, int config) { if (_cache.empty()) return true; /* dump cache to disk */ char cbuf[MAX_PATH]; osal_mkdirp(path); /* Ugly hack to enable fopen/gzopen in Win9x */ #ifdef OS_WINDOWS wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(path); #else char curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); wcstombs(cbuf, path, MAX_PATH); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "wb1"); DBG_INFO(80, wst("gzfp:%x file:%ls\n"), gzfp, filename); if (gzfp) { /* write header to determine config match */ gzwrite(gzfp, &config, 4); std::map<uint64, TXCACHE*>::iterator itMap = _cache.begin(); int total = 0; while (itMap != _cache.end()) { uint8 *dest = (*itMap).second->info.data; uint32 destLen = (*itMap).second->size; uint32 format = (*itMap).second->info.format; /* to keep things simple, we save the texture data in a zlib uncompressed state. */ /* sigh... for those who cannot wait the extra few seconds. changed to keep * texture data in a zlib compressed state. if the GZ_TEXCACHE or GZ_HIRESTEXCACHE * option is toggled, the cache will need to be rebuilt. */ /*if (format & GL_TEXFMT_GZ) { dest = _gzdest0; destLen = _gzdestLen; if (dest && destLen) { if (uncompress(dest, &destLen, (*itMap).second->info.data, (*itMap).second->size) != Z_OK) { dest = nullptr; destLen = 0; } format &= ~GL_TEXFMT_GZ; } }*/ if (dest && destLen) { /* texture checksum */ gzwrite(gzfp, &((*itMap).first), 8); /* other texture info */ gzwrite(gzfp, &((*itMap).second->info.width), 4); gzwrite(gzfp, &((*itMap).second->info.height), 4); gzwrite(gzfp, &format, 4); gzwrite(gzfp, &((*itMap).second->info.texture_format), 2); gzwrite(gzfp, &((*itMap).second->info.pixel_type), 2); gzwrite(gzfp, &((*itMap).second->info.is_hires_tex), 1); gzwrite(gzfp, &destLen, 4); gzwrite(gzfp, dest, destLen); } itMap++; if (_callback) (*_callback)(wst("Total textures saved to HDD: %d\n"), ++total); } gzclose(gzfp); } CHDIR(curpath); return _cache.empty(); }