# # define ever (;;) # define MAXCHS 2000 main(argc,argv) char *argv[]; { char line[200]; extern int cin; extern char *cspace; cspace = getvec(MAXCHS + 100); for ever { if (argc>1) { argc--; argv++; if (match(*argv, "-ms")) *argv = "/usr/lib/tmac.s"; cin = copen(*argv, 'r'); if (cin < 0) { printf(2,"where is input file %s\n",*argv); cexit(); } } while (gets(line)) if (match(line, ".TS")) tableput(); else puts(line); if (argc <= 1) break; } cexit(); } # define MAXCOL 35 # define MAXLIN 220 # define ONELINE 250 char *tabentry[MAXLIN][MAXCOL]; char extra[MAXCHS]; char *cspace, *cstore; char *exstore extra; int sep[MAXCOL], dwide[MAXCOL]; char *instead[MAXLIN]; int newtab[MAXLIN]; char *style[MAXCOL]; tableput() { /* read input, write output, make tables on the way */ char st[ONELINE], *format; int ilin, nlin, icol, ncol, k, ch, ws, cs, ns; int maxchnge, ct; printf(".TS\n"); /* get command line */ cstore = cspace; exstore = extra; ncol = 0; for (ilin=0; ilin MAXCHS) cstore = cspace = getvec(MAXCHS+100); } /* find longest command string */ for (icol=maxchnge=0; icolmaxchnge) maxchnge = slen(style[icol]); /* set tab stops */ printf(".nr 49 0\n"); for (icol = 0; icol0 ? sep[icol-1] : 0); printf(".nr %2d 0\n", icol+50); for (ilin=0; ilin < nlin; ilin++) { if (icol>0 && dwide[icol-1]>0 && tabentry[ilin][icol]==0) { printf(".nr 48 \\n(%2d+\\w'%s'+%dn\n", icol+48, tabentry[ilin][icol-1], sep[icol-1]); printf(".if \\n(48-\\n(%2d .nr %2d \\n(48\n", icol+50,icol+50); } if ( !span(style[icol],ilin) && /* not part of span */ (dwide[icol] == 0 || tabentry[ilin][icol+1]!= 0) /* not a double item */ && (!span(style[icol+1],ilin) || icol==ncol)) { printf(".nr 47 \\n(%2d+\\w'%s'+%dn\n", icol+49,tabentry[ilin][icol], ct); printf(".if \\n(47-\\n(%2d .nr %2d \\n(47\n", icol+50,icol+50); } } /* clean up spanned headings */ for(ilin=0; ilin0 && tabentry[ilin][icol] == 0 )) printf(format, tabentry[ilin][icol]); if (!span(style[icol+1],ilin)) for (k=sep[icol]; k>0; k--) printf(" "); } printf("\n"); } printf(".fc\n"); printf(".TE\n"); } match (s1, s2) char *s1, *s2; { while (*s1 == *s2) if (*s1++ == '\0') return(1); else *s2++; return(0); } slen(str) char *str; { int k; for (k=0; *str++ != '\0'; k++); return(k); } space(ch) { switch (ch) { case ' ': case '\t': return(1); } return(0); } letter (ch) { if (ch >= 'a' && ch <= 'z') return(1); if (ch >= 'A' && ch <= 'Z') return(1); return(0); } numb(str) char *str; { /* convert to integer */ int k; for (k=0; *str >= '0' && *str <= '9'; str++) k = k*10 + *str - '0'; return(k); } broken(str, nlin) { switch(ylet(str,nlin)) { case 'n': case 'N': return(1); } return(0); } ylet (str, k) char *str; { k++; while (*str &&k--) str++; return(*--str); } span(str, k) { switch(ylet(str,k)) { case 's': case 'S': return(1); } return(0); } maknew(str) char *str; { /* make two numerical fields */ int point; char *p, *q; p = str; for (point=0; *str; str++) if (*str=='.') point=1; if (!point && *(str-1)== '$') return(0); for(; str>p; str--) if ( (point && *str == '.') || (!point && digit(*(str-1)) ) ) break; if (!point && p==str) /* not numerical, don't split */ return(0); p= str; q = exstore; while (*exstore++ = *str++); *p = 0; return(q); } digit(x) { return(x>= '0' && x<= '9'); } settab(ncol, ilin) { int k, icol; printf(".ta "); for (icol = 0; icol