/// <summary> /// We require the xml job file as the last argument. /// </summary> /// <param name="args"></param> /// <returns></returns> private static string ParseArgs(string[] args) { if (args.Length == 0) { return("No job file specified."); } if (args.Length == 1) { return(null); } char c; XGetopt go = new XGetopt(); // Note: feed Getopt a string list of flag characters. A character followed by a colon causes it to // consume two args, placing the second in the Optarg property. // For example: "sa:v:" correctly parses "-s -a 3 -v 2" while ((c = go.Getopt(args.Length - 1, args, "mtp:")) != '\0') { //Console.WriteLine("Getopt returned '{0}'", c); switch (c) { case 'm': //Generate mobile version m_MakeMobileVersion = true; break; case 't': m_Test = true; break; case 'p': m_Profile = go.Optarg; break; case '?': return("Illegal or missing argument"); } } //Enforce any constraints here. //Anything left over triggers an error too: if (go.Optarg != "") { return("Unexpected arguments: " + go.Optarg); } if ((m_Profile != null) && (!m_MakeMobileVersion)) { return("-p is only allowed with -m"); } return(null); }
private static void parse_f_option(XGetopt go) { if (go.Optarg == "function-sections") { func_sects = true; } else if (go.Optarg == "data-sections") { data_sects = true; } else if (go.Optarg == "class-sections") { class_sects = true; } else { throw new NotImplementedException(); } }
static SetupOptions ParseSetupOption(string[] args) { var parser = new XGetopt(); char c = '\0'; var opt = new SetupOptions(); while ((c = parser.Getopt(args.Length, args, "c:")) != '\0') { switch (c) { case 'h': default: SetupUsage(); return(null); } } opt.DropAndCreateDatabase = true; return(opt); }
private static void Main(string[] args) { int length = args.Length; bool flag1 = false; bool flag2 = false; bool flag3 = false; bool verbose = false; XGetopt xgetopt = new XGetopt(); char ch; while ((int)(ch = xgetopt.Getopt(length, args, "updv")) != 0) { switch (ch) { case 'd': flag3 = true; continue; case 'p': flag2 = true; continue; case 'u': flag1 = true; continue; case 'v': verbose = true; continue; default: Program.error(string.Format("unknown option: -{0}", (object)ch)); return; } } if (flag2 && flag1 || !flag2 && !flag1) { Program.error("You can set only one command option."); } else if (length - xgetopt.Optind < 1 && length - xgetopt.Optind > 2) { Program.error("You need to set at least input file path. Output file path is optional."); } else { string fullPath = Path.GetFullPath(args[xgetopt.Optind]); string dst = length - xgetopt.Optind != 1 ? Path.GetFullPath(args[xgetopt.Optind + 1]) : (!flag1 ? Path.GetFullPath(args[xgetopt.Optind]) : Path.GetFullPath(Path.GetFileNameWithoutExtension(args[xgetopt.Optind]))); try { if (flag1) { Program.unpack(fullPath, dst, verbose); } else { Program.pack(fullPath, dst, verbose); } } catch (FileNotFoundException ex) { Program.error(ex.Message); if (!flag3) { return; } Program.debugException((Exception)ex); } catch (IOException ex) { Program.error(ex.Message); if (!flag3) { return; } Program.debugException((Exception)ex); } catch (Exception ex) { Program.error(ex.Message); if (!flag3) { return; } Program.debugException(ex); } } }