2004-02-04 18:02:55 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2004 Thomas Vander Stichele <thomas@apestaart.org>
|
|
|
|
*
|
|
|
|
* gst-run.c: tool to launch GStreamer tools with correct major/minor
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-04-26 00:13:03 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-02-04 18:02:55 +00:00
|
|
|
#include <unistd.h>
|
2008-04-26 00:13:03 +00:00
|
|
|
#endif
|
2004-02-04 18:02:55 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
/* global statics for option parsing */
|
|
|
|
static gboolean _print = FALSE;
|
2004-03-13 15:27:01 +00:00
|
|
|
static gchar *_arg_mm = NULL;
|
2004-02-04 18:02:55 +00:00
|
|
|
static gboolean _arg_list_mm = FALSE;
|
|
|
|
|
|
|
|
/* popt options table for the wrapper */
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
static GOptionEntry wrapper_options[] = {
|
|
|
|
{"print", 'p', 0, G_OPTION_ARG_NONE, &_print,
|
|
|
|
"print wrapped command line options", NULL},
|
|
|
|
{"gst-mm", 0, 0, G_OPTION_ARG_STRING, &_arg_mm,
|
|
|
|
"Force major/minor version", "VERSION"},
|
|
|
|
{"gst-list-mm", 0, 0, G_OPTION_ARG_NONE, &_arg_list_mm,
|
|
|
|
"List found major/minor versions", NULL},
|
|
|
|
{NULL}
|
2004-02-04 18:02:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* print out the major/minor, which is the hash key */
|
|
|
|
static void
|
|
|
|
hash_print_key (gchar * key, gchar * value)
|
|
|
|
{
|
|
|
|
g_print ("%s\n", (gchar *) key);
|
|
|
|
}
|
|
|
|
|
2005-12-02 01:35:22 +00:00
|
|
|
/* return value like strcmp, but compares major/minor numerically */
|
|
|
|
static gint
|
|
|
|
compare_major_minor (const gchar * first, const gchar * second)
|
|
|
|
{
|
|
|
|
gchar **firsts, **seconds;
|
|
|
|
gint fmaj, fmin, smaj, smin;
|
|
|
|
gint ret = 0;
|
|
|
|
|
|
|
|
firsts = g_strsplit (first, ".", 0);
|
|
|
|
seconds = g_strsplit (second, ".", 0);
|
|
|
|
|
|
|
|
if (firsts[0] == NULL || firsts[1] == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
if (seconds[0] == NULL || seconds[1] == NULL) {
|
|
|
|
ret = 1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmaj = atoi (firsts[0]);
|
|
|
|
fmin = atoi (firsts[1]);
|
|
|
|
smaj = atoi (seconds[0]);
|
|
|
|
smin = atoi (seconds[1]);
|
|
|
|
|
|
|
|
if (fmaj < smaj) {
|
|
|
|
ret = -1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
if (fmaj > smaj) {
|
|
|
|
ret = 1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fmaj == smaj */
|
|
|
|
if (fmin < smin) {
|
|
|
|
ret = -1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
if (fmin > smin) {
|
|
|
|
ret = 1;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
beach:
|
|
|
|
g_strfreev (firsts);
|
|
|
|
g_strfreev (seconds);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-02-04 18:02:55 +00:00
|
|
|
static void
|
|
|
|
find_highest_version (gchar * key, gchar * value, gchar ** highest)
|
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*highest == NULL) {
|
2004-02-04 18:02:55 +00:00
|
|
|
/* first value, so just set it */
|
|
|
|
*highest = key;
|
|
|
|
}
|
2005-12-02 01:35:22 +00:00
|
|
|
if (compare_major_minor (key, *highest) > 0)
|
2004-03-13 15:27:01 +00:00
|
|
|
*highest = key;
|
2004-02-04 18:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Libtool creates shell scripts named "base" that calls actual binaries as
|
|
|
|
* .libs/lt-base. If we detect this is a libtool script, unmangle so we
|
|
|
|
* find the right binaries */
|
|
|
|
static void
|
|
|
|
unmangle_libtool (gchar ** dir, gchar ** base)
|
|
|
|
{
|
|
|
|
gchar *new_dir, *new_base;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!*dir)
|
|
|
|
return;
|
|
|
|
if (!*base)
|
|
|
|
return;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
2010-05-04 09:29:02 +00:00
|
|
|
/* We assume libtool when base starts with "lt-" and dir ends with ".libs".
|
|
|
|
* On Windows libtool doesn't seem to be adding "lt-" prefix. */
|
|
|
|
#ifndef G_OS_WIN32
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!g_str_has_prefix (*base, "lt-"))
|
|
|
|
return;
|
2010-05-04 09:29:02 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!g_str_has_suffix (*dir, ".libs"))
|
|
|
|
return;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
2010-05-04 09:29:02 +00:00
|
|
|
#ifndef G_OS_WIN32
|
2004-02-04 18:02:55 +00:00
|
|
|
new_base = g_strdup (&((*base)[3]));
|
2010-05-04 09:29:02 +00:00
|
|
|
#else
|
|
|
|
new_base = g_strdup (*base);
|
|
|
|
#endif
|
2004-02-04 18:02:55 +00:00
|
|
|
new_dir = g_path_get_dirname (*dir);
|
|
|
|
g_free (*base);
|
|
|
|
g_free (*dir);
|
|
|
|
*base = new_base;
|
|
|
|
*dir = new_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a directory path that contains the binary given as an argument.
|
|
|
|
* If the binary given contains a path, it gets looked for in that path.
|
|
|
|
* If it doesn't contain a path, it gets looked for in the standard path.
|
|
|
|
*
|
|
|
|
* The returned string is newly allocated.
|
|
|
|
*/
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* gst/gstconfig.h.in:
* libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer):
* libs/gst/check/gstcheck.c: (gst_check_log_message_func),
(gst_check_log_critical_func), (gst_check_drop_buffers),
(gst_check_element_push_buffer_list):
* libs/gst/controller/gstcontroller.c: (gst_controller_get),
(gst_controller_get_type):
* libs/gst/controller/gsthelper.c: (gst_object_control_properties),
(gst_object_get_controller), (gst_object_get_control_source):
* libs/gst/controller/gstinterpolationcontrolsource.c:
(gst_interpolation_control_source_new):
* libs/gst/controller/gstlfocontrolsource.c:
(gst_lfo_control_source_new):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_event_from_packet_0_2):
* plugins/elements/gstfdsrc.c:
* plugins/elements/gstmultiqueue.c:
* plugins/elements/gsttee.c:
* plugins/elements/gsttypefindelement.c:
* plugins/indexers/gstfileindex.c: (_file_index_id_save_xml),
(gst_file_index_add_association):
* plugins/indexers/gstmemindex.c:
* tests/benchmarks/gstpollstress.c: (mess_some_more):
* tests/check/elements/queue.c: (setup_queue):
* tests/check/gst/gstpipeline.c:
* tests/check/libs/collectpads.c: (setup), (teardown),
(gst_collect_pads_suite):
* tests/examples/adapter/adapter_test.c:
* tests/examples/metadata/read-metadata.c: (make_pipeline):
* tests/examples/xml/createxml.c:
* tests/examples/xml/runxml.c:
* tools/gst-inspect.c:
* tools/gst-run.c:
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers, not using variable sized arrays
on the stack, moving variable declarations to the beginning of
a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
|
|
|
static gchar *
|
2004-02-04 18:02:55 +00:00
|
|
|
get_dir_of_binary (const gchar * binary)
|
|
|
|
{
|
|
|
|
gchar *base, *dir;
|
|
|
|
gchar *full;
|
|
|
|
|
|
|
|
base = g_path_get_basename (binary);
|
|
|
|
dir = g_path_get_dirname (binary);
|
|
|
|
|
|
|
|
/* if putting these two together yields the same as binary,
|
|
|
|
* then we have the right breakup. If not, it's because no path was
|
|
|
|
* specified which caused get_basename to return "." */
|
|
|
|
full = g_build_filename (dir, base, NULL);
|
|
|
|
|
2010-05-04 09:29:02 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
/* g_build_filename() should be using the last path separator used in the
|
|
|
|
* input according to the docs, but doesn't actually do that, so we have
|
|
|
|
* to fix up the result. */
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
for (tmp = (gchar *) binary + strlen (binary) - 1; tmp >= binary; tmp--) {
|
|
|
|
if (*tmp == '/' || *tmp == '\\') {
|
|
|
|
full[strlen (dir)] = *tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (strcmp (full, binary) != 0) {
|
|
|
|
if (strcmp (dir, ".") != 0) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_warning ("This should not happen, g_path_get_dirname () has changed.");
|
|
|
|
g_free (base);
|
|
|
|
g_free (dir);
|
|
|
|
g_free (full);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we know no path was specified, so search standard path for binary */
|
|
|
|
g_free (full);
|
|
|
|
full = g_find_program_in_path (base);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!full) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_warning ("This should not happen, %s not in standard path.", base);
|
|
|
|
g_free (base);
|
|
|
|
g_free (dir);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (base);
|
|
|
|
g_free (dir);
|
|
|
|
dir = g_path_get_dirname (full);
|
|
|
|
g_free (full);
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search the given directory for candidate binaries matching the base binary.
|
|
|
|
* Return a GHashTable of major/minor -> directory pairs
|
|
|
|
*/
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* gst/gstconfig.h.in:
* libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer):
* libs/gst/check/gstcheck.c: (gst_check_log_message_func),
(gst_check_log_critical_func), (gst_check_drop_buffers),
(gst_check_element_push_buffer_list):
* libs/gst/controller/gstcontroller.c: (gst_controller_get),
(gst_controller_get_type):
* libs/gst/controller/gsthelper.c: (gst_object_control_properties),
(gst_object_get_controller), (gst_object_get_control_source):
* libs/gst/controller/gstinterpolationcontrolsource.c:
(gst_interpolation_control_source_new):
* libs/gst/controller/gstlfocontrolsource.c:
(gst_lfo_control_source_new):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_event_from_packet_0_2):
* plugins/elements/gstfdsrc.c:
* plugins/elements/gstmultiqueue.c:
* plugins/elements/gsttee.c:
* plugins/elements/gsttypefindelement.c:
* plugins/indexers/gstfileindex.c: (_file_index_id_save_xml),
(gst_file_index_add_association):
* plugins/indexers/gstmemindex.c:
* tests/benchmarks/gstpollstress.c: (mess_some_more):
* tests/check/elements/queue.c: (setup_queue):
* tests/check/gst/gstpipeline.c:
* tests/check/libs/collectpads.c: (setup), (teardown),
(gst_collect_pads_suite):
* tests/examples/adapter/adapter_test.c:
* tests/examples/metadata/read-metadata.c: (make_pipeline):
* tests/examples/xml/createxml.c:
* tests/examples/xml/runxml.c:
* tools/gst-inspect.c:
* tools/gst-run.c:
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers, not using variable sized arrays
on the stack, moving variable declarations to the beginning of
a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
|
|
|
static GHashTable *
|
2004-02-04 18:02:55 +00:00
|
|
|
get_candidates (const gchar * dir, const gchar * base)
|
|
|
|
{
|
|
|
|
GDir *gdir;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *entry;
|
|
|
|
gchar *path;
|
2005-12-02 01:35:22 +00:00
|
|
|
gchar *suffix, *copy;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
gchar *pattern;
|
2005-12-02 01:35:22 +00:00
|
|
|
GPatternSpec *spec, *specexe;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
gchar **dirs;
|
|
|
|
gchar **cur;
|
|
|
|
|
|
|
|
GHashTable *candidates = NULL;
|
|
|
|
|
|
|
|
candidates = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
|
|
|
|
2005-12-02 01:35:22 +00:00
|
|
|
/* compile our pattern specs */
|
2004-02-04 18:02:55 +00:00
|
|
|
pattern = g_strdup_printf ("%s-*.*", base);
|
|
|
|
spec = g_pattern_spec_new (pattern);
|
|
|
|
g_free (pattern);
|
2005-12-02 01:35:22 +00:00
|
|
|
pattern = g_strdup_printf ("%s-*.*.exe", base);
|
|
|
|
specexe = g_pattern_spec_new (pattern);
|
|
|
|
g_free (pattern);
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
/* get all dirs from the path and prepend with given dir */
|
2007-10-15 07:11:04 +00:00
|
|
|
if (dir)
|
|
|
|
path = g_strdup_printf ("%s%c%s",
|
|
|
|
dir, G_SEARCHPATH_SEPARATOR, g_getenv ("PATH"));
|
|
|
|
else
|
|
|
|
path = (gchar *) g_getenv ("PATH");
|
2004-02-04 18:02:55 +00:00
|
|
|
dirs = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 0);
|
2007-10-15 07:11:04 +00:00
|
|
|
if (dir)
|
|
|
|
g_free (path);
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
/* check all of these in reverse order by winding to bottom and going up */
|
|
|
|
cur = &dirs[0];
|
2004-03-13 15:27:01 +00:00
|
|
|
while (*cur)
|
|
|
|
++cur;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (cur != &dirs[0]) {
|
2004-02-04 18:02:55 +00:00
|
|
|
--cur;
|
2006-04-29 23:15:40 +00:00
|
|
|
if (!g_file_test (*cur, G_FILE_TEST_EXISTS) ||
|
|
|
|
!g_file_test (*cur, G_FILE_TEST_IS_DIR)) {
|
2004-02-04 18:02:55 +00:00
|
|
|
continue;
|
2006-04-29 23:15:40 +00:00
|
|
|
}
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
gdir = g_dir_open (*cur, 0, &error);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!gdir) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_warning ("Could not open dir %s: %s", *cur, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
while ((entry = g_dir_read_name (gdir))) {
|
2005-12-02 01:35:22 +00:00
|
|
|
if (g_pattern_match_string (spec, entry)
|
|
|
|
|| g_pattern_match_string (specexe, entry)) {
|
2004-03-15 19:27:17 +00:00
|
|
|
gchar *full;
|
|
|
|
|
|
|
|
/* is it executable ? */
|
|
|
|
full = g_build_filename (*cur, entry, NULL);
|
|
|
|
if (!g_file_test (full, G_FILE_TEST_IS_EXECUTABLE)) {
|
|
|
|
g_free (full);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
g_free (full);
|
|
|
|
|
|
|
|
/* strip base and dash from it */
|
|
|
|
suffix = g_strdup (&(entry[strlen (base) + 1]));
|
2005-12-02 01:35:22 +00:00
|
|
|
copy = g_strdup (suffix);
|
|
|
|
|
|
|
|
/* strip possible .exe from copy */
|
|
|
|
if (g_strrstr (copy, ".exe"))
|
|
|
|
g_strrstr (copy, ".exe")[0] = '\0';
|
2004-03-15 19:27:17 +00:00
|
|
|
|
|
|
|
/* stricter pattern check: check if it only contains digits or dots */
|
2005-12-02 01:35:22 +00:00
|
|
|
g_strcanon (copy, "0123456789.", 'X');
|
|
|
|
if (strstr (copy, "X")) {
|
|
|
|
g_free (suffix);
|
|
|
|
g_free (copy);
|
2004-03-15 19:27:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-12-02 01:35:22 +00:00
|
|
|
g_free (copy);
|
2004-03-15 19:27:17 +00:00
|
|
|
g_hash_table_insert (candidates, suffix, g_strdup (*cur));
|
2004-02-04 18:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (dirs);
|
|
|
|
g_pattern_spec_free (spec);
|
|
|
|
return candidates;
|
|
|
|
}
|
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
2004-02-04 18:02:55 +00:00
|
|
|
{
|
|
|
|
GHashTable *candidates;
|
|
|
|
gchar *dir;
|
|
|
|
gchar *base;
|
|
|
|
gchar *highest = NULL;
|
2004-03-15 19:27:17 +00:00
|
|
|
gchar *binary; /* actual binary we're going to run */
|
|
|
|
gchar *path = NULL; /* and its path */
|
2006-05-05 17:45:41 +00:00
|
|
|
gchar *desc;
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
GOptionContext *ctx;
|
|
|
|
GError *err = NULL;
|
2004-02-04 18:02:55 +00:00
|
|
|
|
2006-05-05 17:45:41 +00:00
|
|
|
/* detect stuff */
|
|
|
|
dir = get_dir_of_binary (argv[0]);
|
|
|
|
base = g_path_get_basename (argv[0]);
|
|
|
|
|
2004-02-04 18:02:55 +00:00
|
|
|
/* parse command line options */
|
2006-05-05 17:45:41 +00:00
|
|
|
desc = g_strdup_printf ("wrapper to call versioned %s", base);
|
|
|
|
ctx = g_option_context_new (desc);
|
|
|
|
g_free (desc);
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
g_option_context_set_ignore_unknown_options (ctx, TRUE);
|
|
|
|
g_option_context_add_main_entries (ctx, wrapper_options, GETTEXT_PACKAGE);
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_print ("Error initializing: %s\n", err->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
2005-10-13 09:57:15 +00:00
|
|
|
g_option_context_free (ctx);
|
2004-02-04 18:02:55 +00:00
|
|
|
|
|
|
|
/* unmangle libtool if necessary */
|
|
|
|
unmangle_libtool (&dir, &base);
|
|
|
|
|
2010-05-04 09:29:02 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* remove .exe suffix, otherwise we'll be looking for gst-blah.exe-*.* */
|
|
|
|
if (strlen (base) > 4 && g_str_has_suffix (base, ".exe")) {
|
|
|
|
base[strlen (base) - 4] = '\0';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-04 18:02:55 +00:00
|
|
|
/* get all candidate binaries */
|
|
|
|
candidates = get_candidates (dir, base);
|
|
|
|
g_free (dir);
|
|
|
|
|
2011-08-05 11:12:33 +00:00
|
|
|
/* only look for 0.10, we don't want 0.11 tools to be picked up accidentally
|
|
|
|
* (and from 0.11 on the unversioned tools are discontinued anyway) */
|
|
|
|
if (_arg_mm == NULL)
|
|
|
|
_arg_mm = GST_MAJORMINOR;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (_arg_mm) {
|
2004-02-04 18:02:55 +00:00
|
|
|
/* if a version was forced, look it up in the hash table */
|
|
|
|
dir = g_hash_table_lookup (candidates, _arg_mm);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!dir) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_print ("ERROR: Major/minor %s of tool %s not found.\n", _arg_mm, base);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
binary = g_strdup_printf ("%s-%s", base, _arg_mm);
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2004-03-10 23:52:02 +00:00
|
|
|
highest = NULL;
|
|
|
|
|
2004-02-04 18:02:55 +00:00
|
|
|
/* otherwise, just look up the highest version */
|
2006-04-29 23:15:40 +00:00
|
|
|
if (candidates) {
|
|
|
|
g_hash_table_foreach (candidates, (GHFunc) find_highest_version,
|
|
|
|
&highest);
|
|
|
|
}
|
|
|
|
|
2004-03-10 23:52:02 +00:00
|
|
|
if (highest == NULL) {
|
2006-04-29 23:15:40 +00:00
|
|
|
g_print ("ERROR: No version of tool %s found.\n", base);
|
2004-02-04 18:02:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2004-03-10 23:52:02 +00:00
|
|
|
dir = g_hash_table_lookup (candidates, highest);
|
2004-02-04 18:02:55 +00:00
|
|
|
binary = g_strdup_printf ("%s-%s", base, highest);
|
|
|
|
}
|
|
|
|
|
2004-02-19 10:36:06 +00:00
|
|
|
g_free (base);
|
|
|
|
|
2004-02-04 18:02:55 +00:00
|
|
|
path = g_build_filename (dir, binary, NULL);
|
|
|
|
g_free (binary);
|
|
|
|
|
|
|
|
/* print out list of major/minors we found if asked for */
|
|
|
|
/* FIXME: do them in order by creating a GList of keys and sort them */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (_arg_list_mm) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_hash_table_foreach (candidates, (GHFunc) hash_print_key, NULL);
|
2004-02-19 10:36:06 +00:00
|
|
|
g_hash_table_destroy (candidates);
|
2004-02-04 18:37:48 +00:00
|
|
|
return 0;
|
2004-02-04 18:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print out command line if asked for */
|
|
|
|
argv[0] = path;
|
2004-03-13 15:27:01 +00:00
|
|
|
if (_print) {
|
2004-02-04 18:02:55 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_print ("%s", argv[i]);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (i < argc - 1)
|
2004-03-15 19:27:17 +00:00
|
|
|
g_print (" ");
|
2004-02-04 18:02:55 +00:00
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* execute */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (execv (path, argv) == -1) {
|
2004-02-04 18:02:55 +00:00
|
|
|
g_warning ("Error executing %s: %s (%d)", path, g_strerror (errno), errno);
|
|
|
|
}
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|