int Bcorrectfilename(char *filename, int removefn) { char *fn; const int MAXTOKARR = 64; char *tokarr[64], *first, *next, *token; int i, ntok = 0, leadslash = 0, trailslash = 0; fn = strdup(filename); if (!fn) return -1; // find the end of the string for (first=fn; *first; first++) { #ifdef _WIN32 // translating backslashes to forwardslashes on the way if (*first == '\\') *first = '/'; #endif } leadslash = (*fn == '/'); trailslash = (first>fn && first[-1] == '/'); // carve up the string into pieces by directory, and interpret // the . and .. components first = fn; do { token = Bstrtoken(first, "/", &next, 1); first = NULL; if (!token) break; else if (token[0] == 0) continue; else if (token[0] == '.' && token[1] == 0) continue; else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1); else tokarr[ntok++] = token; } while (ntok < MAXTOKARR); if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; } if (ntok == 0 && trailslash && leadslash) trailslash = 0; // rebuild the filename first = filename; if (leadslash) *(first++) = '/'; for (i=0; i<ntok; i++) { if (i>0) *(first++) = '/'; for (token=tokarr[i]; *token; token++) *(first++) = *token; } if (trailslash) *(first++) = '/'; *(first++) = 0; free(fn); return 0; }
int32_t Bcorrectfilename(char *filename, int32_t removefn) { char *fn; char *tokarr[64], *first, *next = NULL, *token; int32_t i, ntok = 0, leadslash = 0, trailslash = 0; fn = Bstrdup(filename); if (!fn) return -1; for (first=fn; *first; first++) { #ifdef _WIN32 if (*first == '\\') *first = '/'; #endif } leadslash = (*fn == '/'); trailslash = (first>fn && first[-1] == '/'); first = fn; do { token = Bstrtoken(first, "/", &next, 1); first = NULL; if (!token) break; else if (token[0] == 0) continue; else if (token[0] == '.' && token[1] == 0) continue; else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1); else tokarr[ntok++] = token; } while (1); if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; } if (ntok == 0 && trailslash && leadslash) trailslash = 0; first = filename; if (leadslash) *(first++) = '/'; for (i=0; i<ntok; i++) { if (i>0) *(first++) = '/'; for (token=tokarr[i]; *token; token++) *(first++) = *token; } if (trailslash) *(first++) = '/'; *(first++) = 0; Bfree(fn); return 0; }
int Bcorrectfilename(char *filename, int removefn) { #ifdef _WIN32 int r, trailslash=0; #endif char path[256]="", fn[64]="", scratch[256], *ptr, *ptr2, ch; char cwd[256], *cwdp = cwd; char *tokarr[64]; int ntok=0, i, j; int grpmode = 0; if (!Bstrncasecmp(filename,"GRP:",4)) { grpmode = 1; for (ptr=filename; *ptr; ptr++) if (*ptr == '\\') *ptr = '/'; } #ifdef _WIN32 if (!grpmode) { // Windows uses backslashes so translate all unix-like forwardslashes for (ptr=filename; *ptr; ptr++) if (*ptr == '/') *ptr = '\\'; if (*(ptr-1) == '\\') trailslash = 1; r = GetFullPathName(filename, 256, path, &ptr); if (r > 256) return -1; if (r == 0) return -1; if (!trailslash && removefn && ptr) *ptr=0; if (trailslash) { if (path[ strlen(path) - 1 ] != '\\') strcat(path, "\\"); } for (ptr=path; *ptr; ptr++) if (*ptr == '\\') *ptr = '/'; strcpy(filename,path); } else { #endif #ifndef _WIN32 if (!grpmode) { Bgetcwd(cwd, 256); Bstrcat(cwd, "/"); } else { #endif cwd[0] = '/'; cwd[1] = 0; #ifndef _WIN32 } #endif ptr2 = filename; if (grpmode) { ptr2 += 3; if (ptr2[1] != '/') *ptr2 = '/'; else ptr2++; } if (removefn) { ptr = Bstrrchr(ptr2, '/'); if (ptr) ptr[1] = 0; else if (!grpmode) ptr2[0] = 0; } // now we have all the bits and pieces, clean it all up scratch[0] = 0; if (ptr2[0] != '/') { // relative path, which means prepend the current dir to the path Bstrcat(scratch, cwdp); } Bstrcat(scratch, ptr2); ptr2 = scratch; while ((ptr = Bstrtoken(ptr2==scratch?scratch:NULL,"/",&ptr2,1)) != NULL) { if (!Bstrcmp(ptr,".")) continue; else if (!Bstrcmp(ptr,"..")) { if (ntok>0) ntok--; } else { tokarr[ntok++] = ptr; } } ptr2 = filename; if (grpmode) { Bstrcpy(filename,"GRP:"); ptr2 += 4; } else filename[0] = 0; *(ptr2++) = '/'; for (i=0; i<ntok; i++) { ptr = tokarr[i]; if (i>0) *(ptr2++) = '/'; while (*ptr) *(ptr2++) = *(ptr++); } if (removefn) if (*(ptr2-1) != '/') *(ptr2++) = '/'; *(ptr2) = 0; #ifdef _WIN32 } #endif return 0; }
void baselayer_setupopengl() { char *p,*p2,*p3; static int warnonce = 0; int i; bglEnable(GL_TEXTURE_2D); bglShadeModel(GL_SMOOTH); //GL_FLAT bglClearColor(0,0,0,0.5); //Black Background bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); bglDisable(GL_DITHER); glinfo.vendor = bglGetString(GL_VENDOR); glinfo.renderer = bglGetString(GL_RENDERER); glinfo.version = bglGetString(GL_VERSION); glinfo.extensions = bglGetString(GL_EXTENSIONS); glinfo.maxanisotropy = 1.0; glinfo.bgra = 0; glinfo.texcompr = 0; // process the extensions string and flag stuff we recognize p = strdup(glinfo.extensions); p3 = p; while ((p2 = Bstrtoken(p3 == p ? p : NULL, " ", (char **) &p3, 1)) != NULL) { if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { // supports anisotropy. get the maximum anisotropy level bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS glinfo.clamptoedge = 1; } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { // support bgra textures glinfo.bgra = 1; } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { // support texture compression glinfo.texcompr = 1; } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { // support non-power-of-two texture sizes glinfo.texnpot = 1; } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { // 3dfx cards have issues with fog glinfo.hack_nofog = 1; if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); warnonce |= 1; } else if (!Bstrcmp(p2, "GL_ARB_multisample")) { // supports multisampling glinfo.multisample = 1; } else if (!Bstrcmp(p2, "GL_NV_multisample_filter_hint")) { // supports nvidia's multisample hint extension glinfo.nvmultisamplehint = 1; } else if (!strcmp(p2, "GL_ARB_multitexture")) { glinfo.multitex = 1; } else if (!strcmp(p2, "GL_ARB_texture_env_combine")) { glinfo.envcombine = 1; } } free(p); }