Annotation of researchv10no/cmd/ap/apkeys/flist.c, revision 1.1.1.1

1.1       root        1: # include "stdio.h"
                      2: # include "ctype.h"
                      3: # include "assert.h"
                      4: # include "sys/types.h"
                      5: # include "sys/stat.h"
                      6: /*
                      7:  * given a list of names on the standard input,
                      8:  * compare the dates of those files with those of
                      9:  * a standard file and print the ones which pass
                     10:  * also reject inodes if previously seen
                     11:  */
                     12: main(argc,argv)
                     13:        char *argv[];
                     14: {
                     15: char *refname, *upname;
                     16: long reftime, lseek();
                     17: char fname[50];
                     18: struct stat stbuff;
                     19: # define NI 500
                     20: int ilist[NI], nj=0;
                     21: refname = argc>1 ? argv[1] : "";
                     22: upname = argc>2 ? argv[2] : "";
                     23: if (stat(refname, &stbuff) < 0)
                     24:        reftime=0;
                     25: else
                     26:        reftime = stbuff.st_mtime;
                     27: /* update file */
                     28: if (stat(upname, &stbuff) < 0 || stbuff.st_size==0)
                     29:        {
                     30:        if (creat (upname, 0666)== -1)
                     31:                fprintf(stderr, "Can not creat file %s\n",upname);
                     32:        }
                     33: else
                     34:        {
                     35:        int fd; char x[2];
                     36:        fd = open(upname, 2);
                     37:        assert(fd>0);
                     38:        assert(read(fd, x, 1)==1);
                     39:        assert(lseek(fd, 0L, 0)!= -1);
                     40:        assert(write(fd, x, 1)==1);
                     41:        assert(close(fd)==0);
                     42:        }
                     43: while (gets(fname))
                     44:        {
                     45:        int k;
                     46:        k = stat (fname, &stbuff);
                     47:        if (k<0) continue;
                     48:        if (stbuff.st_mtime >reftime)
                     49:                {
                     50:                int i, ino, found=0;
                     51:                ino = stbuff.st_ino;
                     52:                for(i=0; i<nj; i++)
                     53:                        if (ilist[i]==ino)
                     54:                                found=1;
                     55:                if (found) continue;
                     56:                ilist[nj++]=ino;
                     57:                if (nj>=NI) nj = NI/2;
                     58:                puts(fname);
                     59:                }
                     60:        }
                     61: }

unix.superglobalmegacorp.com

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