ack/lang/occam/headers/prints.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

41 lines
769 B
Plaintext

proc prints(chan out, value fmt[], str[]) =
-- Like fprintf(out, fmt, str), with only %s or %<width>s 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='s'
seq
seq i=[0 for w-str[byte 0]]
out ! ' '
seq i=[0 for str[byte 0]]
out ! str[byte i]
otherwise
out ! key
i:=i+1
otherwise
seq
out ! fmt[byte i]
i:=i+1
: