/// <summary> /// sscanf with 6 results /// </summary> public static int sscanf <T1, T2, T3, T4, T5, T6>(String input, String format, ref T1 r1, ref T2 r2, ref T3 r3, ref T4 r4, ref T5 r5, ref T6 r6) { var parser = new ScanFormatted(); parser.Parse(input, format); var res = parser.Results.Count; if (res > 0) { r1 = (T1)parser.Results[0]; } if (res > 1) { r2 = (T2)parser.Results[1]; } if (res > 2) { r3 = (T3)parser.Results[2]; } if (res > 3) { r4 = (T4)parser.Results[3]; } if (res > 4) { r5 = (T5)parser.Results[4]; } if (res > 5) { r6 = (T6)parser.Results[5]; } return(res); }
private void btnValidate_Click(object sender, EventArgs e) { ScanFormatted sf = new ScanFormatted(); sf.Parse(txtBoxLogEntry.Text.Trim(), txtBoxPattern.Text.Trim()); var isSuccess = IsParsingSuccessful(sf.Results); var ds = new List <KeyValuePair <int, string> >(); int i = 0; foreach (var res in sf.Results) { ds.Add(new KeyValuePair <int, string>(i, res.ToString())); i++; } if (!isSuccess) { dGVResults.ForeColor = Color.Red; lblResult.BackColor = Color.Red; lblResult.ForeColor = Color.White; lblResult.Text = "Error"; } else { dGVResults.ForeColor = Color.Green; lblResult.BackColor = Color.Green; lblResult.ForeColor = Color.White; lblResult.Text = "OK"; } dGVResults.DataSource = ds; dGVResults.ClearSelection(); }
/// <summary> /// sscanf with 1 result /// </summary> public static int sscanf <T>(String input, String format, ref T r) { var parser = new ScanFormatted(); parser.Parse(input, format); var res = parser.Results.Count; if (res > 0) { r = (T)parser.Results[0]; } return(res); }
/// <summary> /// sscanf with 2 results /// </summary> public static int sscanf <T1, T2>(String input, String format, ref T1 r1, ref T2 r2) { var parser = new ScanFormatted(); parser.Parse(input, format); var res = parser.Results.Count; if (res > 0) { r1 = (T1)parser.Results[0]; } if (res > 1) { r2 = (T2)parser.Results[1]; } return(res); }
private void LoadMeshStream(Stream fileStream) { int triangleMode = -1; int ret; var alignedIndexes = true; var scan = new ScanFormatted(); using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, 4096)) { string line; while ((line = streamReader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line) || line.Length < 2) { continue; } if (line[0] == 'v') { if (line[1] == 'n') { ret = scan.Parse(line, "vn %f %f %f"); if (ret > 0) { Normals.Add(new Vector3((float)scan.Results[0], (float)scan.Results[1], (float)scan.Results[2])); } } else if (line[1] == 't') { ret = scan.Parse(line, "vt %f %f"); if (ret > 0) { UV.Add(new Vector2((float)scan.Results[0], (float)scan.Results[1])); } } else if (line[1] == ' ') { ret = scan.Parse(line, "v %f %f %f %f %f %f"); if (ret > 0) { Vertices.Add(new Vector3((float)scan.Results[0], (float)scan.Results[1], (float)scan.Results[2])); } if (ret == 6) { Colors.Add(new Color((float)scan.Results[3], (float)scan.Results[4], (float)scan.Results[5])); } } } else if (line[0] == 'f') { Triangle tri = null; // triangleMode // -1: unknown so try stuff // 1: vertex and uv included // 2: vertex and normal included // 3: vertex and uv and normal included switch (triangleMode) { case -1: // trying vertex and normal only ret = scan.Parse(line, "f %u//%u %u//%u %u//%u"); if (ret == 6) { triangleMode = 2; tri = new Triangle ((uint)scan.Results[0] - 1, 0, (uint)scan.Results[1] - 1, (uint)scan.Results[2] - 1, 0, (uint)scan.Results[3] - 1, (uint)scan.Results[4] - 1, 0, (uint)scan.Results[5] - 1); } else { // trying vertex and uv only ret = scan.Parse(line, "f %u/%u %u/%u %u/%u"); if (ret == 6) { triangleMode = 1; tri = new Triangle ((uint)scan.Results[0] - 1, (uint)scan.Results[1] - 1, 0, (uint)scan.Results[2] - 1, (uint)scan.Results[3] - 1, 0, (uint)scan.Results[4] - 1, (uint)scan.Results[5] - 1, 0); } else { // default to the whole thing triangleMode = 3; ret = scan.Parse(line, "f %u/%u/%u %u/%u/%u %u/%u/%u"); if (ret == 9) { tri = new Triangle ((uint)scan.Results[0] - 1, (uint)scan.Results[1] - 1, (uint)scan.Results[2] - 1, (uint)scan.Results[3] - 1, (uint)scan.Results[4] - 1, (uint)scan.Results[5] - 1, (uint)scan.Results[6] - 1, (uint)scan.Results[7] - 1, (uint)scan.Results[8] - 1); } } } break; case 1: ret = scan.Parse(line, "f %u/%u %u/%u %u/%u"); if (ret == 6) { tri = new Triangle ((uint)scan.Results[0] - 1, (uint)scan.Results[1] - 1, 0, (uint)scan.Results[2] - 1, (uint)scan.Results[3] - 1, 0, (uint)scan.Results[4] - 1, (uint)scan.Results[5] - 1, 0); } break; case 2: ret = scan.Parse(line, "f %u//%u %u//%u %u//%u"); if (ret == 6) { tri = new Triangle ((uint)scan.Results[0] - 1, 0, (uint)scan.Results[1] - 1, (uint)scan.Results[2] - 1, 0, (uint)scan.Results[3] - 1, (uint)scan.Results[4] - 1, 0, (uint)scan.Results[5] - 1); } break; case 3: ret = scan.Parse(line, "f %u/%u/%u %u/%u/%u %u/%u/%u"); if (ret == 9) { tri = new Triangle ((uint)scan.Results[0] - 1, (uint)scan.Results[1] - 1, (uint)scan.Results[2] - 1, (uint)scan.Results[3] - 1, (uint)scan.Results[4] - 1, (uint)scan.Results[5] - 1, (uint)scan.Results[6] - 1, (uint)scan.Results[7] - 1, (uint)scan.Results[8] - 1); } break; default: break; } if (tri != null) { if (!tri.IsNormalAligned) { alignedIndexes = false; } Triangles.Add(tri); } } } } // I'm sure I could do this part better where I could preserve all the data and just add new vertices instead if (!alignedIndexes) { AlignNormals(); } Debug.WriteLine($"Loaded with {Vertices.Count} Vertices, {Normals.Count} Normals, {Colors.Count} Colors, {Triangles.Count} Triangles"); }
public FusionReader( string filename ) { recordFile = filename; // Reading file... Console.Important("Ready to read '" + recordFile + "'."); reader = new StreamReader( recordFile ); if (reader == null) { Console.Important("Recorded file '" + recordFile + "' can't be read."); } PassHeader (); scanner = new ScanFormatted(); }
// http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net internal bool GetLastUpdateVersion(out MedocVersion version) { version = new MedocVersion(); ScanFormatted parser = new ScanFormatted(); string[] allLogFiles = new string[0]; if (!GetLatestLogs(out allLogFiles)) { return(false); } for (int i = allLogFiles.Length - 1; i >= 0; i--) { string logFile = allLogFiles[i]; if (logFile.Trim().Length <= 0) { Log.Write(LogLevel.EXPERT, "MedocInternal: Unexpected log list searching error"); continue; } // string[] file = new string[] { }; try { file = File.ReadAllLines(logFile); } catch (Exception ex) { Log.Write(LogLevel.NORMAL, "Cannot read a latest log file\r\n" + ex.Message); } // Search from the end to start of the file for (int j = file.Length - 1; j >= 0; j--) { string line = file[j]; // bool foundNewVerString = GetLine(line, "newVer"); if (!foundNewVerString) { continue; } int newVerIdx = line.IndexOf("newVer"); if (newVerIdx + "newVer".Length >= line.Length) { continue; } line = line.Substring(newVerIdx); // ScanFormatted fricks stuff up after parsing %s for some reason (doesn't care it's Ukrainian word of English (i.e. "is1C = False")) //string lineformat = "%d.%d.%d %d:%d:%d.%d %s INFO %s: is1C = %s, newVer = %d, newRel = %d, newBld = %d"; string lineformat = "newVer = %d, newRel = %d, newBld = %d"; int count = parser.Parse(line, lineformat); //if(count > 9 /*&& count <= 13*/) if (count == 3) { version = new MedocVersion((int)parser.Results[0], (int)parser.Results[1], (int)parser.Results[2]); Console.WriteLine("Found version: {0}", version.Version); return(true); } } } return(false); }