summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c643
1 files changed, 343 insertions, 300 deletions
diff --git a/main.c b/main.c
index 385e43d..b61ca34 100644
--- a/main.c
+++ b/main.c
@@ -35,12 +35,32 @@
#undef STRICT
#endif
-static int want_debug_spew = 0;
-static int want_verbose_errors = 0;
-static int want_stdout_errors = 0;
char *pcsysrootdir = NULL;
char *pkg_config_pc_path = NULL;
+static gboolean want_my_version = FALSE;
+static gboolean want_version = FALSE;
+static FlagType pkg_flags = 0;
+static gboolean want_list = FALSE;
+static gboolean want_static_lib_list = ENABLE_INDIRECT_DEPS;
+static gboolean want_short_errors = FALSE;
+static gboolean want_uninstalled = FALSE;
+static char *variable_name = NULL;
+static gboolean want_exists = FALSE;
+static gboolean want_provides = FALSE;
+static gboolean want_requires = FALSE;
+static gboolean want_requires_private = FALSE;
+static char *required_atleast_version = NULL;
+static char *required_exact_version = NULL;
+static char *required_max_version = NULL;
+static char *required_pkgconfig_version = NULL;
+static gboolean want_silence_errors = FALSE;
+static gboolean want_variable_list = FALSE;
+static gboolean want_debug_spew = FALSE;
+static gboolean want_verbose_errors = FALSE;
+static gboolean want_stdout_errors = FALSE;
+static gboolean output_opt_set = FALSE;
+
void
debug_spew (const char *format, ...)
{
@@ -133,10 +153,111 @@ define_variable_cb (const char *opt, const char *arg, gpointer data,
}
static gboolean
+output_opt_cb (const char *opt, const char *arg, gpointer data,
+ GError **error)
+{
+ static gboolean vercmp_opt_set = FALSE;
+
+ /* only allow one output mode, with a few exceptions */
+ if (output_opt_set)
+ {
+ gboolean bad_opt = TRUE;
+
+ /* multiple flag options (--cflags --libs-only-l) allowed */
+ if (pkg_flags != 0 &&
+ (strcmp (opt, "--libs") == 0 ||
+ strcmp (opt, "--libs-only-l") == 0 ||
+ strcmp (opt, "--libs-only-other") == 0 ||
+ strcmp (opt, "--libs-only-L") == 0 ||
+ strcmp (opt, "--cflags") == 0 ||
+ strcmp (opt, "--cflags-only-I") == 0 ||
+ strcmp (opt, "--cflags-only-other") == 0))
+ bad_opt = FALSE;
+
+ /* --print-requires and --print-requires-private allowed */
+ if ((want_requires && strcmp (opt, "--print-requires-private") == 0) ||
+ (want_requires_private && strcmp (opt, "--print-requires") == 0))
+ bad_opt = FALSE;
+
+ /* --exists allowed with --atleast/exact/max-version */
+ if (want_exists && !vercmp_opt_set &&
+ (strcmp (opt, "--atleast-version") == 0 ||
+ strcmp (opt, "--exact-version") == 0 ||
+ strcmp (opt, "--max-version") == 0))
+ bad_opt = FALSE;
+
+ if (bad_opt)
+ {
+ fprintf (stderr, "Ignoring incompatible output option \"%s\"\n",
+ opt);
+ return TRUE;
+ }
+ }
+
+ if (strcmp (opt, "--version") == 0)
+ want_my_version = TRUE;
+ else if (strcmp (opt, "--modversion") == 0)
+ want_version = TRUE;
+ else if (strcmp (opt, "--libs") == 0)
+ pkg_flags |= LIBS_ANY;
+ else if (strcmp (opt, "--libs-only-l") == 0)
+ pkg_flags |= LIBS_l;
+ else if (strcmp (opt, "--libs-only-other") == 0)
+ pkg_flags |= LIBS_OTHER;
+ else if (strcmp (opt, "--libs-only-L") == 0)
+ pkg_flags |= LIBS_L;
+ else if (strcmp (opt, "--cflags") == 0)
+ pkg_flags |= CFLAGS_ANY;
+ else if (strcmp (opt, "--cflags-only-I") == 0)
+ pkg_flags |= CFLAGS_I;
+ else if (strcmp (opt, "--cflags-only-other") == 0)
+ pkg_flags |= CFLAGS_OTHER;
+ else if (strcmp (opt, "--variable") == 0)
+ variable_name = g_strdup (arg);
+ else if (strcmp (opt, "--exists") == 0)
+ want_exists = TRUE;
+ else if (strcmp (opt, "--print-variables") == 0)
+ want_variable_list = TRUE;
+ else if (strcmp (opt, "--uninstalled") == 0)
+ want_uninstalled = TRUE;
+ else if (strcmp (opt, "--atleast-version") == 0)
+ {
+ required_atleast_version = g_strdup (arg);
+ want_exists = TRUE;
+ vercmp_opt_set = TRUE;
+ }
+ else if (strcmp (opt, "--exact-version") == 0)
+ {
+ required_exact_version = g_strdup (arg);
+ want_exists = TRUE;
+ vercmp_opt_set = TRUE;
+ }
+ else if (strcmp (opt, "--max-version") == 0)
+ {
+ required_max_version = g_strdup (arg);
+ want_exists = TRUE;
+ vercmp_opt_set = TRUE;
+ }
+ else if (strcmp (opt, "--list-all") == 0)
+ want_list = TRUE;
+ else if (strcmp (opt, "--print-provides") == 0)
+ want_provides = TRUE;
+ else if (strcmp (opt, "--print-requires") == 0)
+ want_requires = TRUE;
+ else if (strcmp (opt, "--print-requires-private") == 0)
+ want_requires_private = TRUE;
+ else
+ return FALSE;
+
+ output_opt_set = TRUE;
+ return TRUE;
+}
+
+static gboolean
pkg_uninstalled (Package *pkg)
{
/* See if > 0 pkgs were uninstalled */
- GSList *tmp;
+ GList *tmp;
if (pkg->uninstalled)
return TRUE;
@@ -149,7 +270,7 @@ pkg_uninstalled (Package *pkg)
if (pkg_uninstalled (pkg))
return TRUE;
- tmp = g_slist_next (tmp);
+ tmp = g_list_next (tmp);
}
return FALSE;
@@ -191,35 +312,171 @@ init_pc_path (void)
#endif
}
+static gboolean
+process_package_args (const char *cmdline, GList **packages, FILE *log)
+{
+ gboolean success = TRUE;
+ GList *reqs;
+
+ reqs = parse_module_list (NULL, cmdline, "(command line arguments)");
+ if (reqs == NULL)
+ {
+ fprintf (stderr, "Must specify package names on the command line\n");
+ return FALSE;
+ }
+
+ for (; reqs != NULL; reqs = g_list_next (reqs))
+ {
+ Package *req;
+ RequiredVersion *ver = reqs->data;
+
+ /* override requested versions with cmdline options */
+ if (required_exact_version)
+ {
+ g_free (ver->version);
+ ver->comparison = EQUAL;
+ ver->version = g_strdup (required_exact_version);
+ }
+ else if (required_atleast_version)
+ {
+ g_free (ver->version);
+ ver->comparison = GREATER_THAN_EQUAL;
+ ver->version = g_strdup (required_atleast_version);
+ }
+ else if (required_max_version)
+ {
+ g_free (ver->version);
+ ver->comparison = LESS_THAN_EQUAL;
+ ver->version = g_strdup (required_max_version);
+ }
+
+ if (want_short_errors)
+ req = get_package_quiet (ver->name);
+ else
+ req = get_package (ver->name);
+
+ if (log != NULL)
+ {
+ if (req == NULL)
+ fprintf (log, "%s NOT-FOUND\n", ver->name);
+ else
+ fprintf (log, "%s %s %s\n", ver->name,
+ comparison_to_str (ver->comparison),
+ (ver->version == NULL) ? "(null)" : ver->version);
+ }
+
+ if (req == NULL)
+ {
+ success = FALSE;
+ verbose_error ("No package '%s' found\n", ver->name);
+ continue;
+ }
+
+ if (!version_test (ver->comparison, req->version, ver->version))
+ {
+ success = FALSE;
+ verbose_error ("Requested '%s %s %s' but version of %s is %s\n",
+ ver->name,
+ comparison_to_str (ver->comparison),
+ ver->version,
+ req->name,
+ req->version);
+ if (req->url)
+ verbose_error ("You may find new versions of %s at %s\n",
+ req->name, req->url);
+ continue;
+ }
+
+ *packages = g_list_prepend (*packages, req);
+ }
+
+ *packages = g_list_reverse (*packages);
+
+ return success;
+}
+
+static const GOptionEntry options_table[] = {
+ { "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output version of pkg-config", NULL },
+ { "modversion", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output version for package", NULL },
+ { "atleast-pkgconfig-version", 0, 0, G_OPTION_ARG_STRING,
+ &required_pkgconfig_version,
+ "require given version of pkg-config", "VERSION" },
+ { "libs", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "output all linker flags", NULL },
+ { "static", 0, 0, G_OPTION_ARG_NONE, &want_static_lib_list,
+ "output linker flags for static linking", NULL },
+ { "short-errors", 0, 0, G_OPTION_ARG_NONE, &want_short_errors,
+ "print short errors", NULL },
+ { "libs-only-l", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output -l flags", NULL },
+ { "libs-only-other", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output other libs (e.g. -pthread)", NULL },
+ { "libs-only-L", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output -L flags", NULL },
+ { "cflags", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "output all pre-processor and compiler flags", NULL },
+ { "cflags-only-I", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output -I flags", NULL },
+ { "cflags-only-other", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output cflags not covered by the cflags-only-I option",
+ NULL },
+ { "variable", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "get the value of variable named NAME", "NAME" },
+ { "define-variable", 0, 0, G_OPTION_ARG_CALLBACK, &define_variable_cb,
+ "set variable NAME to VALUE", "NAME=VALUE" },
+ { "exists", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "return 0 if the module(s) exist", NULL },
+ { "print-variables", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "output list of variables defined by the module", NULL },
+ { "uninstalled", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "return 0 if the uninstalled version of one or more "
+ "module(s) or their dependencies will be used", NULL },
+ { "atleast-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "return 0 if the module is at least version VERSION", "VERSION" },
+ { "exact-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "return 0 if the module is at exactly version VERSION", "VERSION" },
+ { "max-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
+ "return 0 if the module is at no newer than version VERSION", "VERSION" },
+ { "list-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "list all known packages", NULL },
+ { "debug", 0, 0, G_OPTION_ARG_NONE, &want_debug_spew,
+ "show verbose debug information", NULL },
+ { "print-errors", 0, 0, G_OPTION_ARG_NONE, &want_verbose_errors,
+ "show verbose information about missing or conflicting packages "
+ "(default unless --exists or --atleast/exact/max-version given on the "
+ "command line)", NULL },
+ { "silence-errors", 0, 0, G_OPTION_ARG_NONE, &want_silence_errors,
+ "be silent about errors (default when --exists or "
+ "--atleast/exact/max-version given on the command line)", NULL },
+ { "errors-to-stdout", 0, 0, G_OPTION_ARG_NONE, &want_stdout_errors,
+ "print errors from --print-errors to stdout not stderr", NULL },
+ { "print-provides", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "print which packages the package provides", NULL },
+ { "print-requires", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "print which packages the package requires", NULL },
+ { "print-requires-private", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ &output_opt_cb, "print which packages the package requires for static "
+ "linking", NULL },
+#ifdef G_OS_WIN32
+ { "dont-define-prefix", 0, 0, G_OPTION_ARG_NONE, &dont_define_prefix,
+ "don't try to override the value of prefix for each .pc file found with "
+ "a guesstimated value based on the location of the .pc file", NULL },
+ { "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable,
+ "set the name of the variable that pkg-config automatically sets",
+ "PREFIX" },
+ { "msvc-syntax", 0, 0, G_OPTION_ARG_NONE, &msvc_syntax,
+ "output -l and -L flags for the Microsoft compiler (cl)", NULL },
+#endif
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
int
main (int argc, char **argv)
{
- static int want_my_version = 0;
- static int want_version = 0;
- static int want_libs = 0;
- static int want_cflags = 0;
- static int want_l_libs = 0;
- static int want_L_libs = 0;
- static int want_other_libs = 0;
- static int want_I_cflags = 0;
- static int want_other_cflags = 0;
- static int want_list = 0;
- static int want_static_lib_list = ENABLE_INDIRECT_DEPS;
- static int want_short_errors = 0;
- static int want_uninstalled = 0;
- static char *variable_name = NULL;
- static int want_exists = 0;
- static int want_provides = 0;
- static int want_requires = 0;
- static int want_requires_private = 0;
- static char *required_atleast_version = NULL;
- static char *required_exact_version = NULL;
- static char *required_max_version = NULL;
- static char *required_pkgconfig_version = NULL;
- static int want_silence_errors = 0;
- static int want_variable_list = 0;
GString *str;
- GSList *packages = NULL;
+ GList *packages = NULL;
char *search_path;
char *pcbuilddir;
gboolean need_newline;
@@ -227,80 +484,6 @@ main (int argc, char **argv)
GError *error = NULL;
GOptionContext *opt_context;
- GOptionEntry options_table[] = {
- { "version", 0, 0, G_OPTION_ARG_NONE, &want_my_version,
- "output version of pkg-config", NULL },
- { "modversion", 0, 0, G_OPTION_ARG_NONE, &want_version,
- "output version for package", NULL },
- { "atleast-pkgconfig-version", 0, 0, G_OPTION_ARG_STRING,
- &required_pkgconfig_version,
- "require given version of pkg-config", "VERSION" },
- { "libs", 0, 0, G_OPTION_ARG_NONE, &want_libs,
- "output all linker flags", NULL },
- { "static", 0, 0, G_OPTION_ARG_NONE, &want_static_lib_list,
- "output linker flags for static linking", NULL },
- { "short-errors", 0, 0, G_OPTION_ARG_NONE, &want_short_errors,
- "print short errors", NULL },
- { "libs-only-l", 0, 0, G_OPTION_ARG_NONE, &want_l_libs,
- "output -l flags", NULL },
- { "libs-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_libs,
- "output other libs (e.g. -pthread)", NULL },
- { "libs-only-L", 0, 0, G_OPTION_ARG_NONE, &want_L_libs,
- "output -L flags", NULL },
- { "cflags", 0, 0, G_OPTION_ARG_NONE, &want_cflags,
- "output all pre-processor and compiler flags", NULL },
- { "cflags-only-I", 0, 0, G_OPTION_ARG_NONE, &want_I_cflags,
- "output -I flags", NULL },
- { "cflags-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_cflags,
- "output cflags not covered by the cflags-only-I option", NULL },
- { "variable", 0, 0, G_OPTION_ARG_STRING, &variable_name,
- "get the value of variable named NAME", "NAME" },
- { "define-variable", 0, 0, G_OPTION_ARG_CALLBACK, &define_variable_cb,
- "set variable NAME to VALUE", "NAME=VALUE" },
- { "exists", 0, 0, G_OPTION_ARG_NONE, &want_exists,
- "return 0 if the module(s) exist", NULL },
- { "print-variables", 0, 0, G_OPTION_ARG_NONE, &want_variable_list,
- "output list of variables defined by the module", NULL },
- { "uninstalled", 0, 0, G_OPTION_ARG_NONE, &want_uninstalled,
- "return 0 if the uninstalled version of one or more module(s) "
- "or their dependencies will be used", NULL },
- { "atleast-version", 0, 0, G_OPTION_ARG_STRING, &required_atleast_version,
- "return 0 if the module is at least version VERSION", "VERSION" },
- { "exact-version", 0, 0, G_OPTION_ARG_STRING, &required_exact_version,
- "return 0 if the module is at exactly version VERSION", "VERSION" },
- { "max-version", 0, 0, G_OPTION_ARG_STRING, &required_max_version,
- "return 0 if the module is at no newer than version VERSION", "VERSION" },
- { "list-all", 0, 0, G_OPTION_ARG_NONE, &want_list,
- "list all known packages", NULL },
- { "debug", 0, 0, G_OPTION_ARG_NONE, &want_debug_spew,
- "show verbose debug information", NULL },
- { "print-errors", 0, 0, G_OPTION_ARG_NONE, &want_verbose_errors,
- "show verbose information about missing or conflicting packages,"
- "default if --cflags or --libs given on the command line", NULL },
- { "silence-errors", 0, 0, G_OPTION_ARG_NONE, &want_silence_errors,
- "be silent about errors (default unless --cflags or --libs"
- "given on the command line)", NULL },
- { "errors-to-stdout", 0, 0, G_OPTION_ARG_NONE, &want_stdout_errors,
- "print errors from --print-errors to stdout not stderr", NULL },
- { "print-provides", 0, 0, G_OPTION_ARG_NONE, &want_provides,
- "print which packages the package provides", NULL },
- { "print-requires", 0, 0, G_OPTION_ARG_NONE, &want_requires,
- "print which packages the package requires", NULL },
- { "print-requires-private", 0, 0, G_OPTION_ARG_NONE, &want_requires_private,
- "print which packages the package requires for static linking", NULL },
-#ifdef G_OS_WIN32
- { "dont-define-prefix", 0, 0, G_OPTION_ARG_NONE, &dont_define_prefix,
- "don't try to override the value of prefix for each .pc file found with "
- "a guesstimated value based on the location of the .pc file", NULL },
- { "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable,
- "set the name of the variable that pkg-config automatically sets",
- "PREFIX" },
- { "msvc-syntax", 0, 0, G_OPTION_ARG_NONE, &msvc_syntax,
- "output -l and -L flags for the Microsoft compiler (cl)", NULL },
-#endif
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
/* This is here so that we get debug spew from the start,
* during arg parsing
*/
@@ -374,28 +557,25 @@ main (int argc, char **argv)
return 1;
}
+ /* If no output option was set, then --exists is the default. */
+ if (!output_opt_set)
+ {
+ debug_spew ("no output option set, defaulting to --exists\n");
+ want_exists = TRUE;
+ }
/* Error printing is determined as follows:
- * - for --cflags, --libs, etc. it's on by default
- * and --silence-errors can turn it off
- * - for --exists, --max-version, etc. and no options
- * at all, it's off by default and --print-errors
- * will turn it on
+ * - for all output options besides --exists and --*-version,
+ * it's on by default and --silence-errors can turn it off
+ * - for --exists, --*-version, etc. and no options at all,
+ * it's off by default and --print-errors will turn it on
*/
-
- if (want_my_version ||
- want_version ||
- want_libs ||
- want_cflags ||
- want_l_libs ||
- want_L_libs ||
- want_other_libs ||
- want_I_cflags ||
- want_other_cflags ||
- want_list ||
- want_variable_list)
+ if (!want_exists)
{
- debug_spew ("Error printing enabled by default due to use of --version, --libs, --cflags, --libs-only-l, --libs-only-L, --libs-only-other, --cflags-only-I, --cflags-only-other or --list. Value of --silence-errors: %d\n", want_silence_errors);
+ debug_spew ("Error printing enabled by default due to use of output "
+ "options besides --exists or --atleast/exact/max-version. "
+ "Value of --silence-errors: %d\n",
+ want_silence_errors);
if (want_silence_errors && getenv ("PKG_CONFIG_DEBUG_SPEW") == NULL)
want_verbose_errors = FALSE;
@@ -404,7 +584,9 @@ main (int argc, char **argv)
}
else
{
- debug_spew ("Error printing disabled by default, value of --print-errors: %d\n",
+ debug_spew ("Error printing disabled by default due to use of output "
+ "options --exists, --atleast/exact/max-version or no "
+ "output option at all. Value of --print-errors: %d\n",
want_verbose_errors);
/* Leave want_verbose_errors unchanged, reflecting --print-errors */
@@ -423,16 +605,13 @@ main (int argc, char **argv)
/* honor Requires.private if any Cflags are requested or any static
* libs are requested */
- if (want_I_cflags || want_other_cflags || want_cflags ||
- want_requires_private || want_exists ||
- (want_static_lib_list && (want_libs || want_l_libs || want_L_libs)))
+ if (pkg_flags & CFLAGS_ANY || want_requires_private || want_exists ||
+ (want_static_lib_list && (pkg_flags & LIBS_ANY)))
enable_requires_private();
/* ignore Requires if no Cflags or Libs are requested */
- if (!want_I_cflags && !want_other_cflags && !want_cflags &&
- !want_libs && !want_l_libs && !want_L_libs && !want_requires &&
- !want_exists)
+ if (pkg_flags == 0 && !want_requires && !want_exists)
disable_requires();
if (want_my_version)
@@ -483,132 +662,39 @@ main (int argc, char **argv)
}
}
- {
- gboolean failed = FALSE;
- GSList *reqs;
- GSList *iter;
-
- reqs = parse_module_list (NULL, str->str,
- "(command line arguments)");
-
- iter = reqs;
-
- while (iter != NULL)
- {
- Package *req;
- RequiredVersion *ver = iter->data;
-
- /* override requested versions with cmdline options */
- if (required_exact_version)
- {
- g_free (ver->version);
- ver->comparison = EQUAL;
- ver->version = g_strdup (required_exact_version);
- }
- else if (required_atleast_version)
- {
- g_free (ver->version);
- ver->comparison = GREATER_THAN_EQUAL;
- ver->version = g_strdup (required_atleast_version);
- }
- else if (required_max_version)
- {
- g_free (ver->version);
- ver->comparison = LESS_THAN_EQUAL;
- ver->version = g_strdup (required_max_version);
- }
-
- if (want_short_errors)
- req = get_package_quiet (ver->name);
- else
- req = get_package (ver->name);
-
- if (log != NULL)
- {
- if (req == NULL)
- fprintf (log, "%s NOT-FOUND", ver->name);
- else
- fprintf (log, "%s %s %s", ver->name,
- comparison_to_str (ver->comparison),
- (ver->version == NULL) ? "(null)" : ver->version);
- fprintf (log, "\n");
- }
-
- if (req == NULL)
- {
- failed = TRUE;
- verbose_error ("No package '%s' found\n", ver->name);
- goto nextiter;
- }
-
- if (!version_test (ver->comparison, req->version, ver->version))
- {
- failed = TRUE;
- verbose_error ("Requested '%s %s %s' but version of %s is %s\n",
- ver->name,
- comparison_to_str (ver->comparison),
- ver->version,
- req->name,
- req->version);
-
- if (req->url)
- verbose_error ("You may find new versions of %s at %s\n",
- req->name, req->url);
-
- goto nextiter;
- }
-
- packages = g_slist_prepend (packages, req);
-
- nextiter:
- iter = g_slist_next (iter);
- }
-
- if (log != NULL)
- {
- fclose (log);
- }
-
- if (failed) {
- return 1;
- }
+ /* find and parse each of the packages specified */
+ if (!process_package_args (str->str, &packages, log))
+ return 1;
+
+ if (log != NULL)
+ fclose (log);
+
+ g_string_free (str, TRUE);
+
+ if (want_exists)
+ return 0; /* if we got here, all the packages existed. */
if (want_variable_list)
{
- GSList *tmp;
+ GList *tmp;
tmp = packages;
while (tmp != NULL)
{
Package *pkg = tmp->data;
- g_hash_table_foreach(pkg->vars,
- &print_hashtable_key,
- NULL);
- tmp = g_slist_next (tmp);
+ if (pkg->vars != NULL)
+ g_hash_table_foreach(pkg->vars,
+ &print_hashtable_key,
+ NULL);
+ tmp = g_list_next (tmp);
if (tmp) printf ("\n");
}
need_newline = FALSE;
}
- }
-
- g_string_free (str, TRUE);
-
- packages = g_slist_reverse (packages);
-
- if (packages == NULL)
- {
- fprintf (stderr, "Must specify package names on the command line\n");
-
- exit (1);
- }
-
- if (want_exists)
- return 0; /* if we got here, all the packages existed. */
-
if (want_uninstalled)
{
/* See if > 0 pkgs (including dependencies recursively) were uninstalled */
- GSList *tmp;
+ GList *tmp;
tmp = packages;
while (tmp != NULL)
{
@@ -617,7 +703,7 @@ main (int argc, char **argv)
if (pkg_uninstalled (pkg))
return 0;
- tmp = g_slist_next (tmp);
+ tmp = g_list_next (tmp);
}
return 1;
@@ -625,7 +711,7 @@ main (int argc, char **argv)
if (want_version)
{
- GSList *tmp;
+ GList *tmp;
tmp = packages;
while (tmp != NULL)
{
@@ -633,13 +719,13 @@ main (int argc, char **argv)
printf ("%s\n", pkg->version);
- tmp = g_slist_next (tmp);
+ tmp = g_list_next (tmp);
}
}
if (want_provides)
{
- GSList *tmp;
+ GList *tmp;
tmp = packages;
while (tmp != NULL)
{
@@ -650,20 +736,20 @@ main (int argc, char **argv)
key++;
if (strlen(key) > 0)
printf ("%s = %s\n", key, pkg->version);
- tmp = g_slist_next (tmp);
+ tmp = g_list_next (tmp);
}
}
if (want_requires)
{
- GSList *pkgtmp;
- for (pkgtmp = packages; pkgtmp != NULL; pkgtmp = g_slist_next (pkgtmp))
+ GList *pkgtmp;
+ for (pkgtmp = packages; pkgtmp != NULL; pkgtmp = g_list_next (pkgtmp))
{
Package *pkg = pkgtmp->data;
- GSList *reqtmp;
+ GList *reqtmp;
/* process Requires: */
- for (reqtmp = pkg->requires; reqtmp != NULL; reqtmp = g_slist_next (reqtmp))
+ for (reqtmp = pkg->requires; reqtmp != NULL; reqtmp = g_list_next (reqtmp))
{
Package *deppkg = reqtmp->data;
RequiredVersion *req;
@@ -679,19 +765,19 @@ main (int argc, char **argv)
}
if (want_requires_private)
{
- GSList *pkgtmp;
- for (pkgtmp = packages; pkgtmp != NULL; pkgtmp = g_slist_next (pkgtmp))
+ GList *pkgtmp;
+ for (pkgtmp = packages; pkgtmp != NULL; pkgtmp = g_list_next (pkgtmp))
{
Package *pkg = pkgtmp->data;
- GSList *reqtmp;
+ GList *reqtmp;
/* process Requires.private: */
- for (reqtmp = pkg->requires_private; reqtmp != NULL; reqtmp = g_slist_next (reqtmp))
+ for (reqtmp = pkg->requires_private; reqtmp != NULL; reqtmp = g_list_next (reqtmp))
{
Package *deppkg = reqtmp->data;
RequiredVersion *req;
- if (g_slist_find (pkg->requires, reqtmp->data))
+ if (g_list_find (pkg->requires, reqtmp->data))
continue;
req = g_hash_table_lookup(pkg->required_versions, deppkg->key);
@@ -716,53 +802,10 @@ main (int argc, char **argv)
need_newline = TRUE;
}
- if (want_I_cflags)
- {
- char *str = packages_get_I_cflags (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
- else if (want_other_cflags)
- {
- char *str = packages_get_other_cflags (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
- else if (want_cflags)
- {
- char *str = packages_get_all_cflags (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
-
- if (want_l_libs)
+ if (pkg_flags != 0)
{
- char *str = packages_get_l_libs (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
- else if (want_L_libs)
- {
- char *str = packages_get_L_libs (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
- else if (want_other_libs)
- {
- char *str = packages_get_other_libs (packages);
- printf ("%s ", str);
- g_free (str);
- need_newline = TRUE;
- }
- else if (want_libs)
- {
- char *str = packages_get_all_libs (packages);
- printf ("%s ", str);
+ char *str = packages_get_flags (packages, pkg_flags);
+ printf ("%s", str);
g_free (str);
need_newline = TRUE;
}