Mercurial > hg > octave-terminal
changeset 279:c64f870ac8d9
[project @ 1994-01-08 22:51:53 by jwe]
author | jwe |
---|---|
date | Sat, 08 Jan 1994 22:51:53 +0000 |
parents | c2189d67a05c |
children | 7e60a6f52cd4 |
files | src/pt-const.cc src/t-builtins.cc src/variables.cc src/variables.h |
diffstat | 4 files changed, 76 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -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; }
--- a/src/t-builtins.cc +++ b/src/t-builtins.cc @@ -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; }
--- a/src/variables.cc +++ b/src/variables.cc @@ -31,6 +31,7 @@ #endif #include <ctype.h> #include <iostream.h> +#include <strstream.h> #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.
--- a/src/variables.h +++ b/src/variables.h @@ -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&);