home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / S3KILL.OPL < prev    next >
Text File  |  1992-04-27  |  11KB  |  297 lines

  1. REM ***************************************************************************
  2. REM    Name        : RUNAPP%
  3. REM ***************************************************************************
  4. REM    Description : Runs a named application.
  5.  
  6. REM    Parameters  : appname$ = full path name of application image file.
  7. REM                  cmdline$ = command line to the application
  8. REM                  ppid%    = pointer to integer to receive process id
  9.  
  10. REM    Returned    : zero for success, else -ve error number
  11. REM    Conditions  : The file must exist and be a valid image.
  12. REM    Effects     : None
  13.  
  14. REM    Errors      : File not found
  15. REM                  Invalid file
  16. REM    Panics      : None
  17. REM ***************************************************************************
  18.  
  19.  
  20. PROC runapp%:(appname$,cmdline$,ppid%)
  21.  
  22. REM ***************************************************************************                 
  23. REM                 Local Variable Declarations
  24. REM ***************************************************************************                  
  25.  
  26.     local ax%,bx%,cx%,dx%,si%,di%
  27.     local ret%,flags%
  28.     local cmdl$(128),img$(128)
  29.  
  30. REM ***************************************************************************   
  31. REM                       Procedure Code
  32. REM ***************************************************************************   
  33.  
  34.     cmdl$=cmdline$
  35.     img$=appname$+chr$(0)
  36.  
  37.     REM -- first create the application --
  38.     REM
  39.     ax%=$0100                   :REM set AH = 1 for "FilExecute" call
  40.     bx%=addr(img$)+1            :REM set BX = pointer to application name
  41.     cx%=addr(cmdl$)              :REM set CX = pointer to length of command line
  42.     di%=ppid%                   :REM set DI = address to take process id
  43.     flags%=os(135,addr(ax%))    :REM call "FilExecute"
  44.     if (flags% and 1)
  45.         ret%=(ax% and $FF)-256    :REM error returned from O/S call in AL
  46.     else
  47.         REM -- now run the created application --
  48.         REM
  49.         ax%=$0600                   :REM set AH = 6 for "ProcResume" call
  50.         bx%=peekw(ppid%)            :REM set BX = process id
  51.         flags%=os(136,addr(ax%))    :REM call "ProcResume"
  52.         if (flags% and 1)
  53.             ret%=(ax% and $FF)-256    :REM error returned from O/S call in AL
  54.         else
  55.             ret%=0                    :REM return success
  56.         endif
  57.     endif
  58.     return ret%
  59. ENDP
  60.  
  61.  
  62.  
  63. REM ***************************************************************************
  64. REM    Name        : RUNOPL%
  65. REM ***************************************************************************
  66. REM    Description : Runs a named OPL program.
  67.  
  68. REM    Parameters  : oplname$ = full path name of OPL program file.
  69. REM                  ppid%    = pointer to integer to receive process id
  70.  
  71. REM    Returned    : zero for success, else -ve error number
  72. REM    Conditions  : The file must exist and be a valid OPO file.
  73. REM    Effects     : None
  74.  
  75. REM    Errors      : File not found
  76. REM                 Invalid file
  77. REM    Panics      : None
  78. REM ***************************************************************************
  79.  
  80.  
  81. PROC runopl%:(oplname$,ppid%)
  82.  
  83. REM ***************************************************************************    
  84. REM                  Local Variable Declarations
  85. REM ***************************************************************************    
  86.  
  87.     local ret%,i%,pname$(15)
  88.     local cmdl$(150),opo$(15)
  89.  
  90. REM ***************************************************************************   
  91. REM                          Procedure Code
  92. REM ***************************************************************************   
  93.  
  94.     REM -- check if the file exists since a successful return --
  95.     REM --    would still be made for EXOPL.IMG otherwise     --
  96.     REM
  97.     if lower$(right$(oplname$,4))=".opo"
  98.         opo$=oplname$
  99.     else
  100.         opo$=oplname$+".opo"
  101.     endif
  102.     if not exist(opo$)
  103.         ret%=-33 : REM ERR_FILERR_NXIST (module does not exist)
  104.     else
  105.         REM -- build up the command line to EXOPL --
  106.         REM
  107.         cmdl$=opo$+chr$(0)+" -n"             :REM -n flag disables notifier
  108.  
  109.         REM -- attempt to run the program, returning process id or error --
  110.         REM
  111.         ret%=RUNAPP%:("ROM::EXOPL",cmdl$,ppid%)
  112.     endif
  113.     return ret%
  114. ENDP
  115.  
  116.  
  117.  
  118. REM ***************************************************************************
  119. REM    Name        : APPKILL%
  120. REM ***************************************************************************
  121. REM    Description : Kill an existing application.
  122.  
  123. REM    Parameters  : pid% = process id of appliction to kill
  124.  
  125. REM    Returned    : zero for success, else -ve error number
  126. REM    Conditions  : None
  127. REM    Effects     : None
  128.  
  129. REM    Errors      : Process does not exist
  130. REM    Panics      : None
  131. REM ***************************************************************************
  132.  
  133.  
  134. PROC appkill%:(pid%)
  135.  
  136. REM ***************************************************************************   
  137. REM                  Local Variable Declarations
  138. REM ***************************************************************************  
  139.  
  140.     local ax%,bx%,cx%,dx%,si%,di%
  141.     local ret%,flags%
  142.  
  143. REM ***************************************************************************   
  144. REM                         Procedure Code
  145. REM ***************************************************************************   
  146.  
  147.     ax%=$0D00                   :REM set AH = 8 for "ProcTerm" call
  148.     bx%=pid%                    :REM set BX = process id
  149.     flags%=os(136,addr(ax%))    :REM call "ProcTerm"
  150.     if (flags% and 1)
  151.         ret%=(ax% and $FF)-256    :REM error returned from O/S call in AL
  152.     else
  153.         ret%=0                    :REM signal success
  154.     endif
  155.     return ret%
  156. ENDP
  157.  
  158.  
  159. REM ***************************************************************************
  160. REM    Name        : APPDIR$
  161. REM ***************************************************************************
  162. REM    Description : Obtain a list of all processes currently in existence.
  163.  
  164. REM    Parameters  : search$ = wildcard match string
  165. REM                  fidptr% = pointer to integer find handle
  166.  
  167. REM    Returned    : The next process name, else a null string ("") for error
  168. REM    Conditions  : None
  169. REM    Effects     : None
  170.  
  171. REM    Errors      : No more processes
  172. REM    Panics      : None
  173. REM ***************************************************************************
  174.  
  175.  
  176. PROC appdir$:(search$,fidptr%)
  177.  
  178. REM ***************************************************************************   
  179. REM                  Local Variable Declarations
  180. REM ***************************************************************************   
  181.  
  182.     local ax%,bx%,cx%,dx%,si%,di%
  183.     local ret$(15),flags%,name$(15),r%,i%
  184.  
  185. REM ***************************************************************************
  186. REM                         Procedure Code
  187. REM ***************************************************************************
  188.  
  189.     r%=addr(ret$)                 :REM get address of return buffer
  190.     name$=search$                 :REM make local copy of process name
  191.     ax%=$0b00                     :REM set AH = 11 for "ProcFind" call
  192.     bx%=peekw(fidptr%)            :REM set BX = find handle
  193.     si%=r%+1                      :REM set SI = pointer to return buffer
  194.     di%=addr(name$)+1             :REM set DI = wildcard process match string
  195.     flags%=os(136,addr(ax%))      :REM call "ProcFind"
  196.     if (flags% and 1)
  197.         ret$=""                     :REM return null string for error
  198.     else
  199.         i%=1                        :REM search from start of buffer for length
  200.         while peekb(r%+i%)<>0       :REM while terminating 0 is not found
  201.             i%=i%+1                   :REM increment search index
  202.         endwh
  203.         pokeb r%,i%-1               :REM force length into string
  204.         pokew fidptr%,ax%           :REM update the find handle
  205.     endif
  206.     return ret$
  207. ENDP
  208.  
  209.  
  210. REM --------------------------------------------------------------------------
  211. REM    Name        : APPID%
  212. REM  ----------------------------------------------------------------------------
  213. REM    Description : Obtain the id of a process by name.
  214.  
  215. REM    Parameters  : appname$ = process name
  216. REM                  ppid%    = pointer to integer to receive process id
  217.  
  218. REM    Returned    : zero for success, else -ve error nu