2
* \file popt/poptconfig.c
5
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
6
file accompanying popt source distributions, available from
7
ftp://ftp.rpm.org/pub/rpm/dist. */
12
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */
13
static void configLine(poptContext con, char * line)
17
int nameLength = strlen(con->appName);
19
const char * entryType;
21
poptItem item = (poptItem)alloca(sizeof(*item));
25
memset(item, 0, sizeof(*item));
28
if (strncmp(line, con->appName, nameLength)) return;
32
if (*line == '\0' || !isspace(*line)) return;
34
while (*line != '\0' && isspace(*line)) line++;
36
while (*line == '\0' || !isspace(*line)) line++;
39
while (*line != '\0' && isspace(*line)) line++;
40
if (*line == '\0') return;
42
while (*line == '\0' || !isspace(*line)) line++;
45
while (*line != '\0' && isspace(*line)) line++;
46
if (*line == '\0') return;
48
/*@-temptrans@*/ /* FIX: line alias is saved */
49
if (opt[0] == '-' && opt[1] == '-')
50
item->option.longName = opt + 2;
51
else if (opt[0] == '-' && opt[2] == '\0')
52
item->option.shortName = opt[1];
55
if (poptParseArgvString(line, &item->argc, &item->argv)) return;
58
item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN;
59
for (i = 0, j = 0; i < item->argc; i++, j++) {
61
if (!strncmp(item->argv[i], "--POPTdesc=", sizeof("--POPTdesc=")-1)) {
62
f = item->argv[i] + sizeof("--POPTdesc=");
63
if (f[0] == '$' && f[1] == '"') f++;
64
item->option.descrip = f;
65
item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
68
if (!strncmp(item->argv[i], "--POPTargs=", sizeof("--POPTargs=")-1)) {
69
f = item->argv[i] + sizeof("--POPTargs=");
70
if (f[0] == '$' && f[1] == '"') f++;
71
item->option.argDescrip = f;
72
item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
73
item->option.argInfo |= POPT_ARG_STRING;
77
item->argv[j] = item->argv[i];
86
/*@-nullstate@*/ /* FIX: item->argv[] may be NULL */
87
if (!strcmp(entryType, "alias"))
88
(void) poptAddItem(con, item, 0);
89
else if (!strcmp(entryType, "exec"))
90
(void) poptAddItem(con, item, 1);
95
int poptReadConfigFile(poptContext con, const char * fn)
97
const char * file, * chptr, * end;
99
/*@dependent@*/ char * dst;
103
fd = open(fn, O_RDONLY);
105
return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
107
fileLength = lseek(fd, 0, SEEK_END);
108
if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
114
return POPT_ERROR_ERRNO;
117
file = (const char *)alloca(fileLength + 1);
118
if (read(fd, (char *)file, fileLength) != fileLength) {
124
return POPT_ERROR_ERRNO;
127
return POPT_ERROR_ERRNO;
130
dst = buf = (char *)alloca(fileLength + 1);
133
end = (file + fileLength);
134
/*@-infloops@*/ /* LCL: can't detect chptr++ */
135
while (chptr < end) {
140
while (*dst && isspace(*dst)) dst++;
141
if (*dst && *dst != '#')
142
configLine(con, dst);
144
/*@switchbreak@*/ break;
150
/* \ at the end of a line does not insert a \n */
154
/*@switchbreak@*/ break;
157
/*@switchbreak@*/ break;
166
int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
172
if (!con->appName) return 0;
175
rc = poptReadConfigFile(con, "/etc/popt");
177
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
178
if (getuid() != geteuid()) return 0;
181
if ((home = getenv("HOME"))) {
182
fn = (char *)alloca(strlen(home) + 20);
184
strcat(fn, "/.popt");
185
rc = poptReadConfigFile(con, fn);