File: init.c

package info (click to toggle)
uqwk 2.21-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 468 kB
  • ctags: 475
  • sloc: ansic: 4,550; sh: 1,105; makefile: 122; perl: 11
file content (173 lines) | stat: -rw-r--r-- 3,608 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 *  $Id: init.c,v 1.3 1999/04/14 13:44:49 js Exp $
 */

#include <stdio.h>
#include <string.h>
#include "uqwk.h"

#define QWK_MAGIC "Produced by Qmail...Copyright (c) 1987 by Sparkware.  All rights Reserved"

#ifdef NNTP
#include "nntp.h"
extern void connect_nntp();
#endif

/*
 *  Initialize stuff
 */
void InitStuff()
{
	char msg_fname[PATH_LEN];

	/* Mail, conference, etc. lists */
	mail_list = NULL;
	conf_list = NULL;
	last_conf = NULL;
	act_list = NULL;
	nrc_list = NULL;
	trn_list = NULL;
	ng_list = NULL;

	/* Message and conference counts */
	msg_cnt = 0;
	conf_cnt = 0;

	/* Kludge around fclose() bug in close.c */
	msg_fd = NULL;

	/* Open MESSAGES.DAT */
	if (!slnp_mode && !zip_mode && !sum_mode) {
		strcpy (msg_fname, home_dir);
		strcat (msg_fname, "/");
		strcat (msg_fname, "messages.dat");

		if (NULL == (msg_fd = fopen (msg_fname, "w"))) {
			fprintf (stderr, "%s: can't open %s\n",
				progname, msg_fname);
			exit(-1);	/* Return failure errorcode to caller */
		}

		/* Write magic string to MESSAGES.DAT */
		if(	(fprintf(msg_fd, "%-128s", QWK_MAGIC) < 0) /* != 128? */
			&& ferror(msg_fd) ) {
			fprintf(stderr,"%s: write error!\n",progname);
			exit(-1);
		}
		blk_cnt = 2;
	}

	/* Open summary file */
	if (sum_mode) {
		if (NULL == (sum_fd = fopen (sum_file, "w"))) {
			fprintf (stderr, "%s: can't open %s\n",
					progname, sum_file);
			exit(-1);	/* Return failure errorcode to caller */
		}
	}

	/* Read the ng trans table if specified */
	if (strcmp (trn_file, DEF_TRN_FILE)) ReadTrans();

	/* Read the desired newsgroups file if specified */
	if (strcmp (ng_file, DEF_NG_FILE)) ReadNG();

#ifdef NNTP
/* JS -- no need to open a connection if replying only!
	if (strcmp (rep_file, DEF_REP_FILE) || do_news) connect_nntp();
*/
	if (do_news) connect_nntp();

#endif
}

int ReadTrans()
/*
 *  Read the newsgroup name translation table
 */
{
	FILE *trn_fd;
	struct trn_ent *tp;
	char n1[PATH_LEN], n2[PATH_LEN];

	/* Open the file */
	if (NULL == (trn_fd = fopen (trn_file, "r"))) {
		fprintf (stderr, "%s: can't open %s, tran table not used\n",
			progname, trn_file);
		exit(-1);	/* Return failure errorcode to caller */
	}

	/* Read through the file */
	while (2 == fscanf (trn_fd, "%s %s", n1, n2)) {
		/* Get space for new list entry */

		if (NULL == (tp = (struct trn_ent *)
				malloc (sizeof (struct trn_ent)))) {
			OutOfMemory();
		}
		if (NULL == (tp->old = (char *) malloc (strlen(n1)+1))) {
			OutOfMemory();
		}
		if (NULL == (tp->new = (char *) malloc (strlen(n2)+1))) {
			OutOfMemory();
		}

		/* Fill in new entry */
		strcpy (tp->old, n1);
		strcpy (tp->new, n2);

		/* Add to list */
		tp->next = trn_list;
		trn_list = tp;
	}

	fclose (trn_fd);
	return (0);
}

int ReadNG()
/*
 *  Read the desired newsgroups file
 */
{
	FILE *ng_fd;
	struct ng_ent *np, *last_np = NULL;
	char n[PATH_LEN];

	/* Open the file */
	if (NULL == (ng_fd = fopen (ng_file, "r"))) {
		fprintf (stderr, "%s: can't open %s, ng file not used\n",
			progname, ng_file);
		exit(-1);	/* Return failure errorcode to caller */
	}

	/* Read through the file */
	while (1 == fscanf (ng_fd, "%s", n)) {
		/* Get space for new list entry */

		if (NULL == (np = (struct ng_ent *)
				malloc (sizeof (struct ng_ent)))) {
			OutOfMemory();
		}
		if (NULL == (np->name = (char *) malloc (strlen(n)+1))) {
			OutOfMemory();
		}

		/* Fill in new entry */
		strcpy (np->name, n);

		/* Add to list */
		if (ng_list == NULL) {
			/* First one */
			ng_list = np;
		} else {
			/* Add to end */
			last_np->next = np;
		}
		np->next = NULL;
		last_np = np;
	}

	fclose (ng_fd);
	return (0);
}