2001-05-25 21:00:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-02-16 17:53:58 +00:00
|
|
|
#include <sys/stat.h>
|
2003-08-19 08:11:58 +00:00
|
|
|
#include <locale.h>
|
2001-05-27 17:02:25 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-05-27 17:02:25 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#include <gst/gst.h>
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
gchar *name;
|
|
|
|
GSList *srcpads;
|
|
|
|
GSList *sinkpads;
|
|
|
|
GSList *srcpadtemplates;
|
|
|
|
GSList *sinkpadtemplates;
|
|
|
|
GSList *arguments;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
comp_element;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
ARG_INT,
|
|
|
|
ARG_FILENAME,
|
|
|
|
ARG_ENUM
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
gchar *name;
|
|
|
|
int type;
|
|
|
|
GSList *enums;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
comp_argument;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
gint value;
|
|
|
|
gchar *nick;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
enum_value;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
print_match_list (gchar * prefix, int len, GSList * wordlist)
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
GSList *words = wordlist;
|
|
|
|
|
|
|
|
while (words) {
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!len || !strncmp ((gchar *) (words->data), prefix, len))
|
|
|
|
printf ("%s\n", (gchar *) (words->data));
|
2001-05-25 21:00:07 +00:00
|
|
|
words = g_slist_next (words);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
match_element (comp_element * element, gchar * name)
|
|
|
|
{
|
|
|
|
return strcmp (element->name, name);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
xmlDocPtr doc;
|
|
|
|
xmlNodePtr rootnode, elementnode, propnode, argnode;
|
|
|
|
GList *element_list = NULL;
|
|
|
|
comp_element *element;
|
|
|
|
GSList *element_names = NULL;
|
|
|
|
comp_argument *argument;
|
|
|
|
enum_value *option;
|
|
|
|
|
2002-09-20 03:27:54 +00:00
|
|
|
gchar *prev_word;
|
|
|
|
gchar *partial_word;
|
2002-02-16 17:53:58 +00:00
|
|
|
int partial_len;
|
2001-05-25 21:00:07 +00:00
|
|
|
GList *elements;
|
|
|
|
GSList *pads;
|
|
|
|
int num_pads;
|
|
|
|
GSList *args;
|
|
|
|
gchar *word;
|
|
|
|
GSList *words = NULL;
|
|
|
|
|
2002-02-16 17:53:58 +00:00
|
|
|
struct stat stat_buf;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-08-19 08:11:58 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (argc < 4) {
|
|
|
|
fprintf (stderr, "gst-complete called with invalid arguments\n");
|
|
|
|
exit (1);
|
2002-09-20 03:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_word = argv[3];
|
|
|
|
partial_word = argv[2];
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
partial_len = strlen (partial_word);
|
2002-02-16 17:53:58 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
/***** Loading the completion information from the registry *****/
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (stat (GST_CACHE_DIR "/compreg.xml", &stat_buf) == 0) {
|
|
|
|
doc = xmlParseFile (GST_CACHE_DIR "/compreg.xml");
|
2002-02-16 17:53:58 +00:00
|
|
|
} else {
|
|
|
|
exit (1);
|
|
|
|
}
|
2001-05-25 21:00:07 +00:00
|
|
|
rootnode = doc->xmlRootNode;
|
|
|
|
|
|
|
|
elementnode = rootnode->xmlChildrenNode;
|
|
|
|
while (elementnode) {
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!strcmp (elementnode->name, "element")) {
|
|
|
|
element = g_new0 (comp_element, 1);
|
2001-05-25 21:00:07 +00:00
|
|
|
propnode = elementnode->xmlChildrenNode;
|
|
|
|
while (propnode) {
|
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
if (!strcmp (propnode->name, "name")) {
|
|
|
|
element->name = xmlNodeGetContent (propnode);
|
2001-12-14 20:56:51 +00:00
|
|
|
/* fprintf(stderr,element->name); */
|
2004-03-15 19:27:17 +00:00
|
|
|
} else if (!strcmp (propnode->name, "srcpad")) {
|
|
|
|
element->srcpads =
|
|
|
|
g_slist_prepend (element->srcpads, xmlNodeGetContent (propnode));
|
2001-12-14 20:56:51 +00:00
|
|
|
/* fprintf(stderr,"."); */
|
2004-03-15 19:27:17 +00:00
|
|
|
} 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));
|
2001-12-14 20:56:51 +00:00
|
|
|
/* fprintf(stderr,"."); */
|
2004-03-15 19:27:17 +00:00
|
|
|
} 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;
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
element_list = g_list_prepend (element_list, element);
|
|
|
|
element_names = g_slist_prepend (element_names, element->name);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
elementnode = elementnode->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***** Completion *****/
|
|
|
|
|
|
|
|
/* The bulk of the work is in deciding exactly which words are an option. */
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* if we're right at the beginning, with -launch in the first word */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (strstr (prev_word, "-launch")) {
|
2001-12-14 20:56:51 +00:00
|
|
|
/* print out only elements with no sink pad or padtemplate */
|
2001-05-25 21:00:07 +00:00
|
|
|
elements = element_list;
|
|
|
|
while (elements) {
|
2004-03-13 15:27:01 +00:00
|
|
|
element = (comp_element *) (elements->data);
|
2001-05-25 21:00:07 +00:00
|
|
|
if (!element->sinkpads && !element->sinkpadtemplates)
|
2004-03-15 19:27:17 +00:00
|
|
|
words = g_slist_prepend (words, element->name);
|
2004-03-13 15:27:01 +00:00
|
|
|
elements = g_list_next (elements);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* if the previous word is a connection */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (strchr (prev_word, '!')) {
|
2001-12-14 20:56:51 +00:00
|
|
|
/* print out oly elements with a sink pad or template */
|
2001-05-25 21:00:07 +00:00
|
|
|
elements = element_list;
|
|
|
|
while (elements) {
|
2004-03-13 15:27:01 +00:00
|
|
|
element = (comp_element *) (elements->data);
|
2001-05-25 21:00:07 +00:00
|
|
|
if (element->sinkpads || element->sinkpadtemplates)
|
2004-03-15 19:27:17 +00:00
|
|
|
words = g_slist_prepend (words, element->name);
|
2001-05-25 21:00:07 +00:00
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* if the partial word is an argument, and it's an enum */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (strchr (prev_word, '=')) {
|
|
|
|
fprintf (stderr, "it's an arg, but dunno what element yet\n");
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
/* if the previous word is an element, we need to list both pads and arguments */
|
|
|
|
if ((elements =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_list_find_custom (element_list, prev_word,
|
|
|
|
(GCompareFunc) match_element))) {
|
2001-05-25 21:00:07 +00:00
|
|
|
element = elements->data;
|
2001-12-14 20:56:51 +00:00
|
|
|
/* zero the numpads list so we can count them */
|
2001-05-25 21:00:07 +00:00
|
|
|
num_pads = 0;
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* pads */
|
2001-05-25 21:00:07 +00:00
|
|
|
pads = element->srcpads;
|
|
|
|
while (pads) {
|
|
|
|
num_pads++;
|
2004-03-13 15:27:01 +00:00
|
|
|
words =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_slist_prepend (words, g_strdup_printf ("%s!",
|
|
|
|
(gchar *) (pads->data)));
|
2001-05-25 21:00:07 +00:00
|
|
|
pads = g_slist_next (pads);
|
|
|
|
}
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* padtemplates */
|
2001-05-25 21:00:07 +00:00
|
|
|
pads = element->srcpadtemplates;
|
|
|
|
while (pads) {
|
|
|
|
num_pads++;
|
2004-03-13 15:27:01 +00:00
|
|
|
word = g_strdup_printf ("%s!", (gchar *) (pads->data));
|
|
|
|
if (!g_slist_find_custom (words, word, (GCompareFunc) strcmp))
|
2004-03-15 19:27:17 +00:00
|
|
|
words = g_slist_prepend (words, word);
|
2001-05-25 21:00:07 +00:00
|
|
|
pads = g_slist_next (pads);
|
|
|
|
}
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* if there is only one pad, add '!' to the list of completions */
|
2001-05-25 21:00:07 +00:00
|
|
|
if (num_pads == 1) {
|
|
|
|
words = g_slist_prepend (words, "!");
|
|
|
|
}
|
|
|
|
|
2001-12-14 20:56:51 +00:00
|
|
|
/* arguments */
|
2001-05-25 21:00:07 +00:00
|
|
|
args = element->arguments;
|
|
|
|
while (args) {
|
2004-03-13 15:27:01 +00:00
|
|
|
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));
|
2001-05-25 21:00:07 +00:00
|
|
|
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;
|
|
|
|
}
|