Annotation of researchv10no/cmd/refer/update/runup1.c, revision 1.1

1.1     ! root        1: # include "runup.h"
        !             2: # include "sys/types.h"
        !             3: # include "sys/timeb.h"
        !             4: # include "time.h"
        !             5: # include "signal.h"
        !             6: char *Master = "/usr/dict/papers";
        !             7: char *newplace = "other";
        !             8: char rundir[50];
        !             9: int verbose=0;
        !            10: int chatty=0;
        !            11: int vhash=0;
        !            12: long start;
        !            13: extern int garbage();
        !            14: main(argc,argv)
        !            15:        char *argv[];
        !            16: {
        !            17: int (*oldsig)();
        !            18: /* this updates an index and files directly */
        !            19: oldsig=signal(SIGINT, garbage);
        !            20: if (oldsig==SIG_IGN) signal(SIGINT, SIG_IGN);
        !            21: chatty = isatty(0);
        !            22: while (argc>1)
        !            23:        {
        !            24:        if (argv[1][0]=='-')
        !            25:        switch(argv[1][1])
        !            26:                {
        !            27:                case 'p': /* switch default index set */
        !            28:                        Master = argv[2];
        !            29:                        argc-= 2;
        !            30:                        argv+=2;
        !            31:                        continue;
        !            32:                case 'n': /* new place for additions */
        !            33:                        newplace = argv[2];
        !            34:                        argc -= 2; argv += 2;
        !            35:                        continue;
        !            36:                case 'v':
        !            37:                        verbose = chatty = 1;
        !            38:                        vhash = atoi(argv[1]+2);
        !            39: # if D2
        !            40:                        printf("vhash %d\n",vhash);
        !            41: # endif
        !            42: 
        !            43:                        argc--; argv++;
        !            44:                        continue;
        !            45:                case 'c':
        !            46:                        chatty = 1;
        !            47:                        if (argv[1][1]=='0') chatty=0;
        !            48:                        argc--;argv++;
        !            49:                        continue;
        !            50:                }
        !            51:        break;
        !            52:        }
        !            53:        if (verbose)
        !            54:                {start=time(0); printf("start at %s", ctime(&start));}
        !            55: getpwd(rundir);
        !            56:        if (verbose) printf("past getpwd got %.1f of %d sec.\n", tuse(), tlapse());
        !            57: readbib();
        !            58: if (bibs[0].bibfno<0 && argc<=1 ) {printf("No work\n"); exit(0);}
        !            59:        if (verbose) printf("past readbib got %.1f of %d sec.\n", tuse(), tlapse());
        !            60: lock();
        !            61: sortbib();
        !            62:        if (verbose) printf("past sortbib got %.1f of %d sec.\n", tuse(), tlapse());
        !            63: assert(chdir(Master)==0);
        !            64:        if (verbose) printf("past chdir got %.1f of %d sec.\n", tuse(), tlapse());
        !            65: copysource();
        !            66:        if (verbose) printf("past copysource got %.1f of %d sec.\n", tuse(), tlapse());
        !            67: makenew(argc,argv);
        !            68:        if (verbose) printf("past makenew got %.1f of %d sec.\n", tuse(), tlapse());
        !            69: append(argc,argv);
        !            70:        if (verbose) printf("past append got %.1f of %d sec.\n", tuse(), tlapse());
        !            71: fixic();
        !            72:        if (verbose) printf("past fixic got %.1f of %d sec.\n", tuse(), tlapse());
        !            73: fixib();
        !            74:        if (verbose) printf("past fixib got %.1f of %d sec.\n", tuse(), tlapse());
        !            75: signal(SIGINT, SIG_IGN); /* too late-better finish rather than abort */
        !            76: remove();
        !            77: unlock();
        !            78:        if (verbose) printf("past remove got %.1f of %d sec.\n", tuse(), tlapse());
        !            79:        if (chatty) printf("Done\n");
        !            80: }
        !            81: 
        !            82: getpwd(s)
        !            83:        char *s;
        !            84: {
        !            85: int fpip[2], fr, fw;
        !            86: pipe(fpip);
        !            87: fr = fpip[0]; fw = fpip[1];
        !            88: if (fork()==0)
        !            89:        {
        !            90:        close(1);
        !            91:        close(fr);
        !            92:        assert(dup(fw)==1);
        !            93:        close(fw);
        !            94:        execl ("/bin/pwd", "pwd", 0);
        !            95:        execl ("/usr/bin/pwd", "pwd", 0);
        !            96:        assert(0);
        !            97:        }
        !            98: close(fw);
        !            99: wait(0);
        !           100: read(fr, s, 100);
        !           101: close(fr);
        !           102: trim(s);
        !           103: assert(s[0]=='/');
        !           104: }
        !           105: 
        !           106: trim(s)
        !           107:        char *s;
        !           108: {
        !           109: while (*s) s++;
        !           110: if (*--s=='\n') *s=0;
        !           111: }
        !           112: 
        !           113: double
        !           114: tuse()
        !           115: {
        !           116: struct tbuffer {
        !           117:        long proc_user;
        !           118:        long proc_sys;
        !           119:        long child_user;
        !           120:        long child_sys;
        !           121:        } ;
        !           122: struct tbuffer tb;
        !           123: double t;
        !           124: times(&tb);
        !           125: t = (tb.proc_user+tb.proc_sys+tb.child_user+tb.child_sys);
        !           126: return(t/60.0);
        !           127: }
        !           128: 
        !           129: tlapse()
        !           130: {
        !           131: return( (int) (time(0)-start));
        !           132: }
        !           133: char lockf[100];
        !           134: lock()
        !           135: {
        !           136: int f;
        !           137: sprintf(lockf, "%s/pub-lock.n", Master);
        !           138: f = creat(lockf, 000);
        !           139: if (f<0)
        !           140:        {
        !           141:        fprintf(stderr, "Someone else updating\n");
        !           142:        exit(1);
        !           143:        }
        !           144: close(f);
        !           145: }
        !           146: unlock()
        !           147: {
        !           148: unlink(lockf);
        !           149: }

unix.superglobalmegacorp.com

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