[comp.sys.amiga.tech] mixing standard i/o with intuition messages

a976@mindlink.UUCP (Ron Tarrant) (06/13/90)

> phi@goanna.cs.rmit.oz.au 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?
> 
> 
> A related problem: Can I set up a window in a custom screen for standard i/o?
> If so, how?
> 
> 
> Thanks.         phi
> 
> --
> Philip Hingston, Computer Science,ACSnet: phi@goanna.cs.rmit.oz
> R.M.I.T.                          ARPA: phi%goanna.cs.rmit.oz.au@uunet.uu.net
> GPO BOX 2476 V,                   CSNET: phi%goanna.cs.rmit.oz.au@australia
> Melbourne, 3001, AUSTRALIA        UUCP: ...!uunet!goanna.cs.rmit.oz.au!phi


There is an example of mixing messages from intuition, ARexx and a standard i/o
(CLI type) window by David N. Junod called "Modular Event Processing" that
appeared in the Jan/Feb issue of AmigaMail from Commodore. It's written for the
Lattice 5.04 compiler and is very clearly written. The code is available on the
Lattice BBS.
        I wish I could give you a source that was a little closer to home for
you, but that's the only place I know of to get it.
-Ron Tarrant
a976@Mindlink.UUCP

phi@goanna.cs.rmit.oz.au (Philip Hingston) (06/13/90)

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?

Obvious failure:

		forever
			while a message is pending
				act on message
			read a line of input

See the problem?

A related problem: Can I set up a window in a custom screen for standard i/o?
If so, how?

If anyone can suggest a solution to either or both of these problems, it would
should save me a heap of time and trouble. The only solution I can see is to
re-implement the functionality of standard i/o myself based around intuition
messages, or the keyboard device? or maybe the console device?

If it helps any, the standard i/o can be attached to a different window
to the one generating the other messages.

The application is a logo interpreter. Standard i/o is a convenient way to
provide a command line type interface, and I also want to handle resizing
the graphics window, mouse clicks in the window, possibly menus, definitely
an arexx capability etc.


Thanks.		phi

-- 
Philip Hingston, Computer Science,ACSnet: phi@goanna.cs.rmit.oz
R.M.I.T.                          ARPA:   phi%goanna.cs.rmit.oz.au@uunet.uu.net
GPO BOX 2476 V,                   CSNET:  phi%goanna.cs.rmit.oz.au@australia
Melbourne, 3001, AUSTRALIA        UUCP:   ...!uunet!goanna.cs.rmit.oz.au!phi

phi@goanna.cs.rmit.oz.au (Philip Hingston) (06/14/90)

a976@mindlink.UUCP (Ron Tarrant) writes:

>> phi@goanna.cs.rmit.oz.au writes:
>> 
>> The subject line is basically my question: is it possible? Can I write
>> as well as reading lines from standard input?
>> 
>> 
>> A related problem: Can I set up a window in a custom screen for standard i/o?


>There is an example of mixing messages from intuition, ARexx and a standard i/o
>(CLI type) window by David N. Junod called "Modular Event Processing" that
>appeared in the Jan/Feb issue of AmigaMail from Commodore. It's written for the
>Lattice 5.04 compiler and is very clearly written. The code is available on the
>Lattice BBS.
>        I wish I could give you a source that was a little closer to home for
>you, but that's the only place I know of to get it.
>-Ron Tarrant
>a976@Mindlink.UUCP

Thanks Ron --- While I am a registered Lattice owner, there is no way I could
access the Lattice BBS from here. Would anyone who can be willing to mail it
to me, assuming that is allowed, or suggest another source?

b.t.w. several people have suggested setting up a separate task to do the
standard i/o and having it send a message to the main task when a line of
input becomes available. This has attractions but still leaves the 'related
problem' mentioned above. If David N. Junod's example solves this one too then
I'll be extra happy, but if not, has anyone any suggestions?

Thanks again to all who replied.	phi
-- 
Philip Hingston, Computer Science,ACSnet: phi@goanna.cs.rmit.oz
R.M.I.T.                          ARPA:   phi%goanna.cs.rmit.oz.au@uunet.uu.net
GPO BOX 2476 V,                   CSNET:  phi%goanna.cs.rmit.oz.au@australia
Melbourne, 3001, AUSTRALIA        UUCP:   ...!uunet!goanna.cs.rmit.oz.au!phi

cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) (06/15/90)

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<hexaddress of window>" 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: <none>   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!"

brianm@sco.COM (Brian Moffet) (06/27/90)

in some message Jim.Locker@afitamy.fidonet.org (Jim Locker) says
- (4) Enter your Forever loop, and Wait on a signal from either Intuition or
- your Console device.
- (5) Test to see who signaled, and process accordingly.

One warning with doing this, the one program that I have that does this
is a terminal emulator which shares messages from Intuition (menus & keys),
and the Serial Port.  Unfortunately, the method I use tends to favor 
the serial port right now, so things don't happen quite as quickly
as I would like (like hitting DEL or ^C).

Keep in mind the scheduling of your messages, and try not to favor
one type of message over another.

brianm
-- 
Brian Moffet	ext 3567	Mission St _"_e_n_o_u_g_h_ _s_a_i_d_" -- _e_r_i_c_h_i

cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) (06/28/90)

[meta question : Why are Fido mail addresses unreplyable? Should someone
 be allowed to contribute to an email forum without the ability to receive
 mail from that forum?]

In article <263.2687038B@afitamy.fidonet.org> (Jim Locker) writes:
>Sure you can mix standard I/O with Intuition I/O.  Do the following:

"Standard I/O" - n. A set of functions in the C library for doing stream
		 I/O to and from a standard device. see also fopen(), 
		 fprintf(), printf(), scanf(), fscanf(), gets(), fgets(), ...

Anyway, this is the common definition. Both the MANX and Lattice C compilers
support the Standard I/O calls in their libraries, but neither support them
directly to Intution windows/screens. ConMan ( the console handler replace-
ment) provides a way to do this by using the CON:wXXX directive. 


--
--Chuck McManis						    Sun Microsystems
uucp: {anywhere}!sun!cmcmanis   BIX: <none>   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!"