On Mon, Sep 29, 2014 at 07:31:09PM -0700, Eric Pruitt wrote:
> I just noticed that "%F" support in strftime is a C99 feature, and if
> sic is targeting C89, it should be changed to "%Y-%m-%d".
Today I learned that "//" comments are apparently not valid C89, either.
I've attached a revised patch that also adds a couple more configurable
options.
Eric
diff --git a/Makefile b/Makefile
index d77b4f2..6fdcfbb 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,11 @@ options:
@echo CC $<
@${CC} -c ${CFLAGS} $<
-${OBJ}: config.mk util.c
+${OBJ}: config.h config.mk util.c
+
+config.h:
+ @echo creating $@ from config.def.h
+ @cp config.def.h $@
sic: ${OBJ}
@echo CC -o $@
diff --git a/config.def.h b/config.def.h
new file mode 100644
index 0000000..5449fee
--- /dev/null
+++ b/config.def.h
@@ -0,0 +1,14 @@
+/* Host used when "-h" is not given */
+#define DEFAULT_HOST "irc.oftc.net"
+
+/* 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!"
diff --git a/sic.c b/sic.c
index d93c2ec..e91a426 100644
--- a/sic.c
+++ b/sic.c
@@ -8,8 +8,10 @@
#include <time.h>
#include <unistd.h>
-static char *host = "irc.oftc.net";
-static char *port = "6667";
+#include "config.h"
+
+static char *host = DEFAULT_HOST;
+static char *port = DEFAULT_PORT;
static char *password;
static char nick[32];
static char bufin[4096];
@@ -22,7 +24,7 @@ static FILE *srv;
static void
pout(char *channel, char *fmt, ...) {
- static char timestr[18];
+ static char timestr[80];
time_t t;
va_list ap;
@@ -30,7 +32,7 @@ pout(char *channel, char *fmt, ...) {
vsnprintf(bufout, sizeof bufout, fmt, ap);
va_end(ap);
t = time(NULL);
- strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
+ strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t));
fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
}
@@ -61,7 +63,7 @@ parsein(char *s) {
if(s[0] == '\0')
return;
skip(s, '\n');
- if(s[0] != ':') {
+ if(s[0] != COMMAND_PREFIX_CHARACTER) {
privmsg(channel, s);
return;
}
@@ -82,7 +84,7 @@ parsein(char *s) {
if(*p)
*p++ = '\0';
if(!*p)
- p = "sic - 250 LOC are too much!";
+ p = DEFAULT_PARTING_MESSAGE;
sout("PART %s :%s", s, p);
return;
case 'm':