Example #1
0
int
show_direct_depends(const char *pkgarg)
{
	char		*pkgname, query[BUFSIZ];
	Pkglist		*pdp, *mapplist;
	Plisthead	*deptreehead;

	if (SLIST_EMPTY(&r_plisthead)) {
		printf("%s\n", MSG_EMPTY_AVAIL_PKGLIST);
		return EXIT_FAILURE;
	}

	if ((pkgname = unique_pkg(pkgarg, REMOTE_PKG)) == NULL) {
		fprintf(stderr, MSG_PKG_NOT_AVAIL, pkgarg);
		return EXIT_FAILURE;
	}

	deptreehead = init_head();

	snprintf(query, BUFSIZ, EXACT_DIRECT_DEPS, pkgname);

	if (pkgindb_doquery(query, pdb_rec_depends, deptreehead) == PDB_OK) {
		printf(MSG_DIRECT_DEPS_FOR, pkgname);
		SLIST_FOREACH(pdp, deptreehead, next) {
			if (package_version && 
				(mapplist = map_pkg_to_dep(&r_plisthead,
							   pdp->depend))
				!= NULL)
				printf("\t%s\n", mapplist->full);
			else
				printf("\t%s\n", pdp->depend);
		}
		free_pkglist(&deptreehead, DEPTREE);
	}
Example #2
0
void
import_keep(uint8_t do_inst, const char *import_file)
{
	int		list_size = 0;
	char	**pkglist = NULL, *match;
	char	input[BUFSIZ], fullpkgname[BUFSIZ], query[BUFSIZ];
	FILE	*fp;

	if ((fp = fopen(import_file, "r")) == NULL)
		err(EXIT_FAILURE, MSG_ERR_OPEN, import_file);

	while (fgets(input, BUFSIZ, fp) != NULL) {
		if (!isalnum((int)input[0]))
			continue;

		trimcr(input);
		if (strchr(input, '/') != NULL) {
			snprintf(query, BUFSIZ, GET_PKGNAME_BY_PKGPATH, input);

			if ((pkgindb_doquery(query,
					pdb_get_value, fullpkgname)) == PDB_OK)
				XSTRDUP(match, fullpkgname);
			else
				match = NULL;
		} else
			match = unique_pkg(input, REMOTE_PKG);

		if (match == NULL) {
			fprintf(stderr, MSG_PKG_NOT_AVAIL, input);
			continue;
		}
		/* 1st element + NULL */
		XREALLOC(pkglist, (list_size + 2) * sizeof(char *));
		pkglist[list_size] = match;
		pkglist[++list_size] = NULL;
	}
	fclose(fp);

	if (pkglist == NULL)
		errx(EXIT_FAILURE, MSG_EMPTY_IMPORT_LIST);

	pkgin_install(pkglist, do_inst);

	free_list(pkglist);
}