* Fix an error in compilation when Alpine is not built with S/MIME
[alpine.git] / contrib / utils / ansiprt.c
blob17d6e068d5ed81f10f842f1617d3953fbeb742fe
1 /*
2 * ansiprt.c
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.
12 * Michael Seibel, mikes@cac.washington.edu
14 * 21 Apr 92
17 #include <stdio.h>
18 #include <sys/file.h>
20 #define BUFSIZ 8192
22 main(argc, argv)
23 int argc;
24 char **argv;
26 char c[BUFSIZ];
27 int n, d;
28 int ctrld = 0;
30 if(argc > 1){
31 n = 0;
32 while(argc > ++n){
33 if(argv[n][0] == '-'){
34 switch(argv[n][1]){
35 case 'd':
36 ctrld++;
37 break;
38 default :
39 fprintf(stderr,"unknown option: %c\n", argv[n][1]);
40 break;
46 if((d=open("/dev/tty",O_WRONLY)) < 0){
47 perror("/dev/tty");
48 exit(1);
51 write(d,"\033[5i", 4);
52 while((n=read(0, c, BUFSIZ)) > 0)
53 write(d, c, n);
55 if(ctrld)
56 write(d, "\004", 1);
58 write(d,"\033[4i", 4);
59 close(d);