int main(int argc, char **argv) { int ch; char **pkgs, **start, *tmp; warnpkgng(); pkgs = start = argv; while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) switch(ch) { case 'v': Verbose++; break; case 'x': MatchType = MATCH_REGEX; break; case 'E': MatchType = MATCH_EREGEX; break; case 'G': MatchType = MATCH_EXACT; break; case 'N': AutoAnswer = NO; break; case 'Y': AutoAnswer = YES; break; case 'O': PlistOnly = TRUE; break; case 'p': Prefix = optarg; break; case 's': SrcDir = optarg; break; case 'S': BaseDir = optarg; break; case 'f': Contents = optarg; break; case 'C': Conflicts = optarg; break; case 'c': Comment = optarg; break; case 'd': Desc = optarg; break; case 'i': Install = optarg; break; case 'I': PostInstall = optarg; break; case 'k': DeInstall = optarg; break; case 'K': PostDeInstall = optarg; break; case 'r': Require = optarg; break; case 't': strlcpy(PlayPen, optarg, sizeof(PlayPen)); break; case 'X': ExcludeFrom = optarg; break; case 'h': Dereference = TRUE; break; case 'D': Display = optarg; break; case 'm': Mtree = optarg; break; case 'P': Pkgdeps = optarg; break; case 'o': Origin = optarg; break; case 'y': case 'j': Zipper = BZIP2; break; case 'z': Zipper = GZIP; break; case 'J': Zipper = XZ; break; case 'b': InstalledPkg = optarg; while ((tmp = strrchr(optarg, (int)'/')) != NULL) { *tmp++ = '\0'; /* * If character after the '/' is alphanumeric, then we've * found the package name. Otherwise we've come across * a trailing '/' and need to continue our quest. */ if (isalpha(*tmp)) { InstalledPkg = tmp; break; } } break; case 'R': Recursive = TRUE; break; case 'n': Regenerate = FALSE; break; case 0: if (Help) usage(); break; default: usage(); break; } argc -= optind; argv += optind; /* Get all the remaining package names, if any */ while (*argv) *pkgs++ = *argv++; /* If no packages, yelp */ if ((pkgs == start) && (InstalledPkg == NULL)) warnx("missing package name"), usage(); *pkgs = NULL; if ((start[0] != NULL) && (start[1] != NULL)) { warnx("only one package name allowed ('%s' extraneous)", start[1]); usage(); } if (start[0] == NULL) start[0] = InstalledPkg; if (!pkg_perform(start)) { if (Verbose) warnx("package creation failed"); return 1; } else return 0; }
int main(int argc, char **argv) { int ch; char **pkgs, **start; char *pkgs_split; warnpkgng(); whead = malloc(sizeof(struct which_head)); if (whead == NULL) err(2, NULL); TAILQ_INIT(whead); pkgs = start = argv; if (argc == 1) { MatchType = MATCH_ALL; Flags = SHOW_INDEX; } else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch(ch) { case 'a': MatchType = MATCH_ALL; break; case 'b': UseBlkSz = TRUE; break; case 'v': Verbose++; /* Reasonable definition of 'everything' */ Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE; break; case 'E': Flags |= SHOW_PKGNAME; break; case 'I': Flags |= SHOW_INDEX; break; case 'p': Flags |= SHOW_PREFIX; break; case 'c': Flags |= SHOW_COMMENT; break; case 'd': Flags |= SHOW_DESC; break; case 'D': Flags |= SHOW_DISPLAY; break; case 'f': Flags |= SHOW_PLIST; break; case 'g': Flags |= SHOW_CKSUM; break; case 'G': MatchType = MATCH_EXACT; break; case 'i': Flags |= SHOW_INSTALL; break; case 'j': Flags |= SHOW_REQUIRE; break; case 'k': Flags |= SHOW_DEINSTALL; break; case 'K': KeepPackage = TRUE; break; case 'r': Flags |= SHOW_DEPEND; break; case 'R': Flags |= SHOW_REQBY; break; case 'L': Flags |= SHOW_FILES; break; case 'm': Flags |= SHOW_MTREE; break; case 's': Flags |= SHOW_SIZE; break; case 'o': Flags |= SHOW_ORIGIN; break; case 'O': LookUpOrigin = strdup(optarg); if (LookUpOrigin == NULL) err(2, NULL); break; case 'V': Flags |= SHOW_FMTREV; break; case 'l': InfoPrefix = optarg; break; case 'q': Quiet = TRUE; break; case 'Q': Quiet = TRUE; QUIET = TRUE; break; case 't': strlcpy(PlayPen, optarg, sizeof(PlayPen)); break; case 'x': MatchType = MATCH_REGEX; break; case 'X': MatchType = MATCH_EREGEX; break; case 'e': CheckPkg = optarg; break; case 'W': { struct which_entry *entp; entp = calloc(1, sizeof(struct which_entry)); if (entp == NULL) err(2, NULL); strlcpy(entp->file, optarg, PATH_MAX); entp->skip = FALSE; TAILQ_INSERT_TAIL(whead, entp, next); break; } case 'P': Flags = SHOW_PTREV; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; if (Flags & SHOW_PTREV) { if (!Quiet) printf("Package tools revision: "); printf("%d\n", PKG_INSTALL_VERSION); exit(0); } /* Set some reasonable defaults */ if (!Flags) Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; /* Get all the remaining package names, if any */ while (*argv) { /* * Don't try to apply heuristics if arguments are regexs or if * the argument refers to an existing file. */ if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv) && !isURL(*argv)) while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { *pkgs_split++ = '\0'; /* * If character after the '/' is alphanumeric or shell * metachar, then we've found the package name. Otherwise * we've come across a trailing '/' and need to continue our * quest. */ if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ strpbrk(pkgs_split, "*?[]") != NULL)) { *argv = pkgs_split; break; } } *pkgs++ = *argv++; } /* If no packages, yelp */ if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg && TAILQ_EMPTY(whead) && LookUpOrigin == NULL) warnx("missing package name(s)"), usage(); *pkgs = NULL; return pkg_perform(start); }
/* * Parse /usr/port/UPDATING for corresponding entries. If no argument is * passed to pkg_updating all entries for all installed ports are displayed. * If a list of portnames is passed to pkg_updating only entries for the * given portnames are displayed. Use the -d option to define that only newer * entries as this date are shown. */ int main(int argc, char *argv[]) { /* Keyword for searching portname in UPDATING. */ const char *affects = "AFFECTS"; /* Indicate a date -> end of a entry. Will fail on 2100-01-01... */ const char *end = "20"; /* Keyword for searching origin portname of installed port. */ const char *origin = "@comment ORIGIN:"; const char *pkgdbpath = LOG_DIR; /* Location of pkgdb */ const char *updatingfile = UPDATING; /* Location of UPDATING */ char *date = NULL; /* Passed -d argument */ char *dateline = NULL; /* Saved date of an entry */ /* Tmp lines for parsing file */ char *tmpline1 = NULL; char *tmpline2 = NULL; char originline[LINE_MAX]; /* Line of +CONTENTS */ /* Temporary variable to create path to +CONTENTS for installed ports. */ char tmp_file[MAXPATHLEN]; char updatingline[LINE_MAX]; /* Line of UPDATING */ int ch; /* Char used by getopt */ int found = 0; /* Found an entry */ int linelength; /* Length of parsed line */ int maxcharperline = LINE_MAX; /* Max chars per line */ int dflag = 0; /* -d option set */ /* If pflag = 0 UPDATING will be checked for all installed ports. */ int pflag = 0; size_t n; /* Offset to create path */ struct dirent *pkgdbdir; /* pkgdb directory */ struct stat attribute; /* attribute of pkgdb element */ /* Needed nodes for linked list with installed ports. */ INSTALLEDPORT *head = (INSTALLEDPORT *) NULL; INSTALLEDPORT *curr = (INSTALLEDPORT *) NULL; DIR *dir; FILE *fd; warnpkgng(); while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch (ch) { case 'd': dflag = 1; date = optarg; break; case 'f': updatingfile = optarg; break; case 'h': default: usage(); } } argc -= optind; argv += optind; /* Check if passed date has a correct format. */ if (dflag == 1) { linelength = strlen(date); if (linelength != 8) exit(EX_DATAERR); if (strspn(date, "0123456789") != 8) { fprintf(stderr, "unknown date format: %s\n", date); exit(EX_DATAERR); } } /* Save the list of passed portnames. */ if (argc != 0) { pflag = 1; while (*argv) { if ((curr = (INSTALLEDPORT *) malloc(sizeof(INSTALLEDPORT))) == NULL) (void)exit(EXIT_FAILURE); strlcpy(curr->name, *argv, strlen(*argv) + 1); curr->next = head; head = curr; (void)*argv++; } } /* * UPDATING will be parsed for all installed ports * if no portname is passed. */ if (pflag == 0) { /* Open /var/db/pkg and search for all installed ports. */ if ((dir = opendir(pkgdbpath)) != NULL) { while ((pkgdbdir = readdir(dir)) != NULL) { if (strcmp(pkgdbdir->d_name, ".") != 0 && strcmp(pkgdbdir->d_name, "..") != 0) { /* Create path to +CONTENTS file for each installed port */ n = strlcpy(tmp_file, pkgdbpath, sizeof(tmp_file)); n = strlcpy(tmp_file + n, "/", sizeof(tmp_file) - n); n = strlcat(tmp_file + n, pkgdbdir->d_name, sizeof(tmp_file) - n); if (stat(tmp_file, &attribute) == -1) { fprintf(stderr, "can't open %s: %s\n", tmp_file, strerror(errno)); return EXIT_FAILURE; } if (attribute.st_mode & S_IFREG) continue; (void)strlcat(tmp_file + n, "/", sizeof(tmp_file) - n); (void)strlcat(tmp_file + n, CONTENTS_FNAME, sizeof(tmp_file) - n); /* Open +CONTENT file */ fd = fopen(tmp_file, "r"); if (fd == NULL) { fprintf(stderr, "warning: can't open %s: %s\n", tmp_file, strerror(errno)); continue; } /* * Parses +CONTENT for ORIGIN line and * put element into linked list. */ while (fgets(originline, maxcharperline, fd) != NULL) { tmpline1 = strstr(originline, origin); if (tmpline1 != NULL) { /* Tmp variable to store port name. */ char *pname; pname = strrchr(originline, (int)':'); pname++; if ((curr = (INSTALLEDPORT *) malloc(sizeof(INSTALLEDPORT))) == NULL) (void)exit(EXIT_FAILURE); if (pname[strlen(pname) - 1] == '\n') pname[strlen(pname) - 1] = '\0'; strlcpy (curr->name, pname, sizeof(curr->name)); curr->next = head; head = curr; } } if (ferror(fd)) { fprintf(stderr, "error reading input\n"); exit(EX_IOERR); } (void)fclose(fd); } } closedir(dir); } } /* Fetch UPDATING file if needed and open file */ if (isURL(updatingfile)) { if ((fd = fetchGetURL(updatingfile, "")) == NULL) { fprintf(stderr, "Error: Unable to get %s: %s\n", updatingfile, fetchLastErrString); exit(EX_UNAVAILABLE); } } else { fd = fopen(updatingfile, "r"); } if (fd == NULL) { fprintf(stderr, "can't open %s: %s\n", updatingfile, strerror(errno)); exit(EX_UNAVAILABLE); } /* Parse opened UPDATING file. */ while (fgets(updatingline, maxcharperline, fd) != NULL) { /* No entry is found so far */ if (found == 0) { /* Search for AFFECTS line to parse the portname. */ tmpline1 = strstr(updatingline, affects); if (tmpline1 != NULL) { curr = head; while (curr != NULL) { tmpline2 = strstr(updatingline, curr->name); if (tmpline2 != NULL) break; curr = curr->next; } if (tmpline2 != NULL) { /* If -d is set, check if entry is newer than the date. */ if ((dflag == 1) && (strncmp(dateline, date, 8) < 0)) continue; printf("%s", dateline); printf("%s", updatingline); found = 1; } } } /* Search for the end of an entry, if not found print the line. */ else { tmpline1 = strstr(updatingline, end); if (tmpline1 == NULL) printf("%s", updatingline); else { linelength = strlen(updatingline); if (linelength == 10) found = 0; else printf("%s", updatingline); } } /* Save the actual line, it could be a date. */ dateline = strdup(updatingline); } if (ferror(fd)) { fprintf(stderr, "error reading input\n"); exit(EX_IOERR); } (void)fclose(fd); exit(EX_OK); }