Annotation of 43BSDTahoe/new/rn/init.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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