applied 3 additional patches by Dimitris

This commit is contained in:
Anselm R Garbe 2014-11-14 16:06:28 +01:00
parent 5eaa0fff0d
commit 6703fe4592
3 changed files with 99 additions and 30 deletions

View File

@ -34,7 +34,7 @@ clean:
dist: clean
@echo creating dist tarball
@mkdir -p sic-${VERSION}
@cp -R LICENSE Makefile README config.mk sic.1 sic.c util.c sic-${VERSION}
@cp -R LICENSE Makefile README config.def.h config.mk sic.1 sic.c util.c sic-${VERSION}
@tar -cf sic-${VERSION}.tar sic-${VERSION}
@gzip sic-${VERSION}.tar
@rm -rf sic-${VERSION}

63
arg.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Copy me if you can.
* by 20h
*/
#ifndef ARG_H__
#define ARG_H__
extern char *argv0;
/* use main(int argc, char *argv[]) */
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
argv[0] && argv[0][1]\
&& argv[0][0] == '-';\
argc--, argv++) {\
char argc_;\
char **argv_;\
int brk_;\
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
argv++;\
argc--;\
break;\
}\
for (brk_ = 0, argv[0]++, argv_ = argv;\
argv[0][0] && !brk_;\
argv[0]++) {\
if (argv_ != argv)\
break;\
argc_ = argv[0][0];\
switch (argc_)
/* Handles obsolete -NUM syntax */
#define ARGNUM case '0':\
case '1':\
case '2':\
case '3':\
case '4':\
case '5':\
case '6':\
case '7':\
case '8':\
case '9'
#define ARGEND }\
}
#define ARGC() argc_
#define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base)))
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
((x), abort(), (char *)0) :\
(brk_ = 1, (argv[0][1] != '\0')?\
(&argv[0][1]) :\
(argc--, argv++, argv[0])))
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
(char *)0 :\
(brk_ = 1, (argv[0][1] != '\0')?\
(&argv[0][1]) :\
(argc--, argv++, argv[0])))
#endif

44
sic.c
View File

@ -8,8 +8,10 @@
#include <time.h>
#include <unistd.h>
#include "arg.h"
#include "config.h"
char *argv0;
static char *host = DEFAULT_HOST;
static char *port = DEFAULT_PORT;
static char *password;
@ -133,40 +135,44 @@ parsesrv(char *cmd) {
}
}
static void
usage(void) {
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n", argv0);
}
int
main(int argc, char *argv[]) {
int i, c;
struct timeval tv;
const char *user = getenv("USER");
int n;
fd_set rd;
strlcpy(nick, user ? user : "unknown", sizeof nick);
for(i = 1; i < argc; i++) {
c = argv[i][1];
if(argv[i][0] != '-' || argv[i][2])
c = -1;
switch(c) {
ARGBEGIN {
case 'h':
if(++i < argc) host = argv[i];
host = EARGF(usage());
break;
case 'p':
if(++i < argc) port = argv[i];
port = EARGF(usage());
break;
case 'n':
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
strlcpy(nick, EARGF(usage()), sizeof nick);
break;
case 'k':
if(++i < argc) password = argv[i];
password = EARGF(usage());
break;
case 'v':
eprint("sic-"VERSION", © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
eprint("sic-"VERSION", © 2005-2014 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
break;
default:
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
}
}
usage();
} ARGEND;
/* init */
i = dial(host, port);
srv = fdopen(i, "r+");
srv = fdopen(dial(host, port), "r+");
if (!srv)
eprint("fdopen:");
/* login */
if(password)
sout("PASS %s", password);
@ -181,13 +187,13 @@ main(int argc, char *argv[]) {
FD_SET(fileno(srv), &rd);
tv.tv_sec = 120;
tv.tv_usec = 0;
i = select(fileno(srv) + 1, &rd, 0, 0, &tv);
if(i < 0) {
n = select(fileno(srv) + 1, &rd, 0, 0, &tv);
if(n < 0) {
if(errno == EINTR)
continue;
eprint("sic: error on select():");
}
else if(i == 0) {
else if(n == 0) {
if(time(NULL) - trespond >= 300)
eprint("sic shutting down: parse timeout\n");
sout("PING %s", host);