public static string parse_var_assignment(string line, ref vmodifiers vmod) { string p = ""; line = Utils.next_token(line); if (line.Length == 0) { return(""); } p = line; while (true) { string p2 = ""; Variable.variable_flavor flavor = new Variable.variable_flavor(); p2 = Variable.parse_variable_definition(p, ref flavor); // If this is a variable assignment, we're done. if (p2 != null) { break; } // It's not a variable; see if it's a modifier. p2 = Utils.end_of_token(p); if (p.StartsWith("export")) { vmod.export_v = true; } else if (p.StartsWith("override")) { vmod.override_v = true; } else if (p.StartsWith("private")) { vmod.private_v = true; } else if (p.StartsWith("define")) { // We can't have modifiers after 'define' vmod.define_v = true; p = Utils.next_token(p2); break; } else if (p.StartsWith("undefine")) { /* We can't have modifiers after 'undefine' */ vmod.undefine_v = true; p = Utils.next_token(p2); break; } else { /* Not a variable or modifier: this is not a variable assignment. */ return(line); } /* It was a modifier. Try the next word. */ p = Utils.next_token(p2); if (p == null || p == "") { return(line); } } /* Found a variable assignment or undefine. */ vmod.assign_v = true; return(p); }
/* Execute a `define' directive. * The first line has already been read, and NAME is the name of the variable to be defined. The following lines remain to be read. */ public static Variable.variable do_define(string name, Variable.variable_origin origin) { Variable.variable_flavor flavor = new Variable.variable_flavor(); int nlevels = 1; string definition = ""; string p = ""; string var = ""; p = Variable.parse_variable_definition(name, ref flavor); if (p == null) { // No assignment token, so assume recursive. flavor = Variable.variable_flavor.f_recursive; } else { if (Utils.next_token(p).Length != 0) { MessageBox.Show("Extraneous text after 'define' directive - (" + (new StackFrame()).GetFileName() + " - " + (new StackFrame()).GetFileLineNumber() + ")"); } name = name.Trim(); // Chop the string before the assignment token to get the name. name = name.Substring(0, name.Length - ((flavor == Variable.variable_flavor.f_recursive) ? 1 : 2)); } // Expand the variable name and find the beginning (NAME) and end. var = Variable.ExpandString(name); name = Utils.next_token(var); if (name.Length == 0) { MessageBox.Show("Empty variable name - (" + (new StackFrame()).GetFileName() + " - " + (new StackFrame()).GetFileLineNumber() + ")"); } name = name.Trim(); // Now read the value of the variable. while (true) { int len; string line = ReadLine(); // If there is nothing left to be eval'd, there's no 'endef'!! if (line == "") { MessageBox.Show("Missing 'endef', unterminated 'define'"); } // If the line doesn't begin with a tab, test to see if it introduces another define, or ends one. Stop if we find an 'endef' if (line[0] != TAB_CHAR) { p = Utils.next_token(line); len = p.Length; // If this is another 'define', increment the level count. if ((len == 6 || (len > 6 && Utils.isblank(p[6]))) && (p.Substring(0, 6) == "define")) { ++nlevels; } // If this is an 'endef', decrement the count. If it's now 0, we've found the last one. else if ((len == 5 || (len > 5 && Utils.isblank(p[5]))) && (p.Substring(0, 5) == "endef")) { p = p.Substring(5); if (Utils.next_token(p).Length != 0) { MessageBox.Show("Extraneous text after 'endef' directive - (" + (new StackFrame()).GetFileName() + " - " + (new StackFrame()).GetFileLineNumber() + ")"); } if (--nlevels == 0) { break; } } } // Add this line to the variable definition and separate lines with a newline. definition += line + "\n"; } // We've got what we need; define the variable. return(Variable.do_variable_definition(name, definition, origin, flavor, 0)); }