CompuServe Thread

#stdio in Lattice C

6 messages in this thread
#132917From: JEFFREY C. DEGEJul 2, 1988 8:54 PM
I am trying to figure oyt programming on the Amiga. I'm using Lattice C 4.01, and I'm havin a bit of a problem. I've gotten up to chapter four in Berry's "Inside the Amiga". In his examples 4-5 and 4-6, he seems to be using stdin, etc. in ways that just don't work. In a rather round-about way, he attemps to use stdin as a File Handle for an AmigaDOS Read(). As I understand the Lattice manual, stdin is a Lattice level 2 File Pointer. FILE *stdin; not struct FileHandle *stdin; I've found a function, fdopen(), that will take a level 1 File Handle and return a level 2 File Pointer. I can't figure out how to do it the other way around. I've looked through stdio.h, and the FILE is a typedef for a pointer to a struct _iobuf. _iobuf contains info on the buffers, and an int file descriptor, which doesn't seem to be what I want. Anybody out there using Lattice C 4.0+ have any ideas?
#132923From: Bob RakoskyJul 2, 1988 10:18 PM
Jeff, Sounds like you're real close. There are basically two types of file io that you can do, using the standard input and output. (Actually, this is a simplification, but let's leave it at that for now). You can use the Lattice functions to access the input and output streams but using the Lattice level-2 file functions (getc, fgetc, gets, fgets, putc, puts, etc), which the Lattice library routines will process and pass to the AmigaDos FileHandles. Your other option is to use the AmigaDos FileHandles yourself, which you can obtain via the Input() and Output() AmigaDOS function calls, and then read from and write to them as appropriate, using the AmigaDOS file io functions Read() and Write() <— (notice the capitalization). These are basically two equivalent approaches, but using the Lattice libraries is more "standard" across machine environments, while using the AmigaDOS functions directly is more "Amiga". Hope this clarifies more than it confuses…Bob
#132945From: JEFFREY C. DEGEJul 3, 1988 1:45 AM
Thanks for the response. I was trying to rewrite the program, and I couldn't find a way to get the File Handles for stdin and stdout. I found the Input() and Output() functions in the chapter on disk files. Now to get it to work.
#132929From: Scott BallantyneJul 2, 1988 10:43 PM
Sounds like he was using the original lattice compiler, with the startup code written by Amiga, where stdin and stdout where (were, sorry) defined as LONGS and set by calls to Open() urr, Output() Input(). Only thing I can suggest is to see if the old startup code is still supplied on the lattice disk, and then link *only* with amiga.lib. Otherwise, you will have to rewrite the program, you can probably yank the 'true' filehandle out of the iobuff pointer. That help? sdb
#132946From: JEFFREY C. DEGEJul 3, 1988 1:48 AM
I found that I could get the file handles to stdin and stdout using Input() and Outpt(). I still wonder whether there's a way to get a file handle from a level 2 file pointer. I couldn't find it in the listing of iobuf in the sdtio.h, but I'm still new at this.
#133012From: John ToebesJul 3, 1988 12:44 PM
You can convert from any level file handle down. From Level2 to level1, just use fileno(fp). To go from level1 to level0, use: chkufb(fn)->ufbfh This also corresponds to the AmigaDos file handle. Note that this will work with 3.10 or 4.0 even though all the underlying I/O is different. Have fun.