The nsh script is as follows.
I'm curious about the lbl_check part, and the part that declared the macro inside the function that starts in the fourth line below inside the CheckUserEmailAddress function.
Is it okay for macros to call (!insertmacro) before defining?
Additionally, will the lbl_check2~5 part be sequentially progressed?
Function CheckUserEmailAddress
!define CheckUserEmailAddress "!insertmacro CheckUserEmailAddressCall"
!macro CheckUserEmailAddressCall _INPUT _RESULT
Push "${_INPUT}"
Call CheckUserEmailAddress
Pop ${_RESULT}
!macroend
Exch $R0
Push $R1
Push $R2
Push $R3
Push $R4
Push $R5
#count the number of @'s more than one is invalid, less than one is invalid
${WordFind} "$R0" "@" "*" $R1
StrCmp "1" "$R1" lbl_check2 lbl_error
lbl_check2:
#count the number of words delimited by @ it should be 2.
${WordFind} "$R0" "@" "#" $R1
StrCmp "2" "$R1" lbl_check3 lbl_error
lbl_check3:
#Split the words into user and domain
${WordFind} "$R0" "@" "+1" $R2
${WordFind} "$R0" "@" "-1" $R3
#Determine if either of the fields contain special RFC822 characters
${StrFilter} "$R2" "" "" '()<>,;:\"[]' $R1
StrCmp "$R2" "$R1" 0 lbl_error
${StrFilter} "$R3" "" "" '()<>,;:\"[]' $R1
StrCmp "$R3" "$R1" lbl_check4 lbl_error
lbl_check4:
#Determine the number of fields in user and domain, check to see
#the number of delimiter is one less than the number of words.
StrCpy $R4 0
StrCpy $R5 0
${WordFind} "$R2" "." "*" $R4
${WordFind} "$R2" "." "#" $R5
StrCmp "$R4" "$R2" lbl_check5
StrCmp "$R5" "$R2" lbl_check5
IntOp $R4 $R4 + 1
StrCmp "$R4" "$R5" 0 lbl_error
lbl_check5:
StrCpy $R4 0
StrCpy $R5 0
${WordFind} "$R3" "." "*" $R4
${WordFind} "$R3" "." "#" $R5
StrCmp "$R3" "$R4" lbl_error
StrCmp "$R3" "$R5" lbl_error
IntOp $R4 $R4 + 1
StrCmp "$R4" "$R5" 0 lbl_error
; Unused label? lbl_check6:
# make sure there is at least one "." in the domain section.
${WordFind} "$R3" "." "*" $R1
IntCmp 1 $R1 lbl_end lbl_end lbl_error
StrCpy $R0 0
lbl_error:
StrCpy $R0 1
lbl_end:
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!endif
Q1) Is there a reason to redefine!macro one by one from !define below?
Function CheckUserEmailAddress
!define CheckUserEmailAddress "!insertmacro CheckUserEmailAddressCall"
!macro CheckUserEmailAddressCall _INPUT _RESULT
Q2) lbl_check2~5, lbl_error, end
Is it a switch-case phrase?
!define CheckUserEmailAddress "!insertmacro CheckUserEmailAddressCall"
does not call anything, it's just a helper for the user to avoid typing !insertmacro.
Section
${CheckUserEmailAddress} foo bar
SectionEnd
just expands to
Section
!insertmacro CheckUserEmailAddressCall foo bar
SectionEnd
and that expands to
Section
Push foo
Call CheckUserEmailAddress
Pop bar
SectionEnd
The labels are sequentially progressed, it is not a switch.