Subject: ANSIPRINT Source

From: [email-masked] (MARKERT ERICH L. MR.)
Date: 15 Aug 94 12:31:30 GMT

Here's the source:

/*
	These appear to be the conventional ANSI escape sequences for
	turning on and off an attached printer.
 */
static char printer_on[] = "\033[5i";
static char printer_off[] = "\033[4i";

static int dump_file (fd, name) int fd; char *name; {
	char buffer[8192];
	char out[8192];
	int n, m;

	for (m = 0;; m += n) {
		n = read (fd, buffer, sizeof (buffer));
		if (n < 0) {
			perror (name);
			return n;
		}
		else if (n == 0) {
			return m;
		}
		else {
			int i, o;
			for (i = o = 0; i < n; ++i) {
				if (o > sizeof (out) - 2) {
					write (1, out, o);
					o = 0;
				}
				if ((out[o++] = buffer[i]) == '\n')
					out[o++] = '\r';
			}
			if (o > 0) write (1, out, o);
		}
	}
}

main (argc, argv) int argc; char **argv; {
	int fd;

	/* Send printer-on escape sequence. */
	write (1, printer_on, strlen (printer_on));

	/* If there are no arguments, read from standard input. */
	if (argc < 2) {
		dump_file (0, "stdin");
	}
	else {
		for (--argc, ++argv; argc; --argc, ++argv) {
			fd = open (*argv, 0);
			if (fd < 0) {
				perror (*argv);
				exit (1);
			}
			if (dump_file (fd, *argv) < 0) exit (1);
		}
	}

	/* Write a form feed, then the printer-off escape sequence. */
	/* The following line was commented out by me, ERICH MARKERT
	   The reason for this is that the extra form feed causes
	   a blank page to be printed on laser printers
	   If you desire the form feed for your dotmatrix printer
	   simply uncomment this line and recompile 
	*/
	/* write (1, "\f", 1); */
	write (1, printer_off, strlen (printer_off));

	exit (0);
}

-- 
______________________________________________________________________________
Mr. Erich L. Markert                                [email-masked]
Systems Administrator					    TEL (914) 938-5624
Department of Mathematical Sciences                         FAX (914) 938-2409
United States Military Academy	
West Point, NY 10996