home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l360 / 2.ddi / LINITIO.@ / LINITIO.C
Encoding:
C/C++ Source or Header  |  1991-04-08  |  1.6 KB  |  85 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <ios1.h>
  5.  
  6. extern char _DOS,**_ARGV,**environ;
  7. extern int _ARGC;
  8.  
  9. #ifndef TINY
  10. extern int _stack,_fmode,_iomode;
  11. extern struct UFB _ufbs[];
  12. #endif
  13.  
  14. /**
  15. *
  16. * name         initio - open files (extracted from _main.c)
  17. *
  18. * synopsis     initio();
  19. *
  20. * description    This function performs the standard file pre-processing for
  21. *        a Lattice C program.
  22. *
  23. **/
  24. void LINITIO()
  25. {
  26. #ifndef TINY
  27. int x,y;
  28. #endif
  29.  
  30. #if MSDOS1
  31. #ifndef TINY
  32. FILE *fp0, *fp1, *fp2;
  33. extern char _iname[],_oname[];
  34. extern int _bufsiz;
  35. char *getmem();
  36. #endif
  37. #endif
  38.  
  39. /*
  40. *
  41. * Open standard files
  42. *
  43. */
  44. #ifndef TINY
  45. #if MSDOS1
  46. if(_DOS < 2)
  47.     {
  48.     fp0 = freopen(_iname,"r",stdin);
  49.     if(_oname[0] != '>') fp1 = freopen(_oname,"w",stdout);
  50.     else fp1 = freopen(&_oname[1],"a",stdout);
  51.     fp2 = freopen("","a",stderr);
  52.     if (fp2 == NULL) _exit(1);
  53.     if (fp0 == NULL)
  54.        {
  55.        fputs("Can't open stdin file\n", fp2);
  56.        exit(1);
  57.        }
  58.     setbuf(fp0, getmem(_bufsiz));    /* set stdin buffered */
  59.     fp0->_flag &= ~_IOMYBUF;    /* allow rlsmem if later set unbuff'd */
  60.     if (fp1 == NULL)
  61.        {
  62.        fputs("Can't open stdout file\n", fp2);
  63.        exit(1);
  64.        }
  65.     }
  66. else
  67. #endif
  68.     {
  69.     x = (_fmode) ? 0 : _IOXLAT;
  70.     stdin->_file = 0;
  71.     stdin->_flag = _IOREAD | x;
  72.     stdout->_file = 1;
  73.     stdout->_flag = _IOWRT | x;
  74.     if ((getfc(1,&y) == 0) && (y & 0x80)) stdout->_flag |= _IONBF;
  75.     stderr->_file = 2;
  76.     stderr->_flag = _IORW | _IONBF | x;
  77.     stdaux->_file = 3;
  78.     stdaux->_flag = _IORW | x;
  79.     stdprt->_file = 4;
  80.      stdprt->_flag = _IOWRT | x;
  81.     }
  82. #endif
  83.  
  84. }
  85.