nsh脚本如下。
我对 lbl_check 部分以及在 CheckUserEmailAddress 函数内部第四行开始的函数内声明宏的部分感到好奇。
宏在定义之前调用(!insertmacro)可以吗?
另外,lbl_check2~5部分会依次进行吗?
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) 有没有理由从下面的 !define 中一一重新定义!宏?
Function CheckUserEmailAddress
!define CheckUserEmailAddress "!insertmacro CheckUserEmailAddressCall"
!macro CheckUserEmailAddressCall _INPUT _RESULT
Q2)
lbl_check2~5, lbl_error, end
这是一个 switch-case 短语吗?
!define CheckUserEmailAddress "!insertmacro CheckUserEmailAddressCall"
不会调用任何东西,它只是用户避免输入 !insertmacro 的助手。
Section
${CheckUserEmailAddress} foo bar
SectionEnd
只是扩展到
Section
!insertmacro CheckUserEmailAddressCall foo bar
SectionEnd
扩展到
Section
Push foo
Call CheckUserEmailAddress
Pop bar
SectionEnd
标签是按顺序进行的,不是开关。