Skip to content

Commit

Permalink
merge in D2 sections[] code
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 15, 2015
1 parent 686d5a0 commit 701e302
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
49 changes: 35 additions & 14 deletions src/inifile.c
Expand Up @@ -120,13 +120,15 @@ const char *findConfFile(const char *argv0, const char *inifile)
}

/*****************************
* Read and analyze .ini file, i.e. write the entries of the specified section
* into the process environment
* Input:
* filename path to config file
* envsectionname name of the section to process
* Read and analyze .ini file.
* Write the entries into the process environment as
* well as any entries in one of the specified section(s).
*
* Params:
* filename = path to config file
* sections[] = section namesdimension of array of section names
*/
void parseConfFile(const char *filename, const char *envsectionname)
void parseConfFile(const char *filename, Strings *sections)
{
const char *path = FileName::path(filename); // need path for @P macro
#if LOG
Expand All @@ -139,8 +141,8 @@ void parseConfFile(const char *filename, const char *envsectionname)
return; // error reading file

// Parse into lines
bool envsection = true;
size_t envsectionnamelen = strlen(envsectionname);
bool envsection = true; // default is to read

OutBuffer buf;
bool eof = false;
for (size_t i = 0; i < file.len && !eof; i++)
Expand Down Expand Up @@ -241,14 +243,33 @@ void parseConfFile(const char *filename, const char *envsectionname)
char *pn;
for (pn = p; isalnum((utf8_t)*pn); pn++)
;
if (pn - p == envsectionnamelen &&
Port::memicmp(p, envsectionname, envsectionnamelen) == 0 &&
*skipspace(pn) == ']')

if (*skipspace(pn) != ']')
{
envsection = true;
}
else
// malformed [sectionname], so just say we're not in a section
envsection = false;
break;
}

/* Seach sectionnamev[] for p..pn and set envsection to true if it's there
*/
for (size_t j = 0; 1; ++j)
{
if (j == sections->dim)
{
// Didn't find it
envsection = false;
break;
}
const char *sectionname = (*sections)[j];
size_t len = strlen(sectionname);
if (pn - p == len &&
Port::memicmp(p, sectionname, len) == 0)
{
envsection = true;
break;
}
}
break;

default:
Expand Down
15 changes: 12 additions & 3 deletions src/mars.c
Expand Up @@ -52,7 +52,7 @@ static const char* parse_arch_arg(size_t argc, const char** argv, const char* ar
static const char* parse_conf_arg(size_t argc, const char** argv);

const char *findConfFile(const char *argv0, const char *inifile);
void parseConfFile(const char *filename, const char* envsectionname);
void parseConfFile(const char *filename, Strings *sections);


FILE *stdmsg;
Expand Down Expand Up @@ -564,7 +564,14 @@ int main(int iargc, const char *argv[])
#endif
}
}
parseConfFile(global.inifilename, "Environment");

Strings sections;

/* Read the [Environment] section, so we can later
* pick up any DFLAGS settings.
*/
sections.push("Environment");
parseConfFile(global.inifilename, &sections);

size_t dflags_argc = 0;
const char** dflags_argv = NULL;
Expand All @@ -575,9 +582,11 @@ int main(int iargc, const char *argv[])
arch = parse_arch_arg(dflags_argc, dflags_argv, arch);
bool is64bit = arch[0] == '6';

sections.setDim(0);
char envsection[80];
sprintf(envsection, "Environment%s", arch);
parseConfFile(global.inifilename, envsection);
sections.push(envsection);
parseConfFile(global.inifilename, &sections);

getenv_setargv("DFLAGS", &argc, &argv);

Expand Down

0 comments on commit 701e302

Please sign in to comment.