[comp.sys.atari.st] stdprn problem in Sozobon C -- dlibs

achowe@tiger.waterloo.edu (anthony howe) (09/18/89)

I have been having trouble with Sozobon C libraries -- dlibs. It seems
that if I try and use  stdprn  to send output to the printer like 
expect then it goes to the screen yet if I open a  PRN:  file and use
this file stream things work fine. Examples to follow.


/*
	This does not send output to the printer as expected. Instead it
	goes to the screen.
*/
#include <stdio.h>

main()
{
        fprintf( stdprn, "foobar\n" );
}



/*
	This does send output to the printer.
*/
#include <stdio.h>

main()
{
        register FILE* prn;
        prn = fopen( "PRN:", "wb" );
        fprintf( prn, "foobar\n" );
}


I have looked at the code  MAIN.C  and the _iob table and nothing seems
odd. I've quick glanced over the code for  FOPEN.C  and  OPEN.C, also
also printf code right down to  WRITE.C. I can't figure what the problem
or differences are?

Could Dale Schumacker or someone who may have tried to use  stdprn tell
me what either I'm doing wrong or if there is library fix I missed.

- Ant



  achowe@tiger.waterloo.edu     | "Life is not fair. Anyone who tells
   _     -|-|_   _              |  you different is trying to sell you
  (_\ |\| | | | (_) |\| \/      |  something." - The Princess Bride
                     ___/       |                        disclaimer...

dal@syntel.mn.org (Dale Schumacher) (09/20/89)

[achowe@tiger.waterloo.edu (anthony howe) writes...]
> I have been having trouble with Sozobon C libraries -- dlibs. It seems
> that if I try and use  stdprn  to send output to the printer like 
> expect then it goes to the screen yet if I open a  PRN:  file and use
> this file stream things work fine. Examples to follow.
> 
> Could Dale Schumacker or someone who may have tried to use  stdprn tell
> me what either I'm doing wrong or if there is library fix I missed.

Ooops.  There _IS_ a bug in main.c in the _iob[] initialization.  I got
the printer and aux handles (the positive, redirectable ones) backwards.
The lines which now read:

/* stdprn */	{0, NULL, NULL, (_IOWRT | _IONBF), 2, 0, '\0'},
/* stdaux */	{0, NULL, NULL, (_IOREAD | _IOWRT | _IONBF), 3, 0, '\0'},

...should instead read:

/* stdprn */	{0, NULL, NULL, (_IOWRT | _IONBF), 3, 0, '\0'},
/* stdaux */	{0, NULL, NULL, (_IOREAD | _IOWRT | _IONBF), 2, 0, '\0'},

One thing to note, however, is that when you open "PRN:" you will
be talking to the negative handle which refers to the device rather
than the positive one associated with the standard stream.  This
may not make any difference to you, but it will make the handles
different even if they _DO_ talk to the same device.

Another issue is that some shells (like the ones which work well with
GCC) may take over handle 2 (which TOS defines as the standard aux) and
use it for standard error (like *NIX).  This would cause output to
handle 2 (previously, stdprn, but stdaux after the "fix") to appear on
the screen!  This sounds part of your problem.

\\   /  Dale Schumacher                         399 Beacon Ave.
 \\ /   (alias: Dalnefre')                      St. Paul, MN  55104-3527
  ><    ...umn-cs!midgard.mn.org!syntel!dal     United States of America
 / \\   "What is wanted is not the will to believe, but the will to find out,
/   \\  which is the exact opposite." -Bertrand Russell