home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / contrib / ansiprt.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  1.2 KB  |  60 lines

  1. /*
  2.  * ansiprt.c
  3.  *
  4.  * Simple filter to wrap ANSI media copy escape sequences around 
  5.  * text on stdin.  Writes /dev/tty to get around things that might be
  6.  * trapping stdout.  This is actually a feature because it was written
  7.  * to be used with pine's personal print option set up to take "enscript"
  8.  * output and send it displayward to be captured/printed to a postscript 
  9.  * device.  Pine, of course, uses popen() to invoke the personal print
  10.  * command, and interprets stdout as diagnostic messages from the command.
  11.  *
  12.  * Michael Seibel, mikes@cac.washington.edu
  13.  *
  14.  * 21 Apr 92
  15.  *
  16.  */
  17. #include <stdio.h>
  18. #include <sys/file.h>
  19.  
  20.  
  21. main(argc, argv)
  22. int  argc;
  23. char **argv;
  24. {
  25.     char c[40];
  26.     int  n, d;
  27.     int  ctrld = 0;
  28.  
  29.     if(argc > 1){
  30.         n = 0;
  31.     while(argc > ++n){
  32.         if(argv[n][0] == '-'){
  33.         switch(argv[n][1]){
  34.           case 'd':
  35.             ctrld++;
  36.             break;
  37.           default :
  38.             fprintf(stderr,"unknown option: %c\n", argv[n][1]);
  39.             break;
  40.         }
  41.         }
  42.         }
  43.     }
  44.  
  45.     if((d=open("/dev/tty",O_WRONLY)) < 0){
  46.         perror("/dev/tty");
  47.     exit(1);
  48.     }
  49.  
  50.     write(d,"\033[5i", 4);
  51.     while((n=read(0, c, 39)) > 0)
  52.     write(d, c, n);
  53.  
  54.     if(ctrld)
  55.     write(d, "\004", 1);
  56.  
  57.     write(d,"\033[4i", 4);
  58.     close(d);
  59. }
  60.