19 Commits
0.2 ... 0.4

7 changed files with 134 additions and 201 deletions

View File

@ -1 +1,3 @@
de32c537aaf66554894712563ffba8d9bc4c2714 0.1
56350a01f27753cfbdbb3dbc25f2a53dd4c2ac45 0.2
d77f00af559258679a0fad5d264685d663e6975a 0.3

View File

@ -1,59 +1,57 @@
# ii - irc it - simple but flexible IRC client
# (C)opyright MMV Anselm R. Garbe, Nico Golde
# sic - simple irc client
# (C)opyright MMVI Anselm R. Garbe
include config.mk
SRC = sic.c
OBJ = ${SRC:.c=.o}
MAN1 = sic.1
BIN = sic
all: options sic
@echo built sic
options:
@echo ii build options:
@echo "LIBS = ${LIBS}"
@echo sic build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
@echo "LD = ${LD}"
.c.o:
@echo CC $<
@${CC} -c ${CFLAGS} $<
${OBJ}: config.mk
sic: ${OBJ}
@echo LD $@
@${LD} -o $@ ${OBJ} ${LDFLAGS}
@strip $@
clean:
rm -f sic *.o core sic-${VERSION}.tar.gz
@echo cleaning
@rm -f sic ${OBJ} sic-${VERSION}.tar.gz
dist: clean
@echo creating dist tarball
@mkdir -p sic-${VERSION}
@cp -R Makefile README LICENSE config.mk sic.c sic.1 sic-${VERSION}
@cp -R LICENSE Makefile README config.mk sic.1 ${SRC} sic-${VERSION}
@tar -cf sic-${VERSION}.tar sic-${VERSION}
@gzip sic-${VERSION}.tar
@rm -rf sic-${VERSION}
sic: ${OBJ}
@echo LD $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
install: all
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
@for i in ${BIN}; do \
chmod 755 ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
done
@echo installed executable files to ${DESTDIR}${PREFIX}/bin
@cp -f sic ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1
@for i in ${MAN1}; do \
chmod 444 ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
done
@echo installed manual pages to ${DESTDIR}${MANPREFIX}/man1
@sed 's/VERSION/${VERSION}/g' < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
uninstall:
for i in ${BIN}; do \
rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
done
for i in ${MAN1}; do \
rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
done
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
@rm -f ${DESTDIR}${PREFIX}/bin/sic
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
@rm -f ${DESTDIR}${MANPREFIX}/man1/sic.1
.PHONY: all options clean dist install uninstall

10
README
View File

@ -1,11 +1,11 @@
sic - simple irc client
-----------------------
=======================
sic is an extremly fast, small and simple irc client. It reads commands from
standard input and prints all server output to standard output. It multiplexes
also all channel traffic into one output, that you don't have to switch
different channel buffers, that's actually a feature.
Installation
------------
Edit config.mk to match your local setup. sic is installed into
@ -16,11 +16,7 @@ Afterwards enter the following command to build and install sic
$ make clean install
Running sic
-----------
Simply invoke the 'sic' command with the required arguments.
Configuration
-------------
No configuration is needed.

View File

@ -1,18 +1,22 @@
# Customize to fit your system
# sic version
VERSION = 0.4
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
VERSION = 0.2
# includes and libs
LIBS = -L${PREFIX}/lib -L/usr/lib -lc
INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc
# compiler
CFLAGS = -O3 -I${PREFIX}/include -I/usr/include \
-DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 -I${PREFIX}/include -I/usr/include \
# -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
# compiler and linker
CC = cc
LD = ${CC}

38
sic.1
View File

@ -1,19 +1,13 @@
.TH SIC 1 sic-0.2
.TH SIC 1 sic-VERSION
.SH NAME
sic \- simple irc client
.SH SYNOPSIS
.B sic
.RB [ \-s
.IR server ]
.RB [ \-p
.IR port ]
.RB [ \-n
.IR nick ]
.RB [ \-k
.IR keyword ]
.RB [ \-f
.IR fullname ]
.RB \-v
.RB [ \-s " <server>"]
.RB [ \-p " <port>"]
.RB [ \-n " <nick>"]
.RB [ \-k " <keyword>"]
.RB [ \-f " <fullname>"]
.RB [ \-v ]
.SH DESCRIPTION
.B sic
@ -23,38 +17,38 @@ also all channel traffic into one output, that you don't have to switch
different channel buffers, that's actually a feature.
.SH OPTIONS
.TP
.BI \-s " server"
.B \-s <server>
Overrides the default server (irc.oftc.net)
.TP
.BI \-p " port"
.B \-p <port>
Overrides the default port (6667)
.TP
.BI \-n " nickname"
.B \-n <nickname>
Override the default nick ($USER)
.TP
.BI \-k " keyword"
.B \-k <keyword>
Specifies the keyword to authenticate your nick on the server
.TP
.BI \-f " fullname"
.B \-f <fullname>
Specify the real name (default is $USER)
.TP
.BI \-v
Prints version information to standard output, then exits.
.SH COMMANDS
.TP
.BI /j " #channel "
.B /j #channel
Join a channel
.TP
.BI /l " #channel "
.B /l #channel
Leave a channel
.TP
.BI /m " #channel/user msg "
.B /m #channel/user msg
Write a message to #channel/user
.TP
.BI /s " #channel/user "
.B /s #channel/user
Set default channel/user
.TP
.BI /t " topic"
.B /t topic
Set the channel topic
.TP
Everything which is not a command will simply be posted into the channel or to

164
sic.c
View File

@ -1,9 +1,7 @@
/*
* (C)opyright MMV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
/* (C)opyright MMV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* (C)opyright MMV-MMVI Nico Golde <nico at ngolde dot de>
* See LICENSE file for license details.
*/
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
@ -11,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/time.h>
@ -20,7 +19,7 @@
enum { Tnick, Tuser, Tcmd, Tchan, Targ, Ttext, Tlast };
static char *server = "irc.oftc.net";
static int port = 6667;
static unsigned short port = 6667;
static char *nick = NULL;
static char *fullname = NULL;
static char *password = NULL;
@ -31,10 +30,10 @@ static int srv;
static time_t trespond;
static int
getline(int fd, unsigned int len, char *buf)
{
getline(int fd, unsigned int len, char *buf) {
unsigned int i = 0;
char c;
do {
if(read(fd, &c, sizeof(char)) != sizeof(char))
return -1;
@ -46,8 +45,7 @@ getline(int fd, unsigned int len, char *buf)
}
static void
pout(char *channel, char *msg)
{
pout(char *channel, char *msg) {
static char timestr[18];
time_t t = time(0);
@ -56,8 +54,7 @@ pout(char *channel, char *msg)
}
static void
privmsg(char *channel, char *msg)
{
privmsg(char *channel, char *msg) {
snprintf(bufout, sizeof(bufout), "<%s> %s", nick, msg);
pout(channel, bufout);
snprintf(bufout, sizeof(bufout), "PRIVMSG %s :%s\r\n", channel, msg);
@ -65,8 +62,7 @@ privmsg(char *channel, char *msg)
}
static void
parsein(char *msg)
{
parsein(char *msg) {
char *p;
if(msg[0] == 0)
@ -75,42 +71,32 @@ parsein(char *msg)
privmsg(channel, msg);
return;
}
if((p = strchr(&msg[3], ' ')))
*(p++) = 0;
switch (msg[1]) {
default:
snprintf(bufout, sizeof(bufout), "%s\r\n", &msg[1]);
break;
case 'j':
if(msg[3] == '#')
snprintf(bufout, sizeof(bufout), "JOIN %s\r\n", &msg[3]);
else if(p) {
privmsg(&msg[3], p + 1);
return;
}
break;
case 'l':
if(p)
snprintf(bufout, sizeof(bufout), "PART %s :%s\r\n", &msg[3], p);
else
snprintf(bufout, sizeof(bufout), "PART %s :sic\r\n", &msg[3]);
break;
case 'm':
if(!strncmp(msg + 1, "j ", 2) && (msg[3] == '#'))
snprintf(bufout, sizeof(bufout), "JOIN %s\r\n", &msg[3]);
else if(!strncmp(msg + 1, "l ", 2))
snprintf(bufout, sizeof(bufout), "PART %s :sic\r\n", &msg[3]);
else if(!strncmp(msg + 1, "m ", 2)) {
if((p = strchr(&msg[3], ' ')))
*(p++) = 0;
privmsg(&msg[3], p);
return;
case 's':
}
else if(!strncmp(msg + 1, "s ", 2)) {
strncpy(channel, &msg[3], sizeof(channel));
return;
case 't':
snprintf(bufout, sizeof(bufout), "TOPIC %s :%s\r\n", &msg[3], p);
break;
}
else if(!strncmp(msg + 1, "t ", 2)) {
if((p = strchr(&msg[3], ' ')))
*(p++) = 0;
snprintf(bufout, sizeof(bufout), "TOPIC %s :%s\r\n", &msg[3], p);
}
else
snprintf(bufout, sizeof(bufout), "%s\r\n", &msg[1]);
write(srv, bufout, strlen(bufout));
}
static unsigned int
tokenize(char **result, unsigned int reslen, char *str, char delim)
{
tokenize(char **result, unsigned int reslen, char *str, char delim) {
char *p, *n;
unsigned int i = 0;
@ -135,26 +121,25 @@ tokenize(char **result, unsigned int reslen, char *str, char delim)
}
static void
parsesrv(char *msg)
{
parsesrv(char *msg) {
char *argv[Tlast], *cmd, *p;
int i;
if(!msg || !(*msg))
return;
for(i = 0; i < Tlast; i++)
argv[i] = NULL;
/*
<bufout> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
<prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <server> ]
<command> ::= <letter> { <letter> } | <number> <number> <number>
<SPACE> ::= ' ' { ' ' }
<params> ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
<middle> ::= <Any *non-empty* sequence of octets not including SPACE
or NUL or CR or LF, the first of which may not be ':'>
<trailing> ::= <Any, possibly *empty*, sequence of octets not including NUL or CR or LF>
<crlf> ::= CR LF
/* <bufout> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
* <prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <server> ]
* <command> ::= <letter> { <letter> } | <number> <number> <number>
* <SPACE> ::= ' ' { ' ' }
* <params> ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
* <middle> ::= <Any *non-empty* sequence of octets not including SPACE
* or NUL or CR or LF, the first of which may not be ':'>
* <trailing> ::= <Any, possibly *empty*, sequence of octets not including NUL or CR or LF>
* <crlf> ::= CR LF
*/
if(msg[0] == ':') { /* check prefix */
p = strchr(msg, ' ');
@ -168,29 +153,28 @@ parsesrv(char *msg)
}
} else
cmd = msg;
/* remove CRLFs */
for(p = cmd; p && *p != 0; p++)
if(*p == '\r' || *p == '\n')
*p = 0;
if((p = strchr(cmd, ':'))) {
*p = 0;
argv[Ttext] = ++p;
}
tokenize(&argv[Tcmd], Tlast - Tcmd, cmd, ' ');
if(!strncmp("PONG", argv[Tcmd], 5)) {
if(!strncmp("PONG", argv[Tcmd], 5))
return;
} else if(!strncmp("PING", argv[Tcmd], 5)) {
else if(!strncmp("PING", argv[Tcmd], 5)) {
snprintf(bufout, sizeof(bufout), "PONG %s\r\n", argv[Ttext]);
write(srv, bufout, strlen(bufout));
return;
} else if(!argv[Tnick] || !argv[Tuser]) { /* server command */
}
else if(!argv[Tnick] || !argv[Tuser]) { /* server command */
snprintf(bufout, sizeof(bufout), "%s", argv[Ttext] ? argv[Ttext] : "");
pout(server, bufout);
return;
} else if(!strncmp("ERROR", argv[Tcmd], 6))
}
else if(!strncmp("ERROR", argv[Tcmd], 6))
snprintf(bufout, sizeof(bufout), "-!- error %s",
argv[Ttext] ? argv[Ttext] : "unknown");
else if(!strncmp("JOIN", argv[Tcmd], 5)) {
@ -202,10 +186,12 @@ parsesrv(char *msg)
argv[Tchan] = argv[Ttext];
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has joined %s",
argv[Tnick], argv[Tuser], argv[Ttext]);
} else if(!strncmp("PART", argv[Tcmd], 5)) {
}
else if(!strncmp("PART", argv[Tcmd], 5)) {
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has left %s",
argv[Tnick], argv[Tuser], argv[Tchan]);
} else if(!strncmp("MODE", argv[Tcmd], 5))
}
else if(!strncmp("MODE", argv[Tcmd], 5))
snprintf(bufout, sizeof(bufout), "-!- %s changed mode/%s -> %s %s",
argv[Tnick], argv[Tcmd + 1],
argv[Tcmd + 2], argv[Tcmd + 3]);
@ -236,60 +222,53 @@ parsesrv(char *msg)
}
int
main(int argc, char *argv[])
{
main(int argc, char *argv[]) {
int i;
struct timeval tv;
struct hostent *hp;
struct sockaddr_in addr = { 0 };
static struct sockaddr_in addr; /* initially filled with 0's */
char ping[256];
fd_set rd;
nick = fullname = getenv("USER");
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
switch (argv[i][1]) {
default:
for(i = 1; i < argc; i++)
if(!strncmp(argv[i], "-s", 3))
server = argv[++i];
else if(!strncmp(argv[i], "-p", 3))
port = (unsigned short)atoi(argv[++i]);
else if(!strncmp(argv[i], "-n", 3))
nick = argv[++i];
else if(!strncmp(argv[i], "-k", 3))
password = argv[++i];
else if(!strncmp(argv[i], "-f", 3))
fullname = argv[++i];
else if(!strncmp(argv[i], "-v", 3)) {
fputs("sic-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
exit(EXIT_SUCCESS);
}
else {
fputs("usage: sic [-s server] [-p port] [-n nick]"
" [-k keyword] [-f fullname] [-v]\n", stderr);
exit(EXIT_FAILURE);
break;
case 's':
server = argv[++i];
break;
case 'p':
port = atoi(argv[++i]);
break;
case 'n':
nick = argv[++i];
break;
case 'k':
password = argv[++i];
break;
case 'f':
fullname = argv[++i];
break;
case 'v':
fputs("sic-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
exit(EXIT_SUCCESS);
break;
}
}
/* init */
if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
exit(EXIT_FAILURE);
}
hp = gethostbyname(server);
if (NULL == (hp = gethostbyname(server))) {
fprintf(stderr, "sic: cannot resolve hostname '%s'\n", server);
exit(EXIT_FAILURE);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
close(srv);
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
exit(EXIT_FAILURE);
}
/* login */
if(password)
snprintf(bufout, sizeof(bufout),
@ -299,11 +278,11 @@ main(int argc, char *argv[])
snprintf(bufout, sizeof(bufout), "NICK %s\r\nUSER %s localhost %s :%s\r\n",
nick, nick, server, fullname);
write(srv, bufout, strlen(bufout));
snprintf(ping, sizeof(ping), "PING %s\r\n", server);
channel[0] = 0;
setbuf(stdout, NULL); /* unbuffered stdout */
for(;;) {
for(;;) { /* main loop */
FD_ZERO(&rd);
FD_SET(0, &rd);
FD_SET(srv, &rd);
@ -339,6 +318,5 @@ main(int argc, char *argv[])
parsein(bufin);
}
}
return 0;
}

View File

@ -1,39 +0,0 @@
<html>
<head>
<title>sic - simple irc client</title>
<meta name="author" content="Anselm R. Garbe">
<meta name="generator" content="ed">
<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
<style type="text/css">
body {
color: #000000;
font-family: sans-serif;
margin: 20px 20px 20px 20px;
}
</style>
</head>
<body>
<center>
<h3>simple irc client</h3>
</center>
<h3>Description</h3>
<p>
sic is an extremly simple IRC client. It consists of lesser than 400 lines of code.
</p>
<ul>
<li><a href="http://10kloc.org/cgi-bin/man/man2html?query=sic">Man page</a></li>
</ul>
<h3>Download</h3>
<ul>
<li><a href="http://10kloc.org/download/sic-0.2.tar.gz">sic 0.2</a> (5kb) (20060721)</li>
</ul>
<h3>Development</h3>
<p>
You can <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/sic">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
</p>
<p>
<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/sic</code>
</p>
<p><small>--Anselm (20060719)</small></p>
</body>
</html>