Annotation of researchv10no/cmd/lcc/tst/stdarg.c, revision 1.1

1.1     ! root        1: #include <stdarg.h>
        !             2: 
        !             3: struct node { int a[4]; } x = {1,2,3,4};
        !             4: 
        !             5: print(char *fmt, ...);
        !             6: 
        !             7: main() {
        !             8:        print("test 1\n");
        !             9:        print("test %s\n", "2");
        !            10:        print("test %d%c", 3, '\n');
        !            11:        print("%s%s %w%c", "te", "st", 4, '\n');
        !            12:        print("%s%s %f%c", "te", "st", 5.0, '\n');
        !            13:        print("%b %b %b %b %b %b\n", x, x, x, x, x, x);
        !            14: }
        !            15: 
        !            16: print(char *fmt, ...) {
        !            17:        va_list ap;
        !            18: 
        !            19:        va_start(ap, fmt);
        !            20:        for (; *fmt; fmt++)
        !            21:                if (*fmt == '%')
        !            22:                        switch (*++fmt) {
        !            23:                        case 'b': {
        !            24:                                struct node x = va_arg(ap, struct node);
        !            25:                                printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]);
        !            26:                                break;
        !            27:                                }
        !            28:                        case 'c':
        !            29:                                printf("%c", va_arg(ap, char));
        !            30:                                break;
        !            31:                        case 'd':
        !            32:                                printf("%d", va_arg(ap, int));
        !            33:                                break;
        !            34:                        case 'w':
        !            35:                                printf("%x", va_arg(ap, short));
        !            36:                                break;
        !            37:                        case 's':
        !            38:                                printf("%s", va_arg(ap, char *));
        !            39:                                break;
        !            40:                        case 'f':
        !            41:                                printf("%f", va_arg(ap, double));
        !            42:                                break;
        !            43:                        default:
        !            44:                                printf("%c", *fmt);
        !            45:                                break;
        !            46:                        }
        !            47:                 else
        !            48:                        printf("%c", *fmt);
        !            49:        va_end(ap);
        !            50: }

unix.superglobalmegacorp.com

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