16 #if defined(HAVE_FNMATCH_H)
21 #if defined(HAVE_GLOB_H)
24 #if !defined(__GLIBC__)
28 glob_pattern_p (
const char * pattern,
int quote)
33 for (p = pattern; *p !=
'\0'; ++p)
40 if (quote && p[1] !=
'\0')
55 static int poptGlobFlags = 0;
57 static int poptGlob_error(
UNUSED(
const char * epath),
73 int * acp,
const char *** avp)
75 const char * pat = pattern;
78 #if defined(HAVE_GLOB_H)
79 if (glob_pattern_p(pat, 0)) {
80 glob_t _g, *pglob = &_g;
82 if (!(rc = glob(pat, poptGlobFlags, poptGlob_error, pglob))) {
84 *acp = (int) pglob->gl_pathc;
88 *avp = (
const char **) pglob->gl_pathv;
89 pglob->gl_pathv = NULL;
92 }
else if (rc == GLOB_NOMATCH) {
103 if (avp && (*avp = calloc((
size_t)(1 + 1),
sizeof (**avp))) != NULL)
115 if (fn == NULL || strstr(fn,
".rpmnew") || strstr(fn,
".rpmsave"))
117 if (stat(fn, &sb) == -1)
119 if (!S_ISREG(sb.st_mode))
121 if (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))
134 fdno = open(fn, O_RDONLY);
138 if ((nb = lseek(fdno, 0, SEEK_END)) == (off_t)-1
139 || lseek(fdno, 0, SEEK_SET) == (off_t)-1
140 || (b = calloc(
sizeof(*b), (
size_t)nb + 1)) == NULL
141 || read(fdno, (
char *)b, (
size_t)nb) != (ssize_t)nb)
148 if (close(fdno) == -1)
159 for (t = b, s = b, se = b + nb; *s && s < se; s++) {
202 if (con == NULL || con->
appName == NULL)
205 #if defined(HAVE_GLOB_H) && defined(HAVE_FNMATCH_H)
206 if (glob_pattern_p(s, 1)) {
207 static int flags = FNM_PATHNAME | FNM_PERIOD;
209 flags |= FNM_EXTMATCH;
211 rc = fnmatch(s, con->
appName, flags);
223 const char * appName;
224 const char * entryType;
231 if (con == NULL || con->
appName == NULL)
234 memset(item, 0,
sizeof(*item));
248 if (*se !=
'\0') *se++ =
'\0';
251 if (*se ==
'\0')
goto exit;
254 if (opt[0] ==
'-' && *se ==
'\0')
goto exit;
255 if (*se !=
'\0') *se++ =
'\0';
258 if (opt[0] ==
'-' && *se ==
'\0')
goto exit;
260 if (opt[0] ==
'-' && opt[1] ==
'-')
261 item->option.longName = opt + 2;
262 else if (opt[0] ==
'-' && opt[2] ==
'\0')
263 item->option.shortName = opt[1];
265 const char * fn = opt;
270 if (b == NULL || nb == 0)
275 size_t nse = strlen(se) + 1;
276 if ((b = realloc(b, (nb + nse))) == NULL)
284 {
const char * longName = strrchr(fn,
'/');
285 if (longName != NULL)
289 if (longName == NULL)
292 if (longName[1] !=
'\0')
293 item->option.longName = longName;
295 item->option.shortName = longName[0];
302 for (i = 0, j = 0; i < item->argc; i++, j++) {
304 if (!strncmp(item->argv[i],
"--POPTdesc=",
sizeof(
"--POPTdesc=")-1)) {
305 f = item->argv[i] +
sizeof(
"--POPTdesc=");
306 if (f[0] ==
'$' && f[1] ==
'"') f++;
307 item->option.descrip = f;
311 if (!strncmp(item->argv[i],
"--POPTargs=",
sizeof(
"--POPTargs=")-1)) {
312 f = item->argv[i] +
sizeof(
"--POPTargs=");
313 if (f[0] ==
'$' && f[1] ==
'"') f++;
314 item->option.argDescrip = f;
320 item->argv[j] = item->argv[i];
323 item->argv[j] = NULL;
327 if (!strcmp(entryType,
"alias"))
329 else if (!strcmp(entryType,
"exec"))
340 char * b = NULL, *be;
349 return (errno == ENOENT ? 0 : rc);
350 if (b == NULL || nb == 0)
353 if ((t = malloc(nb + 1)) == NULL)
358 for (se = b; se < be; se++) {
364 if (*te && *te !=
'#')
371 if (se < be && *se !=
'\n') {
392 char * buf = (paths ?
xstrdup(paths) : NULL);
397 for (p = buf; p != NULL && *p !=
'\0'; p = pe) {
398 const char ** av = NULL;
405 if (pe != NULL && *pe ==
':')
408 pe = (
char *) (p + strlen(p));
413 for (i = 0; i < ac; i++) {
414 const char * fn = av[i];
439 if (con == NULL || con->
appName == NULL)
goto exit;
444 #if defined(HAVE_GLOB_H)
445 if (!stat(POPT_SYSCONFDIR
"/popt.d", &sb) && S_ISDIR(sb.st_mode)) {
446 const char ** av = NULL;
450 if ((rc =
poptGlob(con, POPT_SYSCONFDIR
"/popt.d/*", &ac, &av)) == 0) {
451 for (i = 0; rc == 0 && i < ac; i++) {
452 const char * fn = av[i];
466 if ((home = getenv(
"HOME"))) {
467 char * fn = malloc(strlen(home) + 20);
489 const struct poptOption * options,
const char * configPaths)
494 if (argv == NULL || argv[0] == NULL || options == NULL)
497 if ((argv0 = strrchr(argv[0],
'/')) != NULL) argv0++;
498 else argv0 = argv[0];
500 con =
poptGetContext(argv0, argc, (
const char **)argv, options, 0);
int poptAddItem(poptContext con, poptItem newItem, int flags)
Add alias/exec item to context.
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Initialize popt context.
poptContext poptFreeContext(poptContext con)
Destroy context.
#define POPT_ARGFLAG_DOC_HIDDEN
#define POPT_READFILE_TRIMNEWLINES
#define POPT_ERROR_MALLOC
int poptParseArgvString(const char *s, int *argcPtr, const char ***argvPtr)
Parse a string into an argument array.
#define POPT_ERROR_NOCONTEXT
#define POPT_ERROR_BADCONFIG
static int poptGlob(poptContext con, const char *pattern, int *acp, const char ***avp)
Return path(s) from a glob pattern.
int poptReadFile(const char *fn, char **bp, size_t *nbp, int flags)
Read a file into a buffer.
static int poptConfigLine(poptContext con, char *line)
int poptReadConfigFiles(poptContext con, const char *paths)
Read configuration file(s).
static int configAppMatch(poptContext con, const char *s)
Check for application match.
int poptReadConfigFile(poptContext con, const char *fn)
Read configuration file.
poptContext poptFini(poptContext con)
Destroy context (alternative implementation).
poptContext poptInit(int argc, const char **argv, const struct poptOption *options, const char *configPaths)
Initialize popt context (alternative implementation).
int poptSaneFile(const char *fn)
Test path/file for config file sanity (regular file, permissions etc)
int poptReadDefaultConfig(poptContext con, int useEnv)
Read default configuration from /etc/popt and $HOME/.popt.
A popt alias or exec argument for poptAddItem().
#define _isspaceptr(_chp)
static char * stpcpy(char *dest, const char *src)
char * xstrdup(const char *str)