1 /* init.c
2  */
3 /* This software is copyrighted as detailed in the LICENSE file. */
4 
5 
6 #include "EXTERN.h"
7 #include "common.h"
8 #include "list.h"
9 #include "env.h"
10 #include "util.h"
11 #include "util2.h"
12 #include "final.h"
13 #include "term.h"
14 #include "last.h"
15 #include "trn.h"
16 #include "hash.h"
17 #include "ngdata.h"
18 #include "nntpclient.h"
19 #include "datasrc.h"
20 #include "nntp.h"
21 #include "nntpinit.h"
22 #include "rcstuff.h"
23 #include "only.h"
24 #include "intrp.h"
25 #include "addng.h"
26 #include "sw.h"
27 #include "opt.h"
28 #include "art.h"
29 #include "artsrch.h"
30 #include "artio.h"
31 #include "backpage.h"
32 #include "cache.h"
33 #include "bits.h"
34 #include "head.h"
35 #include "help.h"
36 #include "mime.h"
37 #include "kfile.h"
38 #include "ngsrch.h"
39 #include "ngstuff.h"
40 #include "rcln.h"
41 #include "respond.h"
42 #include "rthread.h"
43 #include "ng.h"
44 #include "decode.h"
45 #ifdef SCAN
46 #include "scan.h"
47 #endif
48 #ifdef SCORE
49 #include "score.h"
50 #endif
51 #include "mempool.h"
52 #include "color.h"
53 #ifdef USE_TCL
54 #include "tkstuff.h"
55 #endif
56 #include "univ.h"
57 #include "INTERN.h"
58 #include "init.h"
59 #ifdef USE_FILTER
60 #include "filter.h"
61 #endif
62 
63 bool
initialize(argc,argv)64 initialize(argc,argv)
65 int argc;
66 char* argv[];
67 {
68     char* tcbuf;
69     bool foundany = FALSE;
70 #ifdef NOLINEBUF
71     static char std_out_buf[BUFSIZ];	/* must be static or malloced */
72 
73     setbuf(stdout, std_out_buf);
74 #endif
75 
76     tcbuf = safemalloc(TCBUF_SIZE);	/* make temp buffer for termcap and */
77 					/* other initialization stuff */
78 
79     our_pid = (long)getpid();
80 
81     /* init terminal */
82 
83     term_init();			/* must precede opt_init() so that */
84 					/* ospeed is set for baud-rate */
85 					/* switches.  Actually terminal */
86 					/* mode setting is in term_set() */
87     mp_init();
88 
89     /* init syntax etc. for searching (must also precede opt_init()) */
90 
91     search_init();
92 
93     /* we have to know rnlib to look up global switches in %X/INIT */
94 
95     env_init(tcbuf, 1);
96     head_init();
97 
98     /* decode switches */
99 
100     opt_init(argc,argv,&tcbuf);		/* must not do % interps! */
101 					/* (but may mung environment) */
102     color_init();
103 
104     /* init signals, status flags */
105 
106     final_init();
107 
108     /* start up file expansion and the % interpreter */
109 
110     intrp_init(tcbuf, TCBUF_SIZE);
111 
112     /* now make sure we have a current working directory */
113 
114     if (!checkflag)
115 	cwd_check();
116 
117 #ifdef SUPPORT_NNTP
118     if (init_nntp() < 0)
119 	finalize(1);
120 #endif
121 
122     /* if we aren't just checking, turn off echo */
123 
124     if (!checkflag)
125 	term_set(tcbuf);
126 
127     /* get info on last trn run, if any */
128 
129     last_init();
130 
131     free(tcbuf);			/* recover 1024 bytes */
132 
133 #ifdef USE_TCL
134     if (UseTcl
135 #ifdef USE_TK
136  || UseTk
137 #endif
138        ) {
139 	ttcl_init();
140     }
141 #endif
142 
143     univ_init();
144 
145     /* check for news news */
146 
147     if (!checkflag)
148 	newsnews_check();
149 
150     /* process the newsid(s) and associate the newsrc(s) */
151 
152     datasrc_init();
153     ngdata_init();
154 
155     /* now read in the .newsrc file(s) */
156 
157     foundany = rcstuff_init();
158 
159     /* it looks like we will actually read something, so init everything */
160 
161     addng_init();
162     art_init();
163     artio_init();
164     artsrch_init();
165     backpage_init();
166     bits_init();
167     cache_init();
168     help_init();
169     kfile_init();
170 #ifdef USE_FILTER
171     filter_init();
172 #endif
173     mime_init();
174     ng_init();
175     ngsrch_init();
176     ngstuff_init();
177     only_init();
178     rcln_init();
179     respond_init();
180     trn_init();
181     decode_init();
182     thread_init();
183     util_init();
184     xmouse_init(argv[0]);
185 
186     writelast();	/* remember last runtime in .rnlast */
187 
188 #ifdef FINDNEWNG
189     if (maxngtodo)			/* patterns on command line? */
190 	foundany |= scanactive(TRUE);
191 #endif
192 
193     return foundany;
194 }
195 
196 void
newsnews_check()197 newsnews_check()
198 {
199     char* newsnewsname = filexp(NEWSNEWSNAME);
200 
201     if ((tmpfp = fopen(newsnewsname,"r")) != NULL) {
202 	fstat(fileno(tmpfp),&filestat);
203 	if (filestat.st_mtime > (time_t)lasttime) {
204 	    while (fgets(buf,sizeof(buf),tmpfp) != NULL)
205 		fputs(buf,stdout) FLUSH;
206 	    get_anything();
207 	    putchar('\n') FLUSH;
208 	}
209 	fclose(tmpfp);
210     }
211 }
212