|
|
quse -Ke -- nls | quse -Ke -- nls |
*/ | */ |
| |
#define QUSE_FLAGS "eavKLDF:N" COMMON_FLAGS |
#define QUSE_FLAGS "eao:vKLDF:N" COMMON_FLAGS |
static struct option const quse_long_opts[] = { | static struct option const quse_long_opts[] = { |
{"exact", no_argument, NULL, 'e'}, | {"exact", no_argument, NULL, 'e'}, |
{"all", no_argument, NULL, 'a'}, | {"all", no_argument, NULL, 'a'}, |
|
{"overlay", a_argument, NULL, 'o'}, |
{"keywords", no_argument, NULL, 'K'}, | {"keywords", no_argument, NULL, 'K'}, |
{"license", no_argument, NULL, 'L'}, | {"license", no_argument, NULL, 'L'}, |
{"describe", no_argument, NULL, 'D'}, | {"describe", no_argument, NULL, 'D'}, |
|
Lines 28-33
static struct option const quse_long_opt
|
Link Here
|
|---|
|
static const char *quse_opts_help[] = { | static const char *quse_opts_help[] = { |
"Show exact non regexp matching using strcmp", | "Show exact non regexp matching using strcmp", |
"Show annoying things in IUSE", | "Show annoying things in IUSE", |
|
"Only consider the <arg> overlay", |
"Use the KEYWORDS vs IUSE", | "Use the KEYWORDS vs IUSE", |
"Use the LICENSE vs IUSE", | "Use the LICENSE vs IUSE", |
"Describe the USE flag", | "Describe the USE flag", |
|
Lines 38-44
static const char *quse_opts_help[] = {
|
Link Here
|
|---|
|
static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $"; | static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $"; |
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse")) | #define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse")) |
| |
int quse_describe_flag(int ind, int argc, char **argv); |
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv); |
| |
char quse_name_only = 0; | char quse_name_only = 0; |
| |
|
Lines 81-87
static void print_highlighted_use_flags(
|
Link Here
|
|---|
|
} | } |
} | } |
| |
int quse_describe_flag(int ind, int argc, char **argv) |
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv) |
{ | { |
#define NUM_SEARCH_FILES ARR_SIZE(search_files) | #define NUM_SEARCH_FILES ARR_SIZE(search_files) |
char buf[BUFSIZE], *p; | char buf[BUFSIZE], *p; |
|
Lines 91-211
int quse_describe_flag(int ind, int argc
|
Link Here
|
|---|
|
FILE *fp[NUM_SEARCH_FILES]; | FILE *fp[NUM_SEARCH_FILES]; |
DIR *d; | DIR *d; |
struct dirent *de; | struct dirent *de; |
|
overlay_t *cur_overlay; |
| |
for (i = 0; i < NUM_SEARCH_FILES; ++i) { |
cur_overlay=overlay_gentoo; |
snprintf(buf, sizeof(buf), "%s/profiles/%s", portdir, search_files[i]); |
|
if ((fp[i] = fopen(buf, "r")) == NULL) |
|
warnp("skipping %s", search_files[i]); |
|
} |
|
| |
for (i = ind; i < argc; i++) { |
do { |
s = strlen(argv[i]); |
if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search))) |
|
continue; |
|
for (i = 0; i < NUM_SEARCH_FILES; ++i) { |
|
snprintf(buf, sizeof(buf), "%s/profiles/%s", cur_overlay->path, search_files[i]); |
|
if ((fp[i] = fopen(buf, "r")) == NULL) |
|
if (verbose ) |
|
warnp("skipping %s for the %s overlay", search_files[i], cur_overlay->name); |
|
} |
| |
for (f = 0; f < NUM_SEARCH_FILES; ++f) { |
for (i = ind; i < argc; i++) { |
if (fp[f] == NULL) |
s = strlen(argv[i]); |
continue; |
|
| |
while (fgets(buf, sizeof(buf), fp[f]) != NULL) { |
for (f = 0; f < NUM_SEARCH_FILES; ++f) { |
if (buf[0] == '#' || buf[0] == '\n') |
if (fp[f] == NULL) |
continue; | continue; |
| |
if ((p = strrchr(buf, '\n')) != NULL) |
while (fgets(buf, sizeof(buf), fp[f]) != NULL) { |
*p = '\0'; |
if (buf[0] == '#' || buf[0] == '\n') |
|
continue; |
| |
switch (f) { |
if ((p = strrchr(buf, '\n')) != NULL) |
case 0: /* Global use.desc */ |
*p = '\0'; |
if (!strncmp(buf, argv[i], s)) |
|
if (buf[s] == ' ' && buf[s+1] == '-') { |
|
printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
|
goto skip_file; |
|
} |
|
break; |
|
| |
case 1: /* Local use.local.desc */ |
switch (f) { |
if ((p = strchr(buf, ':')) == NULL) |
case 0: /* Global use.desc */ |
|
if (!strncmp(buf, argv[i], s)) |
|
if (buf[s] == ' ' && buf[s+1] == '-') { |
|
if (cur_overlay == overlay_gentoo) |
|
printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
|
else |
|
printf(" (%s) %sglobal%s:%s%s%s: %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
|
goto skip_file; |
|
} |
break; | break; |
++p; |
|
if (!strncmp(p, argv[i], s)) { |
|
if (p[s] == ' ' && p[s+1] == '-') { |
|
*p = '\0'; |
|
printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3); |
|
} |
|
} |
|
break; |
|
| |
case 2: /* Architectures arch.list */ |
case 1: /* Local use.local.desc */ |
if (!strcmp(buf, argv[i])) { |
if ((p = strchr(buf, ':')) == NULL) |
printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]); |
break; |
goto skip_file; |
++p; |
} |
if (!strncmp(p, argv[i], s)) { |
break; |
if (p[s] == ' ' && p[s+1] == '-') { |
|
*p = '\0'; |
|
if (cur_overlay == overlay_gentoo) |
|
printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3); |
|
else |
|
printf(" (%s) %slocal%s:%s%s%s:%s%s%s %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3); |
|
} |
|
} |
|
break; |
| |
case 3: /* Languages lang.desc */ |
case 2: /* Architectures arch.list */ |
if (!strncmp(buf, argv[i], s)) |
if (!strcmp(buf, argv[i])) { |
if (buf[s] == ' ' && buf[s+1] == '-') { |
if (cur_overlay == overlay_gentoo) |
printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]); |
|
else |
|
printf(" (%s) %sarch%s:%s%s%s: %s architecture\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, argv[i]); |
goto skip_file; | goto skip_file; |
} | } |
break; |
break; |
|
|
|
case 3: /* Languages lang.desc */ |
|
if (!strncmp(buf, argv[i], s)) |
|
if (buf[s] == ' ' && buf[s+1] == '-') { |
|
if (cur_overlay == overlay_gentoo) |
|
printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
|
else |
|
printf(" (%s) %slang%s:%s%s%s: %s lingua\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3); |
|
goto skip_file; |
|
} |
|
break; |
|
} |
} | } |
} |
|
| |
skip_file: | skip_file: |
rewind(fp[f]); |
rewind(fp[f]); |
|
} |
|
|
|
if (i == (argc - 1)) |
|
for (f=0; f<NUM_SEARCH_FILES; ++f) |
|
if (fp[f]) { |
|
fclose(fp[f]); |
|
fp[f] = NULL; |
|
} |
} | } |
} |
|
| |
for (f=0; f<NUM_SEARCH_FILES; ++f) |
} while ((cur_overlay=cur_overlay->next)); |
fclose(fp[f]); |
|
| |
/* now scan the desc dir */ | /* now scan the desc dir */ |
snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir); |
cur_overlay=overlay_gentoo; |
d = opendir(buf); |
do { |
while ((de = readdir(d)) != NULL) { |
if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search))) |
if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc")) |
|
continue; | continue; |
|
snprintf(buf, sizeof(buf), "%s/profiles/desc/", cur_overlay->path); |
snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name); |
if (!(d = opendir(buf))) { |
if ((fp[0]=fopen(buf, "r")) == NULL) { |
if (verbose) |
warn("Could not open '%s' for reading; skipping", de->d_name); |
warn("Could not open %s -> skipping", buf); |
continue; | continue; |
} | } |
|
while ((de = readdir(d)) != NULL) { |
|
if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc")) |
|
continue; |
| |
while (fgets(buf, sizeof(buf), fp[0]) != NULL) { |
snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", cur_overlay->path, de->d_name); |
if (buf[0] == '#' || buf[0] == '\n') |
if ((fp[0]=fopen(buf, "r")) == NULL) { |
|
warn("Could not open '%s' for reading; skipping", de->d_name); |
continue; | continue; |
|
} |
| |
if ((p = strrchr(buf, '\n')) != NULL) |
while (fgets(buf, sizeof(buf), fp[0]) != NULL) { |
*p = '\0'; |
if (buf[0] == '#' || buf[0] == '\n') |
|
continue; |
|
|
|
if ((p = strrchr(buf, '\n')) != NULL) |
|
*p = '\0'; |
| |
if ((p = strchr(buf, '-')) == NULL) { |
if ((p = strchr(buf, '-')) == NULL) { |
invalid_line: | invalid_line: |
warn("Invalid line in '%s': %s", de->d_name, buf); |
warn("Invalid line in '%s': %s", de->d_name, buf); |
continue; |
continue; |
} |
} |
while (p[-1] != ' ' && p[1] != ' ') { |
while (p[-1] != ' ' && p[1] != ' ') { |
/* maybe the flag has a '-' in it ... */ |
/* maybe the flag has a '-' in it ... */ |
if ((p = strchr(p+1, '-')) == NULL) |
if ((p = strchr(p+1, '-')) == NULL) |
goto invalid_line; |
goto invalid_line; |
} |
} |
p[-1] = '\0'; |
p[-1] = '\0'; |
p += 2; |
p += 2; |
| |
for (i = ind; i < argc; i++) |
for (i = ind; i < argc; i++) |
if (!strcmp(argv[i], buf)) |
if (!strcmp(argv[i], buf)) { |
printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p); |
if (cur_overlay == overlay_gentoo) |
} |
printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p); |
close(f); |
else |
} |
printf(" (%s) %s%s%s:%s%s%s: %s\n", cur_overlay->name, BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p); |
closedir(d); |
} |
| |
|
} |
|
fclose(fp[0]); |
|
} |
|
closedir(d); |
|
} while ((cur_overlay=cur_overlay->next)); |
return 0; | return 0; |
} | } |
| |
int quse_main(int argc, char **argv) | int quse_main(int argc, char **argv) |
{ | { |
FILE *fp; | FILE *fp; |
char *p; |
char *p, *str; |
|
short myerror = 0, repo = 0; |
|
char repo_search[64]; |
|
char overlay_name[64]; |
| |
char buf0[_Q_PATH_MAX]; | char buf0[_Q_PATH_MAX]; |
char buf1[_Q_PATH_MAX]; | char buf1[_Q_PATH_MAX]; |
|
Lines 218-223
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
short quse_all = 0; | short quse_all = 0; |
int regexp_matching = 1, i, idx = 0; | int regexp_matching = 1, i, idx = 0; |
size_t search_len; | size_t search_len; |
|
overlay_t *cur_overlay, *overlay_tmp; |
|
|
|
cur_overlay = overlay_gentoo; |
|
overlay_name[0] = 0; |
|
repo_search[0] = 0; |
| |
DBG("argc=%d argv[0]=%s argv[1]=%s", | DBG("argc=%d argv[0]=%s argv[1]=%s", |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); | argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
|
Lines 226-231
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
switch (i) { | switch (i) { |
case 'e': regexp_matching = 0; break; | case 'e': regexp_matching = 0; break; |
case 'a': quse_all = 1; break; | case 'a': quse_all = 1; break; |
|
case 'o': |
|
repo = 1; |
|
strncpy(repo_search, optarg, sizeof(repo_search)); |
|
break; |
case 'K': idx = 1; break; | case 'K': idx = 1; break; |
case 'L': idx = 2; break; | case 'L': idx = 2; break; |
case 'D': idx = -1; break; | case 'D': idx = -1; break; |
|
Lines 234-244
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
COMMON_GETOPTS_CASES(quse) | COMMON_GETOPTS_CASES(quse) |
} | } |
} | } |
if (argc == optind && !quse_all && idx >= 0) |
|
|
if (repo) { |
|
do { |
|
if (!strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name))) |
|
break; |
|
} while ((cur_overlay=cur_overlay->next)); |
|
if (NULL == cur_overlay) |
|
err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search); |
|
} |
|
|
|
if (argc == optind && !quse_all && idx >= 0) { |
|
if (idx == 3) |
|
free(search_vars[idx]); |
quse_usage(EXIT_FAILURE); | quse_usage(EXIT_FAILURE); |
|
} |
| |
if (idx == -1) | if (idx == -1) |
return quse_describe_flag(optind, argc, argv); |
return quse_describe_flag(optind, repo, repo_search, argc, argv); |
| |
if (quse_all) optind = argc; | if (quse_all) optind = argc; |
initialize_ebuild_flat(); /* sets our pwd to $PORTDIR */ | initialize_ebuild_flat(); /* sets our pwd to $PORTDIR */ |
|
Lines 250-255
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
return 1; | return 1; |
while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) { | while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) { |
FILE *newfp; | FILE *newfp; |
|
if ((p = strchr(ebuild, ':'))) |
|
{ |
|
*p = 0; |
|
str = p+2; /* separator is '::' */ |
|
p = ebuild; |
|
if (repo && strncmp(repo_search, p, sizeof(repo_search))) |
|
continue; |
|
if (strncmp(overlay_name, p, sizeof(overlay_name))) { |
|
overlay_tmp=overlay_gentoo; |
|
do { |
|
if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name))) |
|
break; |
|
} while ((overlay_tmp=overlay_tmp->next)); |
|
if (overlay_tmp) |
|
{ |
|
cur_overlay = overlay_tmp; |
|
if (chdir(cur_overlay->path) != 0) { |
|
warnp("chdir to PORTDIR '%s' failed", cur_overlay->path); |
|
myerror=1; |
|
} |
|
} else |
|
myerror=1; |
|
|
|
strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name)); |
|
} |
|
strcpy(ebuild, str); |
|
} else |
|
myerror=1; |
|
|
|
if (myerror) { |
|
if (!reinitialize) |
|
warnf("(cache update pending) %s : Unknown overlay", overlay_name); |
|
reinitialize = 1; |
|
myerror=0; |
|
continue; |
|
} |
|
|
if ((p = strchr(ebuild, '\n')) != NULL) | if ((p = strchr(ebuild, '\n')) != NULL) |
*p = 0; | *p = 0; |
if ((newfp = fopen(ebuild, "r")) != NULL) { | if ((newfp = fopen(ebuild, "r")) != NULL) { |
|
Lines 375-381
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
if (verbose > 3) | if (verbose > 3) |
printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING"); | printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING"); |
| |
printf("%s%s%s ", CYAN, ebuild, NORM); |
printf("%s%s::%s%s ", CYAN, cur_overlay->name, ebuild, NORM); |
print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv); | print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv); |
puts(NORM); | puts(NORM); |
if (verbose > 1) { | if (verbose > 1) { |
|
Lines 383-389
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
int ARGC = 0; | int ARGC = 0; |
makeargv(&buf0[search_len+1], &ARGC, &ARGV); | makeargv(&buf0[search_len+1], &ARGC, &ARGV); |
if (ARGC > 0) { | if (ARGC > 0) { |
quse_describe_flag(1, ARGC, ARGV); |
quse_describe_flag(1, repo, repo_search, ARGC, ARGV); |
for (i = 0; i < ARGC; i++) | for (i = 0; i < ARGC; i++) |
free(ARGV[i]); | free(ARGV[i]); |
free(ARGV); | free(ARGV); |
|
Lines 400-405
int quse_main(int argc, char **argv)
|
Link Here
|
|---|
|
} | } |
} | } |
fclose(fp); | fclose(fp); |
|
if (idx == 3) |
|
free(search_vars[idx]); |
return EXIT_SUCCESS; | return EXIT_SUCCESS; |
} | } |
| |