Device-QuickCam
view release on metacpan or search on metacpan
libcqcam/rcfile.C view on Meta::CPAN
else
qcrc = fopen(qcrc_filename[i], "r");
#ifdef DEBUG
fprintf(stderr, "Config file %s %sfound.\n", qcrc_filename[i],
qcrc?"":"not ");
#endif
}
if (qcrc == NULL) {
#ifdef DEBUG
fprintf(stderr, "No config files found.\n");
#endif
return;
}
while (!feof(qcrc)) {
char buf[200], word1[100], word2[100];
char *p;
fgets(buf, 200, qcrc);
if ((p = strchr(buf, '#')) != NULL)
*p = '\0';
sscanf(buf, "%s %s", word1, word2);
if (!feof(qcrc) && *buf != '\0' && *buf != '\n') {
for (i=0; directives[i][0]; i++)
if (!strcasecmp(word1, directives[i][0])) {
switches[nswitches] = new char[strlen(word1) + 1];
strcpy(switches[nswitches], directives[i][1]);
values[nswitches] = new char[strlen(word2) + 1];
strcpy(values[nswitches], word2);
nswitches++;
break;
}
#ifdef DEBUG
if (!directives[i][0])
fprintf(stderr, "Unrecognized option in config file: %s %s\n",
word1, word2);
#endif
}
}
#ifdef DEBUG
for (int q=0; q<nswitches; q++)
fprintf(stderr, "%s %s ", switches[q], values[q]);
fprintf(stderr, "\n");
#endif
}
rcfile_t::~rcfile_t(void) {
for (int i=0; i<nswitches; i++) {
delete[] switches[i];
delete[] values[i];
}
}
char *resolve_home_dir(const char *fn) {
char *ret;
// try the $HOME environment variable
if (getenv("HOME") != NULL) {
ret = new char[strlen(getenv("HOME")) + strlen(fn)];
strcpy(ret, getenv("HOME"));
strcat(ret, fn + 1);
return ret;
}
struct passwd *pw = getpwuid(getuid());
if (!pw) {
ret = new char[strlen(fn) + 1];
strcpy(ret, fn);
return ret;
}
ret = new char[strlen(pw->pw_dir) + strlen(fn)];
strcpy(ret, pw->pw_dir);
strcat(ret, fn + 1);
return ret;
}
void rcfile_t::get(char **sw, char **val, int reset) {
static int c = 0;
if (reset)
c = 0;
if (c == nswitches) {
*sw = NULL;
*val = NULL;
}
else {
*sw = switches[c];
*val = values[c];
c++;
}
}
( run in 1.450 second using v1.01-cache-2.11-cpan-39bf76dae61 )