1: #include "sdef.h"
   2: #include "d.h"
   3: #include "v.h"
   4: #include "tw.h"
   5: #include "s.h"
   6: #include <setjmp.h>
   7: jmp_buf sjbuf;
   8: 
   9: /*
  10: sroff2.c
  11: 
  12: output, cleanup
  13: */
  14: 
  15: extern struct s *frame, *stk, *nxf;
  16: extern filep ip;
  17: extern filep offset;
  18: extern char *enda;
  19: 
  20: 
  21: extern char obuf[OBUFSZ];
  22: extern char *obufp;
  23: extern int dilev;
  24: extern int eschar;
  25: extern int tlss;
  26: extern int tflg;
  27: extern int print;
  28: extern char trtab[];
  29: extern int waitf;
  30: extern char ptname[];
  31: extern int ptid;
  32: extern int em;
  33: extern int ds;
  34: extern int mflg;
  35: extern filep woff;
  36: extern int nflush;
  37: extern int lgf;
  38: extern int app;
  39: extern int nfo;
  40: extern int donef;
  41: extern int *pendw;
  42: extern int trap;
  43: extern struct sgttyb ttys;
  44: extern int ttysave;
  45: extern int quiet;
  46: extern int pendnf;
  47: extern int ndone;
  48: extern int lead;
  49: extern int ralss;
  50: extern char *unlkp;
  51: extern char nextf[];
  52: extern int pipeflg;
  53: extern int ejf;
  54: extern int no_out;
  55: extern int level;
  56: extern int stopmesg;
  57: extern int xxx;
  58: int toolate;
  59: int error;
  60: 
  61: pchar(c)
  62: int c;
  63: {
  64:     register i, j;
  65: 
  66:     if((i=c) & MOT){pchar1(i); return;}
  67:     switch(j = i & CMASK){
  68:         case 0:
  69:         case IMP:
  70:         case RIGHT:
  71:         case LEFT:
  72:             return;
  73:         case HX:
  74:             j = (tlss>>9) | ((i&~0777)>>3);
  75:             if(i & 040000){
  76:                 j &= ~(040000>>3);
  77:                 if(j > dip->blss)dip->blss = j;
  78:             }else{
  79:                 if(j > dip->alss)dip->alss = j;
  80:                 ralss = dip->alss;
  81:             }
  82:             tlss = 0;
  83:             return;
  84:         case LX:
  85:             tlss = i;
  86:             return;
  87:         case PRESC:
  88:             if(dip == &d[0])j = eschar;
  89:         default:
  90:             i = (trtab[j] & BMASK) | (i & ~CMASK);
  91:     }
  92:     pchar1(i);
  93: }
  94: pchar1(c)
  95: int c;
  96: {
  97:     register i, j, *k;
  98:     extern int chtab[];
  99: 
 100:     j = (i = c) & CMASK;
 101:     if(dip != &d[0]){
 102:         wbf(i);
 103:         dip->op = offset;
 104:         return;
 105:     }
 106:     if(!tflg && !print){
 107:         if(j == '\n')dip->alss = dip->blss = 0;
 108:         return;
 109:     }
 110:     if(no_out || (j == FILLER))return;
 111:     ptout(i);
 112: }
 113: oput(i)
 114: char i;
 115: {
 116:     *obufp++ = i;
 117:     if(obufp == (obuf + OBUFSZ)) flusho();
 118: }
 119: oputs(i)
 120: char *i;
 121: {
 122:     while(*i != 0)oput(*i++);
 123: }
 124: flusho(){
 125:     if(!ptid){
 126:         while((ptid=open(ptname,1)) < 0){
 127:             if(++waitf <=2)prstr("Waiting for printer.\n");
 128:             sleep(15);
 129:         }
 130:     }
 131:     if(no_out == 0){
 132: #ifdef TTY
 133:         if (!toolate) {
 134:             toolate++;
 135:             if(ttysave == -1) {
 136:                 gtty(ptid, &ttys);
 137:                 ttysave = ttys.sg_flags;
 138:             }
 139:             ttys.sg_flags &= ~t.breset;
 140:             ttys.sg_flags |= t.bset;
 141:             stty(ptid, &ttys);
 142: #else
 143:         if (!toolate) {
 144:             toolate++;
 145:             if (ptid != 1) {
 146:                 ttys.sg_ispeed = ttys.sg_ospeed = t.bspeed;
 147:                 ttys.sg_flags = t.bflags;
 148:                 stty(ptid, &ttys);
 149: #ifdef  TIOCEXCL
 150:                 ioctl(ptid,TIOCEXCL,(struct sgttyb *)0);
 151: #endif
 152:             }
 153: #endif
 154:             {
 155:             char *p = t.twinit;
 156:             while (*p++)
 157:                 ;
 158:             write(ptid, t.twinit, p-t.twinit-1);
 159:             }
 160:         }
 161:         toolate += write(ptid, obuf, obufp-obuf);
 162:     }
 163:     obufp = obuf;
 164: }
 165: done(x) int x;{
 166:     register i;
 167: 
 168:     error |= x;
 169:     level = 0;
 170:     app = ds = lgf = 0;
 171:     if(i=em){
 172:         donef = -1;
 173:         em = 0;
 174:         if(control(i,0))longjmp(sjbuf,1);
 175:     }
 176:     if(!nfo)done3(0);
 177:     mflg = 0;
 178:     dip = &d[0];
 179:     if(woff)wbt(0);
 180:     if(pendw)getword(1);
 181:     pendnf = 0;
 182:     if(donef == 1)done1(0);
 183:     donef = 1;
 184:     ip = 0;
 185:     frame = stk;
 186:     nxf = frame + 1;
 187:     if(!ejf)tbreak();
 188:     nflush++;
 189:     eject((struct s *)0);
 190:     longjmp(sjbuf,1);
 191: }
 192: done1(x) int x; {
 193:     error |= x;
 194:     if(v.nl){
 195:         trap = 0;
 196:         eject((struct s *)0);
 197:         longjmp(sjbuf,1);
 198:     }
 199:     done2(0);
 200: }
 201: done2(x) int x; {
 202:     register i;
 203: 
 204:     ptlead();
 205:     if(ptid != 1 && stopmesg)
 206:         prstr("Sroff finished.\n");
 207:     flusho();
 208:     done3(x);
 209: }
 210: done3(x) int x;{
 211:     error |= x;
 212:     signal(SIGINT, SIG_IGN);
 213:     signal(SIGTERM, SIG_IGN);
 214:     unlink(unlkp);
 215:     twdone();
 216:     if(quiet){
 217:         ttys.sg_flags |= ECHO;
 218:         stty(0, &ttys);
 219:     }
 220:     exit(error);
 221: }
 222: edone(x) int x;{
 223:     frame = stk;
 224:     nxf = frame + 1;
 225:     ip = 0;
 226:     done(x);
 227: }
 228: casepi(){
 229:     register i;
 230:     int id[2];
 231: 
 232:     if(toolate || skip() || !getname() || (pipe(id) == -1) ||
 233:        ((i=fork()) == -1)){
 234:         prstr("Pipe not created.\n");
 235:         return;
 236:     }
 237:     ptid = id[1];
 238:     if(i>0){
 239:         close(id[0]);
 240:         toolate++;
 241:         pipeflg++;
 242:         return;
 243:     }
 244:     close(0);
 245:     dup(id[0]);
 246:     close(id[1]);
 247:     execl(nextf,nextf,0);
 248:     prstr("Cannot exec: ");
 249:     prstr(nextf);
 250:     prstr("\n");
 251:     exit(-4);
 252: }

Defined functions

casepi defined in line 228; used 2 times
done defined in line 165; used 8 times
done1 defined in line 192; used 3 times
done3 defined in line 210; used 7 times
edone defined in line 222; used 7 times
oput defined in line 113; used 14 times
oputs defined in line 119; used 26 times
pchar defined in line 61; used 11 times
pchar1 defined in line 94; used 20 times

Defined variables

error defined in line 59; used 5 times
sjbuf defined in line 7; used 3 times
toolate defined in line 58; used 9 times
Last modified: 1982-03-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1168
Valid CSS Valid XHTML 1.0 Strict