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/fpradv.x | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 sys/fmtio/fpradv.x (limited to 'sys/fmtio/fpradv.x') diff --git a/sys/fmtio/fpradv.x b/sys/fmtio/fpradv.x new file mode 100644 index 00000000..942c29aa --- /dev/null +++ b/sys/fmtio/fpradv.x @@ -0,0 +1,76 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include +include +include + +# FPRADV -- Copy format chars to output until next "%w.dC" format sequence is +# encountered, or until EOS is encountered on format string. When EOS is +# encountered, return buffer containing format string, and if mem_flag is set, +# close the output file (a string) as well. If a format string contains no +# regular format sequences, and hence requires no PARG_ calls, we are all done. + +procedure fpradv() + +int i, junk, ival, ch +char cch +int ip_save +int ctoi(), cctoc() +include "fmt.com" +errchk putci + +begin + for (ch = format[ip]; ch != EOS; ch = format[ip]) { + cch = ch + if (ch == ESCAPE) { + junk = cctoc (format, ip, cch) + + } else if (ch == START_OF_FORMAT) { + if (format[ip+1] == START_OF_FORMAT) # '%%' --> '%' + ip = ip + 2 + + else if (IS_DIGIT (format[ip+1])) { # %Nw or %Nt + ip_save = ip # ip_save --> '%' + ip = ip + 1 + + junk = ctoi (format, ip, ival) + + switch (format[ip]) { + case FMT_WHITESPACE: # output blanks + do i = 1, ival + call putci (fd, BLANK) + col = col + ival + case FMT_TOCOLUMN: # advance to column + for (; col < ival; col=col+1) + call putci (fd, BLANK) + default: + ip = ip_save # regular format spec + return + } + + ip = ip + 1 # eat "t" or "w" + next + + } else + return # regular format spec + + } else + ip = ip + 1 + + call putc (fd, cch) # output ordinary chars + if (IS_PRINT (cch)) # keep track of column + col = col + 1 + else + call fmt_setcol (cch, col) + } + + switch (ofile_type) { # EOS of format reached + case STRING_FILE: + call close (fd) + case CL_PARAM: + call putline (CLOUT, "\"\n") + } + + ofile_type = REGULAR_FILE # restore default + fd = NULL +end -- cgit