From: Ethan A M. <merritt@u.washington.edu> - 2004-07-24 20:44:30
|
On Wednesday 21 July 2004 12:33 am, Volker Dobler wrote: > There are two functions: quote_str and m_quote_capture. > Using quote_str you will have to do memory allocation yourself, > whereas m_quote_capture will do allocation for you if I remember > correctly. My old patch replaced (hopfully) all the invocations > of quote_str with m_quote_capture and did substitution there. You guys may yet convince me. I think it may be even cleaner than you describe, because the expression parsing code can now handle string constants as well as string-valued functions. So many of the instances of isstring() + m_quote_capture() can be replaced by const_express(&a). Better yet, in many places this is what the code was going to try next anyhow. So the test for string constants as a special case just goes away. Example (taken from the "print" command): #ifndef GP_STRING_VARS /* This is the version 4.0 code */ if (isstring(c_token)) { s = NULL; m_quote_capture(&s, c_token, c_token); fputs(s, print_out); need_space = 0; free(s); ++c_token; } else { (void) const_express(&a); if (need_space) putc(' ', print_out); need_space = 1; disp_value(print_out, &a); } #else /* This is the code after adding string variables */ (void) const_express(&a); disp_value(print_out, &a); if (a.type == STRING) free(a.v.string_val); else putc(' ', print_out); #endif Yes, I know that this code fragment does not exactly duplicate the whitespace layout of the old behaviour. I also see that I must work on when, if ever, to print quote marks when showing the value of string variables. The only thing I am stuck on at the moment is trying to automatically free the dynamically-allocated string created by evaluation of const_express(&a). It is annoying to test for it everywhere, though I suppose it's no worse than having to do the same thing after m_quote_capture in the current code. -- Ethan A Merritt Department of Biochemistry & Biomolecular Structure Center University of Washington, Seattle |