static void Main(string[] args) { if( args.Length < 1 ) { Console.WriteLine("Usage GenerateCode.exe <packageName>"); return; } // This is the code for the base process Process myProcess = new Process(); // Start a new instance of this program but specify the 'spawned' version. ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("rospack", "spawn"); myProcessStartInfo.UseShellExecute = false; myProcessStartInfo.RedirectStandardOutput = true; myProcess.StartInfo = myProcessStartInfo; myProcess.StartInfo.Arguments = "find " + args[0]; myProcess.Start(); StreamReader myStreamReader = myProcess.StandardOutput; // Read the standard output of the spawned process. outputPath = myStreamReader.ReadLine(); myProcess.WaitForExit(); myProcess.Close(); string templateDir = TemplateDir(); if(!Directory.Exists(templateDir)) { Console.Error.WriteLine("Cannot find template directory: "+templateDir); return; } if(args[0].Contains("/")) { int idx = args[0].LastIndexOf('/'); basePackageName = args[0].Substring(idx+1); } else { basePackageName = args[0]; } if( String.IsNullOrEmpty(outputPath)) { Console.WriteLine("Cannot find package name!"); return; } outputPath += "/msg_cs_gen"; //set namespace to packageName namespaceS = args[0]; Console.WriteLine("Querying Ros for messages..."); List<Message> directMessages = MessagesOfPackage(args[0]); for (int i=1; i<args.Length; i++) { if (args[i].EndsWith("/*")) { directMessages.AddRange(MessagesOfPackage(args[i].Substring(0,args[i].Length-2))); } else { directMessages.Add(new Message(args[i])); } } Dictionary<string,Message> allMessages = new Dictionary<string, Message>(); foreach(Message m in directMessages) { allMessages.Add(m.FullName,m); } List<Message> todo = directMessages; do { List<string> addMessages = new List<string>(); foreach(Message m in todo) { List<string> reqmessage = m.RequiredMessages(); addMessages.AddRange(reqmessage); } todo.Clear(); foreach(string nmsg in addMessages) { if (!allMessages.ContainsKey(nmsg)) { Message nmessage = new Message(nmsg); allMessages.Add(nmsg,nmessage); todo.Add(nmessage); } } } while(todo.Count > 0); foreach(Message m in allMessages.Values) { m.SetReferences(allMessages); } Console.WriteLine("Start generating..."); Console.WriteLine("Path for generating files : " + outputPath + "!"); Console.WriteLine("Total msges: {0}",allMessages.Count); //clean autogen before generating //Console.WriteLine(pwd); if( Directory.Exists(outputPath) ) { Console.WriteLine("Cleaning before..."); Directory.Delete(outputPath,true); } msgList = new List<Message>(allMessages.Values); CheckForHashCollisions(msgList); Directory.CreateDirectory(outputPath); Directory.CreateDirectory(outputPath+"/cpp"); Directory.CreateDirectory(outputPath+"/csharp"); CreateCppCode(outputPath+"/cpp"); ProcessTemplates(templateDir,outputPath); CreateCSMessages(outputPath+"/csharp"); }
public static string ProcessTemplate(string t,Message m) { curMessage = m; Regex markers = new Regex(@"<\?([^\?]*)\?>"); return markers.Replace(t,new MatchEvaluator(MatchReplacer)); }