Skip to content

Commit

Permalink
Fixes issues discovered in the XML.cpp routines that are designed to …
Browse files Browse the repository at this point in the history
…upgrade older docVersion documents on opening in the current docVersion of the application.

Added an additional upgrade function: FromDocVersion6through9ToDocVersionCurrent() to be able to upgrade documents created before AI version 6.11.1 which stored filtered information on a following source phrase rather than a previous source phrase.
Added code to the upgrade functions that populates the m_srcSinglePattern (xml ssp) and m_oldKey (xml okey) members when opening documents created as docVersion older than docVersion 10.
Refactored the GetPreviousNonPlaceholderSrcPhrase() function which was failing to search previous source phrases to find a non-placeholder source phrase for storing filtered information. When called from routines in XML.cpp this function was getting into an infinite loop/crash situation.
Fixed a crash that occurred when retrieving a document that was stored in the document history that was created with an older docVersion. The crash was due to a uninitialized pointer gpPreviousSrcPhrase in global space of the XML.cpp source file.
Attempted to fix the failure to make the document "dirty" after opening a document that was upgraded from an older docVersion to the current docVersion. This involved in moving the pDoc->Modify(FALSE) to its previous location after the OnOpenDocument() call, to a position before that call, and placing a pDoc->Modify(TRUE) statement in the upgrade routines. It isn't clear if my changes worked, since it still seems necessary to move the phrasebox to make the document dirty after it is input.
  • Loading branch information
pngbill committed Jun 11, 2024
1 parent e7d508f commit 7456e61
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 33 deletions.
7 changes: 5 additions & 2 deletions source/Adapt_It.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4700,10 +4700,13 @@ void CAdapt_ItApp::GetAndAssignIdValuesToUserProfilesStruct(UserProfiles*& pUser
else
{
// no mapping was found - this shouldn't happen
wxString msg = _T("Programming Error: No mapping found for menu label %s: Check that AI_UserProfiles.xml is in sync with the defaultProfileItems[] array in the App.\n For example, if a menu item was removed, remove the item's xml in AI_UserProfiles in the local copy in work folder, and in the adaptit > xml folder of the dev system - the latter one is crucial.");
wxString msg = _T("Programming Error: No mapping found for menu label: %s\n\nCheck that AI_UserProfiles.xml is in sync with the defaultProfileItems[] array in the App.\n\nFor example, if a menu item was removed, remove the item's xml in AI_UserProfiles in the local copy in work folder,\nand in the adaptit > xml folder of the dev system - the latter one is crucial.");
msg = msg.Format(msg, labelStr.c_str());
#ifdef _DEBUG
wxASSERT_MSG(FALSE, msg);
;
#endif
LogUserAction(msg);

}
pItem->itemIDint = itemId;
}
Expand Down
79 changes: 66 additions & 13 deletions source/Adapt_ItDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35696,7 +35696,11 @@ CSourcePhrase* CAdapt_ItDoc::GetPreviousSrcPhrase(CSourcePhrase* pSrcPhrase)
// document and the returned value would also be NULL.
// This function is used mainly within TokenizeText(), but also has some application within the
// ReconstituteAfterFilteringChange() function, and possibly elsewhere such as within DoMarkerHousekeeping().
CSourcePhrase* CAdapt_ItDoc::GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* pPrevSrcPhrase) //, SPList* pList)
// When this function is called from routines in XML.cpp, the second paramter bXMLInput should be TRUE
// in order to have a work around for a problem with m_pSourcePhrases->Find(pPrevSrcPhrase) and getting
// a previous position in the m_pSourcePhrase list there.
CSourcePhrase* CAdapt_ItDoc::GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* pPrevSrcPhrase,
bool bXMLInput) //, SPList* pList)
{
if (pPrevSrcPhrase == NULL)
return NULL;
Expand All @@ -35705,26 +35709,75 @@ CSourcePhrase* CAdapt_ItDoc::GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* p
// The incoming pPrevSrcPhrase is not a placeholder, so just return it to the caller.
return pPrevSrcPhrase;
}
//int nSequNum = pPrevSrcPhrase->m_nSequNumber;
SPList::Node* pos_pList;
SPList* pList = gpApp->m_pSourcePhrases;
if (pList == NULL || pList->IsEmpty())
return pPrevSrcPhrase;
SPList::Node* pos_pSPList = NULL;

int nSequNum = pPrevSrcPhrase->m_nSequNumber;
// whm 19Mar2024 modified. For situations where TokenizeText() is called to tokenize a sub-string,
// such as when it is called from the first call in OnEditSourceText(), the pList is not suitable
// for determining a position by calling pList->Item(nSequNum) because pList may well be an empty
// list and in any case, the position returned from a pList->Item(nSequNum) will not be accurate
// for use in getting a previous non-placeholder pPrevSrcPhrase to return to the caller.
// Therefore, we set the pos_pList here to its value based on the App's m_pSourcePhrases list.
pos_pList = gpApp->m_pSourcePhrases->Find(pPrevSrcPhrase);
CSourcePhrase* pLastSP = NULL;
pos_pList->GetPrevious();
pLastSP = pos_pList->GetData();
while (pLastSP != NULL && pLastSP->m_bNullSourcePhrase && pLastSP->m_nSequNumber >= 0)
// using m_pSourcePhrases->Find(pPrevSrcPhrase).
// whm 10June2024 workaround. The m_pSourcePhrases->Find(pPrevSrcPhrase) does not appear to work
// well when GetPreviousNonPlaceholderSrcPhrase() is called from the XML upgrade routines
// FromDocVersion4ToDocVersionCurrent() amd FromDocVersion5through9ToDocVersionCurrent(). See
// note inside while loop below for more information on the issue. I've added a bool parameter to
// make the signature GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* pPrevSrcPhrase, bool bXMLInput = FALSE)
// in which when no parameter is given (in calls from TokenizeText etc) a ->Find(pPrevSrcPhrase)
// is used below. When bXMLInput is TRUE, m_pSourcePhrases->Item(nSequNum) is used instead.
CSourcePhrase* pTestSP = NULL;
if (bXMLInput == TRUE)
{
// When called from XML input routines start by determining the pos_pSPList of the last
// source phrase in pList.
pos_pSPList = pList->GetLast();
pTestSP = pos_pSPList->GetData();
#ifdef _DEBUG
wxASSERT(nSequNum == pTestSP->m_nSequNumber);
#endif
}
else
{
pos_pList->GetPrevious();
pLastSP = pos_pList->GetData();
// When called from TokenizeText() etc, start by determining the pos_pSPList position by
// using the pList->Find(pPrevSrcPhrase) command. This is necessary because certain
// calls of TokenizeText() - such as during unfiltering - are made on a sublist of source
// phrases of a larger m_pSourcePhrases list on the App.
pos_pSPList = pList->Find(pPrevSrcPhrase);
pos_pSPList->GetPrevious(); // TODO: Test if this is necessary.
}
if (pLastSP != NULL)
if (pos_pSPList == NULL)
{
pPrevSrcPhrase = pLastSP;
// Couldn't find the pPrevSrcPhrase in the App's gpApp->m_pSourcePhrases which is
// unexpected. Probably best to just return the pPrevSrcPhrase unchanged.
return pPrevSrcPhrase;
}
CSourcePhrase* pPrevSP = NULL;
pPrevSP = pos_pSPList->GetData();
nSequNum = pPrevSP->m_nSequNumber;
while (pPrevSP != NULL && pPrevSP->m_bNullSourcePhrase && pPrevSP->m_nSequNumber >= 0 && nSequNum >= 0)
{
// whm 10Jun2024 strange pos_pSPList->GetPrevious() behavior ovserved.
// I found the pos_pList->GetPrevious() call would sometimes misbehave when trying to get the
// previous position of a source phrase when working with the App's m_pSourcePhrases when
// GetPreviousNonPlaceholderSrcPhrase() was called from within the upgrade routines of XML.cpp.
// The pos_pSPList position value was not changing even when pos_pSPList->GetPrevious() was called.
// Therefore I've decided to use the m_nSequNum of the incoming pPrevSrcPhrase, and just
// use PList->Item(nSequNum) to get the pos_pSPList with decremented values and retrieve the pPrevSP
// source phrases within this while loop until a previous source phrase is found whose
// m_bNullSourcePhrase is FALSE. This approach also works for when this function is called from
// TokenizeText() since the first nSequNum is determined using the pList->Find(pPrevSrcPhrase)
// operation for those cases.
nSequNum--;
pos_pSPList = pList->Item(nSequNum); //pos_pSPList->GetPrevious();
pPrevSP = pos_pSPList->GetData();
}
if (pPrevSP != NULL)
{
pPrevSrcPhrase = pPrevSP;
}
return pPrevSrcPhrase;
}
Expand Down Expand Up @@ -40155,7 +40208,7 @@ int CAdapt_ItDoc::ParseWord(wxChar* pChar,
{
wxString pointsAt = wxString(ptr, 16);
wxLogDebug(_T("ParseWord() line %d , Before ParseNumber() , ptr-> [%s]"), __LINE__, pointsAt.c_str());
if (pSrcPhrase->m_nSequNumber >= 18)
if (pSrcPhrase->m_nSequNumber >= 49)
{
int halt_here = 1; wxUnusedVar(halt_here);
}
Expand Down
3 changes: 2 additions & 1 deletion source/Adapt_ItDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ bool bMarkAsDirty); // might want it instantly saveable
// final . of 5:4-9. (Use primarily in footnotes in the input text)
wxString ParseAWord(wxChar* pChar, wxString& spacelessPuncts, wxChar* pEnd, bool& bWordNotParsed); // BEW 3Aug23 added bWordNotParsed
//CSourcePhrase* GetPreviousSrcPhrase(CSourcePhrase* pSrcPhrase); // BEW added 13Dec22, and commented out 13Dec22 - it isn't needed yet, but is robust
CSourcePhrase* GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* pPrevSrcPhrase); // whm 18Mar2024 added for getting prev SP to store filtered info
CSourcePhrase* GetPreviousNonPlaceholderSrcPhrase(CSourcePhrase* pPrevSrcPhrase,// whm 18Mar2024 added for getting prev SP to store filtered info
bool bXMLInput = FALSE); // defaults to FALSE for calls from TokenizeText() etc.
SPList::Node* GetFollowingNonPlaceholderInsertPosition(SPList::Node* insertPos, CSourcePhrase*& pInsertSP); // whm 18Mar2024 added for getting insert position for unfiltering SP sublist
bool CanParseForward(wxChar* pChar, wxString spacelessPunctuation, wxChar* pEnd); // BEW 26Jul23 refactored, because
// internally the algorithm gave false positives, especially if ' (straight quote) was not in the punctuation set.
Expand Down
2 changes: 1 addition & 1 deletion source/Adapt_ItView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ CPile* CAdapt_ItView::GetNextPile(CPile* pPile)

// BEW try 5Jun24
CAdapt_ItApp* pApp = &wxGetApp();
CAdapt_ItDoc* pDoc = pApp->GetDocument();
CAdapt_ItDoc* pDoc = pApp->GetDocument(); wxUnusedVar(pDoc);
CSourcePhrase* pSP = pPile->GetSrcPhrase();
int index = pSP->m_nSequNumber;
//int index = pPiles->IndexOf(pPile);
Expand Down
14 changes: 13 additions & 1 deletion source/DocPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,12 @@ void CDocPage::OnWizardFinish(wxWizardEvent& WXUNUSED(event))
dt2 = wxDateTime::UNow();
#endif

// whm 10June2024 moved the following pDoc->Modify(FALSE) to this location from below.
// The reason: Calling Modify(FALSE) after OnOpenDocument() nullifies the Modify(TRUE)
// that may get set when an existing document that esd created with docVersion before 10
// is loaded by XML.cpp.
pDoc->Modify(FALSE);

bool bOK = pDoc->OnOpenDocument(docPath, true); // BEW 7Oct14, this sets or
// clears the app boolean m_bZWSPinDoc at the end of the call

Expand Down Expand Up @@ -1255,7 +1261,13 @@ void CDocPage::OnWizardFinish(wxWizardEvent& WXUNUSED(event))
// behaviour that a just-opened document is immediately ready for a Split operation
// without the user having to realize a save must first be done to get the document
// clean for the Split to be enabled
pDoc->Modify(FALSE);
//
// whm 10June2024 moved the pDoc->Modity(FALSE) from here up to just before the
// OnOpenDocument() call. The reason: If the user opens an existing document that
// requires auto upgrading to the current document version, the Modify(FALSE) call
// here resets the Modify(TRUE) calls that are made within the upgrade functions in
// XML.cpp.
//pDoc->Modify(FALSE);
gpApp->RefreshStatusBarInfo();

#ifdef SHOW_DOC_I_O_BENCHMARKS
Expand Down
Loading

0 comments on commit 7456e61

Please sign in to comment.