private string[] SplitLine(string cmdLine) { string cmd = TextHndlr.CutCommand(cmdLine); string[] result = { }; string[] temp = { }; temp = cmdLine.Split(new char[] { ';', ',' }); result = (string[])temp.Clone(); for (int i = 0; i < result.Length; i++) { for (int n = 0; n < result[i].Length; n++) { if (TextHndlr.IsLetter(result[i][n].ToString())) { temp[i] = result[i].Substring(n + 1); } else if (TextHndlr.IsNumber(result[i][n].ToString())) { continue; } else { if (result[i][n] != '.' && result[i][n] != '-') { temp[i] = result[i].Substring(n + 1); } } } if (temp[i] == "") { Array.Clear(temp, i, 1); } } result = (string[])temp.Clone(); temp = new string[] { }; for (int i = 0; i < result.Length; i++) { if (result[i] != null) { Array.Resize(ref temp, temp.Count() + 1); temp[temp.Count() - 1] = result[i]; } } result = temp; return(result); }
/// <summary> /// Sets color of the pen /// </summary> /// <param name="cmdLine">Current command line</param> /// <returns>True or false whether tool is changed or not</returns> public virtual bool Tool(string cmdLine) { if (cmdLine[cmdLine.Length - 1] == ';') { cmdLine = cmdLine.Substring(0, cmdLine.Length - 1).Trim(); } if (cmdLine[0] == 'M') { cmdLine = TextHndlr.NextCommand(cmdLine, "M"); } int color; // Skip command after tool select if (cmdLine.Contains('F')) { color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('F') - 1).Trim()); } else if (cmdLine.Contains('H')) { color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('M') - 1).Trim()); } else if (cmdLine.Contains('T')) { if (cmdLine.Substring(1).Contains('M')) { color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('M') - 1)); } else { color = int.Parse(cmdLine.Substring(1).Trim()); } } else if (cmdLine.Contains("SP")) { color = int.Parse(cmdLine.Substring(2).Trim()); } else if (TextHndlr.IsNumber(cmdLine.Substring(1))) { color = int.Parse(cmdLine.Substring(1).Trim()); } else { color = Color; } // Set color Color = color; return(true); }
/// <summary> /// Call a new sub /// </summary> /// <param name="cmdLine">Current command line</param> /// <returns>True of false whether a new sub is called or not</returns> public virtual bool CallSubmain(string cmdLine) { if (TextHndlr.IsNumber(cmdLine[1].ToString())) { NewSubMain = int.Parse(cmdLine.Substring(1), CultureInfo.InvariantCulture); // Call the sub Output.OutputInstance(NewSubMain, LastX, LastY); if (!SubColors.ContainsKey(NewSubMain.ToString())) { SubColors.Add(NewSubMain.ToString(), Color); } } return(true); }
/// <summary> /// Begins writing a new sub /// </summary> /// <param name="cmdLine">Current command line</param> /// <returns>True of false whether a new sub began</returns> public virtual bool StartSub(string cmdLine) { string result = ""; // Sub keywords string[] subRefs = { "P", "O", "DFS", "$PROGIN", "%" }; // String used to detect start of sub string thisSubRef = ""; bool subFound = false; // Look for the sub reference in line for (int i = 0; i < cmdLine.Length && !subFound; i++) { for (int n = 0; n < subRefs.Length && !subFound; n++) { if (cmdLine[i] == subRefs[n][0]) { if (cmdLine.Substring(i, subRefs[n].Length) == subRefs[n]) { subFound = true; thisSubRef = subRefs[n]; } } } } // Get index of current sub switch (thisSubRef) { case "P": result = cmdLine.Substring(cmdLine.IndexOf(thisSubRef) + thisSubRef.Length); break; case "O": result = cmdLine.Substring(cmdLine.IndexOf(thisSubRef) + thisSubRef.Length); break; case "DFS": result = cmdLine.Substring(cmdLine.IndexOf('P') + 1, (cmdLine.IndexOf(',') + cmdLine.Substring(cmdLine.IndexOf(',') + 1).IndexOf(',')) - cmdLine.IndexOf('P')); break; case "$PROGIN": result = cmdLine.Substring(cmdLine.IndexOf(thisSubRef) + thisSubRef.Length); break; case "%": if (cmdLine.Length > 1 && TextHndlr.IsNumber(cmdLine.Substring(cmdLine.IndexOf("%")) + 1)) { result = cmdLine.Substring(cmdLine.IndexOf(thisSubRef) + thisSubRef.Length); } else { return(true); } break; default: result = ""; break; } if (TextHndlr.IsNumber(result)) { CurrentSub = result; } if (TextHndlr.IsNumber(result) && (!SubFirst && !IsLastSub) && !SubOpen) { // Change current sub CurrentSub = result; // Start new section Output.OutputSectionStart(CurrentSub, CurrentSub); // The sub is now open SubOpen = true; LastX = 0; LastY = 0; } else if (TextHndlr.IsNumber(result) && (SubFirst || IsLastSub) && !SubOpen) { CurrentSub = result; BoxOpen = true; Output.OutputBoxEnd(); Output.OutputBoxStart(CurrentSub); Output.OutputSectionStart(CurrentSub, CurrentSub); LastX = 0; LastY = 0; } return(true); }