mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
b4d7be2014
Original commit message from CVS: 2005-05-04 Andy Wingo <wingo@pobox.com> * check/Makefile.am: * docs/gst/tmpl/gstatomic.sgml: * docs/gst/tmpl/gstplugin.sgml: * gst/base/gstbasesink.c: (gst_basesink_activate): * gst/base/gstbasesrc.c: (gst_basesrc_class_init), (gst_basesrc_init), (gst_basesrc_set_dataflow_funcs), (gst_basesrc_query), (gst_basesrc_set_property), (gst_basesrc_get_property), (gst_basesrc_check_get_range), (gst_basesrc_activate): * gst/base/gstbasesrc.h: * gst/base/gstbasetransform.c: (gst_base_transform_sink_activate), (gst_base_transform_src_activate): * gst/elements/gstelements.c: * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init), (gst_fakesrc_set_property), (gst_fakesrc_get_property): * gst/elements/gsttee.c: (gst_tee_sink_activate): * gst/elements/gsttypefindelement.c: (find_element_get_length), (gst_type_find_element_checkgetrange), (gst_type_find_element_activate): * gst/gstbin.c: (gst_bin_save_thyself), (gst_bin_restore_thyself): * gst/gstcaps.c: (gst_caps_do_simplify), (gst_caps_save_thyself), (gst_caps_load_thyself): * gst/gstelement.c: (gst_element_pads_activate), (gst_element_save_thyself), (gst_element_restore_thyself): * gst/gstpad.c: (gst_pad_load_and_link), (gst_pad_save_thyself), (gst_ghost_pad_save_thyself), (gst_pad_check_pull_range): * gst/gstpad.h: * gst/gstxml.c: (gst_xml_write), (gst_xml_parse_doc), (gst_xml_parse_file), (gst_xml_parse_memory), (gst_xml_get_element), (gst_xml_make_element): * gst/indexers/gstfileindex.c: (gst_file_index_load), (_file_index_id_save_xml), (gst_file_index_commit): * gst/registries/gstlibxmlregistry.c: (read_string), (read_uint), (read_enum), (load_pad_template), (load_feature), (load_plugin), (load_paths): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_caps), (gst_dp_packet_from_event), (gst_dp_caps_from_packet): * tools/gst-complete.c: (main): * tools/gst-compprep.c: (main): * tools/gst-inspect.c: (print_element_properties_info): * tools/gst-launch.c: (xmllaunch_parse_cmdline): * tools/gst-xmlinspect.c: (print_element_properties): GCC 4 fixen.
250 lines
6.7 KiB
C
250 lines
6.7 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <locale.h>
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include "config.h"
|
|
#endif
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
typedef struct
|
|
{
|
|
gchar *name;
|
|
GSList *srcpads;
|
|
GSList *sinkpads;
|
|
GSList *srcpadtemplates;
|
|
GSList *sinkpadtemplates;
|
|
GSList *arguments;
|
|
}
|
|
comp_element;
|
|
|
|
enum
|
|
{
|
|
ARG_INT,
|
|
ARG_FILENAME,
|
|
ARG_ENUM
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
gchar *name;
|
|
int type;
|
|
GSList *enums;
|
|
}
|
|
comp_argument;
|
|
|
|
typedef struct
|
|
{
|
|
gint value;
|
|
gchar *nick;
|
|
}
|
|
enum_value;
|
|
|
|
|
|
void
|
|
print_match_list (gchar * prefix, int len, GSList * wordlist)
|
|
{
|
|
GSList *words = wordlist;
|
|
|
|
while (words) {
|
|
if (!len || !strncmp ((gchar *) (words->data), prefix, len))
|
|
printf ("%s\n", (gchar *) (words->data));
|
|
words = g_slist_next (words);
|
|
}
|
|
}
|
|
|
|
int
|
|
match_element (comp_element * element, gchar * name)
|
|
{
|
|
return strcmp (element->name, name);
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
xmlDocPtr doc;
|
|
xmlNodePtr rootnode, elementnode, propnode, argnode;
|
|
GList *element_list = NULL;
|
|
comp_element *element;
|
|
GSList *element_names = NULL;
|
|
comp_argument *argument;
|
|
enum_value *option;
|
|
|
|
gchar *prev_word;
|
|
gchar *partial_word;
|
|
int partial_len;
|
|
GList *elements;
|
|
GSList *pads;
|
|
int num_pads;
|
|
GSList *args;
|
|
gchar *word;
|
|
GSList *words = NULL;
|
|
|
|
struct stat stat_buf;
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
if (argc < 4) {
|
|
fprintf (stderr, "gst-complete called with invalid arguments\n");
|
|
exit (1);
|
|
}
|
|
|
|
prev_word = argv[3];
|
|
partial_word = argv[2];
|
|
|
|
partial_len = strlen (partial_word);
|
|
|
|
/***** Loading the completion information from the registry *****/
|
|
|
|
if (stat (GST_CACHE_DIR "/compreg.xml", &stat_buf) == 0) {
|
|
doc = xmlParseFile (GST_CACHE_DIR "/compreg.xml");
|
|
} else {
|
|
exit (1);
|
|
}
|
|
rootnode = doc->xmlRootNode;
|
|
|
|
elementnode = rootnode->xmlChildrenNode;
|
|
while (elementnode) {
|
|
if (!strcmp ((char *) elementnode->name, "element")) {
|
|
element = g_new0 (comp_element, 1);
|
|
propnode = elementnode->xmlChildrenNode;
|
|
while (propnode) {
|
|
|
|
if (!strcmp ((char *) propnode->name, "name")) {
|
|
element->name = (gchar *) xmlNodeGetContent (propnode);
|
|
/* fprintf(stderr,element->name); */
|
|
} else if (!strcmp ((char *) propnode->name, "srcpad")) {
|
|
element->srcpads =
|
|
g_slist_prepend (element->srcpads, xmlNodeGetContent (propnode));
|
|
/* fprintf(stderr,"."); */
|
|
} else if (!strcmp ((char *) propnode->name, "sinkpad")) {
|
|
element->sinkpads =
|
|
g_slist_prepend (element->sinkpads, xmlNodeGetContent (propnode));
|
|
} else if (!strcmp ((char *) propnode->name, "srcpadtemplate")) {
|
|
element->srcpadtemplates =
|
|
g_slist_prepend (element->srcpadtemplates,
|
|
xmlNodeGetContent (propnode));
|
|
/* fprintf(stderr,"."); */
|
|
} else if (!strcmp ((char *) propnode->name, "sinkpad")) {
|
|
element->sinkpadtemplates =
|
|
g_slist_prepend (element->sinkpadtemplates,
|
|
xmlNodeGetContent (propnode));
|
|
} else if (!strcmp ((char *) propnode->name, "argument")) {
|
|
argument = g_new0 (comp_argument, 1);
|
|
argument->name = (gchar *) xmlNodeGetContent (propnode);
|
|
argument->type = ARG_INT;
|
|
|
|
/* walk through the values data */
|
|
argnode = propnode->xmlChildrenNode;
|
|
while (argnode) {
|
|
if (!strcmp ((char *) argnode->name, "filename")) {
|
|
argument->type = ARG_FILENAME;
|
|
} else if (!strcmp ((char *) argnode->name, "option")) {
|
|
argument->type = ARG_ENUM;
|
|
option = g_new0 (enum_value, 1);
|
|
sscanf ((char *) xmlNodeGetContent (argnode), "%d",
|
|
&option->value);
|
|
argument->enums = g_slist_prepend (argument->enums, option);
|
|
}
|
|
argnode = argnode->next;
|
|
}
|
|
|
|
element->arguments = g_slist_prepend (element->arguments, argument);
|
|
}
|
|
|
|
propnode = propnode->next;
|
|
}
|
|
element_list = g_list_prepend (element_list, element);
|
|
element_names = g_slist_prepend (element_names, element->name);
|
|
}
|
|
elementnode = elementnode->next;
|
|
}
|
|
|
|
|
|
|
|
/***** Completion *****/
|
|
|
|
/* The bulk of the work is in deciding exactly which words are an option. */
|
|
|
|
/* if we're right at the beginning, with -launch in the first word */
|
|
if (strstr (prev_word, "-launch")) {
|
|
/* print out only elements with no sink pad or padtemplate */
|
|
elements = element_list;
|
|
while (elements) {
|
|
element = (comp_element *) (elements->data);
|
|
if (!element->sinkpads && !element->sinkpadtemplates)
|
|
words = g_slist_prepend (words, element->name);
|
|
elements = g_list_next (elements);
|
|
}
|
|
}
|
|
|
|
/* if the previous word is a connection */
|
|
if (strchr (prev_word, '!')) {
|
|
/* print out oly elements with a sink pad or template */
|
|
elements = element_list;
|
|
while (elements) {
|
|
element = (comp_element *) (elements->data);
|
|
if (element->sinkpads || element->sinkpadtemplates)
|
|
words = g_slist_prepend (words, element->name);
|
|
elements = g_list_next (elements);
|
|
}
|
|
}
|
|
|
|
/* if the partial word is an argument, and it's an enum */
|
|
if (strchr (prev_word, '=')) {
|
|
fprintf (stderr, "it's an arg, but dunno what element yet\n");
|
|
}
|
|
|
|
/* if the previous word is an element, we need to list both pads and arguments */
|
|
if ((elements =
|
|
g_list_find_custom (element_list, prev_word,
|
|
(GCompareFunc) match_element))) {
|
|
element = elements->data;
|
|
/* zero the numpads list so we can count them */
|
|
num_pads = 0;
|
|
|
|
/* pads */
|
|
pads = element->srcpads;
|
|
while (pads) {
|
|
num_pads++;
|
|
words =
|
|
g_slist_prepend (words, g_strdup_printf ("%s!",
|
|
(gchar *) (pads->data)));
|
|
pads = g_slist_next (pads);
|
|
}
|
|
|
|
/* padtemplates */
|
|
pads = element->srcpadtemplates;
|
|
while (pads) {
|
|
num_pads++;
|
|
word = g_strdup_printf ("%s!", (gchar *) (pads->data));
|
|
if (!g_slist_find_custom (words, word, (GCompareFunc) strcmp))
|
|
words = g_slist_prepend (words, word);
|
|
pads = g_slist_next (pads);
|
|
}
|
|
|
|
/* if there is only one pad, add '!' to the list of completions */
|
|
if (num_pads == 1) {
|
|
words = g_slist_prepend (words, "!");
|
|
}
|
|
|
|
/* arguments */
|
|
args = element->arguments;
|
|
while (args) {
|
|
argument = (comp_argument *) (args->data);
|
|
word = strstr (argument->name, "::") + 2;
|
|
words = g_slist_prepend (words, g_strdup_printf ("%s=", word));
|
|
words = g_slist_prepend (words, g_strdup_printf ("%s=...", word));
|
|
args = g_slist_next (args);
|
|
}
|
|
}
|
|
|
|
|
|
/* The easy part is ouptuting the correct list of possibilities. */
|
|
print_match_list (partial_word, partial_len, words);
|
|
|
|
return 0;
|
|
}
|