I add here the first working version of my backup comparison, so other like me can use it as example.
Code:
@possibly using the ListExt of DavidM
\<<
@Plan:
@ given that I make backups of the folder on the SD card, I may, one day,
@ mix the data (like overwriting one variable with the data of another one).
@ This actually already happened and I always realized it (or so I think).
@ What happens when I do not realize it? I will have wrong data for a certain
@ period of time, also in the backups.
@ So the idea is: the user recall a backup on the stack.
@ The backup is the entire life gamification directory.
@ The directory gets saved on those ports rarely used.
@ In particular I realized that port1 sits there unused.
@ See www.hpmuseum.org/forum/thread-8847.html
@ Therefore one can use port1 as storage place for the directory,
@ even overwriting the previous save,
@ and then to report changes. In names, contets and so on.
@ This only for the data though (data saved as lists), for other
@ types I will see.
'LGBP1' "dirNamePort1" DROP
{} "lgbp1Vars" DROP
"" "currVar" DROP
0 "backupListSize" DROP
@it is assumed that all the lists in the backup have the same size.
{} "currVarListProd" DROP
{} "comparisonResultList" DROP
0 "areListEqualBool" DROP
"" "resultStr" DROP
{} "resultList" DROP
@result list in the form { var1-0 var2-5 ... varJ-<FirstMismatchPos> }
\->
@input
stackDirObj
@ on the stack is required the directory object
@local var
dirNamePort1
lgbp1Vars
currVar
backupListSize
currVarListProd
comparisonResultList
areListEqualBool
resultStr
resultList
\<<
@ test if on the stack there is the proper object (a dir blob)
IF
stackDirObj TYPE 15 \=/
THEN
"input agument should be a directory about LIFEG" DOERR
KILL
END
@purge eventual objects in port1
IFERR
dirNamePort1 1 \->TAG
PURGE
THEN
"dir likely does not exist" DROP
@drop the commands if last argument is enabled.
IF
-55 FC?
THEN
DROP
END
END
@ save the directory in port1 , always the same name
stackDirObj
dirNamePort1 1 \->TAG
STO
@ collect the variables names within the directory in port1
@ using a fixed name "protocols!"
IFERR
dirNamePort1 'allListVars' 2 \->LIST
1 \->TAG
RCL
THEN
IF
-55 FC?
THEN
DROP
END
"Please check if 'allListVars' exists in the backup"
"Otherwise make it manually, or manually compare single lists"
KILL
END
'lgbp1Vars' STO
@when I do a backup it is assumed that I check the length of the lists
@so all of them should have the same length
dirNamePort1 lgbp1Vars HEAD 2 \->LIST
1 \->TAG RCL
SIZE 'backupListSize' STO
@ go through the variables collected and, if they are of type list
@ try to find the same name in the "production" directory
@ and compare the contents reporting the results.
1 lgbp1Vars SIZE
FOR ind1
lgbp1Vars ind1 GET 'currVar' STO
@when I do a backup it is assumed that I check the length of the lists
@so all of them should have the same length. Still, the <production directory>
@may have longer lists because the backup is older, I need to trim those.
{ HOME LIFEG } currVar + RCL
@TIL 09:53 21.08.2017 that HOME withing single quotes is generating a syntax error.
@TIL 09:58 21.08.2017 it is not immediately possible to expand a variable within a list
@so it has to be expanded and added later.
1 backupListSize SUB
'currVarListProd' STO
@now comparison
dirNamePort1 currVar 2 \->LIST 1 \->TAG RCL
currVarListProd
2 \<< == \>>
DOLIST
'comparisonResultList' STO
IF
comparisonResultList 0 POS 0 ==
THEN
'resultList' 0 currVar \->TAG STO+
ELSE
'resultList'
comparisonResultList 0 POS
currVar \->TAG STO+
END
NEXT
resultList
\>>
\>>