about summary refs log tree commit diff stats
path: root/utils/lpansi
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>1996-09-02 19:39:24 -0400
committerThomas E. Dickey <dickey@invisible-island.net>1996-09-02 19:39:24 -0400
commite087f6d44e87f489fcb3056e86319ebba4218156 (patch)
treed045b58011bfbbf5186d34c4fed9e0dedb363275 /utils/lpansi
downloadlynx-snapshots-e087f6d44e87f489fcb3056e86319ebba4218156.tar.gz
snapshot of project "lynx", label v2_6
Diffstat (limited to 'utils/lpansi')
-rw-r--r--utils/lpansi/lpansi.c57
-rw-r--r--utils/lpansi/lpansi.txt45
2 files changed, 102 insertions, 0 deletions
diff --git a/utils/lpansi/lpansi.c b/utils/lpansi/lpansi.c
new file mode 100644
index 00000000..456e1488
--- /dev/null
+++ b/utils/lpansi/lpansi.c
@@ -0,0 +1,57 @@
+/* This program allows printing of files from any VT100 or ANSI by simply 
+   calling the program name and a filename argument.
+   Written by: Gary Day, 11/30/93
+   Hey, it doesn't have to be complicated to be useful.
+*/
+
+/* Ansi C function prototypes */
+void ansi_printer_on(void);
+void ansi_printer_off(void);
+int main(int argc, char *argv[]);
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+  int  ch;    /* Where we store our characters */
+  FILE *fp;   /* File pointer */
+  if (argc!=2)
+   {
+    printf("Usage is lpansi <filename>\n");
+    exit(1);
+   }
+/* If you got here, then there is only 1 filename argument - correct */
+  if ((fp=fopen(argv[1], "r"))==NULL)
+  {
+   printf("Can't open %s\n",argv[1]);
+   exit(1);
+  }
+/* Ok, the filename was there, lets do it! */
+
+  ansi_printer_on();
+
+  while ((ch=getc(fp))!=EOF)
+  {
+   putc(ch,stdout);
+  }
+  fclose(fp);
+  
+  printf("\n\x0C");  /* Do a form feed at the end of the document */
+
+  ansi_printer_off();
+
+  return 0;  /* Return a zero if everything is ok */
+} 
+
+/* Send a printer on escape sequence */
+void ansi_printer_on(void)
+{
+  printf("\x1B[5i");
+}
+
+/* Send a printer off escape sequence */
+void ansi_printer_off(void)
+{
+  printf("\x1B[4i");
+}
diff --git a/utils/lpansi/lpansi.txt b/utils/lpansi/lpansi.txt
new file mode 100644
index 00000000..46738a2c
--- /dev/null
+++ b/utils/lpansi/lpansi.txt
@@ -0,0 +1,45 @@
+README for lpansi.c				 		    12/2/1993
+File: lpansi.c				    		     Author: Gary Day  
+							   gday@comp.uark.edu
+
+The problem:  UNIX supplies a printing program called lp <filename> which 
+	      allows the user to print a text (or any really) file to a 
+	      printer.  Unfortunately, that printer is attached to the UNIX 
+	      server which is not where the user usually is.  In my case, it is 
+	      about 230 miles away.  I needed a similar program that would 
+	      allow me to print to my home printer.  
+
+The solution: The VT100 standard defines a printer on and off escape 
+	      sequence.  [FYI: esc[5i is printer on, esc[4i is printer off.]
+	      Lpansi is a VERY simple program that issues a printer on 
+	      sequence, opens the file sent as an argument, reads it character
+	      by character, echos it to stdout (now your local printer) and
+	      ends by sending a form feed and printer off command.
+
+Usage:  I had several purposes in mind when I wrote this.  The first was to
+	find a way to replace lp in a gopher client I had with something that
+	would print at home.  I also wanted to be able to print text 
+	files to my home printer directly from the UNIX prompt.  A 
+	natural extension of this is to add it to LYNX, and other printing
+	clients as your printer command.
+
+Syntax:	lpansi <filename>
+	This program only accepts one filename as an argument, and not 
+	command line options.  It could be easily modified to accept more
+	but that will be up to you to do.  It serves my needs.  
+
+Thanks: Thanks go to Michael Seibel on the PINE development team for 
+	helping me find the correct ANSI codes to turn off the printer.  
+	I found out later that PINE distributes a similar program called 
+	ansiprt which is supposed to do the same thing.  Here, the source
+	code is provided so you may incorporate the concept directly in your
+	program.
+
+Disclaimer:  [Everyone has one so...] I make no promises whatsoever about 
+	     how this will work for you.  If you have VT100 and/or ANSI, it
+	     should work just fine.  If it doesn't, quit using it.  :)  This
+	     program is free to use and modify, but try to keep my name with
+	     it.  I don't do that much cool stuff, so I need all the credit
+	     I can get.  Thanks.
+
+	          *** End of README for lpansi.c ***