Compare commits
No commits in common. "master" and "0.1" have entirely different histories.
@ -1,21 +0,0 @@
|
|||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[{*.c,*.h}]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
indent_style = tab
|
|
||||||
|
|
||||||
[Makefile]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
7
LICENSE
7
LICENSE
@ -1,10 +1,7 @@
|
|||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
© 2022 Alexander Popov <iiiypuk@fastmail.fm>
|
(C)opyright MMV-MMVI Anselm R. Garbe <garbeam@gmail.com>
|
||||||
© 2005-2017 Anselm R Garbe <anselm@garbe.us>
|
(C)opyright MMV Nico Golde <nico at ngolde dot de>
|
||||||
© 2008-2009 Jeroen Schot <schot@a-eskwadraat.nl>
|
|
||||||
© 2007-2009 Kris Maglione <maglione.k@gmail.com>
|
|
||||||
© 2005 Nico Golde <nico at ngolde dot de>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
90
Makefile
90
Makefile
@ -1,59 +1,59 @@
|
|||||||
.POSIX:
|
# ii - irc it - simple but flexible IRC client
|
||||||
|
# (C)opyright MMV Anselm R. Garbe, Nico Golde
|
||||||
|
|
||||||
NAME = sic
|
include config.mk
|
||||||
VERSION = 1.3
|
|
||||||
|
|
||||||
# paths
|
SRC = sic.c
|
||||||
PREFIX = /usr/local
|
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
|
||||||
|
|
||||||
# use system flags.
|
|
||||||
SIC_CFLAGS = ${CFLAGS}
|
|
||||||
SIC_LDFLAGS = ${LDFLAGS}
|
|
||||||
SIC_CPPFLAGS = ${LDFLAGS} -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
|
||||||
|
|
||||||
BIN = sic
|
|
||||||
SRC = ${BIN:=.c}
|
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
MAN1 = ${BIN:=.1}
|
MAN1 = sic.1
|
||||||
|
BIN = sic
|
||||||
|
|
||||||
all: ${BIN}
|
all: options sic
|
||||||
|
@echo built sic
|
||||||
|
|
||||||
${BIN}: ${@:=.o}
|
options:
|
||||||
|
@echo ii build options:
|
||||||
${OBJ}: config.h strlcpy.c util.c
|
@echo "LIBS = ${LIBS}"
|
||||||
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
.o:
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
${CC} -o $@ $< ${SIC_LDFLAGS}
|
@echo "CC = ${CC}"
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${CC} -c ${SIC_CFLAGS} ${SIC_CPPFLAGS} -o $@ -c $<
|
@echo CC $<
|
||||||
|
@${CC} -c ${CFLAGS} $<
|
||||||
config.h:
|
|
||||||
cp config.def.h $@
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ${BIN} ${OBJ} "${NAME}-${VERSION}.tar.gz"
|
rm -f sic *.o core sic-${VERSION}.tar.gz
|
||||||
|
|
||||||
dist:
|
dist: clean
|
||||||
mkdir -p "${NAME}-${VERSION}"
|
@mkdir -p sic-${VERSION}
|
||||||
cp -fR LICENSE Makefile README arg.h config.def.h \
|
@cp -R Makefile README LICENSE config.mk sic.c sic.1 sic-${VERSION}
|
||||||
${MAN1} ${SRC} util.c strlcpy.c "${NAME}-${VERSION}"
|
@tar -cf sic-${VERSION}.tar sic-${VERSION}
|
||||||
tar -cf - "${NAME}-${VERSION}" | \
|
@gzip sic-${VERSION}.tar
|
||||||
gzip -c > "${NAME}-${VERSION}.tar.gz"
|
@rm -rf sic-${VERSION}
|
||||||
rm -rf "${NAME}-${VERSION}"
|
|
||||||
|
sic: ${OBJ}
|
||||||
|
@echo LD $@
|
||||||
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
cp -f ${BIN} "${DESTDIR}${PREFIX}/bin"
|
@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
|
||||||
chmod 755 "${DESTDIR}${PREFIX}/bin/${BIN}"
|
@for i in ${BIN}; do \
|
||||||
mkdir -p "${DESTDIR}${MANPREFIX}/man1"
|
chmod 755 ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
|
||||||
sed "s/VERSION/${VERSION}/g" < ${MAN1} > "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
done
|
||||||
chmod 644 "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
@echo installed executable files to ${DESTDIR}${PREFIX}/bin
|
||||||
|
@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
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f \
|
for i in ${BIN}; do \
|
||||||
"${DESTDIR}${PREFIX}/bin/${BIN}"\
|
rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
|
||||||
"${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
done
|
||||||
|
for i in ${MAN1}; do \
|
||||||
.PHONY: all clean dist install uninstall
|
rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
|
||||||
|
done
|
||||||
|
26
README
Normal file
26
README
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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
|
||||||
|
/usr/local by default.
|
||||||
|
|
||||||
|
Afterwards enter the following command to build and install sic
|
||||||
|
(if necessary as root):
|
||||||
|
|
||||||
|
$ make clean install
|
||||||
|
|
||||||
|
Running sic
|
||||||
|
-----------
|
||||||
|
Simply invoke the 'sic' command with the required arguments.
|
||||||
|
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
No configuration is needed.
|
23
README.md
23
README.md
@ -1,23 +0,0 @@
|
|||||||
sic - simple irc client
|
|
||||||
=======================
|
|
||||||
sic is an extremely 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 so that you don't have to switch
|
|
||||||
different channel buffers: that's actually a feature.
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
Edit the Makefile or override the flags to match your local setup. sic is
|
|
||||||
installed into /usr/local by default.
|
|
||||||
|
|
||||||
Afterwards enter the following command to build and install sic
|
|
||||||
(if necessary as root):
|
|
||||||
|
|
||||||
$ make
|
|
||||||
# make install
|
|
||||||
|
|
||||||
|
|
||||||
Running sic
|
|
||||||
-----------
|
|
||||||
Simply invoke the `sic` command with the required arguments.
|
|
63
arg.h
63
arg.h
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
14
config.def.h
14
config.def.h
@ -1,14 +0,0 @@
|
|||||||
/* Host used when "-h" is not given */
|
|
||||||
#define DEFAULT_HOST "iiiypuk.me"
|
|
||||||
|
|
||||||
/* Port used when "-p" is not given */
|
|
||||||
#define DEFAULT_PORT "6667"
|
|
||||||
|
|
||||||
/* Timestamp format; see strftime(3). */
|
|
||||||
#define TIMESTAMP_FORMAT "%Y-%m-%d %R"
|
|
||||||
|
|
||||||
/* Command prefix character. In most IRC clients this is '/'. */
|
|
||||||
#define COMMAND_PREFIX_CHARACTER ':'
|
|
||||||
|
|
||||||
/* Parting message used when none is specified with ":l ..." command. */
|
|
||||||
#define DEFAULT_PARTING_MESSAGE "sic - 250 LOC are too much!"
|
|
18
config.mk
Normal file
18
config.mk
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Customize to fit your system
|
||||||
|
|
||||||
|
# paths
|
||||||
|
PREFIX = /usr/local
|
||||||
|
MANPREFIX = ${PREFIX}/share/man
|
||||||
|
|
||||||
|
VERSION = 0.1
|
||||||
|
|
||||||
|
# includes and libs
|
||||||
|
LIBS = -L${PREFIX}/lib -L/usr/lib -lc
|
||||||
|
|
||||||
|
# compiler
|
||||||
|
CFLAGS = -Os -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}
|
57
sic.1
57
sic.1
@ -1,54 +1,61 @@
|
|||||||
.TH SIC 1 sic-VERSION
|
.TH SIC 1 sic-0.1
|
||||||
.SH NAME
|
.SH NAME
|
||||||
sic \- simple irc client
|
sic \- simple irc client
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B sic
|
.B sic
|
||||||
.RB [ \-h
|
.RB [ \-s
|
||||||
.IR host ]
|
.IR server ]
|
||||||
.RB [ \-p
|
.RB [ \-p
|
||||||
.IR port ]
|
.IR port ]
|
||||||
.RB [ \-n
|
.RB [ \-n
|
||||||
.IR nick ]
|
.IR nick ]
|
||||||
.RB [ \-k
|
.RB [ \-k
|
||||||
.IR pass ]
|
.IR keyword ]
|
||||||
|
.RB [ \-f
|
||||||
|
.IR fullname ]
|
||||||
|
.RB \-v
|
||||||
.RB [ \-v ]
|
.RB [ \-v ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B sic
|
.B sic
|
||||||
is an extremely fast, small and simple irc client. It reads commands from
|
is an extremly fast, small and simple irc client. It reads commands from
|
||||||
standard input and prints all server output to standard output. It also
|
standard input and prints all server output to standard output. It multiplexes
|
||||||
multiplexes all channel traffic into one output. That way you don't have to
|
also all channel traffic into one output, that you don't have to switch
|
||||||
switch different channel buffers. So that's actually a feature.
|
different channel buffers, that's actually a feature.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.BI \-h " host"
|
.BI \-s " server"
|
||||||
Overrides the default host (irc.oftc.net)
|
Overrides the default server (irc.oftc.net)
|
||||||
.TP
|
.TP
|
||||||
.BI \-p " port"
|
.BI \-p " port"
|
||||||
Overrides the default port (6667)
|
Overrides the default port (6667)
|
||||||
.TP
|
.TP
|
||||||
.BI \-n " nick"
|
.BI \-n " nickname"
|
||||||
Override the default nick ($USER)
|
Override the default nick ($USER)
|
||||||
.TP
|
.TP
|
||||||
.BI \-k " pass"
|
.BI \-k " keyword"
|
||||||
Specifies the PASS connection password
|
Specifies the keyword to authenticate your nick on the server
|
||||||
.TP
|
.TP
|
||||||
.B \-v
|
.BI \-f " fullname"
|
||||||
Prints version information to stderr, then exits
|
Specify the real name (default is $USER)
|
||||||
|
.TP
|
||||||
|
.BI \-v
|
||||||
|
Prints version information to standard output, then exits.
|
||||||
.SH COMMANDS
|
.SH COMMANDS
|
||||||
.TP
|
.TP
|
||||||
.BI :j " #channel"
|
.BI /j " #channel "
|
||||||
Join a channel
|
Join a channel
|
||||||
.TP
|
.TP
|
||||||
.BI :l " #channel"
|
.BI /l " #channel "
|
||||||
Leave a channel
|
Leave a channel
|
||||||
.TP
|
.TP
|
||||||
.BI :m " #channel/user message"
|
.BI /m " #channel/user msg "
|
||||||
Send a message to channel or user
|
Write a message to #channel/user
|
||||||
.TP
|
.TP
|
||||||
.BI :s " #channel/user"
|
.BI /s " #channel/user "
|
||||||
Set default channel or user
|
Set default channel/user
|
||||||
.TP
|
.TP
|
||||||
.BI : command
|
.BI /t " topic"
|
||||||
Any line beginning with
|
Set the channel topic
|
||||||
.B :
|
.TP
|
||||||
is sent as a command
|
Everything which is not a command will simply be posted into the channel or to
|
||||||
|
the server.
|
||||||
|
420
sic.c
420
sic.c
@ -1,224 +1,340 @@
|
|||||||
/* See LICENSE file for license details. */
|
/*
|
||||||
#include <sys/select.h>
|
* (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 <ctype.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "arg.h"
|
#define PINGTIMEOUT 300
|
||||||
#include "config.h"
|
#define MAXMSG 4096
|
||||||
|
|
||||||
char *argv0;
|
enum { Tnick, Tuser, Tcmd, Tchan, Targ, Ttext, Tlast };
|
||||||
static char *host = DEFAULT_HOST;
|
|
||||||
static char *port = DEFAULT_PORT;
|
static char *server = "irc.oftc.net";
|
||||||
static char *password;
|
static int port = 6667;
|
||||||
static char nick[32];
|
static char *nick = NULL;
|
||||||
static char bufin[4096];
|
static char *fullname = NULL;
|
||||||
static char bufout[4096];
|
static char *password = NULL;
|
||||||
|
|
||||||
|
static char bufin[MAXMSG], bufout[MAXMSG];
|
||||||
static char channel[256];
|
static char channel[256];
|
||||||
|
static int srv;
|
||||||
static time_t trespond;
|
static time_t trespond;
|
||||||
static FILE *srv;
|
|
||||||
|
|
||||||
#undef strlcpy
|
static int
|
||||||
#include "strlcpy.c"
|
getline(int fd, unsigned int len, char *buf)
|
||||||
#include "util.c"
|
{
|
||||||
|
unsigned int i = 0;
|
||||||
static void
|
char c;
|
||||||
pout(char *channel, char *fmt, ...) {
|
do {
|
||||||
static char timestr[80];
|
if(read(fd, &c, sizeof(char)) != sizeof(char))
|
||||||
time_t t;
|
return -1;
|
||||||
va_list ap;
|
buf[i++] = c;
|
||||||
|
}
|
||||||
va_start(ap, fmt);
|
while(c != '\n' && i < len);
|
||||||
vsnprintf(bufout, sizeof bufout, fmt, ap);
|
buf[i - 1] = 0;
|
||||||
va_end(ap);
|
return 0;
|
||||||
t = time(NULL);
|
|
||||||
strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t));
|
|
||||||
fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sout(char *fmt, ...) {
|
pout(char *channel, char *msg)
|
||||||
va_list ap;
|
{
|
||||||
|
static char timestr[18];
|
||||||
|
time_t t = time(0);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
strftime(timestr, sizeof(timestr), "%a %R", localtime(&t));
|
||||||
vsnprintf(bufout, sizeof bufout, fmt, ap);
|
fprintf(stdout, "%s: %s %s\n", channel, timestr, msg);
|
||||||
va_end(ap);
|
|
||||||
fprintf(srv, "%s\r\n", bufout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
privmsg(char *channel, char *msg) {
|
privmsg(char *channel, char *msg)
|
||||||
if(channel[0] == '\0') {
|
{
|
||||||
pout("", "No channel to send to");
|
snprintf(bufout, sizeof(bufout), "<%s> %s", nick, msg);
|
||||||
|
pout(channel, bufout);
|
||||||
|
snprintf(bufout, sizeof(bufout), "PRIVMSG %s :%s\r\n", channel, msg);
|
||||||
|
write(srv, bufout, strlen(bufout));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
parsein(char *msg)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if(msg[0] != '/') {
|
||||||
|
privmsg(channel, msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pout(channel, "<%s> %s", nick, msg);
|
if((p = strchr(&msg[3], ' ')))
|
||||||
sout("PRIVMSG %s :%s", channel, msg);
|
*(p++) = 0;
|
||||||
}
|
switch (msg[1]) {
|
||||||
|
default:
|
||||||
static void
|
snprintf(bufout, sizeof(bufout), "%s\r\n", &msg[1]);
|
||||||
parsein(char *s) {
|
break;
|
||||||
char c, *p;
|
|
||||||
|
|
||||||
if(s[0] == '\0')
|
|
||||||
return;
|
|
||||||
skip(s, '\n');
|
|
||||||
if(s[0] != COMMAND_PREFIX_CHARACTER) {
|
|
||||||
privmsg(channel, s);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
c = *++s;
|
|
||||||
if(c != '\0' && isspace((unsigned char)s[1])) {
|
|
||||||
p = s + 2;
|
|
||||||
switch(c) {
|
|
||||||
case 'j':
|
case 'j':
|
||||||
sout("JOIN %s", p);
|
if(msg[3] == '#')
|
||||||
if(channel[0] == '\0')
|
snprintf(bufout, sizeof(bufout), "JOIN %s\r\n", &msg[3]);
|
||||||
strlcpy(channel, p, sizeof channel);
|
else if(p) {
|
||||||
|
privmsg(&msg[3], p + 1);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
s = eat(p, isspace, 1);
|
if(p)
|
||||||
p = eat(s, isspace, 0);
|
snprintf(bufout, sizeof(bufout), "PART %s :%s\r\n", &msg[3], p);
|
||||||
if(!*s)
|
else
|
||||||
s = channel;
|
snprintf(bufout, sizeof(bufout), "PART %s :sic\r\n", &msg[3]);
|
||||||
if(*p)
|
break;
|
||||||
*p++ = '\0';
|
|
||||||
if(!*p)
|
|
||||||
p = DEFAULT_PARTING_MESSAGE;
|
|
||||||
sout("PART %s :%s", s, p);
|
|
||||||
return;
|
|
||||||
case 'm':
|
case 'm':
|
||||||
s = eat(p, isspace, 1);
|
privmsg(&msg[3], p);
|
||||||
p = eat(s, isspace, 0);
|
|
||||||
if(*p)
|
|
||||||
*p++ = '\0';
|
|
||||||
privmsg(s, p);
|
|
||||||
return;
|
return;
|
||||||
case 's':
|
case 's':
|
||||||
strlcpy(channel, p, sizeof channel);
|
strncpy(channel, &msg[3], sizeof(channel));
|
||||||
return;
|
return;
|
||||||
|
case 't':
|
||||||
|
snprintf(bufout, sizeof(bufout), "TOPIC %s :%s\r\n", &msg[3], p);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
write(srv, bufout, strlen(bufout));
|
||||||
}
|
}
|
||||||
sout("%s", s);
|
|
||||||
|
static unsigned int
|
||||||
|
tokenize(char **result, unsigned int reslen, char *str, char delim)
|
||||||
|
{
|
||||||
|
char *p, *n;
|
||||||
|
unsigned int i = 0;
|
||||||
|
|
||||||
|
if(!str)
|
||||||
|
return 0;
|
||||||
|
for(n = str; *n == delim; n++);
|
||||||
|
p = n;
|
||||||
|
for(i = 0; *n != 0;) {
|
||||||
|
if(i == reslen)
|
||||||
|
return i;
|
||||||
|
if(*n == delim) {
|
||||||
|
*n = 0;
|
||||||
|
if(strlen(p))
|
||||||
|
result[i++] = p;
|
||||||
|
p = ++n;
|
||||||
|
} else
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if((i < reslen) && (p < n) && strlen(p))
|
||||||
|
result[i++] = p;
|
||||||
|
return i; /* number of tokens */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parsesrv(char *cmd) {
|
parsesrv(char *msg)
|
||||||
char *usr, *par, *txt;
|
{
|
||||||
|
char *argv[Tlast], *cmd, *p;
|
||||||
usr = host;
|
int i;
|
||||||
if(!cmd || !*cmd)
|
if(!msg || !(*msg))
|
||||||
return;
|
return;
|
||||||
if(cmd[0] == ':') {
|
|
||||||
usr = cmd + 1;
|
|
||||||
cmd = skip(usr, ' ');
|
|
||||||
if(cmd[0] == '\0')
|
|
||||||
return;
|
|
||||||
skip(usr, '!');
|
|
||||||
}
|
|
||||||
skip(cmd, '\r');
|
|
||||||
par = skip(cmd, ' ');
|
|
||||||
txt = skip(par, ':');
|
|
||||||
trim(par);
|
|
||||||
if(!strcmp("PONG", cmd))
|
|
||||||
return;
|
|
||||||
if(!strcmp("PRIVMSG", cmd))
|
|
||||||
pout(par, "<%s> %s", usr, txt);
|
|
||||||
else if(!strcmp("PING", cmd))
|
|
||||||
sout("PONG %s", txt);
|
|
||||||
else {
|
|
||||||
pout(usr, ">< %s (%s): %s", cmd, par, txt);
|
|
||||||
if(!strcmp("NICK", cmd) && !strcmp(usr, nick))
|
|
||||||
strlcpy(nick, txt, sizeof nick);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for(i = 0; i < Tlast; i++)
|
||||||
|
argv[i] = NULL;
|
||||||
|
|
||||||
static void
|
/*
|
||||||
usage(void) {
|
<bufout> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
|
||||||
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n", argv0);
|
<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, ' ');
|
||||||
|
*p = 0;
|
||||||
|
for(++p; *p == ' '; p++);
|
||||||
|
cmd = p;
|
||||||
|
argv[Tnick] = &msg[1];
|
||||||
|
if((p = strchr(msg, '!'))) {
|
||||||
|
*p = 0;
|
||||||
|
argv[Tuser] = ++p;
|
||||||
|
}
|
||||||
|
} 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)) {
|
||||||
|
return;
|
||||||
|
} 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 */
|
||||||
|
snprintf(bufout, sizeof(bufout), "%s", argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
pout(server, bufout);
|
||||||
|
return;
|
||||||
|
} 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)) {
|
||||||
|
if(argv[Ttext]!=NULL){
|
||||||
|
p = strchr(argv[Ttext], ' ');
|
||||||
|
if(p)
|
||||||
|
*p = 0;
|
||||||
|
}
|
||||||
|
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)) {
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has left %s",
|
||||||
|
argv[Tnick], argv[Tuser], argv[Tchan]);
|
||||||
|
} 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]);
|
||||||
|
else if(!strncmp("QUIT", argv[Tcmd], 5))
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has quit \"%s\"",
|
||||||
|
argv[Tnick], argv[Tuser],
|
||||||
|
argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
else if(!strncmp("NICK", argv[Tcmd], 5))
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- %s changed nick to %s",
|
||||||
|
argv[Tnick], argv[Ttext]);
|
||||||
|
else if(!strncmp("TOPIC", argv[Tcmd], 6))
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- %s changed topic to \"%s\"",
|
||||||
|
argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
else if(!strncmp("KICK", argv[Tcmd], 5))
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- %s kicked %s (\"%s\")",
|
||||||
|
argv[Tnick], argv[Targ],
|
||||||
|
argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
else if(!strncmp("NOTICE", argv[Tcmd], 7))
|
||||||
|
snprintf(bufout, sizeof(bufout), "-!- \"%s\")",
|
||||||
|
argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
else if(!strncmp("PRIVMSG", argv[Tcmd], 8)) snprintf(bufout, sizeof(bufout), "<%s> %s",
|
||||||
|
argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
|
||||||
|
if(!argv[Tchan] || !strncmp(argv[Tchan], nick, strlen(nick)))
|
||||||
|
pout(argv[Tnick], bufout);
|
||||||
|
else
|
||||||
|
pout(argv[Tchan], bufout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
const char *user = getenv("USER");
|
struct hostent *hp;
|
||||||
int n;
|
struct sockaddr_in addr = { 0 };
|
||||||
|
char ping[256];
|
||||||
fd_set rd;
|
fd_set rd;
|
||||||
|
|
||||||
strlcpy(nick, user ? user : "unknown", sizeof nick);
|
nick = fullname = getenv("USER");
|
||||||
ARGBEGIN {
|
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
|
||||||
case 'h':
|
switch (argv[i][1]) {
|
||||||
host = EARGF(usage());
|
default:
|
||||||
|
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;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
port = EARGF(usage());
|
port = atoi(argv[++i]);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
strlcpy(nick, EARGF(usage()), sizeof nick);
|
nick = argv[++i];
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
password = EARGF(usage());
|
password = argv[++i];
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
fullname = argv[++i];
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
eprint("sic-"VERSION", © 2005-2017 Anselm R Garbe, Jeroen Schot, Kris Maglione, Nico Golde\n");
|
fputs("sic-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
usage();
|
}
|
||||||
} ARGEND;
|
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
srv = fdopen(dial(host, port), "r+");
|
if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
if (!srv)
|
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
|
||||||
eprint("fdopen:");
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
hp = gethostbyname(server);
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
bcopy(hp->h_addr, &addr.sin_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 */
|
/* login */
|
||||||
if(password)
|
if(password)
|
||||||
sout("PASS %s", password);
|
snprintf(bufout, sizeof(bufout),
|
||||||
sout("NICK %s", nick);
|
"PASS %s\r\nNICK %s\r\nUSER %s localserver %s :%s\r\n",
|
||||||
sout("USER %s localhost %s :%s", nick, host, nick);
|
password, nick, nick, server, fullname ? fullname : nick);
|
||||||
fflush(srv);
|
else
|
||||||
setbuf(stdout, NULL);
|
snprintf(bufout, sizeof(bufout), "NICK %s\r\nUSER %s localserver %s :%s\r\n",
|
||||||
setbuf(srv, NULL);
|
nick, nick, server, fullname ? fullname : nick);
|
||||||
setbuf(stdin, NULL);
|
write(srv, bufout, strlen(bufout));
|
||||||
#ifdef __OpenBSD__
|
|
||||||
if (pledge("stdio", NULL) == -1)
|
snprintf(ping, sizeof(ping), "PING %s\r\n", server);
|
||||||
eprint("error: pledge:");
|
channel[0] = 0;
|
||||||
#endif
|
setbuf(stdout, NULL); /* unbuffered stdout */
|
||||||
for(;;) { /* main loop */
|
for(;;) {
|
||||||
FD_ZERO(&rd);
|
FD_ZERO(&rd);
|
||||||
FD_SET(0, &rd);
|
FD_SET(0, &rd);
|
||||||
FD_SET(fileno(srv), &rd);
|
FD_SET(srv, &rd);
|
||||||
tv.tv_sec = 120;
|
tv.tv_sec = 120;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
n = select(fileno(srv) + 1, &rd, 0, 0, &tv);
|
i = select(srv + 1, &rd, 0, 0, &tv);
|
||||||
if(n < 0) {
|
if(i < 0) {
|
||||||
if(errno == EINTR)
|
if(errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
eprint("sic: error on select():");
|
perror("sic: error on select()");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else if(i == 0) {
|
||||||
|
if(time(NULL) - trespond >= PINGTIMEOUT) {
|
||||||
|
pout(server, "-!- sic shutting down: parseing timeout");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
else if(n == 0) {
|
write(srv, ping, strlen(ping));
|
||||||
if(time(NULL) - trespond >= 300)
|
|
||||||
eprint("sic shutting down: parse timeout\n");
|
|
||||||
sout("PING %s", host);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(FD_ISSET(fileno(srv), &rd)) {
|
if(FD_ISSET(srv, &rd)) {
|
||||||
if(fgets(bufin, sizeof bufin, srv) == NULL)
|
if(getline(srv, sizeof(bufin), bufin) == -1) {
|
||||||
eprint("sic: remote host closed connection\n");
|
perror("sic: remote server closed connection");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
parsesrv(bufin);
|
parsesrv(bufin);
|
||||||
trespond = time(NULL);
|
trespond = time(NULL);
|
||||||
}
|
}
|
||||||
if(FD_ISSET(0, &rd)) {
|
if(FD_ISSET(0, &rd)) {
|
||||||
if(fgets(bufin, sizeof bufin, stdin) == NULL)
|
if(getline(0, sizeof(bufin), bufin) == -1) {
|
||||||
eprint("sic: broken pipe\n");
|
perror("sic: broken pipe");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
parsein(bufin);
|
parsein(bufin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
39
sic.html
Normal file
39
sic.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<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.1.tar.gz">sic 0.1</a> (5kb) (20060720)</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>
|
46
strlcpy.c
46
strlcpy.c
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copy src to string dst of size siz. At most siz-1 characters
|
|
||||||
* will be copied. Always NUL terminates (unless siz == 0).
|
|
||||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
|
||||||
*/
|
|
||||||
size_t
|
|
||||||
strlcpy(char *dst, const char *src, size_t siz)
|
|
||||||
{
|
|
||||||
char *d = dst;
|
|
||||||
const char *s = src;
|
|
||||||
size_t n = siz;
|
|
||||||
/* Copy as many bytes as will fit */
|
|
||||||
if (n != 0) {
|
|
||||||
while (--n != 0) {
|
|
||||||
if ((*d++ = *s++) == '\0')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
|
||||||
if (n == 0) {
|
|
||||||
if (siz != 0)
|
|
||||||
*d = '\0'; /* NUL-terminate dst */
|
|
||||||
while (*s++)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
return(s - src - 1); /* count does not include NUL */
|
|
||||||
}
|
|
66
util.c
66
util.c
@ -1,66 +0,0 @@
|
|||||||
/* See LICENSE file for license details. */
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
eprint(const char *fmt, ...) {
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(bufout, sizeof bufout, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
fprintf(stderr, "%s", bufout);
|
|
||||||
if(fmt[0] && fmt[strlen(fmt) - 1] == ':')
|
|
||||||
fprintf(stderr, " %s\n", strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
dial(char *host, char *port) {
|
|
||||||
struct addrinfo hints;
|
|
||||||
struct addrinfo *res, *r;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
memset(&hints, 0, sizeof hints);
|
|
||||||
hints.ai_family = AF_UNSPEC;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
if(getaddrinfo(host, port, &hints, &res) != 0)
|
|
||||||
eprint("error: cannot resolve hostname '%s':", host);
|
|
||||||
for(r = res; r; r = r->ai_next) {
|
|
||||||
if((fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
|
|
||||||
continue;
|
|
||||||
if(connect(fd, r->ai_addr, r->ai_addrlen) == 0)
|
|
||||||
break;
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
freeaddrinfo(res);
|
|
||||||
if(!r)
|
|
||||||
eprint("error: cannot connect to host '%s'\n", host);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
eat(char *s, int (*p)(int), int r) {
|
|
||||||
while(*s != '\0' && p((unsigned char)*s) == r)
|
|
||||||
s++;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char*
|
|
||||||
skip(char *s, char c) {
|
|
||||||
while(*s != c && *s != '\0')
|
|
||||||
s++;
|
|
||||||
if(*s != '\0')
|
|
||||||
*s++ = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
trim(char *s) {
|
|
||||||
char *e;
|
|
||||||
|
|
||||||
for (e = s + strlen(s); e > s && isspace((unsigned char)*(e - 1)); e--)
|
|
||||||
;
|
|
||||||
*e = '\0';
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user