Annotation of researchv10dc/cmd/treesum.c, revision 1.1

1.1     ! root        1: #include "stdio.h"
        !             2: #include "ftw.h"
        !             3: #include "sys/param.h"
        !             4: #include "sys/stat.h"
        !             5: 
        !             6: #define MAXNAME                1024
        !             7: #define BLOKSIZE       1024
        !             8: 
        !             9: char buf[BUFSIZ];
        !            10: 
        !            11: main(argc, argv)
        !            12: char **argv;
        !            13: {      int i, pr();
        !            14:        struct stat stb;
        !            15:        if (argc < 2) argc = 2; /* use current dir if no args */
        !            16:        for (i = 1; i < argc; i++) {
        !            17:                if(stat(argv[i],&stb)) { perror(argv[i]); exit(1); }
        !            18:                ftw(argv[i], pr, 12);
        !            19:                }
        !            20:        exit(0);
        !            21: }
        !            22: 
        !            23: int pr(s, p, n0)
        !            24: char *s;
        !            25: int n0;
        !            26: struct stat *p;
        !            27: {      int fd;
        !            28:        register char *x;
        !            29:        register int i, n;
        !            30:        register unsigned sum;
        !            31:        void sym_skip_msg();
        !            32: 
        !            33: #ifdef S_IFLNK
        !            34:        if (n0 == FTW_SL) /* symbolic link */ {
        !            35:                sym_skip_msg(s);
        !            36:                return 0;
        !            37:                }
        !            38: #endif
        !            39:                
        !            40:        if((p->st_mode & S_IFMT) != S_IFREG)    /* if not an ordinary file */
        !            41:                return(0);
        !            42:        if((fd = open(s, 0)) < 0) { perror(s); return 0; }
        !            43:        sum = 0;
        !            44:        while((n = read(fd, buf, sizeof(buf))) > 0)
        !            45:                for(i = 0, x = buf; i < n; x++, i++) {
        !            46:                        if (sum&01)
        !            47:                                sum = (sum>>1) + 0x8000;
        !            48:                        else
        !            49:                                sum >>= 1;
        !            50:                        sum += *x&0377;
        !            51:                        sum &= 0xFFFF;
        !            52:                }
        !            53:         if (n==0)
        !            54:                printf("%05u%6ld %s\n", sum, (p->st_size+BLOKSIZE-1)/BLOKSIZE, s);
        !            55:         else { perror(s); }
        !            56:        close(fd);
        !            57:        return(0);
        !            58: }
        !            59: 
        !            60: #ifdef S_IFLNK
        !            61: void
        !            62: sym_skip_msg(s)
        !            63: char *s;
        !            64: {
        !            65:        char symname[MAXNAME];
        !            66:        int i;
        !            67:        i = readlink(s, symname, MAXNAME);
        !            68:        if (i >= MAXNAME) i = MAXNAME - 1;
        !            69:        symname[i] = 0;
        !            70:        printf("skipped symbolic link %s --> %s\n",s,symname);
        !            71: }
        !            72: #endif

unix.superglobalmegacorp.com

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