37 lines
644 B
Plaintext
37 lines
644 B
Plaintext
|
proc printd(chan out, value fmt[], d)=
|
||
|
-- Like fprintf(out, fmt, d), with only %d or %<width>d in fmt[]
|
||
|
|
||
|
def otherwise=true:
|
||
|
var i, len:
|
||
|
seq
|
||
|
len:=fmt[byte 0]
|
||
|
i:=1
|
||
|
|
||
|
while i<=len
|
||
|
if
|
||
|
fmt[byte i] = '%'
|
||
|
var w:
|
||
|
seq
|
||
|
i:=i+1
|
||
|
w:=0
|
||
|
while (i<=len) and ('0'<=fmt[byte i]) and (fmt[byte i]<='9')
|
||
|
seq
|
||
|
w:=(w*10)+(fmt[byte i]-'0')
|
||
|
i:=i+1
|
||
|
if
|
||
|
i<=len
|
||
|
var key:
|
||
|
seq
|
||
|
key:=fmt[byte i]
|
||
|
if
|
||
|
key='d'
|
||
|
decout(out, d, w)
|
||
|
otherwise
|
||
|
out ! key
|
||
|
i:=i+1
|
||
|
otherwise
|
||
|
seq
|
||
|
out ! fmt[byte i]
|
||
|
i:=i+1
|
||
|
:
|