home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / utility / bmake15.lzh / ben / system.c < prev   
Encoding:
C/C++ Source or Header  |  1991-10-26  |  1.3 KB  |  63 lines

  1. /*    system.c
  2.  *  (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/libraries.h>
  7. #include <dos/dos.h>
  8. #include <dos/dosextens.h>
  9. #include <dos/dostags.h>
  10.  
  11. #include <lib/misc.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/dos_protos.h>
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #define BTOC(bptr,ctype)    ((ctype *)((long)bptr << 2))
  19. #define CTOB(ptr)           ((long)(ptr) >> 2)
  20.  
  21. extern struct Library *SysBase;
  22.  
  23. /*    Synchronous external command (wait for return)
  24.  *    Uses your Input/Output unless you supply other handle
  25.  *    Result will be return code of the command, unless the System() call
  26.  *    itself fails, in which case the result will be -1
  27.  */
  28. long
  29. doCommand( char *command, BPTR other )
  30. {
  31.     struct TagItem stags[3];
  32.  
  33.     stags[0].ti_Tag = SYS_Input;
  34.     stags[0].ti_Data = other ? other : Input();
  35.     stags[1].ti_Tag = SYS_Output;
  36.     stags[1].ti_Data = other ? 0L : Output();
  37.     stags[2].ti_Tag = TAG_DONE;
  38.     return( System( command, stags ));
  39. }
  40.  
  41. long
  42. xsystem( char *cmd )
  43. {
  44.     long errcode = -1L;
  45.     char *s;
  46.     int sflag = 1;
  47.  
  48.     if( SysBase->lib_Version < 36L )
  49.         sflag = 0;
  50.     else if( s = getenv( "SYSTEM" ))
  51.         sflag = (*s == 'n') ? 0 : 1;
  52.     
  53.     if( sflag ) {
  54.         errcode = doCommand( cmd, 0L );
  55.     }
  56.     else {
  57.         long r = Execute( cmd, (BPTR)0L, Output());
  58.         /* if( r == -1L ) */
  59.         errcode = IoErr();
  60.     }
  61.     return errcode;
  62. }
  63.