1 /*
2  *	(c) Copyright 1990, Kim Fabricius Storm.  All rights reserved.
3  *      Copyright (c) 1996-2005 Michael T Pins.  All rights reserved.
4  *
5  *	Global declarations and definitions.
6  */
7 
8 #ifndef _NN_GLOBAL_H
9 #define _NN_GLOBAL_H 1
10 
11 #include <stdio.h>
12 
13 /*
14  *	Various constants and types
15  */
16 
17 typedef int8    attr_type;
18 typedef int32   flag_type;
19 
20 #ifdef I286_BUG
21 #define FLAG(n)	(1L<<(n-1))
22 #else
23 #define FLAG(n)	(((flag_type)1)<<(n-1))
24 #endif
25 
26 typedef long    article_number;
27 typedef int32   group_number;
28 typedef uint32  time_stamp;
29 
30 typedef int     (*fct_type) ();
31 #define CALL(fct)  (* (fct))
32 #define NULL_FCT  (fct_type)NULL
33 
34 /* frequently used characters */
35 
36 #define NUL	'\0'
37 #define TAB	'\t'
38 #define NL	'\n'
39 #define CR	'\r'
40 #define BS	'\b'
41 #define SP	' '
42 
43 /* misc macros */
44 
45 #define fl fflush(stdout)
46 
47 #ifdef CONTROL_
48 #undef CONTROL_
49 #endif
50 
51 #define CONTROL_(c)	(c&037)
52 
53 #ifndef HAVE_STRCHR
54 #define	strrchr		rindex
55 #define strchr		index
56 #endif
57 
58 #ifdef SIGNAL_HANDLERS_ARE_VOID
59 #define sig_type void
60 #else
61 #define sig_type int
62 #endif
63 
64 
65 /* define types of own functions */
66 
67 #define	OPEN_READ	0	/* open for reading */
68 #define	OPEN_UPDATE	1	/* open/create for update */
69 #define	OPEN_CREATE	2	/* create/truncate for write */
70 #define	OPEN_APPEND	3	/* open for append */
71 #define OPEN_CREATE_RW	4	/* create for read/write */
72 
73 #define	DONT_CREATE	0x40	/* return if file does not exist */
74 #define	MUST_EXIST	0x80	/* fatal error if cannot open */
75 #define	OPEN_UNLINK	0x100	/* unlink after open (not OPEN_UPDATE) */
76 
77 
78 /*
79  *	Other external definitions
80  *
81  *	NOTICE: the distinction between pointers and arrays is important
82  *		here (they are global variables - not function arguments)
83  */
84 
85 extern char
86                *nn_directory, *lib_directory, version_id[];
87 
88 extern int      use_nntp;	/* 1 iff we are using nntp */
89 
90 extern int
91                 s_hangup,	/* hangup signal */
92                 s_keyboard,	/* keyboard signal */
93                 s_pipe,		/* broken pipe */
94                 s_redraw;	/* continue signal after stop */
95 
96 extern int      who_am_i;
97 
98 #define I_AM_MASTER	0
99 #define I_AM_NN		1
100 #define I_AM_ADMIN	2
101 #define I_AM_CHECK	3
102 #define I_AM_TIDY	4
103 #define I_AM_EMACS	5
104 #define I_AM_GOBACK	6
105 #define I_AM_POST	7
106 #define I_AM_GREP	8
107 #define I_AM_DAILY	9
108 #define I_AM_SPEW	10
109 #define I_AM_EXPIRE	11
110 #define I_AM_ACCT	12
111 #define I_AM_VIEW	13
112 
113 extern uid_t    user_id;
114 
115 extern int      process_id;
116 
117 
118 /*
119  *	Storage management
120  */
121 
122 #define	newobj(type, nelt) \
123     (type *)mem_obj(sizeof(type), (int32)(nelt))
124 
125 #define	newstr(nelt) \
126     mem_str((int32)(nelt))
127 
128 #define	resizeobj(obj, type, nelt) \
129     (type *)mem_resize((char *)(obj), sizeof(type), (int32)(nelt))
130 
131 #define	clearobj(obj, type, nelt) \
132     mem_clear((char *)(obj), sizeof(type), (int32)(nelt))
133 
134 #define	freeobj(obj) mem_free((char *)(obj))
135 
136 #define quicksort(a,n,t,f) qsort((char *)(a), (long)(n), sizeof(t), (int (*)(const void *,const void *)) f)
137 
138 #include "data.h"
139 
140 /*
141  *	db external data
142  */
143 
144 extern master_header master;
145 
146 /* group headers */
147 
148 #ifdef MALLOC_64K_LIMITATION
149 extern group_header **active_groups, **sorted_groups;
150 #else
151 extern group_header *active_groups, **sorted_groups;
152 #endif
153 
154 /* current group information */
155 
156 extern char     group_path_name[];
157 extern char    *group_file_name;
158 
159 extern group_header *current_group, *group_sequence, *rc_sequence;
160 
161 
162 int             l_g_index, s_g_first;
163 
164 #define	Loop_Groups_Number(num) \
165     for (num = 0; num < master.number_of_groups; num++)
166 
167 #ifdef MALLOC_64K_LIMITATION
168 #define Loop_Groups_Header(gh) \
169     for (l_g_index = 0; \
170 	 (l_g_index < master.number_of_groups) && \
171 	 (gh = active_groups[l_g_index]) ;\
172 	 l_g_index++)
173 #else
174 #define Loop_Groups_Header(gh) \
175     for (l_g_index = 0, gh=active_groups; \
176 	 l_g_index < master.number_of_groups; \
177 	 l_g_index++, gh++)
178 #endif
179 
180 #define Loop_Groups_Sorted(gh) \
181     for (l_g_index = s_g_first; \
182 	 (l_g_index < master.number_of_groups) && \
183 	 (gh = sorted_groups[l_g_index]) ;\
184 	 l_g_index++)
185 
186 #define	Loop_Groups_Sequence(gh) \
187     for (gh = group_sequence; gh; gh = gh->next_group)
188 
189 #define	Loop_Groups_Newsrc(gh) \
190     for (gh = rc_sequence; gh; gh = gh->newsrc_seq)
191 
192 #ifdef MALLOC_64K_LIMITATION
193 #define ACTIVE_GROUP(n)	active_groups[n]
194 #else
195 #define ACTIVE_GROUP(n)	&active_groups[n]
196 #endif
197 
198 /* 8 bit support (ISO 8859/...) */
199 
200 #ifdef HAVE_8BIT_CTYPE
201 
202 #ifdef isascii
203 #undef isascii
204 #endif
205 
206 #define isascii(c)	1
207 
208 #define iso8859(c)	(isprint(c))
209 #else
210 #define iso8859(c)	((c) & 0x60)
211 #endif
212 
213 
214 /*
215  *	Some systems don't define these in <sys/stat.h>
216  */
217 
218 #ifndef S_IFMT
219 #define	S_IFMT	0170000		/* type of file */
220 #define S_IFDIR	0040000		/* directory */
221 #define S_IFREG	0100000		/* regular */
222 #endif
223 
224 /* global.c */
225 
226 sig_type        catch_hangup(int);
227 int             init_global(void);
228 int             init_global2(void);
229 void            new_temp_file(void);
230 FILE           *open_file(char *, int);
231 FILE           *open_file_search_path(char *, int);
232 int             fgets_multi(char *, int, FILE *);
233 char           *relative(char *, char *);
234 char           *mk_file_name(char *, char *);
235 char           *home_relative(char *);
236 char           *substchr(char *, char, char);
237 char           *copy_str(char *);
238 time_t          m_time(FILE *);
239 time_t          file_exist(char *, char *);
240 int             cmp_file(char *, char *);
241 int             copy_file(char *, char *, int);
242 int             move_file(char *, char *, int);
243 int             save_old_file(char *, char *);
244 void            sys_error(char *,...);
245 int             sys_warning(char *,...);
246 int             log_entry(int, char *,...);
247 char           *user_name(void);
248 time_t          cur_time(void);
249 char           *date_time(time_t);
250 char           *plural(long);
251 char           *mem_obj(unsigned, int32);
252 char           *mem_str(int32);
253 char           *mem_resize(char *, unsigned, int32);
254 void            mem_clear(char *, unsigned, int32);
255 void            mem_free(char *);
256 int             nn_truncate(char *, off_t);
257 char           *strsave(char *);
258 char           *str3save(char *, char *, char *);
259 char           *fgetstr(FILE *);
260 int             get_line(char *, int);
261 extern char    *tmp_directory;
262 extern char    *nntp_cache_dir;
263 #endif				/* _NN_GLOBAL_H */
264