summaryrefslogtreecommitdiff
path: root/contrib/utils/ansiprt.c
blob: 17d6e068d5ed81f10f842f1617d3953fbeb742fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * ansiprt.c
 *
 * Simple filter to wrap ANSI media copy escape sequences around 
 * text on stdin.  Writes /dev/tty to get around things that might be
 * trapping stdout.  This is actually a feature because it was written
 * to be used with pine's personal print option set up to take "enscript"
 * output and send it displayward to be captured/printed to a postscript 
 * device.  Pine, of course, uses popen() to invoke the personal print
 * command, and interprets stdout as diagnostic messages from the command.
 *
 * Michael Seibel, mikes@cac.washington.edu
 *
 * 21 Apr 92
 *
 */
#include <stdio.h>
#include <sys/file.h>

#define	BUFSIZ	8192

main(argc, argv)
int  argc;
char **argv;
{
    char c[BUFSIZ];
    int  n, d;
    int  ctrld = 0;

    if(argc > 1){
        n = 0;
	while(argc > ++n){
	    if(argv[n][0] == '-'){
		switch(argv[n][1]){
		  case 'd':
		    ctrld++;
		    break;
		  default :
		    fprintf(stderr,"unknown option: %c\n", argv[n][1]);
		    break;
		}
	    }
        }
    }

    if((d=open("/dev/tty",O_WRONLY)) < 0){
        perror("/dev/tty");
	exit(1);
    }

    write(d,"\033[5i", 4);
    while((n=read(0, c, BUFSIZ)) > 0)
	write(d, c, n);

    if(ctrld)
	write(d, "\004", 1);

    write(d,"\033[4i", 4);
    close(d);
}