1 /*
2  * Program source is Copyright 1998 Colten Edwards.
3  * Written specifically for configuring BitchX config.h
4  */
5 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <signal.h>
10 #include <ctype.h>
11 #include <fcntl.h>
12 #include <dirent.h>
13 #include <sys/stat.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #ifdef __EMX__
17 #include <sys/types.h>
18 #endif
19 
20 #include <ncurses.h>
21 
22 #include "ds_cell.h"
23 #include "ds_keys.h"
24 #include "func_pr.h"
25 
26 
27 
28 extern int mapcolors;
29 /*extern _DS_CONFIG config;*/
30 extern int desc_changed;
31 
32 /* Default answer replies for yes/no prompts*/
33 _default default_answer[5] = {
34 	{'Y',					TRUE},
35 	{'N',					FALSE},
36 	{13,					FALSE},
37 	{27,					FALSE},
38 	{'\0',					FALSE}
39 };
40 
41 
42 #define YN_ROW	 18
43 #define YN_COL	 5
44 
45 #define PATHCOL	9
46 #define MAXLEN 280
47 
48 /* Some local function prototypes */
49 int update_select(CELL *c);
50 char *fmt_long(unsigned long int val);
51 int main_dir (CELL *c);
52 int compile_dir (CELL *c);
53 int edit_dir (CELL *c);
54 int flood_dir (CELL *c);
55 int userlist_dir (CELL *c);
56 int toggle_select (CELL *c);
57 int edit_enter (CELL *c);
58 int save_file (CELL *c);
59 int exit_program(CELL *c);
60 int dcc_dir (CELL *c);
61 int server_dir (CELL *c);
62 int various_dir (CELL *c);
63 int load_dir (CELL *c);
64 
65 #define USER_PATH 20
66 #define TOGGLE_FILES 21
67 
68 
69 #define NONE_TYPE 0
70 #define BOOL_TYPE 1
71 #define INT_TYPE 2
72 #define STR_TYPE 3
73 
74 /* Function Table for file routines */
75 struct FuncTable file_cpy_table[] = {
76 	  {LS_END				, ls_end},
77 	  {LS_HOME				, ls_home},
78 	  {LS_PGUP				, ls_pgup},
79 	  {LS_PGDN				, ls_pgdn},
80 	  {CURSOR_UP				, cursor_up},
81 	  {CURSOR_DN				, cursor_dn},
82 	  {LS_QUIT				, ls_quit},
83 	  {WRAP_CURSOR_UP			, NULL},
84 	  {WRAP_CURSOR_DN			, NULL},
85 	  {DO_SHELL				, NULL},
86 	  {LS_ENTER				, update_select },
87 	  {UPFUNC				, NULL },
88 	  {TOGGLE				, NULL },
89 	  {PLUS_IT				, plus_it},
90 	  {MINUS_IT				, minus_it},
91 	  {0					, NULL}};
92 
93 struct FuncTable compile_cpy_table[] = {
94 	  {LS_END				, ls_end},
95 	  {LS_HOME				, ls_home},
96 	  {LS_PGUP				, ls_pgup},
97 	  {LS_PGDN				, ls_pgdn},
98 	  {CURSOR_UP				, cursor_up},
99 	  {CURSOR_DN				, cursor_dn},
100 	  {LS_QUIT				, ls_quit},
101 	  {WRAP_CURSOR_UP			, NULL},
102 	  {WRAP_CURSOR_DN			, NULL},
103 	  {DO_SHELL				, NULL},
104 	  {LS_ENTER				, toggle_select },
105 	  {UPFUNC				, NULL },
106 	  {TOGGLE				, NULL },
107 	  {PLUS_IT				, plus_it},
108 	  {MINUS_IT				, minus_it},
109 	  {0					, NULL}};
110 
111 struct FuncTable edit_cpy_table[] = {
112 	  {LS_END				, ls_end},
113 	  {LS_HOME				, ls_home},
114 	  {LS_PGUP				, ls_pgup},
115 	  {LS_PGDN				, ls_pgdn},
116 	  {CURSOR_UP				, cursor_up},
117 	  {CURSOR_DN				, cursor_dn},
118 	  {LS_QUIT				, ls_quit},
119 	  {WRAP_CURSOR_UP			, NULL},
120 	  {WRAP_CURSOR_DN			, NULL},
121 	  {DO_SHELL				, NULL},
122 	  {LS_ENTER				, edit_enter },
123 	  {0					, NULL}};
124 
125 /* Menu Table for File routines */
126 struct KeyTable file_cpy_menu[] = {
127 	{KEY_END,LS_END,"End"},
128 	{KEY_HOME, LS_HOME, "Home"},
129 	{KEY_PPAGE, LS_PGUP, "PgUp"},
130 	{KEY_NPAGE, LS_PGDN, "PgDn"},
131 	{KEY_UP, CURSOR_UP, "Up"},
132 	{KEY_DOWN, CURSOR_DN, "Down"},
133 	{ESC, LS_QUIT, "Quit"},
134 	{ALT_X, LS_QUIT, "Quit"},
135 	{KEY_F(9), DO_SHELL, "Shell"},
136 	{SPACE, TOGGLE, "Toggle On/Off"},
137 	{'\n', LS_ENTER, "Change Dir"},
138 	{'\r', LS_ENTER, "Change Dir"},
139 	{'+',  PLUS_IT, "Add Mark"},
140 	{'-', MINUS_IT,"Take Mark"},
141 	{-1, -1, ""}};
142 
143 
144 typedef struct _config_type {
145 	char *option;
146 	char *help;
147 	char *out;
148 	int integer;
149 	int type;
150 	int (*func)(CELL *c);
151 } Configure;
152 
153 Configure config_type[] = {
154 	{ "Compile Defaults", "Compile time defaults within the client", NULL, 0, 0, compile_dir },
155 	{ "Flood Settings", "Change the flood protection settings", NULL, 0, 0, flood_dir },
156 	{ "Userlist/Shitlist", "Change settings for the Userlist Shitlist options", NULL, 0, 0, userlist_dir },
157 	{ "DCC Settings",	"Change various DCC settings", NULL, 0, 0, dcc_dir },
158 	{ "Server Settings",	"Change various server and away settings", NULL, 0, 0, server_dir },
159 	{ "Various Settings",	"Change Miscellaneous settings", NULL, 0, 0, various_dir },
160 	{ "Save .config.h", "Save .config.h", NULL, 0, 0, save_file},
161 	{ "Load .config.h", "Load a saved .config.h", NULL, 0, 0, load_dir},
162 	{ "Exit", "Exit this program", NULL, 0, 0, exit_program},
163 	{  NULL, NULL, NULL, 0, 0, NULL }
164 };
165 
166 #define ON 1
167 #define OFF 0
168 
169 Configure compile_default[] = {
170 { "Lite BitchX",	"Disables ALOT of options below to make the client smaller", "BITCHX_LITE",			OFF, BOOL_TYPE, NULL },
171 { "Link Looker",	"Enable LinkLook. This is deprecated as well as dangerous", "WANT_LLOOK",			ON, BOOL_TYPE, NULL },
172 { "Plugin support",	"Enable plugins on supported OS\'s", "WANT_DLL",				ON, BOOL_TYPE, NULL },
173 { "OperView",		"Enable OperView window support", "WANT_OPERVIEW",			ON, BOOL_TYPE, NULL },
174 { "CDCC support",	"Enable builtin cdcc which is a XDCC file offer clone", "WANT_CDCC",			ON, BOOL_TYPE, NULL },
175 { "DCC ftp support",	"Enable builtin ftp support", "WANT_FTP",				ON, BOOL_TYPE, NULL },
176 { "Internal Screen",	"Enable builtin screen utility for /detach", "WANT_DETACH",			ON, BOOL_TYPE, NULL },
177 { "EPIC help file support", "Enable epic helpfile support and /ehelp", "WANT_EPICHELP",		ON, BOOL_TYPE, NULL},
178 { "Humble\'s Hades color","Another color option from the dark days of BX.", "HUMBLE",				OFF, BOOL_TYPE, NULL },
179 { "Xwindows Window create","Xwindows/screen can /window create to create a new \"screen\"", "WINDOW_CREATE",			ON, BOOL_TYPE, NULL},
180 { "Flow Control",	"Leave this enabled, unless you know it's needed","USE_FLOW_CONTROL",			ON, BOOL_TYPE, NULL},
181 { "Allow Ctrl-Z",	"Does Ctrl-Z background BX.", "ALLOW_STOP_IRC",			ON, BOOL_TYPE, NULL},
182 { "Only Std Chars",	"Use only standard chars instead of ibmpc charset", "ONLY_STD_CHARS",			OFF, BOOL_TYPE, NULL},
183 { "Latin1 Char Set",	"Use only the latin1 charset.", "LATIN1", OFF, BOOL_TYPE, NULL},
184 { "Ascii Logos",	"Use the alternate ASCII logos", "ASCII_LOGO", OFF, BOOL_TYPE, NULL},
185 { "Reverse Color",	"Reverse black and white colors for Xterms", "REVERSE_WHITE_BLACK", OFF, BOOL_TYPE, NULL},
186 { "Emacs Keybinds",	"If you have trouble with your keyboard, change this", "EMACS_KEYBINDS", OFF, BOOL_TYPE, NULL},
187 { "Identd Faking",	"Allow identd faking", "IDENT_FAKE",			OFF, BOOL_TYPE, NULL},
188 { "cidentd support",	"Use cidentd .authlie for fake username", "CIDENTD",				OFF, BOOL_TYPE, NULL},
189 { "wdidentd support",	"Use wdidentd for fake username. Do no enable both cidentd and this", "WDIDENT",				OFF, BOOL_TYPE, NULL},
190 { "Include glob support","File Globbing support","INCLUDE_GLOB_FUNCTION",		ON, BOOL_TYPE, NULL},
191 { "Exec Command",	"Enable the /exec command", "EXEC_COMMAND",			ON, BOOL_TYPE, NULL},
192 { "Public Access Enabled","This disables the dangerous commands, making them unsable", "PUBLIC_ACCESS", OFF, BOOL_TYPE, NULL},
193 { "Hebrew Language support", "Hebrew Language Support", "HEBREW",			ON, BOOL_TYPE, NULL},
194 { "Translation Tables", "Keyboard Translation tables", "TRANSLATE",			ON, BOOL_TYPE, NULL},
195 { "Mirc resume support"," Support Mirc\'s Broken resume","MIRC_BROKEN_DCC_RESUME",	ON, BOOL_TYPE, NULL},
196 { "Mode Compression",	"Code for performing mode compression on mass mode changes", "COMPRESS_MODES", ON, BOOL_TYPE, NULL},
197 { "MAX # of urls in list", "Max Number of URLS to save in memory", "DEFAULT_MAX_URLS",   30, INT_TYPE, edit_dir },
198 { "ChatNet Support", "Support chatnet\'s numeric 310", "WANT_CHATNET",			OFF,BOOL_TYPE, NULL},
199 { "Notify BitchX.com", "Notify BitchX.com of our version", "SHOULD_NOTIFY_BITCHX_COM",	ON, BOOL_TYPE, NULL},
200 { "Want Userlist",		"", "WANT_USERLIST",		ON,  BOOL_TYPE, NULL },
201 { NULL, NULL, NULL, 0, 0, NULL }
202 };
203 
204 Configure userlist_default[] = {
205 { "Userlist",			"", "DEFAULT_USERLIST",		ON,  BOOL_TYPE, NULL },
206 { "Auto-op",			"", "DEFAULT_AOP_VAR",		 OFF, BOOL_TYPE, NULL },
207 { "Auto Invite",		"", "DEFAULT_AINV",		0, INT_TYPE, edit_dir },
208 { "Kick ops",			"", "DEFAULT_KICK_OPS",		 ON, BOOL_TYPE, NULL },
209 { "Annoy Kick",			"", "DEFAULT_ANNOY_KICK",	 OFF, BOOL_TYPE, NULL },
210 
211 { "Lamenick",			"", "DEFAULT_LAMELIST", 	ON, BOOL_TYPE, NULL },
212 { "Lame Ident",			"", "DEFAULT_LAME_IDENT", 	OFF, BOOL_TYPE, NULL },
213 { "Shitlist",			"", "DEFAULT_SHITLIST", 	ON, BOOL_TYPE, NULL },
214 { "Auto Rejoin Channel",	"", "DEFAULT_AUTO_REJOIN",	 ON, BOOL_TYPE, NULL },
215 
216 { "Deop Flood",			"", "DEFAULT_DEOPFLOOD",	 ON, BOOL_TYPE, NULL },
217 { "Deop Flood Time",		"", "DEFAULT_DEOPFLOOD_TIME",	 30,INT_TYPE, edit_dir },
218 { "Deop After \'X\' deops",	"", "DEFAULT_DEOP_ON_DEOPFLOOD", 3,INT_TYPE, edit_dir },
219 { "Deop After \'X\' kicks",	"", "DEFAULT_DEOP_ON_KICKFLOOD", 3,INT_TYPE, edit_dir },
220 
221 { "Join Flood",			"", "DEFAULT_JOINFLOOD",	 ON, BOOL_TYPE, NULL },
222 { "Join Flood Time",		"", "DEFAULT_JOINFLOOD_TIME",	 50,INT_TYPE, edit_dir },
223 
224 { "Kick Flood",			"", "DEFAULT_KICKFLOOD",	 ON, BOOL_TYPE, NULL },
225 { "Kick Flood Time",		"", "DEFAULT_KICKFLOOD_TIME",	 30,INT_TYPE, edit_dir },
226 { "Kick on \'X\' Kicks",		"", "DEFAULT_KICK_ON_KICKFLOOD", 4,INT_TYPE, edit_dir },
227 { "Kick on \'X\' Deops",	"", "DEFAULT_KICK_ON_DEOPFLOOD", 3,INT_TYPE, edit_dir },
228 { "Kick On \'X\' Joins",	"", "DEFAULT_KICK_ON_JOINFLOOD", 4,INT_TYPE, edit_dir },
229 
230 { "Nick Flood",			"", "DEFAULT_NICKFLOOD",	 ON, BOOL_TYPE, NULL },
231 { "Nick Flood Time",		"", "DEFAULT_NICKFLOOD_TIME",	 30,INT_TYPE, edit_dir },
232 { "Kick on \'X\' Nick Changes",	"", "DEFAULT_KICK_ON_NICKFLOOD", 3,INT_TYPE, edit_dir },
233 
234 { "Public Flood",		"", "DEFAULT_PUBFLOOD",		 OFF, BOOL_TYPE, NULL },
235 { "Public Flood Time",		"", "DEFAULT_PUBFLOOD_TIME",	 20,INT_TYPE, edit_dir },
236 { "Kick on Public flood",	"", "DEFAULT_KICK_ON_PUBFLOOD", 30,INT_TYPE, edit_dir },
237 
238 { "Kick on ban match",		"", "DEFAULT_KICK_IF_BANNED",	 OFF, BOOL_TYPE, NULL },
239 { "Server op protection",	"Values 0 for none, 1 for deop, 2 for announce only", "DEFAULT_HACKING",		 0,INT_TYPE, edit_dir },  /* 0 1 2 */
240 {"Auto-Unban time",		"", "DEFAULT_AUTO_UNBAN",   600, INT_TYPE, edit_dir },
241 {"Default Ban time",		"", "DEFAULT_BANTIME",   600, INT_TYPE, edit_dir },
242 {"Send ctcp msg",		"Send notice when ctcp command recieved", "DEFAULT_SEND_CTCP_MSG",	 ON, BOOL_TYPE, NULL },
243 {"Send Op msg",			"Send notice when auto-op sent", "DEFAULT_SEND_OP_MSG",	 ON, BOOL_TYPE, NULL },
244 { NULL, NULL, NULL, 0, 0, NULL }
245 };
246 
247 Configure flood_default[] = {
248 { "Flood Prot",		"", "DEFAULT_FLOOD_PROTECTION",		ON,  BOOL_TYPE, NULL },
249 { "Ctcp Flood Prot",	"", "DEFAULT_CTCP_FLOOD_PROTECTION",	ON,  BOOL_TYPE, NULL },
250 { "Ctcp Flood after",	"", "DEFAULT_CTCP_FLOOD_AFTER",		10, INT_TYPE, edit_dir },
251 { "Ctcp Flood rate",	"", "DEFAULT_CTCP_FLOOD_RATE",		3,  INT_TYPE, edit_dir},
252 { "Flood Kick",		"", "DEFAULT_FLOOD_KICK",		ON,  BOOL_TYPE, NULL },
253 { "Flood Rate",		"", "DEFAULT_FLOOD_RATE",		5,  INT_TYPE, edit_dir },
254 { "Flood After",	"", "DEFAULT_FLOOD_AFTER",		4,  INT_TYPE, edit_dir },
255 { "Flood Users",	"", "DEFAULT_FLOOD_USERS",		10, INT_TYPE, edit_dir },
256 { "Flood Warning",	"", "DEFAULT_FLOOD_WARNING",		OFF,  BOOL_TYPE, NULL },
257 { "No CTCP flood",	"", "DEFAULT_NO_CTCP_FLOOD",		ON,  BOOL_TYPE, NULL },
258 { "CDCC flood after",	"", "DEFAULT_CDCC_FLOOD_AFTER",		3,  INT_TYPE, edit_dir },
259 { "CDCC flood rate",	"", "DEFAULT_CDCC_FLOOD_RATE",		4,  INT_TYPE, edit_dir },
260 { "CTCP delay",		"", "DEFAULT_CTCP_DELAY",		3,  INT_TYPE, edit_dir },
261 { "CTCP flood ban",	"", "DEFAULT_CTCP_FLOOD_BAN",		ON,  BOOL_TYPE, NULL },
262 { "CTCP verbose",	"", "DEFAULT_VERBOSE_CTCP",		ON,  BOOL_TYPE, NULL },
263 { "CDCC on/off",	"", "DEFAULT_CDCC",			ON,  BOOL_TYPE, NULL },
264 {"Ignore time on flood","", "DEFAULT_IGNORE_TIME",		600, INT_TYPE, edit_dir },
265 { NULL, NULL, NULL, 0, 0, NULL }
266 };
267 
268 Configure dcc_default[] = {
269 { "DCC Fast", "Enable DCC fast support on supported hosts.", "DEFAULT_DCC_FAST",	ON, BOOL_TYPE, NULL},
270 { "DCC block size", "", "DEFAULT_DCC_BLOCK_SIZE", 2048, INT_TYPE, edit_dir},
271 { "DCC auto-rename", "", "DEFAULT_DCC_AUTORENAME",   ON, BOOL_TYPE, NULL},
272 { "DCC auto-resume", "", "DEFAULT_DCC_AUTORESUME",   OFF, BOOL_TYPE, NULL},
273 { "DCC display bar", " 0 for color bargraph, 1 for non-color bar", "DEFAULT_DCC_BAR_TYPE",   0, INT_TYPE, edit_dir },
274 { "DCC Autoget", "", "DEFAULT_DCC_AUTOGET",   OFF, BOOL_TYPE, NULL},
275 { "DCC Max DCC gets", "", "DEFAULT_DCC_GET_LIMIT",    0, INT_TYPE, edit_dir},
276 { "DCC Max DCC sends", "", "DEFAULT_DCC_SEND_LIMIT",   5, INT_TYPE, edit_dir},
277 { "DCC Queue Limit", "", "DEFAULT_DCC_QUEUE_LIMIT",   10, INT_TYPE, edit_dir},
278 { "DCC Limit get/send", "", "DEFAULT_DCC_LIMIT",   10, INT_TYPE, edit_dir },
279 { "DCC Idle dcc timeout", "", "DEFAULT_DCCTIMEOUT",   600, INT_TYPE, edit_dir },
280 { "CDCC Queue timeout", "", "DEFAULT_QUEUE_SENDS", 0, INT_TYPE, edit_dir },
281 { "DCC MAX dcc filesize get", "", "DEFAULT_MAX_AUTOGET_SIZE", 2000000, INT_TYPE, edit_dir },
282 { NULL, NULL, NULL, 0, 0, NULL }
283 };
284 
285 Configure server_default[] = {
286 {"Auto-Away system on/off", "", "DEFAULT_AUTO_AWAY",     ON, BOOL_TYPE, NULL },
287 {"Send Away to Channel", "", "DEFAULT_SEND_AWAY_MSG",   OFF, BOOL_TYPE, NULL },
288 {"# of seconds for auto-away", "", "DEFAULT_AUTO_AWAY_TIME",   600, INT_TYPE, edit_dir },
289 {"auto-unmark away", "", "DEFAULT_AUTO_UNMARK_AWAY",    OFF, BOOL_TYPE, NULL },
290 {"Channel Name width", "", "DEFAULT_CHANNEL_NAME_WIDTH", 10, INT_TYPE, NULL },
291 {"Socks Port default", "", "DEFAULT_SOCKS_PORT",   1080, INT_TYPE, edit_dir },
292 {"Turn Notify on/off", "", "DEFAULT_NOTIFY",   ON, BOOL_TYPE, NULL},
293 {"Max # of server reconnects", "", "DEFAULT_MAX_SERVER_RECONNECT",   2, INT_TYPE, edit_dir },
294 {"# of Seconds for connect", "", "DEFAULT_CONNECT_TIMEOUT",   30, INT_TYPE, edit_dir },
295 {"Send unknown commands", "", "DEFAULT_DISPATCH_UNKNOWN_COMMANDS",   OFF, BOOL_TYPE, NULL},
296 {"Ignore Server write errors", "", "DEFAULT_NO_FAIL_DISCONNECT",   OFF, BOOL_TYPE, NULL},
297 {"Enable Server groups", "", "DEFAULT_SERVER_GROUPS",   OFF, BOOL_TYPE, NULL},
298 {"Kill window on part OS/2", "", "DEFAULT_WINDOW_DESTROY_PART",   OFF, BOOL_TYPE, NULL},
299 {"Display server MOTD", "", "DEFAULT_SUPPRESS_SERVER_MOTD",   ON, BOOL_TYPE, NULL},
300 {"Reconnect on kill", "", "DEFAULT_AUTO_RECONNECT",   ON, BOOL_TYPE, NULL},
301 {"Show away once", "", "DEFAULT_SHOW_AWAY_ONCE",   ON, BOOL_TYPE, NULL},
302 {"Show Nicks on channel join", "", "DEFAULT_SHOW_CHANNEL_NAMES",   ON, BOOL_TYPE, NULL},
303 {"Show end of server msgs", "", "DEFAULT_SHOW_END_OF_MSGS",   OFF, BOOL_TYPE, NULL},
304 {"Display Numerics", "", "DEFAULT_SHOW_NUMERICS",   OFF, BOOL_TYPE, NULL},
305 {"Show ALL status vars", "", "DEFAULT_SHOW_STATUS_ALL",   OFF, BOOL_TYPE, NULL},
306 {"Show who hop count", "", "DEFAULT_SHOW_WHO_HOPCOUNT",   OFF, BOOL_TYPE, NULL},
307 {"Send ignore msg on ignore", "", "DEFAULT_SEND_IGNORE_MSG",   OFF, BOOL_TYPE, NULL},
308 {"Hide Private channels", "", "DEFAULT_HIDE_PRIVATE_CHANNELS",   OFF, BOOL_TYPE, NULL},
309 {"Default IRC server port", "", "IRC_PORT",   6667, INT_TYPE, edit_dir },
310 {"After # of second turn on", "", "DEFAULT_CPU_SAVER_AFTER",   0, INT_TYPE, edit_dir },
311 {"Every # of seconds allow", "", "DEFAULT_CPU_SAVER_EVERY",   0, INT_TYPE, edit_dir },
312 { NULL, NULL, NULL, 0, 0, NULL }
313 };
314 
315 Configure various_default[] = {
316 {"Ping type", "0 1 2", "DEFAULT_PING_TYPE",   1, INT_TYPE, edit_dir },
317 {"Cloak", "Which ctcp\'s do we respond too. 0 all. 1. ping 2. none", "DEFAULT_CLOAK",	1, INT_TYPE, NULL },
318 {"Msg Logging while away", "", "DEFAULT_MSGLOG",   ON, BOOL_TYPE, NULL},
319 {"Auto-nslookup", "", "DEFAULT_AUTO_NSLOOKUP",   OFF, BOOL_TYPE, NULL},
320 {"LinkLook on/off", "", "DEFAULT_LLOOK",	OFF, BOOL_TYPE, NULL},
321 {"LinkLook Delay", "", "DEFAULT_LLOOK_DELAY",   120, INT_TYPE, edit_dir },
322 {"Split biggest window", "", "DEFAULT_ALWAYS_SPLIT_BIGGEST",   ON, BOOL_TYPE, NULL},
323 {"Auto whowas", "", "DEFAULT_AUTO_WHOWAS",   OFF, BOOL_TYPE, NULL},
324 {"Command Mode", "", "DEFAULT_COMMAND_MODE",   OFF, BOOL_TYPE, NULL},
325 {"Comment Hack for /*", "", "DEFAULT_COMMENT_HACK",   ON, BOOL_TYPE, NULL},
326 {"Display on/off", "", "DEFAULT_DISPLAY",   ON, BOOL_TYPE, NULL},
327 {"8-bit chars", "", "DEFAULT_EIGHT_BIT_CHARACTERS",   ON, BOOL_TYPE, NULL},
328 {"Enable exec protection", "", "DEFAULT_EXEC_PROTECTION",   ON, BOOL_TYPE, NULL},
329 {"Escape chars > 127", "", "DEFAULT_HIGH_BIT_ESCAPE",   OFF, BOOL_TYPE, NULL},
330 {"History", "", "DEFAULT_HISTORY",   100, INT_TYPE, edit_dir },
331 {"Screen paging", "", "DEFAULT_HOLD_MODE",   OFF, BOOL_TYPE, NULL},
332 {"Max lines to hold", "", "DEFAULT_HOLD_MODE_MAX",   0, INT_TYPE, edit_dir },
333 
334 {"Lastlog items", "", "DEFAULT_LASTLOG",   1000, INT_TYPE, edit_dir },
335 {"Logging on/off", "", "DEFAULT_LOG",   OFF, BOOL_TYPE, NULL},
336 {"Enable Mail Check", " 0 1 2", "DEFAULT_MAIL",   2, INT_TYPE, edit_dir },
337 {"Notify on Terminate", "", "DEFAULT_NOTIFY_ON_TERMINATION",   OFF, BOOL_TYPE, NULL},
338 {"Scroll Enabled", "", "DEFAULT_SCROLL_LINES",   ON, BOOL_TYPE, NULL},
339 {"Process limit", "", "DEFAULT_SHELL_LIMIT",   0, INT_TYPE, edit_dir },
340 {"Number of Key Meta\'s", "", "DEFAULT_META_STATES",   5, INT_TYPE, edit_dir },
341 
342 {"Max Deops", "", "DEFAULT_MAX_DEOPS",   2, INT_TYPE, edit_dir },
343 {"Max Idle check kicks", "", "DEFAULT_MAX_IDLEKICKS",   2, INT_TYPE, edit_dir },
344 {"Max Number bans", "", "DEFAULT_NUM_BANMODES",   4, INT_TYPE, edit_dir },
345 {"Num of kicks", "", "DEFAULT_NUM_KICKS",   4, INT_TYPE, edit_dir },
346 {"Num of Whowas", "", "DEFAULT_NUM_OF_WHOWAS",   4, INT_TYPE, edit_dir },
347 {"Num of OPmodes", "", "DEFAULT_NUM_OPMODES",   4, INT_TYPE, edit_dir },
348 
349 {"Enable Help Pager", "", "DEFAULT_HELP_PAGER",   ON, BOOL_TYPE, NULL},
350 {"Enable Help Prompt", "", "DEFAULT_HELP_PROMPT",   ON, BOOL_TYPE, NULL},
351 {"Enable Help Window", "", "DEFAULT_HELP_WINDOW",   OFF, BOOL_TYPE, NULL},
352 
353 {"FTP address grab", "", "DEFAULT_FTP_GRAB",   OFF, BOOL_TYPE, NULL},
354 {"HTTP address grab", "", "DEFAULT_HTTP_GRAB",   OFF, BOOL_TYPE, NULL},
355 
356 {"Nick Completion on/off", "", "DEFAULT_NICK_COMPLETION",   ON, BOOL_TYPE, NULL},
357 {"Len of nick for complete", "", "DEFAULT_NICK_COMPLETION_LEN",   2, INT_TYPE, edit_dir },
358 {"Nick complete type", " 0 1 2", "DEFAULT_NICK_COMPLETION_TYPE",   0, INT_TYPE, edit_dir },
359 
360 {"Full Status bar", "", "DEFAULT_FULL_STATUS_LINE",   ON, BOOL_TYPE, NULL},
361 {"Allow %> to repeat", "", "DEFAULT_STATUS_NO_REPEAT",   ON, BOOL_TYPE, NULL},
362 {"Double Status line", "", "DEFAULT_DOUBLE_STATUS_LINE",   ON, BOOL_TYPE, NULL},
363 {"Expand $ vars in status", "", "DEFAULT_STATUS_DOES_EXPANDOS", OFF, BOOL_TYPE, NULL},
364 
365 
366 {"Operview window hide", "", "DEFAULT_OPERVIEW_HIDE",   0, INT_TYPE, edit_dir },
367 {"Operview on/off", "", "DEFAULT_OPER_VIEW",   OFF, BOOL_TYPE, NULL},
368 
369 {"Enable tabs", "", "DEFAULT_TAB",   ON, BOOL_TYPE, NULL},
370 {"# of Chars to a tab", "", "DEFAULT_TAB_MAX",   8, INT_TYPE, edit_dir },
371 {"Beep on/off", "", "DEFAULT_BEEP",   ON, BOOL_TYPE, NULL},
372 {"Beep MAX", "", "DEFAULT_BEEP_MAX",   3, INT_TYPE, edit_dir },
373 {"Beep when away", "", "DEFAULT_BEEP_WHEN_AWAY",   OFF, BOOL_TYPE, NULL},
374 {"Enable Bold video", "", "DEFAULT_BOLD_VIDEO",   ON, BOOL_TYPE, NULL},
375 {"Enable Blink video", "", "DEFAULT_BLINK_VIDEO",   ON, BOOL_TYPE, NULL},
376 {"Enable Inverse video", "", "DEFAULT_INVERSE_VIDEO",   ON, BOOL_TYPE, NULL},
377 {"Enable Underline video", "", "DEFAULT_UNDERLINE_VIDEO",   ON, BOOL_TYPE, NULL},
378 {"Clock display on/off", "", "DEFAULT_CLOCK",   ON, BOOL_TYPE, NULL},
379 {"24-Hour Clock display", "", "DEFAULT_CLOCK_24HOUR",   OFF, BOOL_TYPE, NULL},
380 {"Floating point math", "", "DEFAULT_FLOATING_POINT_MATH",   OFF, BOOL_TYPE, NULL},
381 {"Indent on/off", "", "DEFAULT_INDENT",   ON, BOOL_TYPE, NULL},
382 {"Enable Input aliases", "", "DEFAULT_INPUT_ALIASES",   OFF, BOOL_TYPE, NULL},
383 {"Enable insert mode", "", "DEFAULT_INSERT_MODE",   ON, BOOL_TYPE, NULL},
384 
385 {"Display Ansi on/off", "", "DEFAULT_DISPLAY_ANSI",   ON, BOOL_TYPE, NULL},
386 {"Display char Mangling", "", "DEFAULT_DISPLAY_PC_CHARACTERS",   4, INT_TYPE, edit_dir },
387 
388 {"# of Scrollback lines", "", "DEFAULT_SCROLLBACK_LINES",   512, INT_TYPE, edit_dir },
389 {"Scrollback ratio", "", "DEFAULT_SCROLLBACK_RATIO",   50, INT_TYPE, edit_dir },
390 {"MAX ND space", "", "DEFAULT_ND_SPACE_MAX",   160, INT_TYPE, edit_dir },
391 {"TabKey", "", "WANT_TABKEY",   ON, BOOL_TYPE, NULL },
392 {"NSlookup", "", "WANT_NSLOOKUP",   ON, BOOL_TYPE, NULL },
393 {"Bhelp command", "", "WANT_CHELP",   ON, BOOL_TYPE, NULL },
394 {"TimeStamp", "", "DEFAULT_TIMESTAMP", OFF, BOOL_TYPE, NULL },
395 { "Default Alt Charset","Use the default ALT charset", "DEFAULT_ALT_CHARSET",			ON, BOOL_TYPE, NULL},
396 { NULL, NULL, NULL, 0, 0, NULL }
397 };
398 
399 
400 
401 
402 /* Mark file and operated on special chars */
403 int mark_char = '*'; /* '*';  0x10;*/
404 int old_mark_char = '-'; /*= 0xfe;*/
405 
406 
407 
408 
409 
410 int changed = 0;
411 
412 
413 /* Current path and filename storage areas */
414 char current_path[MAXPATH + 1];
415 char current_filename[MAXPATH + 1];
416 
417 #define COLOR_MAIN 1
418 #define COLOR_DIALOG 2
419 #define COLOR_STATUS 3
420 #define COLOR_HELP 4
421 #define COLOR_DIRECTORY 5
422 #define COLOR_ONVOL 6
423 #define COLOR_SELECTED 7
424 #define COLOR_BOTTOM 8
425 #define COLOR_TITLE 9
426 char main_foreground = COLOR_WHITE, main_background = COLOR_BLUE,
427 	 dialog_foreground, dialog_background;
428 char status_foreground, status_background,
429 	 help_foreground, help_background;
430 char directory_foreground, directory_background,
431 	 onvol_foreground, onvol_background;
432 char selected_foreground = COLOR_BLUE, selected_background = COLOR_WHITE,
433 	 bottom_foreground, bottom_background;
434 char title_foreground, title_background;
435 
436 
437 #include "save.c"
438 #include "load.c"
439 
load_dir(CELL * c)440 int load_dir(CELL *c)
441 {
442 	load_file(current_path);
443 	return TRUE;
444 }
445 
446 
447 
448 
exit_program(CELL * c)449 int exit_program (CELL *c)
450 {
451 	changed = 0;
452 	c->termkey = ALT_X;
453 	return TRUE;
454 }
455 
456 
457 
setup_colors()458 void setup_colors()
459 {
460 /* Sets up color */
461 
462 	if (has_colors())
463 	{
464 		init_pair(COLOR_MAIN, main_foreground, main_background);
465 		init_pair(COLOR_DIALOG, dialog_foreground, dialog_background);
466 		init_pair(COLOR_STATUS, status_foreground, status_background);
467 		init_pair(COLOR_HELP, help_foreground, help_background);
468 		init_pair(COLOR_DIRECTORY, directory_foreground, directory_background);
469 		init_pair(COLOR_ONVOL, onvol_foreground, onvol_background);
470 		init_pair(COLOR_SELECTED, selected_foreground, selected_background);
471 		init_pair(COLOR_BOTTOM, bottom_foreground, bottom_background);
472 		init_pair(COLOR_TITLE, title_foreground, title_background);
473 	}
474 }
475 
476 
477 /* Initialize the linked list to NULL */
init_dlist(CELL * c)478 void init_dlist ( CELL *c )
479 {
480 	c->start = c->end = c->list_start = c->list_end = c->current = NULL;
481 }
482 
toggle_select(CELL * c)483 int toggle_select (CELL *c)
484 {
485 	if (c->current->datainfo.type == BOOL_TYPE)
486 	{
487 		if (c->current->datainfo.integer)
488 			c->current->datainfo.integer = 0;
489 		else
490 			c->current->datainfo.integer = 1;
491 		c->redraw = TRUE;
492 		return TRUE;
493 	}
494 	if (c->current->datainfo.func)
495 		return (*c->current->datainfo.func) (c);
496 	return TRUE;
497 }
498 
499 /* Add mark to current highlighted item */
plus_it(CELL * c)500 int plus_it(CELL *c)
501 {
502 
503 	if (c->current->datainfo.type == INT_TYPE)
504 	{
505 		c->current->datainfo.integer++;
506 		c->redraw = TRUE;
507 	}
508 	return TRUE;
509 }
510 
511 /* Take away mark from current highlighted item */
minus_it(CELL * c)512 int minus_it(CELL *c) {
513 	if (c->current->datainfo.type == INT_TYPE && c->current->datainfo.integer)
514 	{
515 		c->current->datainfo.integer--;
516 		c->redraw = TRUE;
517 	}
518 	return TRUE;
519 }
520 
521 
update_select(CELL * c)522 int update_select(CELL *c)
523 {
524 	if (c->current->datainfo.func)
525 		return (*c->current->datainfo.func) (c);
526 	return TRUE;
527 }
528 
529 
530 /* clear list of files to play.. Make sure user wants this behavior */
clear_marks(CELL * c)531 int clear_marks(CELL *c)
532 {
533 dlistptr ptr;
534 	ptr = c->start;
535 	while (ptr)
536 	{
537 		ptr->datainfo.mark = 0;
538 		ptr = ptr->nextlistptr;
539 	}
540 	c->redraw = TRUE;
541 	return TRUE;
542 }
543 
544 /* cleate all parts ot the the linked list */
545 
clear_dlist(CELL * c)546 int clear_dlist (CELL *c)
547 {
548 	 dlistptr ptr;
549 	 while (c->start != NULL ) {
550 		ptr = c->start;
551 		c->start = c->start->nextlistptr;
552 		if (ptr->datainfo.option)
553 			free(ptr->datainfo.option);
554 		if (ptr->datainfo.help)
555 			free(ptr->datainfo.help);
556 		free(ptr);
557 	 }
558 	 c->end = NULL;
559 	return TRUE;
560 }
561 
List_Exit(CELL * c)562 int List_Exit(CELL *c) {
563 	clear_dlist(c);
564 	return TRUE;
565 }
566 
567 
568 /*
569  * Update status information including number of files, number of marked files
570  * etc.
571  */
status_update(CELL * c)572 int status_update(CELL *c) {
573 char tmp[(200 + 1) * 2];
574 int center;
575 	center = ((c->ecol - 2) / 2) - (strlen(c->filename) / 2);
576 	memset(tmp, 0, sizeof(tmp));
577 #if 0
578 	memset(tmp, ' ', center);
579 	strcat(tmp, c->filename);
580 	mvwaddstr(c->window, c->srow - 2, c->scol , tmp);
581 #else
582 	memset(tmp, ' ', c->ecol - 2);
583 	mvwaddstr (c->window, c->srow - 2 , c->scol, tmp);
584 	wattron(c->window,A_REVERSE);
585 	mvwaddstr (c->window, c->srow - 2 , center, c->filename);
586 	wattroff(c->window,A_REVERSE);
587 
588 #endif
589 	if (c->current->datainfo.help)
590 	{
591 		sprintf(tmp, " %-75s ", c->current->datainfo.help);
592 		mvwaddstr(c->window, c->max_rows - 3, c->scol, tmp);
593 	}
594 	else
595 		mvwaddstr(c->window, c->max_rows - 2, c->scol, tmp);
596 	return TRUE;
597 }
598 
599 /* Insert an item into the list. IN this case a filename and it's current
600  * attribute's are stored in the list. Item is added to the end of the list.
601  * and pointers are updated.
602  */
insert_fdlist(CELL * c,struct _config_type * current)603 int insert_fdlist (CELL *c, struct _config_type *current) {
604 	dlistptr ptr = NULL;
605 
606 	ptr = (dlistptr) calloc(1, sizeof(struct dlistmem));
607 	if (c->start == NULL) /* start of new list */
608 		c->start = ptr;
609 	else
610 	{
611 		ptr->prevlistptr = c->end;
612 		c->end->nextlistptr = ptr;
613 	}
614 	c->end = ptr;
615 
616 	ptr->datainfo.option = (char *) malloc(strlen(current->option)+1);
617 	strcpy(ptr->datainfo.option, current->option);
618 	ptr->datainfo.help = (char *) malloc(strlen(current->help)+1);
619 	strcpy(ptr->datainfo.help, current->help);
620 	ptr->datainfo.func = current->func;
621 	ptr->datainfo.integer = current->integer;
622 	ptr->datainfo.type = current->type;
623 	return TRUE;
624 
625 }
626 
627 /* on entry to file list routine, setup screen windows and put menu options
628  * on screen.
629  * initilize the list.
630  * Use findfirst/findnext to add filenames into list
631  * Set display begin/end to start of list.
632  * finally sort the list
633  */
634 
File_Entry(CELL * c)635 int File_Entry(CELL *c) {
636 	wmove(c->window,c->srow - 2, c->scol - 1);
637 	wborder(c->window,0,0,0,0,0,0,0,0);
638 
639 	mvwaddch(c->window, c->srow - 1, c->max_cols, ACS_RTEE);
640 	mvwaddch(c->window, c->srow - 1, c->scol - 1, ACS_LTEE);
641 	wmove(c->window,c->srow - 1, c->scol);
642 	whline(c->window, ACS_HLINE, c->max_cols - c->scol);
643 
644 	mvwaddch(c->window, c->erow + 1, c->scol - 1, ACS_LTEE);
645 	mvwaddch(c->window, c->erow + 1, c->max_cols, ACS_RTEE);
646 	wmove(c->window,c->erow + 1, c->scol);
647 	whline(c->window, ACS_HLINE, c->max_cols - c->scol);
648 
649 	wrefresh(c->window);
650 	c->current = c->list_start = c->list_end = c->start;
651 	return TRUE;
652 }
653 
654 /*
655  * screen Display function, formats file info into displayable format
656  * Uses some magic numbers for masking information.
657  */
fDisplay(dlistptr * ptr)658 char *fDisplay (dlistptr *ptr)
659 {
660 	static char p[100];
661 	sprintf(p, " %-36s ", (*ptr)->datainfo.option);
662 	return p;
663 }
664 
665 /*
666  * File redraw routine. Draws current list on screen.
667  */
fredraw(CELL * c)668 int fredraw (CELL * c)
669 {
670 	register int row = c->srow;
671 	dlistptr p = c->list_start;
672 	int i = 0;
673 	char buff[200];
674 	if (c->ecol - c->scol)
675 		sprintf(buff, "%*s",c->ecol - c->scol + 1, " ");
676 	while (i <= c->erow - c->srow && p != NULL)
677 	{
678 		if (p == c->current) wattron(c->window,A_REVERSE);
679 			mvaddstr (row , c->scol, fDisplay(&p));
680 		if (p == c->current) wattroff(c->window,A_REVERSE);
681 			row++; i++;
682 		p = p->nextlistptr;
683 	}
684 	if (row <= c -> erow)
685 		for (; row <= c -> erow ; row++)
686 			mvaddstr(row, c->scol, buff);
687 	wrefresh(c->window);
688 	c -> redraw = FALSE;
689 	return TRUE;
690 }
691 
692 
cDisplay(dlistptr * ptr)693 char *cDisplay (dlistptr *ptr)
694 {
695 	static char p[100];
696 	if ((*ptr)->datainfo.type == BOOL_TYPE)
697 		sprintf(p, " %-28s %8s", (*ptr)->datainfo.option, (*ptr)->datainfo.integer? "On":"Off");
698 	else if ((*ptr)->datainfo.type == INT_TYPE)
699 		sprintf(p, " %-28s %8d", (*ptr)->datainfo.option, (*ptr)->datainfo.integer);
700 	return p;
701 }
702 
703 /*
704  * File redraw routine. Draws current list on screen.
705  */
credraw(CELL * c)706 int credraw (CELL * c)
707 {
708 register int row = c->srow;
709 dlistptr p = c->list_start;
710 int i = 0;
711 char buff[200];
712 	if (c->ecol - c->scol)
713 		sprintf(buff, "%*s",c->ecol - c->scol + 1, " ");
714 
715 	while (i <= c->erow - c->srow && p != NULL)
716 	{
717 		if (p == c->current) wattron(c->window,A_REVERSE);
718 			mvaddstr (row , c->scol, cDisplay(&p));
719 		if (p == c->current) wattroff(c->window,A_REVERSE);
720 			row++; i++;
721 		p = p->nextlistptr;
722 	}
723 	if (row <= c -> erow)
724 		for (; row <= c -> erow ; row++)
725 			mvaddstr(row, c->scol, buff);
726 	wrefresh(c->window);
727 	c -> redraw = FALSE;
728 	return TRUE;
729 }
730 
731 /*
732  * Basically setup values for where the box is to appear.
733  * setup function pointers to default.
734  * save the screen.
735  *	loop
736  *	  execute dispatch key routine
737  *	until ESC or E or termkey is not equal to 0
738  *	retore screen
739  * and return to caller
740  * true indicates that the function was successful in executing whatever
741  * it was supposed to do.
742  */
743  /* In this case also
744   * setup the old drive and path information,
745   * set the current path to Quote Master export directory and
746   * filename to worksheet extension
747   */
main_dir(CELL * c)748 int main_dir(CELL *c) {
749 int i;
750 
751 	getcwd(current_path, sizeof(current_path));
752 	strcat(current_path, "/.config.h");
753 	load_file(current_path);
754 
755 	c->keytable = file_cpy_menu;
756 	c->func_table = file_cpy_table;
757 	c->ListEntryProc = File_Entry;
758 	c->UpdateStatusProc = status_update;
759 	c->redraw = TRUE;
760 	c->ListExitProc = List_Exit;
761 	c->ListPaintProc = fredraw;
762 
763 	c->srow = 3;
764 	c->scol = 1;
765 	c->erow = c->window->_maxy - 5;
766 	c->ecol = c->window->_maxx - 1;
767 	c->max_rows = c->window->_maxy;
768 	c->max_cols = c->window->_maxx;
769 
770 	c->filename = "[ BitchX Config ]";
771 	c->menu_bar = 0;
772 	c->normcolor = 0x07;
773 	c->barcolor = 0x1f;
774 	init_dlist(c);
775 	for (i = 0; config_type[i].option; i++)
776 		insert_fdlist(c, &config_type[i]);
777 
778 
779 	/*
780 	* Go Do It
781 	*/
782 	do {
783 		c->redraw = TRUE;
784 		ls_dispatch(c);
785 	} while (c->termkey != ESC && c->termkey != ALT_X);
786 	return TRUE;
787 }
788 
Compile_Exit(CELL * c)789 int Compile_Exit(CELL *c) {
790 dlistptr ptr = c->start;
791 int i;
792 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
793 		compile_default[i].integer = ptr->datainfo.integer;
794 	clear_dlist(c);
795 	return TRUE;
796 }
797 
compile_dir(CELL * c)798 int compile_dir(CELL *c) {
799 CELL compile = { 0 };
800 int i;
801 	compile.window = c->window;
802 	compile.keytable = file_cpy_menu;
803 	compile.func_table = compile_cpy_table;
804 	compile.ListEntryProc = File_Entry;
805 	compile.UpdateStatusProc = status_update;
806 	compile.redraw = TRUE;
807 	compile.ListExitProc = Compile_Exit;
808 	compile.ListPaintProc = credraw;
809 
810 	compile.srow = 3;
811 	compile.scol = 1;
812 	compile.erow = compile.window->_maxy - 5;
813 	compile.ecol = compile.window->_maxx - 1;
814 	compile.max_rows = compile.window->_maxy;
815 	compile.max_cols = compile.window->_maxx;
816 
817 	compile.filename = "[ BitchX Config ]";
818 	compile.menu_bar = 0;
819 	compile.normcolor = 0x07;
820 	compile.barcolor = 0x1f;
821 	init_dlist(&compile);
822 	for (i = 0; compile_default[i].option; i++)
823 		insert_fdlist(&compile, &compile_default[i]);
824 
825 
826 	/*
827 	* Go Do It
828 	*/
829 	do {
830 		compile.redraw = TRUE;
831 		ls_dispatch(&compile);
832 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
833 	c->redraw = TRUE;
834 	return TRUE;
835 }
836 
userlist_Exit(CELL * c)837 int userlist_Exit (CELL *c)
838 {
839 int i;
840 dlistptr ptr = c->start;
841 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
842 		userlist_default[i].integer = ptr->datainfo.integer;
843 	clear_dlist(c);
844 	return TRUE;
845 }
846 
userlist_dir(CELL * c)847 int userlist_dir(CELL *c) {
848 CELL compile = { 0 };
849 int i;
850 	compile.window = c->window;
851 	compile.keytable = file_cpy_menu;
852 	compile.func_table = compile_cpy_table;
853 	compile.ListEntryProc = File_Entry;
854 	compile.UpdateStatusProc = status_update;
855 	compile.redraw = TRUE;
856 	compile.ListExitProc = userlist_Exit;
857 	compile.ListPaintProc = credraw;
858 
859 	compile.srow = 3;
860 	compile.scol = 1;
861 	compile.erow = compile.window->_maxy - 5;
862 	compile.ecol = compile.window->_maxx - 1;
863 	compile.max_rows = compile.window->_maxy;
864 	compile.max_cols = compile.window->_maxx;
865 
866 	compile.filename = "[ BitchX CSET/Userlist Config ]";
867 	compile.menu_bar = 0;
868 	compile.normcolor = 0x07;
869 	compile.barcolor = 0x1f;
870 	init_dlist(&compile);
871 	for (i = 0; userlist_default[i].option; i++)
872 		insert_fdlist(&compile, &userlist_default[i]);
873 
874 
875 	/*
876 	* Go Do It
877 	*/
878 	do {
879 		compile.redraw = TRUE;
880 		ls_dispatch(&compile);
881 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
882 	c->redraw = TRUE;
883 	return TRUE;
884 }
885 
flood_Exit(CELL * c)886 int flood_Exit (CELL *c)
887 {
888 int i;
889 dlistptr ptr = c->start;
890 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
891 		flood_default[i].integer = ptr->datainfo.integer;
892 	clear_dlist(c);
893 	return TRUE;
894 }
895 
flood_dir(CELL * c)896 int flood_dir(CELL *c) {
897 CELL compile = { 0 };
898 int i;
899 	compile.window = c->window;
900 	compile.keytable = file_cpy_menu;
901 	compile.func_table = compile_cpy_table;
902 	compile.ListEntryProc = File_Entry;
903 	compile.UpdateStatusProc = status_update;
904 	compile.redraw = TRUE;
905 	compile.ListExitProc = flood_Exit;
906 	compile.ListPaintProc = credraw;
907 
908 	compile.srow = 3;
909 	compile.scol = 1;
910 	compile.erow = compile.window->_maxy - 5;
911 	compile.ecol = compile.window->_maxx - 1;
912 	compile.max_rows = compile.window->_maxy;
913 	compile.max_cols = compile.window->_maxx;
914 
915 	compile.filename = "[ BitchX Flood Config ]";
916 	compile.menu_bar = 0;
917 	compile.normcolor = 0x07;
918 	compile.barcolor = 0x1f;
919 	init_dlist(&compile);
920 	for (i = 0; flood_default[i].option; i++)
921 		insert_fdlist(&compile, &flood_default[i]);
922 
923 
924 	/*
925 	* Go Do It
926 	*/
927 	do {
928 		compile.redraw = TRUE;
929 		ls_dispatch(&compile);
930 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
931 
932 	c->redraw = TRUE;
933 	return TRUE;
934 }
935 
936 
dcc_Exit(CELL * c)937 int dcc_Exit (CELL *c)
938 {
939 int i;
940 dlistptr ptr = c->start;
941 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
942 		dcc_default[i].integer = ptr->datainfo.integer;
943 	clear_dlist(c);
944 	return TRUE;
945 }
946 
dcc_dir(CELL * c)947 int dcc_dir(CELL *c) {
948 CELL compile = { 0 };
949 int i;
950 	compile.window = c->window;
951 	compile.keytable = file_cpy_menu;
952 	compile.func_table = compile_cpy_table;
953 	compile.ListEntryProc = File_Entry;
954 	compile.UpdateStatusProc = status_update;
955 	compile.redraw = TRUE;
956 	compile.ListExitProc = dcc_Exit;
957 	compile.ListPaintProc = credraw;
958 
959 	compile.srow = 3;
960 	compile.scol = 1;
961 	compile.erow = compile.window->_maxy - 5;
962 	compile.ecol = compile.window->_maxx - 1;
963 	compile.max_rows = compile.window->_maxy;
964 	compile.max_cols = compile.window->_maxx;
965 
966 	compile.filename = "[ BitchX DCC Config ]";
967 	compile.menu_bar = 0;
968 	compile.normcolor = 0x07;
969 	compile.barcolor = 0x1f;
970 	init_dlist(&compile);
971 	for (i = 0; dcc_default[i].option; i++)
972 		insert_fdlist(&compile, &dcc_default[i]);
973 
974 
975 	/*
976 	* Go Do It
977 	*/
978 	do {
979 		compile.redraw = TRUE;
980 		ls_dispatch(&compile);
981 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
982 
983 	c->redraw = TRUE;
984 	return TRUE;
985 }
986 
server_Exit(CELL * c)987 int server_Exit (CELL *c)
988 {
989 int i;
990 dlistptr ptr = c->start;
991 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
992 		server_default[i].integer = ptr->datainfo.integer;
993 	clear_dlist(c);
994 	return TRUE;
995 }
996 
server_dir(CELL * c)997 int server_dir(CELL *c) {
998 CELL compile = { 0 };
999 int i;
1000 	compile.window = c->window;
1001 	compile.keytable = file_cpy_menu;
1002 	compile.func_table = compile_cpy_table;
1003 	compile.ListEntryProc = File_Entry;
1004 	compile.UpdateStatusProc = status_update;
1005 	compile.redraw = TRUE;
1006 	compile.ListExitProc = server_Exit;
1007 	compile.ListPaintProc = credraw;
1008 
1009 	compile.srow = 3;
1010 	compile.scol = 1;
1011 	compile.erow = compile.window->_maxy - 5;
1012 	compile.ecol = compile.window->_maxx - 1;
1013 	compile.max_rows = compile.window->_maxy;
1014 	compile.max_cols = compile.window->_maxx;
1015 
1016 	compile.filename = "[ BitchX Server Config ]";
1017 	compile.menu_bar = 0;
1018 	compile.normcolor = 0x07;
1019 	compile.barcolor = 0x1f;
1020 	init_dlist(&compile);
1021 	for (i = 0; server_default[i].option; i++)
1022 		insert_fdlist(&compile, &server_default[i]);
1023 
1024 
1025 	/*
1026 	* Go Do It
1027 	*/
1028 	do {
1029 		compile.redraw = TRUE;
1030 		ls_dispatch(&compile);
1031 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
1032 
1033 	c->redraw = TRUE;
1034 	return TRUE;
1035 }
1036 
various_Exit(CELL * c)1037 int various_Exit (CELL *c)
1038 {
1039 int i;
1040 dlistptr ptr = c->start;
1041 	for (i = 0; ptr; ptr = ptr->nextlistptr, i++)
1042 		various_default[i].integer = ptr->datainfo.integer;
1043 	clear_dlist(c);
1044 	return TRUE;
1045 }
1046 
various_dir(CELL * c)1047 int various_dir(CELL *c) {
1048 CELL compile = { 0 };
1049 int i;
1050 	compile.window = c->window;
1051 	compile.keytable = file_cpy_menu;
1052 	compile.func_table = compile_cpy_table;
1053 	compile.ListEntryProc = File_Entry;
1054 	compile.UpdateStatusProc = status_update;
1055 	compile.redraw = TRUE;
1056 	compile.ListExitProc = various_Exit;
1057 	compile.ListPaintProc = credraw;
1058 
1059 	compile.srow = 3;
1060 	compile.scol = 1;
1061 	compile.erow = compile.window->_maxy - 5;
1062 	compile.ecol = compile.window->_maxx - 1;
1063 	compile.max_rows = compile.window->_maxy;
1064 	compile.max_cols = compile.window->_maxx;
1065 
1066 	compile.filename = "[ BitchX Various Config ]";
1067 	compile.menu_bar = 0;
1068 	compile.normcolor = 0x07;
1069 	compile.barcolor = 0x1f;
1070 	init_dlist(&compile);
1071 	for (i = 0; various_default[i].option; i++)
1072 		insert_fdlist(&compile, &various_default[i]);
1073 
1074 
1075 	/*
1076 	* Go Do It
1077 	*/
1078 	do {
1079 		compile.redraw = TRUE;
1080 		ls_dispatch(&compile);
1081 	} while (compile.termkey != ESC && compile.termkey != ALT_X);
1082 
1083 	c->redraw = TRUE;
1084 	return TRUE;
1085 }
1086 
eDisplay(dlistptr * ptr)1087 char *eDisplay (dlistptr *ptr)
1088 {
1089 	static char p[100];
1090 	char str[40];
1091 	sprintf(str, "%d", (*ptr)->datainfo.integer);
1092 	sprintf(p, "%14s", str);
1093 	return p;
1094 }
1095 
1096 /*
1097  * File redraw routine. Draws current list on screen.
1098  */
eredraw(CELL * c)1099 int eredraw (CELL * c)
1100 {
1101 register int row = c->srow;
1102 dlistptr p = c->list_start;
1103 int i = 0;
1104 char buff[200];
1105 
1106 	if (c->ecol - c->scol)
1107 		sprintf(buff, "%*s",c->ecol - c->scol + 1, " ");
1108 
1109 	while (i <= c->erow - c->srow && p != NULL)
1110 	{
1111 		if (p == c->current) wattron(c->window,A_REVERSE);
1112 			mvaddstr (row , c->scol+4, eDisplay(&p));
1113 		if (p == c->current) wattroff(c->window,A_REVERSE);
1114 			row++; i++;
1115 		p = p->nextlistptr;
1116 	}
1117 	if (row <= c -> erow)
1118 		for (; row <= c -> erow ; row++)
1119 			mvaddstr(row, c->scol, buff);
1120 	wrefresh(c->window);
1121 	c -> redraw = FALSE;
1122 	return TRUE;
1123 }
1124 
Edit_Entry(CELL * c)1125 int Edit_Entry(CELL *c) {
1126 char tmp[180];
1127 	memset(tmp, ' ', sizeof(tmp)-1);
1128 	tmp[c->ecol - 2 - c->scol - 4] = 0;
1129 	mvwaddstr (c->window, c->srow - 1 , c->scol, tmp);
1130 	mvwaddstr (c->window, c->srow - 1, c->scol + 4, c->start->datainfo.option);
1131 	wrefresh(c->window);
1132 	c->current = c->list_start = c->list_end = c->start;
1133 	return TRUE;
1134 }
1135 
edit_enter(CELL * c)1136 int edit_enter (CELL *c)
1137 {
1138 char tmp[180];
1139 	memset(tmp, ' ', sizeof(tmp)-1);
1140 	tmp[c->ecol - 2 - c->scol - 4] = 0;
1141 	if (c->current->datainfo.type == INT_TYPE)
1142 	{
1143 		c->redraw = TRUE;
1144 		c->termkey = '\n';
1145 	}
1146 	mvwaddstr (c->window, c->srow , c->scol, tmp);
1147 	return TRUE;
1148 }
1149 
edit_line(CELL * c)1150 int edit_line(CELL *c)
1151 {
1152 int found = 0;
1153 int end = 0;
1154 	if (c->current->datainfo.type == INT_TYPE)
1155 		found = INT_TYPE;
1156 	else if (c->current->datainfo.type == STR_TYPE)
1157 		found = STR_TYPE;
1158 	if (!found || ((found == INT_TYPE) && !isdigit(c->key)) || ((found == STR_TYPE) && !isalpha(c->key)))
1159 		if (!iscntrl(c->key))
1160 			return TRUE;
1161 	end = strlen(c->current->datainfo.save);
1162 	switch(c->key)
1163 	{
1164 		case KEY_BACKSPACE:
1165 			if (*c->current->datainfo.save)
1166 				c->current->datainfo.save[end - 1] = 0;
1167 			break;
1168 		default:
1169 			if (iscntrl(c->key))
1170 				return TRUE;
1171 			if (end < MAXLEN)
1172 				c->current->datainfo.save[end] = c->key;
1173 			else
1174 				beep();
1175 	}
1176 	if (found == INT_TYPE)
1177 	{
1178 		unsigned long temp = 0;
1179 		if (*c->current->datainfo.save)
1180 		{
1181 			temp = strtoul(c->current->datainfo.save, NULL, 10);
1182 			if (temp < 2147483647)
1183 				c->current->datainfo.integer = temp;
1184 			else
1185 				c->current->datainfo.save[end] = 0;
1186 		}
1187 		else
1188 			c->current->datainfo.integer = 0;
1189 	}
1190 	c->redraw = TRUE;
1191 	return TRUE;
1192 }
1193 
edit_exit(CELL * c)1194 int edit_exit(CELL *c)
1195 {
1196 char tmp[180];
1197 	memset(tmp, ' ', sizeof(tmp)-1);
1198 	tmp[c->ecol - 2 - c->scol - 4] = 0;
1199 	mvwaddstr (c->window, c->srow - 1 , c->scol, tmp);
1200 	mvwaddstr (c->window, c->srow , c->scol, tmp);
1201 	return TRUE;
1202 }
1203 
edit_dir(CELL * c)1204 int edit_dir(CELL *c)
1205 {
1206 CELL edit = { 0 };
1207 dlistptr ptr = NULL;
1208 
1209 	edit.window = c->window;
1210 	edit.keytable = file_cpy_menu;
1211 	edit.func_table = edit_cpy_table;
1212 	edit.ListEntryProc = Edit_Entry;
1213 	edit.redraw = TRUE;
1214 	edit.ListPaintProc = eredraw;
1215 	edit.ListExitProc = edit_exit;
1216 
1217 	edit.current_event = edit_line;
1218 
1219 	edit.srow = edit.window->_maxy - 2;
1220 	edit.scol = 1;
1221 	edit.erow = edit.window->_maxy - 2;
1222 	edit.ecol = edit.window->_maxx - 1;
1223 	edit.max_rows = edit.window->_maxy;
1224 	edit.max_cols = edit.window->_maxx;
1225 
1226 	edit.menu_bar = 0;
1227 	edit.normcolor = 0x07;
1228 	edit.barcolor = 0x1f;
1229 
1230 	ptr = (dlistptr) calloc(1, sizeof(struct dlistmem));
1231 	edit.start = ptr;
1232 	ptr->datainfo.option = (char *) malloc(strlen(c->current->datainfo.option)+1);
1233 	strcpy(ptr->datainfo.option, c->current->datainfo.option);
1234 	ptr->datainfo.integer = c->current->datainfo.integer;
1235 	ptr->datainfo.type = c->current->datainfo.type;
1236 	ptr->datainfo.save = (char *) malloc(MAXLEN+1);
1237 	memset(ptr->datainfo.save, 0, MAXLEN);
1238 
1239 	/*
1240 	* Go Do It
1241 	*/
1242 	do
1243 	{
1244 		edit.redraw = TRUE;
1245 		ls_dispatch(&edit);
1246 	} while (edit.termkey != ESC && edit.termkey != ALT_X && edit.termkey != '\n');
1247 	c->redraw = TRUE;
1248 	if (edit.termkey == '\n')
1249 		c->current->datainfo.integer = edit.current->datainfo.integer;
1250 	clear_dlist(&edit);
1251 	return TRUE;
1252 }
1253 
main()1254 int main() {
1255 CELL file_cpy = {0};
1256 WINDOW *mainwin;
1257 	mainwin = initscr();
1258 	start_color();
1259 	setup_colors();
1260 	cbreak();
1261 	noecho();
1262 	keypad(mainwin, TRUE);
1263 	meta(mainwin, TRUE);
1264 	raw();
1265 
1266 	leaveok(mainwin, TRUE);
1267 	wbkgd(mainwin, COLOR_PAIR(COLOR_MAIN));
1268 	wattron(mainwin, COLOR_PAIR(COLOR_MAIN));
1269 	werase(mainwin);
1270 	refresh();
1271 
1272 	file_cpy.window = mainwin;
1273 
1274 	main_dir(&file_cpy);
1275 
1276 	wbkgd(mainwin, A_NORMAL);
1277 	werase(mainwin);
1278 	echo();
1279 	nocbreak();
1280 	noraw();
1281 	refresh();
1282 	endwin();
1283 	return TRUE;
1284 }
1285