home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / pascal / pasexec.inc < prev    next >
Encoding:
Text File  |  1988-08-11  |  4.3 KB  |  103 lines

  1. {   PASEXEC.INC - interface file for C library routines
  2.  
  3.     This include file along with the CEXEC.LIB library has been included
  4.     with your Pascal 3.32 to show you how easy it is to call routines
  5.     written in our new C 4.00 release.    The CEXEC.LIB contains several
  6.     routines from the C library which we think you will find useful in
  7.     extending the power of your Pascal programs.
  8.  
  9.     The memory model that Pascal uses is basically medium model (16-bit
  10.     data pointers) with some extensions for large model addressing
  11.     (32-bit data pointers).  The CEXEC.LIB routines are from the large
  12.     model C library.  This means that you should be careful interfacing
  13.     to these routines.    You should use ADS or VARS instead of ADR or VAR
  14.     so that 32-bit addressed get constructed.
  15.  
  16.     The Microsoft FORTRAN 3.3x, PASCAL 3.32, and C 4.00 releases
  17.     have been designed so that libraries or subprograms can be written
  18.     in any one of these languages and used in any other.
  19.  
  20.     Try compiling and running the demonstration program DEMOEXEC.PAS
  21.     to see some actual examples.
  22. }
  23.  
  24. {   C function
  25.  
  26.         int system(string)
  27.             char *string;
  28.  
  29.     The system() function passes the given C string (00hex terminated)
  30.     to the DOS command interpreter (COMMAND.COM), which interprets and
  31.     executes the string as an MS-DOS command.  This allows MS-DOS commands
  32.     (i.e., DIR or DEL), batch files, and programs to be executed.
  33.  
  34.     Example usage in Pascal
  35.  
  36.     i := system(ads('dir *.for'*chr(0)));
  37.  
  38.     The interface to system is given below.  The [c] attribute is given
  39.     after the function return type.  The [varying] attribute says the
  40.     function has an undetermined number of parameters; in this case, 1.
  41. }
  42.  
  43.     function system : integer [c,varying]; extern;
  44.  
  45. {   C function
  46.  
  47.     int spawnlp(mode,path,arg0,arg1,...,argn)
  48.         int mode;            /* spawn mode */
  49.         char *path;         /* pathname of program to execute */
  50.         char *arg0;         /* should be the same as path */
  51.         char *arg1,...,*argn;   /* command line arguments */
  52.                     /* argn must be NULL */
  53.  
  54.     The spawnlp creates and executes a new child process.  There must be
  55.     enough memory to load and execute the child process.  The mode
  56.     argument determines which form of spawnlp is executed as follows:
  57.  
  58.     Value        Action
  59.  
  60.       0        Suspend parent program and execute the child program.
  61.             When the child program terminates, the parent program
  62.             resumes execution.    The return value from spawnlp is -1
  63.             if an error has occured or if the child process has
  64.             run, the return value is the child processes return
  65.             code.
  66.  
  67.     _p_overlay  Overlay parent program with the child program.  The
  68.             child program is now the running process and the
  69.             parent process is terminated.  spawnlp only returns
  70.             a value if there has been a recoverable error.  Some
  71.             errors can not be recovered from and execution will
  72.             terminate by safely returning to DOS.  This might
  73.             happen if there is not enough memory to run the new
  74.             process.
  75.  
  76.     The path argument specifies the file to be executed as the child
  77.     process.  The path can specify a full path name (from the root
  78.     directory \), a partial path name (from the current working directory),
  79.     or just a file name.  If the path argument does not have a filename
  80.     extension or end with a period (.), the spawnlp call first appends
  81.     the extension ".COM" and searches for the file; if unsuccessful, the
  82.     extension ".EXE" is tried.    The spawnlp routine will also search for
  83.     the file in any of the directories specified in the PATH environment
  84.     variable (using the same procedure as above).
  85.  
  86.     Example usage in Pascal
  87.  
  88.     var     NULL : integer4;
  89.     value   NULL := 0;
  90.     ...
  91.     i := spawnlp(0, ads('exemod'*chr(0)), ads('exemod'*chr(0)),
  92.          ads('demoexec.exe'*chr(0)), NULL);
  93.  
  94.     The C spawnlp function is expecting the addresses of the strings
  95.     (not the actual characters), so we use the ADS() function to pass
  96.     the address of the strings.  The last parameter to the spawnlp
  97.     routine must be a C NULL pointer which is a 32-bit integer 0, so
  98.     we use an INTEGER4 variable NULL set to 0 as the last parameter.
  99. }
  100.  
  101.     var _p_overlay [c,extern] :integer;
  102.     function spawnlp : integer [c,varying]; extern;
  103.