Path: utzoo!attcan!uunet!cs.utexas.edu!usc!ucsd!ames!lll-winken!sun-barr!newstop!sun!stpeter.Eng.Sun.COM!cmcmanis From: cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga.tech Subject: Re: mixing standard i/o with intuition messages Message-ID: <137309@sun.Eng.Sun.COM> Date: 14 Jun 90 21:08:05 GMT References: <3242@goanna.cs.rmit.oz.au> Sender: news@sun.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, Ca. Lines: 67 In article <3242@goanna.cs.rmit.oz.au> (Philip Hingston) writes: >The subject line is basically my question: is it possible? Can I write >a command loop which acts on intuition (or other, e.g. arexx) messages >as well as reading lines from standard input? You probably want something along the lines of select() in UNIX. The answer is that it is possible, it isn't very intuitive and that is a problem, and it isn't as easy as it should be but we will get to that in a minute. First, you have to realize that a single call to Wait() can wait on multiple signals. It does this by ORing the signals it wants to wait for together and then checking the result to see which ones were set. So lets say you had three message ports, IDCMP, Arexx, and I/O you could set it up as : ArexxSig = 1 << Arexxport->mp_SigBit; IDCMPSig = 1 << Window->UserPort->mp_SigBit; IOSig = 1 << MyIOport->mp_SigBit; Then you can Wait for any port to get a signal using : I_got = Wait(ArexxSig | IDCMPSig | IOSig); And you can determine which ones you got using : if ((I_got & ArexxSig) != 0) { /* Process ARexx Message(s) */ } if ((I_got & IDCMPSig) != 0) { /* Process IDCMP Message(s) */ } if ((I_got & IOSig) != 0) { /* Process I/O result(s) */ } Note carefully that you can get more than one signal set in the result so you cannot use "else if" constructs. Also you may get more than one message per/signal so be sure to drain the port of all messages before you return to the Wait() call in your loop. (for performance conscious people the XXXSig stuff can be macros) In the above example, what you probably want to do is to open the console.device and queue up IORequests to the device to read characters. If you don't mind the overhead of dealing with one character at a time you can use RAWKEY events. >A related problem: Can I set up a window in a custom screen for standard i/o? >If so, how? This is the second problem which is a bit tricky. What you would really like to do is open a conhandler handle and use it that way things like fprintf(fp,xxx) etc would work as you expect. ConMan will let you do this by opening up "CON:w" which can give you an stdio FILE * handle. To do this with the standard conhandler requires some pretty gross digging around in the global vector. The problem with all of that is that the characters typed won't generate a signal that you can Wait() for. If that is too much of a problem then you will have to reinvent wheel a bit. -- --Chuck McManis Sun Microsystems uucp: {anywhere}!sun!cmcmanis BIX: Internet: cmcmanis@Eng.Sun.COM These opinions are my own and no one elses, but you knew that didn't you. "I tell you this parrot is bleeding deceased!"