home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / common / redirerr.c < prev    next >
C/C++ Source or Header  |  2002-01-18  |  2KB  |  85 lines

  1. #include "../h/gsupport.h"
  2.  
  3. /*
  4.  * redirerr - redirect error output to the named file. '-' indicates that
  5.  *  it should be redirected to standard out.
  6.  */
  7. int redirerr(p)
  8. char *p;
  9.    {
  10.    if ( *p == '-' ) { /* let - be stdout */
  11.  
  12. /*
  13.  * The following code is operating-system dependent [@redirerr.01].  Redirect
  14.  *  stderr to stdout.
  15.  */
  16.  
  17. #if PORT
  18.    /* may not be possible */
  19.    Deliberate Syntax Error
  20. #endif                    /* PORT */
  21.  
  22. #if AMIGA
  23.    #if AZTEC_C
  24.        /*
  25.         * If it doesn't work, try trick used for HIGH_C, below.
  26.         */
  27.        stderr->_unit  = stdout->_unit;
  28.        stderr->_flags = stdout->_flags;
  29.    #endif                /* AZTEC C */
  30.    #if LATTICE || __SASC
  31.       /*
  32.        * The following code varies from compiler to compiler, or even
  33.        *  between versions of the same compiler (e.g. lattice 3.1 vs. 4.0).
  34.        */
  35.       stderr->_file = stdout->_file;
  36.       stderr->_flag = stdout->_flag;
  37.    #endif                /* LATTICE || __SASC */
  38. #endif                    /* AMIGA */
  39.  
  40. #if ARM 
  41.    /* cannot do this */
  42. #endif                    /* ARM */
  43.  
  44. #if MSDOS || OS2 || VMS
  45.    #if HIGHC_386 || NT
  46.       /*
  47.        * Don't like doing this, but it seems to work.
  48.        */
  49.       setbuf(stdout,NULL);
  50.       setbuf(stderr,NULL);
  51.       stderr->_file = stdout->_file;
  52.    #else                /* HIGHC_386 || NT */
  53.       dup2(fileno(stdout),fileno(stderr));
  54.    #endif                /* HIGHC_386 || NT */
  55. #endif                    /* MSDOS || OS2 ... */
  56.  
  57. #if MACINTOSH
  58.    #if LSC
  59.       /* cannot do */
  60.    #endif                /* LSC */
  61.    #if MPW
  62.       close(fileno(stderr));
  63.       dup(fileno(stdout));
  64.    #endif                /* MPW */
  65. #endif                    /* MACINTOSH */
  66.  
  67. #if UNIX
  68.       /*
  69.        * This relies on the way UNIX assigns file numbers.
  70.        */
  71.       close(fileno(stderr));
  72.       dup(fileno(stdout));
  73. #endif                    /* UNIX */
  74.  
  75. /*
  76.  * End of operating-system specific code.
  77.  */
  78.  
  79.        }
  80.     else    /* redirecting to named file */
  81.        if (freopen(p, "w", stderr) == NULL)
  82.           return 0;
  83.    return 1;
  84.    }
  85.