# HG changeset patch # User jwe # Date 758069513 0 # Node ID c64f870ac8d993b20d27651d748be8c6411a0c0c # Parent c2189d67a05c3b48be300f4e8061a324c84010bd [project @ 1994-01-08 22:51:53 by jwe] diff -r c2189d67a05c -r c64f870ac8d9 src/pt-const.cc --- a/src/pt-const.cc Sat Jan 08 22:43:27 1994 +0000 +++ b/src/pt-const.cc Sat Jan 08 22:51:53 1994 +0000 @@ -1399,40 +1399,39 @@ type_tag = unknown_constant; // Look for type keyword - char tag [128]; - if (extract_keyword (is, "type", tag)) + + char *tag = extract_keyword (is, "type"); + + if (tag != (char *) NULL && *tag != '\0') { - if (tag != (char *) NULL && *tag != '\0') + char *ptr = strchr (tag, ' '); + if (ptr != (char *) NULL) { - char *ptr = strchr (tag, ' '); - if (ptr != (char *) NULL) - { - *ptr = '\0'; - is_global = (strncmp (tag, "global", 6) == 0); - *ptr = ' '; - ptr++; - } - else - ptr = &tag[0]; - - if (strncmp (ptr, "scalar", 6) == 0) - type_tag = load (is, scalar_constant); - else if (strncmp (ptr, "matrix", 6) == 0) - type_tag = load (is, matrix_constant); - else if (strncmp (ptr, "complex scalar", 14) == 0) - type_tag = load (is, complex_scalar_constant); - else if (strncmp (ptr, "complex matrix", 14) == 0) - type_tag = load (is, complex_matrix_constant); - else if (strncmp (ptr, "string", 6) == 0) - type_tag = load (is, string_constant); - else if (strncmp (ptr, "range", 5) == 0) - type_tag = load (is, range_constant); - else - ::error ("unknown constant type `%s'", tag); + *ptr = '\0'; + is_global = (strncmp (tag, "global", 6) == 0); + *ptr = ' '; + ptr++; } else - ::error ("failed to extract keyword specifying value type"); + ptr = &tag[0]; + + if (strncmp (ptr, "scalar", 6) == 0) + type_tag = load (is, scalar_constant); + else if (strncmp (ptr, "matrix", 6) == 0) + type_tag = load (is, matrix_constant); + else if (strncmp (ptr, "complex scalar", 14) == 0) + type_tag = load (is, complex_scalar_constant); + else if (strncmp (ptr, "complex matrix", 14) == 0) + type_tag = load (is, complex_matrix_constant); + else if (strncmp (ptr, "string", 6) == 0) + type_tag = load (is, string_constant); + else if (strncmp (ptr, "range", 5) == 0) + type_tag = load (is, range_constant); + else + ::error ("unknown constant type `%s'", tag); } + else + ::error ("failed to extract keyword specifying value type"); return is_global; } diff -r c2189d67a05c -r c64f870ac8d9 src/t-builtins.cc --- a/src/t-builtins.cc Sat Jan 08 22:43:27 1994 +0000 +++ b/src/t-builtins.cc Sat Jan 08 22:51:53 1994 +0000 @@ -246,9 +246,7 @@ /* * Wipe out user-defined variables and functions given a list of - * regular expressions. - * - * It's not likely that this works correctly now. XXX FIXME XXX + * globbing patterns. */ tree_constant builtin_clear (int argc, char **argv) @@ -736,12 +734,12 @@ stream = file; } - char nm [128]; // XXX FIXME XXX int count = 0; for (;;) { // Read name for this entry or break on EOF. - if (extract_keyword (stream, "name", nm) == 0 || nm == (char *) NULL) + char *nm = extract_keyword (stream, "name"); + if (nm == (char *) NULL) { if (count == 0) { @@ -750,6 +748,8 @@ } break; } + else + count++; if (*nm == '\0') continue; @@ -760,8 +760,13 @@ continue; } - if (load_variable (nm, force, stream)) - count++; + load_variable (nm, force, stream); + + if (error_state) + { + error ("reading file %s", *argv); + break; + } } if (file); @@ -875,7 +880,7 @@ static ofstream file; if (strcmp (*argv, "-") == 0) { -// XXX FIXME XXX -- things intended for the screen should end up in a +// XXX FIXME XXX -- should things intended for the screen end up in a // tree_constant (string)? stream = cout; } diff -r c2189d67a05c -r c64f870ac8d9 src/variables.cc --- a/src/variables.cc Sat Jan 08 22:43:27 1994 +0000 +++ b/src/variables.cc Sat Jan 08 22:51:53 1994 +0000 @@ -31,6 +31,7 @@ #endif #include #include +#include #include "statdefs.h" #include "tree-const.h" @@ -447,13 +448,19 @@ * something like: * * #[ \t]*keyword[ \t]*:[ \t]*string-value\n + * + * Returns a pointer to a static variable which is only valid until + * the next time this function is called. */ -int -extract_keyword (istream& is, char *keyword, char *value) +char * +extract_keyword (istream& is, char *keyword) { - char *ptr = value; + ostrstream buf; - int status = 0; + static char *retval = (char *) NULL; + + delete [] retval; + retval = (char *) NULL; char c; while (is.get (c)) @@ -464,37 +471,41 @@ ; // Skip whitespace and comment characters. if (isalpha (c)) - *ptr++ = c; + buf << c; while (is.get (c) && isalpha (c)) - *ptr++ = c; + buf << c; - if (strncmp (value, keyword, strlen (keyword)) == 0) + buf << ends; + char *tmp = buf.str (); + int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); + delete [] tmp; + + if (match) { - ptr = value; + ostrstream value; while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) ; // Skip whitespace and the colon. if (c != '\n') { - *ptr++ = c; + value << c; while (is.get (c) && c != '\n') - *ptr++ = c; + value << c; } - *ptr = '\0'; - status = 1; + value << ends; + retval = value.str (); break; } } } - return status; + return retval; } int extract_keyword (istream& is, char *keyword, int& value) { - char buf [128]; - char *ptr = buf; + ostrstream buf; int status = 0; value = 0; @@ -508,14 +519,18 @@ ; // Skip whitespace and comment characters. if (isalpha (c)) - *ptr++ = c; + buf << c; while (is.get (c) && isalpha (c)) - *ptr++ = c; + buf << c; - if (strncmp (buf, keyword, strlen (keyword)) == 0) + buf << ends; + char *tmp = buf.str (); + int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); + delete [] tmp; + + if (match) { - ptr = buf; while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) ; // Skip whitespace and the colon. diff -r c2189d67a05c -r c64f870ac8d9 src/variables.h --- a/src/variables.h Sat Jan 08 22:43:27 1994 +0000 +++ b/src/variables.h Sat Jan 08 22:51:53 1994 +0000 @@ -80,7 +80,7 @@ extern int is_globally_visible (const char *nm); -extern int extract_keyword (istream&, char *, char *); +extern char *extract_keyword (istream&, char *); extern int extract_keyword (istream&, char *, int&); extern void skip_comments (istream&);