// Para Compare Versions with Attributes /* // Para Compare Versions //--------------------------------------------------------------------------- // Function: Compare any two versions of the current module // including attributes in the two versions. //--------------------------------------------------------------------------- //********************************** History ****************************** // Name: Date: // Jürgen Albrecht 2008-01-15 // Reinhold Lauer 2010-10-19 //--------------------------------------------------------------------------- */ pragma runLim, 0 Module mLaunchingModule = null Stream strmOutput string strCellBorders = "\\clbrdrt\\brdrs\\brdrw15\\brdrcf11 \\clbrdrl\\brdrs\\brdrw15\\brdrcf11 \\clbrdrb\\brdrs\\brdrw15\\brdrcf11 \\clbrdrr\\brdrs\\brdrw15\\brdrcf11 " Regexp isSlash = regexp "[\\\\]" Regexp isColorTable = regexp "colortbl[^}]*}" DB dbVersionCompare = null DBE dbeListNewer = null DBE dbeListOlder = null DBE dbeAttrNameList = null DBE dbeOutputFileBrowse = null DBE dbeShowAsMarkup = null // dummy call back function void doNothing(DBE dbeKlick, int iKlick) { } // add elements to a sorted list if the element is not listed void addElementToList(DBE dbeList, string sNewElementName) { int iElementPosition for (iElementPosition=0; iElementPosition sNewElementName) break // insert here } insert (dbeList, iElementPosition, sNewElementName) set (dbeList, iElementPosition, true) } // fill the attributes list with module attributes void addModuleAttibutesToList(Module mModule) { AttrDef adAttrDefinition for adAttrDefinition in mModule do { if (adAttrDefinition.module || adAttrDefinition.system) continue addElementToList(dbeAttrNameList, adAttrDefinition.name "") } } // compare an attribute of two objects with same absolute number or agaist a null object bool compareObjects(Object oNewer, oOlder, string sAttrName) { Buffer buffNewerAttr = create Buffer buffOlderAttr = create Buffer buffAttrDifference = create bool bShowAsMarkup = get dbeShowAsMarkup string sNewerAttr = null string sOlderAttr = null Object oConcerned sNewerAttr = probeAttribute_(oNewer, sAttrName, false) if (!null sNewerAttr) buffNewerAttr = sNewerAttr else buffNewerAttr = "" sOlderAttr = probeAttribute_(oOlder, sAttrName, false) if (!null sOlderAttr) buffOlderAttr = sOlderAttr else buffOlderAttr = "" if(!null oNewer) oConcerned = oNewer else oConcerned = oOlder if (buffNewerAttr!=buffOlderAttr) { strmOutput << "\\trowd \\trgaph108\\trleft-108\\trkeep" if (bShowAsMarkup) { diff(buffAttrDifference, buffOlderAttr, buffNewerAttr, "\\cf1\\strike ", "\\cf3 ") string sRTFragment if (isColorTable buffAttrDifference) { sRTFragment = buffAttrDifference[end 0 + 1:(length buffAttrDifference) - 3] } else { sRTFragment = richTextFragment stringOf(buffAttrDifference) } strmOutput << strCellBorders "\\cellx1026 " strCellBorders "\\cellx2727 " strCellBorders "\\cellx9531\n" strmOutput << "\\intbl \\b \\fs16 " identifier(oConcerned) "\\b0 \\cell " sAttrName "\\cell " sRTFragment "\\cell\\row\n" } else { sNewerAttr = richTextFragment probeRichAttr_(oNewer, sAttrName, false) sOlderAttr = richTextFragment probeRichAttr_(oOlder, sAttrName, false) strmOutput << strCellBorders "\\cellx1026 " strCellBorders "\\cellx2727 " strCellBorders "\\cellx6129 " strCellBorders "\\cellx9531\n" strmOutput << "\\intbl \\b \\fs16 " identifier(oConcerned) "\\b0 \\cell " sAttrName "\\cell " sOlderAttr "\\cell " sNewerAttr "\\cell\\row\n" } delete buffNewerAttr delete buffOlderAttr delete buffAttrDifference return false } delete buffNewerAttr delete buffOlderAttr delete buffAttrDifference return true } // Build a skip list which maps absolute numbers onto their corresponding objects Skip getAbsoluteNumbers(Module mModule) { Skip skResult = create Object oObject for oObject in mModule do { int iAbsultueNumber = oObject."Absolute Number" put(skResult, iAbsultueNumber, oObject) } return skResult } // Compare two the two versions of the module void applyCompareVersions (DB dbKlick) { int iNewerIndex = get dbeListNewer // position in list int iOlderIndex = get dbeListOlder string sNewerName = get dbeListNewer // baseline name string sOlderName = get dbeListOlder string sOutputFileName = get dbeOutputFileBrowse string sCurrentModuleName = mLaunchingModule."Name" if (iNewerIndex >= iOlderIndex) // the newer version is the same or older as the old version { ack "The selected newer version is not newer than the older version!\nSelect other versions..." return } if (!isSlash sOutputFileName) { sOutputFileName = currentDirectory "\\" sOutputFileName } strmOutput = write sOutputFileName strmOutput << "{\\rtf1\\deff0{\\fonttbl{\\f0\\fswiss\\fcharset177 Times New Roman;}}{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}\n" strmOutput << "\\paperw11906\\paperh16838\\margl1134\\margr567\\margt1134\\margb851\\headery567\\footery567\n" strmOutput << "\\b \\ul \\fs24 Para Compare Versions in " sCurrentModuleName "\\ul0 \\b0 \\par \\par\n" strmOutput << "\\trowd \\trgaph108\\trleft-108\\trhdr" strmOutput << strCellBorders "\\cellx1026 " strCellBorders "\\cellx2727 " strCellBorders "\\cellx6129 " strCellBorders "\\cellx9531\n" strmOutput << "\\intbl \\b \\fs20 Identifier\\cell Attribute\\cell Older Version\\par " sOlderName " \\cell Newer Version\\par " sNewerName "\\b0 \\cell\\row\n" Baseline bBaseline Baseline blNewer Baseline blOlder string sBaselineName for bBaseline in mLaunchingModule do { string sBaseline = (major bBaseline) "." (minor bBaseline) " " (suffix bBaseline) if (sNewerName==sBaseline) blNewer = bBaseline if (sOlderName==sBaseline) blOlder = bBaseline } Module mNewer Module mOlder if (iNewerIndex==0) { mNewer = mLaunchingModule // the newer module is the current version } else { progressStart(dbVersionCompare, "Compare Versions", "", 1) progressMessage("Loading newer version...") mNewer = load(blNewer, false) addModuleAttibutesToList(mNewer) progressStop() } progressStart(dbVersionCompare, "Compare Versions", "", 1) progressMessage("Loading older version...") mOlder = load(blOlder, false) addModuleAttibutesToList(mOlder) progressStop() int iObjectCount = 0 int iObjectsQuantity = 0 int iDifferences = 0 Skip skNewerAbsoluteNumbers = getAbsoluteNumbers mNewer // build caches of absnos -> objects Skip skOlderAbsoluteNumbers = getAbsoluteNumbers mOlder string sAttrName Object oNewer for oNewer in skNewerAbsoluteNumbers do { iObjectsQuantity++ } progressStart(dbVersionCompare, "Para Compare Version", "", iObjectsQuantity) progressMessage("Comparing attributes of newer objects...") for oNewer in skNewerAbsoluteNumbers do { progressStep(iObjectCount++) Object oOlder = null int iAbsoluteNumbersKey = (int key skNewerAbsoluteNumbers) if(find(skOlderAbsoluteNumbers, iAbsoluteNumbersKey, oOlder)) { delete(skOlderAbsoluteNumbers, iAbsoluteNumbersKey) } for sAttrName in dbeAttrNameList do { if(!compareObjects(oNewer, oOlder, sAttrName)) iDifferences++ } } progressStop() Object oOlder for oOlder in skOlderAbsoluteNumbers do { iObjectsQuantity++ } progressStart(dbVersionCompare, "Para Compare Version", "", iObjectsQuantity) progressMessage("Checking attributes of deleted older objects...") oNewer = null // no newer object exsist iObjectCount = 0 for oOlder in skOlderAbsoluteNumbers do { progressStep(iObjectCount++) for sAttrName in dbeAttrNameList do { if(!compareObjects(oNewer, oOlder, sAttrName)) iDifferences++ } } progressStop() strmOutput << "\\pard \\fs24 \\par " iDifferences " differences found.\\par \\par }" close(strmOutput) delete skNewerAbsoluteNumbers // delete caches delete skOlderAbsoluteNumbers if (mNewer != mLaunchingModule) close mNewer close mOlder current = mLaunchingModule // return to former current module //infoBox "Compare Versions is completed" } //// main program ************************************************************************************** mLaunchingModule = current if (null mLaunchingModule) { ack "Compare Versions requires a current module!\nStart it from the current version of a module..." halt } if (baseline mLaunchingModule) { ack "Compare Versions can not be started from a baseline!\nStart it from the current version of the module..." halt } Baseline bBaseline int iBaselineCount = 0 for bBaseline in mLaunchingModule do { iBaselineCount++ } if (iBaselineCount==0) { ack "No versions to compare to!\nMake a baseline..." halt } // Dialog for selecting two baselines for comparison int iHalfWidth = 275 string sCurrentModuleName = mLaunchingModule."Name" string strEmptyArr[] = {} dbVersionCompare = create "Para Compare Versions in " sCurrentModuleName "" dbeListNewer = list(dbVersionCompare, "Newer version", iHalfWidth, 9, strEmptyArr) dbeListNewer->"left"->"form" dbeListNewer->"right"->"unattached" dbeListOlder = list(dbVersionCompare, "Older version to compare with", iHalfWidth, 9, strEmptyArr) dbeListOlder->"left"->"form" dbeListOlder->"right"->"unattached" dbeAttrNameList = multiList(dbVersionCompare, "Attributes to compare", iHalfWidth, 20, strEmptyArr) dbeAttrNameList->"top"->"aligned"->dbeListNewer dbeAttrNameList->"left"->"flush"->dbeListNewer dbeAttrNameList->"right"->"unattached" dbeShowAsMarkup = toggle(dbVersionCompare,"Show changes as markup", true) dbeShowAsMarkup->"top"->"flush"->dbeListOlder dbeOutputFileBrowse = fileName(dbVersionCompare, "Output File ", "D:\\Doors Export\\Para Compare Versions " sCurrentModuleName ".rtf", "*.rtf", "Rich Text Files", false) dbeOutputFileBrowse->"left"->"form" // dummy to get the copy right in the right place DBE dbeDummy = label(dbVersionCompare, "") dbeDummy->"top"->"spaced"->dbeOutputFileBrowse dbeDummy->"left"->"form" DBE dbeCopyRight = label(dbVersionCompare, "Copyright (C) Reinhold Lauer 2010") dbeCopyRight->"bottom"->"spaced"->dbeDummy dbeCopyRight->"left"->"form" inactive (dbeCopyRight) apply(dbVersionCompare, "Compare", applyCompareVersions) realize (dbVersionCompare, 0, 0) // we realize so that the lists can be populated using insert // fill the newer and older version lists for bBaseline in mLaunchingModule do { string sBaseline = (major bBaseline) "." (minor bBaseline) " " (suffix bBaseline) insert(dbeListNewer, 0, sBaseline) insert(dbeListOlder, 0, sBaseline) } insert(dbeListNewer, 0, "current at " today "") set(dbeListNewer, 0) insert(dbeListOlder, 0, "") set(dbeListOlder, 1) // add the attributes to the list addModuleAttibutesToList(mLaunchingModule) addElementToList(dbeAttrNameList, "Object Text") addElementToList(dbeAttrNameList, "Object Short Text") addElementToList(dbeAttrNameList, "Object Heading") show dbVersionComparet Heading") show dbV