📄 n1.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)n1.c 4.1 ULTRIX 7/17/90";#endif lint/* * Modification history: * * Mar 19, 88: Chetal Pradeep (chetal) * Undid the changes made (explained below) for backwards * compatibility, historic reasons, and not to break some other * programs. * * Sep 15, 87: Chetal Pradeep (chetal) * Code added for NROFF to recognize the TERM type even if the * -T option is not given by the user, so as to pick up the proper * terminal driving table. */#include "tdef.h"#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>extern#include "d.h"extern#include "v.h"#ifdef NROFFextern#include "tw.h"#endif#include "sdef.h"#include <setjmp.h>jmp_buf sjbuf;#include <sgtty.h>/*troff1.cconsume options, initialization, main loop,input routines, escape function calling*/int inchar[LNSIZE], *pinchar = inchar; /* XXX */extern struct s *frame, *stk, *nxf;extern struct s *ejl, *litlev;extern filep ip;extern filep offset;extern filep nextb;extern int stdi;extern int waitf;extern int nofeed;extern int quiet;extern int ptid;extern int ascii;extern int npn;extern int xflg;extern int stop;extern char ibuf[IBUFSZ];extern char xbuf[IBUFSZ];extern char *ibufp;extern char *xbufp;extern char *eibuf;extern char *xeibuf;extern int cbuf[NC];extern int *cp;extern int *vlist;extern int nx;extern int mflg;extern int ch;extern int pto;extern int pfrom;extern int cps;extern int chbits;extern int ibf;extern int ttyod;extern struct sgttyb ttys;extern int iflg;extern int init;extern int rargc;extern char **argp;extern char trtab[256];extern int lgf;extern int copyf;extern int eschar;extern int ch0;extern int cwidth;extern int nlflg;extern int *ap;extern int donef;extern int nflush;extern int nchar;extern int rchar;extern int nfo;extern int ifile;extern int fc;extern int padc;extern int tabc;extern int dotc;extern int raw;extern int tabtab[NTAB];extern char nextf[];extern int nfi;#ifdef NROFFextern char termtab[];extern int tti;#endifextern int ifl[NSO];extern int ifi;extern int pendt;extern int flss;extern int fi;extern int lg;extern char ptname[];extern int print;extern int nonumb;extern int pnlist[];extern int *pnp;extern int nb;extern int trap;extern int tflg;extern int ejf;extern int lit;extern int cc;extern int c2;extern int spread;extern int gflag;extern int oline[];extern int *olinep;extern int dpn;extern int noscale;extern char *unlkp;extern int pts;extern int level;extern int ttysave;extern int tdelim;extern int dotT;extern int tabch, ldrch;extern int eqflg;extern no_out;extern int hflg;#ifndef NROFFextern char codetab[];extern int spbits;#endifextern int xxx;int stopmesg;filep ipl[NSO];long offl[NSO];long ioff;char *ttyp;extern struct contab { int rq; union { int (*f)(); unsigned mx; }x;}contab[NM];int ms[] = {31,28,31,30,31,30,31,31,30,31,30,31};#ifndef NROFFint acctf;#endifmain(argc,argv)int argc;char **argv;{ char *p, *q; register i, j; extern catch(), fpecatch(), kcatch(); signal(SIGHUP,catch); if(signal(SIGINT,catch) == SIG_IGN){ signal(SIGHUP,SIG_IGN); signal(SIGINT,SIG_IGN); signal(SIGQUIT,SIG_IGN); } signal(SIGFPE,fpecatch); signal(SIGPIPE,catch); signal(SIGTERM,kcatch); init1(argv[0][0]);options: while(--argc > 0 && (++argv)[0][0]=='-') switch(argv[0][1]){ case 0: goto start; case 'i': stdi++; continue; case 'q': quiet++; if(gtty(0, &ttys) >= 0) ttysave = ttys.sg_flags; continue; case 'n': npn = cnum(&argv[0][2]); continue; case 'p': xflg = 0; cps = cnum(&argv[0][2]); continue; case 'S': stopmesg++; continue; case 's': if(!(stop = cnum(&argv[0][2])))stop++; continue; case 'r': vlist[findr(argv[0][2])] = cnum(&argv[0][3]); continue; case 'm': p = &nextf[nfi]; q = &argv[0][2]; while((*p++ = *q++) != 0); if (access(nextf, 4) < 0) {char *local = "/usr/local/lib/tmac/tmac.\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; strcat(local, &argv[0][2]); if (access(local, 4) == 0) strcpy(nextf, local); } mflg++; continue; case 'o': getpn(&argv[0][2]); continue;#ifdef NROFF case 'h': hflg++; continue; case 'z': no_out++; continue; case 'e': eqflg++; continue; case 'T': p = &termtab[tti]; q = &argv[0][2]; if(!((*q) & 0177))continue; while((*p++ = *q++) != 0); dotT++; continue;#endif#ifndef NROFF case 'z': no_out++; case 'a': ascii = 1; nofeed++; case 't': ptid = 1; continue; case 'w': waitf = 1; continue; case 'f': nofeed++; continue; case 'x': xflg = 0; continue; case 'b': if(open(ptname,1) < 0)prstr("Busy.\n"); else prstr("Available.\n"); done3(0); case 'g': stop = ptid = gflag = 1; dpn = 0; continue; case 'F': { extern char *fontfile; fontfile = &argv[0][2]; } continue;#endif default: pto = cnum(&argv[0][1]); continue; } if(argv[0][0] == '+'){ pfrom = cnum(&argv[0][1]); print = 0; if(argc > 0)goto options; }start: argp = argv; rargc = argc; init2(); setjmp(sjbuf);loop: copyf = lgf = nb = nflush = nlflg = 0; if(ip && (rbf0(ip)==0) && ejf && (frame->pframe <= ejl)){ nflush++; trap = 0; eject((struct s *)0); goto loop; } i = getch(); if(pendt)goto lt; if(lit && (frame <= litlev)){ lit--; goto lt; } if((j = (i & CMASK)) == XPAR){ copyf++; tflg++; for(;(i & CMASK) != '\n';)pchar(i = getch()); tflg = 0; copyf--; goto loop; } if((j == cc) || (j == c2)){ if(j == c2)nb++; copyf++; while(((j=((i=getch()) & CMASK)) == ' ') || (j == '\t')); ch = i; copyf--; control(getrq(),1); flushi(); goto loop; }lt: ch = i; text(); goto loop;}catch(){/* prstr("Interrupt\n");*/ done3(01);}fpecatch(){ prstrfl("Floating Exception.\n"); signal(SIGFPE,fpecatch);}kcatch(){ signal(SIGTERM,SIG_IGN); done3(01);}#ifndef NROFFacctg() { static char *acct_file = "/usr/adm/tracct"; acctf = open(acct_file,1); setuid(getuid());}#endifinit1(a)char a;{ register char *p; char *mktemp(); register i;#ifndef NROFF acctg();/*open troff actg file while mode 4755*/#endif p = mktemp("/tmp/taXXXXX"); if(a == 'a')p = &p[5]; if((close(creat(p, 0600))) < 0){ prstr("Cannot create temp file.\n"); exit(-1); } ibf = open(p, 2); for(i=256; --i;)trtab[i]=i; trtab[UNPAD] = ' '; mchbits(); if(a != 'a')unlkp = p;}init2(){ register i,j; extern int block; extern char *setbrk(); extern char *ttyname(); ttyod = 2; if(((ttyp=ttyname(j=0)) != (char *)0) || ((ttyp=ttyname(j=1)) != (char *)0) || ((ttyp=ttyname(j=2)) != (char *)0) );else ttyp = "notty"; iflg = j; if(ascii)mesg(0); if((!ptid) && (!waitf)){ if((ptid = open(ptname,1)) < 0){ prstr("Typesetter busy.\n"); done3(-2); } } ptinit(); for(i=NEV; i--;)write(ibf, (char *)&block, EVS*sizeof(int)); olinep = oline; ibufp = eibuf = ibuf; v.hp = init = 0; pinchar = inchar; /* XXX */ ioff = 0; v.nl = -1; cvtime(); frame = stk = (struct s *)setbrk(DELTA); dip = &d[0]; nxf = frame + 1; nx = mflg;}cvtime(){ register i; struct timeval t; struct timezone tz; gettimeofday(&t, &tz); t.tv_sec -= 60*tz.tz_minuteswest; /* 5hrs for EST */ v.dy = (t.tv_sec/86400L) + 1; v.dw = (v.dy + 3)%7 + 1; for(v.yr=70;; v.yr++){ if((v.yr)%4)ms[1]=28;else ms[1]=29; for(i=0;i<12;){ if(v.dy<=ms[i]){ v.mo = i+1; return; } v.dy -= ms[i++]; } }}cnum(a)char *a;{ register i; ibufp = a; eibuf = (char *)MAXPTR; i = atoi(); ch = 0; return(i);}mesg(f)int f;{ static int mode; if (ttyp==0) return; if(!f){ stat(ttyp,cbuf); mode = ((struct stat *)(cbuf))->st_mode; chmod(ttyp,mode & ~022); }else{ chmod(ttyp,mode); }}prstrfl(s)char *s;{ flusho(); prstr(s);}prstr(s)char *s;{ register i; register char *j; j = s; for(i=0;*s;i++)s++; write(ttyod,j,i);}control(a,b)int a,b;{ register i,j; extern filep boff(); i = a; if((i == 0) || ((j = findmn(i)) == -1))return(0); if(contab[j].rq & MMASK){ nxf->nargs = 0; if(b)collect(); flushi(); return(pushi(((filep)contab[j].x.mx)<<BLKBITS)); }else{ if(!b)return(0); return((*contab[j].x.f)(0)); }}getrq(){ register i,j; if(((i=getach()) == 0) || ((j=getach()) == 0))goto rtn; i = PAIR(i,j);rtn: return(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -