summaryrefslogtreecommitdiff
path: root/tbl
diff options
context:
space:
mode:
Diffstat (limited to 'tbl')
-rw-r--r--tbl/Makefile.mk45
-rw-r--r--tbl/t..c223
-rw-r--r--tbl/t0.c85
-rw-r--r--tbl/t1.c189
-rw-r--r--tbl/t2.c49
-rw-r--r--tbl/t3.c132
-rw-r--r--tbl/t4.c473
-rw-r--r--tbl/t5.c250
-rw-r--r--tbl/t6.c250
-rw-r--r--tbl/t7.c181
-rw-r--r--tbl/t8.c425
-rw-r--r--tbl/t9.c92
-rw-r--r--tbl/tb.c154
-rw-r--r--tbl/tbl.1187
-rw-r--r--tbl/tc.c87
-rw-r--r--tbl/te.c122
-rw-r--r--tbl/tf.c109
-rw-r--r--tbl/tg.c127
-rw-r--r--tbl/ti.c82
-rw-r--r--tbl/tm.c91
-rw-r--r--tbl/ts.c89
-rw-r--r--tbl/tt.c117
-rw-r--r--tbl/tu.c401
-rw-r--r--tbl/tv.c186
-rw-r--r--tbl/version.c33
25 files changed, 4179 insertions, 0 deletions
diff --git a/tbl/Makefile.mk b/tbl/Makefile.mk
new file mode 100644
index 0000000000000..13910de6b9e42
--- /dev/null
+++ b/tbl/Makefile.mk
@@ -0,0 +1,45 @@
+OBJ = t0.o t1.o t2.o t3.o t4.o t5.o t6.o t7.o t8.o t9.o tb.o tc.o te.o \
+ tf.o tg.o ti.o tm.o ts.o tt.o tu.o tv.o version.o
+
+FLAGS = -DMACDIR='"$(MACDIR)"'
+
+.c.o:
+ $(CC) $(CFLAGS) $(WARN) $(FLAGS) $(CPPFLAGS) -c $<
+
+all: tbl
+
+tbl: $(OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) $(LIBS) -o tbl
+
+install:
+ $(INSTALL) -c tbl $(ROOT)$(BINDIR)/tbl
+ $(STRIP) $(ROOT)$(BINDIR)/tbl
+ $(INSTALL) -c -m 644 tbl.1 $(ROOT)$(MANDIR)/man1/tbl.1
+
+clean:
+ rm -f $(OBJ) tbl core log *~
+
+mrproper: clean
+
+t..o: t..c
+t0.o: t0.c t..c
+t1.o: t1.c t..c
+t2.o: t2.c t..c
+t3.o: t3.c t..c
+t4.o: t4.c t..c
+t5.o: t5.c t..c
+t6.o: t6.c t..c
+t7.o: t7.c t..c
+t8.o: t8.c t..c
+t9.o: t9.c t..c
+tb.o: tb.c t..c
+tc.o: tc.c t..c
+te.o: te.c t..c
+tf.o: tf.c t..c
+tg.o: tg.c t..c
+ti.o: ti.c t..c
+tm.o: tm.c t..c
+ts.o: ts.c
+tt.o: tt.c t..c
+tu.o: tu.c t..c
+tv.o: tv.c t..c
diff --git a/tbl/t..c b/tbl/t..c
new file mode 100644
index 0000000000000..1181f66620224
--- /dev/null
+++ b/tbl/t..c
@@ -0,0 +1,223 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t..c 1.4 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t..c 1.19 (gritter) 9/11/06
+ */
+
+/* t..c : external declarations */
+
+# include <stdio.h>
+# include <ctype.h>
+# include <inttypes.h>
+
+# if defined (__GLIBC__) && defined (_IO_getc_unlocked)
+# undef getc
+# define getc(f) _IO_getc_unlocked(f)
+# endif
+
+# define MAXCHS 2000
+# define MAXSTR 1024
+# define MAXRPT 100
+# define CLLEN 100
+# define SHORTLINE 4
+# define BIGBUF 8192
+extern int MAXLIN;
+extern int MAXCOL;
+extern int MAXHEAD;
+extern int nlin, ncol, iline, nclin, nslin;
+extern int **style;
+extern int **ctop;
+extern char ***font;
+extern char ***csize;
+extern char ***vsize;
+extern char **cll;
+extern int *xcol;
+extern int *stynum;
+extern int F1, F2;
+extern int **lefline;
+extern int *fullbot;
+extern char **instead;
+extern int expflg;
+extern int xcolflg;
+extern int ctrflg;
+extern int evenflg;
+extern int *evenup;
+extern int boxflg;
+extern int dboxflg;
+extern int decimalpoint;
+extern int linsize;
+extern int tab;
+extern int pr1403;
+extern int graphics;
+extern int Graphics;
+extern int linsize, delim1, delim2;
+extern int allflg;
+extern int textflg;
+extern int left1flg;
+extern int rightl;
+struct colstr {char *col, *rcol;};
+extern struct colstr **table;
+extern char *cspace, *cstore, *cbase;
+extern char *exstore, *exlim;
+extern int *sep;
+extern int *used, *lused, *rused;
+extern int *linestop;
+extern char *leftover;
+extern char *last, *ifile;
+extern int *topat;
+extern intptr_t texname;
+extern int texct;
+extern int texct2;
+extern char texstr[];
+extern int linstart;
+extern int nokeep;
+
+extern const char *progname;
+extern int utf8;
+extern int tlp;
+extern int nflm;
+
+extern FILE *tabin, *tabout;
+# define CRIGHT 80
+# define CLEFT 40
+# define CMID 60
+# define S1 31
+# define S2 32
+# define TMP 38
+# define SF 35
+# define SL 34
+# define LSIZE 33
+# define SIND 37
+# define SVS 36
+/* this refers to the relative position of lines */
+# define LEFT 1
+# define RIGHT 2
+# define THRU 3
+# define TOP 1
+# define BOT 2
+
+/* t1.c */
+int tbl(int, char *[]);
+void setinp(int, char **);
+int swapin(void);
+/* t2.c */
+void tableput(void);
+/* t3.c */
+int getcomm(void);
+void backrest(char *);
+/* t4.c */
+int getspec(void);
+int readspec(void);
+/* t5.c */
+int gettbl(void);
+int nodata(int);
+int oneh(int);
+int permute(void);
+int vspand(int, int, int);
+int vspen(char *);
+/* t6.c */
+void maktab(void);
+void wide(char *, char *, char *);
+int filler(char *);
+/* t7.c */
+int runout(void);
+void runtabs(int, int);
+int ifline(char *);
+void need(void);
+void deftail(void);
+/* t8.c */
+void putline(int, int);
+void puttext(char *, char *, char *);
+void funnies(int, int);
+void putfont(char *);
+void putsize(char *);
+/* t9.c */
+int yetmore(void);
+int domore(char *);
+/* tb.c */
+void checkuse(void);
+int real(char *);
+char *chspace(void);
+void updspace(char *, char *, int);
+struct colstr *alocv(int);
+void release(void);
+/* tc.c */
+int choochar(void);
+int point(int);
+/* te.c */
+int error(char *);
+char *errmsg(int);
+char *gets1(char **, char **, size_t *);
+void un1getc(int);
+int get1char(void);
+/* tf.c */
+void savefill(void);
+void rstofill(void);
+void endoff(void);
+void ifdivert(void);
+void saveline(void);
+void restline(void);
+void cleanfc(void);
+void warnon(void);
+void warnoff(void);
+void svgraph(void);
+/* tg.c */
+char *get_text(char *, int, int, char *, char *);
+void untext(void);
+char *nreg(char *, size_t, const char *, int);
+/* ti.c */
+int interv(int, int);
+int interh(int, int);
+int up1(int);
+/* tm.c */
+char *maknew(char *);
+int ineqn(char *, char *);
+/* ts.c */
+int match(char *, char *);
+int prefix(char *, char *);
+int cprefix(char *, char *);
+int letter(int);
+int numb(char *);
+int digit(int);
+int max(int, int);
+void tcopy(char *, char *);
+/* tt.c */
+int ctype(int, int);
+int min(int, int);
+int fspan(int, int);
+int lspan(int, int);
+int ctspan(int, int);
+void tohcol(int);
+int allh(int);
+int thish(int, int);
+/* tu.c */
+void makeline(int, int, int);
+void fullwide(int, int);
+void drawline(int, int, int, int, int, int);
+void getstop(void);
+int left(int, int, int *);
+int lefdata(int, int);
+int next(int);
+int prev(int);
+/* tv.c */
+void drawvert(int, int, int, int);
+int midbar(int, int);
+int midbcol(int, int);
+int barent(char *);
diff --git a/tbl/t0.c b/tbl/t0.c
new file mode 100644
index 0000000000000..8b59c2b4fdd8a
--- /dev/null
+++ b/tbl/t0.c
@@ -0,0 +1,85 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t0.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t0.c 1.12 (gritter) 9/11/06
+ */
+
+ /* t0.c: storage allocation */
+# include "t..c"
+int MAXLIN;
+int MAXCOL;
+int MAXHEAD;
+int expflg = 0;
+int xcolflg;
+int ctrflg = 0;
+int boxflg = 0;
+int dboxflg = 0;
+int decimalpoint = '.';
+int tab = '\t';
+int linsize;
+int pr1403;
+int graphics;
+int Graphics;
+int delim1, delim2;
+int *evenup, evenflg; /* evenup[MAXCOL] */
+int F1 = 0;
+int F2 = 0;
+int allflg = 0;
+char *leftover = 0;
+int textflg = 0;
+int left1flg = 0;
+int rightl = 0;
+char *cstore, *cspace, *cbase;
+char *last;
+struct colstr **table; /* *table[MAXLIN] */
+int **style; /* style[MAXHEAD][MAXCOL] */
+int **ctop; /* ctop[MAXHEAD][MAXCOL] */
+char ***font; /* font[MAXHEAD][MAXCOL][CLLEN] */
+char ***csize; /* csize[MAXHEAD][MAXCOL][20] */
+char ***vsize; /* vsize[MAXHEAD][MAXCOL][20] */
+int **lefline; /* lefline[MAXHEAD][MAXCOL] */
+char **cll; /* cll[MAXCOL][CLLEN] */
+int *xcol;
+/*char *rpt[MAXHEAD][MAXCOL];*/
+/*char rpttx[MAXRPT];*/
+int *stynum; /* stynum[MAXLIN+1] */
+int nslin, nclin;
+int *sep; /* sep[MAXCOL] */
+int *fullbot; /* fullbot[MAXLIN] */
+char **instead; /* *instead[MAXLIN] */
+int *used, *lused, *rused; /* MAXCOL */
+int *linestop; /* linestop[MAXLIN] */
+int *topat; /* topat[MAXLIN] */
+int nlin, ncol;
+int iline = 1;
+char *ifile = "Input";
+intptr_t texname = 'a';
+int texct = 0;
+int texct2 = -1;
+char texstr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ0123456789";
+int linstart;
+int nokeep;
+char *exstore, *exlim;
+const char *progname;
+FILE *tabin /*= stdin */;
+FILE *tabout /* = stdout */;
+int utf8;
+int tlp;
+int nflm;
diff --git a/tbl/t1.c b/tbl/t1.c
new file mode 100644
index 0000000000000..f9e4776dde4c6
--- /dev/null
+++ b/tbl/t1.c
@@ -0,0 +1,189 @@
+/* Co/pyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t1.c 1.9 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t1.c 1.12 (gritter) 9/8/06
+ */
+
+ /* t1.c: main control and input switching */
+#
+# include "t..c"
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+#include <locale.h>
+# ifdef gcos
+/* required by GCOS because file is passed to "tbl" by troff preprocessor */
+# define _f1 _f
+extern FILE *_f[];
+# endif
+
+# ifndef gcos
+# define MACROS "/usr/doctools/tmac/tmac.s"
+# define MACROSS MACDIR "/s"
+# define PYMACS "/usr/doctools/tmac/tmac.m"
+# define PYMACSS MACDIR "/m"
+# define MEMACSS MACDIR "/e"
+# endif
+
+# ifdef gcos
+# define MACROS "cc/troff/smac"
+# define PYMACS "cc/troff/mmac"
+# endif
+
+# define ever (;;)
+
+int
+main(int argc, char *argv[])
+{
+# ifndef gcos
+void badsig(int);
+# endif
+ progname = basename(argv[0]);
+# ifndef gcos
+signal(SIGPIPE, badsig);
+# endif
+# ifdef gcos
+if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
+# endif
+exit(tbl(argc,argv));
+}
+
+
+int
+tbl(int argc, char *argv[])
+{
+char *line = NULL;
+size_t linesize = 0;
+/* required by GCOS because "stdout" is set by troff preprocessor */
+tabin=stdin; tabout=stdout;
+setinp(argc,argv);
+while (gets1(&line, &line, &linesize))
+ {
+ fprintf(tabout, "%s\n",line);
+ if (cprefix("TS", line))
+ tableput();
+ }
+fclose(tabin);
+free(line);
+return(0);
+}
+int sargc;
+char **sargv;
+void
+setinp(int argc, char **argv)
+{
+ sargc = argc;
+ sargv = argv;
+ sargc--; sargv++;
+ if (sargc>0)
+ swapin();
+ if (pr1403 || utf8 || tlp) nflm = 1;
+}
+int
+swapin(void)
+{
+ char *optarg;
+ while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */
+ {
+ if (sargc<=0) return(0);
+ if (match("-me", *sargv))
+ {
+ *sargv = MEMACSS;
+ break;
+ }
+ if (match("-ms", *sargv))
+ {
+ *sargv = MACROSS;
+ break;
+ }
+ if (match("-mm", *sargv))
+ {
+ *sargv = PYMACSS;
+ break;
+ }
+ if ((*sargv)[1] == 'T') {
+ optarg = *sargv + 2;
+ if (!*optarg) {
+ sargc--; sargv++;
+ if (!sargc || **sargv == '-') {
+ fprintf(stderr, "%s: Argument expected"
+ " after option -T\n", progname);
+ exit(1);
+ }
+ optarg = *sargv;
+ }
+ if (*optarg == 'X' && !optarg[1]) {
+ pr1403=1;
+ } else if (!strcmp(optarg, "lp")) {
+ tlp = 1;
+ utf8 = 0;
+ Graphics = 0;
+ } else if (!strcmp(optarg, "locale")) {
+ Graphics = 0;
+ if (strstr(setlocale(LC_ALL, ""), "UTF-8")) {
+ utf8 = 1;
+ tlp = 0;
+ } else {
+ tlp = 1;
+ }
+ }
+ }
+ else if (match("-g", *sargv))
+ {
+ Graphics=1;
+ utf8 = 0;
+ tlp = 0;
+ }
+ else {
+ (void) fprintf(stderr, "%s: Invalid option "
+ "(%s).\n", progname, *sargv);
+ (void) fprintf(stderr, "Usage: %s [ -me ] "
+ "[ -mm ] [ -ms ] [ filename ... ]\n", progname);
+ exit(1);
+ }
+ sargc--; sargv++;
+ }
+ if (sargc<=0) return(0);
+# ifndef gcos
+/* file closing is done by GCOS troff preprocessor */
+ if (tabin!=stdin) fclose(tabin);
+# endif
+ tabin = fopen(ifile= *sargv, "r");
+ iline=1;
+# ifndef gcos
+/* file names are all put into f. by the GCOS troff preprocessor */
+ fprintf(tabout, ".ds f. %s\n",ifile);
+# endif
+ fprintf(tabout, ".lf 1 %s\n", ifile);
+ if (tabin==NULL)
+ return error("Can't open file");
+ sargc--;
+ sargv++;
+ return(1);
+}
+# ifndef gcos
+void
+badsig(int unused)
+{
+signal(SIGPIPE, SIG_IGN);
+ exit(0);
+}
+# endif
diff --git a/tbl/t2.c b/tbl/t2.c
new file mode 100644
index 0000000000000..3f9b230fc3c69
--- /dev/null
+++ b/tbl/t2.c
@@ -0,0 +1,49 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t2.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t2.c 1.3 (gritter) 7/23/05
+ */
+
+ /* t2.c: subroutine sequencing for one table */
+# include "t..c"
+void
+tableput(void) {
+ saveline();
+ savefill();
+ ifdivert();
+ cleanfc();
+ if (getcomm())
+ return;
+ if (getspec())
+ return;
+ if (gettbl())
+ return;
+ getstop();
+ checkuse();
+ if (choochar())
+ return;
+ maktab();
+ if (runout())
+ return;
+ release();
+ rstofill();
+ endoff();
+ restline();
+}
diff --git a/tbl/t3.c b/tbl/t3.c
new file mode 100644
index 0000000000000..ff2855283e4c7
--- /dev/null
+++ b/tbl/t3.c
@@ -0,0 +1,132 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t3.c 1.5 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t3.c 1.12 (gritter) 9/11/06
+ */
+
+ /* t3.c: interpret commands affecting whole table */
+# include "t..c"
+# include <string.h>
+# include <stdlib.h>
+struct optstr {char *optnam; int *optadd;} options [] = {
+ { "expand", &expflg },
+ { "EXPAND", &expflg },
+ { "center", &ctrflg },
+ { "CENTER", &ctrflg },
+ { "box", &boxflg },
+ { "BOX", &boxflg },
+ { "allbox", &allflg },
+ { "ALLBOX", &allflg },
+ { "doublebox", &dboxflg },
+ { "DOUBLEBOX", &dboxflg },
+ { "frame", &boxflg },
+ { "FRAME", &boxflg },
+ { "doubleframe", &dboxflg },
+ { "DOUBLEFRAME", &dboxflg },
+ { "tab", &tab },
+ { "TAB", &tab },
+ { "linesize", &linsize },
+ { "LINESIZE", &linsize },
+ { "decimalpoint", &decimalpoint },
+ { "DECIMALPOINT", &decimalpoint },
+ { "delim", &delim1 },
+ { "DELIM", &delim1 },
+ { "graphics", &graphics },
+ { "GRAPICS", &graphics },
+ { "nokeep", &nokeep },
+ { "NOKEEP", &nokeep },
+ { "left", NULL },
+ { NULL, NULL }
+};
+
+int
+getcomm(void) {
+ char *line = NULL, *cp, nb[25], *t;
+ size_t linesize = 0;
+ struct optstr *lp;
+ int c, ci, found;
+ for(lp= options; lp->optadd; lp++)
+ *(lp->optadd) = 0;
+ texname = texstr[texct=0];
+ texct2 = -1;
+ tab = '\t';
+ decimalpoint = '.';
+ if (pr1403) graphics = 0;
+ else graphics = Graphics;
+ printf(".nr %d \\n(.s\n", LSIZE);
+ gets1(&line, &line, &linesize);
+ /* see if this is a command line */
+ if (strchr(line,';') == NULL) {
+ backrest(line);
+ free(line);
+ return 0;
+ }
+ for(cp=line; (c = *cp) != ';'; cp++) {
+ if (!letter(c)) continue;
+ found=0;
+ for(lp= options; lp->optnam; lp++) {
+ if (prefix(lp->optnam, cp)) {
+ cp += strlen(lp->optnam);
+ if (letter(*cp))
+ return
+ error("Misspelled global option");
+ while (*cp==' ')cp++;
+ t=nb;
+ if ( *cp == '(')
+ while ((ci= *++cp) != ')')
+ *t++ = ci;
+ else cp--;
+ *t++ = 0; *t=0;
+ if (!lp->optadd)
+ goto found;
+ *(lp->optadd) = 1;
+ if (lp->optadd == &tab || lp->optadd ==
+ &decimalpoint) {
+ if (nb[0])
+ *(lp->optadd) = nb[0];
+ }
+ if (lp->optadd == &linsize)
+ printf(".nr %d %s\n", LSIZE, nb);
+ if (lp->optadd == &delim1) {
+ delim1 = nb[0];
+ delim2 = nb[1];
+ }
+found:
+ found=1;
+ break;
+ }
+ }
+ if (!found)
+ return error("Illegal option");
+ }
+ cp++;
+ backrest(cp);
+ free(line);
+ return 0;
+}
+
+void
+backrest(char *cp) {
+ char *s;
+ for(s=cp; *s; s++);
+ un1getc('\n');
+ while (s>cp)
+ un1getc(*--s);
+}
diff --git a/tbl/t4.c b/tbl/t4.c
new file mode 100644
index 0000000000000..9810576b2140e
--- /dev/null
+++ b/tbl/t4.c
@@ -0,0 +1,473 @@
+/*
+ * Copyright 1983-2003 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/* from OpenSolaris "t4.c 1.10 05/06/02 SMI" */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ * Portions Copyright (c) 2015 Carsten Kunze
+ *
+ * Sccsid @(#)t4.c 1.7 (gritter) 9/8/06
+ */
+
+ /* t4.c: read table specification */
+# include "t..c"
+# include <stdlib.h>
+# include <string.h>
+int oncol;
+static int morecols(int);
+static int moreheads(int);
+static void initspec(int);
+static void inithead(int, int);
+
+int
+getspec(void) {
+ int i;
+ moreheads(0);
+ morecols(0);
+ initspec(0);
+ nclin=ncol=0;
+ oncol =0;
+ left1flg=rightl=0;
+ if (readspec())
+ return -1;
+ fprintf(tabout, ".rm");
+ for(i=0; i<ncol; i++)
+ fprintf(tabout, " %02d", 80+i);
+ fprintf(tabout, "\n");
+ return 0;
+}
+
+int
+readspec(void)
+{
+ int icol, c, sawchar, stopc, i;
+ char sn[10], *snp, *temp;
+ sawchar=icol=0;
+ while ((c=get1char()))
+ {
+ switch(c)
+ {
+ default:
+ if (c != tab)
+ return error("bad table specification character");
+ case ' ': /* note this is also case tab */
+ continue;
+ case '\n':
+ if(sawchar==0) continue;
+ case ',':
+ case '.': /* end of table specification */
+ ncol = max(ncol, icol);
+ if (lefline[nclin][ncol]>0) {ncol++; rightl++;};
+ if(sawchar)
+ nclin++;
+ if (nclin>=MAXHEAD && !moreheads(nclin))
+ return error("too many lines in specification");
+ icol=0;
+ if (ncol==0 || nclin==0)
+ return error("no specification");
+ if (c== '.')
+ {
+ while ((c=get1char()) && c != '\n')
+ if (c != ' ' && c != '\t')
+ return error(
+ "dot not last character on format line");
+ /* fix up sep - default is 3 except at edge */
+ for(icol=0; icol<ncol; icol++)
+ if (sep[icol]<0)
+ sep[icol] = icol+1<ncol ? 3 : 1;
+ if (oncol == 0)
+ oncol = ncol;
+ else if (oncol +2 <ncol)
+ return error("tried to widen table in T&, not allowed");
+ return 0;
+ }
+ sawchar=0;
+ continue;
+ case 'C': case 'S': case 'R': case 'N': case 'L': case 'A':
+ c += ('a'-'A');
+ case '_': if (c=='_') c= '-';
+ case '=': case '-':
+ case '^':
+ case 'c': case 's': case 'n': case 'r': case 'l': case 'a':
+ style[nclin][icol]=c;
+ if (c== 's' && icol<=0)
+ return error("first column can not be S-type");
+ if (c=='s' && style[nclin][icol-1] == 'a')
+ {
+ fprintf(tabout,
+ ".tm warning: can't span a-type cols, changed to l\n");
+ style[nclin][icol-1] = 'l';
+ }
+ if (c=='s' && style[nclin][icol-1] == 'n')
+ {
+ fprintf(tabout,
+ ".tm warning: can't span n-type cols, changed to c\n");
+ style[nclin][icol-1] = 'c';
+ }
+ icol++;
+ if (c=='^' && nclin<=0)
+ return error("first row can not contain vertical span");
+ if (icol>=MAXCOL && !morecols(icol))
+ return error("too many columns in table");
+ sawchar=1;
+ continue;
+ case 'b': case 'i':
+ c += 'A'-'a';
+ /* FALLTHRU */
+ case 'B': case 'I':
+ if (sawchar == 0)
+ continue;
+ if (icol==0) continue;
+ snp=font[nclin][icol-1];
+ snp[0]= (c=='I' ? '2' : '3');
+ snp[1]=0;
+ continue;
+ case 't': case 'T':
+ if (sawchar == 0) {
+ continue;
+ }
+ if (icol>0)
+ ctop[nclin][icol-1] = 1;
+ continue;
+ case 'd': case 'D':
+ if (sawchar == 0)
+ continue;
+ if (icol>0)
+ ctop[nclin][icol-1] = -1;
+ continue;
+ case 'f': case 'F':
+ if (sawchar == 0)
+ continue;
+ if (icol==0) continue;
+ snp=font[nclin][icol-1];
+ snp[0]=snp[1]=stopc=0;
+ for(i=0; i<CLLEN; i++)
+ {
+ if (stopc==0 && i==2) break;
+ do
+ c = get1char();
+ while (i==0 && c==' ');
+ if (i==0 && c=='(')
+ {
+ stopc=')';
+ c = get1char();
+ }
+ if (c==0) break;
+ if (c==stopc) {stopc=0; break;}
+ if (stopc==0) if (c==' ' || c== tab ) break;
+ if (c=='.'){un1getc(c); break;}
+ if (c=='\n'){un1getc(c); break;}
+ snp[i] = c;
+ if (c>= '0' && c<= '9') break;
+ }
+ if (stopc) if (get1char()!=stopc)
+ return error("Nonterminated font name");
+ continue;
+ case 'P': case 'p':
+ if (sawchar == 0)
+ continue;
+ if (icol<=0) continue;
+ temp = snp = csize[nclin][icol-1];
+ while ((c = get1char()))
+ {
+ if (c== ' ' || c== tab || c=='\n') break;
+ if (c=='-' || c == '+')
+ if (snp>temp)
+ break;
+ else
+ *snp++=c;
+ else
+ if (digit(c))
+ *snp++ = c;
+ else break;
+ if (snp-temp>20)
+ return error("point size too large");
+ }
+ *snp = 0;
+ if (atoi(temp)>36)
+ return error("point size unreasonable");
+ un1getc (c);
+ continue;
+ case 'V': case 'v':
+ if (sawchar == 0)
+ continue;
+ if (icol<=0) continue;
+ temp = snp = vsize[nclin][icol-1];
+ while ((c = get1char()))
+ {
+ if (c== ' ' || c== tab || c=='\n') break;
+ if (c=='-' || c == '+')
+ if (snp>temp)
+ break;
+ else
+ *snp++=c;
+ else
+ if (digit(c))
+ *snp++ = c;
+ else break;
+ if (snp-temp>20)
+ return error(
+ "vertical spacing value too large");
+ }
+ *snp=0;
+ un1getc(c);
+ continue;
+ case 'w': case 'W':
+ if (sawchar == 0) {
+ /*
+ * This should be an error case.
+ * However, for the backward-compatibility,
+ * treat as if 'c' was specified.
+ */
+ style[nclin][icol] = 'c';
+ icol++;
+ if (icol >= MAXCOL && !morecols(icol)) {
+ return error("too many columns in table");
+ }
+ sawchar = 1;
+ }
+
+ snp = cll [icol-1];
+ /* Dale Smith didn't like this check
+ * possible to have two text blocks
+ * of different widths now ....
+ if (*snp)
+ {
+ fprintf(tabout,
+ "Ignored second width specification");
+ continue;
+ }
+ * end commented out code ... */
+ stopc=0;
+ while ((c = get1char()))
+ {
+ if (snp==cll[icol-1] && c==' ')
+ continue;
+ if (snp==cll[icol-1] && c=='(')
+ {
+ stopc = ')';
+ continue;
+ }
+ if ( !stopc && (c>'9' || c< '0'))
+ break;
+ if (stopc && c== stopc)
+ break;
+ if (snp-cll[icol-1]>CLLEN)
+ return error ("column width too long");
+ *snp++ =c;
+ }
+ *snp=0;
+ if (!stopc)
+ un1getc(c);
+ continue;
+ case 'x': case 'X':
+ if (!sawchar || icol < 1) break;
+ xcol[icol-1] = 1;
+ xcolflg++;
+ expflg = 0;
+ break;
+ case 'e': case 'E':
+ if (sawchar == 0)
+ continue;
+ if (icol<1) continue;
+ evenup[icol-1]=1;
+ evenflg=1;
+ continue;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ sn[0] = c;
+ snp=sn+1;
+ while (digit(*snp++ = c = get1char()))
+ ;
+ un1getc(c);
+ sep[icol-1] = max(sep[icol-1], numb(sn));
+ continue;
+ case '|':
+ lefline[nclin][icol]++;
+ if (icol==0) left1flg=1;
+ continue;
+ }
+ }
+ return error("EOF reading table specification");
+}
+
+static int
+morecols(int n)
+{
+ int i, j, inc = 10, maxcol;
+ void *vp;
+ if (n < MAXCOL) return(1);
+ while ((maxcol = MAXCOL + inc) < n) inc *= 2;
+ for (i=0; i<MAXHEAD; i++)
+ {
+ if ((vp = realloc(style[i], maxcol * sizeof **style)) == NULL)
+ return(0);
+ style[i] = vp;
+ if ((vp = realloc(ctop[i], maxcol * sizeof **ctop)) == NULL)
+ return(0);
+ ctop[i] = vp;
+ if ((vp = realloc(font[i], maxcol * sizeof **font)) == NULL)
+ return(0);
+ font[i] = vp;
+ if ((vp = realloc(csize[i], maxcol * sizeof **csize)) == NULL)
+ return(0);
+ csize[i] = vp;
+ if ((vp = realloc(vsize[i], maxcol * sizeof **vsize)) == NULL)
+ return(0);
+ vsize[i] = vp;
+ if ((vp = realloc(lefline[i], maxcol * sizeof **lefline)) == NULL)
+ return(0);
+ lefline[i] = vp;
+ for (j=MAXCOL; j<maxcol; j++)
+ {
+ if ((font[i][j] = calloc(CLLEN, sizeof ***font)) == NULL)
+ return(0);
+ if ((csize[i][j] = calloc(20, sizeof ***csize)) == NULL)
+ return(0);
+ if ((vsize[i][j] = calloc(20, sizeof ***vsize)) == NULL)
+ return(0);
+ }
+ }
+ if ((vp = realloc(cll, maxcol * sizeof *cll)) == NULL)
+ return(0);
+ cll = vp;
+ for (j=MAXCOL; j<maxcol; j++)
+ if ((cll[j] = calloc(CLLEN, sizeof **cll)) == NULL)
+ return(0);
+ if ((vp = realloc(xcol, maxcol * sizeof(*xcol))) == NULL)
+ return 0;
+ xcol = vp;
+ if ((vp = realloc(evenup, maxcol * sizeof *evenup)) == NULL)
+ return(0);
+ evenup = vp;
+ if ((vp = realloc(sep, maxcol * sizeof *sep)) == NULL)
+ return(0);
+ sep = vp;
+ if ((vp = realloc(used, maxcol * sizeof *used)) == NULL)
+ return(0);
+ used = vp;
+ if ((vp = realloc(lused, maxcol * sizeof *lused)) == NULL)
+ return(0);
+ lused = vp;
+ if ((vp = realloc(rused, maxcol * sizeof *rused)) == NULL)
+ return(0);
+ rused = vp;
+ if ((vp = realloc(topat, maxcol * sizeof *topat)) == NULL)
+ return(0);
+ topat = vp;
+ MAXCOL = maxcol;
+ initspec(MAXCOL - inc);
+ return(1);
+}
+static int
+moreheads(int n)
+{
+ int i, j, inc = 10, maxhead;
+ void *vp;
+ if (n<MAXHEAD) return(1);
+ while ((maxhead = MAXHEAD + inc) < n) inc *= 2;
+ if ((vp = realloc(style, maxhead * sizeof *style)) == NULL)
+ return(0);
+ style = vp;
+ if ((vp = realloc(ctop, maxhead * sizeof *ctop)) == NULL)
+ return(0);
+ ctop = vp;
+ if ((vp = realloc(font, maxhead * sizeof *font)) == NULL)
+ return(0);
+ font = vp;
+ if ((vp = realloc(csize, maxhead * sizeof *csize)) == NULL)
+ return(0);
+ csize = vp;
+ if ((vp = realloc(vsize, maxhead * sizeof *vsize)) == NULL)
+ return(0);
+ vsize = vp;
+ if ((vp = realloc(lefline, maxhead * sizeof *lefline)) == NULL)
+ return(0);
+ lefline = vp;
+ if (MAXCOL == 0)
+ {
+ memset(style, 0, maxhead * sizeof *style);
+ memset(ctop, 0, maxhead * sizeof *ctop);
+ memset(font, 0, maxhead * sizeof *font);
+ memset(csize, 0, maxhead * sizeof *csize);
+ memset(vsize, 0, maxhead * sizeof *vsize);
+ memset(lefline, 0, maxhead * sizeof *lefline);
+ }
+ if (MAXCOL) for (i=MAXHEAD; i<maxhead; i++)
+ {
+ if ((vp = calloc(MAXCOL, sizeof **style)) == NULL)
+ return(0);
+ style[i] = vp;
+ if ((vp = calloc(MAXCOL, sizeof **ctop)) == NULL)
+ return(0);
+ ctop[i] = vp;
+ if ((vp = calloc(MAXCOL, sizeof **font)) == NULL)
+ return(0);
+ font[i] = vp;
+ if ((vp = calloc(MAXCOL, sizeof **csize)) == NULL)
+ return(0);
+ csize[i] = vp;
+ if ((vp = calloc(MAXCOL, sizeof **vsize)) == NULL)
+ return(0);
+ vsize[i] = vp;
+ if ((vp = calloc(MAXCOL, sizeof **lefline)) == NULL)
+ return(0);
+ lefline[i] = vp;
+ for (j=0; j<MAXCOL; j++)
+ {
+ if ((vp = calloc(CLLEN, sizeof ***font)) == NULL)
+ return(0);
+ font[i][j] = vp;
+ if ((vp = calloc(20, sizeof ***csize)) == NULL)
+ return(0);
+ csize[i][j] = vp;
+ if ((vp = calloc(20, sizeof ***vsize)) == NULL)
+ return(0);
+ vsize[i][j] = vp;
+ }
+ }
+ MAXHEAD = maxhead;
+ for (j=0; j<MAXCOL; j++)
+ inithead(MAXHEAD-inc, j);
+ return(1);
+}
+static void
+initspec(int scol)
+{
+ int icol;
+ for(icol=scol; icol<MAXCOL; icol++)
+ {
+ sep[icol]= -1;
+ evenup[icol]=0;
+ cll[icol][0]=0;
+ xcol[icol] = 0;
+ inithead(0, icol);
+ }
+ xcolflg = 0;
+}
+static void
+inithead(int shead, int icol)
+{
+int i;
+for(i=shead; i<MAXHEAD; i++)
+ {
+ csize[i][icol][0]=0;
+ vsize[i][icol][0]=0;
+ font[i][icol][0] = lefline[i][icol] = 0;
+ ctop[i][icol]=0;
+ style[i][icol]= 'l';
+ }
+}
diff --git a/tbl/t5.c b/tbl/t5.c
new file mode 100644
index 0000000000000..ab44521d5ddec
--- /dev/null
+++ b/tbl/t5.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright 1983-2003 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/* from OpenSolaris "t5.c 1.6 05/06/02 SMI" */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t5.c 1.8 (gritter) 10/2/07
+ */
+
+ /* t5.c: read data for table */
+# include <stdlib.h>
+# include <string.h>
+# include "t..c"
+# include <inttypes.h>
+
+static int morelines(int);
+
+int
+gettbl(void)
+{
+ int icol, ch;
+ char *ocbase;
+ size_t linesize = MAXSTR;
+ morelines(0);
+ if (!(cbase = cstore = cspace = chspace()))
+ return -1;
+ textflg=0;
+ for (nlin=nslin=0; ocbase=cbase, gets1(&cbase, &cstore, &linesize); nlin++)
+ {
+ cspace += cbase - ocbase;
+ stynum[nlin]=nslin;
+ if (cprefix("TE", cstore))
+ {
+ leftover=0;
+ break;
+ }
+ if (cprefix("TC", cstore) || cprefix("T&", cstore))
+ {
+ if (readspec())
+ return -1;
+ nslin++;
+ }
+ if (nlin>=MAXLIN && !morelines(nlin))
+ {
+ leftover=cstore;
+ break;
+ }
+ table[nlin] = NULL;
+ fullbot[nlin]=0;
+ if (cstore[0] == '.' && !isdigit((unsigned char)cstore[1]))
+ {
+ instead[nlin] = cstore;
+ while (*cstore++);
+ continue;
+ }
+ else instead[nlin] = 0;
+ if (nodata(nlin))
+ {
+ if ((ch = oneh(nlin)))
+ fullbot[nlin]= ch;
+ nlin++;
+ nslin++;
+ instead[nlin]=(char *)0;
+ fullbot[nlin]=0;
+ }
+ if ((table[nlin] = alocv((ncol+2)*sizeof(table[0][0])))
+ == (struct colstr *)-1)
+ return -1;
+ if (cstore[1]==0)
+ switch(cstore[0])
+ {
+ case '_': fullbot[nlin]= '-'; continue;
+ case '=': fullbot[nlin]= '='; continue;
+ }
+ stynum[nlin] = nslin;
+ nslin = min(nslin+1, nclin-1);
+ for (icol = 0; icol <ncol; icol++)
+ {
+ table[nlin][icol].col = cstore;
+ table[nlin][icol].rcol=0;
+ ch=1;
+ if (match(cstore, "T{")) { /* text follows */
+ /* get_text was originally gettext and was renamed */
+ if ((table[nlin][icol].col =
+ get_text(cstore, nlin, icol,
+ font[stynum[nlin]][icol],
+ csize[stynum[nlin]][icol])) == (char *)-1)
+ return -1;
+ } else {
+ for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
+ ;
+ *cstore++ = '\0';
+ switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
+ {
+ case 'n':
+ if ((table[nlin][icol].rcol =
+ maknew(table[nlin][icol].col))
+ == (char *)-1)
+ return -1;
+ break;
+ case 'a':
+ table[nlin][icol].rcol = table[nlin][icol].col;
+ table[nlin][icol].col = "";
+ break;
+ }
+ }
+ while (ctype(nlin,icol+1)== 's') /* spanning */
+ table[nlin][++icol].col = "";
+ if (ch == '\0') break;
+ }
+ while (++icol <ncol+2)
+ {
+ table[nlin][icol].col = "";
+ table [nlin][icol].rcol=0;
+ }
+ while (*cstore != '\0')
+ cstore++;
+ if (cstore-cspace > MAXCHS)
+ if (!(cbase = cstore = cspace = chspace()))
+ return -1;
+ }
+ last = cstore;
+ if (permute())
+ return -1;
+ if (textflg) untext();
+ return 0;
+}
+
+int
+nodata(int il)
+{
+ int c;
+ for (c=0; c<ncol;c++)
+ {
+ switch(ctype(il,c))
+ {
+ case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
+ return(0);
+ }
+ }
+ return(1);
+}
+int
+oneh(int lin)
+{
+ int k, icol;
+ k = ctype(lin,0);
+ for(icol=1; icol<ncol; icol++)
+ {
+ if (k != ctype(lin,icol))
+ return(0);
+ }
+ return(k);
+}
+
+# define SPAN "\\^"
+
+int
+permute(void)
+{
+ int irow, jcol, is;
+ char *start, *strig;
+ for(jcol=0; jcol<ncol; jcol++)
+ {
+ for(irow=1; irow<nlin; irow++)
+ {
+ if (vspand(irow,jcol,0))
+ {
+ is = prev(irow);
+ if (is<0)
+ return error("Vertical spanning in "
+ "first row not allowed");
+ start = table[is][jcol].col;
+ strig = table[is][jcol].rcol;
+ while (irow<nlin &&vspand(irow,jcol,0))
+ irow++;
+ table[--irow][jcol].col = start;
+ table[irow][jcol].rcol = strig;
+ while (is<irow)
+ {
+ table[is][jcol].rcol =0;
+ table[is][jcol].col= SPAN;
+ is = next(is);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+int
+vspand(int ir, int ij, int ifform)
+{
+ if (ir<0) return(0);
+ if (ir>=nlin)return(0);
+ if (instead[ir]) return(0);
+ if (ifform==0 && ctype(ir,ij)=='^') return(1);
+ if (table[ir]==0) return(0);
+ if (table[ir][ij].rcol!=0) return(0);
+ if (fullbot[ir]) return(0);
+ return(vspen(table[ir][ij].col));
+}
+int
+vspen(char *s)
+{
+ if (s==0) return(0);
+ if (!point((intptr_t)s)) return(0);
+ return(match(s, SPAN));
+}
+static int
+morelines(int n)
+{
+ int inc = 200, maxlin;
+ void *vp;
+ if (n>MAXLIN) return(1);
+ while ((maxlin = MAXLIN + inc) < n) inc *= 2;
+ if ((vp = realloc(table, maxlin * sizeof *table)) == NULL)
+ return(0);
+ table = vp;
+ if ((vp = realloc(stynum, (maxlin + 1) * sizeof *stynum)) == NULL)
+ return(0);
+ stynum = vp;
+ if ((vp = realloc(fullbot, maxlin * sizeof *fullbot)) == NULL)
+ return(0);
+ fullbot = vp;
+ memset(&fullbot[MAXLIN], 0, inc * sizeof *fullbot);
+ if ((vp = realloc(instead, maxlin * sizeof *instead)) == NULL)
+ return(0);
+ instead = vp;
+ memset(&instead[MAXLIN], 0, inc * sizeof *instead);
+ if ((vp = realloc(linestop, maxlin * sizeof *linestop)) == NULL)
+ return(0);
+ linestop = vp;
+ MAXLIN = maxlin;
+ return(1);
+}
diff --git a/tbl/t6.c b/tbl/t6.c
new file mode 100644
index 0000000000000..82f59d8da4569
--- /dev/null
+++ b/tbl/t6.c
@@ -0,0 +1,250 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t6.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ * Portions Copyright (c) 2015 Carsten Kunze
+ *
+ * Sccsid @(#)t6.c 1.6 (gritter) 2/8/06
+ */
+
+ /* t6.c: compute tab stops */
+# define tx(a) ((a)!=(char *)0 && !point((intptr_t)(a)))
+# include "t..c"
+# include <inttypes.h>
+void
+maktab(void)
+{
+# define FN(i,c) font[stynum[i]][c]
+# define SZ(i,c) csize[stynum[i]][c]
+ /* define the tab stops of the table */
+ int icol, ilin, tsep, k, ik, vforml, il, text;
+ int doubled[MAXCOL], acase[MAXCOL];
+ char *s;
+ char space[40];
+ for(icol=0; icol <ncol; icol++)
+ {
+ doubled[icol] = acase[icol] = 0;
+ fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
+ for(text=0; text<2; text++)
+ {
+ if (text) {
+ warnoff();
+ fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
+ warnon();
+ }
+ for(ilin=0; ilin<nlin; ilin++)
+ {
+ if (instead[ilin]|| fullbot[ilin]) continue;
+ vforml=ilin;
+ for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
+ vforml=il;
+ if (fspan(vforml,icol)) continue;
+ if (filler(table[ilin][icol].col)) continue;
+ switch(ctype(vforml,icol))
+ {
+ case 'a':
+ acase[icol]=1;
+ s = table[ilin][icol].col;
+ if (tx(s) && text)
+ {
+ if (doubled[icol]==0)
+ fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
+ doubled[icol]=1;
+ nreg(space, sizeof(space), s,
+ '-');
+ fprintf(tabout, ".if %s>\\n(%d .nr %d %s\n",space,S2,S2,space);
+ }
+ case 'n':
+ if (table[ilin][icol].rcol!=0)
+ {
+ if (doubled[icol]==0 && text==0)
+ fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
+ doubled[icol]=1;
+ if (real(s=table[ilin][icol].col) && !vspen(s))
+ {
+ if (tx(s) != text) continue;
+ fprintf(tabout, ".nr %d ", TMP);
+ wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
+ fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
+ }
+ if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
+ {
+ fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
+ fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
+ }
+ continue;
+ }
+ case 'r':
+ case 'c':
+ case 'l':
+ if (real(s=table[ilin][icol].col) && !vspen(s))
+ {
+ if (tx(s) != text) continue;
+ fprintf(tabout, ".nr %d ", TMP);
+ wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
+ fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
+ }
+ }
+ }
+ }
+ if (acase[icol])
+ {
+ fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
+ }
+ if (doubled[icol])
+ {
+ fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
+ fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
+ fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
+ fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,icol+CRIGHT,TMP);
+ }
+ if (cll[icol][0])
+ {
+ fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
+ fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP);
+ }
+ for(ilin=0; ilin<nlin; ilin++)
+ if ((k=lspan(ilin, icol)))
+ {
+ s=table[ilin][icol-k].col;
+ if (!real(s) || barent(s) || vspen(s) ) continue;
+ fprintf(tabout, ".nr %d ", TMP);
+ wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
+ for(ik=k; ik>=0; ik--)
+ {
+ fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik);
+ if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
+ }
+ fprintf(tabout, "\n");
+ fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
+ fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
+ for(ik=0; ik<k; ik++)
+ {
+ if (doubled[icol-k+ik])
+ fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
+ fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP);
+ }
+ }
+ }
+ if (textflg) untext();
+ /* if even requested, make all columns widest width */
+# define TMP1 S1
+# define TMP2 S2
+ if (evenflg)
+ {
+ fprintf(tabout, ".nr %d 0\n", TMP);
+ for(icol=0; icol<ncol; icol++)
+ {
+ if (evenup[icol]==0) continue;
+ fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
+ icol+CRIGHT, TMP, TMP, icol+CRIGHT);
+ }
+ for(icol=0; icol<ncol; icol++)
+ {
+ if (evenup[icol]==0)
+ /* if column not evened just retain old interval */
+ continue;
+ if (doubled[icol])
+ fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
+ icol+CMID, icol+CMID, icol+CRIGHT, TMP);
+ /* that nonsense with the 100's and parens tries
+ to avoid overflow while proportionally shifting
+ the middle of the number */
+ fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP);
+ }
+ }
+ /* now adjust for total table width */
+ for(tsep=icol=0; icol<ncol; icol++)
+ tsep+= sep[icol];
+ if (expflg)
+ {
+ fprintf(tabout, ".nr %d 0", TMP);
+ for(icol=0; icol<ncol; icol++)
+ fprintf(tabout, "+\\n(%d", icol+CRIGHT);
+ fprintf(tabout, "\n");
+ fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d%s\n", TMP, TMP,
+ (utf8 || tlp) && (boxflg || dboxflg || allflg) ? "-1n" : "");
+ if (boxflg || dboxflg || allflg)
+ tsep += 1;
+ else
+ tsep -= sep[ncol-1];
+ fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP, tsep);
+ fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP);
+ }
+ else if (xcolflg) {
+ fprintf(tabout, ".nr %d 0", TMP);
+ for(icol=0; icol<ncol; icol++)
+ fprintf(tabout, "+\\n(%d", icol+CRIGHT);
+ fprintf(tabout, "\n");
+ fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d-%dn/%d\n", TMP,
+ TMP, tsep + ((boxflg || dboxflg || allflg) ?
+ (utf8 || tlp) ? 2 : 1 : -1), xcolflg);
+ for(icol=0; icol<ncol; icol++) {
+ if (!xcol[icol]) continue;
+ fprintf(tabout, ".nr %d +\\n(%d\n", icol+CRIGHT, TMP);
+ }
+ fprintf(tabout, ".nr %d 1n\n", TMP);
+ }
+ else
+ fprintf(tabout, ".nr %d 1n\n", TMP);
+ fprintf(tabout, ".nr %d 0\n",CRIGHT-1);
+ tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
+ for(icol=0; icol<ncol; icol++)
+ {
+ fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
+ fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
+ if (doubled[icol])
+ {
+ /* the next line is last-ditch effort to avoid zero field width */
+ /*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
+ fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
+ /* fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
+ }
+ tsep=sep[icol];
+ }
+ if (rightl)
+ fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
+ fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
+ if (boxflg || allflg || dboxflg)
+ fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
+ fprintf(tabout,
+ ".if t .if \\n(TW>\\n(.l .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile);
+ return;
+}
+void
+wide(char *s, char *fn, char *size)
+{
+ char space[40];
+ if (point((intptr_t)s))
+ {
+ fprintf(tabout, "\\w%c", F1);
+ if (*fn>0) putfont(fn);
+ if (*size) putsize(size);
+ fprintf(tabout, "%s", s);
+ if (*fn>0) putfont("P");
+ if (*size) putsize("0");
+ fprintf(tabout, "%c",F1);
+ }
+ else
+ fprintf(tabout, "%s", nreg(space, sizeof(space), s, '-'));
+}
+int
+filler(char *s)
+{
+return (point((intptr_t)s) && s[0]=='\\' && s[1] == 'R');
+}
diff --git a/tbl/t7.c b/tbl/t7.c
new file mode 100644
index 0000000000000..ec4026b5cb7bf
--- /dev/null
+++ b/tbl/t7.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 1983-1998 by Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t7.c 1.5 05/06/02 SMI" */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t7.c 1.8 (gritter) 10/25/06
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+ /* t7.c: control to write table entries */
+# include "t..c"
+# include <inttypes.h>
+# define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
+
+int
+runout(void)
+{
+ int i;
+ if ((boxflg || allflg || dboxflg) && !nokeep) need();
+ if (ctrflg)
+ {
+ fprintf(tabout, ".nr #I \\n(.i\n");
+ fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
+ }
+ fprintf(tabout, ".fc %c %c\n", F1, F2);
+ fprintf(tabout, ".nr #T 0-1\n");
+ deftail();
+ for(i=0; i<nlin; i++)
+ putline(i,i);
+ if (leftover)
+ if (yetmore())
+ return -1;
+ fprintf(tabout, ".fc\n");
+ fprintf(tabout, ".nr T. 1\n");
+ fprintf(tabout, ".T# 1\n");
+ if (ctrflg)
+ fprintf(tabout, ".in \\n(#Iu\n");
+ return 0;
+}
+
+void
+runtabs(int lform, int ldata)
+{
+ int c, ct, vforml, lf;
+ fprintf(tabout, ".ta ");
+ for(c=0; c<ncol; c++)
+ {
+ vforml=lform;
+ for (lf=prev(lform); lf>=0 && vspen(table[lf][c].col);
+ lf=prev(lf))
+ vforml=lf;
+ if (fspan(vforml,c))
+ continue;
+ switch(ct=ctype(vforml,c))
+ {
+ case 'n':
+ case 'a':
+ if (table[ldata][c].rcol)
+ if (lused[c]) /*Zero field width*/
+ fprintf(tabout, "\\n(%du ",c+CMID);
+ case 'c':
+ case 'l':
+ case 'r':
+ if (realsplit? rused[c]: (used[c]+lused[c]))
+ fprintf(tabout, "\\n(%du ",c+CRIGHT);
+ continue;
+ case 's':
+ if (lspan(lform, c))
+ fprintf(tabout, "\\n(%du ", c+CRIGHT);
+ continue;
+ }
+ }
+ fprintf(tabout, "\n");
+}
+
+int
+ifline(char *s) {
+ if (!point((intptr_t)s) || !*s)
+ return 0;
+ if (*s == '\\')
+ s++;
+ if (s[1])
+ return 0;
+ if (*s == '_')
+ return '-';
+ if (*s == '=')
+ return '=';
+ return 0;
+}
+
+void
+need(void)
+{
+ int texlin, horlin, i;
+
+ for(texlin = horlin = i = 0; i < nlin; i++) {
+ if (allh(i))
+ horlin++;
+ else if (instead[i] != 0)
+ continue;
+ else
+ texlin++;
+ }
+ /*
+ * For nroff runs, we need to reserve space for the full height of the
+ * horizontal rules. If we don't reserve sufficient height, we'll have
+ * problems trying to draw the vertical lines across the page boundary.
+ */
+ (void) fprintf(tabout, ".ie n .ne %dv\n", 2 * texlin + 2 * horlin + 2);
+ (void) fprintf(tabout, ".el .ne %dv\n", texlin + 1);
+}
+
+void
+deftail(void)
+{
+ int i, c, lf, lwid;
+ for(i=0; i<MAXHEAD; i++)
+ if (linestop[i])
+ fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
+ fprintf(tabout, ".nr #a 0-1\n");
+ fprintf(tabout, ".eo\n");
+ fprintf(tabout, ".de T# 00\n");
+ fprintf(tabout, ".ds #d .d\n");
+ fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
+ fprintf(tabout, ".mk ##\n");
+ fprintf(tabout, ".nr ## -1v\n");
+ if (graphics)
+ svgraph();
+ fprintf(tabout, ".ls 1\n");
+ for(i=0; i<MAXHEAD; i++)
+ if (linestop[i])
+ fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
+ if (boxflg || allflg || dboxflg) { /* bottom of table line */
+ if (!nflm)
+ fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
+ fprintf(tabout, ".if \\n(T. ");
+ drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
+ fprintf(tabout, "\n");
+ if (!nflm)
+ fprintf(tabout, ".if \\n(T. .vs\n");
+ /* T. is really an argument to a macro but because of
+ eqn we don't dare pass it as an argument and reference by $1 */
+ }
+ if (!(utf8 || tlp)) {
+ for(c=0; c<ncol; c++)
+ {
+ if (nlin>0 && (lf=left(nlin-1,c, &lwid))>=0)
+ {
+ fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
+ fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
+ tohcol(c);
+ drawvert(lf, nlin-1, c, lwid);
+ fprintf(tabout, "\\h'|\\n(TWu'\n");
+ }
+ }
+ if (boxflg || allflg || dboxflg) /* right hand line */
+ {
+ fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
+ fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
+ drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
+ fprintf(tabout, "\n");
+ }
+ }
+ fprintf(tabout, ".ls\n");
+ fprintf(tabout, ".00\n");
+ fprintf(tabout, ".ec\n");
+}
diff --git a/tbl/t8.c b/tbl/t8.c
new file mode 100644
index 0000000000000..2fe8b352b5b66
--- /dev/null
+++ b/tbl/t8.c
@@ -0,0 +1,425 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "t8.c 1.6 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ * Portions Copyright (c) 2015 Carsten Kunze
+ *
+ * Sccsid @(#)t8.c 1.12 (gritter) 10/2/07
+ */
+
+ /* t8.c: write out one line of output table */
+# include "t..c"
+# include <inttypes.h>
+# define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
+int watchout;
+int once;
+void
+putline (
+ /* i is line number for deciding format */
+ /* nl is line number for finding data usually identical */
+ int i,
+ int nl
+)
+ /* i is line number for deciding format */
+ /* nl is line number for finding data usually identical */
+{
+ int c, lf, ct, form, lwid, vspf, ip = -1, cmidx = 0, exvspen, vforml;
+ int vct, chfont;
+ char *s, *size, *fn;
+ char space[40];
+ watchout=vspf=exvspen=0;
+ if (graphics)
+ svgraph();
+ if (i==0) once=0;
+ if (i==0 && ( allflg || boxflg || dboxflg))
+ {
+ fullwide(0, dboxflg? '=' : '-');
+ }
+ if (instead[nl]==0 && fullbot[nl] ==0)
+ for(c=0; c<ncol; c++)
+ {
+ s = table[nl][c].col;
+ if (s==0) continue;
+ if (vspen(s))
+ {
+ for(ip=nl; ip<nlin; ip=next(ip))
+ if (!vspen(s=table[ip][c].col)) break;
+ if (s!=(char *)0 && !point((intptr_t)s))
+ fprintf(tabout, ".ne %su+\\n(.Vu\n",
+ nreg(space, sizeof(space), s,
+ '|'));
+ continue;
+ }
+ if (point((intptr_t)s)) continue;
+ fprintf(tabout, ".ne %su+\\n(.Vu\n",
+ nreg(space, sizeof(space), s, '|'));
+ watchout=1;
+ }
+ if (linestop[nl])
+ fprintf(tabout, ".mk #%c\n", linestop[nl]+'a'-1);
+ lf = prev(nl);
+ if (instead[nl])
+ {
+ puts(instead[nl]);
+ return;
+ }
+ if (fullbot[nl])
+ {
+ switch (ct=fullbot[nl])
+ {
+ case '=':
+ case '-':
+ fullwide(nl,ct);
+ }
+ return;
+ }
+ for(c=0; c<ncol; c++)
+ {
+ if (instead[nl]==0 && fullbot[nl]==0)
+ if (vspen(table[nl][c].col)) vspf=1;
+ if (lf>=0)
+ if (vspen(table[lf][c].col)) vspf=1;
+ }
+ if (vspf)
+ {
+ fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
+ fprintf(tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
+ }
+ vspf=0;
+ chfont=0;
+ for(c=0; c<ncol; c++)
+ {
+ s = table[nl][c].col;
+ if (s==0) continue;
+ chfont |= (intptr_t)(font[stynum[nl]][c]);
+ if (point((intptr_t)s) ) continue;
+ lf=prev(nl);
+ nreg(space, sizeof(space), s, '|');
+ warnoff();
+ if (lf>=0 && vspen(table[lf][c].col))
+ fprintf(tabout, ".if (%s+\\n(^%c-1v)>\\n(#- .nr #- +(%s+\\n(^%c-\\n(#--1v)\n",space,'a'+c,space,'a'+c);
+ else
+ fprintf(tabout, ".if (%s+\\n(#^-1v)>\\n(#- .nr #- +(%s+\\n(#^-\\n(#--1v)\n",space,space);
+ }
+ warnon();
+ if (allflg && once>0 )
+ fullwide(i,'-');
+ once=1;
+ runtabs(i, nl);
+ if (allh(nl) && !nflm)
+ {
+ fprintf(tabout, ".nr %d \\n(.v\n", SVS);
+ fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
+ }
+ if (chfont)
+ fprintf(tabout, ".nr %2d \\n(.f\n", S1);
+ fprintf(tabout, ".nr 35 1m\n");
+ if ((utf8 || tlp) && (boxflg || allflg || dboxflg)) { /* right hand line */
+ fprintf(tabout, "\\h'|\\n(TWu'");
+ fprintf(tabout, "%s", tlp ? "|" :
+ dboxflg ? "\\U'2551'" : /* ║ */
+ "\\U'2502'"); /* │ */
+ }
+ fprintf(tabout, "\\&");
+ vct = 0;
+ for(c=0; c<ncol; c++)
+ {
+ if (utf8 || tlp) {
+ char *s = table[nl][c ? c-1 : 0].col;
+ if ((lwid = lefdata(i, c)) && (!ifline(s) ||
+ *s == '\\')) {
+ tohcol(c);
+ fprintf(tabout, "%s",
+ tlp ? "|" :
+ lwid == 2 ? "\\U'2551'" : /* ║ */
+ "\\U'2502'"); /* │ */
+ vct += 2;
+ }
+ } else
+ if (watchout==0 && i+1<nlin && (lf=left(i,c, &lwid))>=0)
+ {
+ tohcol(c);
+ drawvert(lf, i, c, lwid);
+ vct += 2;
+ }
+ if (rightl && c+1==ncol) continue;
+ vforml=i;
+ for(lf=prev(nl); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
+ vforml= lf;
+ form= ctype(vforml,c);
+ if (form != 's')
+ {
+ ct = c+CLEFT;
+ if (form=='a') ct = c+CMID;
+ if (form=='n' && table[nl][c].rcol && lused[c]==0) ct= c+CMID;
+ fprintf(tabout, "\\h'|\\n(%du'", ct);
+ }
+ s= table[nl][c].col;
+ fn = font[stynum[vforml]][c];
+ size = csize[stynum[vforml]][c];
+ if (*size==0)size=0;
+ switch(ct=ctype(vforml, c))
+ {
+ case 'n':
+ case 'a':
+ if (table[nl][c].rcol)
+ {
+ if (lused[c]) /*Zero field width*/
+ {
+ ip = prev(nl);
+ if (ip>=0)
+ if (vspen(table[ip][c].col))
+ {
+ if (exvspen==0)
+ {
+ fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
+ if (cmidx)
+ fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
+ vct++;
+ fprintf(tabout, ")'");
+ exvspen=1;
+ }
+ }
+ fprintf(tabout, "%c%c",F1,F2);
+ puttext(s,fn,size);
+ fprintf(tabout, "%c",F1);
+ }
+ s= table[nl][c].rcol;
+ form=1;
+ break;
+ }
+ case 'c':
+ form=3; break;
+ case 'r':
+ form=2; break;
+ case 'l':
+ form=1; break;
+ case '-':
+ case '=':
+ if (real(table[nl][c].col))
+ fprintf(stderr,"%s: line %d: Data ignored on table line %d\n", ifile, iline-1, i+1);
+ makeline(i,c,ct);
+ continue;
+ default:
+ continue;
+ }
+ if (realsplit ? rused[c]: used[c]) /*Zero field width*/
+ {
+ /* form: 1 left, 2 right, 3 center adjust */
+ if (ifline(s))
+ {
+ makeline(i,c,ifline(s));
+ continue;
+ }
+ if (filler(s))
+ {
+ printf("\\l'|\\n(%du\\&%s'", c+CRIGHT, s+2);
+ continue;
+ }
+ ip = prev(nl);
+ cmidx = ctop[stynum[nl]][c]==0;
+ if (ip>=0)
+ if (vspen(table[ip][c].col))
+ {
+ if (exvspen==0)
+ {
+ fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
+ if (cmidx)
+ fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
+ vct++;
+ fprintf(tabout, ")'");
+ }
+ }
+ fprintf(tabout, "%c", F1);
+ if (form!= 1)
+ fprintf(tabout, "%c", F2);
+ if (vspen(s))
+ vspf=1;
+ else
+ puttext(s, fn, size);
+ if (form !=2)
+ fprintf(tabout, "%c", F2);
+ fprintf(tabout, "%c", F1);
+ }
+ if (ip>=0)
+ {
+ if (vspen(table[ip][c].col))
+ {
+ exvspen = (c+1 < ncol) && vspen(table[ip][c+1].col) &&
+ (topat[c] == topat[c+1]) &&
+ (cmidx == (ctop [stynum[nl]][c+1]==0)) && (left(i,c+1,&lwid)<0);
+ if (exvspen==0)
+ {
+ fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c+'a');
+ if (cmidx)
+ fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
+ vct++;
+ fprintf(tabout, ")'");
+ }
+ }
+ else
+ exvspen=0;
+ }
+ /* if lines need to be split for gcos here is the place for a backslash */
+ if (vct > 7 && c < ncol)
+ {
+ fprintf(tabout, "\n.sp -1\n\\&");
+ vct=0;
+ }
+ }
+ fprintf(tabout, "\n");
+ if (allh(nl) && !nflm) fprintf(tabout, ".vs \\n(%du\n", SVS);
+ if (watchout)
+ funnies(i,nl);
+ if (vspf)
+ {
+ for(c=0; c<ncol; c++)
+ if (vspen(table[nl][c].col) && (nl==0 || (lf=prev(nl))<0 || !vspen(table[lf][c].col)))
+ {
+ fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a'+c);
+ topat[c]=nl;
+ }
+ }
+}
+void
+puttext(char *s, char *fn, char *size)
+{
+ if (point((intptr_t)s))
+ {
+ putfont(fn);
+ putsize(size);
+ fprintf(tabout, "%s",s);
+ if (*fn>0) fprintf(tabout, "\\f\\n(%2d", S1);
+ if (size!=0) putsize("0");
+ }
+}
+void
+funnies(int stl, int lin)
+{
+ /* write out funny diverted things */
+ int c, pl, lwid, dv, lf, ct = 0;
+ intptr_t s;
+ char *fn;
+ char space[40];
+ fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
+ fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
+ for(c=0; c<ncol; c++)
+ {
+ s = (intptr_t)table[lin][c].col;
+ if (point(s)) continue;
+ if (s==0) continue;
+ fprintf(tabout, ".sp |\\n(##u-1v\n");
+ fprintf(tabout, ".nr %d ", SIND);
+ for(pl=stl; pl>=0 && !isalpha(ct=ctype(pl,c)); pl=prev(pl))
+ ;
+ switch (ct)
+ {
+ case 'n':
+ case 'c':
+ fprintf(tabout, "(\\n(%du+\\n(%du-%su)/2u\n",
+ c + CLEFT, c - 1 + ctspan(lin, c) + CRIGHT,
+ nreg(space, sizeof(space), (char *)s, '-'));
+ break;
+ case 'l':
+ fprintf(tabout, "\\n(%du\n",c+CLEFT);
+ break;
+ case 'a':
+ fprintf(tabout, "\\n(%du\n",c+CMID);
+ break;
+ case 'r':
+ fprintf(tabout, "\\n(%du-%su\n", c + CRIGHT,
+ nreg(space, sizeof(space), (char *)s, '-'));
+ break;
+ }
+ fprintf(tabout, ".in +\\n(%du\n", SIND);
+ fn=font[stynum[stl]][c];
+ putfont(fn);
+ pl = prev(stl);
+ if (stl>0 && pl>=0 && vspen(table[pl][c].col))
+ {
+ fprintf(tabout, ".sp |\\n(^%cu\n", 'a'+c);
+ if (ctop[stynum[stl]][c]==0)
+ {
+ fprintf(tabout,
+ ".nr %d \\n(#-u-\\n(^%c-%s+1v\n", TMP,
+ 'a' + c, nreg(space, sizeof(space),
+ (char *)s, '|'));
+ fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u\n", TMP, TMP);
+ }
+ }
+ if (s<128)
+ fprintf(tabout, ".%c+\n",(int)s);
+ else
+ fprintf(tabout, ".do %ld+\n",s);
+ fprintf(tabout, ".in -\\n(%du\n", SIND);
+ if (*fn>0) putfont("P");
+ fprintf(tabout, ".mk %d\n", S2);
+ fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
+ }
+ fprintf(tabout, ".sp |\\n(%du\n", S1);
+ for(c=dv=0; c<ncol; c++)
+ {
+ if (utf8 || tlp) {
+ if ((lwid = lefdata(stl,c))) {
+ if (!dv++)
+ fprintf(tabout, ".sp -1\n");
+ tohcol(c);
+ dv++;
+ fprintf(tabout,
+ "\\L'-(\\n(%du-\\n(##u)%s'", S1,
+ tlp ? "|" :
+ lwid == 2 ? "\\U'2551'" : /* ║ */
+ "\\U'2502'"); /* │ */
+ fprintf(tabout, "\\v'\\n(%du-\\n(##u'", S1);
+ }
+ } else
+ if (stl+1< nlin && (lf=left(stl,c,&lwid))>=0)
+ {
+ if (dv++ == 0)
+ fprintf(tabout, ".sp -1\n");
+ tohcol(c);
+ dv++;
+ drawvert(lf, stl, c, lwid);
+ }
+ }
+ if ((utf8 || tlp) && (allflg || boxflg || dboxflg)) {
+ if (!dv++)
+ fprintf(tabout, ".sp -1\n");
+ fprintf(tabout, "\\h'|\\n(TWu'");
+ fprintf(tabout,
+ "\\L'-(\\n(%du-\\n(##u)%s'", S1,
+ tlp ? "|" :
+ lwid == 2 ? "\\U'2551'" : /* ║ */
+ "\\U'2502'"); /* │ */
+ fprintf(tabout, "\\v'\\n(%du-\\n(##u'", S1);
+ }
+ if (dv)
+ fprintf(tabout,"\n");
+}
+void
+putfont(char *fn)
+{
+ if (fn && *fn)
+ fprintf(tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn);
+}
+void
+putsize(char *s)
+{
+ if (s && *s)
+ fprintf(tabout, "\\s%s",s);
+}
diff --git a/tbl/t9.c b/tbl/t9.c
new file mode 100644
index 0000000000000..924cd94b9b350
--- /dev/null
+++ b/tbl/t9.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 1983-2003 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/* from OpenSolaris "t9.c 1.6 05/06/02 SMI" */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)t9.c 1.7 (gritter) 2/26/06
+ */
+
+ /* t9.c: write lines for tables over MAXLIN lines */
+# include "t..c"
+
+static int useln;
+
+int
+yetmore(void) {
+ size_t linesize = MAXSTR;
+ int i;
+ for(useln=0; useln<MAXLIN && table[useln]==0; useln++);
+ if (useln>=MAXLIN)
+ return error("Weird. No data in table.");
+ table[0]=table[useln];
+ for(useln=nlin-1; useln>=0 && (fullbot[useln] || instead[useln]);
+ useln--);
+ if (useln<0)
+ return error("Weird. No real lines in table.");
+ if (domore(leftover) == -1)
+ return -1;
+ while (gets1(&cbase, &cspace, &linesize) && (cstore=cspace) &&
+ (i = domore(cstore)))
+ if (i == -1)
+ return -1;
+ last =cstore;
+ return 0;
+}
+
+int
+domore(char *dataln) {
+ int icol, ch;
+ if (cprefix("TE", dataln))
+ return(0);
+ if (dataln[0] == '.' && !isdigit((unsigned char)dataln[1])) {
+ puts(dataln);
+ return(1);
+ }
+ instead[0]=0;
+ fullbot[0]=0;
+ if (dataln[1]==0)
+ switch(dataln[0]) {
+ case '_': fullbot[0]= '-'; putline(useln,0); return(1);
+ case '=': fullbot[0]= '='; putline(useln, 0); return(1);
+ }
+ for (icol = 0; icol <ncol; icol++) {
+ table[0][icol].col = dataln;
+ table[0][icol].rcol=0;
+ for(; (ch= *dataln) != '\0' && ch != tab; dataln++)
+ ;
+ *dataln++ = '\0';
+ switch(ctype(useln,icol)) {
+ case 'n':
+ if ((table[0][icol].rcol = maknew(table[0][icol].col))
+ == (char *)-1)
+ return -1;
+ break;
+ case 'a':
+ table[0][icol].rcol = table[0][icol].col;
+ table[0][icol].col= "";
+ break;
+ }
+ while (ctype(useln,icol+1)== 's') /* spanning */
+ table[0][++icol].col = "";
+ if (ch == '\0') break;
+ }
+ while (++icol <ncol)
+ table[0][icol].col = "";
+ putline(useln,0);
+ return(1);
+}
diff --git a/tbl/tb.c b/tbl/tb.c
new file mode 100644
index 0000000000000..5a4a975ec9d7c
--- /dev/null
+++ b/tbl/tb.c
@@ -0,0 +1,154 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tb.c 1.5 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tb.c 1.7 (gritter) 9/8/06
+ */
+
+ /* tb.c: check which entries exist, also storage allocation */
+# include "t..c"
+# include <stdlib.h>
+# include <string.h>
+# include <inttypes.h>
+void
+checkuse(void)
+{
+int i,c, k;
+for(c=0; c<ncol; c++)
+ {
+ used[c]=lused[c]=rused[c]=0;
+ for(i=0; i<nlin; i++)
+ {
+ if (instead[i] || fullbot[i]) continue;
+ k = ctype(i,c);
+ if (k== '-' || k == '=') continue;
+ if ((k=='n'||k=='a'))
+ {
+ rused[c]|= real(table[i][c].rcol);
+ if( !real(table[i][c].rcol))
+ used[c] |= real(table[i][c].col);
+ if (table[i][c].rcol)
+ lused[c] |= real(table[i][c].col);
+ }
+ else
+ used[c] |= real(table[i][c].col);
+ }
+ }
+}
+int
+real(char *s)
+{
+if (s==0) return(0);
+if (!point((intptr_t)s)) return(1);
+if (*s==0) return(0);
+return(1);
+}
+int spcount = 0;
+int maxvec = 0;
+char **spvecs;
+
+char *
+chspace(void) {
+ char *pp;
+ int n;
+ if (spcount>=maxvec) {
+ n = maxvec + 20;
+ spvecs = realloc(spvecs, n * sizeof *spvecs);
+ if (spvecs == NULL) {
+ error("Too many characters in table");
+ return NULL;
+ }
+ do
+ spvecs[maxvec] = 0;
+ while (++maxvec < n);
+ }
+ if (spvecs[spcount])
+ return(spvecs[spcount++]);
+ spvecs[spcount++]= pp = calloc(MAXCHS+MAXSTR,1);
+ if (pp == 0) {
+ error("no space for characters");
+ return NULL;
+ }
+ return(pp);
+}
+
+void
+updspace(char *old, char *new, int area)
+{
+int i, j, d = new - old;
+for (i = 0; i < spcount; i++)
+ if (spvecs[i] == old) {
+ spvecs[i] = new;
+ for (i = 0; i < nlin; i++) {
+ if (instead[i] >= old && instead[i] < &old[area])
+ instead[i] += d;
+ if (table[i])
+ for (j = 0; j <= ncol; j++)
+ if (table[i][j].col >= old &&
+ table[i][j].col < &old[area])
+ table[i][j].col += d;
+ }
+ if (leftover >= old && leftover < &old[area])
+ leftover += d;
+ break;
+ }
+}
+
+static int MAXPC;
+char *thisvec;
+int tpcount = -1;
+char **tpvecs;
+
+struct colstr *
+alocv(int n) {
+ int *tp, *q;
+ if (tpcount<0 || thisvec+n > tpvecs[tpcount]+MAXCHS) {
+ tpcount++;
+ if (tpcount >= MAXPC) {
+ tpvecs = realloc(tpvecs, (tpcount+1) * sizeof *tpvecs);
+ if (tpvecs == 0) goto nospace;
+ memset(&tpvecs[MAXPC], 0, (tpcount+1-MAXPC) * sizeof *tpvecs);
+ MAXPC = tpcount+1;
+ }
+ if (tpvecs[tpcount]==0) {
+ tpvecs[tpcount] = calloc(MAXCHS,1);
+ }
+ thisvec = tpvecs[tpcount];
+ if (thisvec == 0) {
+nospace:
+ error("no space for vectors");
+ return (struct colstr *)-1;
+ }
+ }
+ tp=(int *)thisvec;
+ thisvec+=n;
+ for(q=tp; q<(int *)thisvec; q++)
+ *q=0;
+ return (struct colstr *)tp;
+}
+
+void
+release(void)
+{
+extern char *exstore;
+/* give back unwanted space in some vectors */
+spcount=0;
+tpcount= -1;
+exstore=0;
+}
diff --git a/tbl/tbl.1 b/tbl/tbl.1
new file mode 100644
index 0000000000000..c6a09db59e2f5
--- /dev/null
+++ b/tbl/tbl.1
@@ -0,0 +1,187 @@
+'\" t
+.\" Sccsid @(#)tbl.1b 1.7 (gritter) 9/9/06
+.\" Derived from tbl(1), Unix 7th edition:
+.\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" Redistributions of source code and documentation must retain the
+.\" above copyright notice, this list of conditions and the following
+.\" disclaimer.
+.\" Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed or owned by Caldera
+.\" International, Inc.
+.\" Neither the name of Caldera International, Inc. nor the names of
+.\" other contributors may be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
+.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.Dd March 2, 2015
+.Dt TBL 1 "Heirloom Documentation Tools"
+.Sh NAME
+.Nm tbl
+.Nd format tables for nroff or troff
+.Sh SYNOPSIS
+.Nm
+.Op Fl g | Fl T Ar name
+.Op Fl me | Fl mm | Fl ms
+.Op Ar
+.Sh DESCRIPTION
+.Nm
+is a preprocessor for formatting tables for
+.Xr nroff
+or
+.Xr troff .
+The input files are copied to the standard output,
+except for lines between
+.Li .TS
+and
+.Li .TE
+command lines, which are assumed to describe tables
+and reformatted.
+Arbitrary whitespace can be inserted between the dot and the commands
+.Li .TS
+or
+.Li .TE .
+Macros with these names are ignored by tbl if
+.Sq '
+is used instead of
+.Sq \&. .
+.Sh OPTIONS
+.Bl -tag -width ".Fl T Ar name"
+.It Fl g
+.Nm
+normally uses line drawing commands with repeated
+underline and box rule characters
+(\el and \eL).
+With the
+.Fl g
+option,
+graphic drawing commands (\eD) are used instead.
+(This should only be used when processing troff input.)
+Option
+.Fl g
+overrides a previous
+.Fl T Ar name .
+.It Fl me | mm | ms
+With these options the respective macro packages
+are copied to the beginning of the output.
+Details are given in the reference manual.
+.It Fl T Ar name
+Configure nroff input processing.
+.Ar name
+can be one of:
+. Bl -tag -width ".Cm locale"
+. It Cm locale
+If
+. Nm
+is used to process nroff input in an UTF-8 locale and
+. Fl Tlocale
+is given lines are printed using Unicode box characters
+instead of underline and box rule characters.
+If the current locale does not support UTF-8 this Option
+has the same effect as
+. Fl Tlp .
+Option
+. Fl Tlocale
+overrides a previous
+. Fl g .
+. It Cm lp
+Use ASCII characters (\-, =, |, +)
+instead of underline and box rule characters.
+Overrides a previous
+. Fl g .
+. It Cm X
+The
+. Fl TX
+option causes
+. Nm
+not to produce fractional line motions.
+. El
+.El
+.Sh "EXTENSIONS TO THE AT&T TBL KEY LETTERS
+.Bl -tag -width ".Cm x , X"
+.It Cm x , X
+Expand column to make table as wide as the current line length.
+If there is more then one column with a x specifier these
+columns are expanded by the same amount.
+This feature had been a GNU tbl extension.
+.El
+.Sh EXAMPLE
+As an example, letting \(rst represent a tab (which should
+be typed as a genuine tab)
+the input
+.Bd -unfilled -literal -offset indent
+\&.TS
+c s s
+c c s
+c c c
+l n n.
+Household Population
+Town\\tHouseholds
+\\tNumber\\tSize
+Bedminster\\t789\\t3.26
+Bernards Twp.\\t3087\\t3.74
+Bernardsville\\t2018\\t3.30
+Bound Brook\\t3425\\t3.04
+Branchburg\\t1644\\t3.49
+Bridgewater\\t7897\\t3.81
+Far Hills\\t240\\t3.19
+\&.TE
+.Ed
+.Pp
+yields
+.Pp
+.TS
+c s s
+c c s
+c c c
+l n n.
+Household Population
+Town Households
+ Number Size
+Bedminster 789 3.26
+Bernards Twp. 3087 3.74
+Bernardsville 2018 3.30
+Bound Brook 3425 3.04
+Branchburg 1644 3.49
+Bridgewater 7897 3.81
+Far Hills 240 3.19
+.TE
+.Pp
+If no arguments are given,
+.Nm
+reads the standard input,
+so it may be used as a filter.
+When it is used with
+.Xr eqn
+or
+.Xr neqn
+the
+.Nm
+command should be first, to minimize the volume
+of data passed through
+pipes.
+.Sh SEE ALSO
+.Xr troff 1 ,
+.Xr eqn 1
+.Rs
+.%A "M. E. Lesk"
+.%T TBL
+.Re
diff --git a/tbl/tc.c b/tbl/tc.c
new file mode 100644
index 0000000000000..02a91f733dbca
--- /dev/null
+++ b/tbl/tc.c
@@ -0,0 +1,87 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tc.c 1.5 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tc.c 1.5 (gritter) 10/15/05
+ */
+
+ /* tc.c: find character not in table to delimit fields */
+# include "t..c"
+# include <inttypes.h>
+
+int
+choochar(void) {
+ /* choose funny characters to delimit fields */
+ int had[128], ilin, icol, k;
+ char *s;
+ for(icol=0; icol<128; icol++)
+ had[icol]=0;
+ F1 = F2 = 0;
+ for(ilin=0;ilin<nlin;ilin++) {
+ if (instead[ilin]) continue;
+ if (fullbot[ilin]) continue;
+ for(icol=0; icol<ncol; icol++) {
+ k = ctype(ilin, icol);
+ if (k==0 || k == '-' || k == '=')
+ continue;
+ s = table[ilin][icol].col;
+ if (point((intptr_t)s))
+ while (*s) {
+ if (*s > 0 && *(unsigned char *)s <= 127)
+ had[(int)*s++]=1;
+ else
+ s++;
+ }
+ s=table[ilin][icol].rcol;
+ if (point((intptr_t)s))
+ while (*s) {
+ if (*s > 0 && *(unsigned char *)s <= 127)
+ had[(int)*s++]=1;
+ else
+ s++;
+ }
+ }
+ }
+ /* choose first funny character */
+ for(s="\002\003\005\006\007!%&#/?,:;<=>@`^~_{}+-*ABCDEFGHIJKMNOPQRSTUVWXYZabcdefgjkoqrstwxyz";
+ *s; s++) {
+ if (had[(int)*s]==0) {
+ F1= *s;
+ had[F1]=1;
+ break;
+ }
+ }
+ /* choose second funny character */
+ for(s="\002\003\005\006\007:_~^`@;,<=>#%&!/?{}+-*ABCDEFGHIJKMNOPQRSTUVWXZabcdefgjkoqrstuwxyz";
+ *s; s++) {
+ if (had[(int)*s]==0) {
+ F2= *s;
+ break;
+ }
+ }
+ if (F1==0 || F2==0)
+ return error(
+ "couldn't find characters to use for delimiters");
+ return 0;
+}
+
+int
+point(int s) {
+ return s >= 4096 || s < 0;
+}
diff --git a/tbl/te.c b/tbl/te.c
new file mode 100644
index 0000000000000..061aa2df3b346
--- /dev/null
+++ b/tbl/te.c
@@ -0,0 +1,122 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright 1983-1988,2003 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* from OpenSolaris "te.c 1.6 05/06/02 SMI" */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)te.c 1.13 (gritter) 8/6/06
+ */
+
+ /* te.c: error message control, input line count */
+# include "t..c"
+# include <errno.h>
+# include <string.h>
+# include <stdlib.h>
+
+int
+error(char *s) {
+ fprintf(stderr, "\n%s: line %d: %s\n", ifile, iline, s);
+ fprintf(stderr, "%s quits\n", progname);
+ return -1;
+}
+
+char *
+errmsg(int errnum)
+{
+ return (strerror(errnum));
+}
+char *
+gets1(char **bp, char **sp, size_t *zp)
+{
+char *s, *p = 0;
+int c, n = 0;
+int nbl;
+for (;;)
+ {
+ iline++;
+ for (;;)
+ {
+ if (n + MAXCHS >= *zp)
+ {
+ int oz = *zp;
+ *zp = n + MAXCHS + 128;
+ if ((p = realloc(*bp, *zp))==NULL)
+ error("Line too long");
+ updspace(*bp, p, oz);
+ *sp += p - *bp;
+ *bp = p;
+ }
+ if ((c = getc(tabin))==EOF)
+ {
+ if (ferror(tabin))
+ error(errmsg(errno));
+ if (swapin()==0)
+ return(0);
+ iline++;
+ continue;
+ }
+ if (c=='\n')
+ {
+ p = *sp;
+ s = n ? &(*sp)[n-1] : *sp;
+ (*sp)[n] = '\0';
+ break;
+ }
+ (*sp)[n++] = c;
+ }
+ for(nbl=0; *s == '\\' && s>p; s--)
+ nbl++;
+ if (linstart && nbl % 2) /* fold escaped nl if in table */
+ {
+ n--;
+ continue;
+ }
+ break;
+ }
+
+return(p);
+}
+# define BACKMAX 500
+char backup[BACKMAX];
+char *backp = backup;
+void
+un1getc(int c)
+{
+if (c=='\n')
+ iline--;
+*backp++ = c;
+if (backp >= backup+BACKMAX)
+ error("too much backup");
+}
+int
+get1char(void)
+{
+int c;
+if (backp>backup)
+ c = *--backp;
+else
+ c=getc(tabin);
+if (c== EOF) /* EOF */
+ {
+ if (swapin() ==0)
+ error("unexpected EOF");
+ c = getc(tabin);
+ }
+if (c== '\n')
+ iline++;
+return(c);
+}
diff --git a/tbl/tf.c b/tbl/tf.c
new file mode 100644
index 0000000000000..5deee8629096f
--- /dev/null
+++ b/tbl/tf.c
@@ -0,0 +1,109 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tf.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tf.c 1.9 (gritter) 9/9/06
+ */
+
+ /* tf.c: save and restore fill mode around table */
+# include "t..c"
+void
+savefill(void)
+{
+/* remembers various things: fill mode, vs, ps in mac 35 (SF) */
+fprintf(tabout, ".de %d 00\n",SF);
+fprintf(tabout, ".ps \\n(.s\n");
+fprintf(tabout, ".vs \\n(.vu\n");
+fprintf(tabout, ".in \\n(.iu\n");
+fprintf(tabout, ".if \\n(.u .fi\n");
+fprintf(tabout, ".if \\n(.j .ad\n");
+fprintf(tabout, ".if \\n(.j=0 .na\n");
+fprintf(tabout, ".00\n");
+fprintf(tabout, ".nf\n");
+/* set obx offset if useful */
+fprintf(tabout, ".nr #~ 0\n");
+fprintf(tabout, ".if n .nr #~ 0.6n\n");
+}
+void
+rstofill(void)
+{
+fprintf(tabout, ".%d\n",SF);
+}
+void
+endoff(void)
+{
+int i;
+ warnoff();
+ for(i=0; i<MAXHEAD; i++)
+ if (linestop[i])
+ fprintf(tabout, ".nr #%c 0\n", 'a'+i);
+ for(i=0; i<texct; i++)
+ fprintf(tabout, ".rm %c+\n",texstr[i]);
+ for(i=300; i<=texct2; i++)
+ fprintf(tabout, ".do rm %d+\n",i);
+ warnon();
+fprintf(tabout,".lf %d %s\n", iline - 1, ifile);
+fprintf(tabout, "%s\n", last);
+}
+void
+ifdivert(void)
+{
+fprintf(tabout, ".ds #d .d\n");
+fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
+}
+void
+saveline(void)
+{
+fprintf(tabout,".lf 2 table-at-line-%d-of-%s\n", iline-1, ifile);
+fprintf(tabout, ".de 00\n..\n");
+fprintf(tabout, ".do nr w. \\n[.warn]\n");
+warnoff();
+fprintf(tabout, ".if \\n+(b.=1 .nr d. \\n(.c-\\n(c.-1\n");
+warnon();
+linstart=iline;
+}
+void
+restline(void)
+{
+warnoff();
+fprintf(tabout,".if \\n-(b.=0 .nr c. \\n(.c-\\n(d.-%d\n", iline-linstart);
+warnon();
+fprintf(tabout,".lf %d %s\n", iline, ifile);
+linstart = 0;
+}
+void
+cleanfc(void)
+{
+fprintf(tabout, ".fc\n");
+}
+void
+warnoff(void)
+{
+fprintf(tabout, ".if \\n(.X>0 .do warn -mac -reg\n");
+}
+void
+warnon(void)
+{
+fprintf(tabout, ".if \\n(.X>0 .do warn \\n(w.\n");
+}
+void
+svgraph(void)
+{
+fprintf(tabout, ".nr #D .2m\n");
+}
diff --git a/tbl/tg.c b/tbl/tg.c
new file mode 100644
index 0000000000000..3b65254aa29a9
--- /dev/null
+++ b/tbl/tg.c
@@ -0,0 +1,127 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tg.c 1.6 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tg.c 1.10 (gritter) 10/2/07
+ */
+
+ /* tg.c: process included text blocks */
+# include "t..c"
+# include <stdlib.h>
+# include <inttypes.h>
+
+/* get_text was originally gettext and was renamed */
+char *
+get_text(char *sp, int ilin, int icol, char *fn, char *sz)
+{
+ /* get a section of text */
+ char *line = NULL;
+ size_t linesize = 0;
+ char *oname;
+ char *vs;
+ if (texname==0) texct2 = texname = 300;
+ if (texct2>0 && point(texct2)) {
+ error("Too many text block diversions");
+ return (char *)-1;
+ }
+ if (textflg==0)
+ {
+ fprintf(tabout, ".nr %d \\n(.lu\n", SL); /* remember old line length */
+ textflg=1;
+ }
+ fprintf(tabout, ".eo\n");
+ fprintf(tabout, ".am %02d 00\n", icol+80);
+ fprintf(tabout, ".br\n");
+ if (texct2 < 0)
+ fprintf(tabout, ".di %c+\n", (int)texname);
+ else
+ fprintf(tabout, ".do di %d+\n", texct2);
+ rstofill();
+ if (fn && *fn) fprintf(tabout, ".nr %d \\n(.f\n.ft %s\n", S1, fn);
+ fprintf(tabout, ".ft \\n(.f\n"); /* protect font */
+ vs = vsize[stynum[ilin]][icol];
+ if ((sz && *sz) || (vs && *vs))
+ {
+ fprintf(tabout, ".nr %d \\n(.v\n", S2);
+ if (vs==0 || *vs==0) vs= "\\n(.s+2";
+ if (sz && *sz)
+ fprintf(tabout, ".ps %s\n",sz);
+ fprintf(tabout, ".vs %s\n",vs);
+ fprintf(tabout, ".if \\n(%du>\\n(.vu .sp \\n(%du-\\n(.vu\n", S2,S2);
+ }
+ if (cll[icol][0])
+ fprintf(tabout, ".ll %sn\n", cll[icol]);
+ else
+ fprintf(tabout, ".ll \\n(%du*%du/%du\n",SL,ctspan(ilin,icol),ncol+1);
+ fprintf(tabout,".if \\n(.l<\\n(%d .ll \\n(%du\n", icol+CRIGHT, icol+CRIGHT);
+ if (ctype(ilin,icol)=='a')
+ fprintf(tabout, ".ll -2n\n");
+ fprintf(tabout, ".in 0\n");
+ while (gets1(&line, &line, &linesize))
+ {
+ if (line[0]=='T' && line[1]=='}' && line[2]== tab) break;
+ if (match("T}", line)) break;
+ fprintf(tabout, "%s\n", line);
+ }
+ if (fn && *fn) fprintf(tabout, ".ft \\n(%d\n", S1);
+ if (sz && *sz) fprintf(tabout, ".br\n.ps\n.vs\n");
+ fprintf(tabout, ".br\n");
+ fprintf(tabout, ".di\n");
+ if (texct2 < 0)
+ {
+ fprintf(tabout, ".nr %c| \\n(dn\n", (int)texname);
+ fprintf(tabout, ".nr %c- \\n(dl\n", (int)texname);
+ }
+ else
+ {
+ fprintf(tabout, ".do nr %d| \\n(dn\n", texct2);
+ fprintf(tabout, ".do nr %d- \\n(dl\n", texct2);
+ }
+ fprintf(tabout, ".00\n");
+ fprintf(tabout, ".ec \\\n");
+ /* copy remainder of line */
+ if (line[2])
+ tcopy (sp, line+3);
+ else
+ *sp=0;
+ oname = (char *)texname;
+ if (texct2 < 0)
+ texname = texstr[++texct];
+ else
+ texname = ++texct2;
+ free(line);
+ return oname;
+}
+void
+untext(void)
+{
+ rstofill();
+ fprintf(tabout, ".nf\n");
+ fprintf(tabout, ".ll \\n(%du\n", SL);
+}
+char *
+nreg(char *space, size_t siz, const char *_n, int c)
+{
+ int n = (intptr_t)_n;
+ if (n < 128)
+ snprintf(space, siz, "\\n(%c%c", n, c);
+ else
+ snprintf(space, siz, "\\n[%d%c]", n, c);
+ return(space);
+}
diff --git a/tbl/ti.c b/tbl/ti.c
new file mode 100644
index 0000000000000..8357a41684218
--- /dev/null
+++ b/tbl/ti.c
@@ -0,0 +1,82 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "ti.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)ti.c 1.3 (gritter) 7/23/05
+ */
+
+ /* ti.c: classify line intersections */
+# include "t..c"
+/* determine local environment for intersections */
+int
+interv(int i, int c)
+{
+int ku, kl;
+if (c>=ncol || c == 0)
+ {
+ if (dboxflg)
+ {
+ if (i==0) return(BOT);
+ if (i>=nlin) return(TOP);
+ return(THRU);
+ }
+ if (c>=ncol)
+ return(0);
+ }
+ku = i>0 ? lefdata(i-1,c) : 0;
+if (i+1 >= nlin)
+ kl=0;
+else
+kl = lefdata(allh(i) ? i+1 : i, c);
+if (ku==2 && kl==2) return(THRU);
+if (ku ==2) return(TOP);
+if (kl==BOT) return(2);
+return(0);
+}
+int
+interh(int i, int c)
+{
+int kl, kr;
+if (fullbot[i]== '=' || (dboxflg && (i==0 || i>= nlin-1)))
+ {
+ if (c==ncol)
+ return(LEFT);
+ if (c==0)
+ return(RIGHT);
+ return(THRU);
+ }
+if (i>=nlin) return(0);
+kl = c>0 ? thish (i,c-1) : 0;
+if (kl<=1 && i>0 && allh(up1(i)))
+ kl = c>0 ? thish(up1(i),c-1) : 0;
+kr = thish(i,c);
+if (kr<=1 && i>0 && allh(up1(i)))
+ kr = c>0 ? thish(up1(i), c) : 0;
+if (kl== '=' && kr == '=') return(THRU);
+if (kl== '=') return(LEFT);
+if (kr== '=') return(RIGHT);
+return(0);
+}
+int
+up1(int i)
+{
+i--;
+while (instead[i] && i>0) i--;
+return(i);
+}
diff --git a/tbl/tm.c b/tbl/tm.c
new file mode 100644
index 0000000000000..41e8141d5f8c0
--- /dev/null
+++ b/tbl/tm.c
@@ -0,0 +1,91 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tm.c 1.5 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tm.c 1.5 (gritter) 9/15/05
+ */
+
+ /* tm.c: split numerical fields */
+# include "t..c"
+
+char *
+maknew(char *str)
+{
+ /* make two numerical fields */
+ int c;
+ char *dpoint, *p, *q, *ba;
+ p = str;
+ for (ba= 0; (c = *str); str++)
+ if (c == '\\' && *(str+1)== '&')
+ ba=str;
+ str=p;
+ if (ba==0) {
+ for (dpoint=0; *str; str++) {
+ if ((*str&0377)==decimalpoint && !ineqn(str,p) &&
+ ((str>p && digit(*(str-1))) ||
+ digit(*(str+1))))
+ dpoint=str;
+ }
+ if (dpoint==0)
+ for(; str>p; str--) {
+ if (digit( * (str-1) ) && !ineqn(str, p))
+ break;
+ }
+ if (!dpoint && p==str) /* not numerical, don't split */
+ return NULL;
+ if (dpoint) str=dpoint;
+ }
+ else
+ str = ba;
+ p =str;
+ if (exstore ==0 || exstore >exlim) {
+ if (!(exstore = chspace()))
+ return (char *)-1;
+ exlim= exstore+MAXCHS;
+ }
+ q = exstore;
+ ba = exstore + MAXSTR;
+ do {
+ if (exstore > ba) {
+ error("numeric field too big");
+ return (char *)-1;
+ }
+ } while ((*exstore++ = *str++));
+ *p = 0;
+ return(q);
+}
+
+int
+ineqn(char *s, char *p)
+{
+/* true if s is in a eqn within p */
+int ineq = 0, c;
+while ((c = *p))
+ {
+ if (s == p)
+ return(ineq);
+ p++;
+ if ((ineq == 0) && (c == delim1))
+ ineq = 1;
+ else
+ if ((ineq == 1) && (c == delim2))
+ ineq = 0;
+ }
+return(0);
+}
diff --git a/tbl/ts.c b/tbl/ts.c
new file mode 100644
index 0000000000000..7d7e7f8f65956
--- /dev/null
+++ b/tbl/ts.c
@@ -0,0 +1,89 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "ts.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)ts.c 1.3 (gritter) 7/23/05
+ */
+
+ /* ts.c: minor string processing subroutines */
+int
+match(char *s1, char *s2)
+{
+ while (*s1 == *s2)
+ if (*s1++ == '\0')
+ return(1);
+ else
+ s2++;
+ return(0);
+}
+
+int
+prefix(char *small, char *big) {
+ int c;
+ while ((c= *small++) == *big++)
+ if (c==0) return(1);
+ return(c==0);
+}
+
+/* returns: 1 for match, 0 else */
+int
+cprefix(char *ctl, char *line)
+{
+ char c;
+
+ if (*line++ != '.') return 0;
+ while (*line == ' ' || *line == '\t') line++;
+ while ((c = *ctl++) == *line++)
+ if (!c) return 1;
+ return !c;
+}
+
+int
+letter(int ch)
+ {
+ if (ch >= 'a' && ch <= 'z')
+ return(1);
+ if (ch >= 'A' && ch <= 'Z')
+ return(1);
+ return(0);
+ }
+int
+numb(char *str)
+ {
+ /* convert to integer */
+ int k;
+ for (k=0; *str >= '0' && *str <= '9'; str++)
+ k = k*10 + *str - '0';
+ return(k);
+ }
+int
+digit(int x)
+ {
+ return(x>= '0' && x<= '9');
+ }
+int
+max(int a, int b)
+{
+return( a>b ? a : b);
+}
+void
+tcopy(char *s, char *t)
+{
+ while ((*s++ = *t++));
+}
diff --git a/tbl/tt.c b/tbl/tt.c
new file mode 100644
index 0000000000000..3b8e2f3c8b20e
--- /dev/null
+++ b/tbl/tt.c
@@ -0,0 +1,117 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tt.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tt.c 1.3 (gritter) 7/23/05
+ */
+
+ /* tt.c: subroutines for drawing horizontal lines */
+# include "t..c"
+# include <inttypes.h>
+int
+ctype(int il, int ic)
+{
+ if (instead[il])
+ return(0);
+ if (fullbot[il])
+ return(0);
+ il = stynum[il];
+ return(style[il][ic]);
+}
+int
+min(int a, int b)
+{
+return(a<b ? a : b);
+}
+int
+fspan(int i, int c)
+{
+c++;
+return(c<ncol && ctype(i,c)=='s');
+}
+int
+lspan(int i, int c)
+{
+int k;
+if (ctype(i,c) != 's') return(0);
+c++;
+if (c < ncol && ctype(i,c)== 's')
+ return(0);
+for(k=0; ctype(i,--c) == 's'; k++);
+return(k);
+}
+int
+ctspan(int i, int c)
+{
+int k;
+c++;
+for(k=1; c<ncol && ctype(i,c)=='s'; k++)
+ c++;
+return(k);
+}
+void
+tohcol(int ic)
+{
+ if (ic==0)
+ fprintf(tabout, "\\h'|0'");
+ else
+ fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
+}
+int
+allh(int i)
+{
+ /* return true if every element in line i is horizontal */
+ /* also at least one must be horizontl */
+ int c, one, k;
+ if (fullbot[i]) return(1);
+ for(one=c=0; c<ncol; c++)
+ {
+ k = thish(i,c);
+ if (k==0) return(0);
+ if (k==1) continue;
+ one=1;
+ }
+ return(one);
+}
+int
+thish(int i, int c)
+{
+ int t;
+ char *s;
+ struct colstr *pc;
+ if (c<0)return(0);
+ if (i<0) return(0);
+ t = ctype(i,c);
+ if (t=='_' || t == '-')
+ return('-');
+ if (t=='=')return('=');
+ if (t=='^') return(1);
+ if (fullbot[i] )
+ return(fullbot[i]);
+ if (t=='s') return(thish(i,c-1));
+ if (t==0) return(1);
+ pc = &table[i][c];
+ s = (t=='a' ? pc->rcol : pc->col);
+ if (s==0 || (point((intptr_t)s) && *s==0))
+ return(1);
+ if (vspen(s)) return(1);
+ if ((t=barent( s)))
+ return(t);
+ return(0);
+}
diff --git a/tbl/tu.c b/tbl/tu.c
new file mode 100644
index 0000000000000..d8756b0d2e4aa
--- /dev/null
+++ b/tbl/tu.c
@@ -0,0 +1,401 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tu.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ * Portions Copyright (c) 2015 Carsten Kunze
+ *
+ * Sccsid @(#)tu.c 1.4 (gritter) 9/8/06
+ */
+
+ /* tu.c: draws horizontal lines */
+# include "t..c"
+# include <string.h>
+
+/* 0 1 2
+ * lintype - =
+ * tl | ||
+ * bl | ||
+ * c |< ~ >| */
+
+static char *udbdc[2][3][3][3] = { /* vs. uhbdc */
+ { { { NULL , /* 0000 */
+ NULL , /* 0001 */
+ NULL } , /* 0002 */
+ { "\\U'250C'" /* ┌ */ , /* 0010 */
+ "\\U'252C'" /* ┬ */ , /* 0011 */
+ "\\U'2510'" /* ┐ */ } , /* 0012 */
+ { "\\U'2553'" /* ╓ */ , /* 0020 */
+ "\\U'2565'" /* ╥ */ , /* 0021 */
+ "\\U'2556'" /* ╖ */ } } , /* 0022 */
+ { { "\\U'2514'" /* └ */ , /* 0100 */
+ "\\U'2534'" /* ┴ */ , /* 0101 */
+ "\\U'2518'" /* ┘ */ } , /* 0102 */
+ { "\\U'251c'" /* ├ */ , /* 0110 */
+ "\\U'253c'" /* ┼ */ , /* 0111 */
+ "\\U'2524'" /* ┤ */ } , /* 0112 */
+ { "\\U'2553'" /* ╓ */ , /* 0120 ! */
+ "\\U'2565'" /* ╥ */ , /* 0121 ! */
+ "\\U'2556'" /* ╖ */ } } , /* 0122 ! */
+ { { "\\U'2559'" /* ╙ */ , /* 0200 */
+ "\\U'2568'" /* ╨ */ , /* 0201 */
+ "\\U'255C'" /* ╜ */ } , /* 0202 */
+ { "\\U'2559'" /* ╙ */ , /* 0210 ! */
+ "\\U'2568'" /* ╨ */ , /* 0211 ! */
+ "\\U'255C'" /* ╜ */ } , /* 0212 ! */
+ { "\\U'255F'" /* ╟ */ , /* 0220 */
+ "\\U'256B'" /* ╫ */ , /* 0221 */
+ "\\U'2562'" /* ╢ */ } } } , /* 0222 */
+ { { { NULL , /* 1000 */
+ NULL , /* 1001 */
+ NULL } , /* 1002 */
+ { "\\U'2552'" /* ╒ */ , /* 1010 */
+ "\\U'2564'" /* ╤ */ , /* 1011 */
+ "\\U'2555'" /* ╕ */ } , /* 1012 */
+ { "\\U'2554'" /* ╔ */ , /* 1020 */
+ "\\U'2566'" /* ╦ */ , /* 1021 */
+ "\\U'2557'" /* ╗ */ } } , /* 1022 */
+ { { "\\U'2558'" /* ╘ */ , /* 1100 */
+ "\\U'2567'" /* ╧ */ , /* 1101 */
+ "\\U'255B'" /* ╛ */ } , /* 1102 */
+ { "\\U'255E'" /* ╞ */ , /* 1110 */
+ "\\U'256A'" /* ╪ */ , /* 1111 */
+ "\\U'2561'" /* ╡ */ } , /* 1112 */
+ { "\\U'2554'" /* ╔ */ , /* 1120 ! */
+ "\\U'2566'" /* ╦ */ , /* 1121 ! */
+ "\\U'2557'" /* ╗ */ } } , /* 1122 ! */
+ { { "\\U'255A'" /* ╚ */ , /* 1200 */
+ "\\U'2569'" /* ╩ */ , /* 1201 */
+ "\\U'255D'" /* ╝ */ } , /* 1202 */
+ { "\\U'255A'" /* ╚ */ , /* 1210 ! */
+ "\\U'2569'" /* ╩ */ , /* 1211 ! */
+ "\\U'255D'" /* ╝ */ } , /* 1212 ! */
+ { "\\U'2560'" /* ╠ */ , /* 1220 */
+ "\\U'256C'" /* ╬ */ , /* 1221 */
+ "\\U'2563'" /* ╣ */ } } } /* 1222 */
+};
+
+static char *grbe(int i, int lintype);
+static char *glibe(int, int, int, int, int);
+
+void
+makeline(int i, int c, int lintype)
+{
+ int cr, type, shortl;
+ type = thish(i,c);
+ if (type==0) return;
+ cr=c;
+ shortl = (table[i][c].col[0]=='\\');
+ if (c>0 && !shortl && thish(i,c-1) == type)return;
+ if (shortl==0)
+ for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
+ else
+ for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
+ drawline(i, c, cr-1, lintype, 0, shortl);
+}
+void
+fullwide(int i, int lintype)
+{
+ int cr, cl;
+ if (!nflm)
+ fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
+ cr= 0;
+ while (cr<ncol)
+ {
+ cl=cr;
+ while (i>0 && vspand(prev(i),cl,1))
+ cl++;
+ for(cr=cl; cr<ncol; cr++)
+ if (i>0 && vspand(prev(i),cr,1))
+ break;
+ if (cl<ncol)
+ drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
+ }
+ fprintf(tabout, "\n");
+ if (!nflm)
+ fprintf(tabout, ".vs \\n(%du\n", SVS);
+}
+
+void
+drawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
+{
+ char *exhr, *exhl, *lnch;
+ int lcount, ln, linpos, oldpos, nodata;
+ lcount=0;
+ exhr=exhl= "";
+ switch(lintype)
+ {
+ case '-': lcount=1;break;
+ case '=': lcount = nflm ? 1 : 2; break;
+ case SHORTLINE: lcount=1; break;
+ }
+ if (lcount<=0) return;
+ nodata = cr-cl>=ncol || noheight || allh(i);
+ if (!nflm) {
+ if (!nodata)
+ fprintf(tabout, "\\v'-.5m'");
+ if (graphics)
+ fprintf(tabout, "\\v'\\n(#Du'");
+ }
+ for(ln=oldpos=0; ln<lcount; ln++)
+ {
+ linpos = 2*ln - lcount +1;
+ if (linpos != oldpos)
+ fprintf(tabout, "\\v'%dp'", linpos-oldpos);
+ oldpos=linpos;
+ if (shortl==0)
+ {
+ tohcol(cl);
+ if (lcount>1)
+ {
+ switch(interv(i,cl))
+ {
+ case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
+ case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
+ case THRU: exhl = "1p"; break;
+ }
+ if (exhl[0])
+ fprintf(tabout, "\\h'%s'", exhl);
+ }
+ else if (lcount==1)
+ {
+ switch(interv(i,cl))
+ {
+ case TOP: case BOT: exhl = "-1p"; break;
+ case THRU: exhl = "1p"; break;
+ }
+ if (exhl[0])
+ fprintf(tabout, "\\h'%s'", exhl);
+ }
+ if (lcount>1)
+ {
+ switch(interv(i,cr+1))
+ {
+ case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
+ case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
+ case THRU: exhr = "-1p"; break;
+ }
+ }
+ else if (lcount==1)
+ {
+ switch(interv(i,cr+1))
+ {
+ case TOP: case BOT: exhr = "+1p"; break;
+ case THRU: exhr = "-1p"; break;
+ }
+ }
+ }
+ else
+ fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
+ if (!graphics)
+ fprintf(tabout, "\\s\\n(%d",LSIZE);
+ if (linsize)
+ fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
+ if (shortl) {
+ if (graphics)
+ fprintf(tabout, "\\D'l |\\n(%du 0'", cr+CRIGHT);
+ else
+ fprintf(tabout, "\\l'|\\n(%du%s'", cr+CRIGHT,
+ utf8 ? "\\U'2500'" : /* ─ */
+ tlp ? "\\-" :
+ "");
+ }
+ else if (graphics) {
+ if (cr+1>=ncol)
+ fprintf(tabout, "\\D'l |\\n(TWu%s 0'", exhr);
+ else
+ fprintf(tabout, "\\D'l (|\\n(%du+|\\n(%du)/2u%s 0'",
+ cr+CRIGHT, cr+1+CLEFT, exhr);
+ }
+ else
+ {
+ lnch = "\\(ul";
+ if (utf8)
+ lnch = lintype == '=' ? "\\U'2550'" : /* ═ */
+ "\\U'2500'" ; /* ─ */
+ else if (tlp)
+ lnch = lintype == '=' ? "\\&=" : "\\-";
+ else
+ if (pr1403)
+ lnch = lintype == '=' ? "\\&=" : "\\(ru";
+ if (cr+1>=ncol)
+ fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
+ else
+ fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
+ cr+1+CLEFT, exhr, lnch);
+ }
+ if (linsize)
+ fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
+ if (!graphics)
+ fprintf(tabout, "\\s0");
+ }
+ if (oldpos!=0)
+ fprintf(tabout, "\\v'%dp'", -oldpos);
+ if (graphics)
+ fprintf(tabout, "\\v'-\\n(#Du'");
+ if (!nodata)
+ fprintf(tabout, "\\v'+.5m'");
+ if (!shortl && (utf8 || tlp)) {
+ int corred, c, ccr, licr;
+ char *s;
+ ccr = cr;
+ if (ccr == cl) ccr++;
+ corred = 0;
+ if (ccr == ncol && (boxflg || allflg || dboxflg) &&
+ (s = grbe(i, lintype))) {
+ fprintf(tabout, "\n.sp -1\n");
+ corred = 1;
+ fprintf(tabout, "\\h'|\\n(TWu'");
+ fprintf(tabout, "%s", s);
+ }
+ licr = ccr;
+ if (licr == ncol) {
+ licr--;
+ if (!(boxflg || allflg || dboxflg)) ccr--;
+ }
+ for(c = cl; c <= licr; c++) {
+ if ((s = glibe(i, c, cl, ccr, lintype))) {
+ if (!corred) {
+ fprintf(tabout, "\n.sp -1\n");
+ corred = 1;
+ }
+ tohcol(c);
+ fprintf(tabout, "%s", s);
+ }
+ }
+ }
+}
+
+static char *glibe(int i, int c, int cl, int cr, int lintype) {
+ char *s = NULL;
+ int tl, bl;
+ int cx = c == cl ? 0 :
+ c == cr ? 2 : 1 ;
+ lintype = lintype == '=' ? 1 : 0;
+ if (!i) {
+ bl = lefdata(1, c);
+ if (bl >= 1 && bl <= 2)
+ s = tlp ? "+" :
+ udbdc[lintype][0][bl][cx];
+ } else if (i < nlin - 1) {
+ tl = lefdata(i - 1, c);
+ bl = lefdata(i + 1, c);
+ if (tl >= 0 && tl <= 2 && bl >= 0 && bl <= 2)
+ {
+ if (tlp) {
+ if (tl || bl) s = "+";
+ } else
+ s = udbdc[lintype][tl][bl][cx];
+ }
+ } else {
+ tl = lefdata(i - 1, c);
+ if (tl >= 1 && tl <= 2)
+ s = tlp ? "+" :
+ udbdc[lintype][tl][0][cx];
+ }
+ return s;
+}
+
+static char *grbe(int i, int lintype) {
+ int tl, bl;
+ lintype = lintype == '=' ? 1 : 0;
+ tl = !i ? 0 :
+ dboxflg ? 2 : 1;
+ bl = i && i >= nlin - 1 ? 0 :
+ dboxflg ? 2 : 1;
+ if (utf8) return udbdc[lintype][tl][bl][2];
+ else if (tl || bl) return "+";
+ else return NULL;
+}
+
+void
+getstop(void)
+{
+int i,c,k,junk, stopp;
+stopp=1;
+for(i=0; i<MAXLIN; i++)
+ linestop[i]=0;
+for(i=0; i<nlin; i++)
+ for(c=0; c<ncol; c++)
+ {
+ k = left(i,c,&junk);
+ if (k>=0 && linestop[k]==0)
+ linestop[k]= ++stopp;
+ }
+if (boxflg || allflg || dboxflg)
+ linestop[0]=1;
+}
+int
+left(int i, int c, int *lwidp)
+{
+ int kind, li = 0, lj;
+ /* returns -1 if no line to left */
+ /* returns number of line where it starts */
+ /* stores into lwid the kind of line */
+ *lwidp=0;
+ kind = lefdata(i,c);
+ if (kind==0) return(-1);
+ if (i+1<nlin)
+ if (lefdata(next(i),c)== kind) return(-1);
+ while (i>=0 && lefdata(i,c)==kind)
+ i=prev(li=i);
+ if (prev(li)== -1) li=0;
+ *lwidp=kind;
+ for(lj= i+1; lj<li; lj++)
+ if (instead[lj] && strcmp(instead[lj], ".TH")==0)
+ return(li);
+ for(i= i+1; i<li; i++)
+ if (fullbot[i])
+ li=i;
+ return(li);
+}
+int
+lefdata(int i, int c)
+{
+ int ck;
+ if (i>=nlin) i=nlin-1;
+ if (ctype(i,c) == 's')
+ {
+ for(ck=c; ctype(i,ck)=='s'; ck--);
+ if (thish(i,ck)==0)
+ return(0);
+ }
+ i =stynum[i];
+ i = lefline[i][c];
+ if (i>0) return(i);
+ if (dboxflg && c==0) return(2);
+ if (allflg)return(1);
+ if (boxflg && c==0) return(1);
+ return(0);
+}
+int
+next(int i)
+{
+while (i+1 <nlin)
+ {
+ i++;
+ if (!fullbot[i] && !instead[i]) break;
+ }
+return(i);
+}
+int
+prev(int i)
+{
+while (--i >=0 && (fullbot[i] || instead[i]))
+ ;
+return(i);
+}
diff --git a/tbl/tv.c b/tbl/tv.c
new file mode 100644
index 0000000000000..6376ad022d650
--- /dev/null
+++ b/tbl/tv.c
@@ -0,0 +1,186 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "tv.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ *
+ * Sccsid @(#)tv.c 1.4 (gritter) 9/8/06
+ */
+
+ /* tv.c: draw vertical lines */
+# include "t..c"
+# include <inttypes.h>
+void
+drawvert(int start, int end, int c, int lwid)
+{
+ char *exb=0, *ext=0;
+ int tp=0, sl, ln, pos, epb, ept, vm;
+ end++;
+ vm='v';
+ /* note: nr 35 has value of 1m outside of linesize */
+ while (instead[end]) end++;
+ for(ln=0; ln<lwid; ln++)
+ {
+ epb=ept=0;
+ pos = 2*ln-lwid+1;
+ if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
+ tp = pos;
+ if (end<nlin)
+ {
+ if (fullbot[end]|| (!instead[end] && allh(end)))
+ epb=2;
+ else
+ switch (midbar(end,c))
+ {
+ case '-':
+ exb = "1v-.5m"; break;
+ case '=':
+ exb = "1v-.5m";
+ epb = 1; break;
+ }
+ }
+ if (lwid>1)
+ switch(interh(end, c))
+ {
+ case THRU: epb -= 1; break;
+ case RIGHT: epb += (ln==0 ? 1 : -1); break;
+ case LEFT: epb += (ln==1 ? 1 : -1); break;
+ }
+ if (lwid==1)
+ switch(interh(end,c))
+ {
+ case THRU: epb -= 1; break;
+ case RIGHT: case LEFT: epb += 1; break;
+ }
+ if (start>0)
+ {
+ sl = start-1;
+ while (sl>=0 && instead[sl]) sl--;
+ if (sl>=0 && (fullbot[sl] || allh(sl)))
+ ept=0;
+ else
+ if (sl>=0)
+ switch(midbar(sl,c))
+ {
+ case '-':
+ ext = ".5m"; break;
+ case '=':
+ ext= ".5m"; ept = -1; break;
+ default:
+ vm = 'm'; break;
+ }
+ else
+ ept = -4;
+ }
+ else if (start==0 && allh(0))
+ {
+ ept=0;
+ vm = 'm';
+ }
+ if (lwid>1)
+ switch(interh(start,c))
+ {
+ case THRU: ept += 1; break;
+ case LEFT: ept += (ln==0 ? 1 : -1); break;
+ case RIGHT: ept += (ln==1 ? 1 : -1); break;
+ }
+ else if (lwid==1)
+ switch(interh(start,c))
+ {
+ case THRU: ept += 1; break;
+ case LEFT: case RIGHT: ept -= 1; break;
+ }
+ if (exb)
+ fprintf(tabout, "\\v'%s'", exb);
+ if (epb)
+ fprintf(tabout, "\\v'%dp'", epb);
+ if (graphics)
+ fprintf(tabout, "\\v'\\n(#Du'");
+ else
+ fprintf(tabout, "\\s\\n(%d",LSIZE);
+ if (linsize)
+ fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
+ fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
+ if (graphics)
+ fprintf(tabout, "\\D'l 0 |\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
+ else
+ fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
+ if (ext)
+ fprintf(tabout, "-(%s)",ext);
+ if (exb)
+ fprintf(tabout, "-(%s)", exb);
+ pos = ept-epb;
+ if (pos)
+ fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
+ /* the string #d is either "nl" or ".d" depending
+ on diversions; on GCOS not the same */
+ fprintf(tabout, "'");
+ if (graphics)
+ fprintf(tabout, "\\v'-\\n(#Du'");
+ else
+ fprintf(tabout, "\\s0");
+ fprintf(tabout, "\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
+ if (ext)
+ fprintf(tabout, "+%s",ext);
+ if (ept)
+ fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
+ fprintf(tabout, "'");
+ if (linsize)
+ fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
+ }
+}
+
+
+int
+midbar(int i, int c)
+{
+ int k;
+ k = midbcol(i,c);
+ if (k==0 && c>0)
+ k = midbcol(i, c-1);
+ return(k);
+}
+int
+midbcol(int i, int c)
+{
+ int ct;
+ while ( (ct=ctype(i,c)) == 's')
+ c--;
+ if (ct=='-' || ct == '=')
+ return(ct);
+ if ((ct=barent(table[i][c].col)))
+ return(ct);
+ return(0);
+}
+
+int
+barent(char *s)
+{
+ if (s==0) return (1);
+ if (!point((intptr_t)s)) return(1);
+ if (s[0]== '\\') s++;
+ if (s[1]!= 0)
+ return(0);
+ switch(s[0])
+ {
+ case '_':
+ return('-');
+ case '=':
+ return('=');
+ }
+ return(0);
+}
diff --git a/tbl/version.c b/tbl/version.c
new file mode 100644
index 0000000000000..4dd58bcffbb03
--- /dev/null
+++ b/tbl/version.c
@@ -0,0 +1,33 @@
+#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4
+#define USED __attribute__ ((used))
+#elif defined __GNUC__
+#define USED __attribute__ ((unused))
+#else
+#define USED
+#endif
+static const char sccsid[] USED = "@(#)/usr/ucb/tbl.sl 5.19 (gritter) 10/2/07";
+/* SLIST */
+/*
+t..c: * Sccsid @(#)t..c 1.19 (gritter) 9/11/06
+t0.c: * Sccsid @(#)t0.c 1.12 (gritter) 9/11/06
+t1.c: * Sccsid @(#)t1.c 1.12 (gritter) 9/8/06
+t2.c: * Sccsid @(#)t2.c 1.3 (gritter) 7/23/05
+t3.c: * Sccsid @(#)t3.c 1.12 (gritter) 9/11/06
+t4.c: * Sccsid @(#)t4.c 1.7 (gritter) 9/8/06
+t5.c: * Sccsid @(#)t5.c 1.8 (gritter) 10/2/07
+t6.c: * Sccsid @(#)t6.c 1.6 (gritter) 2/8/06
+t7.c: * Sccsid @(#)t7.c 1.8 (gritter) 10/25/06
+t8.c: * Sccsid @(#)t8.c 1.12 (gritter) 10/2/07
+t9.c: * Sccsid @(#)t9.c 1.7 (gritter) 2/26/06
+tb.c: * Sccsid @(#)tb.c 1.7 (gritter) 9/8/06
+tc.c: * Sccsid @(#)tc.c 1.5 (gritter) 10/15/05
+te.c: * Sccsid @(#)te.c 1.13 (gritter) 8/6/06
+tf.c: * Sccsid @(#)tf.c 1.9 (gritter) 9/9/06
+tg.c: * Sccsid @(#)tg.c 1.10 (gritter) 10/2/07
+ti.c: * Sccsid @(#)ti.c 1.3 (gritter) 7/23/05
+tm.c: * Sccsid @(#)tm.c 1.5 (gritter) 9/15/05
+ts.c: * Sccsid @(#)ts.c 1.3 (gritter) 7/23/05
+tt.c: * Sccsid @(#)tt.c 1.3 (gritter) 7/23/05
+tu.c: * Sccsid @(#)tu.c 1.4 (gritter) 9/8/06
+tv.c: * Sccsid @(#)tv.c 1.4 (gritter) 9/8/06
+*/