Path: utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!ucsd!usc!sdd.hp.com!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!wjs From: wjs@milton.u.washington.edu (William Jon Shipley) Newsgroups: comp.sys.next Subject: Re: Connecting a Stream to a Text Object Message-ID: <11900@milton.u.washington.edu> Date: 29 Nov 90 02:28:05 GMT References: <1484@lee.SEAS.UCLA.EDU> Distribution: na Organization: University of Washington, Seattle Lines: 61 Kenneth Martin writes: >On page 10-4 of the Concepts manual, it says "You can also implement the >functions needed to connect a stream to a different source or destination, >such as a Text object, thereby creating your own type of stream." Well, I'll take a guess at this... First off, this is my guess at explaining how one might create one's own NXStream. It SOUNDS like you don't really want to do this, so skip on to the end and I'll guess at what you really want to do (I think). Creating your own kind of NXStream ================================== Lets say you have a NXStream *myStream. Then there will be a structure myStream->functions. This structure looks like: struct stream_functions { int (*read_bytes)(NXStream *s, void *buf, int count); int (*write_bytes)(NXStream *s, const void *buf, int count); int (*flush_buffer)(NXStream *s); int (*fill_buffer)(NXStream *s); void (*change_buffer)(NXStream *s); void (*seek)(NXStream *s, long offset); void (*destroy)(NXStream *s); }; I'd guess that most of the work of defining a new type of stream would be pointing those function pointers to some functions of your own devising. (For example, when you have an NXStream that is connected to a file descriptor, read_bytes probably just points to read(2) (with some packaging).) So, if you wanted to hook up an NXStream to your Text object, you'd make write_bytes point to a routine that adds a character to the object, read_bytes point to a routine that gets a character, etc. Of course, you don't want to do this for the Text object, because it's already done for you... Reading and Writing to a Text object with an NXStream ===================================================== The Text object has "readText:" and "writeText:" methods which both take a stream. The first reads text from the stream into the Text object, the second writes the Text object out onto the stream. It sounds like this is what you want to do. However, you may be saying to yourself: "Well, what if I want to read text in that I generate myself on the fly (that is, not from a file or from memory or a port)?" Then you can either a) try to diddle with the above, b) wait for the 2.0 docs to arrive, or c) just write the text you generate into an NXStream opened on a port opened into memory, and then read the memory NXStream into your Text object using the "readText:" method. I use the c) method in my newsreader (when I'm grabbing articles off of NNTP). Clear as mud? Good. Send mail to me if you have any questions, but realise that I'm bluffing here. (Hey, there aren't really any docs.) -william shipley