home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d523 / bmake.lha / BMake / source.lzh / ben / system.c < prev   
C/C++ Source or Header  |  1991-07-20  |  1KB  |  64 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 <graphics/gfxbase.h>
  8. #include <dos/dos.h>
  9. #include <dos/dosextens.h>
  10. #include <dos/dostags.h>
  11.  
  12. #include <lib/misc.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18.  
  19. #define BTOC(bptr,ctype)    ((ctype *)((long)bptr << 2))
  20. #define CTOB(ptr)           ((long)(ptr) >> 2)
  21.  
  22. extern struct GfxBase *GfxBase;
  23.  
  24. /*    Synchronous external command (wait for return)
  25.  *    Uses your Input/Output unless you supply other handle
  26.  *    Result will be return code of the command, unless the System() call
  27.  *    itself fails, in which case the result will be -1
  28.  */
  29. long
  30. doCommand( char *command, BPTR other )
  31. {
  32.     struct TagItem stags[3];
  33.  
  34.     stags[0].ti_Tag = SYS_Input;
  35.     stags[0].ti_Data = other ? other : Input();
  36.     stags[1].ti_Tag = SYS_Output;
  37.     stags[1].ti_Data = other ? 0L : Output();
  38.     stags[2].ti_Tag = TAG_DONE;
  39.     return( System( command, stags ));
  40. }
  41.  
  42. long
  43. xsystem( char *cmd )
  44. {
  45.     long errcode = -1L;
  46.     char *s;
  47.     int sflag = 1;
  48.  
  49.     if( GfxBase->LibNode.lib_Version < 36L )
  50.         sflag = 0;
  51.     else if( s = getenv( "SYSTEM" ))
  52.         sflag = (*s == 'n') ? 0 : 1;
  53.     
  54.     if( sflag ) {
  55.         errcode = doCommand( cmd, 0L );
  56.     }
  57.     else {
  58.         long r = Execute( cmd, (BPTR)0L, Output());
  59.         /* if( r == -1L ) */
  60.         errcode = IoErr();
  61.     }
  62.     return errcode;
  63. }
  64.