void plyr_read_stats_v(int *k, int *d){ char filename[PATH_MAX]; int k1=-1,k2=0,d1=-1,d2=0; PHYSFS_file *f; *k=0;*d=0;//in case the file doesn't exist. memset(filename, '\0', PATH_MAX); snprintf(filename,PATH_MAX,GameArg.SysUsePlayersDir?"Players/%s.eff":"%s.eff",Players[Player_num].callsign); f = PHYSFSX_openReadBuffered(filename); if(f) { char line[256],*word; if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"kills")) *k=atoi(line); d_free(word); } if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"deaths")) *d=atoi(line); d_free(word); } if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"key") && strlen(line)>10){ unsigned char *p; if (line[0]=='0' && line[1]=='1'){ if ((p=decode_stat((unsigned char*)line+3,&k1,effcode1))&& (p=decode_stat(p+1,&k2,effcode2))&& (p=decode_stat(p+1,&d1,effcode3))){ decode_stat(p+1,&d2,effcode4); } } } d_free(word); } if (k1!=k2 || k1!=*k || d1!=d2 || d1!=*d) { *k=0;*d=0; } } if(f) PHYSFS_close(f); }
static void add_multiple_strings(Repodata *data, Id handle, Id name, char *value) { char *str; while ((str = splitword(&value)) != 0) repodata_add_poolstr_array(data, handle, name, str); }
static void add_multiple_urls(Repodata *data, Id handle, char *value, Id type) { char *url; while ((url = splitword(&value)) != 0) { repodata_add_poolstr_array(data, handle, PRODUCT_URL, url); repodata_add_idarray(data, handle, PRODUCT_URL_TYPE, type); } }
static unsigned int adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id marker) { char *name; Id id; while ((name = splitword(&line)) != 0) { /* Hack, as the content file adds 'package:' for package dependencies sometimes. */ if (!strncmp (name, "package:", 8)) name += 8; id = pool_str2id(pool, name, 1); if (*line == '<' || *line == '>' || *line == '=') /* rel follows */ { char *rel = splitword(&line); char *evr = splitword(&line); int flags; if (!rel || !evr) { pool_debug(pool, SOLV_ERROR, "repo_content: bad relation '%s %s'\n", name, rel); continue; } for (flags = 0; flags < 6; flags++) if (!strcmp(rel, flagtab[flags])) break; if (flags == 6) { pool_debug(pool, SOLV_ERROR, "repo_content: unknown relation '%s'\n", rel); continue; } id = pool_rel2id(pool, id, pool_str2id(pool, evr, 1), flags + 1, 1); } olddeps = repo_addid_dep(pd->repo, olddeps, id, marker); } return olddeps; }
void InitArgs( int argc,char **argv ) { int i; FILE *f; char *line,*word; Num_args=0; for (i=0; i<argc; i++ ) Args[Num_args++] = strdup( argv[i] ); for (i=0; i< Num_args; i++ ) { //killed 02/06/99 Matthew Mueller - interferes with filename args which might start with / // if ( Args[i][0] == '/' ) // Args[i][0] = '-'; //end kill -MM if ( Args[i][0] == '-' ) strlwr( Args[i] ); // Convert all args to lowercase } if((i=FindArg("-ini"))) f=fopen(Args[i+1],"rt"); else f=fopen("d1x.ini","rt"); if(f) { while(!feof(f)) { line=fsplitword(f,'\n'); word=splitword(line,' '); Args[Num_args++] = strdup(word); if(line) Args[Num_args++] = strdup(line); free(line); free(word); } fclose(f); } atexit(FreeArgs); }
int repo_add_content(Repo *repo, FILE *fp, int flags) { Pool *pool = repo->pool; char *line, *linep; int aline; Solvable *s; struct parsedata pd; Repodata *data; Id handle = 0; int contentstyle = 0; char *descrdir = 0; char *datadir = 0; char *defvendor = 0; int i = 0; int res = 0; /* architectures we use the first architecture in BASEARCHS or noarch for the product. At the end we create (clone) the product for each one of the remaining architectures we allow max 4 archs */ unsigned int numotherarchs = 0; Id *otherarchs = 0; memset(&pd, 0, sizeof(pd)); line = solv_malloc(1024); aline = 1024; pd.repo = repo; linep = line; s = 0; data = repo_add_repodata(repo, flags); for (;;) { char *key, *value; /* read line into big-enough buffer */ if (linep - line + 16 > aline) { aline = linep - line; line = solv_realloc(line, aline + 512); linep = line + aline; aline += 512; } if (!fgets(linep, aline - (linep - line), fp)) break; linep += strlen(linep); if (linep == line || linep[-1] != '\n') continue; while ( --linep > line && ( linep[-1] == ' ' || linep[-1] == '\t' ) ) ; /* skip trailing ws */ *linep = 0; linep = line; /* expect "key value" lines */ value = line; key = splitword(&value); if (key) { #if 0 fprintf (stderr, "key %s, value %s\n", key, value); #endif #define istag(x) (!strcmp (key, x)) #define code10 (contentstyle == 10) #define code11 (contentstyle == 11) if (istag ("CONTENTSTYLE")) { if (contentstyle) pool_debug(pool, SOLV_ERROR, "repo_content: 'CONTENTSTYLE' must be first line of 'content'\n"); contentstyle = atoi(value); continue; } if (!contentstyle) contentstyle = 10; /* repository tags */ /* we also replicate some of them into the product solvables * to be backward compatible */ if (istag ("REPOID")) { repodata_add_poolstr_array(data, SOLVID_META, REPOSITORY_REPOID, value); continue; } if (istag ("REPOKEYWORDS")) { add_multiple_strings(data, SOLVID_META, REPOSITORY_KEYWORDS, value); continue; } if (istag ("DISTRO")) { Id dh = repodata_new_handle(data); char *p; /* like with createrepo --distro */ if ((p = strchr(value, ',')) != 0) { *p++ = 0; if (*value) repodata_set_poolstr(data, dh, REPOSITORY_PRODUCT_CPEID, value); } else p = value; if (*p) repodata_set_str(data, dh, REPOSITORY_PRODUCT_LABEL, p); repodata_add_flexarray(data, SOLVID_META, REPOSITORY_DISTROS, dh); continue; } if (istag ("DESCRDIR")) { if (descrdir) free(descrdir); else repodata_set_str(data, SOLVID_META, SUSETAGS_DESCRDIR, value); if (s) repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, value); descrdir = solv_strdup(value); continue; } if (istag ("DATADIR")) { if (datadir) free(datadir); else repodata_set_str(data, SOLVID_META, SUSETAGS_DATADIR, value); if (s) repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, value); datadir = solv_strdup(value); continue; } if (istag ("VENDOR")) { if (defvendor) free(defvendor); else repodata_set_poolstr(data, SOLVID_META, SUSETAGS_DEFAULTVENDOR, value); if (s) s->vendor = pool_str2id(pool, value, 1); defvendor = solv_strdup(value); continue; } if (istag ("META") || istag ("HASH") || istag ("KEY")) { char *checksumtype, *checksum; Id fh, type; int l; if ((checksumtype = splitword(&value)) == 0) continue; if ((checksum = splitword(&value)) == 0) continue; if (!*value) continue; type = solv_chksum_str2type(checksumtype); if (!type) { pool_error(pool, -1, "%s: unknown checksum type '%s'", value, checksumtype); res = 1; continue; } l = solv_chksum_len(type); if (strlen(checksum) != 2 * l) { pool_error(pool, -1, "%s: invalid checksum length for %s", value, checksumtype); res = 1; continue; } fh = repodata_new_handle(data); repodata_set_poolstr(data, fh, SUSETAGS_FILE_TYPE, key); repodata_set_str(data, fh, SUSETAGS_FILE_NAME, value); repodata_set_checksum(data, fh, SUSETAGS_FILE_CHECKSUM, type, checksum); repodata_add_flexarray(data, SOLVID_META, SUSETAGS_FILE, fh); continue; } /* product tags */ if ((code10 && istag ("PRODUCT")) || (code11 && istag ("NAME"))) { if (s && !s->name) { /* this solvable was created without seeing a PRODUCT entry, just set the name and continue */ s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1); continue; } if (s) { /* finish old solvable */ if (!s->arch) s->arch = ARCH_NOARCH; if (!s->evr) s->evr = ID_EMPTY; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); if (code10) s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0); } /* create new solvable */ s = pool_id2solvable(pool, repo_add_solvable(repo)); handle = s - pool->solvables; s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1); if (datadir) repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, datadir); if (descrdir) repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, descrdir); if (defvendor) s->vendor = pool_str2id(pool, defvendor, 1); continue; } /* Sometimes PRODUCT/NAME is not the first entry, but we need a solvable from here on. */ if (!s) { s = pool_id2solvable(pool, repo_add_solvable(repo)); handle = s - pool->solvables; } if (istag ("VERSION")) pd.tmpvers = solv_strdup(value); else if (istag ("RELEASE")) pd.tmprel = solv_strdup(value); else if (code11 && istag ("DISTRIBUTION")) repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_DISTRIBUTION, value); else if (istag ("UPDATEURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "update", 1)); else if (istag ("EXTRAURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "extra", 1)); else if (istag ("OPTIONALURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "optional", 1)); else if (istag ("RELNOTESURL")) add_multiple_urls(data, handle, value, pool_str2id(pool, "releasenotes", 1)); else if (istag ("SHORTLABEL")) repodata_set_str(data, s - pool->solvables, PRODUCT_SHORTLABEL, value); else if (istag ("LABEL")) /* LABEL is the products SUMMARY. */ repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, value); else if (!strncmp (key, "LABEL.", 6)) repodata_set_str(data, s - pool->solvables, pool_id2langid(pool, SOLVABLE_SUMMARY, key + 6, 1), value); else if (istag ("FLAGS")) add_multiple_strings(data, handle, PRODUCT_FLAGS, value); else if (istag ("VENDOR")) /* actually already handled above */ s->vendor = pool_str2id(pool, value, 1); else if (istag ("BASEARCHS")) { char *arch; if ((arch = splitword(&value)) != 0) { s->arch = pool_str2id(pool, arch, 1); while ((arch = splitword(&value)) != 0) { otherarchs = solv_extend(otherarchs, numotherarchs, 1, sizeof(Id), 7); otherarchs[numotherarchs++] = pool_str2id(pool, arch, 1); } } } if (!code10) continue; /* * Every tag below is Code10 only * */ if (istag ("ARCH")) /* Theoretically we want to have the best arch of the given modifiers which still is compatible with the system arch. We don't know the latter here, though. */ s->arch = ARCH_NOARCH; else if (istag ("PREREQUIRES")) s->requires = adddep(pool, &pd, s->requires, value, SOLVABLE_PREREQMARKER); else if (istag ("REQUIRES")) s->requires = adddep(pool, &pd, s->requires, value, -SOLVABLE_PREREQMARKER); else if (istag ("PROVIDES")) s->provides = adddep(pool, &pd, s->provides, value, 0); else if (istag ("CONFLICTS")) s->conflicts = adddep(pool, &pd, s->conflicts, value, 0); else if (istag ("OBSOLETES")) s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0); else if (istag ("RECOMMENDS")) s->recommends = adddep(pool, &pd, s->recommends, value, 0); else if (istag ("SUGGESTS")) s->suggests = adddep(pool, &pd, s->suggests, value, 0); else if (istag ("SUPPLEMENTS")) s->supplements = adddep(pool, &pd, s->supplements, value, 0); else if (istag ("ENHANCES")) s->enhances = adddep(pool, &pd, s->enhances, value, 0); /* FRESHENS doesn't seem to exist. */ else if (istag ("TYPE")) repodata_set_str(data, s - pool->solvables, PRODUCT_TYPE, value); /* XXX do something about LINGUAS and ARCH? * <ma>: Don't think so. zypp does not use or propagate them. */ #undef istag } else pool_debug(pool, SOLV_ERROR, "repo_content: malformed line: %s\n", line); } if (datadir) free(datadir); if (descrdir) free(descrdir); if (defvendor) free(defvendor); if (s && !s->name) { pool_debug(pool, SOLV_ERROR, "repo_content: 'content' incomplete, no product solvable created!\n"); repo_free_solvable(repo, s - pool->solvables, 1); s = 0; } if (s) { if (pd.tmprel) s->evr = makeevr(pool, join(&pd, pd.tmpvers, "-", pd.tmprel)); else s->evr = makeevr(pool, pd.tmpvers); pd.tmpvers = solv_free((void *)pd.tmpvers); pd.tmprel = solv_free((void *)pd.tmprel); if (!s->arch) s->arch = ARCH_NOARCH; if (!s->evr) s->evr = ID_EMPTY; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); if (code10) s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0); /* now for every other arch, clone the product except the architecture */ for (i = 0; i < numotherarchs; ++i) { Solvable *p = pool_id2solvable(pool, repo_add_solvable(repo)); p->name = s->name; p->evr = s->evr; p->vendor = s->vendor; p->arch = otherarchs[i]; /* self provides */ if (s->name && p->arch != ARCH_SRC && p->arch != ARCH_NOSRC) p->provides = repo_addid_dep(repo, p->provides, pool_rel2id(pool, p->name, p->evr, REL_EQ, 1), 0); /* now merge the attributes */ repodata_merge_attrs(data, p - pool->solvables, s - pool->solvables); } } if (pd.tmp) solv_free(pd.tmp); solv_free(line); solv_free(otherarchs); if (!(flags & REPO_NO_INTERNALIZE)) repodata_internalize(data); return res; }
int read_player_d1x(char *filename) { PHYSFS_file *f; int rc = 0; char line[50],*word; int Stop=0; plyr_read_stats(); f = PHYSFSX_openReadBuffered(filename); if(!f || PHYSFS_eof(f) ) return errno; while( !Stop && !PHYSFS_eof(f) ) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); strupr(word); if (strstr(word,"WEAPON REORDER")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { unsigned int wo0=0,wo1=0,wo2=0,wo3=0,wo4=0,wo5=0; if(!strcmp(word,"PRIMARY")) { sscanf(line,"0x%x,0x%x,0x%x,0x%x,0x%x,0x%x",&wo0, &wo1, &wo2, &wo3, &wo4, &wo5); PlayerCfg.PrimaryOrder[0]=wo0; PlayerCfg.PrimaryOrder[1]=wo1; PlayerCfg.PrimaryOrder[2]=wo2; PlayerCfg.PrimaryOrder[3]=wo3; PlayerCfg.PrimaryOrder[4]=wo4; PlayerCfg.PrimaryOrder[5]=wo5; } else if(!strcmp(word,"SECONDARY")) { sscanf(line,"0x%x,0x%x,0x%x,0x%x,0x%x,0x%x",&wo0, &wo1, &wo2, &wo3, &wo4, &wo5); PlayerCfg.SecondaryOrder[0]=wo0; PlayerCfg.SecondaryOrder[1]=wo1; PlayerCfg.SecondaryOrder[2]=wo2; PlayerCfg.SecondaryOrder[3]=wo3; PlayerCfg.SecondaryOrder[4]=wo4; PlayerCfg.SecondaryOrder[5]=wo5; } d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"JOYSTICK")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"SENSITIVITY0")) PlayerCfg.JoystickSens[0] = atoi(line); if(!strcmp(word,"SENSITIVITY1")) PlayerCfg.JoystickSens[1] = atoi(line); if(!strcmp(word,"SENSITIVITY2")) PlayerCfg.JoystickSens[2] = atoi(line); if(!strcmp(word,"SENSITIVITY3")) PlayerCfg.JoystickSens[3] = atoi(line); if(!strcmp(word,"SENSITIVITY4")) PlayerCfg.JoystickSens[4] = atoi(line); if(!strcmp(word,"SENSITIVITY5")) PlayerCfg.JoystickSens[5] = atoi(line); if(!strcmp(word,"DEADZONE0")) PlayerCfg.JoystickDead[0] = atoi(line); if(!strcmp(word,"DEADZONE1")) PlayerCfg.JoystickDead[1] = atoi(line); if(!strcmp(word,"DEADZONE2")) PlayerCfg.JoystickDead[2] = atoi(line); if(!strcmp(word,"DEADZONE3")) PlayerCfg.JoystickDead[3] = atoi(line); if(!strcmp(word,"DEADZONE4")) PlayerCfg.JoystickDead[4] = atoi(line); if(!strcmp(word,"DEADZONE5")) PlayerCfg.JoystickDead[5] = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"MOUSE")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"FLIGHTSIM")) PlayerCfg.MouseFlightSim = atoi(line); if(!strcmp(word,"SENSITIVITY0")) PlayerCfg.MouseSens[0] = atoi(line); if(!strcmp(word,"SENSITIVITY1")) PlayerCfg.MouseSens[1] = atoi(line); if(!strcmp(word,"SENSITIVITY2")) PlayerCfg.MouseSens[2] = atoi(line); if(!strcmp(word,"SENSITIVITY3")) PlayerCfg.MouseSens[3] = atoi(line); if(!strcmp(word,"SENSITIVITY4")) PlayerCfg.MouseSens[4] = atoi(line); if(!strcmp(word,"SENSITIVITY5")) PlayerCfg.MouseSens[5] = atoi(line); if(!strcmp(word,"FSDEAD")) PlayerCfg.MouseFSDead = atoi(line); if(!strcmp(word,"FSINDI")) PlayerCfg.MouseFSIndicator = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"WEAPON KEYS V2")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { int kc1=0,kc2=0,kc3=0; int i=atoi(word); if(i==0) i=10; i=(i-1)*3; sscanf(line,"0x%x,0x%x,0x%x",&kc1,&kc2,&kc3); PlayerCfg.KeySettingsD1X[i] = kc1; PlayerCfg.KeySettingsD1X[i+1] = kc2; PlayerCfg.KeySettingsD1X[i+2] = kc3; d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"COCKPIT")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"MODE")) PlayerCfg.CockpitMode[0] = PlayerCfg.CockpitMode[1] = atoi(line); else if(!strcmp(word,"HUD")) PlayerCfg.HudMode = atoi(line); else if(!strcmp(word,"RETTYPE")) PlayerCfg.ReticleType = atoi(line); else if(!strcmp(word,"RETRGBA")) sscanf(line,"%i,%i,%i,%i",&PlayerCfg.ReticleRGBA[0],&PlayerCfg.ReticleRGBA[1],&PlayerCfg.ReticleRGBA[2],&PlayerCfg.ReticleRGBA[3]); else if(!strcmp(word,"RETSIZE")) PlayerCfg.ReticleSize = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"TOGGLES")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"PERSISTENTDEBRIS")) PlayerCfg.PersistentDebris = atoi(line); if(!strcmp(word,"PRSHOT")) PlayerCfg.PRShot = atoi(line); if(!strcmp(word,"NOREDUNDANCY")) PlayerCfg.NoRedundancy = atoi(line); if(!strcmp(word,"MULTIMESSAGES")) PlayerCfg.MultiMessages = atoi(line); if(!strcmp(word,"BOMBGAUGE")) PlayerCfg.BombGauge = atoi(line); if(!strcmp(word,"AUTOMAPFREEFLIGHT")) PlayerCfg.AutomapFreeFlight = atoi(line); if(!strcmp(word,"NOFIREAUTOSELECT")) PlayerCfg.NoFireAutoselect = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"GRAPHICS")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"ALPHAEFFECTS")) PlayerCfg.AlphaEffects = atoi(line); if(!strcmp(word,"DYNLIGHTCOLOR")) PlayerCfg.DynLightColor = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"PLX VERSION")) // know the version this pilot was used last with - allow modifications { int v1=0,v2=0,v3=0; d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { sscanf(line,"%i.%i.%i",&v1,&v2,&v3); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } if (v1 == 0 && v2 == 56 && v3 == 0) // was 0.56.0 if (D1XMAJORi != v1 || D1XMINORi != v2 || D1XMICROi != v3) // newer (presumably) { // reset mouse cycling fields PlayerCfg.KeySettings[1][44] = 255; PlayerCfg.KeySettings[1][45] = 255; PlayerCfg.KeySettings[1][46] = 255; PlayerCfg.KeySettings[1][47] = 255; PlayerCfg.KeySettings[2][27] = 255; PlayerCfg.KeySettings[2][28] = 255; } } else if (strstr(word,"END") || PHYSFS_eof(f)) { Stop=1; } else { if(word[0]=='['&&!strstr(word,"D1X OPTIONS")) { while(!strstr(line,"END") && !PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); strupr(line); } } } if(word) d_free(word); } PHYSFS_close(f); return rc; }
void InitArgs (int argc, char **argv) { int i, j; CFILE *f; char *pszLine, *pszToken, fnIni [FILENAME_LEN]; static char **pszArgs = NULL; static int nArgs = 0; if (argv) { pszArgs = argv; nArgs = argc; } else if (pszArgs) { argv = pszArgs; argc = nArgs; } else return; LogErr ("Loading program arguments\n"); args_exit (); for (i = 0; i < argc; i++) Args [Num_args++] = D2_STRDUP (argv [i]); for (i = 0; i < Num_args; i++) if (Args [i] [0] == '-') strlwr (Args [i]); // Convert all args to lowercase // look for the ini file // for unix, allow both ~/.d2x-xl and <config dir>/d2x.ini #ifdef _DEBUG GetIniFileName (fnIni, 1); #else GetIniFileName (fnIni, 0); #endif f = CFOpen (fnIni, "", "rt", 0); #ifdef _DEBUG if (!f) { GetIniFileName (fnIni, 0); f = CFOpen (fnIni, "", "rt", 0); } #endif if (f) { while (!CFEoF (f)) { pszLine = fsplitword (f, '\n'); if (*pszLine && (*pszLine != ';')) { pszToken = splitword (pszLine, ' '); if (Num_args >= MAX_ARGS) break; Args [Num_args++] = pszToken; if (pszLine) { if (Num_args >= MAX_ARGS) { LogErr ("too many program arguments\n"); break; } Args [Num_args++] = *pszLine ? D2_STRDUP (pszLine) : NULL; } } D2_FREE (pszLine); } CFClose (f); } LogErr (" "); for (i = j = 0; i < Num_args; i++, j++) { if (!Args [i]) continue; if ((Args [i][0] == '-') && (isalpha (Args [i][1]) || (j == 2))) { LogErr ("\n "); j = 0; } LogErr (Args [i]); LogErr (" "); } LogErr ("\n"); atexit (args_exit); }