home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
cug
/
softt-12.lbr
/
PRINTF.RQT
/
PRINTF.RAT
Wrap
Text File
|
1984-07-05
|
6KB
|
197 lines
#-h- printf.r 5671 local 01/05/81 22:36:40
#-h- printf 3471 local 01/05/81 21:59:14
##printf--print arguments according to s
subroutine printf(fd,s,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
character s(ARB)
integer myllc, a(ARB), ctoi, length, rtoc, xtoc
integer arg(9)
integer fd, i, j, c, w, p, ap, len
integer buf(MAXCHARS)
character fmt(ARB)
arg(1) = arg1
arg(2) = arg2
arg(3) = arg3
arg(4) = arg4
arg(5) = arg5
arg(6) = arg6
arg(7) = arg7
arg(8) = arg8
arg(9) = arg9
ap = 1
if (s(1) > 127 | s(1) < 0) {
for (i = 1; myllc(fmt(i),s,i-1) != 0; i = i + 1)
;
fmt(i) = EOS
}
else
call scopy(s, 1, fmt, 1)
for (i = 1; fmt(i) != EOS; i = i + 1) {
c = fmt(i)
if (c == BAR) { # special character
i = i + 1
c = fmt(i)
if (c == DIG0)
return
else if (c == LETT | c == BIGT)
c = TAB
else if (c == LETN | c == BIGN)
c = NEWLINE
else if (c == LETB | c == BIGB)
c = BACKSPACE
call putch(c, fd)
}
else if (c != PERCENT) #ordinary character
call putch(c, fd)
else { #format code
i = i + 1
w = ctoi(fmt, i)
if (fmt(i) == PERIOD) {
i = i + 1
p = ctoi(fmt, i)
}
else
p = -1
c = fmt(i)
if (c == LETD | c == BIGD)
{
call remark('we think it is a decimal.')
call putint(arg(ap), w, fd)
}
else if (c == LETO | c == BIGO) { # %wo print octal integer
len = xtoc(arg(ap), buf, MAXCHARS, 8)
call putstr(buf, w, fd)
}
else if (c == LETX | c == BIGX) { # %w.bx print integer in base b
if (p < 2 | p > 36) # default is hex
p = 16
len = xtoc(arg(ap), buf, MAXCHARS, p)
call putstr(buf, w, fd)
}
else if (c == LETS | c == BIGS) { # %ws print string
call locarg(ap,argout,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
if (arg(ap) <= 127 & arg(ap) > 0) # unpacked string
len = length(argout)
else # packed string
for (len=0; myllc(c,argout,len) != 0; len = len+1)
if (c == BAR)
if (myllc(c, argout, len+1) == DIG0)
break
if (p > 0 & p < len) # truncate if precision given
len = p
for ( ; w > len; w = w - 1)
call putch(BLANK, fd)
if (arg(ap) <= 127 & arg(ap) > 0) # unpacked string
for (j = 0; j < len; j = j + 1)
call putch(argout,fd)
else # packed string
for (j = 0; j < len; j = j + 1)
call putch(myllc(c, argout,j), fd)
for ( ; w < -len; w = w + 1)
call putch(BLANK, fd)
}
else if (c == LETF | c == BIGF) { # %w.df print real number
if (p == -1) # default precision is 666
p = 6
len = rtoc(arg(ap), buf, p, MAXCHARS)
call putstr(buf, w, fd)
}
else if (c == LETE | c == BIGE) { # %w.de print real number
if (p == -1)
p = 6
len = rtoc(arg(ap), buf, -p, MAXCHARS) # force e format
call putstr(buf, w, fd)
}
else if (c == LETC | c == BIGC) { # %wc print character
for ( ; w > 1; w = w - 1)
call putch(BLANK, fd)
if (arg(ap) <= 127 & arg(ap) > 0)
call putch(arg(ap),fd)
else
call putch(myllc(c, arg(ap), 0), fd)
for ( ; w < -1; w = w + 1)
call putch(BLANK,fd)
}
else if (c == LETN | c == BIGN) # %n change output file
fd = arg(ap)
else { # funny code
call putch(c, fd)
next
}
ap = ap + 1
}
}
return
end
#-t- printf 3471 local 01/05/81 21:59:14
#-h- xtoc 716 local 01/05/81 21:59:15
# xtoc - convert integer int to char string in str in base b
integer function xtoc(int, str, size, b)
integer abs, mod
integer i, int, intval, j, k, size, b
character str(ARB)
intval = abs(int)
str(1) = EOS
i = 1
repeat { # generate digits
i = i + 1
str(i) = DIG0 + mod(intval, b)
if (b > 10)
str(i) = str(i) + LETA - DIG9 - 1
intval = intval / b
} until (intval == 0 | i >= size)
if (int < 0 & i < size) { # then sign
i = i + 1
str(i) = MINUS
}
xtoc = i - 1
for (j = 1; j < i; j = j + 1) { # then reverse
k = str(i)
str(i) = str(j)
str(j) = k
i = i - 1
}
return
end
#-t- xtoc 716 local 01/05/81 21:59:15
#-h- myllc 142 local 01/05/81 21:59:15
##myllc puts the ith character (base-0) of a into c
integer function myllc(c,a,i)
character a(ARB), c
integer i
c = a(i+1)
myllc = c
end
#-t- myllc 142 local 01/05/81 21:59:15
#-h- locarg 388 local 01/05/81 21:59:16
##locarg--finds the ith argument writes it to argout
subroutine locarg(ap,argout,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
integer ap,argout(ARB),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
if (ap == 1)
call scopy(arg1,1,argout,1)
else if(ap == 2)
call scopy(arg2,1,argout,1)
else if(ap == 3)
call scopy(arg3,1,argout,1)
else if(ap == 4)
call scopy(arg4,1,argout,1)
else if (ap == 5)
call scopy(arg5,1,argout,1)
else if (ap == 6)
call scopy(arg6,1,argout,1)
else if (ap == 7)
call scopy(arg7,1,argout,1)
else if (ap == 8)
call scopy(arg8,1,argout,1)
else if (ap == 9)
call scopy(arg9,1,argout,1)
else argout(1) = EOS
return
end
#-t- locarg 388 local 01/05/81 21:59:16
#-t- printf.r 5671 local 01/05/81 22:36:40
#-t- printf.lbl 9621 local 01/05/81 22:41:16