summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2011-10-20 14:09:48 -0400
committerDave Reisner <dreisner@archlinux.org>2011-10-20 14:10:22 -0400
commit7ec0a2ff1e1df2d80415a1ffbb42dbac27c11c79 (patch)
treea3cd81ea79154503a59579f597acd46e81e46973
parent7427696c2f0fd15b41df9864ca32b708ff4586d3 (diff)
downloadexpac-7ec0a2ff1e1df2d80415a1ffbb42dbac27c11c79.tar.xz
add -p option to alpm_pkg_load arguments
-rw-r--r--README.pod5
-rw-r--r--expac.c42
2 files changed, 39 insertions, 8 deletions
diff --git a/README.pod b/README.pod
index 5d74b4e..3924b40 100644
--- a/README.pod
+++ b/README.pod
@@ -52,6 +52,11 @@ newline character.
Separate each list item with the specified I<string>. Lists are any interpreted
sequence specified with a capital letter. The default value is two spaces.
+=item B<-p, --file>
+
+Interpret targets as paths to local files. This option only makes sense with the
+-Q option.
+
=item B<-t, --timefmt> <format>
Output time described by the specified I<format>. This string is passed directly
diff --git a/expac.c b/expac.c
index 7ee6274..0f944c6 100644
--- a/expac.c
+++ b/expac.c
@@ -58,6 +58,7 @@ bool verbose = false;
bool search = false;
bool local = false;
bool groups = false;
+bool localpkg = false;
const char *format = NULL;
const char *timefmt = NULL;
const char *listdelim = NULL;
@@ -172,6 +173,7 @@ static void usage(void) {
" -1, --readone return only the first result of a sync search\n\n"
" -d, --delim <string> separator used between packages (default: \"\\n\")\n"
" -l, --listdelim <string> separator used between list elements (default: \" \")\n"
+ " -p, --file query local files instead of the DB\n"
" -t, --timefmt <fmt> date format passed to strftime (default: \"%%c\")\n\n"
" -v, --verbose be more verbose\n\n"
" -h, --help display this help and exit\n\n");
@@ -186,6 +188,7 @@ static int parse_options(int argc, char *argv[], alpm_handle_t *handle) {
{"listdelim", required_argument, 0, 'l'},
{"group", required_argument, 0, 'g'},
{"help", no_argument, 0, 'h'},
+ {"file", no_argument, 0, 'p'},
{"local", no_argument, 0, 'Q'},
{"sync", no_argument, 0, 'S'},
{"search", no_argument, 0, 's'},
@@ -194,7 +197,7 @@ static int parse_options(int argc, char *argv[], alpm_handle_t *handle) {
{0, 0, 0, 0}
};
- while (-1 != (opt = getopt_long(argc, argv, "1l:d:ghf:QSst:v", opts, &option_index))) {
+ while (-1 != (opt = getopt_long(argc, argv, "1l:d:ghf:pQSst:v", opts, &option_index))) {
switch (opt) {
case 'S':
if (dblist) {
@@ -226,6 +229,9 @@ static int parse_options(int argc, char *argv[], alpm_handle_t *handle) {
case 'h':
usage();
return 1;
+ case 'p':
+ localpkg = true;
+ break;
case 's':
search = true;
break;
@@ -578,7 +584,7 @@ static alpm_list_t *resolve_pkg(alpm_list_t *targets) {
int main(int argc, char *argv[]) {
int ret = 1;
alpm_handle_t *handle;
- alpm_list_t *results, *i;
+ alpm_list_t *results = NULL, *i;
handle = alpm_init();
if (!handle) {
@@ -592,17 +598,37 @@ int main(int argc, char *argv[]) {
/* ensure sane defaults */
if (!dblist) {
- local = true;
- dblist = alpm_list_add(dblist, db_local);
+ if (localpkg) {
+ /* load each target as a package */
+ for (i = targets; i; i = alpm_list_next(i)) {
+ alpm_pkg_t *pkg;
+ int err;
+
+ err = alpm_pkg_load(handle, i->data, 0,
+ ALPM_SIG_PACKAGE|ALPM_SIG_PACKAGE_OPTIONAL, &pkg);
+ if (err) {
+ fprintf(stderr, "error: %s: %s\n", (const char*)i->data,
+ alpm_strerror(alpm_errno(handle)));
+ continue;
+ }
+ results = alpm_list_add(results, pkg);
+ }
+ } else {
+ local = true;
+ dblist = alpm_list_add(dblist, db_local);
+ }
}
+
delim = delim ? delim : DEFAULT_DELIM;
listdelim = listdelim ? listdelim : DEFAULT_LISTDELIM;
timefmt = timefmt ? timefmt : DEFAULT_TIMEFMT;
- results = resolve_pkg(targets);
- if (!results) {
- ret = 1;
- goto finish;
+ if (!localpkg) {
+ results = resolve_pkg(targets);
+ if (!results) {
+ ret = 1;
+ goto finish;
+ }
}
for (i = results; i; i = alpm_list_next(i)) {