aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormcpcpc <michaelczigler@icloud.com>2020-08-21 07:01:15 -0400
committermcpcpc <michaelczigler@icloud.com>2020-08-21 07:01:15 -0400
commit189bc5f3d462bf94b8357272b2c00a587f81a2ae (patch)
tree08cdd45114156ff8ff59964871b75ae14da073d4
parenteliminated nested while loops (diff)
downloadkirc-189bc5f3d462bf94b8357272b2c00a587f81a2ae.tar.gz
kirc-189bc5f3d462bf94b8357272b2c00a587f81a2ae.tar.bz2
kirc-189bc5f3d462bf94b8357272b2c00a587f81a2ae.tar.xz
kirc-189bc5f3d462bf94b8357272b2c00a587f81a2ae.tar.zst
kirc-189bc5f3d462bf94b8357272b2c00a587f81a2ae.zip
add -o argument option for irc chat logging
Diffstat (limited to '')
-rw-r--r--README5
-rw-r--r--kirc.c14
2 files changed, 16 insertions, 3 deletions
diff --git a/README b/README
index d5c2a50..fefd7d0 100644
--- a/README
+++ b/README
@@ -7,7 +7,7 @@ BACKGROUND
----------
After having tried multiple IRC clients, I decided to develope my own. The
-result is a portable <250 sloc application that has no dependencies other
+result is a portable <300 sloc application that has no dependencies other
than a C99 compiler.
@@ -51,7 +51,7 @@ USAGE
-----
usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name]
-[-u username] [-k password] [-w columns] [-W columns] [-v|V]
+[-u username] [-k password] [-w columns] [-W columns] [-o path] [-v|V]
-s server address (default: 'irc.freenode.org')
-p server port (default: '6667')
-c channel name (default: '#kisslinux')
@@ -61,6 +61,7 @@ usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name]
-r real name (optional)
-v version information
-V verbose output (e.g. raw stream)
+-o output path to log irc stream
-w maximum width of the printed left column (default: '10')
-W maximum width of the entire printed stream (default '80')
diff --git a/kirc.c b/kirc.c
index cec5845..0e40632 100644
--- a/kirc.c
+++ b/kirc.c
@@ -26,6 +26,15 @@ static char * nick = NULL; /* nickname */
static char * pass = NULL; /* server password */
static char * user = NULL; /* server user name */
static char * real = NULL; /* server user real name */
+static char * olog = NULL; /* log irc stream parh */
+
+/* append string to specified file path */
+static void
+append_to_file(char *str) {
+ FILE *out = fopen(olog, "a");
+ fprintf(out, "%s", str);
+ fclose(out);
+}
/* wait for keyboard press to interrupt stream */
static int
@@ -76,6 +85,7 @@ raw(char *cmd_str, char *fmt, ...) {
va_end(ap);
if (verb) printf("<< %s", cmd_str);
+ if (olog) append_to_file(cmd_str);
write(conn, cmd_str, strlen(cmd_str));
}
@@ -149,6 +159,7 @@ parser(int sl, char *s) {
o = -1;
if (verb) printf(">> %s", buf_c);
+ if (olog) append_to_file(buf_c);
if (!strncmp(buf_c, "PING", 4)) {
buf_c[1] = 'O';
@@ -182,7 +193,7 @@ main(int argc, char **argv) {
int fd[2], cval;
- while ((cval = getopt(argc, argv, "s:p:n:k:c:u:r:w:W:vV")) != -1) {
+ while ((cval = getopt(argc, argv, "s:p:o:n:k:c:u:r:w:W:vV")) != -1) {
switch (cval) {
case 'v' : puts("kirc 0.0.2"); break;
case 'V' : verb = 1; break;
@@ -192,6 +203,7 @@ main(int argc, char **argv) {
case 'p' : port = optarg; break;
case 'r' : real = optarg; break;
case 'u' : user = optarg; break;
+ case 'o' : olog = optarg; break;
case 'n' : nick = optarg; break;
case 'k' : pass = optarg; break;
case 'c' : chan = optarg; break;