# 2.11BSD#431 - /usr/src/lib/libc/pdp/stdio/doprnt.s

##### Functions

    __doprnt          X

       1: /*
       2:  * Copyright (c) 1987 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #ifdef LIBC_SCCS
       8: /*	<@(#)doprnt.s	5.4 (Berkeley) 1/25/87\0> */
       9:         <@(#)doprnt.s	5.6 (2.11BSD GTE) 2/02/95\0>
      10:         .even
      11: #endif LIBC_SCCS
      12:
      13: /*
      14:  * doprnt(fmt, argl, iop)
      15:  *	char	*fmt, *argl;
      16:  *	FILE	*iop;
      17:  *
      18:  * Output argl to iop using fmt - implements printf, etc.
      19:  */
      20: #include "DEFS.h"
      21:
      22:         .data
      23: swtab:
      24:         decimal;        'd
      25:         octal;          'o
      26:         hex;            'x
      27:         float;          'f
      28:         scien;          'e
      29:         general;        'g
      30:         charac;         'c
      31:         string;         's
      32:         longorunsg;     'l
      33:         longorunsg;     'L
      34:         unsigned;       'u
      35:         long;           'D
      36:         loct;           'O
      37:         lhex;           'X
      38:         lunsigned;      'U
      39:         0;  0
      40: .text
      41:
      42: .globl  __strout, csv, cret
      43: .globl  pgen, pfloat, pscien
      44:
      45: width   = -10.
      46: formp   = -12.
      47: rjust   = -14.
      48: ndfnd   = -16.
      49: ndigit  = -18.
      50: zfill   = -20.
      51:
      52: ENTRY(_doprnt)
      53:         jsr     r5,csv
      54:         sub     $300.+12.,sp            / was 128.
      55:         mov     4(r5),formp(r5)         / format
      56:         mov     6(r5),r4
      57: loop:
      58:         mov     sp,r3
      59:         mov     formp(r5),r1
      60: 2:
      61:         movb    (r1)+,r2
      62:         beq     2f
      63:         cmp     r2,$'%
      64:         beq     2f
      65:         movb    r2,(r3)+
      66:         br      2b
      67: 2:
      68:         mov     r1,formp(r5)
      69:         cmp     r3,sp
      70:         beq     2f
      71:         mov     sp,r0
      72:         mov     8(r5),-(sp)
      73:         clr     -(sp)
      74:         mov     r0,-(sp)        / string
      75:         mov     r3,-(sp)        / count
      76:         sub     r0,(sp)
      77:         jsr     pc,__strout
      78:         add     $8,sp
      79: 2:
      80:         tst     r2
      81:         bne     2f
      82:         jmp     cret
      83: 2:
      84:         mov     sp,r3
      85: 2:
      86:         clr     rjust(r5)
      87:         clr     ndigit(r5)
      88:         mov     $' ,zfill(r5)
      89:         cmpb    *formp(r5),$'-
      90:         bne     2f
      91:         inc     formp(r5)
      92:         inc     rjust(r5)
      93: 2:
      94:         cmpb    *formp(r5),$'0
      95:         bne     2f
      96:         mov     $'0,zfill(r5)
      97: 2:
      98:         jsr     r3,gnum
      99:         mov     r1,width(r5)
     100:         clr     ndfnd(r5)
     101:         cmp     r0,$'.
     102:         bne     1f
     103:         jsr     r3,gnum
     104:         mov     r1,ndigit(r5)
     105: 1:
     106:         mov     $swtab,r1
     107: 1:
     108:         mov     (r1)+,r2
     109:         bne     2f
     110:         movb    r0,(r3)+
     111:         jmp     prbuf
     112: 2:
     113:         cmp     r0,(r1)+
     114:         bne     1b
     115:         jmp     (r2)
     116:
     117: general:
     118:         mov     ndigit(r5),r0
     119:         mov     ndfnd(r5),r2
     120:         jsr     pc,pgen
     121:         jbr     prbuf
     122:
     123: longorunsg:
     124:         movb    *formp(r5),r0
     125:         inc     formp(r5)
     126:         cmp     r0,$'o
     127:         beq     loct
     128:         cmp     r0,$'x
     129:         beq     lhex
     130:         cmp     r0,$'d
     131:         beq     long
     132:         cmp     r0,$'u
     133:         beq     lunsigned
     134:         dec     formp(r5)
     135:         br      unsigned
     136:
     137: octal:
     138:         clr     r0
     139:         br      1f
     140: loct:
     141:         mov     (r4)+,r0
     142: 1:
     143:         mov     $8.,r2
     144:         br      2f
     145:
     146: hex:
     147:         clr     r0
     148:         br      1f
     149:
     150: lhex:
     151:         mov     (r4)+,r0
     152: 1:
     153:         mov     $16.,r2
     154: 2:
     155:         mov     (r4)+,r1
     156:         br      compute
     157:
     158: decimal:
     159:         mov     (r4)+,r1
     160:         sxt     r0
     161:         bmi     3f
     162:         br      2f
     163:
     164: unsigned:
     165:         clr     r0
     166:         br      1f
     167:
     168: long:
     169:         mov     (r4)+,r0
     170:         bge     1f
     171:         mov     (r4)+,r1
     172: 3:
     173:         neg     r0
     174:         neg     r1
     175:         sbc     r0
     176:         movb    $'-,(r3)+
     177:         br      2f
     178:
     179: lunsigned:
     180:         mov     (r4)+,r0
     181: 1:
     182:         mov     (r4)+,r1
     183: 2:
     184:         mov     $10.,r2
     185:
     186: /*
     187:  * Algorithm courtesy Keith Davis
     188:  */
     189: compute:
     190:         mov     r5,-(sp)
     191:         mov     r4,-(sp)
     192:         mov     r0,r4
     193:         mov     ndigit(r5),r0
     194:         mov     r1,r5
     195:         ashc    $0,r4
     196:         beq     1f
     197:         tst     r0
     198:         beq     1f
     199:         movb    $'0,(r3)+
     200: 1:
     201:         jsr     pc,1f
     202:         mov     (sp)+,r4
     203:         mov     (sp)+,r5
     204:         br      prbuf
     205:
     206: 1:
     207:         clr     r0
     208:         mov     r4,r1
     209:         beq     2f
     210:         div     r2,r0
     211:         mov     r0,r4
     212:         mov     r1,r0
     213: 2:
     214:         mov     r5,r1
     215:         asl     r2
     216:         div     r2,r0
     217:         asr     r2
     218:         asl     r0
     219:         cmp     r2,r1
     220:         bgt     2f
     221:         sub     r2,r1
     222:         inc     r0
     223: 2:
     224:         mov     r1,-(sp)
     225:         mov     r0,r5
     226:         bne     2f
     227:         tst     r4
     228:         beq     1f
     229: 2:
     230:         jsr     pc,1b
     231: 1:
     232:         mov     (sp)+,r0
     233:         add     $'0,r0
     234:         cmp     r0,$'9
     235:         ble     1f
     236:         add     $'a-'0-10.,r0
     237: 1:
     238:         movb    r0,(r3)+
     239:         rts     pc
     240:
     241: charac:
     242:         mov     $' ,zfill(r5)
     243:         mov     (r4)+,r0
     244:         movb    r0,(r3)+
     245:         br      prbuf
     246:
     247: string:
     248:         mov     $' ,zfill(r5)
     249:         mov     ndigit(r5),r1
     250:         mov     (r4),r2
     251:         mov     r2,r3
     252: 1:
     253:         tstb    (r2)+
     254:         beq     1f
     255:         inc     r3
     256:         sob     r1,1b
     257: 1:
     258:         mov     (r4)+,r2
     259:         br      prstr
     260:
     261: float:
     262:         mov     ndigit(r5),r0
     263:         mov     ndfnd(r5),r2
     264:         jsr     pc,pfloat
     265:         br      prbuf
     266:
     267: scien:
     268:         mov     ndigit(r5),r0
     269:         inc     r0
     270:         tst     ndfnd(r5)
     271:         bne     1f
     272:         mov     $7,r0
     273: 1:
     274:         mov     pc,r2
     275:         jsr     pc,pscien
     276:
     277: prbuf:
     278:         mov     sp,r2
     279: prstr:
     280:         sub     r2,r3
     281:         mov     width(r5),r1
     282:         sub     r3,r1
     283:         bge     1f
     284:         clr     r1
     285: 1:
     286:         tst     rjust(r5)
     287:         bne     1f
     288:         neg     r1
     289: 1:
     290:         mov     zfill(r5),-(sp)
     291:         mov     8(r5),-(sp)
     292:         mov     r1,-(sp)
     293:         mov     r2,-(sp)        / string
     294:         mov     r3,-(sp)        / count
     295:         jsr     pc,__strout
     296:         add     $10.,sp
     297:         jmp     loop
     298:
     299: gnum:
     300:         clr     ndfnd(r5)
     301:         clr     r1
     302: 1:
     303:         movb    *formp(r5),r0
     304:         inc     formp(r5)
     305:         sub     $'0,r0
     306:         cmp     r0,$'*-'0
     307:         bne     2f
     308:         mov     (r4)+,r0
     309:         br      3f
     310: 2:
     311:         cmp     r0,$9.
     312:         bhi     1f
     313: 3:
     314:         inc     ndfnd(r5)
     315:         mul     $10.,r1
     316:         add     r0,r1
     317:         br      1b
     318: 1:
     319:         add     $'0,r0
     320:         rts     r3

#### Defined functions

__doprnt defined in line 52; used 19 times

- in /usr/src/games/cribbage/io.c line 441
- in /usr/src/lib/libc/stdio/fprintf.c line 23, 30
- in /usr/src/lib/libc/stdio/printf.c line 10
- in /usr/src/lib/libc/stdio/sprintf.c line 33
- in /usr/src/lib/libc/stdio/vfprintf.c line 37, 44
- in /usr/src/lib/libc/stdio/vprintf.c line 32
- in /usr/src/lib/libc/stdio/vsprintf.c line 35
- in /usr/src/new/rcs/src/rcslex.c line 652
- in /usr/src/new/rcs/src/sccstorcs.c line 81
- in /usr/src/ucb/ftp/ftp.c line 291-294(2), 307-310(2)
- in /usr/src/ucb/vacation.c line 409, 431
- in /usr/src/ucb/window/wwprintf.c line 31
- in /usr/src/usr.lib/libcurses/printw.c line 58

charac defined in line 241; used 1 times

- in line 30

compute defined in line 189; used 1 times

- in line 156

decimal defined in line 158; used 1 times

- in line 24

float defined in line 261; used 1 times

- in line 27

formp defined in line 46; used 11 times

- in line 55-59(2), 68, 89-94(3), 124-125(2), 134, 303-304(2)

general defined in line 117; used 1 times

- in line 29

gnum defined in line 299; used 2 times

- in line 98-103(2)

hex defined in line 146; used 1 times

- in line 26

lhex defined in line 150; used 2 times

- in line 37, 129

loct defined in line 140; used 2 times

- in line 36, 127

long defined in line 168; used 2 times

- in line 35, 131

longorunsg defined in line 123; used 2 times

- in line 32-33(2)

loop defined in line 57; used 1 times

- in line 297

lunsigned defined in line 179; used 2 times

- in line 38, 133

ndfnd defined in line 48; used 6 times

- in line 100, 119, 263, 270, 300, 314

ndigit defined in line 49; used 7 times

- in line 87, 104, 118, 193, 249, 262, 268

octal defined in line 137; used 1 times

- in line 25

prbuf defined in line 277; used 5 times

- in line 111, 121, 204, 245, 265

prstr defined in line 279; used 1 times

- in line 259

rjust defined in line 47; used 3 times

- in line 86, 92, 286

scien defined in line 267; used 1 times

- in line 28

string defined in line 247; used 1 times

- in line 31

unsigned defined in line 164; used 2 times

- in line 34, 135

width defined in line 45; used 2 times

- in line 99, 281

zfill defined in line 50; used 5 times

- in line 88, 96, 242, 248, 290

#### Defined variables

swtab defined in line 23; used 1 times

- in line 106

Last modified: 1995-02-03 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1126 |