From: Adam Dickmeiss Date: Mon, 17 Apr 1995 09:36:32 +0000 (+0000) Subject: ttyemit moved from kernel directory. X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=498946306c461b20d24308aae074bf43f6050698;p=egate.git ttyemit moved from kernel directory. --- diff --git a/util/Makefile b/util/Makefile index 86e6637..fb69be6 100644 --- a/util/Makefile +++ b/util/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.13 1995/03/29 11:44:29 adam +# Revision 1.14 1995/04/17 09:36:32 adam +# ttyemit moved from kernel directory. +# +# Revision 1.13 1995/03/29 11:44:29 adam # New functions: iso2709_a_.. for record manipulation. # # Revision 1.12 1995/03/28 16:07:06 adam @@ -48,7 +51,7 @@ TPROG1=iso2709dump TPROG2=gwdbtest LIB=../lib/util.a PO=iso2709.o iso27dis.o iso2709o.o iso2709a.o strqueue.o \ - gw-db.o gip.o gips.o gipc.o + gw-db.o gip.o gips.o gipc.o ttyemit.o CPP=$(CC) -E DEFS=$(INCLUDE) -DSTUPID_ISO_DBC=1 @@ -74,14 +77,14 @@ clean: depend: depend2 depend1: - mv Makefile Makefile.tmp - sed '/^#Depend/q' Makefile - $(CPP) $(INCLUDE) -M *.c >>Makefile - -rm Makefile.tmp + sed '/^#Depend/q' Makefile.tmp + $(CPP) $(DEFS) -M *.c >>Makefile.tmp + mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend +#GNU make style depend ifeq (.depend,$(wildcard .depend)) include .depend endif diff --git a/util/ttyemit.c b/util/ttyemit.c new file mode 100644 index 0000000..26b76a6 --- /dev/null +++ b/util/ttyemit.c @@ -0,0 +1,120 @@ +/* Gateway tty print utility + * Europagate, 1995 + * + * $Log: ttyemit.c,v $ + * Revision 1.1 1995/04/17 09:36:34 adam + * ttyemit moved from kernel directory. + * + * + */ +#include +#include +#include + +#include + +static char line_buf[256]; +static int line_col = 0; +static int esc_flag = 0; + +static int line_min = 30; +static int line_max = 76; +static FILE *out_f = stdout; + +void tty_init (FILE *out, int min, int max) +{ + out_f = out; + if (min > 0) + line_min = min; + if (max > 2) + line_max = max; + line_col = 0; + esc_flag = 0; +} + +static void flush (void) +{ + int j; + + for (j = 0; j1 && line_buf[j] >= 'A'&& line_buf[j] <= 'Z' + && line_buf[j-1] == ' ' + && (line_buf[j-2] == '.' || line_buf[j-2] == ';') + && extra < line_max-i ) + { + extra++; + putc (' ', out_f); + } +#endif + putc (line_buf[j], out_f); + } + putc ('\n', out_f); + j = 0; + ++i; + while (i < line_col) + line_buf[j++] = line_buf[i++]; + line_col = j; + break; + } + else if (i < line_min) + flush (); +} + +static void escape (int ch) +{ + switch (ch) + { + case 'n': + if (line_col >= line_max) + split (' '); + else + flush (); + break; + case 't': + do + line_buf[line_col++] = ' '; + while (line_col & 7); + break; + case 's': + line_buf[line_col++] = ' '; + break; + default: + line_buf[line_col++] = ch; + } +} + +void tty_emit (int ch) +{ + if (esc_flag) + { + escape (ch); + esc_flag = 0; + } + else if (ch == '\\') + esc_flag = 1; + else if (ch == '\n') + flush (); + else if (line_col || ch != ' ') + { + line_buf[line_col++] = ch; + if (line_col >= line_max) + split (ch); + } +}