From 5a7af006a83a06697d14c5f9b50af8ee69f42ceb Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 23 Jun 2011 21:29:00 +0000 Subject: [PATCH] Only convert Page and Document formats is the related Format file exists. Skip commented lines in INI file. Remove inline comments before processing INI file. Use more explicit comparisons to determine type of command. Replace spaces with {sp}. --- PROMS/fmtxml/FmtToXml.cs | 32 ++++++++++++++++++-------------- PROMS/fmtxml/PSI.cs | 40 ++++++++++++++++++++++++++++++---------- PROMS/fmtxml/RtfToSvg.cs | 1 + 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/PROMS/fmtxml/FmtToXml.cs b/PROMS/fmtxml/FmtToXml.cs index c44310c6..c69d9d21 100644 --- a/PROMS/fmtxml/FmtToXml.cs +++ b/PROMS/fmtxml/FmtToXml.cs @@ -488,20 +488,22 @@ namespace fmtxml try { // get the default base & plant files to use when figuring out inheritance. - GetPlantBaseDefaultFonts(); + if (GetPlantBaseDefaultFonts()) + { - // will have entire name, such as aep.x01 - use number to differentiate it. - int indx = nm.IndexOf('.'); - if (indx > 0) - { - LoadPageFile(nm); - LoadDocFile(nm); - } - else - { - LoadPageFile(nm + ".pag"); - LoadDocFile(nm + ".doc"); - } + // will have entire name, such as aep.x01 - use number to differentiate it. + int indx = nm.IndexOf('.'); + if (indx > 0) + { + LoadPageFile(nm); + LoadDocFile(nm); + } + else + { + LoadPageFile(nm + ".pag"); + LoadDocFile(nm + ".doc"); + } + } } catch (Exception ex) { @@ -1144,7 +1146,9 @@ namespace fmtxml int indx = fmtName.IndexOf('.'); if (indx > 0) lfmtName = fmtName.Substring(0, fmtName.Length - 4) + "_" + fmtName.Substring(fmtName.Length - 2, 2); - xdoc.Load("fmt_xml\\" + lfmtName + "f.xml"); + string fName = "fmt_xml\\" + lfmtName + "f.xml"; + if (!File.Exists(fName)) return false; + xdoc.Load(fName); xfont = xdoc.SelectSingleNode("FormatData/Font"); if (xfont!=null)DefPlantFont = new VE_Font(xfont); } diff --git a/PROMS/fmtxml/PSI.cs b/PROMS/fmtxml/PSI.cs index 3c366e7f..5e4c80fc 100644 --- a/PROMS/fmtxml/PSI.cs +++ b/PROMS/fmtxml/PSI.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using System.IO; using System.Xml; +using System.Text.RegularExpressions; namespace fmtxml { @@ -13,6 +14,16 @@ namespace fmtxml private int NumTexts = 0; private int NumFields = 0; private int CountForLists = 0; + private Regex removeComment = new Regex("/[*].*?[*]/"); + private Regex removeComment1 = new Regex("/[*].*?$"); + private Regex removeComment2 = new Regex("[*]/"); + private string RemoveComments(string inStr) + { + string str = removeComment.Replace(inStr, ""); + str = removeComment1.Replace(str, ""); + str = removeComment2.Replace(str, ""); + return str; + } public void PsiIniToXml(ref FormatData fmtdata, string path) { string sLine; @@ -31,17 +42,20 @@ namespace fmtxml { // read in the count of objects - these may not be in order, fix this: sLine = myReader.ReadLine(); + while(sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments int indx = sLine.IndexOf("="); string tmp = sLine.Substring(indx + 1, sLine.Length - indx - 1); - NumBoxes = Convert.ToInt32(tmp); + NumBoxes = Convert.ToInt32(RemoveComments(tmp)); sLine = myReader.ReadLine(); + while (sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments indx = sLine.IndexOf("="); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); - NumTexts = Convert.ToInt32(tmp); + NumTexts = Convert.ToInt32(RemoveComments(tmp)); sLine = myReader.ReadLine(); + while (sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments indx = sLine.IndexOf("="); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); - NumFields = Convert.ToInt32(tmp); + NumFields = Convert.ToInt32(RemoveComments(tmp)); fmtdata.ProcData.Psi.Boxes = new PsiBox[NumBoxes]; fmtdata.ProcData.Psi.Labels = new PsiLabel[NumTexts]; fmtdata.ProcData.Psi.Fields = new PsiField[NumFields]; @@ -59,7 +73,7 @@ namespace fmtxml default: if (sLine.IndexOf("=") >= 0) { - AddParam(ref fmtdata, sLine); + AddParam(ref fmtdata, RemoveComments(sLine)); } break; } @@ -72,11 +86,17 @@ namespace fmtxml } myReader.Close(); } + private Regex findBOX = new Regex("^BOX[0-9]+$"); + private Regex findSIZE = new Regex("^SIZE$"); + private Regex findFONT = new Regex("^FONT$"); + private Regex findCAPTION = new Regex("^CAPTION$"); + private Regex findBUTTONSONBOTTOM = new Regex("^BUTTONSONBOTTOM$"); + private Regex findTEXT = new Regex("^TEXT[0-9]+$"); private void AddParam(ref FormatData fmtdata, string sParam) { int i = sParam.IndexOf("="); string attrname = sParam.Substring(0, i); - if (attrname.Contains("SIZE")) + if (findSIZE.IsMatch(attrname)) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; string sb = sParam.Substring(i + 1, end - i - 1); @@ -85,7 +105,7 @@ namespace fmtxml fmtdata.ProcData.Psi.y = Convert.ToInt32(split[1].Trim()); return; } - if (attrname.Contains("FONT")) + if (findFONT.IsMatch(attrname)) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; string sb = sParam.Substring(i + 1, end - i - 1); @@ -93,19 +113,19 @@ namespace fmtxml fmtdata.ProcData.Psi.font = split[0].Trim(); return; } - if (attrname.Contains("CAPTION")) + if (findCAPTION.IsMatch(attrname)) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; fmtdata.ProcData.Psi.Caption = sParam.Substring(i + 1, end-i-1).Replace("\"",""); return; } - if (attrname.Contains("BUTTONSONBOTTOM")) + if (findBUTTONSONBOTTOM.IsMatch(attrname)) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; fmtdata.ProcData.Psi.ButtonsOnBottom = sParam.Substring(i + 1, end - i - 1); return; } - if (attrname.Contains("BOX")) + if (findBOX.IsMatch(attrname)) // attrname.StartsWith("BOX")) { // int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; @@ -119,7 +139,7 @@ namespace fmtxml CountForLists++; return; } - if (attrname.Contains("TEXT")) + if (findTEXT.IsMatch(attrname)) { //