home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / atari / st / tech / 4687 < prev    next >
Encoding:
Text File  |  1992-09-04  |  2.7 KB  |  64 lines

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