[comp.unix.wizards] TSR type appls

clayc@uunet.uu.net (Clay Calhoun) (06/28/90)

Hi,

I've a user here who wants to implement a "Terminate and Stay Resident"
type application on a Unix box.  Here's the situation:

  1.  He has an "off-the-shelf" application that he's using.  No
      source code available.  If his "chosen key sequence isn't
      entered - then the input gets passed to the application and
      the TSR continues to listen.

  2.  He wants to develop an application to run in the background,
      capture his input - and perform "something" if a certain key
      combination is received.
  
My dilema is, I'm not sure which application will be controlling the
I/O.  If he starts his "TSR" and shoves it in the background - will
it still have access to the I/O coming from the keyboard once he 
starts the application he wants to use?

I'm lost.

===========
Cheers,
 clay
 ssds!clayc@uunet.uu.net

cliffs@suntrek.Central.Sun.COM (Clifford C. Skolnick) (06/29/90)

In article <23762@adm.BRL.MIL> ssds!clayc@uunet.uu.net (Clay Calhoun) writes:
>  
>My dilema is, I'm not sure which application will be controlling the
>I/O.  If he starts his "TSR" and shoves it in the background - will
>it still have access to the I/O coming from the keyboard once he 
>starts the application he wants to use?
>

I would recomend you study the source code to a program called "screen"
which will give you the functionality of multiple sessions on a dumb,
well not too dumb, terminal.  I hope your system has pty's :-).

			Cliff
--
   Cliff Skolnick - Technical Consultant                  cliffs@east.sun.com
           [I only work for Sun, I do not speak for them]

         "The floggings will continue until morale improves"

bambi@kirk.nmg.bu.oz (David J. Hughes) (07/03/90)

From article <23762@adm.BRL.MIL>, by ssds!clayc@uunet.uu.net (Clay Calhoun):
> I've a user here who wants to implement a "Terminate and Stay Resident"
> type application on a Unix box.  Here's the situation:
> 
>   1.  He has an "off-the-shelf" application that he's using.  No
>       source code available.  If his "chosen key sequence isn't
>       entered - then the input gets passed to the application and
>       the TSR continues to listen.
> 
>   2.  He wants to develop an application to run in the background,
>       capture his input - and perform "something" if a certain key
>       combination is received.
>   
> My dilema is, I'm not sure which application will be controlling the
> I/O.  If he starts his "TSR" and shoves it in the background - will
> it still have access to the I/O coming from the keyboard once he 
> starts the application he wants to use?

If the user always wishes to run these two programs together there is a
simple solution.  Let's say that the main application is app_A and the
"TSR" you mentioned is app_B.  App_B acts as a master to the execution
of app_A. The basic outline follows :-

	1. Upon execution of app_B, create a pipe and fork a child process.
	2. In the child process, dup2() the read end of the pipe 
		(pipe[0]) to be stdin.
	3. The child process now exec[l|v]'s app_A
	4. app_B now enters a read&write loop that is terminated if
		the child process app_A terminates (SIGCHLD).
	5. app_B just reads from stdin, has a look at the input,
		and either jumps into life if this is the desired
		input, or just passes it to the write end of the pipe
		(pipe[1]).
	6. app_A will just read from it's stdin (the pipe in this case)
		as it normally would, but will only receive the input
		that doesn't match the "TSR" magic string sequence.


In this approach, the "TSR" app_B, will control input for the duration
of the session of app_A.  The only thing to watch is that the magic
string (or HotKEY sequence for TSR people) is totally unique and that
it is not something that will be typed as a command or a response to the
main application (app_A).



Hope this helps.

bambi

+----------------------------------------------------------------------------+
| David J. Hughes   (AKA bambi)	 |   bambi@kowande.bu.oz.au                  |
| Systems Programmer		 |   bambi@kowande.bu.oz.au@uunet.uu.net     |
| Network Management Group       |   ..!uunet!munnari!kowande.bu.oz.au!bambi |
| Bond University, Gold Coast    |   Phone : +61 75 951111                   |
| Queensland,  Australia  4229   |   Fax :   +61 75 951456                   |
+----------------------------------------------------------------------------+