# HG changeset patch # User jwe # Date 746739837 0 # Node ID 04c30624aaf9b5359b1ba2af83c7620e1973f26d # Parent 0fda6e1f90e04c610fa111312f351e0bea62c8a5 [project @ 1993-08-30 19:43:25 by jwe] diff -r 0fda6e1f90e0 -r 04c30624aaf9 src/builtins.cc --- a/src/builtins.cc Mon Aug 30 15:40:48 1993 +0000 +++ b/src/builtins.cc Mon Aug 30 19:43:57 1993 +0000 @@ -154,7 +154,7 @@ "change current working directory\n", }, { "clear", -1, builtin_clear, - "clear symbol(s) from symbol table\n", }, + "clear symbol(s) matching a list of regular expressions\n", }, { "dir", -1, builtin_ls, "print a directory listing\n", }, diff -r 0fda6e1f90e0 -r 04c30624aaf9 src/t-builtins.cc --- a/src/t-builtins.cc Mon Aug 30 15:40:48 1993 +0000 +++ b/src/t-builtins.cc Mon Aug 30 19:43:57 1993 +0000 @@ -50,6 +50,7 @@ #include #include #include +#include #include "procstream.h" @@ -206,8 +207,22 @@ return retval; } +static int +in_list (char *s, char **list) +{ + while (*list != (char *) NULL) + { + if (strcmp (s, *list) == 0) + return 1; + list++; + } + + return 0; +} + /* - * Wipe out user-defined variables and functions. + * Wipe out user-defined variables and functions given a list of + * regular expressions. */ tree_constant builtin_clear (int argc, char **argv) @@ -220,12 +235,55 @@ } else { + int count; + char **names = curr_sym_tab->list (count); + + int g_count; + char **g_names = global_sym_tab->list (g_count); + + int num_cleared = 0; + char **locals_cleared = new char * [count+1]; + locals_cleared[num_cleared] = (char *) NULL; + while (--argc > 0) { argv++; - if (*argv != (char *) NULL && ! curr_sym_tab->clear (*argv)) - global_sym_tab->clear (*argv); + if (*argv != (char *) NULL) + { + Regex rx (*argv); + + int i; + for (i = 0; i < count; i++) + { + String nm (names[i]); + if (nm.matches (rx) && curr_sym_tab->clear (names[i])) + { + locals_cleared[num_cleared++] = strsave (names[i]); + locals_cleared[num_cleared] = (char *) NULL; + } + } + + for (i = 0; i < g_count; i++) + { + String nm (g_names[i]); + if (nm.matches (rx) + && ! in_list (g_names[i], locals_cleared)) + { + global_sym_tab->clear (g_names[i]); + } + } + } } + + int i = 0; + while (locals_cleared[i] != (char *) NULL) + delete [] locals_cleared[i++]; + delete [] locals_cleared; + + delete [] names; + delete [] g_names; + delete [] g_names; + } return retval; }