public string ParseScriptFiles() { string retValue = ""; CreateXmlFile(); PushScriptExtensionGroup(); foreach (FileInfo file in Path.GetFiles("*.js")) { if (true == file.Name.StartsWith("doc_")) { MyLogger.Log("Skipping file " + file.Name + ", due to doc_ tag." + Environment.NewLine); } else { MyLogger.Log("Parsing file " + file.Name + ": " + Environment.NewLine); MyLogger.IncreaseIndent(); retValue += file.Name + Environment.NewLine; ParseScriptFile(file); } } PopScriptExtensionGroup(); if (null != description) { using (StreamWriter outfile = new StreamWriter(description.Directory + "\\" + FileName, true)) { foreach (string str in input) { outfile.WriteLine(str); } outfile.Close(); } } return(retValue); }
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("&", "&"); formatted = formatted.Replace("<", "<"); formatted = formatted.Replace(">", ">"); formatted = formatted.Replace("\"", """); formatted = formatted.Replace("\'", "'"); input.Add(formatted); } } input.Add(tab + tab + tab + tab + "</Method>"); } }
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); }
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; }
/* * <?xml version="1.0" encoding="UTF-8"?> * <ScriptExtensionGroup> * <ScriptExtension Name ="Alarm Object" Author="Anv" Version="0.1" HomePage ="None"> * <Script Name ="alarm.js" > * */ protected void ParseScriptFile(FileInfo file) { using (StreamReader reader = new StreamReader(file.FullName)) { string line; bool klassFound = false; bool mute = false; string comment = @"^(/\*\*| \* | \*\/){1}.*$"; string klass = @"^\/\/\*class (.*) {.*$"; string _namespace = @"^\/\/\*namespace (.*) {.*$"; string strpublic = @"^//\*public:.*$"; string strprotected = @"^//\*(protected|private):.*$"; string function = @"^function ([A-Za-z0-9_]+)\(.*$"; string endClass = @"^\/\/\*};$"; // Instantiate the regular expression object. Regex commentRegex = new Regex(comment, RegexOptions.Multiline); Regex klassRegex = new Regex(klass, RegexOptions.Multiline); Regex _namespaceRegex = new Regex(_namespace, RegexOptions.Multiline); Regex publicRegex = new Regex(strpublic, RegexOptions.Multiline); Regex protectedRegex = new Regex(strprotected, RegexOptions.Multiline); Regex functionRegex = new Regex(function, RegexOptions.Multiline); Regex endClassRegex = new Regex(endClass, RegexOptions.Multiline); string NameSpace = null; if (true == FileNotBackedUp) { description = new FileInfo(file.Directory + "/" + FileName); if (description.Exists) { string dateFormatted = DateTime.Now.ToString().Replace('-', '.').Replace(':', '.'); string preBackup = description.Name; description.MoveTo(description.FullName + "." + dateFormatted + ".old"); MyLogger.Log("Taking backup of \"" + preBackup + "\" to \"" + description.Name + Environment.NewLine); } else { MyLogger.Log("Didn't find file " + description.Name + " in Directory " + description.Directory + "." + Environment.NewLine); } FileNotBackedUp = false; } while ((line = reader.ReadLine()) != null) { // Do something with line Match commentMatch = commentRegex.Match(line); if (commentMatch.Success) { if (0 < store.Count && commentMatch.Groups[1].ToString().Contains("/**")) { MyLogger.Log("New start of comment received before clear of store."); store.Clear(); } store.Add(line); } Match NameSpaceMatch = _namespaceRegex.Match(line); if (NameSpaceMatch.Success) { NameSpace = NameSpaceMatch.Groups[1].ToString(); } Match klassMatch = klassRegex.Match(line); if (klassMatch.Success) { if (false == klassFound) { MyLogger.Log("Namespace is: " + NameSpace); PushScriptExtension(klassMatch.Groups[1].ToString(), file, NameSpace); klassFound = true; } else { mute = true; } } if (mute && endClassRegex.Match(line).Success) { mute = false; } Match publicMatch = publicRegex.Match(line); if (publicMatch.Success && !mute) { isPublic = true; } Match protectedMatch = protectedRegex.Match(line); if (protectedMatch.Success && !mute) { isPublic = false; } Match functionMatch = functionRegex.Match(line); if (functionMatch.Success) { if (true == isPublic) { CreateMethod(line); } else { MyLogger.Log("Skipping description for function \"" + functionMatch.Groups[1] + "\"." + Environment.NewLine); } store.Clear(); } } if (true == klassFound) { PopScriptExtension(); } MyLogger.DecreaseIndent(); MyLogger.Log("Done parsing file " + file.Name + Environment.NewLine); } }