private bool verifyIntegrity(string userstr) { char[] sep = { ' ', '\t' }; string[] tokens = userstr.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { return(true); } int mid = userStrToMainCmdID(tokens[0]); if (mid == -1) { return(false); } Console.WriteLine("verify integrity : token[0] = " + tokens[0] + " len = " + tokens.Length); if (tokens.Length == 1) { return(true); } SubCommand subcmd = userStrToSubCmdClass(mid, tokens[1]); Console.WriteLine("verify integrity : token[1] = " + tokens[1] + " sub=null? = " + (subcmd == null)); if (subcmd == null) { return(false); } if (tokens.Length == 2) { return(true); } /* * Now start working with token pairs */ for (int i = 2; i < tokens.Length; i += 2) { string ukey = tokens[i]; string uvalue = ((i + 1) > (tokens.Length - 1)) ? null : tokens[i + 1]; if (subcmd.checkIfKeyValueIsValid(false, ukey, uvalue) == false) { return(false); } else if (uvalue == null) { return(true); } } return(true); }
private string autofill_string(string userstr) { Console.WriteLine("::: In autofill_string = " + userstr); char[] sep = { ' ', '\t' }; string[] tokens = userstr.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 1) { //try to match maincmd for (int i = 0; i < maincmdcnt; i++) { if (maincmd[i].IndexOf(tokens[0]) != -1) { return(maincmd[i] + " "); } } return(null); } else if (tokens.Length == 2) { int mid = userStrToMainCmdID(tokens[0]); if (mid == -1) { return(null); } //try to match maincmd for (int i = 0; i < subcommandscnt; i++) { if (subcommands[i].subcmd_name.IndexOf(tokens[1]) == 0 && subcommands[i].is_valid_for_maincmd(mid)) { return(maincmd[mid] + " " + subcommands[i].subcmd_name + " "); } } return(null); } else if (tokens.Length >= 3) //3 or greater. { //we have a token, so we have to search for autofill option. Console.WriteLine("tokenlen 3+ " + userstr); string finalretval = ""; int mid = userStrToMainCmdID(tokens[0]); if (mid == -1) { return(null); } //try to match maincmd SubCommand subcmd = null; for (int i = 0; i < subcommandscnt; i++) { if (subcommands[i].subcmd_name == tokens[1] && subcommands[i].is_valid_for_maincmd(mid)) { subcmd = subcommands[i]; } } if (subcmd == null) { return(null); } finalretval += maincmd[mid] + " " + subcmd.subcmd_name + " "; for (int i = 2; i < tokens.Length; i += 2) { Console.WriteLine("I=" + i + " t=" + tokens[i] + " final=" + finalretval); string ukey = tokens[i]; string uvalue = ((i + 1) > (tokens.Length - 1)) ? null : tokens[i + 1]; //below must be modified to autofill value if the key is correct!. - todo. if (subcmd.checkIfKeyValueIsValid(true, ukey, uvalue) == false) { string str2 = subcmd.autofill_key(tokens[i]); Console.WriteLine("^^^^ failed verificatioin, now do autofill ^^^ str2 = " + str2); if (str2 == null) { return(null); } return(finalretval + str2 + ((uvalue == null) ? " " : " " + uvalue)); } else { finalretval += (ukey + " " + uvalue + " "); } } } //cannot reach return(null); }