📄 staftest.cmd
字号:
PS_CurrType = "Value" PS_CurrData = "" PS_IsLiteral = 0 end end /* if whitespace */ else if PS_Char = '\' then do if PS_InQuotes & \PS_InEscape then PS_InEscape = 1 else do PS_CurrData = PS_CurrData || PS_Char PS_InEscape = 0 end end else if PS_Char = '"' then do if PS_InEscape then PS_CurrData = PS_CurrData || PS_Char else if PS_InQuotes & PS_CurrData \== "" then do if PS_IsLiteral then PS_CurrType = "Value" else if ValueIsOption(PS_CurrData) \= 0 then PS_CurrType = "Option" PS_Word.0 = PS_Word.0 + 1 PS_WordIndex = PS_Word.0 PS_Word.PS_WordIndex.!Type = PS_CurrType PS_Word.PS_WordIndex.!Data = PS_CurrData PS_CurrType = "Value" PS_CurrData = "" PS_InQuotes = 0 PS_IsLiteral = 0 end else do PS_InQuotes = 1 PS_IsLiteral = 1 end PS_InEscape = 0 end /* end if quote character */ else do PS_InEscape = 0 PS_CurrData = PS_CurrData || PS_Char end end /* looping through parse string */ if PS_InLengthField | PS_InDataField then do call VALUE PS_ErrorBuffer, "Invalid length delimited data specifier" RETURN 1 end else if PS_CurrData \== "" then do if PS_IsLiteral then PS_CurrType = "Value" else if ValueIsOption(PS_CurrData) \= 0 then PS_CurrType = "Option" PS_Word.0 = PS_Word.0 + 1 PS_WordIndex = PS_Word.0 PS_Word.PS_WordIndex.!Type = PS_CurrType PS_Word.PS_WordIndex.!Data = PS_CurrData end /* Now walk the word list looking for options, etc. */ PS_ValueRequirement = "NO" PS_CurrOption = "" PS_CurrValue = "" do PS_i = 1 to PS_Word.0 PS_CurrWord = PS_Word.PS_i.!Data if PS_Word.PS_i.!Type = "Option" then do do PS_OptionIndex = 1 to OpString_Option.OpString_CurrentParser.0, UNTIL TRANSLATE(OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Name) =, TRANSLATE(PS_CurrWord) end if PS_ValueRequirement = "YES" then do call VALUE PS_ErrorBuffer, "Option," PS_CurrOption",", "requires a value" RETURN 1 end else if PS_ValueRequirement = "ALLOWED" then do OpString_Instance.OpString_CurrentParser.0 = OpString_Instance.OpString_CurrentParser.0 + 1 OpString_InstanceIndex = OpString_Instance.OpString_CurrentParser.0 OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Name = PS_CurrOption OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Value = PS_CurrValue end /* Check once here for whether this new option instance will */ /* exceed the limit for this option */ if (OptionTimes(OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Name) =, OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Times) &, (OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Times \= 0) then do call VALUE PS_ErrorBuffer, "You may have no more than", OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Times, "instance(s) of option", OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Name RETURN 1 end PS_CurrOption = OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Name PS_CurrValue = "" PS_ValueRequirement =, TRANSLATE(OpString_Option.OpString_CurrentParser.PS_OptionIndex.!ValueRequired) if PS_ValueRequirement = "NO" then do OpString_Instance.OpString_CurrentParser.0 = OpString_Instance.OpString_CurrentParser.0 + 1 OpString_InstanceIndex = OpString_Instance.OpString_CurrentParser.0 OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Name = PS_CurrOption OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Value = PS_CurrValue PS_CurrOption = "" PS_CurrValue = "" end end else if PS_ValueRequirement = "NO" then do OpString_Arg.OpString_CurrentParser.0 = OpString_Arg.OpString_CurrentParser.0 + 1 OpString_ArgIndex = OpString_Arg.OpString_CurrentParser.0 OpString_Arg.OpString_CurrentParser.OpString_ArgIndex = PS_CurrWord end else do PS_CurrValue = PS_CurrWord OpString_Instance.OpString_CurrentParser.0 = OpString_Instance.OpString_CurrentParser.0 + 1 OpString_InstanceIndex = OpString_Instance.OpString_CurrentParser.0 OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Name = PS_CurrOption OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Value = PS_CurrValue PS_CurrOption = "" PS_CurrValue = "" PS_ValueRequirement = "NO" end end /* end for each word */ /* If the last word was an option, we need to check for its value */ /* requirements here */ if PS_ValueRequirement = "YES" then do call VALUE PS_ErrorBuffer, "Option,", OpString_Option.OpString_CurrentParser.PS_OptionIndex.!Name",", "requires a value" RETURN 1 end else if PS_ValueRequirement = "ALLOWED" then do OpString_Instance.OpString_CurrentParser.0 = OpString_Instance.OpString_CurrentParser.0 + 1 OpString_InstanceIndex = OpString_Instance.OpString_CurrentParser.0 OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Name = PS_CurrOption OpString_Instance.OpString_CurrentParser.OpString_InstanceIndex.!Value = PS_CurrValue end /* Check the restriction on number of arguments */ if OpString_Arg.OpString_CurrentParser.0 >, OpString_MaxArguments.OpString_CurrentParser then do PS_InvalidArgIndex = OpString_MaxArguments.OpString_CurrentParser + 1 call VALUE PS_ErrorBuffer, "You may have no more than", OpString_MaxArguments.OpString_CurrentParser "argument(s).", " You specified" OpString_Arg.OpString_CurrentParser.0, "argument(s). The first excess argument is, ", OpString_Arg.OpString_CurrentParser.PS_InvalidArgIndex"." RETURN 1 end /* Now check all the group requirements */ do PS_i = 1 to OpString_OptionGroup.OpString_CurrentParser.0 PS_GroupCount = 0; PS_GroupWordCount =, WORDS(OpString_OptionGroup.OpString_CurrentParser.PS_i.!Group) do PS_j = 1 to PS_GroupWordCount if OptionTimes(WORD(OpString_OptionGroup.OpString_CurrentParser.PS_i.!Group, PS_j)) \= 0 then PS_GroupCount = PS_GroupCount + 1 end if (PS_GroupCount <, OpString_OptionGroup.OpString_CurrentParser.PS_i.!Minimum) |, (PS_GroupCount >, OpString_OptionGroup.OpString_CurrentParser.PS_i.!Maximum) then do call VALUE PS_ErrorBuffer, "You must have at least", OpString_OptionGroup.OpString_CurrentParser.PS_I.!Minimum",", "but no more than", OpString_OptionGroup.OpString_CurrentParser.PS_I.!Maximum, "of the option(s),", OpString_OptionGroup.OpString_CurrentParser.PS_I.!Group RETURN 1 end end /* do for each group */ /* Now check the need requirements */ do PS_i = 1 to OpString_OptionNeed.OpString_CurrentParser.0 PS_FoundNeeder = 0 PS_FoundNeedee = 0 do PS_j = 1 to WORDS(OpString_OptionNeed.OpString_CurrentParser.PS_I.!Needer), while PS_FoundNeeder = 0 if (OptionTimes(WORD(OpString_OptionNeed.OpString_CurrentParser.PS_i.!Needer, PS_j)) \= 0) then PS_FoundNeeder = 1 end do PS_j = 1 to WORDS(OpString_OptionNeed.OpString_CurrentParser.PS_I.!Needee), while PS_FoundNeedee = 0 if (OptionTimes(WORD(OpString_OptionNeed.OpString_CurrentParser.PS_i.!Needee, PS_j)) \= 0) then PS_FoundNeedee = 1 end if (PS_FoundNeeder & \PS_FoundNeedee) then do call VALUE PS_ErrorBuffer, "When specifying one of the options", OpString_OptionNeed.OpString_CurrentParser.PS_i.!Needer",", "you must also specify one of the options", OpString_OptionNeed.OpString_CurrentParser.PS_i.!Needee RETURN 1 end end /* do for each need */ RETURN 0/* End of ParseString */ValueIsOption: parse arg VIO_Value do VIO_i = 1 to OpString_Option.OpString_CurrentParser.0 if TRANSLATE(OpString_Option.OpString_CurrentParser.VIO_i.!Name) =, TRANSLATE(VIO_Value) then do RETURN VIO_i end end RETURN 0/* End of ValueIsOption */FileStatus: parse arg FS_file, FS_maxwait, FS_openfor FS_status = '' FS_rc = 0 FS_openfor = translate(FS_openfor) if FS_openfor = "READ" then FS_openfor = "open read" else if FS_openfor = "WRITE" then FS_openfor = "open write" else FS_openfor = "open" call SysFileTree FS_file, FS_stem, 'F' /* Check if file exists */ if FS_stem.0 = 0 then do /* File not found */ FS_rc = 1 errorBuffer = STAFError.!FileOpenError.!text || lineSep || FS_file end else /* File exists, see if it is READY */ do do FS_maxwait /* Repeat maxwait times or file READY */ FS_status = stream(FS_file, "c", FS_openfor) if FS_status = "READY:" then leave /* File READY */ call SysSleep 1 end if FS_status \= "READY:" then do FS_rc = 2 errorBuffer = "File not READY: " || lineSep || FS_file end endRETURN FS_rc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -