# 2.11BSD#431 - /usr/src/bin/adb/format.c

##### Functions

    exform            X
    inkdot            X
    printesc          X
    scanform          X
    unox              X

##### Variables

    ADWRAP            X
    BADMOD            X
    NOFORK            X
    dot               X
    dotinc            X
    errflg            X
    lastc             X
    lp                X
    maxoff            X
    mkfault           X
    printbuf          X
    printptr          X
    sigint            X
    sigqit            X
    var               X

       1: #include "defs.h"
       2: #include <ctype.h>
       3:
       4:     MSG BADMOD;
       5:     MSG NOFORK;
       6:     MSG ADWRAP;
       7: extern  struct  SYMbol  *symbol;
       8:     int mkfault;
       9:     char    *lp;
      10:     char    *printptr, printbuf[];
      11:     int maxoff;
      12:     int sigint;
      13:     int sigqit;
      14:     char    *errflg;
      15:     char    lastc;
      16:     long    dot;
      17:     int dotinc;
      18:     long    var[];
      19:
      20: scanform(icount,ifp,itype,ptype)
      21:     long    icount;
      22:     char    *ifp;
      23: {
      24:     char    *fp;
      25:     char    modifier;
      26:     int fcount, init=1;
      27:     long    savdot;
      28:
      29:     WHILE icount
      30:     DO  fp=ifp;
      31:         IF init==0 ANDF findsym(shorten(dot),ptype)==0 ANDF maxoff
      32:         THEN printf("\n%s:%16t", cache_sym(symbol));
      33:         FI
      34:         savdot=dot; init=0;
      35:
      36:         /*now loop over format*/
      37:         WHILE *fp ANDF errflg==0
      38:         DO  IF isdigit(modifier = *fp)
      39:         THEN fcount=0;
      40:              WHILE isdigit(modifier = *fp++)
      41:              DO fcount *= 10;
      42:             fcount += modifier-'0';
      43:              OD
      44:              fp--;
      45:         ELSE fcount=1;
      46:         FI
      47:
      48:         IF *fp==0 THEN break; FI
      49:         fp=exform(fcount,fp,itype,ptype);
      50:         OD
      51:         dotinc=dot-savdot;
      52:         dot=savdot;
      53:
      54:         IF errflg
      55:         THEN IF icount<0
      56:          THEN errflg=0; break;
      57:          ELSE error(errflg);
      58:          FI
      59:         FI
      60:         IF --icount
      61:         THEN dot=inkdot(dotinc);
      62:         FI
      63:         IF mkfault THEN error((char *)0); FI
      64:     OD
      65: }
      66:
      67: char *
      68: exform(fcount,ifp,itype,ptype)
      69:     int fcount;
      70:     char    *ifp;
      71:     int itype, ptype;
      72: {
      73:     /* execute single format item `fcount' times
      74: 	 * sets `dotinc' and moves `dot'
      75: 	 * returns address of next format item
      76: 	 */
      77:     u_int   w;
      78:     long    savdot, wx;
      79:     char    *fp;
      80:     char    c, modifier, longpr;
      81:     struct  {
      82:         long    sa;
      83:         int sb,sc;
      84:         } fw;
      85:
      86:     WHILE fcount>0
      87:     DO  fp = ifp; c = *fp;
      88:         longpr=(c>='A')&(c<='Z')|(c=='f');
      89:         IF itype==NSP ORF *fp=='a'
      90:         THEN wx=dot; w=dot;
      91:         ELSE w=get(dot,itype);
      92:              IF longpr
      93:              THEN wx=itol(w,get(inkdot(2),itype));
      94:              ELSE wx=w;
      95:              FI
      96:         FI
      97:         IF c=='F'
      98:         THEN fw.sb=get(inkdot(4),itype);
      99:              fw.sc=get(inkdot(6),itype);
     100:         FI
     101:         IF errflg THEN return(fp); FI
     102:         IF mkfault THEN error((char *)0); FI
     103:         var[0]=wx;
     104:         modifier = *fp++;
     105:         dotinc=(longpr?4:2);;
     106:
     107:         if (!(printptr - printbuf) && modifier != 'a')
     108:             printf("%16m");
     109:
     110:         switch(modifier) {
     111:
     112:             case SP: case TB:
     113:             break;
     114:
     115:             case 't': case 'T':
     116:             printf("%T",fcount); return(fp);
     117:
     118:             case 'r': case 'R':
     119:             printf("%M",fcount); return(fp);
     120:
     121:             case 'a':
     122:             psymoff(dot,ptype,":%16t"); dotinc=0; break;
     123:
     124:             case 'p':
     125:             psymoff(var[0],ptype,"%16t"); break;
     126:
     127:             case 'u':
     128:             printf("%-8u",w); break;
     129:
     130:             case 'U':
     131:             printf("%-16U",wx); break;
     132:
     133:             case 'c': case 'C':
     134:             IF modifier=='C'
     135:             THEN printesc(w&LOBYTE);
     136:             ELSE printc(w&LOBYTE);
     137:             FI
     138:             dotinc=1; break;
     139:
     140:             case 'b': case 'B':
     141:             printf("%-8o", w&LOBYTE); dotinc=1; break;
     142:
     143:             case 's': case 'S':
     144:             savdot=dot; dotinc=1;
     145:             WHILE (c=get(dot,itype)&LOBYTE) ANDF errflg==0
     146:             DO dot=inkdot(1);
     147:                IF modifier == 'S'
     148:                THEN printesc(c);
     149:                ELSE printc(c);
     150:                FI
     151:                endline();
     152:             OD
     153:             dotinc=dot-savdot+1; dot=savdot; break;
     154:
     155:             case 'x':
     156:             printf("%-8x",w); break;
     157:
     158:             case 'X':
     159:             printf("%-16X", wx); break;
     160:
     161:             case 'Y':
     162:             printf("%-24Y", wx); break;
     163:
     164:             case 'q':
     165:             printf("%-8q", w); break;
     166:
     167:             case 'Q':
     168:             printf("%-16Q", wx); break;
     169:
     170:             case 'o':
     171:             case 'w':
     172:             printf("%-8o", w); break;
     173:
     174:             case 'O':
     175:             case 'W':
     176:             printf("%-16O", wx); break;
     177:
     178:             case 'i':
     179:             printins(itype,w); printc(EOR); break;
     180:
     181:             case 'd':
     182:             printf("%-8d", w); break;
     183:
     184:             case 'D':
     185:             printf("%-16D", wx); break;
     186:
     187:             case 'f':
     188:             *(double *)&fw = 0.0;
     189:             fw.sa = wx;
     190:             printf("%-16.9f", *(double *)&fw);
     191:             dotinc=4; break;
     192:
     193:             case 'F':
     194:             fw.sa = wx;
     195:             printf("%-32.18F", *(double *)&fw);
     196:             dotinc=8; break;
     197:
     198:             case 'n': case 'N':
     199:             printc('\n'); dotinc=0; break;
     200:
     201:             case '"':
     202:             dotinc=0;
     203:             WHILE *fp != '"' ANDF *fp
     204:             DO printc(*fp++); OD
     205:             IF *fp THEN fp++; FI
     206:             break;
     207:
     208:             case '^':
     209:             dot=inkdot(-dotinc*fcount); return(fp);
     210:
     211:             case '+':
     212:             dot=inkdot(fcount); return(fp);
     213:
     214:             case '-':
     215:             dot=inkdot(-fcount); return(fp);
     216:
     217:             default: error(BADMOD);
     218:         }
     219:         IF itype!=NSP
     220:         THEN    dot=inkdot(dotinc);
     221:         FI
     222:         fcount--; endline();
     223:     OD
     224:
     225:     return(fp);
     226: }
     227:
     228: unox()
     229: {
     230:     int rc, status, unixpid;
     231:     char    *argp = lp;
     232:
     233:     WHILE lastc!=EOR DO rdc(); OD
     234:     IF (unixpid=fork())==0
     235:     THEN    signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
     236:         *lp=0; execl("/bin/sh", "sh", "-c", argp, 0);
     237:         exit(16);
     238:     ELIF unixpid == -1
     239:     THEN    error(NOFORK);
     240:     ELSE    signal(SIGINT,SIG_IGN);
     241:         WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE
     242:         signal(SIGINT,sigint);
     243:         printc('!'); lp--;
     244:     FI
     245: }
     246:
     247:
     248: printesc(c)
     249: {
     250:     c &= STRIP;
     251:     IF c<SP ORF c>'~' ORF c=='@'
     252:     THEN printf("@%c",(c=='@' ? '@' : c^0140));
     253:     ELSE printc(c);
     254:     FI
     255: }
     256:
     257: long
     258: inkdot(incr)
     259: {
     260:     long    newdot;
     261:
     262:     newdot=dot+incr;
     263:     IF (dot ^ newdot) >> 24 THEN error(ADWRAP); FI
     264:     return(newdot);
     265: }

#### Defined functions

exform defined in line 67; used 4 times

- in line 49
- in /usr/src/bin/adb/command.c line 144, 151
- in /usr/src/bin/adb/defs.h line 192

inkdot defined in line 257; used 20 times

- in line 61, 93-99(3), 146, 209-220(4)
- in /usr/src/bin/adb/command.c line 68, 128-131(2), 149
- in /usr/src/bin/adb/defs.h line 188
- in /usr/src/bin/adb/expr.c line 198-201(2)
- in /usr/src/bin/adb/opset.c line 398(2), 404, 449

printesc defined in line 248; used 2 times

- in line 135, 148

scanform defined in line 20; used 1 times

- in /usr/src/bin/adb/command.c line 171

unox defined in line 228; used 1 times

- in /usr/src/bin/adb/command.c line 192

#### Defined variables

ADWRAP defined in line 6; used 1 times

- in line 263

BADMOD defined in line 4; used 1 times

- in line 217

NOFORK defined in line 5; used 1 times

- in line 239

dot defined in line 16; used 20 times

- in line 31-34(2), 51-52(2), 61, 90-91(3), 122, 144-146(3), 153(2), 209-220(4), 262-263(2)

dotinc defined in line 17; used 14 times

- in line 51, 61, 105, 122, 138-144(3), 153, 191-202(4), 209, 220

errflg defined in line 14; used 6 times

- in line 37, 54-57(3), 101, 145

lastc defined in line 15; used 1 times

- in line 233

lp defined in line 9; used 3 times

- in line 231-236(2), 243

maxoff defined in line 11; used 1 times

- in line 31

mkfault defined in line 8; used 2 times

- in line 63, 102

printbuf defined in line 10; used 1 times

- in line 107

printptr defined in line 10; used 1 times

- in line 107

sigint defined in line 12; used 2 times

- in line 235, 242

sigqit defined in line 13; used 1 times

- in line 235

var defined in line 18; used 2 times

- in line 103, 125

Last modified: 1994-01-13 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 909 |