ack/lang/occam/headers/printd.ocm
dtrg 5c5f711cbb Done a major overhaul of the way target include files are installed and
how platform libraries are built. The ARCH pm variable has now been
renamed PLATFORM (which is more accurate) and a different ARCH
variable added, which represents the CPU family rather than the
hardware platform.
2007-02-20 00:46:10 +00:00

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
: