Beispiel #1
0
 public static string func_if(List <string> args)
 {
     Variable.variable v = null;
     if (args[0].StartsWith("UNRESOLVED"))
     {
         if (args.Count == 2)
         {
             v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(if " + args[0] + "," + args[1] + ")");
         }
         else if (args.Count == 3)
         {
             v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(if " + args[0] + "," + args[1] + "," + args[2] + ")");
         }
         return(v.name);
     }
     if (Variable.ExpandString(args[0].Trim()) == "")
     {
         if (args.Count == 3)
         {
             // Evaluate else part
             return(Variable.ExpandString(args[2].Trim()));
         }
         return("");
     }
     else
     {
         // Evaluate then part
         return(Variable.ExpandString(args[1].Trim()));
     }
 }
Beispiel #2
0
        public static string func_origin(List <string> args)
        {
            Variable.variable v = Variable.lookup_variable(args[0]);
            if (v == null)
            {
                return("undefined");
            }
            switch (v.origin)
            {
            default:
            case Variable.variable_origin.o_invalid:
                return("invalid");

            case Variable.variable_origin.o_default:
                return("default");

            case Variable.variable_origin.o_env:
                return("environment");

            case Variable.variable_origin.o_file:
                return("file");

            case Variable.variable_origin.o_env_override:
                return("environment override");

            case Variable.variable_origin.o_command:
                return("command line");

            case Variable.variable_origin.o_override:
                return("override");

            case Variable.variable_origin.o_automatic:
                return("automatic");
            }
        }
Beispiel #3
0
 public static string func_words(List <string> args)
 {
     if (args[0].StartsWith("UNRESOLVED"))
     {
         Variable.variable v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(words " + args[0] + ")");
         return(v.name);
     }
     return(ChopString(args[0]).Count.ToString());
 }
Beispiel #4
0
        public static string func_call(List <string> args)
        {
            if (args.Count == 0)
            {
                return("");
            }
            // There is no way to define a variable with a space in the name, so strip leading and trailing whitespace as a favor to the user
            string fname = args[0].Trim();

            if (fname == "")
            {
                return("");
            }

            // Are we invoking a builtin function?
            function func = lookup_function(fname);

            if (func != null)
            {
                // How many arguments do we have?
                List <string> subargs = new List <string>();
                for (int j = 1; j < args.Count; j++)
                {
                    subargs.Add(args[j]);
                }
                return(expand_builtin_function("", subargs, func));
            }

            // Not a builtin, so the first argument is the name of a variable to be expanded and interpreted as a function.  Find it
            Variable.variable v = Variable.lookup_variable(fname);
            if (v == null)
            {
                MessageBox.Show("Undefined Variable in Call '" + fname + "' - (" + (new StackFrame()).GetFileName() + " - " + (new StackFrame()).GetFileLineNumber() + ")");
                return("");
            }
            if (v.value == "")
            {
                return("");
            }

            // Set up arguments $(1) .. $(N).  $(0) is the function name
            for (int i = 0; i < args.Count; i++)
            {
                Variable.define_variable_in_set(i.ToString(), args[i], Variable.variable_origin.o_automatic, false, Variable.current_variable_set_list);
            }

            // Expand the body in the context of the arguments, adding the result to the variable buffer
            string result = Variable.ExpandString("$(" + fname + ")");

            for (int i = 0; i < args.Count; i++)
            {
                Variable.undefine_variable(i.ToString(), null);
            }

            return(result);
        }
Beispiel #5
0
 public static string func_value(List <string> args)
 {
     Variable.variable v = Variable.lookup_variable(args[0]);
     if (v == null)
     {
         return("");
     }
     else
     {
         return(v.value);
     }
 }
Beispiel #6
0
        public static string func_lastword(List <string> args)
        {
            List <string> strs = ChopString(args[0]);

            if (strs[strs.Count - 1].StartsWith("UNRESOLVED"))
            {
                Variable.variable v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(lastword " + strs[strs.Count - 1] + ")");
                return(v.name);
            }
            else
            {
                return(strs[strs.Count - 1]);
            }
        }
Beispiel #7
0
 public static string func_flavor(List <string> args)
 {
     Variable.variable v = Variable.lookup_variable(args[0]);
     if (v == null)
     {
         return("undefined");
     }
     if (v.flavor == Variable.variable_flavor.f_recursive)
     {
         return("recursive");
     }
     else
     {
         return("simple");
     }
 }
Beispiel #8
0
        public static string func_foreach(List <string> args)
        {
            string        varname = Variable.ExpandString(args[0]);
            List <string> list    = ChopString(Variable.ExpandString(args[1]));
            string        body    = args[2];

            /*
             * foreach(string item in list)
             * {
             *  if(item.StartsWith("UNRESOLVED"))
             *      {
             *      Variable.variable v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(foreach " + args[0] + "," + args[1] + "," + args[2] +  ")", null);
             *      return v.name;
             *  }
             * }
             */
            string result = "";

            Variable.variable saveVar = Variable.lookup_variable(varname);
            if (saveVar != null)
            {
                Variable.undefine_variable(varname, null);
            }

            Variable.variable var = Variable.define_variable_in_set(varname, "", Variable.variable_origin.o_automatic, false, Variable.current_variable_set_list);
            for (int i = 0; i < list.Count; i++)
            {
                var.value = list[i];
                result   += Variable.ExpandString(body);
                if (i < list.Count - 1)
                {
                    result += " ";
                }
            }

            Variable.undefine_variable(varname, null);
            if (saveVar != null)
            {
                Variable.current_variable_set_list.Add(saveVar.name, saveVar);
            }

            return(result);
        }
Beispiel #9
0
        public static string func_abspath(List <string> args)
        {
            List <string> strs   = ChopString(args[0]);
            string        result = "";

            for (int i = 0; i < strs.Count; i++)
            {
                if (strs[i].StartsWith("UNRESOLVED"))
                {
                    Variable.variable v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(abspath " + strs[i] + ")");
                    result += v.name;
                }
                else
                {
                    result += strs[i].Replace(".", "").Replace("//", "/");
                }
                if (i < strs.Count - 1)
                {
                    result += " ";
                }
            }
            return(result);
        }
Beispiel #10
0
        public static void ParseMakeFile()
        {
            Form1.makefileTextControl.Text = "";
            Form1.makefileReader           = new StreamReader(Form1.makefileName);

            int           ignoring          = 0;
            int           in_ignored_define = 0;
            List <string> filenames         = new List <string>(); // nameseq
            List <string> targets           = new List <string>();
            List <string> prerequisites     = new List <string>();

            while (true)
            {
                string     line = "";
                int        wlen;
                string     p    = "";
                string     p2   = "";
                vmodifiers vmod = new vmodifiers();

                // If line is equal to null, then we are done parsing!
                if ((line = ReadLine()) == "")
                {
                    break;
                }

                if (line[0] == TAB_CHAR) // This is a start of a recipe line
                {
                    foreach (string target in targets)
                    {
                        Form1.rules[target].recipe += Variable.ExpandRecipeString(line.Substring(1), Form1.rules[target]);
                    }
                    Form1.UpdateRulesTree();
                    continue;
                }

                // See if this is a variable assignment.  We need to do this early, to allow variables with names like 'ifdef', 'export', 'private', etc.
                p = parse_var_assignment(line, ref vmod);
                if (vmod.assign_v)
                {
                    Variable.variable        v      = new Variable.variable();
                    Variable.variable_origin origin = vmod.override_v? Variable.variable_origin.o_override : Variable.variable_origin.o_file;

                    // If we're ignoring then we're done now.
                    if (ignoring == 1)
                    {
                        in_ignored_define = 1;
                        continue;
                    }
                    if (vmod.undefine_v)
                    {
                        do_undefine(p, origin);
                        continue;
                    }
                    else if (vmod.define_v)
                    {
                        v = do_define(p, origin);
                    }
                    else
                    {
                        v = Variable.try_variable_definition(p, origin, 0);
                    }


                    if (v == null)
                    {
                        MessageBox.Show("Variable at line(" + LINENO + ") should not be NULL");
                    }

                    if (vmod.export_v)
                    {
                        v.export = Variable.variable_export.v_export;
                    }
                    if (vmod.private_v)
                    {
                        v.private_var = true;
                    }

                    // This line has been dealt with.
                    continue;
                }

                // If this line is completely empty, ignore it.
                if (p.Length == 0)
                {
                    continue;
                }

                p2   = Utils.end_of_token(p);
                wlen = p.IndexOf(p2);
                p2   = Utils.next_token(p2);

                // If we're in an ignored define, skip this line (but maybe get out).
                if (in_ignored_define == 1)
                {
                    // See if this is an endef line (plus optional comment).
                    if (p.Equals("endef") && (p2.Length == 0 || p2[0] == '#'))
                    {
                        in_ignored_define = 0;
                    }
                    continue;
                }

                if (line.StartsWith("ifeq") || line.StartsWith("ifneq") || line.StartsWith("ifdef") || line.StartsWith("ifndef"))
                {
                    IF_COUNTS++;
                }
                // Check for conditional state changes.

                /*{
                 *  int i = conditional_line(p, wlen, fstart);
                 *  if (i != -2)
                 *  {
                 *      if (i == -1)
                 *          MessageBox.Show("Invalid syntax in conditional - (" + (new StackFrame()).GetFileName() + " - " + (new StackFrame()).GetFileLineNumber() + ")");
                 *
                 *      ignoring = i;
                 *      continue;
                 *  }
                 * }*/

                // Manage the "export" keyword used outside of variable assignment as well as "unexport".
                if (p.StartsWith("export") || p.StartsWith("unexport"))
                {
                    bool exporting = p[0] == 'u';

                    // (un)export by itself causes everything to be (un)exported.
                    if (p2.Length == 0)
                    {
                        export_all_variables = exporting;
                    }
                    else
                    {
                        string cp = "";
                        string ap = "";

                        // Expand the line so we can use indirect and constructed variable names in an (un)export command.
                        cp = ap = Variable.ExpandString(p2);

                        for (p = Utils.find_next_token(ref cp); p != null; p = Utils.find_next_token(ref cp))
                        {
                            if (cp != "")
                            {
                                p = p.Substring(0, p.IndexOf(cp));
                            }
                            Variable.variable v = Variable.lookup_variable(p);
                            if (v == null)
                            {
                                v = Variable.do_variable_definition(p, "", Variable.variable_origin.o_file, 0, 0);
                            }
                            v.export = exporting ? Variable.variable_export.v_export : Variable.variable_export.v_noexport;
                        }
                    }
                    continue;
                }

                // Handle the special syntax for vpath.
                if (p.StartsWith("vpath"))
                {
                    string cp   = "";
                    string vpat = "";
                    cp = Variable.ExpandString(p2);
                    p  = Utils.find_next_token(ref cp);
                    if (p != null)
                    {
                        if (cp != "")
                        {
                            vpat = p.Substring(0, p.IndexOf(cp));
                        }
                        p = Utils.find_next_token(ref cp);
                        // No searchpath means remove all previous selective VPATH's with the same pattern.
                    }
                    else
                    {
                        // No pattern means remove all previous selective VPATH's.
                        vpat = "";
                    }
                    //construct_vpath_list(vpat, p);
                    continue;
                }

                // Handle include and variants.
                if (p.StartsWith("include") || p.StartsWith("-include") || p.StartsWith("sinclude"))
                {
                    // "-include" (vs "include") says no error if the file does not exist.  "sinclude" is an alias for this from SGI.
                    bool noerror = p[0] != 'i';

                    p = Variable.ExpandString(p2);

                    // If no filenames, it's a no-op.
                    if (p == null || p == "")
                    {
                        continue;
                    }

                    // Parse the list of file names.  Don't expand archive references!
                    List <string> files = Utils.ChopString(p);

                    // Read each included makefile.
                    foreach (string file in files)
                    {
                        Form1.Includes.Add("[INCLUDE]" + file);
                    }

                    continue;
                }

                string expandedLine = Variable.ExpandString(line);
                int    colonIndex   = expandedLine.IndexOf(':');
                if (colonIndex >= 0)
                {
                    bool singleColon = false;
                    if (colonIndex == expandedLine.Length - 1)
                    {
                        singleColon = true;
                    }
                    else
                    {
                        if (expandedLine[colonIndex + 1] == ':')
                        {
                            singleColon = false;
                        }
                        else
                        {
                            singleColon = true;
                        }
                    }

                    int semiColonIndex = expandedLine.IndexOf(';', colonIndex);
                    targets = Utils.ChopString(expandedLine.Substring(0, colonIndex));
                    if (semiColonIndex >= 0)
                    {
                        prerequisites = Utils.ChopString(expandedLine.Substring(singleColon ? colonIndex + 1 : colonIndex + 2, semiColonIndex - (singleColon ? colonIndex + 1 : colonIndex + 2)));
                    }
                    else
                    {
                        prerequisites = Utils.ChopString(expandedLine.Substring(singleColon ? colonIndex + 1 : colonIndex + 2));
                    }

                    if (singleColon) // Single-Coloned rules are combined with other -if any-
                    {
                        foreach (string target in targets)
                        {
                            Rule rule;
                            if (Form1.rules.ContainsKey(target))
                            {
                                rule = Form1.rules[target];
                            }
                            else
                            {
                                rule             = new Rule();
                                rule.target      = target;
                                rule.singleColon = true;
                                rule.lineno      = LINENO;
                                Form1.rules.Add(rule.target, rule);
                            }
                            foreach (string prerequisite in prerequisites)
                            {
                                rule.prerequisites.Add(prerequisite);
                            }
                            if (semiColonIndex >= 0)
                            {
                                rule.recipe = expandedLine.Substring(semiColonIndex + 1);
                            }
                        }
                    }
                    else // Double-Coloned rules are added directly to SDG
                    {
                        List <string> doubleColonTargets = new List <string>();
                        foreach (string target in targets)
                        {
                            Rule rule = new Rule();
                            rule.target = Utils.GetTargerName(target);
                            doubleColonTargets.Add(rule.target);
                            rule.singleColon = false;
                            Form1.rules.Add(rule.target, rule);
                            foreach (string prerequisite in prerequisites)
                            {
                                rule.prerequisites.Add(prerequisite);
                            }
                            if (semiColonIndex >= 0)
                            {
                                rule.recipe = expandedLine.Substring(semiColonIndex + 1);
                            }
                        }
                        targets.Clear();
                        foreach (string target in doubleColonTargets)
                        {
                            targets.Add(target);
                        }
                    }
                    Form1.UpdateRulesTree();
                    continue;
                }
            }
        }
Beispiel #11
0
 public static string func_wildcard(List <string> args)
 {
     Variable.variable v = Variable.define_unresolved_variable(Utils.GetUnresolvedName(), "$(wildcard " + args[0] + ")");
     return(v.name);
 }