summaryrefslogtreecommitdiff
path: root/vchat-ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-ui.c')
-rwxr-xr-xvchat-ui.c195
1 files changed, 158 insertions, 37 deletions
diff --git a/vchat-ui.c b/vchat-ui.c
index 526727f..eba6ab0 100755
--- a/vchat-ui.c
+++ b/vchat-ui.c
@@ -46,6 +46,9 @@ static WINDOW *topic = NULL;
46static WINDOW *channel = NULL; 46static WINDOW *channel = NULL;
47static WINDOW *private = NULL; 47static WINDOW *private = NULL;
48static WINDOW *output = NULL; 48static WINDOW *output = NULL;
49
50static FILE *vchat_logfile = NULL;
51
49/* our screen dimensions */ 52/* our screen dimensions */
50static int screensx = 0; 53static int screensx = 0;
51static int screensy = 0; 54static int screensy = 0;
@@ -75,6 +78,7 @@ struct sb_entry {
75 78
76struct sb_data { 79struct sb_data {
77 struct sb_entry *entries; 80 struct sb_entry *entries;
81 struct sb_entry *last;
78 int count; 82 int count;
79 int scroll; 83 int scroll;
80}; 84};
@@ -242,7 +246,10 @@ sb_add (struct sb_data *sb, unsigned char *line, time_t when) {
242 newone->what = strdup(line); 246 newone->what = strdup(line);
243 newone->link = sb->entries; 247 newone->link = sb->entries;
244 newone->stamp= 0xffff; 248 newone->stamp= 0xffff;
245 if( sb->entries ) sb->entries->link = (struct sb_entry*)((unsigned long)sb->entries->link ^ (unsigned long)newone); 249 if( sb->entries )
250 sb->entries->link = (struct sb_entry*)((unsigned long)sb->entries->link ^ (unsigned long)newone);
251 else
252 sb->last = newone;
246 sb->entries = newone; 253 sb->entries = newone;
247 } 254 }
248 return newone; 255 return newone;
@@ -258,8 +265,10 @@ void flushout ( )
258 265
259void hideout( ) 266void hideout( )
260{ 267{
261 outputshown = 0; 268 if( outputshown ) {
262 resize(0); 269 outputshown = 0;
270 resize(0);
271 }
263} 272}
264 273
265void showout (void) 274void showout (void)
@@ -284,6 +293,12 @@ int writechan (unsigned char *str) {
284 time_t now = time(NULL); 293 time_t now = time(NULL);
285 tmp = sb_add(sb_pub,str,now); 294 tmp = sb_add(sb_pub,str,now);
286 295
296 if( getintoption( CF_KEEPLOG ) && vchat_logfile ) {
297 char date[16];
298 strftime( date, sizeof(date), "%Y%m%d%H%M%S", localtime(&now));
299 fprintf( vchat_logfile, "%s0%s\n", date, str);
300 }
301
287 if ( (sb_pub->scroll == sb_pub->count) && ((filtertype == 0) || ( testfilter(tmp)))) { 302 if ( (sb_pub->scroll == sb_pub->count) && ((filtertype == 0) || ( testfilter(tmp)))) {
288 i = writescr(channel, tmp); 303 i = writescr(channel, tmp);
289 wnoutrefresh(channel); 304 wnoutrefresh(channel);
@@ -293,42 +308,56 @@ int writechan (unsigned char *str) {
293} 308}
294 309
295int writecf (formtstr id,unsigned char *str) { 310int writecf (formtstr id,unsigned char *str) {
296 struct sb_entry *tmp; 311 struct sb_entry *tmp;
297 int i = 0; 312 int i = 0;
298 time_t now = time(NULL); 313 time_t now = time(NULL);
299 snprintf(tmpstr,TMPSTRSIZE,getformatstr(id),str); 314 snprintf(tmpstr,TMPSTRSIZE,getformatstr(id),str);
300 tmp = sb_add(sb_pub,tmpstr,now); 315 tmp = sb_add(sb_pub,tmpstr,now);
301 if ( (sb_pub->scroll == sb_pub->count) && 316
302 ((filtertype == 0) || ( testfilter(tmp)))) { 317 if( getintoption( CF_KEEPLOG ) && vchat_logfile ) {
303 i = writescr(channel, tmp); 318 char date[16];
304 wnoutrefresh(channel); 319 strftime( date, sizeof(date), "%Y%m%d%H%M%S", localtime(&now));
305 } 320 fprintf( vchat_logfile, "%s0%s\n", date, str);
306 consoleline(NULL); 321 }
307 return i; 322
323 if ( (sb_pub->scroll == sb_pub->count) &&
324 ((filtertype == 0) || ( testfilter(tmp)))) {
325 i = writescr(channel, tmp);
326 wnoutrefresh(channel);
327 }
328 consoleline(NULL);
329 return i;
308} 330}
309 331
310int writepriv (unsigned char *str) { 332int writepriv (unsigned char *str) {
311 int i = 0; 333 int i = 0;
312 time_t now = time (NULL); 334 if (private) {
313 struct sb_entry *tmp; 335
314 336 time_t now = time (NULL);
315 if (private) { 337 struct sb_entry *tmp;
316 tmp = sb_add(sb_priv,str,now); 338 tmp = sb_add(sb_priv,str,now);
317 if ( (sb_priv->scroll == sb_priv->scroll) && 339
318 ((filtertype == 0) || ( testfilter(tmp)))) { 340 if( getintoption( CF_KEEPLOG ) && vchat_logfile ) {
319 i = writescr(private, tmp); 341 char date[16];
320 } 342 strftime( date, sizeof(date), "%Y%m%d%H%M%S", localtime(&now));
321 if( privwinhidden ) { 343 fprintf( vchat_logfile, "%s1%s\n", date, str);
322 privheight_desired = privwinhidden; 344 }
323 privwinhidden = 0; 345
324 resize(0); 346 if ( (sb_priv->scroll == sb_priv->scroll) &&
325 } 347 ((filtertype == 0) || ( testfilter(tmp)))) {
326 wnoutrefresh(private); 348 i = writescr(private, tmp);
327 topicline(NULL); 349 }
328 } else 350 if( privwinhidden ) {
329 i = writechan( str ); 351 privheight_desired = privwinhidden;
330 352 privwinhidden = 0;
331 return i; 353 resize(0);
354 }
355 wnoutrefresh(private);
356 topicline(NULL);
357 } else
358 i = writechan( str );
359
360 return i;
332} 361}
333 362
334/* Get #if 's out of code */ 363/* Get #if 's out of code */
@@ -468,6 +497,87 @@ writescr ( WINDOW *win, struct sb_entry *entry ) {
468} 497}
469 498
470static void 499static void
500writelog_processentry ( FILE *file, struct sb_entry* entry )
501{
502 char *outtmp;
503 int outoff = 0;
504 if( usetime ) {
505 outtmp = tmpstr+64;
506 strftime(outtmp,64,getformatstr(FS_TIME),localtime(&entry->when));
507 while(*outtmp)
508 if( *outtmp > 1 )
509 tmpstr[outoff++] = *(outtmp++);
510 else
511 if( *(++outtmp))
512 outtmp++;
513 }
514
515 outtmp = entry->what;
516 while(*outtmp)
517 while(*outtmp && ( outoff < TMPSTRSIZE-1) ) {
518 if( *outtmp > 1 )
519 tmpstr[outoff++] = *(outtmp++);
520 else
521 if( *(++outtmp))
522 outtmp++;
523 tmpstr[outoff]=0; outoff = 0;
524 fputs( tmpstr, file );
525 }
526
527 fputc( '\n', file);
528}
529
530void
531writelog_i ( FILE *file)
532{
533 if( !private ) {
534 writelog( file);
535 } else {
536 struct sb_entry *now1= sb_pub->last, *prev1 = NULL, *tmp;
537 struct sb_entry *now2= sb_priv->last, *prev2 = NULL;
538 fputs( "Interleaved messages:\n\n", file);
539 while( now1 || now2 ) {
540 int process;
541 if( now1 && now2 ) {
542 process = ( now1->when < now2->when ) ? 1 : 2;
543 } else {
544 process = now1 ? 1 : 2;
545 }
546
547 if( process == 1 ) {
548 writelog_processentry( file, now1 );
549 tmp = now1; now1 = (struct sb_entry*)((unsigned long)now1->link ^ (unsigned long)prev1); prev1 = tmp;
550 } else {
551 writelog_processentry( file, now2 );
552 tmp = now2; now2 = (struct sb_entry*)((unsigned long)now2->link ^ (unsigned long)prev2); prev2 = tmp;
553 }
554 }
555 }
556}
557
558void
559writelog ( FILE *file )
560{
561 if( sb_pub->last ) {
562 struct sb_entry *now = sb_pub->last, *prev = NULL, *tmp;
563 fputs( "Public messages:\n\n", file);
564 while( now ) {
565 writelog_processentry( file, now );
566 tmp = now; now = (struct sb_entry*)((unsigned long)now->link ^ (unsigned long)prev); prev = tmp;
567 }
568 putc( '\n', file );
569 }
570 if( private && sb_priv->last ) {
571 struct sb_entry *now = sb_priv->last, *prev = NULL, *tmp;
572 fputs( "Private messages:\n\n", file);
573 while( now ) {
574 writelog_processentry( file, now );
575 tmp = now; now = (struct sb_entry*)((unsigned long)now->link ^ (unsigned long)prev); prev = tmp;
576 }
577 }
578}
579
580static void
471resize_output ( ) 581resize_output ( )
472{ 582{
473 int outputwidth = (outputwidth_desired + 7 > screensx) ? screensx - 7 : outputwidth_desired; 583 int outputwidth = (outputwidth_desired + 7 > screensx) ? screensx - 7 : outputwidth_desired;
@@ -1068,6 +1178,15 @@ initui (void)
1068 writeout (vchat_us_version); 1178 writeout (vchat_us_version);
1069 writeout (vchat_cm_version); 1179 writeout (vchat_cm_version);
1070 showout( ); 1180 showout( );
1181
1182 if( getintoption( CF_KEEPLOG ) ) {
1183 unsigned char *logfile = getstroption( CF_LOGFILE );
1184 if( logfile && *logfile ) {
1185 if( *logfile == '~' )
1186 logfile = tilde_expand( logfile );
1187 vchat_logfile = fopen( logfile, "a+" );
1188 }
1189 }
1071} 1190}
1072 1191
1073/* render colorized line to window */ 1192/* render colorized line to window */
@@ -1169,6 +1288,8 @@ exitui (void)
1169 rl_callback_handler_remove (); 1288 rl_callback_handler_remove ();
1170 endwin (); 1289 endwin ();
1171 ui_init = 0; 1290 ui_init = 0;
1291 if( vchat_logfile )
1292 fclose( vchat_logfile );
1172 } 1293 }
1173} 1294}
1174 1295
@@ -1414,7 +1535,7 @@ addfilter( char colour, unsigned char *regex ) {
1414 /* couldn't compile regex ... print error, return */ 1535 /* couldn't compile regex ... print error, return */
1415 free( newflt ); 1536 free( newflt );
1416 1537
1417 snprintf( tmpstr, TMPSTRSIZE, " %s ", regex); 1538 snprintf( tmpstr, TMPSTRSIZE, " %s ", regex);
1418 writeout( " Bad regular expression: "); 1539 writeout( " Bad regular expression: ");
1419 writeout( tmpstr ); 1540 writeout( tmpstr );
1420 showout( ); 1541 showout( );