diff options
Diffstat (limited to 'sys/fmtio/fmtsetcol.x')
-rw-r--r-- | sys/fmtio/fmtsetcol.x | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/fmtio/fmtsetcol.x b/sys/fmtio/fmtsetcol.x new file mode 100644 index 00000000..a8d06855 --- /dev/null +++ b/sys/fmtio/fmtsetcol.x @@ -0,0 +1,28 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <ctype.h> +include <printf.h> + +# FMT_SETCOL -- Called when a control character is output, to keep track of +# the column index during output, for the "%nt" (tabulate) format. Columns +# are indexed from the start of the printf, rather than in absolute units on +# the output, unless a \r or \n is output during the print. + +procedure fmt_setcol (ch, col) + +char ch +int col + +begin + switch (ch) { + case '\t': # next tab stop + col = ((col + TABSTOP-1) / TABSTOP) * TABSTOP + 1 + case '\n', '\r', '\f': + col = 1 + case '\b': + col = col - 1 + default: + if (IS_PRINT (ch)) + col = col + 1 + } +end |