home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / SCRIPT.OPL < prev    next >
Text File  |  1992-08-26  |  5KB  |  127 lines

  1. REM -------------------------------------------------------------------------
  2. REM    Name        : SCRIPT
  3. REM ------------------------------------------------------------------------- 
  4.  
  5. REM   Author     :  DP
  6.  
  7. REM   Description:  Runs a named script file from an OPL program
  8.  
  9.  
  10. PROC script:
  11.  
  12.  
  13. REM                 --------------------------- 
  14. REM                 Local Variable Declarations  
  15. REM                 --------------------------- 
  16.  
  17.     LOCAL appn$(128)    REM  full application name and path
  18.     LOCAL cmdl$(128)    REM  full command line
  19.     LOCAL ppid%        REM  process id (handled by OS)
  20.     LOCAL ret%        REM  return value for errors
  21.  
  22. REM          --------------------------- 
  23. REM                      Notes            
  24. REM          --------------------------- 
  25.  
  26. REM The application to use for scripts is "LOC::C:\APP\COMMS.APP"
  27. REM for OPO or OPA files use "ROM::SYS$PRGO.IMG" and for other ROM
  28. REM based applications use "ROM::DATA.APP" for DATA "ROM::WORD.APP"
  29. REM for WORD etc.
  30.  
  31. REM The command line consists of the following syntax.
  32.  
  33. REM For OPOs:
  34. REM  cRunOpl+CHR$(0)+<aliasInfo>+CHR$(0)+<fullPathOpo>
  35. REM For OPAs:
  36. REM  c<familyName>+CHR$(0)+<aliasInfo>+CHR$(0)+<fullPathUsedFile>+CHR$(0)+<fullPathOPA>
  37. REM For APPs
  38. REM  c<familyName>+CHR$(0)+<aliasInfo>+CHR$(0)+<fullPathUsedFile>
  39.  
  40. REM Where:
  41. REM       c    = command byte ('C' for create 'O' for open)
  42. REM             NB.  command byte ignored for OPOs.
  43. REM       CHR$(0) = zero byte terminate the strings
  44.  
  45. REM       <familyName> is as defined in APP keyword of OPA or
  46. REM                apllication name of APP.
  47. REM                NB. This string must only have the first letter in upper case
  48.  
  49. REM       <aliasInfo>  the file extension the APP or OPA looks for 
  50.  
  51. REM       <fullPathUsedFile> file that OPA or APP is to open or create
  52.  
  53. REM NB. all parameters in <> are optional
  54.  
  55.  
  56. REM              --------------------------- 
  57. REM                     Procedure Code       
  58. REM              --------------------------- 
  59.  
  60.     appn$="LOC::C:\APP\COMMS.APP"
  61.     cmdl$="OComms"+CHR$(0)+".SCO"+CHR$(0)+"LOC::C:\SCO\_CIX.SCO"+CHR$(0)
  62.     ret%=runapp%:(appn$,cmdl$,addr(ppid%))              
  63.  
  64.     REM The above code passes the name of the script file to be run
  65.     REM which is _cix.sco on the 'C' device
  66.  
  67. ENDP
  68.  
  69. REM --------------------------------------------------------------------------
  70. REM     Name        : RUNAPP%
  71. REM ----------------------------------------------------------------------------
  72. REM     Description : Runs a named application.
  73.  
  74. REM     Parameters  : appname$ = full path name of application image file.
  75. REM                   cmdline$ = command line to the application
  76. REM                   ppid%    = pointer to integer to receive process id
  77.  
  78. REM     Returned    : zero for success, else -ve error number
  79. REM     Conditions  : The file must exist and be a valid image.
  80. REM     Effects     : None
  81.  
  82. REM     Errors      : File not found
  83. REM                   Invalid file
  84. REM     Panics      : None
  85. REM  -------------------------------------------------------------------------- */
  86.  
  87. PROC runapp%:(appname$,cmdline$,ppid%)
  88.  
  89. REM                   --------------------------- */
  90. REM                    Local Variable Declarations */ 
  91. REM                   --------------------------- */
  92.  
  93.   local ax%,bx%,cx%,dx%,si%,di%
  94.   local ret%,flags%
  95.   local cmdl$(128),img$(128)
  96.  
  97. REM                    --------------------------- */
  98. REM                         Procedure Code        */
  99. REM                    --------------------------- */
  100.  
  101.   cmdl$=cmdline$+chr$(0)         REM must be zero terminated
  102.   img$=appname$+chr$(0)
  103.  
  104.   REM -- first create the application --
  105.   REM
  106.   ax%=$0100                   REM set AH = 1 for "FilExecute" call
  107.   bx%=addr(img$)+1            REM set BX = pointer to application name
  108.   cx%=addr(cmdl$)             REM set CX = pointer to legth byte of command line
  109.   di%=ppid%                   REM set DI = address to take process id
  110.   flags%=os(135,addr(ax%))    REM call "FilExecute"
  111.   if (flags% and 1)
  112.     ret%=(ax% and $FF)-256    REM error returned from O/S call in AL
  113.   else
  114.     REM -- now run the created application --
  115.     REM
  116.     ax%=$0600                   REM set AH = 6 for "ProcResume" call
  117.     bx%=peekw(ppid%)            REM set BX = process id
  118.     flags%=os(136,addr(ax%))    REM call "ProcResume"
  119.     if (flags% and 1)
  120.       ret%=(ax% and $FF)-256    REM error returned from O/S call in AL
  121.     else
  122.       ret%=0                    REM return success
  123.     endif
  124.   endif
  125.   return ret%
  126. ENDP
  127.