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

Defined functions

initialize defined in line 52; used 2 times
lock_check defined in line 252; used 2 times
newsnews_check defined in line 326; used 2 times
Last modified: 1987-05-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3493
Valid CSS Valid XHTML 1.0 Strict