
/* pipes.q: example showing the use of pipes in Q 12-16-1993 AG
   revised 07-02-2001 AG */

/* This script is very UNIX-specific; don't expect it to work in other
   environments. */

/* ls returns a list of all filenames matching a given specification.
   Example: ls "*.q" (note that you have to escape this expression as
   `? ls "*.q"' to prevent the interpreter from running the built-in
   ls command) */

ls S:String	= freadls (popen ("ls "++S) "r");

freadls F:File	= [] if feof F;
		= [freads F|freadls F] otherwise;

/* more pipes a file through "more". Example: more "huffman.q" */

more S:String	= fcopy (fopen S "r") (popen "more" "w");

fcopy F:File G:File
		= () if feof F;
		= fwritec G (freadc F) || fcopy F G otherwise;
