[comp.lang.pascal] Patching a process in prompt

ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu (Josep Sau B.) (01/14/91)

Has anyone any idea/code to achieve that every time system
PROMPT appears a program gets called before?

I have thought of doing some patch in COMMAND.COM just before
the code that emits system PROMPT, or some resident program
that intercepts it and executes the external program just before
PROMPT is emitted.

The program objective is to emit a different sentence before every
system PROMPT. These sentences should be chosen randomly from
a text file on disk by the program.

The idea is taken from a program called FORTUNE, that is accessible
in TRICKLE at <MSDOS.SYSUTL>4TUNE.ZIP by L.Favaro.
This program chooses a sentence and inserts it in system PROMPT,
but just ONCE.

Any pertinent answer very welcome.

--Josep Sau B. <ZCCBJSB@EB0UB011>
------------------------------------------------------------------
'Every science needs the right words to be expressed the right way'
           Raimundus Lulius (Catalan philosopher)
------------------------------------------------------------------

zhou@brazil.psych.purdue.edu (Albert Zhou) (01/15/91)

In article <25493@adm.brl.mil> ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu (Josep Sau B.) writes:
>
>Has anyone any idea/code to achieve that every time system
>PROMPT appears a program gets called before?
>
It is possible to do this. However, it would be very slow since each time the
program has to be loaded from the disk and executed. But anyway, you can do
that with TP4.0 and up by writing your own shell (very easy, since you can     
make full use of the existing command interpreter). The code will be something
like this:

		repeat
		  execute you pre-prompt program 
                        (like this: exec(program, parameters);		
		  write prompt;	
		  read a command line;
		  decide whether it is an internal command or an external one
		  if it is an internal command then
		     use this form: exec('command.comm`, `/c ` + commandline)
		  else use this form: exec(command, parameters);
		until whatever;

dave@tygra.ddmi.com (David Conrad) (01/15/91)

Hmm.  Here is one way to acheive the desired effect.  A batch file:
 
Place the following in fort.bat:
BEGIN--cut here--cut here
echo off
:repeat
fortune
cmd
goto repeat
END--cut here--cut here
 
And the following in cmd.pas:
BEGIN--cut here--cut here
program cmd;
{$M 1024,0,0}
 
uses dos;
 
var
  prompt,command : string;
 
procedure promptUser (prompt : string);
begin
  {...Sorry, you'll have to implement this yourself...}
end;
 
begin
  prompt := GetEnv('PROMPT');
  promptUser (prompt);
  readln (command);
  Exec (GetEnv('COMSPEC'),'/C '+command);
end.
END--cut here--cut here
 
Two comments.  One, you may want to call the DOS INT $21 func $a "Get
Buffered Input" to provide standard editing.  Two, you have to display
the prompt yourself, supporting all the possible options (which gets
pretty hairy).  Can anyone think of a way to get DOS to display the
prompt for you?  If you just call COMMAND.COM with no /C command then
the user would have to type `exit' after each command to get back to
your shell.
--
David R. Conrad
dave@tygra.ddmi.com
-- 
=  CAT-TALK Conferencing Network, Computer Conferencing and File Archive  =
-  1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.  AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET")        =
   E-MAIL Address: dave@DDMI.COM