[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Antiright-devel] antiright/gtkshell Makefile gtkshell.h guidl.y ...
From: |
Jeffrey Bedard |
Subject: |
[Antiright-devel] antiright/gtkshell Makefile gtkshell.h guidl.y ... |
Date: |
Fri, 13 Apr 2007 22:48:26 +0000 |
CVSROOT: /sources/antiright
Module name: antiright
Changes by: Jeffrey Bedard <jefbed> 07/04/13 22:48:25
Modified files:
gtkshell : Makefile gtkshell.h guidl.y guidl_dialog.c
guidl_util.c guidl_util.h options.c
Log message:
Use dictionaries for keyword to option mapping in GUIDL.
Use a common structure for parser data.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/Makefile?cvsroot=antiright&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/gtkshell.h?cvsroot=antiright&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/guidl.y?cvsroot=antiright&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/guidl_dialog.c?cvsroot=antiright&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/guidl_util.c?cvsroot=antiright&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/guidl_util.h?cvsroot=antiright&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/options.c?cvsroot=antiright&r1=1.13&r2=1.14
Patches:
Index: Makefile
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/Makefile,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Makefile 13 Apr 2007 03:58:59 -0000 1.22
+++ Makefile 13 Apr 2007 22:48:25 -0000 1.23
@@ -37,7 +37,8 @@
updated_options.o add_options.o option_options.o dialog_options.o\
file_dialog.o row.o containers.o geometry.o font.o dragdrop.o\
image_button.o terminal.o terminal_options.o menu.o updated.o\
- guidl_util.o about_dialog.o init.o guidl_dialog.o
+ guidl_util.o about_dialog.o init.o guidl_dialog.o guidl_dictionary.o\
+ guidl_options.o
program=main.o
Index: gtkshell.h
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/gtkshell.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- gtkshell.h 13 Apr 2007 03:59:00 -0000 1.32
+++ gtkshell.h 13 Apr 2007 22:48:25 -0000 1.33
@@ -91,11 +91,13 @@
#include "image_button.h"
#include "terminal_options.h"
#include "terminal.h"
+#include "guidl_dictionary.h"
#include "guidl_util.h"
#include "about_dialog.h"
#include "menu.h"
#include "init.h"
#include "guidl_dialog.h"
+#include "guidl_options.h"
GtkWidget *
gsh_create_main_window();
Index: guidl.y
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/guidl.y,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- guidl.y 13 Apr 2007 03:59:00 -0000 1.13
+++ guidl.y 13 Apr 2007 22:48:25 -0000 1.14
@@ -47,8 +47,7 @@
return 1;
}
-extern char **gsh_parsed_argv;
-extern int gsh_parsed_argc;
+struct GDLEnvironment * gsh_guidl_env;
%}
%union
@@ -98,17 +97,21 @@
option:
OPTION STRING
{
- gsh_guidl_string_option($2);
+ gsh_guidl_option($2, NULL);
}
|
OPTION STRING STRING
{
- gsh_guidl_string_arg_option($2, $3);
+ gsh_guidl_option($2, $3);
}
|
OPTION STRING NUM
{
- gsh_guidl_string_num_arg_option($2, $3);
+ gchar * num_string;
+ ar_asprintf(&num_string, "%d", $3);
+ g_free($3);
+ gsh_guidl_option($2, num_string);
+ /* num_string is freed in above call. */
}
;
Index: guidl_dialog.c
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/guidl_dialog.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- guidl_dialog.c 13 Apr 2007 15:06:17 -0000 1.2
+++ guidl_dialog.c 13 Apr 2007 22:48:25 -0000 1.3
@@ -22,52 +22,40 @@
#include "gtkshell.h"
-static void
-add_dialog(gchar * option_string, gchar * argument)
-{
- ARPASSERT(option_string);
- gsh_guidl_add(option_string, argument);
- g_free(option_string);
-}
+extern struct GDLEnvironment * gsh_guidl_env;
-GTree * gsh_guidl_dialog_dictionary=NULL;
+#define DEF(a, b) GSH_GUIDL_DEFINE(gsh_guidl_env->dictionaries.dialogs, a, b)
static void
setup_dictionary()
{
- gsh_guidl_dialog_dictionary=g_tree_new(strcmp);
- g_tree_insert(gsh_guidl_dialog_dictionary, "file", "-df");
- g_tree_insert(gsh_guidl_dialog_dictionary, "font", "-dF");
- g_tree_insert(gsh_guidl_dialog_dictionary, "about", "-da");
- g_tree_insert(gsh_guidl_dialog_dictionary, "folder", "-dd");
- g_tree_insert(gsh_guidl_dialog_dictionary,
- "create folder", "-dD");
- g_tree_insert(gsh_guidl_dialog_dictionary, "save", "-ds");
- g_tree_insert(gsh_guidl_dialog_dictionary, "color", "-dc");
- g_tree_insert(gsh_guidl_dialog_dictionary, "info", "-di");
- g_tree_insert(gsh_guidl_dialog_dictionary, "warning", "-dw");
- g_tree_insert(gsh_guidl_dialog_dictionary, "error", "-de");
+ gsh_guidl_env->dictionaries.dialogs=g_tree_new(strcmp);
+ DEF("file", "-df");
+ DEF("font", "-dF");
+ DEF("about", "-da");
+ DEF("folder", "-dd");
+ DEF( "create folder", "-dD");
+ DEF("save", "-ds");
+ DEF("color", "-dc");
+ DEF("info", "-di");
+ DEF("warning", "-dw");
+ DEF("error", "-de");
}
-/* The returned memory must be freed. */
-static gchar *
-lookup_dialog_flag(gchar * string)
+void
+gsh_guidl_dialog(gchar * dialog_type, gchar * argument)
{
- if(gsh_guidl_dialog_dictionary == NULL)
- setup_dictionary();
+ GSH_GUIDL_CHECK_DICTIONARY(dialogs);
+ {
+ gpointer result;
+ result=gsh_guidl_lookup(gsh_guidl_env->dictionaries.dialogs,
+ (gpointer)dialog_type);
+ if(result != NULL)
{
- gchar * result;
- result = g_tree_lookup(gsh_guidl_dialog_dictionary, string);
- if(result == NULL)
- ARWARN("dialog keyword not found");
- return result;
+ gsh_guidl_add(result, argument);
+ g_free(result);
+ }
}
-}
-
-void
-gsh_guidl_dialog(gchar * dialog_type, gchar * argument)
-{
- add_dialog(lookup_dialog_flag(dialog_type), argument);
}
Index: guidl_util.c
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/guidl_util.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- guidl_util.c 13 Apr 2007 03:59:00 -0000 1.6
+++ guidl_util.c 13 Apr 2007 22:48:25 -0000 1.7
@@ -22,156 +22,93 @@
#include "gtkshell.h"
-char **gsh_parsed_argv;
-int gsh_parsed_argc=0;
+struct GDLEnvironment * gsh_guidl_env=NULL;
void
-gsh_add_system_button(gchar * command)
+gsh_setup_GDLEnvironment(struct GDLEnvironment * env)
{
- /* Adds a button containing the output of
- * a command specified by STRING. */
- gchar * output;
-
- output=antiright_pipe_read(command);
- g_free(command);
- gsh_append_arg(output);
- g_free(output);
+ ar_setup_ARArguments(&(env->args));
}
void
-gsh_add_system_label(gchar * command)
+gsh_setup_GDLDictionaries(struct GDLDictionaries * dictionaries)
{
- /* Adds a label containing the output of
- * a command specified by STRING. */
-
- gchar * output;
-
- output=antiright_pipe_read(command);
- g_free(command);
- gsh_guidl_add("-al", output);
- /* OUTPUT is freed in gsh_guidl_add(). */
+ dictionaries->widgets=NULL;
+ dictionaries->options=NULL;
+ dictionaries->dialogs=NULL;
}
-void
-gsh_append_arg(gchar * arg)
+struct GDLDictionaries *
+gsh_new_GDLDictionaries()
{
- gsh_parsed_argc++;
- gsh_parsed_argv=realloc(gsh_parsed_argv, sizeof(char*)*gsh_parsed_argc);
- gsh_parsed_argv[gsh_parsed_argc-1]=strdup(arg);
+ struct GDLDictionaries * dictionaries;
+
+ dictionaries=g_malloc(sizeof(struct GDLDictionaries));
+ gsh_setup_GDLDictionaries(dictionaries);
+
+ return dictionaries;
}
-void
-gsh_free_parse_memory()
+struct GDLEnvironment *
+gsh_new_GDLEnvironment()
{
- for(;gsh_parsed_argc>0; gsh_parsed_argc--)
- free(gsh_parsed_argv[gsh_parsed_argc-1]);
- free(gsh_parsed_argv);
+ struct GDLEnvironment * env;
+ env=(struct GDLEnvironment *)g_malloc(sizeof(struct GDLEnvironment));
+ gsh_setup_GDLEnvironment(env);
+ return env;
}
static void
-add_option_to_argument_list(gchar option)
+check_gsh_guidl_env()
{
- char * option_string;
-
- ar_asprintf(&option_string, "-o%c", option);
- gsh_append_arg(option_string);
- g_free(option_string);
+ if(gsh_guidl_env == NULL)
+ gsh_guidl_env=gsh_new_GDLEnvironment();
}
-void
-gsh_guidl_string_option(gchar * string)
-{
- gchar option;
-
- if(!strcmp(string, "undecorated"))
- option='n';
- else if(!strcmp(string, "frame_labels"))
- option='f';
- else if(!strcmp(string, "exit_on_activate"))
- option='e';
- else if(!strcmp(string, "horizontal_labels"))
- option='h';
- else if(!strcmp(string, "scrolled"))
- option='s';
- else if(!strcmp(string, "no label fill"))
- option='l';
- else if(!strcmp(string, "label fill")) /* default fill type */
- option='L';
- else
- {
- /* Ensure that STRING is freed
- * in case of this condition. */
- g_free(string);
- ARWARN("invalid option");
- return; /* No match, so complain but do nothing. */
- }
- g_free(string);
- add_option_to_argument_list(option);
+void
+gsh_delete_GDLEnvironment(struct GDLEnvironment * env)
+{
+ ARPASSERT(env);
+ gsh_delete_GDLDictionaries_contents(&(env->dictionaries));
+ ar_delete_ARArguments_contents(&(env->args));
}
void
-gsh_guidl_string_arg_option(gchar * option, gchar * arg)
+gsh_add_system_button(gchar * command)
{
- gchar * option_switch;
- gchar * option_string;
-
- option_switch=NULL;
-
- if(!strcmp(option, "geometry"))
- option_switch=g_strdup("g");
- else if(!strcmp(option, "terminal font"))
- option_switch=g_strdup("tf");
- else if(!strcmp(option, "title"))
- option_switch=g_strdup("T");
- else
- {
- ARWARN("Invalid option.");
- return;
- }
-
-
- ar_asprintf(&option_string, "-o%s", option_switch);
- g_free(option_switch);
- gsh_guidl_add(option_string, arg);
- free(option_string);
+ /* Adds a button containing the output of
+ * a command specified by STRING. */
+ gchar * output;
- g_free(option);
+ output=antiright_pipe_read(command);
+ g_free(command);
+ gsh_append_arg(output);
+ g_free(output);
}
void
-gsh_guidl_string_num_arg_option(gchar * option, gint num)
+gsh_add_system_label(gchar * command)
{
- gchar * option_switch;
- gchar * option_string;
-
- option_switch=NULL;
+ /* Adds a label containing the output of
+ * a command specified by STRING. */
- if(!strcmp(option, "update_frequency"))
- option_switch = g_strdup("u");
- else if(!strcmp(option, "rows"))
- option_switch = g_strdup("r");
- else if(!strcmp(option, "terminal height"))
- option_switch = g_strdup("th");
- else if(!strcmp(option, "terminal width"))
- option_switch = g_strdup("tw");
- else
- {
- ARWARN("invalid option");
- return;
- }
+ gchar * output;
- ar_asprintf(&option_string, "-o%s", option_switch);
- g_free(option_switch);
- gsh_append_arg(option_string);
- free(option_string);
- asprintf(&option_string, "%d", num);
- gsh_append_arg(option_string);
- free(option_string);
+ output=antiright_pipe_read(command);
+ g_free(command);
+ gsh_guidl_add("-al", output);
+ /* OUTPUT is freed in gsh_guidl_add(). */
+}
- g_free(option);
+void
+gsh_append_arg(gchar * arg)
+{
+ check_gsh_guidl_env();
+ gsh_guidl_env->args.add(&(gsh_guidl_env->args), arg);
}
+
void
gsh_guidl_add(const char * switches, gchar * argument)
{
Index: guidl_util.h
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/guidl_util.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- guidl_util.h 13 Apr 2007 03:00:07 -0000 1.3
+++ guidl_util.h 13 Apr 2007 22:48:25 -0000 1.4
@@ -23,6 +23,26 @@
#ifndef GSH_GUIDL_UTIL_H
#define GSH_GUIDL_UTIL_H
+
+struct GDLEnvironment
+{
+ struct GDLDictionaries dictionaries;
+ struct ARArguments args;
+};
+
+void
+gsh_delete_GDLEnvironment(struct GDLEnvironment * env);
+
+
+struct GDLEnvironment *
+gsh_new_GDLEnvironment();
+
+void
+gsh_setup_GDLEnvironment(struct GDLEnvironment * env);
+
+void
+gsh_setup_GDLDictionaries(struct GDLDictionaries * dictionaries);
+
void
gsh_add_system_button(gchar * command);
Index: options.c
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/options.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- options.c 13 Apr 2007 15:06:17 -0000 1.13
+++ options.c 13 Apr 2007 22:48:25 -0000 1.14
@@ -23,8 +23,7 @@
#include "gtkshell.h"
extern FILE *yyin, *yyout;
-extern int gsh_parsed_argc;
-extern char ** gsh_parsed_argv;
+extern struct GDLEnvironment * gsh_guidl_env;
#ifdef _GNU_SOURCE
inline
@@ -36,7 +35,19 @@
g_assert((*counter) <= argc);
}
-extern GSList * gsh_guidl_dialog_dictionary;
+static void
+common_guidl_handler(struct GSH * gsh)
+{
+ gsh_append_arg((char*)"guidl");
+ yyparse();
+ {
+ struct ARArguments * args = &(gsh_guidl_env->args);
+ gsh_parse_arguments(gsh, args->argc, args->argv);
+ }
+ gsh_delete_GDLEnvironment(gsh_guidl_env);
+ gsh_guidl_env=NULL;
+ /* Free parse memory in main. */
+}
void
gsh_handle_switch_arguments(struct GSH * gsh, int argc,
@@ -54,23 +65,13 @@
case 'f':
gsh_count(argc, counter);
yyin=fopen(argv[*counter], "r");
- gsh_append_arg((char*)"guidl");
- yyparse();
- gsh_parse_arguments(gsh, gsh_parsed_argc, gsh_parsed_argv);
- if(gsh_guidl_dialog_dictionary != NULL)
- g_tree_destroy(gsh_guidl_dialog_dictionary);
- /* Free parse memory in main. */
+ common_guidl_handler(gsh);
break;
case 'o':
gsh_handle_option_arguments(gsh, argc, argv, counter);
break;
case 'p': /* Handle piped in GUIDL input. */
- gsh_append_arg((char*)"guidl");
- yyparse();
- gsh_parse_arguments(gsh, gsh_parsed_argc, gsh_parsed_argv);
- if(gsh_guidl_dialog_dictionary != NULL)
- g_tree_destroy(gsh_guidl_dialog_dictionary);
- /* Free parse memory in main. */
+ common_guidl_handler(gsh);
break;
default:
g_warning("%s: %s undefined\n", argv[0], argv[(*counter)]);