Annotation of coherent/d/bin/bc/output.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include "bc.h"
        !             3: 
        !             4: 
        !             5: /*
        !             6:  *     The int left is equal to the number of columns left on the
        !             7:  *     output line.
        !             8:  */
        !             9: 
        !            10: static int     left = LINELEN;
        !            11: 
        !            12: 
        !            13: /*
        !            14:  *     Pstring is used to print a string onto the standard output,
        !            15:  *     maintaining the number of characters left on the line in
        !            16:  *     left.  `field' is the minimum number of characters to be used.
        !            17:  *     Padding is zeros on the left.
        !            18:  */
        !            19: 
        !            20: pstring(str, field)
        !            21: register char  *str;
        !            22: int            field;
        !            23: {
        !            24:        register int    len;
        !            25:        static char newln[] = "\\\n";
        !            26: 
        !            27:        if (field == 0) {
        !            28:                while (*str != 0) {
        !            29:                        if (*str == '\t') {
        !            30:                                if (left & 7)
        !            31:                                        left &= ~7;
        !            32:                                else
        !            33:                                        left -= 8;
        !            34:                                if (left <= 0) {
        !            35:                                        left = LINELEN - 8;
        !            36:                                        printf(newln);
        !            37:                                }
        !            38:                                putchar(*str++);
        !            39:                        } else {
        !            40:                                putchar(*str++);
        !            41:                                if (--left == 0) {
        !            42:                                        left = LINELEN;
        !            43:                                        printf(newln);
        !            44:                                }
        !            45:                        }
        !            46:                }
        !            47:        } else {
        !            48:                len = strlen(str);
        !            49:                if (field < len)
        !            50:                        field = len;
        !            51:                if (left < field && field <= LINELEN) {
        !            52:                        printf(newln);
        !            53:                        left = LINELEN;
        !            54:                }
        !            55:                for (field -= len; field != 0; --field) {
        !            56:                        putchar('0');
        !            57:                        if (--left == 0) {
        !            58:                                left = LINELEN;
        !            59:                                printf(newln);
        !            60:                        }
        !            61:                }
        !            62:                for (; left < len; len -= left) {
        !            63:                        printf("%.*s\\\n", left, str);
        !            64:                        str += left;
        !            65:                        left = LINELEN;
        !            66:                }
        !            67:                printf("%s", str);
        !            68:                left -= len;
        !            69:        }
        !            70: }
        !            71: 
        !            72: 
        !            73: /*
        !            74:  *     Pnewln prints out a newline on standard output, updateing
        !            75:  *     left.
        !            76:  */
        !            77: 
        !            78: pnewln()
        !            79: {
        !            80:        putchar('\n');
        !            81:        left = LINELEN;
        !            82: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.