int qatom_main(int argc, char **argv) { enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT } action = _EXPLODE; const char *format = QATOM_FORMAT; depend_atom *atom; depend_atom *atomc; int i; while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) { switch (i) { case 'F': format = optarg; break; case 'c': action = _COMPARE; break; case 'p': action = _PRINT; break; COMMON_GETOPTS_CASES(qatom) } } if (argc == optind) qatom_usage(EXIT_FAILURE); if (action == _COMPARE && (argc - optind) % 2) err("compare needs even number of arguments"); for (i = optind; i < argc; ++i) { atom = atom_explode(argv[i]); if (atom == NULL) { warnf("invalid atom: %s\n", argv[i]); continue; } switch (action) { case _COMPARE: i++; atomc = atom_explode(argv[i]); if (atomc == NULL) { warnf("invalid atom: %s\n", argv[i]); break; } printf("%s %s ", atom_to_string(atom), booga[atom_compare(atom, atomc)]); printf("%s\n", atom_to_string(atomc)); atom_implode(atomc); break; case _EXPLODE: qatom_printf(format, atom, verbose); putchar('\n'); break; case _PRINT: printf("%s\n", atom_to_string(atom)); break; } atom_implode(atom); } return EXIT_SUCCESS; }
int qtemp_main(int argc, char **argv) { int i; DBG("argc=%d argv[0]=%s argv[1]=%s", argc, argv[0], argc > 1 ? argv[1] : "NULL?"); while ((i = GETOPT_LONG(QTEMP, qtemp, "")) != -1) { switch (i) { COMMON_GETOPTS_CASES(qtemp) } } return EXIT_SUCCESS; }
int qglsa_main(int argc, char **argv) { int i; char *fixed_list; qglsa_action action = GLSA_FUNKYTOWN; bool all_glsas = false; while ((i = GETOPT_LONG(QGLSA, qglsa, "")) != -1) { #define set_action(a) { if (action == 0) action = a; else err("cannot specify more than one action at a time"); } switch (i) { case 'l': set_action(GLSA_LIST); break; case 'd': set_action(GLSA_DUMP); break; case 't': set_action(GLSA_TEST); break; case 'p': pretend = 1; break; case 'f': set_action(GLSA_FIX); break; case 'i': set_action(GLSA_INJECT); break; COMMON_GETOPTS_CASES(qglsa) } } if (action == GLSA_FUNKYTOWN) qglsa_usage(EXIT_FAILURE); if (action != GLSA_LIST && optind == argc) err("specified action requires a list, either 'all', 'new', or GLSA numbers"); for (i = optind; i < argc; ++i) { if (!strcmp(argv[i], "all")) { all_glsas = true; if (optind+1 != argc) err("You may only use class names by themselves"); } else if (!strcmp(argv[i], "new")) { all_glsas = false; if (optind+1 != argc) err("You may only use class names by themselves"); } } fixed_list = qglsa_load_list(); int ret = 0; size_t n; const char *overlay; array_for_each(overlays, n, overlay) ret |= qglsa_run_action(overlay, action, fixed_list, all_glsas, optind, argc, argv); return ret; }
/* * Main. */ int main(int argc, char **argv, char **env) { int c; char *programname=argv[0]; char *plugname="/tmp/vde.ctl"; char *remotehost = NULL; char *remoteusr = NULL; char *pre_shared = NULL; enum e_enc_type enc_type = ENC_SSH; unsigned short udp_port = PORTNO; unsigned short remoteport = PORTNO; unsigned char keepalives=0; char *scp_extra_options; int daemonize = 0; scp_extra_options=getenv("SCP_EXTRA_OPTIONS"); while (1) { int option_index = 0; char *ctl_socket; const char sepusr='******'; const char sepport=':'; char *pusr,*pport, *vvv=NULL; static struct option long_options[] = { {"sock", 1, 0, 's'}, {"vdesock", 1, 0, 's'}, {"unix", 1, 0, 's'}, {"localport", 1, 0, 'p'}, {"connect",1,0,'c'}, {"preshared ",1,0,'P'}, {"noencrypt",0,0,'x'}, {"keepalive",0,0,'k'}, {"verbose",optional_argument,0,'v'}, {"help",0,0,'h'}, {"daemon",0,0,'d'}, {0, 0, 0, 0} }; c = GETOPT_LONG (argc, argv, "s:p:c:P:hv::xkd", long_options, &option_index); if (c == -1) break; switch (c) { case 's': plugname=strdup(optarg); break; case 'v': verbose=1; if(optarg) vvv=strdup(optarg); while(vvv && *vvv++ == 'v') verbose++; break; case 'x': enc_type = ENC_NOENC; break; case 'c': ctl_socket=strdup(optarg); pusr=strchr(ctl_socket,sepusr); pport=strchr(ctl_socket,sepport); if( ( pusr != strrchr(ctl_socket,sepusr)) || (pport != strrchr(ctl_socket,sepport)) || (pport && pusr>pport) ) Usage(programname); if(!pusr && !pport){ remoteusr=NULL; remoteport=PORTNO; remotehost=strdup(ctl_socket); break; } if(!pport){ remoteusr=(char *)strndup(ctl_socket,pusr-ctl_socket); remotehost=(char *)strndup(pusr+1,strlen(ctl_socket)-strlen(remoteusr)-1); remoteport=PORTNO; break; } if(!pusr){ remoteusr=NULL; remotehost=(char *)strndup(ctl_socket,pport-ctl_socket); remoteport=atoi((char *)strndup(pport+1,strlen(ctl_socket)-strlen(remotehost)-1)); break; } remoteusr=(char *)strndup(ctl_socket,pusr-ctl_socket); remotehost=(char *)strndup(pusr+1,pport-pusr-1); remoteport=atoi((char *)strndup(pport+1,strlen(ctl_socket)-strlen(remotehost)-strlen(remoteusr)-2)); break; case 'p': udp_port=atoi(optarg); break; case 'P': pre_shared=strdup(optarg); fprintf(stderr,"Using pre-shared key %s\n",pre_shared); enc_type = ENC_PRESHARED; break; case 'k': keepalives=1; break; case 'd': daemonize=1; break; case 'h': default: Usage(programname); } } if(optind < argc) Usage(programname); if (keepalives && remotehost==NULL){ fprintf(stderr,"\nkeepalive option is valid in client mode only.\n\n"); Usage(programname); } if (pre_shared && enc_type == ENC_NOENC){ fprintf(stderr,"\nWarning: Not using pre-shared key mode, encryption disabled.\n\n"); pre_shared = NULL; } vc_printlog(1,"Verbosity: %d", verbose); chksum_crc32gentab(); switch(enc_type){ case ENC_NOENC: vc_printlog(1,"Encryption Disabled."); break; case ENC_PRESHARED: vc_printlog(1,"Using pre-shared key %s",pre_shared); break; case ENC_SSH: vc_printlog(1,"Using ssh key exchange for authentication"); break; } if (daemonize) { if (fork() == 0) { setsid(); close(STDIN_FILENO); close(STDOUT_FILENO); if (fork() > 0) exit(0); } else exit(0); } if(!remotehost){ cryptcab_server(plugname, udp_port, enc_type, pre_shared); } else { cryptcab_client(plugname, udp_port, enc_type, pre_shared, remoteusr, remotehost, remoteport, keepalives, scp_extra_options); } exit(0); }
int main(int argc, char **argv) { static char *sockname=NULL; static char *tapname=NULL; int daemonize=0; int tapfd; register ssize_t nx; struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700}; int c; static struct pollfd pollv[]={{0,POLLIN|POLLHUP}, {0,POLLIN|POLLHUP}, {0,POLLIN|POLLHUP}}; int npollv; prog=argv[0]; while (1) { int option_index = 0; static struct option long_options[] = { {"sock", 1, 0, 's'}, {"port", 1, 0, 'p'}, {"help",0,0,'h'}, {"mod",1,0,'m'}, {"group",1,0,'g'}, {"daemon",0,0,'d'}, {"pidfile", 1, 0, 'P'}, {0, 0, 0, 0} }; c = GETOPT_LONG (argc, argv, "hdP:p:s:m:g:", long_options, &option_index); if (c == -1) break; switch (c) { case 'p': open_args.port=atoi(optarg); if (open_args.port <= 0) usage(); //implies exit break; case 'h': usage(); //implies exit break; case 's': sockname=strdup(optarg); break; case 'm': sscanf(optarg,"%o",(unsigned int *)&(open_args.mode)); break; case 'g': open_args.group=strdup(optarg); break; case 'd': daemonize=1; break; case 'P': pidfile=strdup(optarg); break; default: usage(); //implies exit } } if (daemonize) { openlog(basename(prog), LOG_PID, 0); logok=1; syslog(LOG_INFO,"VDE_PLUG2TAP started"); } /* saves current path in pidfile_path, because otherwise with daemonize() we * forget it */ if(getcwd(pidfile_path, PATH_MAX-1) == NULL) { printlog(LOG_ERR, "getcwd: %s", strerror(errno)); exit(1); } strcat(pidfile_path, "/"); if (daemonize && daemon(0, 0)) { printlog(LOG_ERR,"daemon: %s",strerror(errno)); exit(1); } /* once here, we're sure we're the true process which will continue as a * server: save PID file if needed */ if(pidfile) save_pidfile(); if (optind < argc) tapname=argv[optind]; else usage(); // implies exit atexit(cleanup); setsighandlers(); tapfd=open_tap(tapname); if(tapfd<0) exit(1); pollv[0].fd=tapfd; if (sockname==NULL || strcmp(sockname,"-") != 0) { conn=vde_open(sockname,"vde_plug2tap:",&open_args); if (conn == NULL) { printlog(LOG_ERR,"vde_open %s: %s",sockname?sockname:"DEF_SWITCH",strerror(errno)); exit(1); } pollv[1].fd=vde_datafd(conn); pollv[2].fd=vde_ctlfd(conn); npollv=3; } else { vdestream=vdestream_open(&tapfd,STDOUT_FILENO,vde_plug2tap_recv,NULL); if (vdestream == NULL) exit(1); pollv[1].fd=STDIN_FILENO; npollv=2; } for(;;) { poll(pollv,3,-1); if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) & POLLHUP || (npollv > 2 && pollv[2].revents & POLLIN)) break; if (pollv[0].revents & POLLIN) { nx=read(tapfd,bufin,sizeof(bufin)); /* if POLLIN but not data it means that the stream has been * closed at the other end */ //fprintf(stderr,"%s: RECV %d %x %x \n",prog,nx,bufin[0],bufin[1]); if (nx<=0) break; if (conn != NULL) vde_send(conn,bufin,nx,0); else vdestream_send(vdestream, bufin, nx); } if (pollv[1].revents & POLLIN) { if (conn != NULL) { nx=vde_recv(conn,bufin,sizeof(bufin),0); if (nx<=0) break; write(tapfd,bufin,nx); } else { nx=read(STDIN_FILENO,bufin,sizeof(bufin)); if (nx<=0) break; vdestream_recv(vdestream,bufin,nx); } //fprintf(stderr,"%s: SENT %d %x %x \n",prog,nx,bufin[0],bufin[1]); } } return(0); }
int qpkg_main(int argc, char **argv) { q_vdb_ctx *ctx; q_vdb_cat_ctx *cat_ctx; q_vdb_pkg_ctx *pkg_ctx; size_t s, pkgs_made; int i; struct stat st; char buf[BUFSIZE]; const char *bindir; depend_atom *atom; int restrict_chmod = 0; int qclean = 0; while ((i = GETOPT_LONG(QPKG, qpkg, "")) != -1) { switch (i) { case 'E': eclean = qclean = 1; break; case 'c': qclean = 1; break; case 'p': pretend = 1; break; case 'P': restrict_chmod = 1; free(qpkg_bindir); qpkg_bindir = xstrdup(optarg); if (access(qpkg_bindir, W_OK) != 0) errp("%s", qpkg_bindir); break; COMMON_GETOPTS_CASES(qpkg) } } if (qclean) return qpkg_clean(qpkg_bindir == NULL ? pkgdir : qpkg_bindir); if (argc == optind) qpkg_usage(EXIT_FAILURE); /* setup temp dirs */ i = 0; bindir = qpkg_get_bindir(); if (*bindir != '/') err("'%s' is not a valid package destination", bindir); retry_mkdir: if (mkdir(bindir, 0750) == -1) { lstat(bindir, &st); if (!S_ISDIR(st.st_mode)) { unlink(bindir); if (!i++) goto retry_mkdir; errp("could not create temp bindir '%s'", bindir); } if (!restrict_chmod) if (chmod(bindir, 0750)) errp("could not chmod(0750) temp bindir '%s'", bindir); } /* we have to change to the root so that we can feed the full paths * to tar when we create the binary package. */ xchdir(portroot); /* first process any arguments which point to /var/db/pkg */ pkgs_made = 0; s = strlen(portvdb); for (i = optind; i < argc; ++i) { size_t asize = strlen(argv[i]); if (asize == 0) { argv[i] = NULL; continue; } if (argv[i][asize-1] == '/') argv[i][asize-1] = '\0'; if (!strncmp(portvdb, argv[i], s)) memmove(argv[i], argv[i]+s+1, asize-s); else if (argv[i][0] == '/' && !strncmp(portvdb, argv[i]+1, s)) memmove(argv[i], argv[i]+s+2, asize-s-1); else continue; atom = atom_explode(argv[i]); if (atom) { if (!qpkg_make(atom)) ++pkgs_made; atom_implode(atom); } else warn("could not explode '%s'", argv[i]); argv[i] = NULL; } /* now try to run through vdb and locate matches for user inputs */ ctx = q_vdb_open(portroot, portvdb); if (!ctx) return EXIT_FAILURE; /* scan all the categories */ while ((cat_ctx = q_vdb_next_cat(ctx))) { /* scan all the packages in this category */ const char *catname = cat_ctx->name; while ((pkg_ctx = q_vdb_next_pkg(cat_ctx))) { const char *pkgname = pkg_ctx->name; /* see if user wants any of these packages */ snprintf(buf, sizeof(buf), "%s/%s", catname, pkgname); atom = atom_explode(buf); if (!atom) { warn("could not explode '%s'", buf); goto next_pkg; } snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN); for (i = optind; i < argc; ++i) { if (!argv[i]) continue; if (!strcmp(argv[i], atom->PN) || !strcmp(argv[i], atom->P) || !strcmp(argv[i], buf) || !strcmp(argv[i], "world")) if (!qpkg_make(atom)) ++pkgs_made; } atom_implode(atom); next_pkg: q_vdb_close_pkg(pkg_ctx); } } s = (argc - optind) - pkgs_made; if (s && !pretend) printf(" %s*%s %i package%s could not be matched :/\n", RED, NORM, (int)s, (s > 1 ? "s" : "")); if (pkgs_made) qprintf(" %s*%s Packages can be found in %s\n", GREEN, NORM, bindir); return (pkgs_made ? EXIT_SUCCESS : EXIT_FAILURE); }
int qsearch_main(int argc, char **argv) { FILE *fp; char *ebuild = NULL; char last[126] = ""; char *p, *q, *str; char *search_me = NULL; char show_homepage = 0, show_name_only = 0; char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD; const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" }; size_t search_len, ebuild_len; int i, idx=0; DBG("argc=%d argv[0]=%s argv[1]=%s", argc, argv[0], argc > 1 ? argv[1] : "NULL?"); while ((i = GETOPT_LONG(QSEARCH, qsearch, "")) != -1) { switch (i) { COMMON_GETOPTS_CASES(qsearch) case 'a': search_all = 1; break; case 'c': search_cache = CACHE_METADATA; break; case 'e': search_cache = CACHE_EBUILD; break; case 's': search_desc = 0; search_name = 1; break; case 'S': search_desc = 1; search_name = 0; break; case 'N': show_name_only = 1; break; case 'H': show_homepage = 1, idx = 1; break; } } if (search_all) { search_desc = 1; search_name = 0; } else { if (argc == optind) qsearch_usage(EXIT_FAILURE); search_me = argv[optind]; } #ifdef TESTING /* FIXME: hardcoded */ if ((search_cache == CACHE_EBUILD) && (access("/usr/portage/.qsearch.x", R_OK) == 0)) { if ((fp = fopen("/usr/portage/.qsearch.x", "r")) != NULL) { search_len = strlen(search_me); while (fgets(buf, sizeof(buf), fp) != NULL) { if (strlen(buf) <= search_len) continue; /* add regexp, color highlighting and basename checks */ if (strncmp(buf, search_me, search_len) == 0) { fputs(buf, stdout); } } fclose(fp); return 0; } } #endif last[0] = 0; fp = fopen(initialize_flat(search_cache, false), "r"); if (!fp) return 1; int portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH); if (portdir_fd < 0) errp("open(%s) failed", portdir); q = NULL; /* Silence a gcc warning. */ search_len = strlen(search_vars[idx]); while (getline(&ebuild, &ebuild_len, fp) != -1) { if ((p = strchr(ebuild, '\n')) != NULL) *p = 0; if (!ebuild[0]) continue; switch (search_cache) { case CACHE_METADATA: { portage_cache *pcache; if ((pcache = cache_read_file(ebuild)) != NULL) { if (strcmp(pcache->atom->PN, last) != 0) { strncpy(last, pcache->atom->PN, sizeof(last)); if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE) == 0) || search_all) printf("%s%s/%s%s%s %s\n", BOLD, pcache->atom->CATEGORY, BLUE, pcache->atom->PN, NORM, (show_name_only ? "" : (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION))); } cache_free(pcache); } else { if (!reinitialize) warnf("(cache update pending) %s", ebuild); reinitialize = 1; } break; } case CACHE_EBUILD: { FILE *ebuildfp; str = xstrdup(ebuild); p = dirname(str); if (strcmp(p, last) != 0) { bool show_it = false; strncpy(last, p, sizeof(last)); if (search_name) { if (rematch(search_me, basename(last), REG_EXTENDED | REG_ICASE) != 0) { goto no_cache_ebuild_match; } else { q = NULL; show_it = true; } } int fd = openat(portdir_fd, ebuild, O_RDONLY|O_CLOEXEC); if (fd != -1) { ebuildfp = fdopen(fd, "r"); if (ebuildfp == NULL) { close(fd); continue; } } else { if (!reinitialize) warnfp("(cache update pending) %s", ebuild); reinitialize = 1; goto no_cache_ebuild_match; } char *buf = NULL; size_t buflen; while (getline(&buf, &buflen, ebuildfp) != -1) { if (strlen(buf) <= search_len) continue; if (strncmp(buf, search_vars[idx], search_len) != 0) continue; if ((q = strrchr(buf, '"')) != NULL) *q = 0; if (strlen(buf) <= search_len) break; q = buf + search_len + 1; if (!search_all && !search_name && rematch(search_me, q, REG_EXTENDED | REG_ICASE) != 0) break; show_it = true; break; } if (show_it) { printf("%s%s/%s%s%s %s\n", BOLD, dirname(p), BLUE, basename(p), NORM, (show_name_only ? "" : q ? : "<no DESCRIPTION found>")); } free(buf); fclose(ebuildfp); } no_cache_ebuild_match: free(str); break; } /* case CACHE_EBUILD */ } /* switch (search_cache) */ }
int qgrep_main(int argc, char **argv) { int i; int count = 0; char *p; char do_count, do_regex, do_eclass, do_installed, do_list; char show_filename, skip_comments, invert_list, show_name; char per_file_output; FILE *fp = NULL; DIR *eclass_dir = NULL; DIR *vdb_dir = NULL; DIR *cat_dir = NULL; struct dirent *dentry; char ebuild[_Q_PATH_MAX]; char name[_Q_PATH_MAX]; char *label; int reflags = 0; char invert_match = 0; regex_t preg, skip_preg; char *skip_pattern = NULL; depend_atom** include_atoms = NULL; unsigned long int context_optarg; char num_lines_before = 0; char num_lines_after = 0; qgrep_buf_t *buf_list; int need_separator = 0; char status = 1; QGREP_STR_FUNC strfunc = strstr; do_count = do_regex = do_eclass = do_installed = do_list = 0; show_filename = skip_comments = invert_list = show_name = 0; while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { switch (i) { case 'I': invert_match = 1; break; case 'i': strfunc = strcasestr; reflags |= REG_ICASE; break; case 'c': do_count = 1; break; case 'l': do_list = 1; break; case 'L': do_list = invert_list = 1; break; case 'e': do_regex = 1; break; case 'x': do_regex = 1; reflags |= REG_EXTENDED; break; case 'J': do_installed = 1; break; case 'E': do_eclass = 1; break; case 'H': show_filename = 1; break; case 'N': show_name = 1; break; case 's': skip_comments = 1; break; case 'S': skip_pattern = optarg; break; case 'B': case 'A': errno = 0; context_optarg = strtol(optarg, &p, 10); if (errno != 0) errp("%s: not a valid integer", optarg); else if (p == optarg || *p != '\0') err("%s: not a valid integer", optarg); if (context_optarg > 254) err("%s: silly value!", optarg); if (i == 'B') num_lines_before = context_optarg; else num_lines_after = context_optarg; break; COMMON_GETOPTS_CASES(qgrep) } } if (argc == optind) qgrep_usage(EXIT_FAILURE); if (do_list && do_count) { warn("%s and --count are incompatible options. The former wins.", (invert_list ? "--invert-list" : "--list")); do_count = 0; } if (show_name && show_filename) { warn("--with-name and --with-filename are incompatible options. The former wins."); show_filename = 0; } if (do_list && num_lines_before) { warn("%s and --before are incompatible options. The former wins.", (invert_list ? "--invert-list" : "--list")); num_lines_before = 0; } if (do_list && num_lines_after) { warn("%s and --after are incompatible options. The former wins.", (invert_list ? "--invert-list" : "--list")); num_lines_after = 0; } if (do_count && num_lines_before) { warn("--count and --before are incompatible options. The former wins."); num_lines_before = 0; } if (do_count && num_lines_after) { warn("--count and --after are incompatible options. The former wins."); num_lines_after = 0; } if (do_installed && do_eclass) { warn("--installed and --eclass are incompatible options. The former wins."); do_eclass = 0; } /* do we report results once per file or per line ? */ per_file_output = do_count || (do_list && (!verbose || invert_list)); /* label for prefixing matching lines or listing matching files */ label = (show_name ? name : ((verbose || show_filename || do_list) ? ebuild : NULL)); if (argc > (optind + 1)) { include_atoms = xcalloc(sizeof(depend_atom*), (argc - optind - 1)); for (i = (optind + 1); i < argc; i++) if ((include_atoms[i - optind - 1] = atom_explode(argv[i])) == NULL) warn("%s: invalid atom, will be ignored", argv[i]); } /* pre-compile regexps once for all */ if (do_regex) { if (invert_match || *RED == '\0') reflags |= REG_NOSUB; xregcomp(&preg, argv[optind], reflags); reflags |= REG_NOSUB; if (skip_pattern) xregcomp(&skip_preg, skip_pattern, reflags); } /* allocate a circular buffers list for --before */ buf_list = qgrep_buf_list_alloc(num_lines_before + 1); size_t n; char *overlay; array_for_each(overlays, n, overlay) { /* go look either in ebuilds or eclasses or VDB */ if (!do_eclass && !do_installed) { fp = fopen(initialize_flat(overlay, CACHE_EBUILD, false), "re"); if (fp == NULL) continue; xchdir(overlay); } else if (do_eclass) { xchdir(overlay); if ((eclass_dir = opendir("eclass")) == NULL) { if (errno != ENOENT) warnp("opendir(\"%s/eclass\") failed", overlay); continue; } } else { /* if (do_install) */ char buf[_Q_PATH_MAX]; snprintf(buf, sizeof(buf), "%s/%s", portroot, portvdb); xchdir(buf); if ((vdb_dir = opendir(".")) == NULL) errp("could not opendir(%s/%s) for ROOT/VDB", portroot, portvdb); } /* iteration is either over ebuilds or eclasses */ while (do_eclass ? ((dentry = readdir(eclass_dir)) && snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name)) : (do_installed ? (get_next_installed_ebuild(ebuild, vdb_dir, &dentry, &cat_dir) != NULL) : (fgets(ebuild, sizeof(ebuild), fp) != NULL))) { FILE *newfp; /* filter badly named files, prepare eclass or package name, etc. */ if (do_eclass) { if ((p = strrchr(ebuild, '.')) == NULL) continue; if (strcmp(p, ".eclass")) continue; if (show_name || (include_atoms != NULL)) { /* cut ".eclass" */ *p = '\0'; /* and skip "eclass/" */ snprintf(name, sizeof(name), "%s", ebuild + 7); /* restore the filepath */ *p = '.'; } } else { if ((p = strchr(ebuild, '\n')) != NULL) *p = '\0'; if (show_name || (include_atoms != NULL)) { /* cut ".ebuild" */ if (p == NULL) p = ebuild + strlen(ebuild); *(p-7) = '\0'; /* cut "/foo/" from "cat/foo/foo-x.y" */ if ((p = strchr(ebuild, '/')) == NULL) continue; *(p++) = '\0'; /* find head of the ebuild basename */ if ((p = strchr(p, '/')) == NULL) continue; /* find start of the pkg name */ snprintf(name, sizeof(name), "%s/%s", ebuild, (p+1)); /* restore the filepath */ *p = '/'; *(p + strlen(p)) = '.'; ebuild[strlen(ebuild)] = '/'; } } /* filter the files we grep when there are extra args */ if (include_atoms != NULL) if (!qgrep_name_match(name, (argc - optind - 1), include_atoms)) continue; if ((newfp = fopen(ebuild, "r")) != NULL) { int lineno = 0; char remaining_after_context = 0; count = 0; /* if there have been some matches already, then a separator will be needed */ need_separator = (!status) && (num_lines_before || num_lines_after); /* whatever is in the circular buffers list is no more a valid context */ qgrep_buf_list_invalidate(buf_list); /* reading a new line always happen in the next buffer of the list */ while ((buf_list = buf_list->next) && (fgets(buf_list->buf, sizeof(buf_list->buf), newfp)) != NULL) { lineno++; buf_list->valid = 1; /* cleanup EOL */ if ((p = strrchr(buf_list->buf, '\n')) != NULL) *p = 0; if ((p = strrchr(buf_list->buf, '\r')) != NULL) *p = 0; if (skip_comments) { /* reject comments line ("^[ \t]*#") */ p = buf_list->buf; while (*p == ' ' || *p == '\t') p++; if (*p == '#') goto print_after_context; } if (skip_pattern) { /* reject some other lines which match an optional pattern */ if (!do_regex) { if (strfunc(buf_list->buf, skip_pattern) != NULL) goto print_after_context; } else { if (regexec(&skip_preg, buf_list->buf, 0, NULL, 0) == 0) goto print_after_context; } } /* four ways to match a line (with/without inversion and regexp) */ if (!invert_match) { if (do_regex == 0) { if (strfunc(buf_list->buf, argv[optind]) == NULL) goto print_after_context; } else { if (regexec(&preg, buf_list->buf, 0, NULL, 0) != 0) goto print_after_context; } } else { if (do_regex == 0) { if (strfunc(buf_list->buf, argv[optind]) != NULL) goto print_after_context; } else { if (regexec(&preg, buf_list->buf, 0, NULL, 0) == 0) goto print_after_context; } } count++; status = 0; /* got a match, exit status should be 0 */ if (per_file_output) continue; /* matching files are listed out of this loop */ if ((need_separator > 0) && (num_lines_before || num_lines_after)) printf("--\n"); /* "need_separator" is not a flag, but a counter, so that * adjacent contextes are not separated */ need_separator = 0 - num_lines_before; if (!do_list) { /* print the leading context */ qgrep_print_before_context(buf_list, num_lines_before, label, ((verbose > 1) ? lineno : -1)); /* print matching line */ if (invert_match || *RED == '\0') qgrep_print_matching_line_nocolor(buf_list, label, ((verbose > 1) ? lineno : -1)); else if (do_regex) qgrep_print_matching_line_regcolor(buf_list, label, ((verbose > 1) ? lineno : -1), &preg); else qgrep_print_matching_line_strcolor(buf_list, label, ((verbose > 1) ? lineno : -1), strfunc, argv[optind]); } else { /* in verbose do_list mode, list the file once per match */ printf("%s", label); if (verbose > 1) printf(":%d", lineno); putchar('\n'); } /* init count down of trailing context lines */ remaining_after_context = num_lines_after; continue; print_after_context: /* print some trailing context lines when needed */ if (!remaining_after_context) { if (!status) /* we're getting closer to the need of a separator between * current match block and the next one */ ++need_separator; } else { qgrep_print_context_line(buf_list, label, ((verbose > 1) ? lineno : -1)); --remaining_after_context; } } fclose(newfp); if (!per_file_output) continue; /* matches were already displayed, line per line */ if (do_count && count) { if (label != NULL) /* -c without -v/-N/-H only outputs * the matches count of the file */ printf("%s:", label); printf("%d\n", count); } else if ((count && !invert_list) || (!count && invert_list)) printf("%s\n", label); /* do_list == 1, or we wouldn't be here */ } } if (do_eclass) closedir(eclass_dir); else if (!do_installed) fclose(fp); if (do_installed) break; } if (do_regex) regfree(&preg); if (do_regex && skip_pattern) regfree(&skip_preg); if (include_atoms != NULL) { for (i = 0; i < (argc - optind - 1); i++) if (include_atoms[i] != NULL) atom_implode(include_atoms[i]); free(include_atoms); } qgrep_buf_list_free(buf_list); return status; }
int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString manitou_tr_path = ":/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } int connected=0; if (cnx_string==NULL) { // get the connection parameters from a dialog box QString qcs; login_dialog dlg; QSettings settings("Manitou-Mail", "manitou-ui"); dlg.set_login(settings.value("login").toString()); dlg.set_dbname(settings.value("dbname").toString()); dlg.set_host(settings.value("host").toString()); dlg.set_params(settings.value("params").toString()); dlg.set_focus(); do { if (dlg.exec()==1) { qcs = dlg.connect_string(); } else { helper::close(); exit(0); // exit if connection dialog closed with 'Cancel' } QString errstr; if (!(connected=ConnectDb(qcs.toLocal8Bit(), &errstr))) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); } else { settings.setValue("login", dlg.login()); settings.setValue("dbname", dlg.dbnames()); // stringlist settings.setValue("host", dlg.host()); settings.setValue("params", dlg.params()); } } while (!connected); } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); exit(1); } } if (!explicit_config) { QByteArray qb = conf_name.toLatin1(); printf("Configuration used: %s\n", qb.constData()); fflush(stdout); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); msgs_filter filter; filter.m_sql_stmt="0"; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif /* Instantiate the user in the database if necessary. Ideally we should ask for a fullname if not already known, but there's no GUI support for that yet */ user::create_if_missing(QString::null); users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); DBG_PRINTF(1, "end"); return 0; }
int main(int argc, char **argv) { static char *sockname=NULL; register ssize_t nx; struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700}; uname(&me); //get the login name callerpwd=getpwuid(getuid()); if (argv[0][0] == '-') netusage(); //implies exit /* option parsing */ { int c; while (1) { int option_index = 0; static struct option long_options[] = { {"sock", 1, 0, 's'}, {"vdesock", 1, 0, 's'}, {"unix", 1, 0, 's'}, {"port", 1, 0, 'p'}, {"help",0,0,'h'}, {"mod",1,0,'m'}, {"group",1,0,'g'}, {0, 0, 0, 0} }; c = GETOPT_LONG (argc, argv, "hc:p:s:m:g:l", long_options, &option_index); if (c == -1) break; switch (c) { case 'c': if (strcmp(optarg,"vde_plug")==0) { #ifdef DO_SYSLOG write_syslog_entry("START"); atexit(write_syslog_close); #ifdef VDE_IP_LOG vde_ip_log=1; #endif #endif } else netusage(); //implies exit break; case 'p': open_args.port=atoi(optarg); if (open_args.port <= 0) usage(argv[0]); //implies exit break; case 'h': usage(argv[0]); //implies exit break; case 's': sockname=strdup(optarg); break; case 'm': sscanf(optarg,"%o",(unsigned int *)&(open_args.mode)); break; case 'g': open_args.group=strdup(optarg); break; case 'l': #ifdef VDE_IP_LOG write_syslog_entry("START"); atexit(write_syslog_close); vde_ip_log=1; break; #endif default: usage(argv[0]); //implies exit } } if (optind < argc && sockname==NULL) sockname=argv[optind]; } atexit(cleanup); setsighandlers(); conn=vde_open(sockname,"vde_plug:",&open_args); if (conn == NULL) { fprintf(stderr,"vde_open %s: %s\n",sockname?sockname:"DEF_SWITCH",strerror(errno)); exit(1); } vdestream=vdestream_open(conn,STDOUT_FILENO,vdeplug_recv,vdeplug_err); pollv[1].fd=vde_datafd(conn); pollv[2].fd=vde_ctlfd(conn); for(;;) { poll(pollv,3,-1); if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) & POLLHUP || pollv[2].revents & POLLIN) break; if (pollv[0].revents & POLLIN) { nx=read(STDIN_FILENO,bufin,sizeof(bufin)); /* if POLLIN but not data it means that the stream has been * closed at the other end */ /*fprintf(stderr,"%s: RECV %d %x %x \n",myname,nx,bufin[0],bufin[1]);*/ if (nx==0) break; vdestream_recv(vdestream, bufin, nx); } if (pollv[1].revents & POLLIN) { nx=vde_recv(conn,bufin,BUFSIZE-2,0); if (nx<0) perror("vde_plug: recvfrom "); else { vdestream_send(vdestream, bufin, nx); /*fprintf(stderr,"%s: SENT %d %x %x \n",myname,nx,bufin[0],bufin[1]);*/ } } } return(0); }
int q_main(int argc, char **argv) { int i, install; const char *p; APPLET func; if (argc == 0) return 1; argv0 = p = basename(argv[0]); if ((func = lookup_applet(p)) == NULL) return 1; if (strcmp("q", p) != 0) return (func)(argc, argv); if (argc == 1) q_usage(EXIT_FAILURE); install = 0; while ((i = GETOPT_LONG(Q, q, "+")) != -1) { switch (i) { COMMON_GETOPTS_CASES(q) case 'M': modpath = optarg; break; case 'i': install = 1; break; } } if (install) { char buf[_Q_PATH_MAX]; const char *prog, *dir; ssize_t rret; int fd, ret; if (!quiet) printf("Installing symlinks:\n"); #if defined(__MACH__) rret = proc_pidpath(getpid(), buf, sizeof(buf)); if (rret != -1) rret = strlen(buf); #elif defined(__sun) && defined(__SVR4) prog = getexecname(); rret = strlen(prog); if ((size_t)rret > sizeof(buf) - 1) { rret = -1; } else { snprintf(buf, sizeof(buf), "%s", prog); } #else rret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); #endif if (rret == -1) { warnfp("haha no symlink love for you"); return 1; } buf[rret] = '\0'; prog = basename(buf); dir = dirname(buf); fd = open(dir, O_RDONLY|O_CLOEXEC|O_PATH); if (fd < 0) { warnfp("open(%s) failed", dir); return 1; } ret = 0; for (i = 1; applets[i].desc; ++i) { int r = symlinkat(prog, fd, applets[i].name); if (!quiet) printf(" %s ...\t[%s]\n", applets[i].name, r ? strerror(errno) : "OK"); if (r && errno != EEXIST) ret = 1; } close(fd); return ret; } if (argc == optind) q_usage(EXIT_FAILURE); if ((func = lookup_applet(argv[optind])) == NULL) return 1; /* In case of "q --option ... appletname ...", remove appletname from the * applet's args. */ if (optind > 1) { argv[0] = argv[optind]; for (i = optind; i < argc; ++i) argv[i] = argv[i + 1]; } else ++argv; optind = 0; /* reset so the applets can call getopt */ return (func)(argc - 1, argv); }
int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString s = QApplication::applicationDirPath(); gl_help_path = s + "/help"; QString manitou_tr_path = s + "/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } /* Call createUuid() before creating any window as a workaround against QTBUG-11080 or QTBUG-11213 in Qt-4.6.2 on Linux. Otherwise, createUuid() may return a UUID that is always the same when creating a new Message-Id later on. The fix for this Qt bug has not been backported in Ubuntu-10.04 LTS at this time (2012-10-08). */ (void)QUuid::createUuid(); if (cnx_string==NULL) { login_dialog dlg; if (dlg.exec() == QDialog::Rejected) return 0; } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); return 1; } } if (!explicit_config) { printf("Configuration used: %s\n", conf_name.toLocal8Bit().constData()); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); if (!QFile::exists(gl_xpm_path+"/"+FT_ICON16_QUIT)) { gl_pApplication->display_warning(QObject::tr("Icon files not found at: %1").arg(gl_xpm_path)); } msgs_filter filter; QString sq = get_config().get_string("display/start_query"); filter.m_sql_stmt= sq.isEmpty() ? "0" : sq; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); tags_repository::fetch(); app.setup_desktop_tray_icon(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); return 0; }
int qgrep_main(int argc, char **argv) { int i; char *p; bool do_eclass; bool do_installed; DIR *eclass_dir = NULL; struct dirent *dentry = NULL; int reflags = 0; unsigned long int context_optarg; char status = 1; size_t n; char *overlay; struct qgrep_grepargs args = { .do_count = 0, .do_regex = 0, .do_list = 0, .show_filename = 0, .show_name = 0, .skip_comments = 0, .invert_list = 0, .invert_match = 0, .skip_pattern = NULL, .num_lines_before = 0, .num_lines_after = 0, .buf_list = NULL, .query = NULL, .strfunc = strstr, .include_atoms = NULL, .portdir = NULL, }; do_eclass = do_installed = 0; while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { switch (i) { case 'I': args.invert_match = true; break; case 'i': args.strfunc = strcasestr; reflags |= REG_ICASE; break; case 'c': args.do_count = true; break; case 'l': args.do_list = true; break; case 'L': args.do_list = args.invert_list = true; break; case 'e': args.do_regex = true; break; case 'x': args.do_regex = true; reflags |= REG_EXTENDED; break; case 'J': do_installed = true; break; case 'E': do_eclass = true; break; case 'H': args.show_filename = true; break; case 'N': args.show_name = true; break; case 's': args.skip_comments = true; break; case 'R': args.show_repo = args.show_name = true; break; case 'S': args.skip_pattern = optarg; break; case 'B': case 'A': errno = 0; context_optarg = strtol(optarg, &p, 10); if (errno != 0) errp("%s: not a valid integer", optarg); else if (p == optarg || *p != '\0') err("%s: not a valid integer", optarg); if (context_optarg > 254) err("%s: silly value!", optarg); if (i == 'B') args.num_lines_before = context_optarg; else args.num_lines_after = context_optarg; break; COMMON_GETOPTS_CASES(qgrep) } } if (argc == optind) qgrep_usage(EXIT_FAILURE); if (args.do_list && args.do_count) { warn("%s and --count are incompatible options. The former wins.", (args.invert_list ? "--invert-list" : "--list")); args.do_count = false; } if (args.show_name && args.show_filename) { warn("--with-name and --with-filename are incompatible options. " "The former wins."); args.show_filename = false; } if (args.do_list && args.num_lines_before) { warn("%s and --before are incompatible options. The former wins.", (args.invert_list ? "--invert-list" : "--list")); args.num_lines_before = 0; } if (args.do_list && args.num_lines_after) { warn("%s and --after are incompatible options. The former wins.", (args.invert_list ? "--invert-list" : "--list")); args.num_lines_after = 0; } if (args.do_count && args.num_lines_before) { warn("--count and --before are incompatible options. The former wins."); args.num_lines_before = 0; } if (args.do_count && args.num_lines_after) { warn("--count and --after are incompatible options. The former wins."); args.num_lines_after = 0; } if (do_installed && do_eclass) { warn("--installed and --eclass are incompatible options. " "The former wins."); do_eclass = false; } if (argc > (optind + 1)) { depend_atom **d = args.include_atoms = xcalloc(sizeof(depend_atom *), (argc - optind - 1) + 1); for (i = (optind + 1); i < argc; i++) { *d = atom_explode(argv[i]); if (*d == NULL) { warn("%s: invalid atom, will be ignored", argv[i]); } else { d++; } } *d = NULL; } /* make it easier to see what needs to be printed */ if (!args.show_name && (verbose || args.do_list)) args.show_filename = true; /* pre-compile regexps once for all */ if (args.do_regex) { if (args.invert_match || *RED == '\0') reflags |= REG_NOSUB; xregcomp(&args.preg, argv[optind], reflags); reflags |= REG_NOSUB; if (args.skip_pattern) xregcomp(&args.skip_preg, args.skip_pattern, reflags); } args.query = argv[optind]; /* allocate a circular buffers list for --before */ args.buf_list = qgrep_buf_list_alloc(args.num_lines_before + 1); array_for_each(overlays, n, overlay) { args.portdir = overlay; if (do_eclass) { char buf[_Q_PATH_MAX]; char name[_Q_PATH_MAX]; char *label; int efd; snprintf(buf, sizeof(buf), "%s/%s/eclass", portroot, overlay); efd = open(buf, O_RDONLY|O_CLOEXEC); if (efd == -1 || (eclass_dir = fdopendir(efd)) == NULL) { if (errno != ENOENT) warnp("opendir(\"%s/eclass\") failed", overlay); continue; } while ((dentry = readdir(eclass_dir)) != NULL) { if (strstr(dentry->d_name, ".eclass") == NULL) continue; /* filter the files we grep when there are extra args */ if (args.include_atoms != NULL) { depend_atom **d; for (d = args.include_atoms; *d != NULL; d++) { if ((*d)->PN != NULL && strncmp(dentry->d_name, (*d)->PN, strlen((*d)->PN)) == 0) break; } if (*d == NULL) continue; } label = NULL; if (args.show_name) { snprintf(name, sizeof(name), "%s%.*s%s", BLUE, (int)(strlen(dentry->d_name) - 7), dentry->d_name, NORM); label = name; } else if (args.show_filename) { snprintf(name, sizeof(name), "eclass/%s", dentry->d_name); label = name; } status = qgrep_grepat(efd, dentry->d_name, label, &args); } closedir(eclass_dir); } else if (do_installed) { status = q_vdb_foreach_pkg(portroot, portvdb, qgrep_vdb_cb, &args, NULL); } else { /* do_ebuild */ status = cache_foreach_pkg(portroot, overlay, qgrep_cache_cb, &args, NULL); } } if (args.do_regex) regfree(&args.preg); if (args.do_regex && args.skip_pattern) regfree(&args.skip_preg); if (args.include_atoms != NULL) { for (i = 0; i < (argc - optind - 1); i++) if (args.include_atoms[i] != NULL) atom_implode(args.include_atoms[i]); free(args.include_atoms); } qgrep_buf_list_free(args.buf_list); return status; }