[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jul 20 16:50:29 2003 
Subject:running a remote pop11 process from ved 
From:A . Sloman 
Volume-ID:1030720.02 

In case anyone following this thread is interested, here's a demo of
how to use the run_unix_program library (described in HELP run_unix_program)
to create a procedure start_pop that starts another pop11 process running.

Three VED commands are provided:
	ENTER psend
		send current line to the other pop11 process
	ENTER rsend
		send marked range in current file to other pop11 process
	ENTER pget
		get any intput waiting from other process and insert it at
		the end of 'output.p' file.

Some test examples are provided at the top, with instructions, to save
typing if you want to try it out.

It should be easy, using vedsetkey, to get from here to a mode
in which if you are in special file every time you press RETURN
it sends the current line.

Note that unlike ved_imcsh this does not depend on prompts.

Thus if the remote program is taking some time to respond
to the last command you may interleave sending and getting
outputs. It could be confusing.

But anything that works from pop11 like this should be doable
from Java, as David requires.

In principle, this mechanism could be used to set up different
remote pop11 processes associated with different ved buffers.
But at present it uses global variables for senders and receivers and
assumes there is only on such remote pop11 process.

I assume a variant of this could run a remote pop11 process on another
machine using sockets.

I have checked that if this line is sent
	"x" -> vedusewindows;

then sending a ved or teach or help, etcp command brings up an Xved
window.

A bug: the ved_pget and ved_psend procedures should mishap if
the other process has terminated. That probably requires some
extra test which may or may not be easy!

Aaron
==========================CUT === HERE =======================

/*
FOR TESTING
;;; Compile this file (e.g. in VED do ENTER l1
;;; that will start a separate pop11 process.
;;;
;;; Put cursor on next line and do ENTER psend twice:
999*99 =>
'the cat' <> ' sat on the mat' =>

;;; Now do ENTER pget, to get the output from those.

;;; Do psend on this line, then pget to get the mishap message
"one" + "one" =>

;;; Mark next 7 lines, do ENTER rsend, to send range, then ENTER pget
define silly();
	repeat 5 times
		'silly running'=>
	endrepeat;
enddefine;

silly();

;;; test that pop_charin_escapes works OK
[
% repeat 10 times 99 endrepeat
%
] =>

;;; see if readline works?

readline() =>

*/

;;; Compiling this file starts a separate pop11 process
;;; Three procedures will be produced below:
;;; 	one to send current line in Ved
;;;		one to receive any input waiting
;;; 	one to send marked range in ved

global vars procedure(ved_psend, ved_pget, ved_rsend);

define start_pop() -> (sender, receiver);

    lvars indev, outdev, errdev, status, pid;

    define pop_send(input, dev);
        syswrite(dev, 1, input, length(input));
		;;; add a newline after everything sent.
        syswrite(dev, 1, '\n', 1);
		sysflush(dev)
    enddefine;

    ;;; define pop_receive(dev) -> output;
    define pop_receive(dev);
        lconstant buff = inits(256);
		;;; initialise empty output string
		;;; lvars output = '';
        while sys_input_waiting(dev) do
        	lvars n;
            sysread(dev, 1, buff, 257) -> n;
            ;;; output <> substring(1, n, buff) -> output;
            vedinsertstring(substring(1, n, buff));
        endwhile;
		;;; debugging stuff
		;;; vedputmessage(output);
		;;; syssleep(50);
    enddefine;


	;;; start a pop11 program
    run_unix_program(sysfileok('$usepop/pop/pop/pop11'),
		[': procedure; true -> pop_first_setpop; setpop(); endprocedure; -> interrupt; [] -> pop_charin_escapes' ],
		true, true, 1, false)
        -> (indev, outdev, errdev, status, pid);

	procedure(indev);
		;;; procedure to send a line from Ved buffer through the remote program's
		;;; input device
		false -> ved_on_status;
		pop_send(vedthisline(), indev);
		vednextline();
	endprocedure(%indev%) -> sender;

	
	procedure(outdev);
		;;; procedure to receive stuff via the remote program's output device
		;;; and print it in file 'output.p'
		edit('output.p');
		vedendfile();
		false -> ved_on_status;
		pop_receive(outdev)
	endprocedure(%outdev%) -> receiver;


enddefine;


define ved_rsend();
	;;; Send a marked range; Leave cursor just after end of range.
	vedjumpto(vvedmarklo, 1);
	while vedline <= vvedmarkhi do
		ved_psend();
	endwhile;
enddefine;

;;; create the new process and set up sender and receiver procedures
start_pop() -> (ved_psend, ved_pget);