diff options
author | Oliver Maruhn <oliver@maruhn.com> | 2000-02-02 01:06:36 +0000 |
---|---|---|
committer | Oliver Maruhn <oliverm@src.gnome.org> | 2000-02-02 01:06:36 +0000 |
commit | 786a39e6483b68cf2c2268f0ecfd6c18aa342497 (patch) | |
tree | 3d8407c7bf6b5e982307ab27dbd15544eed92eb7 | |
parent | 251400b3cc6749db1edcdae0b7faed465069ade5 (diff) |
Macros are defined via regular expressions instead of prefixes [this nice
2000-02-02 Oliver Maruhn <oliver@maruhn.com>
* src/macro.c and other places: Macros are defined via regular
expressions instead of prefixes [this nice idea has been suggested
by Alejandro Forero Cuervo <bachue@bachue.com>]
-rw-r--r-- | mini-commander/ChangeLog | 4 | ||||
-rw-r--r-- | mini-commander/NEWS | 6 | ||||
-rw-r--r-- | mini-commander/TODO | 8 | ||||
-rw-r--r-- | mini-commander/src/command_line.c | 16 | ||||
-rw-r--r-- | mini-commander/src/history.c | 20 | ||||
-rw-r--r-- | mini-commander/src/macro.c | 123 | ||||
-rw-r--r-- | mini-commander/src/preferences.c | 188 | ||||
-rw-r--r-- | mini-commander/src/preferences.h | 15 | ||||
-rw-r--r-- | mini-commander/src/terminal.c | 12 |
9 files changed, 223 insertions, 169 deletions
diff --git a/mini-commander/ChangeLog b/mini-commander/ChangeLog index 208def876..f378001fd 100644 --- a/mini-commander/ChangeLog +++ b/mini-commander/ChangeLog @@ -1,5 +1,9 @@ 2000-02-02 Oliver Maruhn <oliver@maruhn.com> + * src/macro.c and other places: Macros are defined via regular + expressions instead of prefixes [this nice idea has been suggested + by Alejandro Forero Cuervo <bachue@bachue.com>] + * src/history.c (delete_history_entry): added (append_history_entry): now really no dupes are stored in the diff --git a/mini-commander/NEWS b/mini-commander/NEWS index 2a9b483e3..e40389a5c 100644 --- a/mini-commander/NEWS +++ b/mini-commander/NEWS @@ -1,4 +1,8 @@ - * Now really no dupes are stored in the command history. + * Macros are defined via regular expressions instead of + prefixes. This nice idea has been suggested by Alejandro + Forero Cuervo. + + * Really no dupes are stored in the command history. * The size and layout of the applet will be modified automatically if the panel size is changed. diff --git a/mini-commander/TODO b/mini-commander/TODO index ce4a1aa5f..738a30afe 100644 --- a/mini-commander/TODO +++ b/mini-commander/TODO @@ -1,9 +1,5 @@ TODO: -* I wish I had to set up the `macros' using regular expressions - instead of just prefixes. It would be *far* more flexible [by - Alejandro Forero Cuervo <bachue@bachue.com>] - * use history for command completion, too * use a real shell (like bash) optionally as backend @@ -52,6 +48,10 @@ TODO: DONE: +* I wish I had to set up the `macros' using regular expressions + instead of just prefixes. It would be *far* more flexible [by + Alejandro Forero Cuervo <bachue@bachue.com>] + * make handle box optional * working command completion when using a prefix diff --git a/mini-commander/src/command_line.c b/mini-commander/src/command_line.c index 8c0941142..3ce5ab73e 100644 --- a/mini-commander/src/command_line.c +++ b/mini-commander/src/command_line.c @@ -43,7 +43,7 @@ static gchar* history_auto_complete(GtkWidget *widget, GdkEventKey *event); GtkWidget *entry_command = NULL; -static int history_position = HISTORY_DEPTH; +static int history_position = LENGTH_HISTORY_LIST; static char browsed_filename[300] = ""; static gint @@ -74,7 +74,7 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) || key == GDK_Pointer_Up) { /* up key pressed */ - if(history_position == HISTORY_DEPTH) + if(history_position == LENGTH_HISTORY_LIST) { /* store current command line */ strcpy(current_command, (char *) gtk_entry_get_text(GTK_ENTRY(widget))); @@ -94,11 +94,11 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) || key == GDK_Pointer_Down) { /* down key pressed */ - if(history_position < HISTORY_DEPTH - 1) + if(history_position < LENGTH_HISTORY_LIST - 1) { gtk_entry_set_text(GTK_ENTRY(widget), (gchar *) get_history_entry(++history_position)); } - else if(history_position == HISTORY_DEPTH - 1) + else if(history_position == LENGTH_HISTORY_LIST - 1) { gtk_entry_set_text(GTK_ENTRY(widget), (gchar *) current_command); ++history_position; @@ -121,7 +121,7 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) exec_command(command); append_history_entry((char *) command); - history_position = HISTORY_DEPTH; + history_position = LENGTH_HISTORY_LIST; free(command); strcpy(current_command, ""); @@ -260,7 +260,7 @@ show_history_signal(GtkWidget *widget, gpointer data) int i, j; /* count commands stored in history list */ - for(i = 0, j = 0; i < HISTORY_DEPTH; i++) + for(i = 0, j = 0; i < LENGTH_HISTORY_LIST; i++) if(exists_history_entry(i)) j++; @@ -332,7 +332,7 @@ show_history_signal(GtkWidget *widget, gpointer data) /* add history entries to list */ - for(i = 0; i < HISTORY_DEPTH; i++) + for(i = 0; i < LENGTH_HISTORY_LIST; i++) { if(exists_history_entry(i)) { @@ -510,7 +510,7 @@ history_auto_complete(GtkWidget *widget, GdkEventKey *event) int i; sprintf(current_command, "%s%s", gtk_entry_get_text(GTK_ENTRY(widget)), event->string); - for(i = HISTORY_DEPTH - 1; i >= 0; i--) + for(i = LENGTH_HISTORY_LIST - 1; i >= 0; i--) { if(!exists_history_entry(i)) break; diff --git a/mini-commander/src/history.c b/mini-commander/src/history.c index 0638b1d09..0e29c5c30 100644 --- a/mini-commander/src/history.c +++ b/mini-commander/src/history.c @@ -19,6 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* Actually the command history is a simple list. So, I guess this + here could also be done with the list routines of glib. */ + #include <string.h> #include <config.h> #include <gnome.h> @@ -27,7 +30,7 @@ #include "preferences.h" #include "message.h" -static char *history_command[HISTORY_DEPTH]; +static char *history_command[LENGTH_HISTORY_LIST]; static void delete_history_entry(int element_number); @@ -58,14 +61,11 @@ append_history_entry(char * entry) int pos; /* remove older dupes */ - for(pos = 0; pos <= HISTORY_DEPTH - 1; pos++) + for(pos = 0; pos <= LENGTH_HISTORY_LIST - 1; pos++) { if(exists_history_entry(pos) && strcmp(entry, history_command[pos]) == 0) - { - /* dupe found */ - printf("%d: %s\n", pos, history_command[pos]); - delete_history_entry(pos); - } + /* dupe found */ + delete_history_entry(pos); } /* delete oldest entry */ @@ -73,15 +73,15 @@ append_history_entry(char * entry) free(history_command[0]); /* move entries */ - for(pos = 0; pos < HISTORY_DEPTH - 1; pos++) + for(pos = 0; pos < LENGTH_HISTORY_LIST - 1; pos++) { history_command[pos] = history_command[pos+1]; /* printf("%s\n", history_command[pos]); */ } /* append entry */ - history_command[HISTORY_DEPTH - 1] = (char *)malloc(sizeof(char) * (strlen(entry) + 1)); - strcpy(history_command[HISTORY_DEPTH - 1], entry); + history_command[LENGTH_HISTORY_LIST - 1] = (char *)malloc(sizeof(char) * (strlen(entry) + 1)); + strcpy(history_command[LENGTH_HISTORY_LIST - 1], entry); } void diff --git a/mini-commander/src/macro.c b/mini-commander/src/macro.c index 53b95c363..c9e42a61d 100644 --- a/mini-commander/src/macro.c +++ b/mini-commander/src/macro.c @@ -20,6 +20,7 @@ */ #include <string.h> +#include <regex.h> #include <config.h> #include <gnome.h> @@ -40,17 +41,17 @@ prefix_number(char *command) int found_prefix_no = -1; unsigned int found_prefix_len = 0; - for(i=0; i<=MAX_PREFIXES-1; i++) - if (prop.prefix[i] != (char *) NULL && - strlen(prop.prefix[i]) > found_prefix_len && - strncmp(command, prop.prefix[i], strlen(prop.prefix[i])) == 0 && - (strstr(prop.command[i], "$1") != NULL || strlen(prop.prefix[i]) == strlen(command))) + for(i=0; i<=MAX_NUM_MACROS-1; i++) + if (prop.macro_pattern[i] != NULL && + strlen(prop.macro_pattern[i]) > found_prefix_len && + strncmp(command, prop.macro_pattern[i], strlen(prop.macro_pattern[i])) == 0 && + (strstr(prop.macro_command[i], "$1") != NULL || strlen(prop.macro_pattern[i]) == strlen(command))) { /* found a matching prefix; if macro does not contain "$1" then the prefix has to to have the same lenght as the command */ found_prefix_no = i; found_prefix_len = - strlen(prop.prefix[i]); } + strlen(prop.macro_pattern[i]); } return(found_prefix_no); } @@ -61,7 +62,7 @@ prefix_length(char *command) int pn = prefix_number(command); if(pn > -1) - return strlen(prop.prefix[pn]); + return strlen(prop.macro_pattern[pn]); /* no prefix found */ return(0); @@ -86,7 +87,7 @@ get_prefix(char *command) int pn = prefix_number(command); if(pn > -1) - return((char *) prop.prefix[pn]); + return((char *) prop.macro_pattern[pn]); /* no prefix found */ return((char *) NULL); @@ -96,48 +97,70 @@ get_prefix(char *command) void expand_command(char *command) { - /* FIXME: code cleanup needed */ - int pn = prefix_number(command); - int prefix_len = prefix_length_Including_whithespaces(command); - char *prefix = (pn > -1) ? prop.prefix[pn] : (char *) NULL; - char *macro = (pn > -1) ? prop.command[pn] : (char *) NULL; - char command_exec[1000]; - char buffer[1000]; - char *subst_ptr; - int j; - - if(prefix == NULL) - return; - - /* there is a prefix */ - strcpy(buffer, macro); - if ((subst_ptr = strstr(buffer, "$1")) != (char *) NULL) - { - /* "$1" found */ - *subst_ptr = '\000'; - strcpy(command_exec, buffer); - strcat(command_exec, command + prefix_len); - strcat(command_exec, subst_ptr + 2); - } - else - { - /* no $1 in this macro */ - strcpy(command_exec, macro); - } - - for(j=0; j<10; j++) - { - /* substitute up to ten $1's */ - strcpy(buffer, command_exec); - if ((subst_ptr = strstr(buffer, "$1")) != (char *) NULL) - { - /* "$1" found */ - *subst_ptr = '\000'; - strcpy(command_exec, buffer); - strcat(command_exec, command + prefix_len); - strcat(command_exec, subst_ptr + 2); - } - } + char command_exec[1000] = ""; + char placeholder[100]; + int inside_placeholder; + int parameter_number; + char *macro; + char *char_p; + int i, j; + regmatch_t regex_matches[MAX_NUM_MACRO_PARAMETERS]; + + for(i = 0; i < MAX_NUM_MACROS - 1; ++i) + if(prop.macro_regex[i] != NULL && + regexec(prop.macro_regex[i], command, MAX_NUM_MACRO_PARAMETERS, regex_matches, 0) != REG_NOMATCH) + { + /* found a matching macro regex pattern; */ + /* fprintf(stderr, "%u: %s\n", i, prop.macro_pattern[i]); */ + + macro = prop.macro_command[i]; + + inside_placeholder = 0; + for(char_p = macro; *char_p != '\0'; ++char_p) + { + if(inside_placeholder == 0 + && *char_p == '\\' + && *(char_p + 1) >= '0' + && *(char_p + 1) <= '9') + { + strcpy(placeholder, ""); + inside_placeholder = 1; + /* fprintf(stderr, ">%c\n", *char_p); */ + } + else if(inside_placeholder + && (*(char_p + 1) < '0' + || *(char_p + 1) > '9')) + { + inside_placeholder = 2; + /* fprintf(stderr, "<%c\n", *char_p); */ + } +/* else */ +/* fprintf(stderr, "|%c\n", *char_p); */ + + if(inside_placeholder == 0) + strncat(command_exec, char_p, 1); + else + strncat(placeholder, char_p, 1); + + if(inside_placeholder == 2) + { + parameter_number = atoi(placeholder + 1); + + if(parameter_number <= MAX_NUM_MACRO_PARAMETERS + && regex_matches[parameter_number].rm_eo > 0) + strncat(command_exec, + command + regex_matches[parameter_number].rm_so, + regex_matches[parameter_number].rm_eo + - regex_matches[parameter_number].rm_so); + + inside_placeholder = 0; + /* fprintf(stderr, "placeholder: %s, %d\n", placeholder, parameter_number); */ + } + + } + break; + } + fprintf(stderr, "command_exec: %s\n", command_exec); strcpy(command, command_exec); } diff --git a/mini-commander/src/preferences.c b/mini-commander/src/preferences.c index 19eb3a1ff..f2cc9aa24 100644 --- a/mini-commander/src/preferences.c +++ b/mini-commander/src/preferences.c @@ -187,20 +187,25 @@ properties_box_apply_signal(GnomePropertyBox *property_box_widget, gint page, gp } /* macros */ - for(i=0; i<=MAX_PREFIXES-1; i++) + for(i = 0; i <= MAX_NUM_MACROS - 1; ++i) { - if (prop_tmp.prefix[i] != (char *) NULL) + if(prop_tmp.macro_pattern[i] != (char *)NULL) { - free(prop.prefix[i]); - prop.prefix[i] = prop_tmp.prefix[i]; - prop_tmp.prefix[i] = (char *) NULL; - } - - if (prop_tmp.command[i] != (char *) NULL) + free(prop.macro_pattern[i]); + prop.macro_pattern[i] = prop_tmp.macro_pattern[i]; + prop_tmp.macro_pattern[i] = (char *)NULL; + + if(prop.macro_regex[i] != NULL) + free(prop.macro_regex[i]); + prop.macro_regex[i] = malloc(sizeof(regex_t)); + /* currently we don't care about syntax errors in regex patterns */ + regcomp(prop.macro_regex[i], prop.macro_pattern[i], REG_EXTENDED); + } + if(prop_tmp.macro_command[i] != (char *)NULL) { - free(prop.command[i]); - prop.command[i] = prop_tmp.command[i]; - prop_tmp.command[i] = (char *) NULL; + free(prop.macro_command[i]); + prop.macro_command[i] = prop_tmp.macro_command[i]; + prop_tmp.macro_command[i] = (char *)NULL; } } @@ -214,12 +219,15 @@ properties_box_apply_signal(GnomePropertyBox *property_box_widget, gint page, gp reset_temporary_prefs(); /* Why is this not done automatically??? */ - /* Ok, looks like this is done right now. */ - /* save_session(); */ + save_session(); + return; - property_box_widget = NULL; - page = 0; - data = NULL; + + /* + property_box_widget = NULL; + page = 0; + data = NULL; + */ } void @@ -227,8 +235,8 @@ load_session(void) { int i; char section[MAX_COMMAND_LENGTH + 100]; - char default_prefix[MAX_PREFIX_LENGTH]; - char default_command[MAX_COMMAND_LENGTH]; + char default_macro_pattern[MAX_MACRO_PATTERN_LENGTH]; + char default_macro_command[MAX_COMMAND_LENGTH]; /* read properties */ /* gnome_config_push_prefix(APPLET_WIDGET(applet)->globcfgpath); */ @@ -258,100 +266,112 @@ load_session(void) prop.cmd_line_color_bg_b = gnome_config_get_int("mini_commander/cmd_line_color_bg_b=0"); /* macros */ - for(i=0; i<=MAX_PREFIXES-1; i++) + for(i=0; i<=MAX_NUM_MACROS-1; i++) { - switch (i+1) + switch (i + 1) /* set default macros */ { case 1: - strcpy(default_prefix, "http://"); - strcpy(default_command, "netscape -remote open_uRL\\(http://$1\\) || netscape http://$1"); + strcpy(default_macro_pattern, "^(http://.*)$"); + strcpy(default_macro_command, "netscape -remote openURL\\(\\1\\) || netscape \\1"); break; case 2: - strcpy(default_prefix, "ftp://"); - strcpy(default_command, "netscape -remote open_uRL\\(ftp://$1\\) || netscape ftp://$1"); + strcpy(default_macro_pattern, "^(ftp://.*)"); + strcpy(default_macro_command, "netscape -remote openURL\\(\\1\\) || netscape \\1"); break; case 3: - strcpy(default_prefix, "www."); - strcpy(default_command, "netscape -remote open_uRL\\(http://www.$1\\) || netscape http://www.$1"); + strcpy(default_macro_pattern, "^(www\\..*)$"); + strcpy(default_macro_command, "netscape -remote openURL\\(http://\\1\\) || netscape http://\\1"); break; case 4: - strcpy(default_prefix, "ftp."); - strcpy(default_command, "netscape -remote open_uRL\\(ftp.://ftp.$1\\) || netscape ftp://ftp.$1"); + strcpy(default_macro_pattern, "(ftp\\..*)"); + strcpy(default_macro_command, "netscape -remote openURL\\(ftp://\\1\\) || netscape ftp://\\1"); break; case 5: - strcpy(default_prefix, "lynx:"); - strcpy(default_command, "gnome-terminal -e \"sh -c 'lynx $1'\""); + strcpy(default_macro_pattern, "^lynx: *(.*)$"); + strcpy(default_macro_command, "gnome-terminal -e \"sh -c 'lynx \\1'\""); break; case 6: - strcpy(default_prefix, "term:"); - strcpy(default_command, "gnome-terminal -e \"sh -c '$1'\""); + strcpy(default_macro_pattern, "^term: *(.*)$"); + strcpy(default_macro_command, "gnome-terminal -e \"sh -c '\\1'\""); break; case 7: - strcpy(default_prefix, "xterm:"); - strcpy(default_command, "xterm -e sh -c '$1'"); + strcpy(default_macro_pattern, "^xterm: *(.*)$"); + strcpy(default_macro_command, "xterm -e sh -c '\\1'"); break; case 8: - strcpy(default_prefix, "nxterm:"); - strcpy(default_command, "nxterm -e sh -c '$1'"); + strcpy(default_macro_pattern, "^nxterm: *(.*)$"); + strcpy(default_macro_command, "nxterm -e sh -c '\\1'"); break; case 9: - strcpy(default_prefix, "rxvt:"); - strcpy(default_command, "rxvt -e sh -c '$1'"); + strcpy(default_macro_pattern, "^rxvt: *(.*)$"); + strcpy(default_macro_command, "rxvt -e sh -c '\\1'"); break; case 10: - strcpy(default_prefix, "less:"); - strcpy(default_command, "$1 | gless"); + strcpy(default_macro_pattern, "^less: *(.*)$"); + strcpy(default_macro_command, "\\1 | gless"); break; case 11: - strcpy(default_prefix, "av:"); - strcpy(default_command, "set altavista search by Chad Powell; gnome-moz-remote --newwin http://www.altavista.net/cgi-bin/query?pg=q\\&kl=XX\\&q=$(echo '$1'|sed -e ': p;s/+/%2B/;t p;: s;s/\\ /+/;t s;: q;s/\\\"/%22/;t q')"); + strcpy(default_macro_pattern, "^av: *(.*)$"); + strcpy(default_macro_command, "set altavista search by Chad Powell; gnome-moz-remote --newwin http://www.altavista.net/cgi-bin/query?pg=q\\&kl=XX\\&q=$(echo '\\1'|sed -e ': p;s/+/%2B/;t p;: s;s/\\ /+/;t s;: q;s/\\\"/%22/;t q')"); break; case 12: - strcpy(default_prefix, "yahoo:"); - strcpy(default_command, "set yahoo search by Chad Powell; gnome-moz-remote --newwin http://ink.yahoo.com/bin/query?p=$(echo '$1'|sed -e ': p;s/+/%2B/;t p;: s;s/\\ /+/;t s;: q;s/\\\"/%22/;t q')"); + strcpy(default_macro_pattern, "^yahoo: *(.*)$"); + strcpy(default_macro_command, "set yahoo search by Chad Powell; gnome-moz-remote --newwin http://ink.yahoo.com/bin/query?p=$(echo '\\1'|sed -e ': p;s/+/%2B/;t p;: s;s/\\ /+/;t s;: q;s/\\\"/%22/;t q')"); break; case 13: - strcpy(default_prefix, "fm:"); - strcpy(default_command, "set freshmeat search by Chad Powell; gnome-moz-remote --newwin http://core.freshmeat.net/search.php3?query=$(echo '$1'|tr \" \" +)"); + strcpy(default_macro_pattern, "^fm: *(.*)$"); + strcpy(default_macro_command, "set freshmeat search by Chad Powell; gnome-moz-remote --newwin http://core.freshmeat.net/search.php3?query=$(echo '\\1'|tr \" \" +)"); break; case 14: - strcpy(default_prefix, "dictionary:"); - strcpy(default_command, "set dictionary search by Chad Powell; gnome-moz-remote --newwin http://www.dictionary.com/cgi-bin/dict.pl?term=$1"); + strcpy(default_macro_pattern, "^dictionary: *(.*)$"); + strcpy(default_macro_command, "set dictionary search by Chad Powell; gnome-moz-remote --newwin http://www.dictionary.com/cgi-bin/dict.pl?term=\\1"); break; case 15: - strcpy(default_prefix, "t"); - strcpy(default_command, "gnome-terminal"); + strcpy(default_macro_pattern, "^t$"); + strcpy(default_macro_command, "gnome-terminal"); break; case 16: - strcpy(default_prefix, "nx"); - strcpy(default_command, "nxterm"); + strcpy(default_macro_pattern, "^nx$"); + strcpy(default_macro_command, "nxterm"); break; case 17: - strcpy(default_prefix, "n"); - strcpy(default_command, "netscape"); + strcpy(default_macro_pattern, "^n$"); + strcpy(default_macro_command, "netscape"); break; default: - strcpy(default_prefix, ""); - strcpy(default_command, ""); + strcpy(default_macro_pattern, ""); + strcpy(default_macro_command, ""); } - g_snprintf(section, sizeof(section), "mini_commander/prefix_%d=%s", i+1, default_prefix); - free(prop.prefix[i]); - prop.prefix[i] = (char *) gnome_config_get_string((gchar *) section); + g_snprintf(section, sizeof(section), "mini_commander/macro_pattern_%.2u=%s", i+1, default_macro_pattern); + free(prop.macro_pattern[i]); + prop.macro_pattern[i] = (char *)gnome_config_get_string((gchar *) section); + + g_snprintf(section, sizeof(section), "mini_commander/macro_command_%.2u=%s", i+1, default_macro_command); + free(prop.macro_command[i]); + prop.macro_command[i] = (char *)gnome_config_get_string((gchar *) section); + + if(prop.macro_pattern[i][0] != '\0') + { + prop.macro_regex[i] = malloc(sizeof(regex_t)); + /* currently we don't care about syntax errors in regex patterns */ + regcomp(prop.macro_regex[i], prop.macro_pattern[i], REG_EXTENDED); + } + else + { + prop.macro_regex[i] = NULL; + } - g_snprintf(section, sizeof(section), "mini_commander/command_%d=%s", i+1, default_command); - free(prop.command[i]); - prop.command[i] = (char *) gnome_config_get_string((gchar *) section); + prop_tmp.macro_pattern[i] = (char *)NULL; + prop_tmp.macro_command[i] = (char *)NULL; - prop_tmp.prefix[i] = (char *) NULL; - prop_tmp.command[i] = (char *) NULL; } /* history */ - for(i = 0; i < HISTORY_DEPTH; i++) + for(i = 0; i < LENGTH_HISTORY_LIST; i++) { - g_snprintf(section, sizeof(section), "mini_commander/history_%d=%s", i, ""); + g_snprintf(section, sizeof(section), "mini_commander/history_%.2u=%s", i, ""); if(strcmp("", (char *) gnome_config_get_string((gchar *) section)) != 0) append_history_entry(gnome_config_get_string((gchar *) section)); } @@ -398,22 +418,22 @@ save_session(void) gnome_config_set_int("mini_commander/cmd_line_color_bg_b", prop.cmd_line_color_bg_b); /* macros */ - for(i=0; i<=MAX_PREFIXES-1; i++) + for(i=0; i<=MAX_NUM_MACROS-1; i++) { - g_snprintf(section, sizeof(section), "mini_commander/prefix_%d", i+1); - gnome_config_set_string((gchar *) section, (gchar *) prop.prefix[i]); + g_snprintf(section, sizeof(section), "mini_commander/macro_pattern_%.2u", i+1); + gnome_config_set_string((gchar *) section, (gchar *) prop.macro_pattern[i]); - g_snprintf(section, sizeof(section), "mini_commander/command_%d", i+1); - gnome_config_set_string((gchar *) section, (gchar *) prop.command[i]); + g_snprintf(section, sizeof(section), "mini_commander/macro_command_%.2u", i+1); + gnome_config_set_string((gchar *) section, (gchar *) prop.macro_command[i]); - prop_tmp.prefix[i] = (char *) NULL; - prop_tmp.command[i] = (char *) NULL; + prop_tmp.macro_pattern[i] = (char *) NULL; + prop_tmp.macro_command[i] = (char *) NULL; } /* history */ - for(i = 0; i < HISTORY_DEPTH; i++) + for(i = 0; i < LENGTH_HISTORY_LIST; i++) { - g_snprintf(section, sizeof(section), "mini_commander/history_%d", i); + g_snprintf(section, sizeof(section), "mini_commander/history_%.2u", i); if(exists_history_entry(i)) gnome_config_set_string((gchar *) section, (gchar *) get_history_entry(i)); else @@ -776,23 +796,23 @@ properties_box(AppletWidget *applet, gpointer data) /* gtk_container_add(GTK_CONTAINER(scrolled_window), vbox1); does not work */ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox1); - for(i=0; i < MAX_PREFIXES; i++) + for(i=0; i < MAX_NUM_MACROS; i++) { hbox = gtk_hbox_new(FALSE, GNOME_PAD_SMALL); gtk_box_pack_start(GTK_BOX(vbox1), hbox, TRUE, TRUE, 0); /* prefix */ - g_snprintf(text_label, sizeof(text_label), _("Prefix %.2d:"), i+1); + g_snprintf(text_label, sizeof(text_label), _("Regex %.2d:"), i+1); gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(text_label), FALSE, TRUE, 0); - entry = gtk_entry_new_with_max_length(MAX_PREFIX_LENGTH); + entry = gtk_entry_new_with_max_length(MAX_MACRO_PATTERN_LENGTH); gtk_widget_set_usize(entry, 75, -1); - if (prop.prefix[i] != (gchar *) NULL) - gtk_entry_set_text(GTK_ENTRY(entry), (gchar *) prop.prefix[i]); + if (prop.macro_pattern[i] != (gchar *) NULL) + gtk_entry_set_text(GTK_ENTRY(entry), (gchar *) prop.macro_pattern[i]); gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(entry_changed_signal), - &prop_tmp.prefix[i]); + &prop_tmp.macro_pattern[i]); gtk_signal_connect_object(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(gnome_property_box_changed), @@ -804,12 +824,12 @@ properties_box(AppletWidget *applet, gpointer data) gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(text_label), FALSE, TRUE, 0); entry = gtk_entry_new_with_max_length(MAX_COMMAND_LENGTH); - if (prop.command[i] != (gchar *) NULL) - gtk_entry_set_text(GTK_ENTRY(entry), prop.command[i]); + if (prop.macro_command[i] != (gchar *) NULL) + gtk_entry_set_text(GTK_ENTRY(entry), prop.macro_command[i]); gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(entry_changed_signal), - &prop_tmp.command[i]); + &prop_tmp.macro_command[i]); gtk_signal_connect_object(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(gnome_property_box_changed), diff --git a/mini-commander/src/preferences.h b/mini-commander/src/preferences.h index ea60647fd..87e82e483 100644 --- a/mini-commander/src/preferences.h +++ b/mini-commander/src/preferences.h @@ -1,9 +1,11 @@ +#include <regex.h> #include <applet-widget.h> -#define HISTORY_DEPTH 50 -#define MAX_COMMAND_LENGTH 500 -#define MAX_PREFIXES 99 -#define MAX_PREFIX_LENGTH 25 +#define LENGTH_HISTORY_LIST 50 +#define MAX_COMMAND_LENGTH 500 +#define MAX_NUM_MACROS 99 +#define MAX_NUM_MACRO_PARAMETERS 100 +#define MAX_MACRO_PATTERN_LENGTH 25 typedef struct struct_properties properties; @@ -26,8 +28,9 @@ struct struct_properties int cmd_line_color_bg_r; int cmd_line_color_bg_g; int cmd_line_color_bg_b; - char *prefix[MAX_PREFIXES]; - char *command[MAX_PREFIXES]; + char *macro_pattern[MAX_NUM_MACROS]; + char *macro_command[MAX_NUM_MACROS]; + regex_t *macro_regex[MAX_NUM_MACROS]; }; extern properties prop; diff --git a/mini-commander/src/terminal.c b/mini-commander/src/terminal.c index 1bd33aa49..01f3550e6 100644 --- a/mini-commander/src/terminal.c +++ b/mini-commander/src/terminal.c @@ -37,7 +37,7 @@ GtkWidget *terminal_zvt = NULL; #if 0 -static int history_position = HISTORY_DEPTH; +static int history_position = LENGTH_HISTORY_LIST; static char browsed_filename[300] = ""; static gchar * history_auto_complete(GtkWidget *widget, GdkEventKey *event); @@ -70,7 +70,7 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) || key == GDK_Pointer_Up) { /* up key pressed */ - if(history_position == HISTORY_DEPTH) + if(history_position == LENGTH_HISTORY_LIST) { /* store current command line */ strcpy(current_command, (char *) gtk_entry_get_text(GTK_ENTRY(widget))); @@ -90,11 +90,11 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) || key == GDK_Pointer_Down) { /* down key pressed */ - if(history_position < HISTORY_DEPTH - 1) + if(history_position < LENGTH_HISTORY_LIST - 1) { gtk_entry_set_text(GTK_ENTRY(widget), (gchar *) get_history_entry(++history_position)); } - else if(history_position == HISTORY_DEPTH - 1) + else if(history_position == LENGTH_HISTORY_LIST - 1) { gtk_entry_set_text(GTK_ENTRY(widget), (gchar *) current_command); ++history_position; @@ -117,7 +117,7 @@ command_key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) exec_command(command); append_history_entry((char *) command); - history_position = HISTORY_DEPTH; + history_position = LENGTH_HISTORY_LIST; free(command); strcpy(current_command, ""); @@ -167,7 +167,7 @@ history_auto_complete(GtkWidget *widget, GdkEventKey *event) int i; sprintf(current_command, "%s%s", gtk_entry_get_text(GTK_ENTRY(widget)), event->string); - for(i = HISTORY_DEPTH - 1; i >= 0; i--) + for(i = LENGTH_HISTORY_LIST - 1; i >= 0; i--) { if(!exists_history_entry(i)) break; |