/// <summary> /// Command line parser and executer /// </summary> /// <param name="args">The command list</param> /// <returns>The return code, 0 for success, 1 for error.</returns> private static int ParseAndExec(IEnumerable<string> args) { // switch to script mode appScriptMode = true; currentArgs = args; argsIndex = 0; int res = 0; string cmd = string.Empty; bool done = false; while (done == false) { string tok = GetNextToken(); if (tok == string.Empty) { break; } int paramNumber = IsCommand(tok); if (paramNumber < 0) { Http2Logger.LogError("Unknown command " + tok); return 1; } cmd = tok; string paramString = string.Empty; while (paramNumber != 0) { tok = GetNextToken(); if (tok == string.Empty) { done = true; break; } if (IsCommand(tok) >= 0) { // HELP command is legal, for everything else we find next command if (cmd.ToUpper() == "HELP") { // add to list of parameters for current command if (paramString != string.Empty) { paramString += " "; } paramString += tok; paramNumber--; } else { PutBackToken(); paramNumber = 0; } } else { // add to list of parameters for current command if (paramString != string.Empty) { paramString += " "; } paramString += tok; paramNumber--; } } ArgPair argpair = new ArgPair(cmd, paramString); Parameters.Enqueue(argpair); } while ((Parameters.Count != 0) && (res == 0)) { ArgPair ap = (ArgPair)Parameters.Dequeue(); res = ExecuteOneCommand(ap.Cmd, ap.Value); if (res == 0) { Thread.Sleep(400); } } return res; }
/// <summary> /// Command line parser and executer /// </summary> /// <param name="args">The command list</param> /// <returns>The return code, 0 for success, 1 for error.</returns> private static int ParseAndExec(string[] args) { int res = 0; bool needNext = false; string cmd = string.Empty; foreach (string txt in args) { if (needNext) { ArgPair argpair = new ArgPair(cmd, txt); needNext = false; parameters.Enqueue(argpair); } else { switch (txt.ToUpper()) { case "CLOSE": case "HELP": case "DIR": case "DUMP-STATS": case "EXIT": ArgPair argpair = new ArgPair(txt, string.Empty); parameters.Enqueue(argpair); break; case "CAPTURE-STATS": case "CONNECT": case "GET": case "HTTPGET": case "RUN": case "SAVE-STATS": case "VERBOSE": cmd = txt; needNext = true; break; default: SMLogger.LogError("Unknown command " + txt); return 1; } } } if (needNext) { SMLogger.LogError("Command " + cmd + " missing value."); return 1; } while ((parameters.Count != 0) && (res == 0)) { ArgPair ap = (ArgPair)parameters.Dequeue(); res = ExecuteOneCommand(ap.Cmd, ap.Value); Thread.Sleep(400); } return 0; }