//TH-Header //*************************************************************************************** //* CmdLine.Pkg //* //* Contents: //* Class cCmdLine to handle CommandLine Parameters... //* //* Two Commands a predefined, and for my opinion the first step to a Dataflex //* Scripting Language. (lol) //* //* "RUN" "EXPRESSION" //* "RUN_SCRIPT" "FILENAME" // Performs a RUN on every line of the File! //* //* Example: //* Your *.VDX is named "TEST" and you have a Procedure "ShowName" for Desktop defined in it //* than the following can be done by "RUN": //* //* DFRUN TEST "RUN" "(MSG_ShowName(Desktop,sParameter1,sParameter2))" //* //* Than the Procedure would be executed with the 2 Parameters. //* If you use a String use ' instead of " //* //* Michael Kurz 2000' 28.08. mkurz@sbox.tu-graz.ac.at //*************************************************************************************** //* This Class was basically developped to handle CmdLine Parameters //* in the following way: //* "COMAND" "Parameter1" ... "Parameter10" "COMMAND" ... //* //* Every Comamnd need to be implemented in form of a PROCEDURE //* and is registered like: //* //* send RegisterCommand "NAME1" Msg_XX1 iDestObject1 sDescription1 //* send RegisterCommand "NAME2" Msg_XX2 iDestObject2 sDescription2 //* ... //* send RegisterCommand "NAMEX" Msg_XXX iDestObjectX sDescriptionX //* //* After Registered all CmdLine Commands your Application should support you have to: //* send RunCmdLine //*************************************************************************************** //TH-RevisionStart // 23.06.2001 18:07 Added ability to set a command as Mk SERVER // standard command //TH-RevisionEnd Use Set.Pkg Class cCmdLine_Mixin Is a Mixin Procedure Define_cCmdLine_Mixin Property Integer piDefaultCommand -1 // Used to allow a default command, which is used if no command is passed and only parameters. Object oCmdElements Is an Array End_Object Object oPara Is an Array End_Object Object oCmds Is a Set End_Object Object oCmdMsg Is an Array End_Object Object oCmdDest Is an Array End_Object Object oCmdDesc Is an Array End_Object End_Procedure // This sets the last called command to the default command. Procedure SetDefaultCommand Set piDefaultCommand To (Item_Count(oCmds(Self))-1) End_Procedure // To acces all commandline parameters. Function CmdLine_Count Returns Integer Function_Return (Item_Count(oCmdElements(Self))) End_Function Function CmdLine_Value Integer iNr Returns String Function_Return (Value(oCmdElements(Self),0)) End_Function // Parameterstorage... Procedure AddPara String sP Set value Of (oPara(Self)) Item (Item_Count(oPara(Self))) To sP End_Procedure Procedure ClearPara Send Delete_Data To (oPara(Self)) End_Procedure Function sPara Integer iC Returns String Function_Return (Value(oPara(Self),iC)) End_Function // Delivers the ID of a Command, if none lt zero! Function isCommand String sCmd Returns Integer Integer iC Get Find_Element Of (oCmds(Self)) (Trim(sCmd)) To iC Function_Return iC End_Function // Cause I access the CmdLine Command with a function I can get the data // where ever I want by overwriting this! Function GetCmdLine Returns String String sL CmdLine sL Move (ToOem(sL)) To sL // To convert everything to OEM. Function_Return sL End_Function // Register Commands: // If the iDest=0 iMsg is simply sent! Procedure RegisterCommand String sName Integer iMsg Integer iDest String sDesc Integer iC If (isCommand(Self,sName)) Ge 0 Begin Send Stop_Box (Append("Command already exists, could not be registered! ",sName)) "Error" Procedure_Return 0 End Set value Of (oCmds(Self)) Item (Item_Count(oCmds(Self))) To sName Set value Of (oCmdMsg(Self)) Item (Item_Count(oCmdMsg(Self))) To iMsg Set value Of (oCmdDest(Self)) Item (Item_Count(oCmdDest(Self))) To iDest Set value Of (oCmdDesc(Self)) Item (Item_Count(oCmdDesc(Self))) To sDesc Procedure_Return 1 End_Procedure // Executes the Command: "iCmd" with up to 10 Parameters! Procedure ExecuteCmd Integer iCmd String sP1 String sP2 String sP3 String sP4 String sP5 ; String sP6 String sP7 String sP8 String sP9 String sP10 Integer iMsg iDest Get value Of (oCmdMsg(Self)) Item iCmd To iMsg Get value Of (oCmdDest(Self)) Item iCmd To iDest If iCmd Ge 0 If iMsg Begin If iDest Begin Send iMsg To iDest sP1 sP2 sP3 sP4 sP5 sP6 sP7 sP8 sP9 sP10 End Else Send iMsg sP1 sP2 sP3 sP4 sP5 sP6 sP7 sP8 sP9 sP10 End End_Procedure // Runs every Command in the CommandLine with its parameters (up to 10) Procedure RunCmdLine String sLine sCmd Integer iRet iCmd iCmdOld Get piDefaultCommand To iCmd Repeat Move (GetCmdLine(Self)) To sLine If sLine Ne "" Set value Of (oCmdElements(Self)) Item (item_count(oCmdElements(Self))) To sLine Move (isCommand(Self,sLine)) To iRet If iRet Lt 0 Send AddPara sLine Else Begin Send ExecuteCmd iCmd (sPara(Self,0)) (sPara(Self,1)) (sPara(Self,2)) (sPara(Self,3)) (sPara(Self,4)) ; (sPara(Self,5)) (sPara(Self,6)) (sPara(Self,7)) (sPara(Self,8)) (sPara(Self,9)) Send ClearPara Move iRet To iCmd End Until (sLine Eq "") Send ExecuteCmd iCmd (sPara(Self,0)) (sPara(Self,1)) (sPara(Self,2)) (sPara(Self,3)) (sPara(Self,4)) ; (sPara(Self,5)) (sPara(Self,6)) (sPara(Self,7)) (sPara(Self,8)) (sPara(Self,9)) End_Procedure Procedure Help Integer iC iCount Get Item_Count Of (oCmds(Self)) To iCount Showln "[ Registered commandline commands: ]" Showln For iC From 0 To (iCount-1) Showln (Value(oCmds(Self),iC)) " " (Value(oCmdDesc(Self),iC)) Loop inkey iC abort End_Procedure // Runs Procedures and functions with n parameters... Procedure Run String sTerm String sFkt sPart sParameter sP1 sP2 sP3 sP4 sP5 sP6 sP7 sRet Integer iFkt iPos iC iP1 iObjectFlag Move (Trim(sTerm)) To sTerm Move (Right(sTerm,(Length(sTerm)-1))) To sTerm // "=" und Klammer auf weg! Move (Left(sTerm,(Length(sTerm)-2))) To sTerm // 2 Klammer zu am Ende weg! Move (Left(sTerm,Pos("(",sTerm))) To sFkt // Funktionsname Move (Replace(sFkt,sTerm,"")) To sTerm Move (Replace("(",sFkt,"")) To sFkt If (Left(sFkt,4)) Ne "MSG_" ; Move (Append("GET_",Trim(sFkt))) To sFkt // mit MSG_ k”nne auch Proceduren Move (Uppercase(sFkt)) To sFkt // aufgerufen werden! Move (Eval(sFkt)) To iFkt // Funktion ID Move 0 To iObjectFlag Repeat Increment iC Move (Pos(",",sTerm)) To iPos If iPos Le 0 Move sTerm To sPart Else Move (Left(sTerm,iPos)) To sPart Move (Replace(sPart,sTerm,"")) To sTerm Move (Replace(",",sPart,"")) To sPart Move "" To sParameter If (Left(sPart,1)) Eq '"' ; // String Term... Move (Replaces('"',sPart,"")) To sParameter If (Left(sPart,1)) In "1,2,3,4,5,6,7,8,9,0" ; // Numerischer Term... Move sPart To sParameter If sParameter Eq "" Begin If iC Eq 1 Begin If (uppercase(trim(sPart))) Eq "DESKTOP" Move 1 To iObjectFlag If (uppercase(trim(sPart))) Eq "SELF" Move 1 To iObjectFlag If ".OBJ" In (uppercase(sPart)) Move 1 To iObjectFlag End Move (Eval(Uppercase(sPart))) To sParameter End If iC Eq 1 If iObjectFlag Move sParameter To iP1 If iC Eq 1 Move sParameter To sP1 If iC Eq 2 Move sParameter To sP2 If iC Eq 3 Move sParameter To sP3 If iC Eq 4 Move sParameter To sP4 If iC Eq 5 Move sParameter To sP5 If iC Eq 6 Move sParameter To sP6 If iC Eq 7 Move sParameter To sP7 If iC Gt 7 Move "" To sTerm Until (sTerm Eq "") If iFkt Begin If iP1 Gt 0 Get iFkt Of iP1 sP2 sP3 sP4 sP5 sP6 sP7 To sRet Else Get iFkt sP1 sP2 sP3 sP4 sP5 sP6 sP7 To sRet End End_Procedure Procedure Run_Script String sFile String sL Direct_Input sFile Repeat ReadLn sL [Not Seqeof] If (Trim(sL)) Ne "" Send Run (Trim(sL)) Until [Seqeof] Close_Input End_Procedure Procedure AbortPrg Abort End_Procedure Procedure RegisterStandardCommands //____StandardCommands_which_are_supported...____________________ Send RegisterCommand "-?" Msg_Help 0 "Shows all registered cmdline commands" Send RegisterCommand "-RUN" Msg_Run 0 "Starts procedures and functions with any number of parameters" Send RegisterCommand "-RUN_SCRIPT" Msg_Run_Script 0 "Performs a RUN on every line of the given file" Send RegisterCommand "-ABORT" Msg_AbortPrg 0 "Stops programm execution" End_Procedure End_Class