1: #include "sdef.h"
   2: #include "d.h"
   3: #include "v.h"
   4: #include "tw.h"
   5: /*
   6: sroff9.c
   7: 
   8: misc functions
   9: */
  10: 
  11: extern int cbuf[];
  12: extern int *cp;
  13: extern int ch;
  14: extern int chbits;
  15: extern int dfact;
  16: extern int vflag;
  17: extern int Em;
  18: extern int fc;
  19: extern int padc;
  20: extern int tabtab[];
  21: extern int nlflg;
  22: extern int lss;
  23: extern int tabch, ldrch;
  24: extern int tabc, dotc;
  25: extern int nchar, rchar;
  26: extern int xxx;
  27: 
  28: setz(){
  29:     register i;
  30: 
  31:     if(!((i = getch()) & MOT))i |= ZBIT;
  32:     return(i);
  33: }
  34: setline(){
  35:     register *i, length, c;
  36:     int w, cnt, delim, rem, temp;
  37:     if((delim = getch()) & MOT)return;
  38:         else delim =& CMASK;
  39:     vflag = 0;
  40:     dfact = Em;
  41:     length = atoi();
  42:     dfact = 1;
  43:     if(!length){
  44:         eat(delim);
  45:         return;
  46:     }
  47: s0:
  48:     if(((c = getch()) & CMASK) == delim){
  49:         ch = c;
  50:         c = 0137 | chbits;
  51:     }else if((c & CMASK) == FILLER)goto s0;
  52:     w = width(c);
  53:     i = cbuf;
  54:     if(length < 0){
  55:         *i++ = makem(length);
  56:         length = -length;
  57:     }
  58:     if(!(cnt = length/w)){
  59:         *i++ = makem(-(temp = ((w-length)/2)));
  60:         *i++ = c;
  61:         *i++ = makem(-(w - length - temp));
  62:         goto s1;
  63:     }
  64:     if(rem = length%w){
  65:         switch(c & CMASK){
  66:             case 0137: /*rule stan*/
  67:             case C_UR: /*underrule stan*/
  68:             case C_RN: /*root en stan*/
  69:                 *i++ = c | ZBIT;
  70:             default:
  71:                 *i++ = makem(rem);
  72:         }
  73:     }
  74:     if(cnt){
  75:         *i++ = RPT;
  76:         *i++ = cnt;
  77:         *i++ = c;
  78:     }
  79: s1:
  80:     *i++ = 0;
  81:     eat(delim);
  82:     cp = cbuf;
  83: }
  84: 
  85: eat(c)
  86: int c;
  87: {
  88:     register i;
  89: 
  90:     while(((i = getch() & CMASK) != c) &&
  91:         (i != '\n'));
  92:     return(i);
  93: }
  94: setov(){
  95:     register i, j, k;
  96:     int *p, delim, o[NOV], w[NOV];
  97: 
  98:     if((delim = getch()) & MOT)return;
  99:         else delim &= CMASK;
 100:     for(k=0; (k<NOV) && ((j=(i = getch()) & CMASK) != delim) &&
 101:         (j != '\n'); k++){
 102:             o[k] = i;
 103:             w[k] = width(i);
 104:     }
 105:     o[k] = w[k] = 0;
 106:     if(o[0])for(j=1; j;){
 107:         j = 0;
 108:         for(k=1; o[k] ; k++){
 109:             if(w[k-1] < w[k]){
 110:                 j++;
 111:                 i = w[k];
 112:                 w[k] = w[k-1];
 113:                 w[k-1] = i;
 114:                 i = o[k];
 115:                 o[k] = o[k-1];
 116:                 o[k-1] = i;
 117:             }
 118:         }
 119:     }else return;
 120:     p = cbuf;
 121:     for(k=0; o[k]; k++){
 122:         *p++ = o[k];
 123:         *p++ = makem(-((w[k]+w[k+1])/2));
 124:     }
 125:     *p++ = makem(w[0]/2);
 126:     *p = 0;
 127:     cp = cbuf;
 128: }
 129:         /* stan,  escape sequences for the sanders
 130: 			  use \E'abc...' as in overstriking
 131: 			  this is an add on to nroff */
 132: 
 133: setesc(){
 134:     register i, j, k;
 135:     int *p, delim;
 136: 
 137:     if((delim = getch()) & MOT)return;
 138:         else delim =& CMASK;
 139:     p = cbuf;
 140:     while (((j=(i = getch()) & CMASK) != delim) && (j != '\n'))
 141:             *p++ = i | EBIT;
 142:     *p = 0;
 143:     cp = cbuf;
 144: }
 145: 
 146: setbra(){
 147:     register i, *j, k;
 148:     int cnt, delim, dwn;
 149: 
 150:     if((delim = getch()) & MOT)return;
 151:         else delim &= CMASK;
 152:     j = cbuf + 1;
 153:     cnt = 0;
 154:     dwn = Em | MOT | VMOT;
 155:     while(((k = (i = getch()) & CMASK) != delim) && (k != '\n') &&
 156:         (j <= (cbuf+NC-4))){
 157:         *j++ = i | ZBIT;
 158:         *j++ = dwn;
 159:         cnt++;
 160:     }
 161:     if(--cnt < 0)return;
 162:         else if (!cnt){
 163:             ch = *(j-2);
 164:             return;
 165:     }
 166:     *j = 0;
 167:     *--j = *cbuf = (cnt*Em)/2 | MOT | NMOT | VMOT;
 168:     *--j &= ~ZBIT;
 169:     cp = cbuf;
 170: }
 171: setvline(){
 172:     register i, c, *k;
 173:     int cnt, neg, rem, ver, delim, dflt;
 174: 
 175:     if((delim = getch()) & MOT)return;
 176:         else delim &= CMASK;
 177:     dfact = lss;
 178:     vflag++;
 179:     i = atoi();
 180:     dfact = 1;
 181:     if(!i){
 182:         eat(delim);
 183:         vflag = 0;
 184:         return;
 185:     }
 186: #define VBHEIGHT 101
 187:     if(((c = getch()) & CMASK) == delim){
 188:         /*
 189: 		 * In the default case, simulate box rule but do the motions
 190: 		 * by hand, to minimize motion commands to the printer.
 191: 		 */
 192:         dflt = 1;
 193:         c = C_VB|ZBIT;      /* single vertical line, sci-pi font */
 194:         ver = VBHEIGHT;     /* height of C_VB */
 195:     } else {
 196:         dflt = 0;
 197:         getch();
 198:         ver = Em;
 199:         c |= ZBIT;
 200:     }
 201:     neg = 0;
 202:     if(i < 0){
 203:         i = -i;
 204:         neg = NMOT;
 205:     }
 206:     cnt = utos(i)/utos(ver);
 207:     rem = i-(stou(cnt*utos(ver)));
 208:     rem = makem(rem) | neg;
 209:     ver = makem(ver) | neg;
 210:     vflag = 0;
 211:     k = cbuf;
 212:     if(!neg)*k++ = ver;
 213:     if (dflt)
 214:         *k++ = makem(-getcw(c)/2);
 215:     if(rem & ~MOTV){
 216:         *k++ = c;
 217:         *k++ = rem;
 218:     }
 219:     while((k < (cbuf+NC-3)) && cnt--){
 220:         *k++ = c;
 221:         *k++ = ver;
 222:     }
 223:     *(k-2) &= ~ZBIT;
 224:     if(!neg)k--;
 225:     if (dflt)
 226:         *k++ = makem(-getcw(c)/2);
 227:     *k = 0;
 228:     cp = cbuf;
 229: }
 230: casefc(){
 231:     register i;
 232: 
 233:     fc = IMP;
 234:     padc = ' ';
 235:     if(skip() ||
 236:        ((i = getch()) & MOT) ||
 237:        ((i &= CMASK) == '\n'))return;
 238:     fc = i;
 239:     if(skip() || (ch & MOT) || ((ch &= CMASK) == fc))return;
 240:     padc = ch;
 241: }
 242: setfield(x)
 243: int x;
 244: {
 245:     register i, j, *fp;
 246:     int length, ws, npad, temp, type;
 247:     int **pp, *padptr[NPP];
 248:     static int fbuf[FBUFSZ];
 249:     int savfc, savtc, savlc;
 250: 
 251:     if(x == tabch) rchar = tabc | chbits;
 252:     else if(x ==  ldrch) rchar = dotc | chbits;
 253:     temp = npad = ws = 0;
 254:     savfc = fc; savtc = tabch; savlc = ldrch;
 255:     tabch = ldrch = fc = IMP;
 256:     for(j=0;;j++){
 257:         if((tabtab[j] & TMASK)== 0){
 258:             if(x==savfc)prstr("Zero field width.\n");
 259:             j = 0;
 260:             goto rtn;
 261:         }
 262:         if((length = ((tabtab[j] & TMASK) - v.hp)) > 0 )break;
 263:     }
 264:     type = tabtab[j] & (~TMASK);
 265:     fp = fbuf;
 266:     pp = padptr;
 267:     if(x == savfc){while(1){
 268:         if(((j = (i = getch()) & CMASK)) == padc){
 269:             npad++;
 270:             *pp++ = fp;
 271:             if(pp > (padptr + NPP - 1))break;
 272:             goto s1;
 273:         }else if(j == savfc) break;
 274:             else if(j == '\n'){
 275:                 temp = j;
 276:                 nlflg = 0;
 277:                 break;
 278:             }
 279:         ws += width(i);
 280:     s1:
 281:         *fp++ = i;
 282:         if(fp > (fbuf + FBUFSZ -3))break;
 283:     }
 284:     if(!npad){
 285:         npad++;
 286:         *pp++ = fp;
 287:         *fp++ = 0;
 288:     }
 289:     *fp++ = temp;
 290:     *fp++ = 0;
 291:     temp = i = (j = length-ws)/npad;
 292:     if((j -= i*npad) <0)j = -j;
 293:     i = makem(i);
 294:     if(temp <0)i |= NMOT;
 295:     for(;npad > 0; npad--){
 296:         *(*--pp) = i;
 297:         if(j){
 298:             j -= HOR;
 299:             (*(*pp)) += HOR;
 300:         }
 301:     }
 302:     cp = fbuf;
 303:     j = 0;
 304:     }else if(type == 0){
 305:     /*plain tab or leader*/
 306:         if((j = width(rchar)) == 0)nchar = 0;
 307:         else{
 308:             nchar = length /j;
 309:             length %= j;
 310:         }
 311:         if(length)j = length | MOT;
 312:         else j = getch0();
 313:     }else{
 314:     /*center tab*/
 315:     /*right tab*/
 316:         while(((j = (i = getch()) & CMASK) != savtc) &&
 317:             (j != '\n') && (j != savlc)){
 318:             ws += width(i);
 319:             *fp++ = i;
 320:             if(fp > (fbuf +FBUFSZ - 3)) break;
 321:         }
 322:         *fp++ = i;
 323:         *fp++ = 0;
 324:         if(type == RTAB)length -= ws;
 325:         else length -= ws/2; /*CTAB*/
 326:         if(((j = width(rchar)) == 0) || (length <= 0))nchar = 0;
 327:         else{
 328:             nchar = length/j;
 329:             length %= j;
 330:         }
 331:         j = makem(length);
 332:         cp = fbuf;
 333:         nlflg = 0;
 334:     }
 335: rtn:
 336:     fc = savfc; tabch = savtc; ldrch = savlc;
 337:     return(j);
 338: }

Defined functions

casefc defined in line 230; used 2 times
eat defined in line 85; used 6 times
setbra defined in line 146; used 1 times
setesc defined in line 133; used 1 times
setfield defined in line 242; used 1 times
setline defined in line 34; used 1 times
setov defined in line 94; used 1 times
setvline defined in line 171; used 1 times
setz defined in line 28; used 1 times

Defined macros

VBHEIGHT defined in line 186; used 1 times
Last modified: 1982-04-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1180
Valid CSS Valid XHTML 1.0 Strict