mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-13 03:46:34 +00:00
added initial bash commandline completion code
Original commit message from CVS: added initial bash commandline completion code
This commit is contained in:
parent
9bc5f785d7
commit
12d962e174
4 changed files with 298 additions and 1 deletions
2
tools/.gitignore
vendored
2
tools/.gitignore
vendored
|
@ -9,4 +9,6 @@ Makefile.in
|
||||||
gstreamer-launch
|
gstreamer-launch
|
||||||
gstreamer-register
|
gstreamer-register
|
||||||
gstreamer-inspect
|
gstreamer-inspect
|
||||||
|
gstreamer-compprep
|
||||||
|
gstreamer-complete
|
||||||
*.xml
|
*.xml
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
bin_PROGRAMS = gstreamer-launch gstreamer-register gstreamer-inspect
|
bin_PROGRAMS = gstreamer-launch gstreamer-register gstreamer-inspect \
|
||||||
|
gstreamer-compprep gstreamer-complete
|
||||||
|
|
||||||
man_MANS = gstreamer-launch.1 gstreamer-register.1 gstreamer-inspect.1
|
man_MANS = gstreamer-launch.1 gstreamer-register.1 gstreamer-inspect.1
|
||||||
|
|
||||||
|
|
203
tools/gstreamer-complete.c
Normal file
203
tools/gstreamer-complete.c
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <parser.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "config.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 = argv[3];
|
||||||
|
gchar *partial_word = argv[2];
|
||||||
|
int partial_len = strlen(partial_word);
|
||||||
|
GList *elements;
|
||||||
|
GSList *pads;
|
||||||
|
int num_pads;
|
||||||
|
GSList *args;
|
||||||
|
gchar *word;
|
||||||
|
GSList *words = NULL;
|
||||||
|
|
||||||
|
/***** Loading the completion information from the registry *****/
|
||||||
|
|
||||||
|
doc = xmlParseFile (GST_CONFIG_DIR "/compreg.xml");
|
||||||
|
rootnode = doc->xmlRootNode;
|
||||||
|
|
||||||
|
elementnode = rootnode->xmlChildrenNode;
|
||||||
|
while (elementnode) {
|
||||||
|
if (!strcmp(elementnode->name, "element")) {
|
||||||
|
element = g_new0(comp_element,1);
|
||||||
|
propnode = elementnode->xmlChildrenNode;
|
||||||
|
while (propnode) {
|
||||||
|
|
||||||
|
if (!strcmp(propnode->name, "name")) {
|
||||||
|
element->name = xmlNodeGetContent(propnode);
|
||||||
|
//fprintf(stderr,element->name);
|
||||||
|
} else if (!strcmp(propnode->name, "srcpad")) {
|
||||||
|
element->srcpads = g_slist_prepend(element->srcpads, xmlNodeGetContent(propnode));
|
||||||
|
//fprintf(stderr,".");
|
||||||
|
} else if (!strcmp(propnode->name, "sinkpad")) {
|
||||||
|
element->sinkpads = g_slist_prepend(element->sinkpads, xmlNodeGetContent(propnode));
|
||||||
|
} else if (!strcmp(propnode->name, "srcpadtemplate")) {
|
||||||
|
element->srcpadtemplates = g_slist_prepend(element->srcpadtemplates, xmlNodeGetContent(propnode));
|
||||||
|
//fprintf(stderr,".");
|
||||||
|
} else if (!strcmp(propnode->name, "sinkpad")) {
|
||||||
|
element->sinkpadtemplates = g_slist_prepend(element->sinkpadtemplates, xmlNodeGetContent(propnode));
|
||||||
|
} else if (!strcmp(propnode->name, "argument")) {
|
||||||
|
argument = g_new0(comp_argument,1);
|
||||||
|
argument->name = xmlNodeGetContent(propnode);
|
||||||
|
argument->type = ARG_INT;
|
||||||
|
|
||||||
|
// walk through the values data
|
||||||
|
argnode = propnode->xmlChildrenNode;
|
||||||
|
while (argnode) {
|
||||||
|
if (!strcmp(argnode->name, "filename")) {
|
||||||
|
argument->type = ARG_FILENAME;
|
||||||
|
} else if (!strcmp(argnode->name,"option")) {
|
||||||
|
argument->type = ARG_ENUM;
|
||||||
|
option = g_new0(enum_value,1);
|
||||||
|
sscanf(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;
|
||||||
|
}
|
91
tools/gstreamer-compprep.c
Normal file
91
tools/gstreamer-compprep.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
#include <gst/gst.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
int main(int argc,char *argv[]) {
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlNodePtr factorynode, padnode, argnode, optionnode;
|
||||||
|
GList *plugins, *factories, *padtemplates, *pads;
|
||||||
|
GstPlugin *plugin;
|
||||||
|
GstElementFactory *factory;
|
||||||
|
GstElement *element;
|
||||||
|
GstPad *pad;
|
||||||
|
GstPadTemplate *padtemplate;
|
||||||
|
GtkArg *args;
|
||||||
|
guint32 *flags;
|
||||||
|
gint num_args,i;
|
||||||
|
|
||||||
|
gst_debug_set_categories(0);
|
||||||
|
gst_info_set_categories(0);
|
||||||
|
gst_init(&argc,&argv);
|
||||||
|
|
||||||
|
doc = xmlNewDoc("1.0");
|
||||||
|
doc->xmlRootNode = xmlNewDocNode(doc, NULL, "GST-CompletionRegistry", NULL);
|
||||||
|
|
||||||
|
plugins = gst_plugin_get_list();
|
||||||
|
while (plugins) {
|
||||||
|
plugin = (GstPlugin *)(plugins->data);
|
||||||
|
plugins = g_list_next (plugins);
|
||||||
|
|
||||||
|
factories = gst_plugin_get_factory_list(plugin);
|
||||||
|
while (factories) {
|
||||||
|
factory = (GstElementFactory *)(factories->data);
|
||||||
|
factories = g_list_next (factories);
|
||||||
|
|
||||||
|
factorynode = xmlNewChild (doc->xmlRootNode, NULL, "element", NULL);
|
||||||
|
xmlNewChild (factorynode, NULL, "name", factory->name);
|
||||||
|
|
||||||
|
element = gst_elementfactory_create(factory,"element");
|
||||||
|
if (element == NULL) {
|
||||||
|
fprintf(stderr,"couldn't construct element from factory %s\n",factory->name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write out the padtemplates
|
||||||
|
padtemplates = factory->padtemplates;
|
||||||
|
while (padtemplates) {
|
||||||
|
padtemplate = (GstPadTemplate *)(padtemplates->data);
|
||||||
|
padtemplates = g_list_next (padtemplates);
|
||||||
|
|
||||||
|
if (padtemplate->direction == GST_PAD_SRC)
|
||||||
|
padnode = xmlNewChild (factorynode, NULL, "srcpadtemplate", padtemplate->name_template);
|
||||||
|
else if (padtemplate->direction == GST_PAD_SINK)
|
||||||
|
padnode = xmlNewChild (factorynode, NULL, "sinkpadtemplate", padtemplate->name_template);
|
||||||
|
}
|
||||||
|
|
||||||
|
pads = gst_element_get_pad_list (element);
|
||||||
|
while (pads) {
|
||||||
|
pad = (GstPad *)(pads->data);
|
||||||
|
pads = g_list_next (pads);
|
||||||
|
|
||||||
|
if (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
|
||||||
|
padnode = xmlNewChild (factorynode, NULL, "srcpad", GST_PAD_NAME(pad));
|
||||||
|
else if (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
|
||||||
|
padnode = xmlNewChild (factorynode, NULL, "sinkpad", GST_PAD_NAME(pad));
|
||||||
|
}
|
||||||
|
|
||||||
|
// write out the args
|
||||||
|
args = gtk_object_query_args(GTK_OBJECT_TYPE(element), &flags, &num_args);
|
||||||
|
for (i=0;i<num_args;i++) {
|
||||||
|
argnode = xmlNewChild (factorynode, NULL, "argument", args[i].name);
|
||||||
|
if (args[i].type == GST_TYPE_FILENAME) {
|
||||||
|
xmlNewChild (argnode, NULL, "filename", NULL);
|
||||||
|
} else if (GTK_FUNDAMENTAL_TYPE (args[i].type) == GTK_TYPE_ENUM) {
|
||||||
|
GtkEnumValue *values;
|
||||||
|
gint j;
|
||||||
|
|
||||||
|
values = gtk_type_enum_get_values (args[i].type);
|
||||||
|
for (j=0;values[j].value_name;j++) {
|
||||||
|
gchar *value = g_strdup_printf("%d",values[j].value);
|
||||||
|
optionnode = xmlNewChild (argnode, NULL, "option", value);
|
||||||
|
xmlNewChild (optionnode, NULL, "value_nick", values[j].value_nick);
|
||||||
|
g_free(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlSaveFile(GST_CONFIG_DIR "/compreg.xml",doc);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue