gno compatibility

This commit is contained in:
Kelvin Sherlock 2012-07-09 22:44:46 -04:00
parent e8a24d7bda
commit 7ed023f15d
4 changed files with 87 additions and 4 deletions

12
bin/sic-1.1/Makefile.mk Normal file
View File

@ -0,0 +1,12 @@
DEFINES += -DVERSION=1.1 #-D__STACK_CHECK__=1
CFLAGS += $(DEFINES) -v -w
LDFLAGS += -l/usr/lib/libnetdb
OBJS = sic.o
sic: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
sic.o: sic.c util.c

View File

@ -1,4 +1,4 @@
.TH SIC 1 sic-VERSION
.TH SIC 1 sic-1.1
.SH NAME
sic \- simple irc client
.SH SYNOPSIS

View File

@ -6,8 +6,18 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef __GNO__
#include <gno/gno.h>
#endif
#ifdef __ORCAC__
#pragma optimize 79
#pragma stacksize 2048 // 1063 bytes ... better safe than sorry.
#endif
static char *host = "irc.oftc.net";
static char *port = "ircd";
static char *password;
@ -30,8 +40,13 @@ pout(char *channel, char *fmt, ...) {
vsnprintf(bufout, sizeof bufout, fmt, ap);
va_end(ap);
t = time(NULL);
#ifdef __GNO__
fprintf(stdout, "%-12s: %s\n", channel, bufout);
#else
strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
#endif
}
static void
@ -138,6 +153,10 @@ main(int argc, char *argv[]) {
const char *user = getenv("USER");
fd_set rd;
#ifdef __GNO__
__REPORT_STACK();
#endif
strlcpy(nick, user ? user : "unknown", sizeof nick);
for(i = 1; i < argc; i++) {
c = argv[i][1];
@ -157,14 +176,18 @@ main(int argc, char *argv[]) {
if(++i < argc) password = argv[i];
break;
case 'v':
eprint("sic-"VERSION", © 2005-2009 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
eprint("sic-1.1, (c) 2005-2009 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
default:
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
}
}
/* init */
i = dial(host, port);
#ifdef __GNO__
srv = fdopen(i, "rb+");
#else
srv = fdopen(i, "r+");
#endif
/* login */
if(password)
sout("PASS %s", password);
@ -175,7 +198,7 @@ main(int argc, char *argv[]) {
setbuf(srv, NULL);
for(;;) { /* main loop */
FD_ZERO(&rd);
FD_SET(0, &rd);
FD_SET(STDIN_FILENO, &rd);
FD_SET(fileno(srv), &rd);
tv.tv_sec = 120;
tv.tv_usec = 0;
@ -183,6 +206,7 @@ main(int argc, char *argv[]) {
if(i < 0) {
if(errno == EINTR)
continue;
perror(NULL);
eprint("sic: error on select():");
}
else if(i == 0) {
@ -197,11 +221,12 @@ main(int argc, char *argv[]) {
parsesrv(bufin);
trespond = time(NULL);
}
if(FD_ISSET(0, &rd)) {
if(FD_ISSET(STDIN_FILENO, &rd)) {
if(fgets(bufin, sizeof bufin, stdin) == NULL)
eprint("sic: broken pipe\n");
parsein(bufin);
}
}
return 0;
}

View File

@ -2,6 +2,26 @@
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#ifndef __GNO__
#include <machine/endian.h>
#endif
// from freebsd 9.0.0
void *
memccpy(void *t, const void *f, int c, size_t n)
{
if (n) {
unsigned char *tp = t;
const unsigned char *fp = f;
unsigned char uc = c;
do {
if ((*tp++ = *fp++) == uc)
return (tp);
} while (--n != 0);
}
return (0);
}
static void
eprint(const char *fmt, ...) {
@ -18,6 +38,31 @@ eprint(const char *fmt, ...) {
static int
dial(char *host, char *port) {
#ifdef __GNO__
int srv;
struct hostent *hp;
struct sockaddr_in sin;
hp = gethostbyname(host);
if (hp == NULL)
eprint("error: cannot resolve hostname '%s':", host);
srv = socket(hp->h_addrtype, SOCK_STREAM, 0);
if (srv < 0)
eprint("error: socket");
bzero((caddr_t)&sin, sizeof (sin));
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
sin.sin_port = htons(atoi(port));
if (connect(srv, (struct __SOCKADDR *)&sin, sizeof(sin)) < 0)
eprint("error: cannot connect to host '%s'\n", host);
return srv;
#else
static struct addrinfo hints;
int srv;
struct addrinfo *res, *r;
@ -38,6 +83,7 @@ dial(char *host, char *port) {
if(!r)
eprint("error: cannot connect to host '%s'\n", host);
return srv;
#endif
}
#define strlcpy _strlcpy