Guidance
指路人
g.yi.org
Software / Reginald / Examples / VarServer / Run.rex

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
run: PROCEDURE EXPOSE option. cmd. cpt. divu$. dive$. divr$.
USE ARG cmd,mylist.
starttime=TIME('R')
CALL init
IF option.server='NO' THEN CALL noserver
CALL initclip
CALL readparms
option.keepalso=0   /* keep also is just for one command, reset it after execution */
option.kept=''      /* same for KEPT-DATAs */
option.keep=''      /* same for KEPT-DATAs */
DROP cmd.           /* release command parameters, must be set always new */
servertime=TIME('E')
CALL sendreceive
resulttime=TIME('E')
IF ARG(2,'E')=0 THEN CALL mpoutdd(mylist.)
displaytime=TIME('E')
CALL writelog
IF option.echo=1 THEN SAY ptime() LEFT(cmd 'ended 'COPIES('.',50),50)
RETURN 0
/* ---------------------------------------------------------------------------------
 * Init exchange CLIP
 * ---------------------------------------------------------------------------------
 */
initclip:
LIBRARY rxclip
mpout='MPOUT'RANDOM(1,1000)
dictin=clipnewformat('MPIN'DIRECTORY())
mympout=clipnewformat(mpout)
dictoken='MPSF'hash(DIRECTORY(),99999)
retcount=0
IF EXISTS('cpt.ServerStarted')=1 THEN IF cpt.serverstarted=1 THEN RETURN
                                      ELSE NOP 
ELSE IF lock('TESTEXCLUSIVE',servermode)=0 THEN DO /* not locked yet, start server */
   CALL startserver
   cpt.serverchecked=1    /* save for next call of same run */ 
END 
ELSE DO     /* server was started previously, just use it */ 
   cpt.serverchecked=1    /* save for next call of same run */ 
END
RETURN 
/* ---------------------------------------------------------------------------------
 * Start Server if not yet done  
 * ---------------------------------------------------------------------------------
 */
startserver:
PARSE ARG reason
SAY ptime()' Automatic start of Server'
waitr=30
sleepi=0.511
rexdir=VALUE('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\RxLaunch.exe\Path', ,"WIN32")
ITERATEEXE(rexdir'RXLAUNCH','VarServer.REX',,,,'M')
DO i=1 TO waitr 
   SLEEP(sleepi)
   IF lock('TESTEXCLUSIVE',servermode'Start')=0 THEN LEAVE /* locked, server sarted */
END 
IF i<waitr THEN SAY ptime()' Server started' 
ELSE DO 
   SAY ptime()' Server not started'
   EXIT 8
END
RETURN  
/* ---------------------------------------------------------------------------------
 * Init RUN procedure 
 * ---------------------------------------------------------------------------------
 */
init:
IF EXISTS('option.server')=0 THEN option.server='YES'
IF EXISTS('option.echo')=0 THEN option.echo=1
IF option.echo=1 THEN SAY ptime() LEFT(cmd 'started 'COPIES('.',50),50)
option.mprout=1
servermode='Variable Server' 
RETURN 
/* ---------------------------------------------------------------------------------
 * Read Command 
 * ---------------------------------------------------------------------------------
 */
readparms:
incmd=TRANSLATE(cmd,,"()")
cmdx=WORD(incmd,1)
cmdv=''
wrds=WORDS(incmd)
DROP myvar.
mylist.1=''
myvar.2=getoption()
myvar.2=myvar.2' ; 'getcmd()
myvar.3=cmdx
j=3
DO i=2 TO wrds 
   j=i+2
   myvar.j=WORD(incmd,i)
   cmdv=cmdv||word(incmd,i)' '
END
myvar.0=j
myvar.1=mpout' 'j   /* MPOUT list and number of parms CLIPSET doesn't clear out old lines?? */
option.keep=''      /* Must be set explicetly for each command */
RETURN
/* ---------------------------------------------------------------------------------
 * Read Options
 * ---------------------------------------------------------------------------------
 */
getoption:
sendstem=''
DO vars OVER option.
   sendstem=sendstem' option.'vars"='"VALUE('option.'vars)"' ;"
END
RETURN sendstem
/* ---------------------------------------------------------------------------------
 * Read Command Parameters
 * ---------------------------------------------------------------------------------
 */
getcmd:
sendstem=''
DO vars OVER cmd.
   sendstem=sendstem' cmd.'vars"='"VALUE('cmd.'vars)"' ;"
END
RETURN sendstem
/* --------------------------------------------------------------------------------------------
 * Get Variable (test if exists)
 * --------------------------------------------------------------------------------------------
 */
testgetvar:
USE ARG tvar,default
default=ARG(2)
IF EXISTS(tvar)=1 THEN RETURN VALUE(tvar)
tvar=TRANSLATE(tvar)
IF EXISTS(tvar)=0 THEN RETURN default
ELSE RETURN VALUE(tvar)
/* ---------------------------------------------------------------------------------
 * Wait for esults
 * ---------------------------------------------------------------------------------
 */
sendreceive:
clipset("MyVar.", dictin)  /* send Clip to Server */
evt=eventcreate(servermode,2710)
IF evt \=2710 THEN DO
   SAY 'Server did not respond, correctly: 'evt
   EXIT 8
END    
clipget("MyLIST.", mympout)
IF EXISTS('myLIST.0')=0 THEN DO
   SAY cmd' did not produce any output' 
   EXIT 8
END 
lastline=mylist.0
mylist.0=WORD(mylist.lastline,2)
mpsftime=WORD(mylist.lastline,3)
RETURN 
/* ---------------------------------------------------------------------------------
 * Write Result to MPOUT 
 * ---------------------------------------------------------------------------------
 */
mpoutdd:
USE ARG mylist.
IF DATATYPE(mylist.0)\='NUM' THEN mylist.0=0
DO i=1 TO mylist.0-1
   SAY mylist.i
END
IF mylist.0<2 THEN SAY cmd' did not produce any output' 
RETURN 
/* ---------------------------------------------------------------------------------
 * Display log information  
 * ---------------------------------------------------------------------------------
 */
writelog:
transtime=displaytime          /* transaction time */
sendtime=servertime-starttime  /* time to send request to server */
servtime=resulttime-servertime /* time needed to perform at server and receive results */
outtime=displaytime-resulttime /* time to display results */
IF EXISTS('option.logtime')=0 THEN option.logtime=0 
IF option.logtime=1 THEN DO
   SAY '..... Transaction time log .....'
   SAY 'Transaction             ' xtime(transtime) 
   SAY 'Send command to Server  ' xtime(sendtime)
   SAY 'Server perform and send ' xtime(servtime)
   SAY 'Real Server usage       ' xtime(mpsftime)
   SAY 'display output          ' xtime(outtime)
END  
RETURN
/* ---------------------------------------------------------------------------------
 * Simulate Server, don't pass commands run it directly 	
 * ---------------------------------------------------------------------------------
 */
noserver:
IF EXISTS('dive$.next_extension')=0 THEN CALL divin('DIV')
option.mprout=1
incmd=TRANSLATE(cmd,,"()")
cmdx=WORD(incmd,1)
cmdv=WORD(incmd,2)
PARSE VALUE cmdv WITH p0 p1 p2 p3 p4 p5 
keepin=testgetvar('option.kept','DUMMYIN')'.'
keepout=testgetvar('option.keep','DUMMYOUT')'.'
INTERPRET 'procedure expose keepout'
SAY cmdx'-'cmdv
SAY 'call 'cmdx'('keepout','keepin',p0,p1,p2,p3,p4,p5)'
INTERPRET 'call 'cmdx'('keepout','keepin',p0,p1,p2,p3,p4,p5)'
SAY 'Members Kept in 'keepout VALUE(keepout'0')
CALL mpoutdd(mpout.)
DROP cmd.           /* release command parameters, must be set always new */
EXIT 0
/* ---------------------------------------------------------------------------------
 * Format time log  
 * ---------------------------------------------------------------------------------
 */
xtime: PROCEDURE
PARSE ARG intime
IF intime=0 THEN RETURN '0.000'
IF SUBSTR(intime,1,1)='.' THEN intime='0'||intime
inlen=LENGTH(intime)
IF inlen>2 THEN IF SUBSTR(intime,inlen-2,3)='000' THEN intime=SUBSTR(intime,1,inlen-3)
RETURN intime 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/*** --------------------------------------------------------------------------- */
/*** Auto Loaded Modules, source changes should be done in the original modules  */
/*** --------------------------------------------------------------------------- */  /*$$AUTOLOAD ALL */
ptime: PROCEDURE
ptime=TIME('l')
len=LENGTH(ptime)-3
RETURN SUBSTR(ptime,1,len)
hash:procedure
PARSE ARG text,maxvalue
len=LENGTH(text)
sqs=0
DO i=1 TO len BY 4
   sqs=sqs+c2d(SUBSTR(text,i,4)) 
END   
IF sqs>maxvalue THEN sqs=sqs//maxvalue
RETURN sqs
lock: PROCEDURE
PARSE ARG mode,resource
lockfile=DIRECTORY()'\'resource'.lck'
IF ABBREV('EXCLUSIVE',mode)=1 THEN DO 
   IF STREAM(lockfile, "C", "OPEN WRITE REPLACE")='READY:' THEN RETURN 0
   ELSE RETURN 8
END
IF ABBREV('TESTEXCLUSIVE',mode)=1 THEN DO 
   IF STREAM(lockfile, "C", "OPEN WRITE REPLACE")='READY:' THEN DO
      STREAM(lockfile, "C", "CLOSE")
      RETURN 0
   END
   ELSE RETURN 8
END
IF ABBREV('RELEASE',mode)=1 THEN DO 
      SAY STREAM(lockfile, "C", "CLOSE")
      DELETEFILE(lockfile)
      RETURN 0
END
eventcreate: PROCEDURE
PARSE ARG windowtitle,event,p0,p1
LIBRARY rexxgui
FUNCDEF('FindWindowA', 'void, str, str', 'user32', , 'o 0')
target = findwindowa('rexxgui', windowtitle)
IF target=='' THEN RETURN -2    /* window not found */
guisendmsg(target, event, p0,p1) 
IF EXISTS('guisignal')=0 THEN RETURN -1
RETURN guisignal                /*$$AUTOLOAD END ALL */
/*** ------------------------------------------------------------------------------------------------------- */
/*** XREF of (Auto-) Loaded Modules                                                                          */
/*** ------------------------------------------------------------------------------------------------------- */
/*** PTIME.REX               I:\Varserver\\SysProc\                 AUTOLOAD       281BT 23/12/2008 15:12:04 */
/*** HASH.REX                I:\Varserver\\SysProc\                 AUTOLOAD       181BT 28/12/2008 19:12:36 */
/*** LOCK.REX                I:\Varserver\\SysProc\                 AUTOLOAD         1KB 01/01/2009 10:01:10 */
/*** EVENTCREATE.REX         I:\Varserver\\SysProc\                 AUTOLOAD       345BT 31/12/2008 11:12:36 */
/*** ------------------------------------------------------------------------------------------------------- */
/*** XREF of Procedures      Defined  Used in Line   Suffix "+" Label, none Procedure                        */
/*** ------------------------------------------------------------------------------------------------------- */
/***   1 EVENTCREATE           259    132                                                                    */
/***   2 GETCMD                109+   83                                                                     */
/***   3 GETOPTION              99+   82                                                                     */
/***   4 HASH                  231    29                                                                     */
/***   5 INIT                   65+                                                                          */
/***   6 INITCLIP               24+                                                                          */
/***   7 LOCK                  240    33 53                                                                  */
/***   8 MPOUTDD               146+   15 190                                                                 */
/***   9 NOSERVER              176+                                                                          */
/***  10 PTIME                 227    18 47 55 57 68                                                         */
/***  11 READPARMS              75+                                                                          */
/***  12 RUN                     1                                                                           */
/***  13 SENDRECEIVE           130+                                                                          */
/***  14 STARTSERVER            45+                                                                          */
/***  15 TESTGETVAR            119+   183 184                                                                */
/***  16 WRITELOG              157+                                                                          */
/***  17 XTIME                 197    165 166 167 168 169                                                    */
/*** ------------------------------------------------------------------------------------------------------- */
/*** XREF of Variables              Modified in Line   Suffix "+" Parse Arg, "*" Parse Variable, none SET    */
/*** ------------------------------------------------------------------------------------------------------- */
/***   1 CMDV                                78 89 181                                                       */
/***   2 CMDX                                77 180                                                          */
/***   3 CPT.SERVERCHECKED                   35 38                                                           */
/***   4 DEFAULT                             121                                                             */
/***   5 DICTIN                              27                                                              */
/***   6 DICTOKEN                            29                                                              */
/***   7 DISPLAYTIME                         16                                                              */
/***   8 EVENT                               260+                                                            */
/***   9 EVT                                 132                                                             */
/***  10 INCMD                               76 179                                                          */
/***  11 INLEN                               201                                                             */
/***  12 INTIME                              198+                                                            */
/***  13 J                                   85 87                                                           */
/***  14 KEEPIN                              183                                                             */
/***  15 KEEPOUT                             184                                                             */
/***  16 LASTLINE                            138                                                             */
/***  17 LEN                                 229 233                                                         */
/***  18 LOCKFILE                            242                                                             */
/***  19 MAXVALUE                            232+                                                            */
/***  20 MODE                                241+                                                            */
/***  21 MPOUT                               26                                                              */
/***  22 MPSFTIME                            140                                                             */
/***  23 MYLIST.0                            139                                                             */
/***  24 MYLIST.1                            81                                                              */
/***  25 MYMPOUT                             28                                                              */
/***  26 MYVAR.0                             91                                                              */
/***  27 MYVAR.1                             92                                                              */
/***  28 MYVAR.2                             82 83                                                           */
/***  29 MYVAR.3                             84                                                              */
/***  30 MYVAR.J                             88                                                              */
/***  31 OPTION.KEEP                         10 93                                                           */
/***  32 OPTION.KEEPALSO                     8                                                               */
/***  33 OPTION.KEPT                         9                                                               */
/***  34 OPTION.MPROUT                       69 178                                                          */
/***  35 OUTTIME                             161                                                             */
/***  36 P0                                  182*                                                            */
/***  37 P1                                  182* 260+                                                       */
/***  38 P3                                  182*                                                            */
/***  39 P4                                  182*                                                            */
/***  40 P5                                  182*                                                            */
/***  41 PTIME                               228                                                             */
/***  42 REASON                              46+                                                             */
/***  43 RESOURCE                            241+                                                            */
/***  44 RESULTTIME                          14                                                              */
/***  45 RETCOUNT                            30                                                              */
/***  46 SENDSTEM                            100 102 110 112                                                 */
/***  47 SENDTIME                            159                                                             */
/***  48 SERVERTIME                          12                                                              */
/***  49 SERVTIME                            160                                                             */
/***  50 SLEEPI                              49                                                              */
/***  51 SQS                                 234 236                                                         */
/***  52 STARTTIME                           3                                                               */
/***  53 TARGET                              263                                                             */
/***  54 TEXT                                232+                                                            */
/***  55 TRANSTIME                           158                                                             */
/***  56 TVAR                                123                                                             */
/***  57 WAITR                               48                                                              */
/***  58 WINDOWTITLE                         260+                                                            */
/***  59 WRDS                                79                                                              */
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2017-9-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2011-06-15 11:46:11