From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/fmtio/fmtstr.x | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sys/fmtio/fmtstr.x (limited to 'sys/fmtio/fmtstr.x') diff --git a/sys/fmtio/fmtstr.x b/sys/fmtio/fmtstr.x new file mode 100644 index 00000000..197ea2bd --- /dev/null +++ b/sys/fmtio/fmtstr.x @@ -0,0 +1,49 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include + +# FMTSTR -- Place a string in a field of the given width, left or right +# justifying as indicated, and output to the named file. The length of +# the text string may exceed the field width, in which case there is no +# filling. + +procedure fmtstr (fd, str, col, fill_char, left_justify, maxch, width) + +int fd # output file +char str[ARB] # string to be output +int col # column: both input and output parameter +char fill_char # fill character, if right justify +int left_justify # YES or NO +int maxch # maximum string chars to output +int width # field width +int nchars, nfill, ip +int strlen() +errchk putc, putci + +begin + if (fd <= 0) + return + + if (width > 0) { + nchars = min (maxch, strlen(str)) + nfill = max (0, width - nchars) + } else { + nchars = maxch + nfill = 0 # free format + } + + if (left_justify == NO) # fill at left + for (col=col+nfill; nfill > 0; nfill=nfill-1) + call putc (fd, fill_char) + + for (ip=1; str[ip] != EOS && ip <= nchars; ip=ip+1) { # put string + call putc (fd, str[ip]) + if (IS_PRINT (str[ip])) + col = col + 1 + else + call fmt_setcol (str[ip], col) + } + + for (col=col+nfill; nfill > 0; nfill=nfill-1) # fill at right + call putci (fd, ' ') +end -- cgit