home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.atari.st.tech
- Path: sparky!uunet!sun-barr!ames!agate!usenet.ins.cwru.edu!news.csuohio.edu!neumann.cba.csuohio.edu!max
- From: max@neumann.cba.csuohio.edu (Max Polk)
- Subject: Re: LASER C PRINTING
- Message-ID: <1992Sep4.145336.4676@news.csuohio.edu>
- Summary: Short explanation of IO and fprintf (stdprt, ...)
- Sender: news@news.csuohio.edu (USENET News System)
- Organization: Cleveland State University
- Date: Fri, 4 Sep 1992 14:53:36 GMT
- Lines: 52
-
- From what I can tell, Atari and LASER C run things this way:
-
- LEVEL OF COMMUNICATION IMPLEMENTATION TYPICAL CALLS
- Device BIOS Bconin, Bconout
- File descriptor GEMDOS Fopen, Fread, Fwrite, Cconin, Cconout
- Stream LASER C fopen, fread, fwrite, printf, fprintf
-
- Each higher level uses the previous level to accomplish their tasks.
- For example, printf calls Fwrite, (yes, even for screen output!), and
- Fwrite within the operating system calls Bconout at some point.
-
- An array of 20 _iob structures are standard for LASER C programs, which
- are used for the fread, fwrite, printf, etc. The first three are
- already used when your program runs, much like UNIX does things. These
- are _iob[0], _iob[1], and _iob[2], which are structures whose addresses
- are stdin, stdout, and stderr, and represent buffered file IO, called
- streams.
-
- In UNIX, the first three _iob structures use file descriptors 0, 1, and
- 2. But in LASER C, it is 0, 1, and 1. Writing to stderr is really the
- same as stdout. In UNIX, programs know to write to any one of three files
- whose descriptors are 0, 1, or 2. But in Atari, there is only 0 and 1.
-
- Even if you can manage to Fdup the console output and change the
- association of stderr to it, programs executed with this in place won't
- care about what you did, because only file descriptors 0 and 1 have
- significance.
-
- Furthermore, in UNIX, opening a file results in file descriptor 3, the
- next consecutive number, being used, wherease in Atari, it is number 6.
- (Let me use "fd" to mean file descriptor.) This is because Atari is
- different than UNIX as far as standard devices is concerned. UNIX uses
- your /dev/tty?? as your single device. Atari likewise has the console input
- and output like UNIX but also has a serial port (fd 2), printer port (fd 3),
- and two other devices open (fd 4 and fd 5) when your program begins.
-
- LASER C has no such thing as stdprt, that is, a pre-opened stream
- connected with the printer. However, the printer device is ready and has
- fd 3, so you can simply associate a stream with it as follows:
-
- #include <stdio.h>
-
- FILE *stdprt;
-
- main ()
- {
- stdprt = fdopen (3, "w"); /* make a stream for the printer */
-
- fprintf (stdprt, "This goes to the printer");
-
- ....
- }
-