BDIR *Bopendir(const char *name) { BDIR_real *dirr; #ifdef _MSC_VER char *t, *tt; t = (char *)Bmalloc(Bstrlen(name) + 1 + 4); if (!t) return NULL; #endif dirr = (BDIR_real *)Bmalloc(sizeof(BDIR_real) + Bstrlen(name)); if (!dirr) { #ifdef _MSC_VER Bfree(t); #endif return NULL; } #ifdef _MSC_VER Bstrcpy(t, name); tt = t + Bstrlen(name) - 1; while (*tt == ' ' && tt > t) tt--; if (*tt != '/' && *tt != '\\') *(++tt) = '/'; *(++tt) = '*'; *(++tt) = '.'; *(++tt) = '*'; *(++tt) = 0; dirr->dir = _findfirst(t, &dirr->fid); Bfree(t); if (dirr->dir == -1) { Bfree(dirr); return NULL; } #else dirr->dir = opendir(name); if (dirr->dir == NULL) { Bfree(dirr); return NULL; } #endif dirr->status = 0; Bstrcpy(dirr->name, name); return (BDIR *)dirr; }
// // addnewsymbol() -- Allocates space for a new symbol and attaches it // appropriately to the lists, sorted. // static symbol_t *addnewsymbol(const char *name) { symbol_t *newsymb, *s, *t; newsymb = (symbol_t *)Bmalloc(sizeof(symbol_t)); if (!newsymb) { return NULL; } Bmemset(newsymb, 0, sizeof(symbol_t)); // link it to the main chain if (!symbols) { symbols = newsymb; } else { if (Bstrcasecmp(name, symbols->name) <= 0) { t = symbols; symbols = newsymb; symbols->next = t; } else { s = symbols; while (s->next) { if (Bstrcasecmp(s->next->name, name) > 0) break; s=s->next; } t = s->next; s->next = newsymb; newsymb->next = t; } } return newsymb; }
void SCRIPT_PutString ( int32 scripthandle, const char * sectionname, const char * entryname, const char * string ) { char *raw,*p; const char *q; int len = 3; if (!string) string = ""; for (q=string; *q; q++) { if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; else if (*q >= ' ') len++; } p = raw = Bmalloc(len); *(p++) = '"'; for (q=string; *q; q++) { if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } else if (*q >= ' ') *(p++) = *q; } *(p++) = '"'; *p=0; SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); Bfree(raw); }
int32_t SCRIPT_Load(char * filename) { int32_t s,h,l; char *b; h = SafeOpenRead(filename, filetype_binary); l = SafeFileLength(h)+1; b = (char *)Bmalloc(l); SafeRead(h,b,l-1); b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser SafeClose(h); s = SCRIPT_Init(filename); if (s<0) { Bfree(b); return -1; } SCRIPT_ParseBuffer(s,b,l); Bfree(b); return s; }
void loadwaves(void) { long fil, dawaversionum, i, tmp; long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES]; char *p; fil = kopen4load("WAVES.KWV", 0); if (fil != -1) { kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum); if (dawaversionum != 0) { kclose(fil); return; } kread(fil, &numwaves, 4); numwaves = B_LITTLE32(numwaves); for (i=0; i<numwaves; i++) { kread(fil, &instname[i][0], 16); kread(fil, &wavleng[i], 4); wavleng[i] = B_LITTLE32(wavleng[i]); kread(fil, &repstart[i], 4); repstart[i] = B_LITTLE32(repstart[i]); kread(fil, &repleng[i], 4); repleng[i] = B_LITTLE32(repleng[i]); kread(fil, &finetune[i], 4); finetune[i] = B_LITTLE32(finetune[i]); } } else { dawaversionum = 0; numwaves = 0; } for (i=numwaves; i<MAXWAVES; i++) { memset(&instname[i][0], 0, 16); wavleng[i] = 0; repstart[i] = 0; repleng[i] = 0; finetune[i] = 0; samples[i] = NULL; } if (fil == -1) return; #if 0 for (i=0; i<numwaves; i++) { if (repleng[i]) tmp = FSOUND_LOOP_NORMAL; else tmp = FSOUND_LOOP_OFF; samples[i] = FSOUND_Sample_Alloc(FSOUND_FREE, wavleng[i], tmp, 11025, 255, 128, 1); if (!samples[i]) continue; p = (char*)Bmalloc(wavleng[i]); kread(fil,p,wavleng[i]); FSOUND_Sample_Upload(samples[i], p, FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED); Bfree(p); if (repleng[i]) FSOUND_Sample_SetLoopPoints(samples[i], repstart[i], repstart[i]+repleng[i]); } #endif kclose(fil); printOSD("Loaded %d waves\n", numwaves); }
void SCRIPT_PutDoubleString ( int32_t scripthandle, char * sectionname, char * entryname, char * string1, char * string2 ) { char *raw,*q,*p; int32_t len = 6; if (!string1) string1 = ""; if (!string2) string2 = ""; for (q=string1; *q; q++) { if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; else if (*q >= ' ') len++; } for (q=string2; *q; q++) { if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; else if (*q >= ' ') len++; } p = raw = Bmalloc(len); *(p++) = '"'; for (q=string1; *q; q++) { if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } else if (*q >= ' ') *(p++) = *q; } *(p++) = '"'; *(p++) = ' '; *(p++) = '"'; for (q=string2; *q; q++) { if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } else if (*q >= ' ') *(p++) = *q; } *(p++) = '"'; *p=0; SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); Bfree(raw); }
struct Bdirent *Breaddir(BDIR *dir) { BDIR_real *dirr = (BDIR_real *)dir; #ifdef _MSC_VER if (dirr->status > 0) { if (_findnext(dirr->dir, &dirr->fid) != 0) { dirr->status = -1; return NULL; } } dirr->info.namlen = Bstrlen(dirr->fid.name); dirr->info.name = dirr->fid.name; dirr->status++; #else struct dirent *de = readdir(dirr->dir); if (de == NULL) { dirr->status = -1; return NULL; } else { dirr->status++; } dirr->info.namlen = Bstrlen(de->d_name); dirr->info.name = de->d_name; #endif dirr->info.mode = 0; dirr->info.size = 0; dirr->info.mtime = 0; char *fn = (char *)Bmalloc(Bstrlen(dirr->name) + 1 + dirr->info.namlen + 1); if (fn) { Bsprintf(fn, "%s/%s", dirr->name, dirr->info.name); struct Bstat st; if (!Bstat(fn, &st)) { dirr->info.mode = st.st_mode; dirr->info.size = st.st_size; dirr->info.mtime = st.st_mtime; } Bfree(fn); } return &dirr->info; }
int32_t SCRIPT_New(void) { int32_t i; for (i=0; i<MAXSCRIPTFILES; i++) { if (!SC(i)) { SC(i) = (script_t *)Bmalloc(sizeof(script_t)); if (!SC(i)) return -1; memset(SC(i), 0, sizeof(script_t)); return i; } } return -1; }
int32_t addsearchpath_ProgramFiles(const char *p) { int32_t returncode = -1, i; const char *ProgramFiles[2] = { Bgetenv("ProgramFiles"), Bgetenv("ProgramFiles(x86)") }; for (i = 0; i < 2; ++i) { if (ProgramFiles[i]) { char *buffer = (char*)Bmalloc((strlen(ProgramFiles[i])+1+strlen(p)+1)*sizeof(char)); Bsprintf(buffer,"%s/%s",ProgramFiles[i],p); if (addsearchpath(buffer) == 0) // if any work, return success returncode = 0; Bfree(buffer); } } return returncode; }
char *Bgetsystemdrives(void) { #ifdef _WIN32 char *str, *p; DWORD drv, mask; int32_t number = 0; drv = GetLogicalDrives(); if (drv == 0) return NULL; for (mask = 1; mask < 0x8000000l; mask <<= 1) { if ((drv & mask) == 0) continue; number++; } str = p = (char *)Bmalloc(1 + (3 * number)); if (!str) return NULL; number = 0; for (mask = 1; mask < 0x8000000l; mask <<= 1, number++) { if ((drv & mask) == 0) continue; *(p++) = 'A' + number; *(p++) = ':'; *(p++) = 0; } *(p++) = 0; return str; #else // Perhaps have Unix OS's put /, /home/user, and /mnt/* in the "drives" list? return NULL; #endif }
void BuildEngineApp::Startup() { _buildargc = 0; // carve up the command line into more recognizable pieces argvbuf = Bstrdup(GetCommandLineA()); _buildargc = 0; if (argvbuf) { char quoted = 0, instring = 0, swallownext = 0; char *p, *wp; int32_t i; for (p = wp = argvbuf; *p; p++) { if (*p == ' ') { if (instring && !quoted) { // end of a string *(wp++) = 0; instring = 0; } else if (instring) { *(wp++) = *p; } } else if (*p == '"' && !swallownext) { if (instring && quoted) { // end of a string if (p[1] == ' ') { *(wp++) = 0; instring = 0; quoted = 0; } else { quoted = 0; } } else if (instring && !quoted) { quoted = 1; } else if (!instring) { instring = 1; quoted = 1; _buildargc++; } } else if (*p == '\\' && p[1] == '"' && !swallownext) { swallownext = 1; } else { if (!instring) _buildargc++; instring = 1; *(wp++) = *p; swallownext = 0; } } *wp = 0; _buildargv = (const char **)Bmalloc(sizeof(char *)*(_buildargc + 1)); wp = argvbuf; for (i = 0; i < _buildargc; i++, wp++) { _buildargv[i] = wp; while (*wp) wp++; } _buildargv[_buildargc] = NULL; } polymerNG.Init(); numpages = 1; if (editorManager.IsEditorModeEnabled()) { editorThread = new EditorThread(_buildargc, _buildargv); } else { gameThread = new GameThread(_buildargc, _buildargv); } }
int32_t ScanGroups(void) { CACHE1D_FIND_REC *srch, *sidx; struct grpcache *fg, *fgg; struct grpfile *grp; char *fn; struct Bstat st; #define BUFFER_SIZE (1024 * 1024 * 8) uint8_t *buf = (uint8_t *)Bmalloc(BUFFER_SIZE); if (!buf) { initprintf("Error allocating %d byte buffer to scan GRPs!\n", BUFFER_SIZE); return 0; } initprintf("Searching for game data...\n"); LoadGameList(); //LoadGroupsCache(); SB: disabled to match local srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE); for (sidx = srch; sidx; sidx = sidx->next) { for (fg = grpcache; fg; fg = fg->next) { if (!Bstrcmp(fg->name, sidx->name)) break; } if (fg) { if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { Bfree(fn); continue; } // failed to stat the file Bfree(fn); if (fg->size == st.st_size && fg->mtime == st.st_mtime) { grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = fg->crcval; grp->size = fg->size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; fgg->crcval = fg->crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; continue; } } { int32_t b, fh; int32_t crcval; fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); if (fh < 0) continue; if (Bfstat(fh, &st)) continue; initprintf(" Checksumming %s...", sidx->name); crc32init((uint32_t *)&crcval); do { b = read(fh, buf, BUFFER_SIZE); if (b > 0) crc32block((uint32_t *)&crcval, (uint8_t *)buf, b); } while (b == BUFFER_SIZE); crc32finish((uint32_t *)&crcval); close(fh); initprintf(" Done\n"); grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = crcval; grp->size = st.st_size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); Bstrncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; fgg->crcval = crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; } } klistfree(srch); FreeGroupsCache(); for (grp = foundgrps; grp; /*grp=grp->next*/) { struct grpfile *igrp; for (igrp = listgrps; igrp; igrp=igrp->next) if (grp->crcval == igrp->crcval) break; if (igrp == NULL) { grp = grp->next; continue; } if (igrp->dependency) { struct grpfile *depgrp; //initprintf("found grp with dep\n"); for (depgrp = foundgrps; depgrp; depgrp=depgrp->next) if (depgrp->crcval == igrp->dependency) break; if (depgrp == NULL || depgrp->crcval != igrp->dependency) // couldn't find dependency { //initprintf("removing %s\n", grp->name); RemoveGroup(igrp->crcval); grp = foundgrps; continue; } } if (igrp->game && !grp->game) grp->game = igrp->game; grp=grp->next; } if (usedgrpcache) { int32_t i = 0; FILE *fp; fp = fopen(GRPCACHEFILE, "wt"); if (fp) { for (fg = usedgrpcache; fg; fg=fgg) { fgg = fg->next; fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); Bfree(fg); i++; } fclose(fp); } // initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file"); Bfree(buf); return 0; } initprintf("Found no recognized game data!\n"); Bfree(buf); return 0; }
FORCE_INLINE void* XXH_malloc(size_t s) { return Bmalloc(s); }