internal RawTable(RawTable src) { ContainingSpecPart = src.ContainingSpecPart; TableCaption = src.TableCaption; Comment = src.Comment; NumHandles = src.NumHandles; int nRows = src.Table.Length; int nCols = src.Table[0].Length; Table = new string[nRows][]; for (int j = 0; j < nRows; j++) { Table[j] = new string[nCols]; for (int k = 0; k < nCols; k++) { Table[j][k] = src.Table[j][k]; } } }
internal static void Add(SpecPart part, string caption, string comment, string[,] contents, int numHandles) { int len1 = contents.GetLength(0); int len2 = contents.GetLength(1); string[][] temp = new string[len1][]; for (int j = 0; j < len1; j++) { temp[j] = new string[len2]; for (int k = 0; k < len2; k++) { temp[j][k] = contents[j, k]; } } Tables.Add(new RawTable { ContainingSpecPart = part, TableCaption = caption, Comment = comment, Table = temp, NumHandles = numHandles }); }
void ProcessDoc(string docName, SpecPart specPart) { app = new Application(); //app.Visible = true; sourceDoc = app.Documents.Open(docName, Visible: true, ReadOnly: false); if (sourceDoc.TrackRevisions) { sourceDoc.AcceptAllRevisions(); } Paragraph para, prevHeading = null; int tableCount = sourceDoc.Tables.Count; for (int j = 1; j <= tableCount; j++) { Table tbl = sourceDoc.Tables[j]; int rowCount = tbl.Rows.Count; int colCount = tbl.Columns.Count; Range tableRange = tbl.Range; para = tableRange.Paragraphs[1].Previous(); string tableText = tableRange.Text; string tableCaption = para.Range.Text; tableCaption = tableCaption.TrimEnd(new char[] { '\r' }); if (!tableCaption.StartsWith("Table") || tableCaption.Contains("xx")) { // Skip illustrative tables Console.WriteLine("{0}: Ignoring '{1}'", specPart, tableCaption); continue; } if (specPart == SpecPart.Commands) { // fingerprint for tables if (!(tableCaption.EndsWith("Command") || tableCaption.EndsWith("Response"))) { Console.WriteLine("{0}: Skipping '{1}'", specPart, tableCaption); continue; } // Try to extract a description for the command. // Go back to the "General Description" and then get the next paragraph. while (!para.Range.Text.Contains("General Description")) { para = para.Previous(); } } else { // fingerprint for tables if (!(tableCaption.Contains("Definition") || tableCaption.Contains("Defines for"))) { Console.WriteLine("{0}: Skipping '{1}'", specPart, tableCaption); continue; } // Try to extract a comment for the definition. // Heuristic: Go back to find a heading that looks promising // and then take the next paragraph. while (!(para.get_Style() as Style).NameLocal.StartsWith("Heading") || para.Range.Text.StartsWith("Structure Definition")) { para = para.Previous(); } if (prevHeading == para) { // Current table does not have a description paragraph. // Use table caption as a comment para = tableRange.Paragraphs[1].Previous().Previous(); } else { // Mark the current stop-heading to avoid its reuse for the // next possibly comment-less table. prevHeading = para; } } int numHandles; string[,] stringTable = WordTableToStringTable(tbl, out numHandles, TrimNonPrintable(tableCaption)); RawTables.Add(specPart, TrimNonPrintable(tableCaption), TrimNonPrintable(para.Next().Range.Text), // comment text stringTable, numHandles); } ((Microsoft.Office.Interop.Word._Document)sourceDoc).Close(WdSaveOptions.wdDoNotSaveChanges); ((Microsoft.Office.Interop.Word._Application)app).Quit(WdSaveOptions.wdDoNotSaveChanges); }
protected void when_parsing_the_specline() { TheSpecPart = SpecPartFactory.Create(SpecLine); }