1 /*
2  *  Copyright (C) 1995, 1996  Karl-Johan Johnsson.
3  */
4 
5 #undef  _POSIX_SOURCE
6 #define _POSIX_SOURCE   1
7 #undef  _POSIX_C_SOURCE
8 #define _POSIX_C_SOURCE 2
9 
10 #define KNEWS_VERSION	"1.0b.1"
11 
12 #include "../configure.h"
13 
14 #ifndef BIN_SH
15 #  define BIN_SH "/bin/sh"
16 #endif
17 
18 #include <X11/Intrinsic.h>
19 #include <X11/StringDefs.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <time.h>
28 #include <sys/types.h>
29 #include <regex.h>
30 #include "../Widgets/ArtTreeNode.h"
31 
32 extern XtAppContext	app_cont;
33 extern Display		*display;
34 
35 typedef enum {
36     NewsModeDisconnected,
37     NewsModeConnected,
38     NewsModeGroup,
39     NewsModeThread,
40     NewsModeAllgroups,
41     NewsModeSomegroups,
42     NewsModeNewgroups
43 } NewsMode;
44 
45 typedef struct subj_node {
46     struct subj_node	*hash_next;
47     struct subj_node	*next;
48     struct subj_node	*prev;
49     struct art_node	*thread;
50     char		*subject;
51     long		disp;
52     long		no_unread;
53     Pixmap		pixmap;
54     unsigned short	hash_len;
55     unsigned char	has_tagged;
56 } SUBJECT;
57 
58 typedef struct art_node {
59     ART_TREE_NODE	tree_data;
60     struct art_node     *hash_next;
61     struct art_node     *next;
62     char                *msgid;
63     SUBJECT             *subject;
64     char                *from;
65     char                *xref;
66     time_t		date;
67     long                no;
68     Pixmap		pixmap;
69     unsigned short	hash_len;
70     unsigned short	lines;
71 #if 0
72     long		bytes;
73 #endif
74     unsigned char	read;
75     unsigned char	killed;
76 } ARTICLE;
77 
78 #define PARENT(art)	((art)->tree_data.parent)
79 #define CHILD1(art)	((art)->tree_data.child1)
80 #define SIBLING(art)	((art)->tree_data.sibling)
81 
82 #define A_PARENT(art)	((ARTICLE *)PARENT(art))
83 #define A_CHILD1(art)	((ARTICLE *)CHILD1(art))
84 #define A_SIBLING(art)	((ARTICLE *)SIBLING(art))
85 
86 #define REGEXP_COMPILE_FLAGS \
87 ((global.icase_regexps ? REG_ICASE : 0) | REG_NOSUB | REG_EXTENDED)
88 
89 #define HOT_PIXMAP_SIZE	8
90 
91 typedef struct art_list_node {
92     long                  first;
93     long                  last;
94     struct art_list_node  *next;
95 } ART_LIST_NODE;
96 
97 typedef struct group {
98     char		*name;
99     char		*description;
100     long		no_unread;
101     long		first_art;
102     long		last_art;
103     ART_LIST_NODE	*read_arts;
104     long		disp;
105     char		subscribed;
106     char		moderated;
107     char		found_in_newsrc;
108     char		ahead_flag;
109 } GROUP;
110 
111 extern struct Global {
112     String		nntp_server;
113     String		config_nntp_server;
114     String		config_posting_agent;
115     String		edit_command;
116     String		url_command;
117     String		print_command;
118     String		needs_terminal;
119     String		copious_output;
120     Cursor		cursor;
121     Cursor		busy_cursor;
122     String		version;
123     String		mail_name;
124     String		config_file;
125     String		newsrc_templ;
126     String		old_newsrc_templ;
127     String		kill_file_templ;
128     String		group_kill_file_templ;
129     String		auto_subscribe;
130     String		mime_types;
131     String		retrieve_descr;
132     String		read_active_file;
133     String		fill_newsrc_file;
134     String		show_number_lines;
135     String		keep_thread_info;
136     String		check_for_new_groups;
137     String		confirm_quit_group;
138     Pixel		default_hot_pixel;
139     Pixel		pixel;
140     Pixel		quote_pixel;
141     Pixel		header_pixel;
142     Pixel		alert_pixel;
143     Pixel		clickable_pixel;
144     long		stderr_timeout;
145     int			chunk_size;
146     int			post_misc_menu_size;
147     int			extra_menu_size;
148     int			type_menu_size;
149     int			forward_menu_size;
150     int			n_cols;
151     Boolean		separate_windows;
152     Boolean		bell;
153     Boolean		head_debug;
154     Boolean		use_icon;
155     Boolean		confirm_quit;
156     Boolean		confirm_catchup;
157     Boolean		icase_regexps;
158     Boolean		show_cache;
159     Boolean		bogus_file_system;
160     Boolean		generate_path;
161     Boolean		mime_forward;
162     Boolean		quote_empty;
163     Boolean		sort_groups;
164     Boolean		inline_images;
165     Boolean		show_xfaces;
166     Boolean		color_hack;
167     /* private */
168     char		*user_id;
169     char		*domain_name;
170     void		*serv_addr;
171     GROUP		**groups;
172     long		no_groups;
173     long		max_groups;
174     GROUP		**new_groups;
175     long		no_new_groups;
176     SUBJECT		*curr_subj;
177     ARTICLE		*curr_art;
178     GROUP		*curr_group;
179     long		n_hot;
180     long		n_killed;
181     time_t		last_time;
182     GC			gc;
183     Visual		*visual;
184     Colormap		cmap;
185     Cardinal		depth;
186     NewsMode		mode;
187     unsigned int	busy;
188     Boolean		posting_allowed;
189     Boolean		xover_supported;
190     Boolean             list_active_supported;
191 } global;
192 
193 extern struct SERVER		*main_server;
194 extern struct THREAD_CONTEXT	*main_thr;
195