From 18de21a2765f1fa33ef313fb20f5baad510cd86d Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sun, 25 May 2003 15:06:30 +0000 Subject: encoding, time, logging, params --- Makefile | 4 ++-- sample-count.fmt | 2 +- sample-devlog.fmt | 2 +- sample-erdgeist.fmt | 3 ++- sample-mAsq.fmt | 2 +- vchat-client.c | 36 +++++++++++++++++++++++++++--------- vchat-config.h | 4 +++- vchat-messages.h | 3 +++ vchat-protocol.c | 1 + vchat-ui.c | 41 +++++++++++++++++++++++++++++++++++++---- vchat.h | 12 +++++++----- 11 files changed, 85 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 0342b47..6c737cb 100755 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ # configuration # ############################################## -CFLAGS = -Wall -Os -#CFLAGS = -Wall -g -ggdb +#CFLAGS = -Wall -Os +CFLAGS = -Wall -g -ggdb ## use this line when you've got an readline before 4.(x|2) #CFLAGS += -DOLDREADLINE diff --git a/sample-count.fmt b/sample-count.fmt index 019c46e..d008991 100755 --- a/sample-count.fmt +++ b/sample-count.fmt @@ -42,7 +42,7 @@ FS_IDLE = "^8%s" FS_TIME = "^5[%H:%M]-- ^0" FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "[ %s@%s:%d, use .h to get help, send bugs reports and feature requests to vchat@pulse.flatline.de ..." +FS_CONSOLE = "%s@%s:%d, use .h to get help" FS_CONNECTED = "^2# Connected to '^6%s^2', port ^6%d^2 ..." FS_TOPIC = "^2# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^2# Channel ^6%d^2 has no topic" diff --git a/sample-devlog.fmt b/sample-devlog.fmt index 56d67f7..e70364d 100755 --- a/sample-devlog.fmt +++ b/sample-devlog.fmt @@ -47,7 +47,7 @@ FS_IDLE = "^8%s" FS_TIME = "^2[%H:%M]^0 " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "[ %s@%s:%d, use .h to get help" +FS_CONSOLE = "%s@%s:%d, use .h to get help" FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%d^2 ..." FS_TOPIC = "^1# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^1# Channel ^6%d^2 has no topic" diff --git a/sample-erdgeist.fmt b/sample-erdgeist.fmt index cce9ef2..5fc87e1 100755 --- a/sample-erdgeist.fmt +++ b/sample-erdgeist.fmt @@ -39,9 +39,10 @@ FS_DBG = "^3%s" FS_ERR = "^1%s" FS_IDLE = "^8%s" FS_TIME = "^9[%H:%M]^0 " +FS_CONSOLETIME = "[%H:%M] " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "[ %s@%s:%d, use .h to get help" +FS_CONSOLE = "%s@%s:%d, use .h to get help" FS_CONNECTED = "^2# Connected to '^0%s^2', port ^0%d^2 ..." FS_TOPIC = "^1# Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^1# Channel ^6%d^2 has no topic" diff --git a/sample-mAsq.fmt b/sample-mAsq.fmt index 02908b0..9bed139 100755 --- a/sample-mAsq.fmt +++ b/sample-mAsq.fmt @@ -42,7 +42,7 @@ FS_IDLE = "^8%s" FS_TIME = "^5%H:%M^0 " FS_TOPICW = "[ Channel %d: %s" FS_NOTOPICW = "[ Channel %d has no topic" -FS_CONSOLE = "[ %s@%s:%d, use .h to get help, send bugs reports and feature requests to vchat@pulse.flatline.de ..." +FS_CONSOLE = "%s@%s:%d, use .h to get help" FS_CONNECTED = "^2*^0C^2* Connected to '^6%s^2', port ^6%d^2 ..." FS_TOPIC = "^2*^0T^2* Channel ^6%d^2 topic is: '^0%s^2'" FS_NOTOPIC = "^2*^0T^2* Channel ^6%d^2 has no topic" diff --git a/vchat-client.c b/vchat-client.c index 039301e..2fc1ea9 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -386,15 +386,24 @@ cleanup (int signal) exit (0); } +static int oldseconds = 0; + void calleverysecond( void ) { /* timetriggered execution, don't rely on being called every 1000us */ /* rather see it as a chance for being called 9 times in 10 seconds */ /* so check time() */ + time_t now = time( NULL ); + struct tm *mytime = localtime( &now ); + if( mytime->tm_sec < oldseconds ) { + consoleline( NULL ); + } + oldseconds = mytime->tm_sec; if(quitrequest) quitrequest--; if(outputcountdown && !--outputcountdown) hideout( ); + } /* this function is called in the master loop */ @@ -437,19 +446,23 @@ eventloop (void) } void usage(unsigned char *name) { - printf ("usage: %s [-C config-file] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname]\n",name); - puts (" -C load a second config-file, overriding the first one\n"); - puts (" -l local connect (no SSL + connects localhost:2323)\n"); - puts (" -z don't use certificate files\n"); + printf ("usage: %s [-C config-file] [-F formats] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname] [-k] [-K] [-L logfile]\n",name); + puts (" -C load a second config-file, overriding the first one"); + puts (" -F load format strings (skins) from this file"); + puts (" -l local connect (no SSL + connects localhost:2323)"); + puts (" -z don't use certificate files"); printf (" -s set server (default \"%s\")\n",getstroption(CF_SERVERHOST)); printf (" -p set port (default %d)\n",getintoption(CF_SERVERPORT)); printf (" -c set channel (default %d)\n",getintoption(CF_CHANNEL)); if (nick) printf(" -n set nickname (default \"%s\")\n",nick); else - puts (" -n set nickname\n"); + puts (" -n set nickname"); printf (" -f set from (default \"%s\")\n",getstroption(CF_FROM)); - puts (" -h gives this help\n"); + puts (" -k keep autolog"); + puts (" -K don't keep autolog"); + printf (" -L use this file as logfile (default \"%s\")\n",getstroption(CF_LOGFILE)); + puts (" -h gives this help"); } /* main - d'oh */ @@ -461,12 +474,10 @@ main (int argc, char **argv) loadconfig (GLOBAL_CONFIG_FILE); loadconfig (getstroption (CF_CONFIGFILE)); - loadformats(GLOBAL_FORMAT_FILE); - loadformats(getstroption (CF_FORMFILE)); /* parse commandline */ while (cmdsunparsed) { - pchar = getopt(argc,argv,"C:lzs:p:c:n:f:h"); + pchar = getopt(argc,argv,"C:F:lzs:p:c:n:f:kKL:h"); #ifdef DEBUG fprintf(stderr,"parse commandline: %d ('%c'): %s\n",pchar,pchar,optarg); #endif @@ -474,6 +485,7 @@ main (int argc, char **argv) switch (pchar) { case -1 : cmdsunparsed = 0; break; case 'C': loadconfig(optarg); break; + case 'F': setstroption(CF_FORMFILE,optarg); break; case 'l': setintoption(CF_USESSL,0); break; case 'z': setintoption(CF_USECERT,0); break; case 's': setstroption(CF_SERVERHOST,optarg); break; @@ -481,6 +493,9 @@ main (int argc, char **argv) case 'c': setintoption(CF_CHANNEL,strtol(optarg,NULL,10)); break; case 'n': setstroption(CF_NICK,optarg); break; case 'f': setstroption(CF_FROM,optarg); break; + case 'k': setintoption(CF_KEEPLOG,1); break; + case 'K': setintoption(CF_KEEPLOG,0); break; + case 'L': setstroption(CF_LOGFILE,optarg); break; case 'h': usage(argv[0]); exit(0); break; default : usage(argv[0]); exit(1); } @@ -488,6 +503,9 @@ main (int argc, char **argv) if (optind < argc) { usage(argv[0]); exit(1); } + loadformats(GLOBAL_FORMAT_FILE); + loadformats(getstroption (CF_FORMFILE)); + if (!getintoption(CF_USESSL)) { setstroption(CF_SERVERHOST,"localhost"); setintoption(CF_SERVERPORT,2323); diff --git a/vchat-config.h b/vchat-config.h index 85db619..ca938b7 100755 --- a/vchat-config.h +++ b/vchat-config.h @@ -39,6 +39,7 @@ static volatile configoption configoptions[] = { {CF_KEYFILE, CO_STR, "keyfile", "~/.vchat/key", NULL, NULL }, {CF_FORMFILE, CO_STR, "formatfile", "~/.vchat/formats", NULL, NULL }, {CF_LOGFILE, CO_STR, "logfile", "~/.vchat/log", NULL, NULL, }, + {CF_ENCODING, CO_STR, "encoding", NULL, NULL, &encoding }, {CF_USESSL, CO_INT, "usessl", (char *) 1, (char *)-1, (unsigned char **)&usessl }, {CF_USECERT, CO_INT, "usecert", (char *) 1, (char *)-1, NULL }, {CF_USETIME, CO_INT, "usetime", (char *) 1, (char *)-1, (unsigned char **)&usetime }, @@ -91,9 +92,10 @@ static formatstring formatstrings[] = { FE( FS_ERR_STRING, "\0011%s %s"), FE( FS_IDLE, "\0018%s"), FE( FS_TIME, "\0015[%H:%M]\0010 "), + FE( FS_CONSOLETIME, "[%H:%M] "), FE( FS_TOPICW, "[ Channel %d: %s"), FE( FS_NOTOPICW, "[ Channel %d has no topic"), - FE( FS_CONSOLE, "[ %s@%s:%d, use .h to get help, send bugs reports and feature requests to vchat@pulse.flatline.de ..."), + FE( FS_CONSOLE, "%s@%s:%d, use .h to get help "), FE( FS_CONNECTED, "\0012# Connected to '\0016%s\0012', port \0016%d\0012 ..."), FE( FS_TOPIC, "\0012# Channel \0016%d\0012 topic is: '\0010%s\0012'"), FE( FS_NOTOPIC, "\0012# Channel \0016%d\0012 has no topic"), diff --git a/vchat-messages.h b/vchat-messages.h index 08114d5..e73e567 100755 --- a/vchat-messages.h +++ b/vchat-messages.h @@ -56,6 +56,9 @@ servermessage servermessages[] = { /* 123 User Login / Logout Information */ {"123", SM_USERINFO, NULL, NULL}, +/* 169 + List of known encodings */ + {"169", SM_INFO, NULL, NULL}, /* 201 Server signon */ {"201", SM_IGNORE, NULL, NULL}, diff --git a/vchat-protocol.c b/vchat-protocol.c index 05abc26..d04d9b0 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -73,6 +73,7 @@ static void pmnotsent (unsigned char *message); extern int status; int usessl = 1; +unsigned char *encoding; /* connects to server */ int diff --git a/vchat-ui.c b/vchat-ui.c index 15623e2..4eb625e 100755 --- a/vchat-ui.c +++ b/vchat-ui.c @@ -317,7 +317,7 @@ int writecf (formtstr id,unsigned char *str) { if( getintoption( CF_KEEPLOG ) && vchat_logfile ) { char date[16]; strftime( date, sizeof(date), "%Y%m%d%H%M%S", localtime(&now)); - fprintf( vchat_logfile, "%s0%s\n", date, str); + fprintf( vchat_logfile, "%s0%s\n", date, tmpstr); } if ( (sb_pub->scroll == sb_pub->count) && @@ -1185,16 +1185,38 @@ initui (void) writeout (vchat_cm_version); showout( ); */ - resize(0); if( getintoption( CF_KEEPLOG ) ) { unsigned char *logfile = getstroption( CF_LOGFILE ); if( logfile && *logfile ) { if( *logfile == '~' ) logfile = tilde_expand( logfile ); - vchat_logfile = fopen( logfile, "a+" ); + vchat_logfile = fopen( logfile, "r+" ); + if( vchat_logfile ) { + char date[16]; + time_t now; struct tm now_tm; + int dst, lenstr; + char *str; + while( !feof( vchat_logfile)) { + if( (fread( date, 14, 1, vchat_logfile) == 1) && + (strptime( date, "%Y%m%d%H%M%S", &now_tm)) && + (((dst = fgetc( vchat_logfile )) == '0') || (dst == '1')) && + (str = fgetln(vchat_logfile, &lenstr))&& + (str[lenstr-1] == '\n')) + { + str[lenstr-1] = 0; + now = mktime( &now_tm ); + sb_add( dst == '0' ? sb_pub : sb_priv, str, now); + } else { + fseek( vchat_logfile, 0, SEEK_END); + fgetc( vchat_logfile ); + } + } + } } } + + resize(0); } /* render colorized line to window */ @@ -1236,7 +1258,18 @@ consoleline (unsigned char *message) for (i = 0; i < console->_maxx; i++) waddch (console, ' '); - mvwaddnstr (console, 0, 0, message ? message : consolestr, console->_maxx); + + if( !message && usetime ) + { + char date[10]; + time_t now = time(NULL); + strftime( date, sizeof(date), getformatstr(FS_CONSOLETIME), localtime(&now)); + snprintf( tmpstr, TMPSTRSIZE, "%s%s", date, consolestr); + mvwaddnstr (console, 0, 0, tmpstr, console->_maxx); + } else { + mvwaddnstr (console, 0, 0, message ? message : consolestr, console->_maxx); + } + snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_SBINF),sb_pub->scroll,sb_pub->count); mvwaddstr (console, 0, console->_maxx - (strlen(tmpstr)-1),tmpstr); if (sb_win == 0) mvwaddch (console, 0, console->_maxx,'*'); diff --git a/vchat.h b/vchat.h index 4dca1a1..c2821a2 100755 --- a/vchat.h +++ b/vchat.h @@ -38,14 +38,15 @@ typedef enum { CO_NIL, CO_STR, CO_INT } conftype; typedef enum { CF_NIL, CF_NICK, CF_FROM, CF_SERVERHOST, CF_SERVERPORT, CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGFILE, CF_USESSL, CF_USECERT, CF_PRIVHEIGHT, CF_HSCROLL, CF_CHANNEL, CF_USETIME, -CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, CF_KEEPLOG } confopt; +CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, CF_KEEPLOG, +CF_ENCODING } confopt; /* format strings */ typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR, -FS_IDLE, FS_TIME, FS_TOPICW, FS_NOTOPICW, FS_CONSOLE, FS_CONNECTED, FS_TOPIC, -FS_NOTOPIC, FS_CHGTOPIC, FS_USONLINE, FS_USMATCH, FS_SIGNON, FS_SIGNOFF, FS_JOIN, -FS_LEAVE, FS_NICKCHANGE, FS_UNKNOWNMSG, FS_BOGUSMSG, FS_RXPUBURL, FS_MYPUBURL, -FS_RXPUBMSG, FS_MYPUBMSG, FS_TXPUBMSG, FS_RXPRIVMSG, FS_TXPRIVMSG, +FS_IDLE, FS_TIME, FS_CONSOLETIME, FS_TOPICW, FS_NOTOPICW, FS_CONSOLE, FS_CONNECTED, +FS_TOPIC, FS_NOTOPIC, FS_CHGTOPIC, FS_USONLINE, FS_USMATCH, FS_SIGNON, FS_SIGNOFF, +FS_JOIN, FS_LEAVE, FS_NICKCHANGE, FS_UNKNOWNMSG, FS_BOGUSMSG, FS_RXPUBURL, +FS_MYPUBURL, FS_RXPUBMSG, FS_MYPUBMSG, FS_TXPUBMSG, FS_RXPRIVMSG, FS_TXPRIVMSG, FS_BGPRIVMSG, FS_PUBACTION, FS_TXPUBACTION, FS_BGTXPUBACTION, FS_COMMAND, FS_LOCALCOMMAND, FS_BOGUSCOMMAND, FS_SBINF, FS_MISSTYPED, FS_UNKNCMD, FS_BADREGEX, FS_ERR_STRING } formtstr; @@ -134,6 +135,7 @@ extern unsigned char *vchat_ui_version; #define CONSOLESTRSIZE 1024 extern unsigned char topicstr[]; extern unsigned char consolestr[]; +extern unsigned char *encoding; /* init / exit functions */ void initui (void); -- cgit v1.2.3