Esempio n. 1
0
        private void PushScriptExtension(string objectName, FileInfo filename, string _namespace = null)
        {
            //<ScriptExtension Name ="Alarm Object" Author="Anv" Version="0.1" HomePage ="None">
            string name           = objectName + " Object";
            string author         = "";
            string authorPattern  = @"^(.*@author )([A-Za-z0-9]+)$";
            string version        = "";
            string versionPattern = @"^(.*@version )([A-Za-z0-9.]+)$";
            string briefPattern   = @"^(.*@brief )([A-Za-z0-9 .]+)$";
            string pathPattern    = @"^.*\\(_[A-Za-z1-9]+).*$";
            string nameSpace      = "ARCHER";

            foreach (string str in store)
            {
                if (Regex.IsMatch(str, authorPattern, RegexOptions.Multiline))
                {
                    if (author != "")
                    {
                        author += ", ";
                    }
                    author += Regex.Match(str, authorPattern).Groups[2].ToString();
                }
                else if (Regex.IsMatch(str, versionPattern, RegexOptions.Multiline))
                {
                    version = Regex.Match(str, versionPattern).Groups[2].ToString();
                }
                else if (Regex.IsMatch(str, briefPattern, RegexOptions.Multiline))
                {
                    brief = Regex.Match(str, briefPattern).Groups[2].ToString();
                }
            }
            if (Regex.IsMatch(filename.DirectoryName, pathPattern, RegexOptions.Multiline))
            {
                nameSpace = Regex.Match(filename.DirectoryName, pathPattern).Groups[1].ToString();
                name      = objectName + " " + nameSpace.Substring(1) + " Object";
            }
            store.Clear();
            if (author == "")
            {
                MyLogger.Alert("Missing @author tag for " + filename.Name + " class description" + Environment.NewLine);
                author = "TBD";
            }
            if ("" == version)
            {
                MyLogger.Alert("Missing @version tag for " + filename.Name + " class description" + Environment.NewLine);
                version = "TBD";
            }
            input.Add(tab + "<ScriptExtension Name =\"" + name + "\" Author=\"" + author + "\" Version=\"" + version + "\" HomePage=\"None\">");
            input.Add(tab + tab + "<Script Name =\"" + filename.Name + "\">");
            if (null == _namespace)
            {
                input.Add(tab + tab + tab + "<RuntimeObject Name=\"" + objectName + "\" Namespace=\"" + nameSpace + "\">");
            }
            else
            {
                input.Add(tab + tab + tab + "<RuntimeObject Name=\"" + objectName + "\" Namespace=\"" + _namespace + "\">");
            }
        }
Esempio n. 2
0
        private void CreateMethod(string line)
        {
            //<Method Name="SetSinceFire" Routine="SetSinceFire">

/**
 * Set since fire alarm time in the system
 * <h3>Code Example</h3>
 * @code
 *   ARCHER.Alarm.SetSinceFire(30, 60, 90);
 * @endcode
 * @param [in] alarm Alarm time in seconds
 * @param [in] secondWarning Second warning time in seconds
 * @param [in] firstWarning First warning time in seconds
 */
            //</Method>
            string functionPattern = @"^(.*function )([A-Za-z0-9_]+)\(.*$";

            if (Regex.IsMatch(line, functionPattern, RegexOptions.Multiline))
            {
                string functionName = Regex.Match(line, functionPattern).Groups[2].ToString();
                MyLogger.Log("Adding function \"" + functionName + "\" to description." + Environment.NewLine);
                input.Add(tab + tab + tab + tab + "<Method Name=\"" + functionName + "\" Routine=\"" + functionName + "\">");
                if (0 == store.Count)
                {
                    MyLogger.Alert("Found no viable comment for " + functionName + "." + Environment.NewLine);
                }
                else
                {
                    foreach (string str in store)
                    {
                        string formatted = str;
                        // Compensate for xml special characters.
                        formatted = formatted.Replace("&", "&amp;");
                        formatted = formatted.Replace("<", "&lt;");
                        formatted = formatted.Replace(">", "&gt;");
                        formatted = formatted.Replace("\"", "&quot;");
                        formatted = formatted.Replace("\'", "&#39;");
                        input.Add(formatted);
                    }
                }
                input.Add(tab + tab + tab + tab + "</Method>");
            }
        }
Esempio n. 3
0
        public bool ParseScriptFiles()
        {
            bool retValue = true;

            foreach (FileInfo file in Path.GetFiles("*.js"))
            {
                MyLogger.Log("Parsing file " + file.FullName + ": " + Environment.NewLine);
                MyLogger.IncreaseIndent();
                if (false == ParseScriptFile(file) && true == retValue)
                {
                    MyLogger.Alert("First failure occured on file " + file.Name + ": " + Environment.NewLine);
                    retValue = false;
                }
                MyLogger.Log("Done parsing file " + file.Name + "." + Environment.NewLine);
                MyLogger.Log("Writing file " + file.Name + " as cpp." + Environment.NewLine);
                PrintDoxygenFile();
                MyLogger.Log("Done writing file " + file.Name + " as cpp." + Environment.NewLine);
                MyLogger.DecreaseIndent();
            }
            return(retValue);
        }
Esempio n. 4
0
        private void btn_parse_Click(object sender, EventArgs e)
        {
            btn_parse.Enabled = false;
            ClearLog();
            if (true == cbx_parseXml.Checked)
            {
                try
                {
                    Process proc = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            FileName               = tbx_parseFile.Text,
                            Arguments              = "",
                            UseShellExecute        = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true,
                            CreateNoWindow         = true
                        }
                    };
                    proc.OutputDataReceived += new DataReceivedEventHandler(MyLogger.WriteOutput);
                    proc.ErrorDataReceived  += new DataReceivedEventHandler(MyLogger.WriteError);
                    proc.Start();
                    proc.BeginErrorReadLine();
                    proc.BeginOutputReadLine();
                    proc.WaitForExit();
                }
                catch (Exception ex)
                {
                    MyLogger.Alert(ex.Message + Environment.NewLine);
                }
            }
            string rootdir   = Directory.GetCurrentDirectory();
            string fileWrite = "";

            try
            {
                DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories);
                foreach (DirectoryInfo D1 in DI)
                {
                    //rtb_information.Text += "Directory:" + D1.Name + Environment.NewLine;
                    DescriptionBuilder builder = new DescriptionBuilder(D1, cbx_doBackup.Checked);
                    fileWrite = builder.ParseScriptFiles();
                    //rtb_information.Text += builder.GetText();
                }
            }
            catch (DirectoryNotFoundException dEX)
            {
                MyLogger.Alert("Directory Not Found " + dEX.Message + Environment.NewLine);
            }
            catch (Exception ex)
            {
                MyLogger.Alert(ex.Message + Environment.NewLine);
            }
            if (true == cbx_doBackup.Checked)
            {
                btn_clear.Enabled = FileExistsRecursive(Directory.GetCurrentDirectory(), "*.old");
            }
            else
            {
                DirectoryInfo[] DI        = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories);
                Delete          delObject = new Delete(DI);
                delObject.ClearFiles();
            }
            btn_parse.Enabled = true;
        }
Esempio n. 5
0
        private void btn_parse_doxygen_Click(object sender, EventArgs e)
        {
            btn_parse_doxygen.Enabled = false;
            ClearLog();
            string rootdir = Directory.GetCurrentDirectory();

            try
            {
                DirectoryInfo Target = new DirectoryInfo(rootdir + "\\doxygen");
                if (Target.Exists)
                {
                    MyLogger.Log("Directory " + Target.FullName + " exists, deleting." + Environment.NewLine);
                    Directory.Delete(Target.FullName, true);
                }
                DirectoryInfo DoxygenOutput = new DirectoryInfo(rootdir + "\\doc");
                if (DoxygenOutput.Exists)
                {
                    MyLogger.Log("Directory " + DoxygenOutput.FullName + " exists, deleting." + Environment.NewLine);
                    Directory.Delete(DoxygenOutput.FullName, true);
                }
                DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories);
                MyLogger.Log("Creating Target Directory " + Target.FullName + "." + Environment.NewLine);
                Target.Create();
                foreach (DirectoryInfo D1 in DI)
                {
                    if (false == D1.Name.Contains("svn") &&
                        false == D1.Name.Contains("doxygen") &&
                        false == D1.Name.Contains("doc"))
                    {
                        DoxygenBuilder builder = new DoxygenBuilder(D1, Target);
                        builder.ParseScriptFiles();
                    }
                }
            }
            catch (DirectoryNotFoundException dEX)
            {
                MyLogger.Alert("Directory Not Found " + dEX.Message + Environment.NewLine);
            }
            catch (Exception ex)
            {
                MyLogger.Alert(ex.Message + Environment.NewLine);
            }
            try
            {
                if (DialogResult.OK == MessageBox.Show("Do you want to clear output before generation of doxygen?", "Clear Log", MessageBoxButtons.OKCancel))
                {
                    ClearLog();
                }
                Process proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName               = "generate doxygen.bat",
                        Arguments              = "",
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        CreateNoWindow         = true
                    }
                };
                proc.OutputDataReceived += new DataReceivedEventHandler(MyLogger.WriteOutput);
                proc.ErrorDataReceived  += new DataReceivedEventHandler(MyLogger.WriteError);
                proc.Start();
                proc.BeginErrorReadLine();
                proc.BeginOutputReadLine();
                proc.WaitForExit();
            }
            catch (Exception ex)
            {
                MyLogger.Alert(ex.Message + Environment.NewLine);
            }
            btn_parse_doxygen.Enabled = true;
        }
Esempio n. 6
0
        private bool ParseScriptFile(FileInfo file)
        {
            bool retValue = true;

            input.Clear();
            using (StreamReader reader = new StreamReader(file.FullName))
            {
                bool   funcFound = false;
                string funcName  = "";
                int    isClass   = 0;

                string line          = "";
                string function      = @"^function ([A-Za-z0-9_]+)\(.*$";
                string classFunction = @"^([ \t]*)this\.([A-Za-z0-9]+)(.*)function(.*)$";
                string comment       = @"^([ \t]*)\/\/\*.*$";
                string classParam    = @"^([ \t]*)this\.([A-Za-z0-9]+) = (.*)$";
                string extension     = @"^([ \t]*)(.*)(_[A-Z0-9]+)\.([A-Za-z0-9]+)\.(.*)$";

                Regex functionRegex      = new Regex(function, RegexOptions.Multiline);
                Regex classFunctionRegex = new Regex(classFunction, RegexOptions.Multiline);
                Regex commentRegex       = new Regex(comment, RegexOptions.Multiline);
                Regex classParamRegex    = new Regex(classParam, RegexOptions.Multiline);
                Regex extensionRegex     = new Regex(extension, RegexOptions.Multiline);

                int dirlength = Target.FullName.Length - 8;
                targetDir   = Target.FullName;
                targetDir  += Path.FullName.Substring(dirlength) + "\\";
                targetName += file.Name.Replace(".js", ".cpp");

                while ((line = reader.ReadLine()) != null)
                {
                    Match functionMatch      = functionRegex.Match(line);
                    Match classFunctionMatch = classFunctionRegex.Match(line);
                    Match classParamMatch    = classParamRegex.Match(line);
                    if (false == functionMatch.Success &&
                        false == classFunctionMatch.Success &&
                        false == classParamMatch.Success)
                    {
                        Match commentMatch   = commentRegex.Match(line);
                        Match extensionMatch = extensionRegex.Match(line);
                        if (false == commentMatch.Success && true == funcFound)
                        {
                            string ToBuild = "";
                            foreach (string str in funcName.Split(' '))
                            {
                                if (str.Equals("function"))
                                {
                                    ToBuild = "void";
                                }
                                else
                                {
                                    ToBuild += " " + str;
                                }
                            }
                            MyLogger.Alert("No function name provided for function \"" + funcName + "\" temporary replace is: \"" + ToBuild + "\"." + Environment.NewLine);
                            input.Add(ToBuild);
                        }
                        if (commentMatch.Success)
                        {
                            if (isClass == 0 && line.Contains("class"))
                            {
                                isClass = 1;
                            }
                            else if (isClass == 1 && line.Contains("public:"))
                            {
                                isClass = 2;
                            }
                            if (line.Contains("("))
                            {
                                input.Add(line.Replace("//*", "").Replace(";", ""));
                            }
                            else
                            {
                                input.Add(line.Replace("//*", ""));
                            }
                        }
                        else if (extensionMatch.Success)
                        {
                            string ToBuild = "";
                            foreach (string str in line.Split(' '))
                            {
                                string add = "";
                                if (1 < str.Count(f => f == '.'))
                                {
                                    add = str.Replace(".", "::");
                                }
                                else
                                {
                                    add = str;
                                }
                                if (ToBuild.Length > 0)
                                {
                                    ToBuild += " ";
                                }
                                ToBuild += add;
                            }
                            input.Add(ToBuild); // Remake to CPP method calling
                        }
                        else
                        {
                            input.Add(line);
                        }
                        if (0 != isClass &&
                            false == line.Contains("class") &&
                            false == line.Contains("public:"))
                        {
                            isClass = 0;
                        }
                        funcFound = false;
                    }
                    else if (true == functionMatch.Success && isClass != 2)
                    {
                        funcName  = line;
                        funcFound = true;
                    }
                }
            }

            return(retValue);
        }