Annotation of 43BSD/contrib/rn/init.c, revision 1.1

1.1     ! root        1: /* $Header: init.c,v 4.3.1.3 85/07/23 18:08:36 lwall Exp $
        !             2:  *
        !             3:  * $Log:       init.c,v $
        !             4:  * Revision 4.3.1.3  85/07/23  18:08:36  lwall
        !             5:  * Fixed up NOLINEBUF option to work.
        !             6:  * 
        !             7:  * Revision 4.3.1.2  85/05/21  14:22:46  lwall
        !             8:  * Sped up "rn -c" by avoiding unnecessary initialization.
        !             9:  * 
        !            10:  * Revision 4.3.1.1  85/05/10  11:33:39  lwall
        !            11:  * Branch for patches.
        !            12:  * 
        !            13:  * Revision 4.3  85/05/01  16:16:13  lwall
        !            14:  * Baseline for release with 4.3bsd.
        !            15:  * 
        !            16:  */
        !            17: 
        !            18: #include "EXTERN.h"
        !            19: #include "common.h"
        !            20: #include "util.h"
        !            21: #include "final.h"
        !            22: #include "term.h"
        !            23: #include "last.h"
        !            24: #include "rn.h"
        !            25: #include "rcstuff.h"
        !            26: #include "ngdata.h"
        !            27: #include "only.h"
        !            28: #include "intrp.h"
        !            29: #include "addng.h"
        !            30: #include "sw.h"
        !            31: #include "art.h"
        !            32: #include "artsrch.h"
        !            33: #include "artio.h"
        !            34: #include "backpage.h"
        !            35: #include "bits.h"
        !            36: #include "cheat.h"
        !            37: #include "head.h"
        !            38: #include "help.h"
        !            39: #include "kfile.h"
        !            40: #include "ngsrch.h"
        !            41: #include "ngstuff.h"
        !            42: #include "rcln.h"
        !            43: #include "respond.h"
        !            44: #include "ng.h"
        !            45: #include "INTERN.h"
        !            46: #include "init.h"
        !            47: 
        !            48: bool
        !            49: initialize(argc,argv)
        !            50: int argc;
        !            51: char *argv[];
        !            52: {
        !            53:     char *tcbuf;
        !            54:     register bool foundany = FALSE;
        !            55:     long time();
        !            56: #ifdef NOLINEBUF
        !            57:     static char std_out_buf[BUFSIZ];   /* must be static or malloced */
        !            58: 
        !            59:     setbuf(stdout, std_out_buf);
        !            60: #endif
        !            61: 
        !            62:     tcbuf = safemalloc(1024);          /* make temp buffer for termcap and */
        !            63:                                        /* other initialization stuff */
        !            64:     
        !            65:     /* init terminal */
        !            66:     
        !            67:     term_init();                       /* must precede sw_init() so that */
        !            68:                                        /* ospeed is set for baud-rate */
        !            69:                                        /* switches.  Actually terminal */
        !            70:                                        /* mode setting is in term_set() */
        !            71: 
        !            72:     /* we have to know rnlib to look up global switches in %X/INIT */
        !            73: 
        !            74:     lib = savestr(filexp(LIB));
        !            75:     rnlib = savestr(filexp(RNLIB));
        !            76: 
        !            77:     /* decode switches */
        !            78: 
        !            79:     sw_init(argc,argv,&tcbuf);          /* must not do % interps! */
        !            80:                                        /* (but may mung environment) */
        !            81: 
        !            82:     /* init signals, status flags */
        !            83: 
        !            84:     final_init();
        !            85:     
        !            86:     /* start up file expansion and the % interpreter */
        !            87: 
        !            88:     intrp_init(tcbuf);
        !            89:     
        !            90:     /* now make sure we have a current working directory */
        !            91: 
        !            92:     if (!checkflag)
        !            93:        cwd_check();
        !            94:     
        !            95:     /* now that we know where to save things, cd to news directory */
        !            96: 
        !            97:     if (chdir(spool)) {
        !            98:        printf(nocd,spool) FLUSH;
        !            99:        finalize(1);
        !           100:     }
        !           101: 
        !           102:     /* if we aren't just checking, turn off echo */
        !           103: 
        !           104:     if (!checkflag)
        !           105:        term_set(tcbuf);
        !           106: 
        !           107:     /* get info on last rn run, if any */
        !           108: 
        !           109:     if (!checkflag)
        !           110:        last_init(tcbuf);
        !           111: 
        !           112:     free(tcbuf);                       /* recover 1024 bytes */
        !           113: 
        !           114:     /* make sure we are the right version */
        !           115: 
        !           116:     if (!checkflag)
        !           117:        version_check();
        !           118: 
        !           119:     /* make sure we are the sole possessors of .newsrc */
        !           120: 
        !           121:     if (!checkflag)
        !           122:        lock_check();
        !           123: 
        !           124:     /* check for news news */
        !           125: 
        !           126:     if (!checkflag)
        !           127:        newsnews_check();
        !           128: 
        !           129:     /* open active file, etc. */
        !           130: 
        !           131:     ngdata_init();
        !           132: 
        !           133:     /* now read in the .newsrc file */
        !           134: 
        !           135:     foundany = rcstuff_init();
        !           136: 
        !           137:     /* it looks like we will actually read something, so init everything */
        !           138: 
        !           139:     addng_init();
        !           140:     art_init();
        !           141:     artio_init();
        !           142:     artsrch_init();
        !           143:     backpage_init();
        !           144:     bits_init();
        !           145:     cheat_init();
        !           146: /*  final_init();      already done */
        !           147:     head_init();
        !           148:     help_init();
        !           149: /*  intrp_init();      already done */
        !           150:     kfile_init();
        !           151: /*  last_init();       already done */
        !           152:     ng_init();
        !           153: /*  ngdata_init();     already done */
        !           154:     ngsrch_init();
        !           155:     ngstuff_init();
        !           156:     only_init();
        !           157:     rcln_init();
        !           158: /*  rcstuff_init();    already done */
        !           159:     respond_init();
        !           160:     rn_init();
        !           161:     search_init();
        !           162: /*  sw_init();      already done */
        !           163: /*  term_init();       already done */
        !           164:     util_init();
        !           165: 
        !           166: #ifdef FINDNEWNG
        !           167:     fstat(actfp->_file,&filestat);     /* did active file grow? */
        !           168:     if (filestat.st_size != lastactsiz) {
        !           169:        long actsiz = filestat.st_size; /* remember new size */
        !           170:        NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
        !           171: #ifdef FASTNEW
        !           172:        bool munged = writesoft || !lastactsiz;
        !           173:                                        /* bad soft ptrs -> edited active */
        !           174: #else
        !           175:        bool munged = TRUE;             /* just assume .newsrc munged */
        !           176: #endif
        !           177: 
        !           178: #ifdef VERBOSE
        !           179:        IF(verbose)
        !           180:            fputs("\nChecking active list for new newsgroups...\n",stdout)
        !           181:              FLUSH;
        !           182:        ELSE
        !           183: #endif
        !           184: #ifdef TERSE
        !           185:            fputs("\nNew newsgroups:\n",stdout) FLUSH;
        !           186: #endif
        !           187: #ifdef FASTNEW
        !           188:        if (!munged) {                  /* maybe just do tail of file? */
        !           189:            fseek(actfp,lastactsiz-1,0);
        !           190:            fgets(buf,LBUFLEN,actfp);
        !           191:            munged = (*buf != '\n');
        !           192:            if (!munged)
        !           193:                munged = newlist(munged,FALSE);
        !           194:        }
        !           195: #endif
        !           196:        if (munged) {                   /* must we scan entire file? */
        !           197:            fseek(actfp,0L,0);          /* rewind active file */
        !           198:            newlist(munged,FALSE);      /* sure hope they use hashing... */
        !           199:        }
        !           200:        lastactsiz = actsiz;            /* remember for .rnlast */
        !           201:        if (nextrcline != oldnext) {    /* did we add any new groups? */
        !           202:            foundany = TRUE;            /* let main() know */
        !           203:            starthere = 0;              /* and start ng scan from the top */
        !           204:        }
        !           205:     }
        !           206: #endif
        !           207:     time(&lasttime);                   /* remember when we inited-- */
        !           208:                                        /* ends up back in .rnlast */
        !           209:     writelast();                       /* in fact, put it there now */
        !           210:     
        !           211: #ifdef FINDNEWNG
        !           212: # ifdef ONLY
        !           213:     if (maxngtodo)                     /* patterns on command line? */
        !           214:        foundany |= scanactive();
        !           215: # endif
        !           216: #endif
        !           217: 
        !           218:     return foundany;
        !           219: }
        !           220: 
        !           221: /* make sure there is no rn out there already */
        !           222: 
        !           223: void
        !           224: lock_check()
        !           225: {
        !           226:     lockname = savestr(filexp(LOCKNAME));
        !           227:     if (!checkflag) {
        !           228:        tmpfp = fopen(lockname,"r");
        !           229:        if (tmpfp != Nullfp) {
        !           230:            int processnum;
        !           231:     
        !           232:            fgets(buf,LBUFLEN,tmpfp);
        !           233:            fclose(tmpfp);
        !           234:            processnum = atoi(buf);
        !           235: #ifdef VERBOSE
        !           236:            IF(verbose)
        !           237:                printf("You seem to have left an rn running, process %d.\n",
        !           238:                    processnum) FLUSH;
        !           239:            ELSE
        !           240: #endif
        !           241: #ifdef TERSE
        !           242:                printf("Rn left running, #%d.\n", processnum) FLUSH;
        !           243: #endif
        !           244:            if (kill(processnum, SIGEMT)) {
        !           245:                                    /* does process not exist? */
        !           246:                                    /* (rn ignores SIGEMT) */
        !           247:                sleep(2);
        !           248: #ifdef VERBOSE
        !           249:                IF(verbose)
        !           250:                    fputs("\n\
        !           251: That process does not seem to exist anymore.  The count of read articles\n\
        !           252: may be incorrect in the last newsgroup accessed by that other (defunct)\n\
        !           253: process.\n\n",stdout) FLUSH;
        !           254:                ELSE
        !           255: #endif
        !           256: #ifdef TERSE
        !           257:                    fputs("\nProcess crashed.\n",stdout) FLUSH;
        !           258: #endif
        !           259:                if (*lastngname) {
        !           260: #ifdef VERBOSE
        !           261:                    IF(verbose)
        !           262:                        printf("(The last newsgroup accessed was %s.)\n\n",
        !           263:                        lastngname) FLUSH;
        !           264:                    ELSE
        !           265: #endif
        !           266: #ifdef TERSE
        !           267:                        printf("(In %s.)\n\n",lastngname) FLUSH;
        !           268: #endif
        !           269:                }
        !           270:                get_anything();
        !           271:                putchar('\n') FLUSH;
        !           272:            }
        !           273:            else {
        !           274: #ifdef VERBOSE
        !           275:                IF(verbose)
        !           276:                    fputs("\n\
        !           277: You may not have two copies of rn running simultaneously.  Goodbye.\n\
        !           278: ",stdout) FLUSH;
        !           279:                ELSE
        !           280: #endif
        !           281: #ifdef TERSE
        !           282:                    fputs("\nCan't start another.\n",stdout) FLUSH;
        !           283: #endif
        !           284:                finalize(0);
        !           285:            }
        !           286:        }
        !           287:        tmpfp = fopen(lockname,"w");
        !           288:        if (tmpfp == Nullfp) {
        !           289:            printf(cantcreate,lockname) FLUSH;
        !           290:            sig_catcher(0);
        !           291:        }
        !           292:        fprintf(tmpfp,"%d\n",getpid());
        !           293:        fclose(tmpfp);
        !           294:     }
        !           295: }
        !           296: 
        !           297: void
        !           298: newsnews_check()
        !           299: {
        !           300:     char *newsnewsname = filexp(NEWSNEWSNAME);
        !           301: 
        !           302:     if ((tmpfp = fopen(newsnewsname,"r")) != Nullfp) {
        !           303:        fstat(tmpfp->_file,&filestat);
        !           304:        if (filestat.st_mtime > lasttime) {
        !           305:            while (fgets(buf,sizeof(buf),tmpfp) != Nullch)
        !           306:                fputs(buf,stdout) FLUSH;
        !           307:            get_anything();
        !           308:            putchar('\n') FLUSH;
        !           309:        }
        !           310:        fclose(tmpfp);
        !           311:     }
        !           312: }
        !           313: 
        !           314: void
        !           315: version_check()
        !           316: {
        !           317:     set_ngname("net.announce");
        !           318:     if (access(ngdir,0)) {
        !           319: #ifdef VERBOSE
        !           320:        IF(verbose)
        !           321:            fputs("Can't find net.announce.  Wrong news version?\n",stdout)
        !           322:              FLUSH;
        !           323:        ELSE
        !           324: #endif
        !           325: #ifdef TERSE
        !           326:            fputs("Wrong version?\n",stdout) FLUSH;
        !           327: #endif
        !           328:        finalize(1);
        !           329:     }
        !           330: }

unix.superglobalmegacorp.com

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