Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 586 lines (575 sloc) 12.979 kb
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
1 /*
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
2 quIRC - simple terminal-based IRC client
4e3364b Sound and Fury Nudge copyright year to 2013
authored
3 Copyright (C) 2010-13 Edward Cree
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
4
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
5 See quirc.c for license information
6 config: rc file and option parsing
7 */
8
9 #include "config.h"
d6da95d Sound and Fury Rejiggered many #includes and the Makefile
authored
10 #include "bits.h"
11 #include "colour.h"
12 #include "text.h"
13 #include "version.h"
14 #include "buffer.h"
15 #include "strbuf.h"
16 #include "ttyesc.h"
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
17
62617ff Configurable keymapping
ec429 authored
18 #include "keymap.c"
19
20 void loadkeys(FILE *fp)
21 {
22 if(!fp) return;
23 while(!feof(fp))
24 {
25 char *line=fgetl(fp);
26 if(line)
27 {
28 if((*line)&&(*line!='#'))
29 {
30 keymod new;
31 new.name=strtok(line, " \t");
32 char *mod=strtok(NULL, " \t");
33 if(!mod)
34 {
35 char msg[32+strlen(new.name)];
36 sprintf(msg, "keys: missing mod in %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
37 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
38 free(line);
39 continue;
40 }
41 off_t o=strlen(mod);
42 if(o&1)
43 {
44 char msg[32+strlen(new.name)];
45 sprintf(msg, "keys: odd mod length in %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
46 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
47 free(line);
48 continue;
49 }
50 new.mod=malloc((o>>1)+1);
51 if(!new.mod)
52 {
53 char msg[32+strlen(new.name)];
54 sprintf(msg, "keys: malloc failure in %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
55 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
56 free(line);
57 continue;
58 }
59 bool cont=false;
60 for(int i=0;i<o;i+=2)
61 {
62 if(!(isxdigit(mod[i])&&isxdigit(mod[i+1])))
63 {
64 char msg[32+strlen(new.name)];
65 sprintf(msg, "keys: bad mod (not hex) in %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
66 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
67 free(line);
68 cont=true;
69 break;
70 }
71 char buf[3];buf[0]=mod[i];buf[1]=mod[i+1];buf[2]=0;
72 unsigned int c;
73 if(sscanf(buf, "%x", &c)!=1)
74 {
75 char msg[32+strlen(new.name)];
76 sprintf(msg, "keys: sscanf failed in %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
77 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
78 free(line);
79 cont=true;
80 break;
81 }
82 new.mod[i>>1]=c;
83 }
84 if(cont) continue;
85 new.mod[o>>1]=0;
86 bool match=false;
f146cd2 Sound and Fury cleanup: fix some memory leaks. There's still something in getaddrinfo_...
authored
87 for(unsigned int i=0;i<nkeys;i++)
62617ff Configurable keymapping
ec429 authored
88 {
89 if(strcmp(new.name, kmap[i].name)==0)
90 {
91 free(kmap[i].mod);
92 kmap[i].mod=strdup(new.mod);
93 match=true;
94 }
95 }
96 if(!match)
97 {
98 char msg[32+strlen(new.name)];
99 sprintf(msg, "keys: unrecognised name %s", new.name);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
100 atr_failsafe(&s_buf, ERR, msg, "init: ");
62617ff Configurable keymapping
ec429 authored
101 }
102 free(new.mod);
103 }
104 free(line);
105 }
106 else
107 break;
108 }
109 return;
110 }
111
de4ae60 config: generate much of the config code from a concise descriptions fil...
ec429 authored
112 #include "config_check.c"
113
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
114 int def_config(void)
115 {
de4ae60 config: generate much of the config code from a concise descriptions fil...
ec429 authored
116 #include "config_def.c"
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
117 autojoin=true;
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
118 int l, c;
119 if(!termsize(STDIN_FILENO, &c, &l))
120 {
121 height=max(l, 5);
122 width=max(c, 30);
123 }
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
124 char *cols=getenv("COLUMNS"), *rows=getenv("LINES");
125 if(cols) sscanf(cols, "%u", &width);
126 if(rows) sscanf(rows, "%u", &height);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
127 servs=NULL;
a21b9dd Add /ignores in .quirc
Sound and Fury authored
128 igns=NULL;
86c5674 Fix & improve the line editing
Sound and Fury authored
129 portno=strdup("6667");
1e291c6 Use $USER for the default value of _username_ (used at connect time)
ec429 authored
130 char *eu=getenv("USER");
131 username=strdup(eu?eu:"quirc");
ac2ac2c Backport fixes from openSUSE (pbleser)
ec429 authored
132 fname=malloc(64+strlen(VERSION_TXT));
1e291c6 Use $USER for the default value of _username_ (used at connect time)
ec429 authored
133 nick=strdup(eu?eu:"ac");
44b847a If --uname then use it instead of username for default nick
ec429 authored
134 defnick=true;
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
135 pass=NULL;
552a329 Sound and Fury Use github address in CTCP SOURCE response (and refactor with fname)
authored
136 snprintf(fname, 64+strlen(VERSION_TXT), "quIRC %hhu.%hhu.%hhu%s%s : %s", VERSION_MAJ, VERSION_MIN, VERSION_REV, VERSION_TXT[0]?"-":"", VERSION_TXT, CLIENT_SOURCE);
ac2ac2c Backport fixes from openSUSE (pbleser)
ec429 authored
137 version=malloc(16+strlen(VERSION_TXT));
138 snprintf(version, 16+strlen(VERSION_TXT), "%hhu.%hhu.%hhu%s%s", VERSION_MAJ, VERSION_MIN, VERSION_REV, VERSION_TXT[0]?"-":"", VERSION_TXT);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
139 return(0);
140 }
141
142 int rcread(FILE *rcfp)
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
143 {
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
144 int nerrors=0; // number of lines with errors
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
145 while(!feof(rcfp))
146 {
147 char *line=fgetl(rcfp);
448a19f Don't preserve trailing \n in fgetl()
Sound and Fury authored
148 char *cmd=*line?strtok(line, " \t"):line;
149 if((*cmd=='#') || (!*cmd)) // #lines are comments, blank lines are ignored
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
150 {
151 // do nothing
152 }
153 else if(*cmd=='%')
154 {
155 int which=0;
156 // custom colours
157 if(*++cmd=='S')
158 {
159 which=1;
160 cmd++;
161 }
162 else if(*cmd=='R')
163 {
164 which=2;
165 cmd++;
166 }
167 colour *what=NULL;
168 if(strcmp(cmd, "msg")==0)
169 {
170 what=c_msg;
171 }
172 else if(strcmp(cmd, "notice")==0)
173 {
174 what=c_notice;
175 }
176 else if(strcmp(cmd, "join")==0)
177 {
178 what=c_join;
179 }
180 else if(strcmp(cmd, "part")==0)
181 {
182 what=c_part;
183 }
184 else if(strcmp(cmd, "quit")==0)
185 {
186 what=c_quit;
187 }
188 else if(strcmp(cmd, "nick")==0)
189 {
190 what=c_nick;
191 }
192 else if(strcmp(cmd, "act")==0)
193 {
194 what=c_actn;
195 }
196 else if(strcmp(cmd, "status")==0)
197 {
198 what=&c_status;which=-1;
199 }
200 else if(strcmp(cmd, "err")==0)
201 {
202 what=&c_err;which=-1;
203 }
204 else if(strcmp(cmd, "unk")==0)
205 {
206 what=&c_unk;which=-1;
207 }
208 else if(strcmp(cmd, "unn")==0)
209 {
210 what=&c_unn;which=-1;
211 }
212 if(what)
213 {
448a19f Don't preserve trailing \n in fgetl()
Sound and Fury authored
214 char *spec=strtok(NULL, "");
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
215 colour new;int hi, ul;
216 sscanf(spec, "%d %d %d %d", &new.fore, &new.back, &hi, &ul);
217 new.hi=hi;new.ul=ul;
218 if(which!=2)
219 what[0]=new;
220 if((which%2)==0)
221 what[1]=new;
222 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
223 else
224 {
7cb81a2 start_buffer, catches messages produced before bufs initialised
ec429 authored
225 char msg[48+strlen(cmd)];
226 sprintf(msg, "rc: Unrecognised ident in %%colour (%s)", cmd);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
227 atr_failsafe(&s_buf, ERR, msg, "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
228 nerrors++;
229 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
230 }
231 else
232 {
448a19f Don't preserve trailing \n in fgetl()
Sound and Fury authored
233 char *rest=strtok(NULL, "");
de4ae60 config: generate much of the config code from a concise descriptions fil...
ec429 authored
234 bool need=true;
235 #include "config_need.c"
236 if(need&&!rest)
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
237 {
7cb81a2 start_buffer, catches messages produced before bufs initialised
ec429 authored
238 char msg[40+strlen(cmd)];
239 sprintf(msg, "rc: Command (%s) without argument", cmd);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
240 atr_failsafe(&s_buf, ERR, msg, "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
241 nerrors++;
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
242 }
243 else if(strcmp(cmd, "server")==0)
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
244 {
245 servlist * new=(servlist *)malloc(sizeof(servlist));
246 new->next=servs;
247 new->name=strdup(rest);
248 new->nick=strdup(nick);
249 new->portno=strdup(portno);
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
250 new->pass=pass?strdup(pass):NULL;
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
251 new->join=false;
252 new->chans=NULL;
a21b9dd Add /ignores in .quirc
Sound and Fury authored
253 new->igns=NULL;
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
254 servs=new;
255 }
256 else if(servs && (strcmp(cmd, "*port")==0))
257 {
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
258 free(servs->portno);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
259 servs->portno=strdup(rest);
260 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
261 else if(strcmp(cmd, "port")==0)
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
262 {
263 free(portno);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
264 portno=strdup(rest);
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
265 }
266 else if(strcmp(cmd, "pass")==0)
267 {
268 free(pass);
269 pass=strdup(rest);
270 }
271 else if(servs && (strcmp(cmd, "*pass")==0))
272 {
273 free(servs->pass);
274 servs->pass=strdup(rest);
275 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
276 else if(strcmp(cmd, "uname")==0)
44b847a If --uname then use it instead of username for default nick
ec429 authored
277 {
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
278 username=strdup(rest);
44b847a If --uname then use it instead of username for default nick
ec429 authored
279 if(defnick)
280 {
281 free(nick);
282 nick=strdup(username);
283 }
284 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
285 else if(strcmp(cmd, "fname")==0)
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
286 {
287 free(fname);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
288 fname=strdup(rest);
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
289 }
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
290 else if(servs && (strcmp(cmd, "*nick")==0))
291 {
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
292 free(servs->nick);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
293 servs->nick=strdup(rest);
294 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
295 else if(strcmp(cmd, "nick")==0)
44b847a If --uname then use it instead of username for default nick
ec429 authored
296 {
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
297 free(nick);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
298 nick=strdup(rest);
44b847a If --uname then use it instead of username for default nick
ec429 authored
299 defnick=false;
300 }
a21b9dd Add /ignores in .quirc
Sound and Fury authored
301 else if(strcmp(cmd, "ignore")==0)
302 {
303 char *sw=strtok(rest, " \t");
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
304 if(*sw!='-')
305 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
306 atr_failsafe(&s_buf, ERR, "rc: ignore: need options (use '-' for no options)", "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
307 nerrors++;
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
308 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
309 else
a21b9dd Add /ignores in .quirc
Sound and Fury authored
310 {
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
311 rest=strtok(NULL, "");
312 if(!rest)
a21b9dd Add /ignores in .quirc
Sound and Fury authored
313 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
314 atr_failsafe(&s_buf, ERR, "rc: ignore: need options (use '-' for no options)", "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
315 nerrors++;
a21b9dd Add /ignores in .quirc
Sound and Fury authored
316 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
317 else
a21b9dd Add /ignores in .quirc
Sound and Fury authored
318 {
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
319 bool icase=strchr(sw, 'i');
320 bool pms=strchr(sw, 'p');
321 bool regex=strchr(sw, 'r');
322 if(regex)
323 {
324 name *new=n_add(&igns, rest, RFC1459);
325 if(new)
326 {
327 new->icase=icase;
328 new->pms=pms;
329 }
330 }
331 else
332 {
333 char *iusr=strtok(rest, "@");
334 char *ihst=strtok(NULL, "");
335 if((!iusr) || (*iusr==0) || (*iusr=='*'))
336 iusr="[^@]*";
337 if((!ihst) || (*ihst==0) || (*ihst=='*'))
338 ihst="[^@]*";
339 char expr[10+strlen(iusr)+strlen(ihst)];
340 sprintf(expr, "^%s[_~]*@%s$", iusr, ihst);
341 name *new=n_add(&igns, expr, RFC1459);
342 if(new)
343 {
344 new->icase=icase;
345 new->pms=pms;
346 }
347 }
a21b9dd Add /ignores in .quirc
Sound and Fury authored
348 }
349 }
350 }
351 else if(servs && (strcmp(cmd, "*ignore")==0))
352 {
353 char *sw=strtok(rest, " \t");
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
354 if(*sw!='-')
355 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
356 atr_failsafe(&s_buf, ERR, "rc: *ignore: need options (use '-' for no options)", "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
357 nerrors++;
594acbf Fix crash bug in parsing malformed .quirc files (null dereference)
Sound and Fury authored
358 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
359 else
a21b9dd Add /ignores in .quirc
Sound and Fury authored
360 {
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
361 rest=strtok(NULL, "");
362 if(!rest)
a21b9dd Add /ignores in .quirc
Sound and Fury authored
363 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
364 atr_failsafe(&s_buf, ERR, "rc: *ignore: need options (use '-' for no options)", "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
365 nerrors++;
a21b9dd Add /ignores in .quirc
Sound and Fury authored
366 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
367 else
a21b9dd Add /ignores in .quirc
Sound and Fury authored
368 {
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
369 bool icase=strchr(sw, 'i');
370 bool pms=strchr(sw, 'p');
371 bool regex=strchr(sw, 'r');
372 if(regex)
373 {
374 name *new=n_add(&servs->igns, rest, RFC1459);
375 if(new)
376 {
377 new->icase=icase;
378 new->pms=pms;
379 }
380 }
381 else
382 {
383 char *isrc,*iusr,*ihst;
384 prefix_split(rest, &isrc, &iusr, &ihst);
385 if((!isrc) || (*isrc==0) || (*isrc=='*'))
386 isrc="[^!@]*";
387 if((!iusr) || (*iusr==0) || (*iusr=='*'))
388 iusr="[^!@]*";
389 if((!ihst) || (*ihst==0) || (*ihst=='*'))
390 ihst="[^@]*";
391 char expr[16+strlen(isrc)+strlen(iusr)+strlen(ihst)];
392 sprintf(expr, "^%s[_~]*!%s@%s$", isrc, iusr, ihst);
393 name *new=n_add(&servs->igns, expr, RFC1459);
394 if(new)
395 {
396 new->icase=icase;
397 new->pms=pms;
398 }
399 }
a21b9dd Add /ignores in .quirc
Sound and Fury authored
400 }
401 }
402 }
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
403 else if(servs && (strcmp(cmd, "*chan")==0))
404 {
405 chanlist * new=(chanlist *)malloc(sizeof(chanlist));
406 new->next=servs->chans;
407 new->name=strdup(rest);
408 if((new->key=strpbrk(new->name, " \t")))
409 {
410 *new->key++=0;
870eaea Fix crash bug with chanlist->key (was not a free()able pointer)
Sound and Fury authored
411 new->key=strdup(new->key);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
412 }
a21b9dd Add /ignores in .quirc
Sound and Fury authored
413 new->igns=NULL;
f146cd2 Sound and Fury cleanup: fix some memory leaks. There's still something in getaddrinfo_...
authored
414 new->logt=LOGT_NONE;
415 new->logf=NULL;
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
416 servs->chans=new;
417 }
977e366 Configure logging in rc file with ">log $type $file" lines
ec429 authored
418 else if(servs && servs->chans && (strcmp(cmd, ">log")==0))
419 {
420 if(servs->chans->logf) fclose(servs->chans->logf);
421 char *type=strtok(rest, " \t");
422 logtype logt=LOGT_NONE;
423 if(strcasecmp(type, "plain")==0)
424 logt=LOGT_PLAIN;
425 else if(strcasecmp(type, "symbolic")==0)
426 logt=LOGT_SYMBOLIC;
427 else
428 {
429 atr_failsafe(&s_buf, ERR, "rc: >log: Unrecognised log type (valid types are: plain, symbolic)", "init: ");
430 nerrors++;
431 }
432 if(logt!=LOGT_NONE)
433 {
434 char *logf=strtok(NULL, "");
435 servs->chans->logf=fopen(logf, "a");
436 if(!servs->chans->logf)
437 {
438 atr_failsafe(&s_buf, ERR, "rc: >log: Failed to open log file for append", "init: ");
439 atr_failsafe(&s_buf, ERR, strerror(errno), "fopen: ");
440 nerrors++;
441 }
442 servs->chans->logt=logt;
443 }
444 }
de4ae60 config: generate much of the config code from a concise descriptions fil...
ec429 authored
445 #include "config_rcread.c"
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
446 else
447 {
7cb81a2 start_buffer, catches messages produced before bufs initialised
ec429 authored
448 char msg[48+strlen(cmd)];
e6c0fd7 Fix text error in message (rc file location)
ec429 authored
449 sprintf(msg, "rc: Unrecognised cmd %s in .quirc/rc (ignoring)", cmd);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
450 atr_failsafe(&s_buf, ERR, msg, "init: ");
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
451 nerrors++;
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
452 }
453 }
454 free(line);
455 }
15c709f Fixed bug with .quirc file and improved .quirc error handling
ec429 authored
456 return(nerrors);
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
457 }
458
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
459 signed int pargs(int argc, char *argv[])
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
460 {
461 bool check=false;
462 int arg;
463 for(arg=1;arg<argc;arg++)
464 {
465 if((strcmp(argv[arg], "--help")==0)||(strcmp(argv[arg], "-h")==0))
466 {
467 fprintf(stderr, USAGE_MSG);
f5e7385 Generated options list for --help output
ec429 authored
468 fprintf(stderr, "options:\n");
469 #include "config_help.c"
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
470 return(0);
471 }
472 else if((strcmp(argv[arg], "--version")==0)||(strcmp(argv[arg], "-V")==0)||(strcmp(argv[arg], "-v")==0)) // allow -v as we did in old versions; depr
473 {
474 fprintf(stderr, VERSION_MSG);
475 return(0);
476 }
477 else if((strcmp(argv[arg], "--no-server")==0)||(strcmp(argv[arg], "--no-auto-connect")==0)) // the "-auto" forms are from older versions; depr
478 {
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
479 freeservlist(servs);
480 servs=NULL;
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
481 }
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
482 else if(servs && ((strcmp(argv[arg], "--no-chan")==0)||(strcmp(argv[arg], "--no-auto-join")==0)))
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
483 {
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
484 autojoin=false;
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
485 }
cb19680 "--check" option, to check .quirc and cmdline for errors
Sound and Fury authored
486 else if((strcmp(argv[arg], "--check")==0)||(strcmp(argv[arg], "--lint")==0))
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
487 {
488 check=true;
489 }
490 else if(strncmp(argv[arg], "--server=", 9)==0)
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
491 {
492 servs=(servlist *)malloc(sizeof(servlist));
493 servs->next=NULL;
494 servs->name=strdup(argv[arg]+9);
495 servs->nick=strdup(nick);
496 servs->portno=strdup(portno);
497 servs->join=false;
498 servs->chans=NULL;
a21b9dd Add /ignores in .quirc
Sound and Fury authored
499 servs->igns=NULL;
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
500 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
501 else if(strncmp(argv[arg], "--port=", 7)==0)
86c5674 Fix & improve the line editing
Sound and Fury authored
502 {
503 free(portno);
504 portno=strdup(argv[arg]+7);
505 }
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
506 else if(strncmp(argv[arg], "--pass=", 7)==0)
507 {
508 free(pass);
509 pass=strdup(argv[arg]+7);
510 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
511 else if(strncmp(argv[arg], "--uname=", 8)==0)
86c5674 Fix & improve the line editing
Sound and Fury authored
512 {
513 free(username);
514 username=strdup(argv[arg]+8);
44b847a If --uname then use it instead of username for default nick
ec429 authored
515 if(defnick)
516 {
517 free(nick);
518 nick=strdup(username);
519 }
86c5674 Fix & improve the line editing
Sound and Fury authored
520 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
521 else if(strncmp(argv[arg], "--fname=", 8)==0)
86c5674 Fix & improve the line editing
Sound and Fury authored
522 {
523 free(fname);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
524 fname=argv[arg]+8;
86c5674 Fix & improve the line editing
Sound and Fury authored
525 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
526 else if(strncmp(argv[arg], "--nick=", 7)==0)
86c5674 Fix & improve the line editing
Sound and Fury authored
527 {
528 free(nick);
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
529 nick=strdup(argv[arg]+7);
44b847a If --uname then use it instead of username for default nick
ec429 authored
530 defnick=false;
86c5674 Fix & improve the line editing
Sound and Fury authored
531 }
57f8e48 Fix crash bug (using --chan with no server defined)
Sound and Fury authored
532 else if(servs && (strncmp(argv[arg], "--chan=", 7)==0))
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
533 {
534 chanlist * new=(chanlist *)malloc(sizeof(chanlist));
535 new->next=servs->chans;
536 new->name=strdup(argv[arg]+7);
537 if((new->key=strpbrk(new->name, " \t")))
538 {
539 *new->key++=0;
e9c745f Sound and Fury Fix some memory-management bugs with channel keys
authored
540 new->key=strdup(new->key);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
541 }
a21b9dd Add /ignores in .quirc
Sound and Fury authored
542 new->igns=NULL;
f146cd2 Sound and Fury cleanup: fix some memory leaks. There's still something in getaddrinfo_...
authored
543 new->logt=LOGT_NONE;
544 new->logf=NULL;
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
545 servs->chans=new;
546 }
de4ae60 config: generate much of the config code from a concise descriptions fil...
ec429 authored
547 #include "config_pargs.c"
cb19680 "--check" option, to check .quirc and cmdline for errors
Sound and Fury authored
548 else
549 {
7cb81a2 start_buffer, catches messages produced before bufs initialised
ec429 authored
550 char msg[40+strlen(argv[arg])];
551 sprintf(msg, "pargs: Unrecognised argument '%s'", argv[arg]);
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
552 atr_failsafe(&s_buf, ERR, msg, "init: ");
cb19680 "--check" option, to check .quirc and cmdline for errors
Sound and Fury authored
553 }
fcf9495 Refactored .quirc and cmdline parsing; other refactoring
Sound and Fury authored
554 }
555 if(check) return(0);
556 return(-1);
557 }
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
558
977e366 Configure logging in rc file with ">log $type $file" lines
ec429 authored
559 void freeservlist(servlist *serv)
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
560 {
561 if(serv)
562 {
4b8ff78 De-if all the free()s
ec429 authored
563 free(serv->name);
564 free(serv->nick);
565 free(serv->portno);
a1d59c7 Fixed some more memory leaks
ec429 authored
566 free(serv->pass);
567 n_free(serv->igns);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
568 freechanlist(serv->chans);
569 freeservlist(serv->next);
570 }
7cd540a Fix a memory leak
ec429 authored
571 free(serv);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
572 }
573
977e366 Configure logging in rc file with ">log $type $file" lines
ec429 authored
574 void freechanlist(chanlist *chan)
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
575 {
576 if(chan)
577 {
4b8ff78 De-if all the free()s
ec429 authored
578 free(chan->name);
579 free(chan->key);
977e366 Configure logging in rc file with ">log $type $file" lines
ec429 authored
580 if(chan->logf) fclose(chan->logf);
a1d59c7 Fixed some more memory leaks
ec429 authored
581 n_free(chan->igns);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
582 freechanlist(chan->next);
583 }
7cd540a Fix a memory leak
ec429 authored
584 free(chan);
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
585 }
Something went wrong with that request. Please try again.