Annotation of coherent/g/usr/bin/me/detab.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Turn tabs to spaces.
                      3:  */
                      4: #include <stdio.h>
                      5: 
                      6: main(argc, argv)
                      7: char **argv;
                      8: {
                      9:        extern char *getenv();
                     10:        register int tabsiz, loc, to, c;
                     11:        char *env;
                     12: 
                     13:        switch (argc) {
                     14:        case 1:         /* no argument */
                     15:                tabsiz = ((NULL == (env = getenv("TABSIZ"))) ? 8 : atoi(env));
                     16:                break;
                     17:        case 2:         /* 1 argument */
                     18:                tabsiz = atoi(argv[1]);
                     19:                break;
                     20:        default:
                     21:                fprintf(stderr, "usage: detab [tabsize]\n");
                     22:                exit(1);
                     23:        }
                     24: 
                     25:        if (tabsiz < 2 || tabsiz > 256) {
                     26:                fprintf(stderr, "detab: %d is illegal tab size\n", tabsiz);
                     27:                fprintf(stderr, "usage: detab [tabsize]\n");
                     28:                exit(1);
                     29:        }
                     30: 
                     31:        for (loc = 0;;) {
                     32:                switch (c = getchar()) {
                     33:                case EOF:
                     34:                        exit(0);
                     35:                case '\n':
                     36:                case '\r':
                     37:                        loc = -1;       /* next char will be at 0 */
                     38:                        break;
                     39:                case '\a':
                     40:                        loc--;          /* alarm takes no space */
                     41:                        break;
                     42:                case '\b':
                     43:                        loc -= 2;       /* backspace */
                     44:                        break;
                     45:                case '\t':              /* space to the spot */
                     46:                        for (to = loc + tabsiz - (loc % tabsiz);
                     47:                             loc < to;
                     48:                             loc++)
                     49:                                putchar(' ');
                     50:                        continue;
                     51:                }
                     52:                loc++;
                     53:                putchar(c);
                     54:        }
                     55: }

unix.superglobalmegacorp.com

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