Skip to content

Commit 189bc5f

Browse files
committed
add -o argument option for irc chat logging
1 parent 44c8c6d commit 189bc5f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ BACKGROUND
77
----------
88

99
After having tried multiple IRC clients, I decided to develope my own. The
10-
result is a portable <250 sloc application that has no dependencies other
10+
result is a portable <300 sloc application that has no dependencies other
1111
than a C99 compiler.
1212

1313

@@ -51,7 +51,7 @@ USAGE
5151
-----
5252

5353
usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name]
54-
[-u username] [-k password] [-w columns] [-W columns] [-v|V]
54+
[-u username] [-k password] [-w columns] [-W columns] [-o path] [-v|V]
5555
-s server address (default: 'irc.freenode.org')
5656
-p server port (default: '6667')
5757
-c channel name (default: '#kisslinux')
@@ -61,6 +61,7 @@ usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name]
6161
-r real name (optional)
6262
-v version information
6363
-V verbose output (e.g. raw stream)
64+
-o output path to log irc stream
6465
-w maximum width of the printed left column (default: '10')
6566
-W maximum width of the entire printed stream (default '80')
6667

kirc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ static char * nick = NULL; /* nickname */
2626
static char * pass = NULL; /* server password */
2727
static char * user = NULL; /* server user name */
2828
static char * real = NULL; /* server user real name */
29+
static char * olog = NULL; /* log irc stream parh */
30+
31+
/* append string to specified file path */
32+
static void
33+
append_to_file(char *str) {
34+
FILE *out = fopen(olog, "a");
35+
fprintf(out, "%s", str);
36+
fclose(out);
37+
}
2938

3039
/* wait for keyboard press to interrupt stream */
3140
static int
@@ -76,6 +85,7 @@ raw(char *cmd_str, char *fmt, ...) {
7685
va_end(ap);
7786

7887
if (verb) printf("<< %s", cmd_str);
88+
if (olog) append_to_file(cmd_str);
7989

8090
write(conn, cmd_str, strlen(cmd_str));
8191
}
@@ -149,6 +159,7 @@ parser(int sl, char *s) {
149159
o = -1;
150160

151161
if (verb) printf(">> %s", buf_c);
162+
if (olog) append_to_file(buf_c);
152163

153164
if (!strncmp(buf_c, "PING", 4)) {
154165
buf_c[1] = 'O';
@@ -182,7 +193,7 @@ main(int argc, char **argv) {
182193

183194
int fd[2], cval;
184195

185-
while ((cval = getopt(argc, argv, "s:p:n:k:c:u:r:w:W:vV")) != -1) {
196+
while ((cval = getopt(argc, argv, "s:p:o:n:k:c:u:r:w:W:vV")) != -1) {
186197
switch (cval) {
187198
case 'v' : puts("kirc 0.0.2"); break;
188199
case 'V' : verb = 1; break;
@@ -192,6 +203,7 @@ main(int argc, char **argv) {
192203
case 'p' : port = optarg; break;
193204
case 'r' : real = optarg; break;
194205
case 'u' : user = optarg; break;
206+
case 'o' : olog = optarg; break;
195207
case 'n' : nick = optarg; break;
196208
case 'k' : pass = optarg; break;
197209
case 'c' : chan = optarg; break;

0 commit comments

Comments
 (0)