home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / fs24 / fs3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-19  |  2.5 KB  |  85 lines

  1. /* FS3.C
  2.  * swap_system function
  3.  * MSC7
  4.  * FS 2.4
  5.  * 201093
  6.  * Copyright (C) M. van Breemen, 1992-1993, All rights reserved.
  7.  *
  8.  * fs_systemo is a tailored version of Ralf Browns' systemo which will pass the
  9.  * current environment and calls the command interpreter without /C if 
  10.  * command is ""
  11.  *
  12.  * fs_spawnvpeo is a replacement for spawnvpeo wich is malfunctioning when
  13.  * TBCHECK is active on some systems.
  14.  */
  15.  
  16. #include <dos.h>
  17. #include <io.h>
  18. #include <stdlib.h>
  19. #include <errno.h>
  20. #include <string.h>
  21. #include "spawno.h"
  22.  
  23. int cdecl fs_systemo(const char *overlay_path, const char *command);
  24. int _Cdecl fs_spawnvpeo(const char *overlay_path, const char *prog_name,
  25.             const char **args, const char **env);
  26. void locate_processor(char *command, char *processor);
  27. unsigned int pascal __spawn_buildenv(const char **env) ;
  28. void pascal __spawn_free_env(void) ;
  29.  
  30.  
  31. int cdecl fs_systemo(const char *overlay_path, const char *command)
  32. {
  33.    char *comspec;
  34.    char c_switch[3];
  35.    char *arglist[4];           /* final argument list */
  36.  
  37.    comspec = getenv("COMSPEC") ;   
  38.    if (!comspec || *comspec == '\0') comspec = "COMMAND";  /* default command interpreter */
  39.  
  40.    if (strlen(command)) strcpy(c_switch,"/C");             /* execute command and exit */
  41.    else strcpy(c_switch," ");                              /* or just start the command interpreter */
  42.                                /* this will save one instance of command */
  43.    arglist[0]=comspec;
  44.    arglist[1]=c_switch;
  45.    arglist[2]=(char *) command;
  46.    arglist[3]=(char *) 0L;
  47.  
  48.    return fs_spawnvpeo(overlay_path,comspec,arglist,_environ) ;
  49. }
  50.  
  51.  
  52.  
  53. int _Cdecl fs_spawnvpeo(const char *overlay_path, const char *prog_name,
  54.              const char **args, const char **env)
  55. {
  56.    char prog_path[_MAX_PATH];
  57.  
  58.    /* find the processor location */
  59.    locate_processor( (char *) prog_name, prog_path);
  60.  
  61.    /* ending with .BAT. We can't spawn a batch file */
  62.    if (strstr(prog_path,".BAT")==(prog_path+strlen(prog_path)-4))
  63.    {
  64.       errno = ENOENT ;       /* path or filename not found */
  65.       _doserrno= ENOENT;   /* not sure about this one */
  66.       return -1 ;
  67.    }
  68.  
  69.    /* Did we find a valid processor to spawn ? */
  70.    if (strlen(prog_path))
  71.    {
  72.       int retval ;
  73.  
  74.       retval = __spawnv(overlay_path,prog_path,args,__spawn_buildenv(env)) ;
  75.       __spawn_free_env() ;
  76.       return retval ;
  77.    }
  78.    else
  79.    {
  80.       errno = ENOENT ;        /* path or filename not found */
  81.       _doserrno= ENOENT;    /* not sure about this one */
  82.       return -1 ;
  83.    }
  84. }
  85.