Annotation of coherent/d/usr/bin/emacs/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:                if (NULL == (env = getenv("TABSIZ")))
                     16:                        tabsiz = 8;
                     17:                else
                     18:                        tabsiz = atoi(env);
                     19:                break;
                     20:        case 2:         /* 1 argument */
                     21:                tabsiz = atoi(argv[1]);
                     22:                break;
                     23:        default:
                     24:                fprintf(stderr, "usage: detab tabsize\n");
                     25:                exit(1);
                     26:        }
                     27: 
                     28:        for (loc = 0;;) {
                     29:                switch (c = getchar()) {
                     30:                case EOF:
                     31:                        exit(0);
                     32:                case '\n':
                     33:                case '\r':
                     34:                        loc = -1;       /* next char will be at 0 */
                     35:                        break;
                     36:                case '\a':
                     37:                        loc--;          /* alarm takes no space */
                     38:                        break;
                     39:                case '\b':
                     40:                        loc -= 2;       /* backspace */
                     41:                        break;
                     42:                case '\t':
                     43:                        for (to = loc + tabsiz - (loc % tabsiz); loc < to; loc++)
                     44:                                putchar(' ');
                     45:                        continue;
                     46:                }
                     47:                loc++;
                     48:                putchar(c);
                     49:        }
                     50: }

unix.superglobalmegacorp.com

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