comparison nnchat.c @ 162:e59cec397811

Add a debug mode option (commandline) and enable certain features when we are in debug mode.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Nov 2010 14:56:27 +0200
parents 6dd282b5f431
children cc1cc49d26f0
comparison
equal deleted inserted replaced
161:6dd282b5f431 162:e59cec397811
50 WINDOW *mainWin = NULL, 50 WINDOW *mainWin = NULL,
51 *statusWin = NULL, 51 *statusWin = NULL,
52 *editWin = NULL; 52 *editWin = NULL;
53 BOOL setPrvMode = FALSE; 53 BOOL setPrvMode = FALSE;
54 BOOL setIgnoreMode = FALSE; 54 BOOL setIgnoreMode = FALSE;
55 BOOL optDebug = FALSE;
55 56
56 57
57 qlist_t *nnIgnoreList = NULL; 58 qlist_t *nnIgnoreList = NULL;
58 nn_userhash_t *nnUsers = NULL; 59 nn_userhash_t *nnUsers = NULL;
59 char *setConfigFile = NULL, 60 char *setConfigFile = NULL,
70 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, 71 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
71 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, 72 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ },
72 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, 73 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
73 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, 74 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE },
74 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ }, 75 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ },
76 { 8, 'd', "debug", "Enable various debug features", OPT_NONE },
75 }; 77 };
76 78
77 const int optListN = (sizeof(optList) / sizeof(optList[0])); 79 const int optListN = (sizeof(optList) / sizeof(optList[0]));
78 80
79 81
122 break; 124 break;
123 125
124 case 6: 126 case 6:
125 optDaemon = TRUE; 127 optDaemon = TRUE;
126 THMSG(1, "Running in pseudo-daemon mode.\n"); 128 THMSG(1, "Running in pseudo-daemon mode.\n");
129 break;
130
131 case 8:
132 optDebug = TRUE;
133 THMSG(1, "Debug mode enabled.\n");
127 break; 134 break;
128 135
129 default: 136 default:
130 THERR("Unknown option '%s'.\n", currArg); 137 THERR("Unknown option '%s'.\n", currArg);
131 return FALSE; 138 return FALSE;
379 } 386 }
380 387
381 388
382 if (*s == '/') { 389 if (*s == '/') {
383 /* Ignore room join/leave messages */ 390 /* Ignore room join/leave messages */
384 if (strstr(s, "left the room") || strstr(s, "joined the room from")) 391 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from")))
385 goto error; 392 goto error;
386 393
387 t = nn_strip_tags(s + 1); 394 t = nn_strip_tags(s + 1);
388 if (!strncmp(t, "BPRV", 4)) { 395 if (!strncmp(t, "BPRV", 4)) {
389 h = nn_decode_str2(t + 1); 396 h = nn_decode_str2(t + 1);
528 for (i = 0; i < nprotoCmds; i++) { 535 for (i = 0; i < nprotoCmds; i++) {
529 ssize_t cmdLen = protoCmds[i].len; 536 ssize_t cmdLen = protoCmds[i].len;
530 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) 537 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen))
531 return protoCmds[i].handler(sock, buf + cmdLen); 538 return protoCmds[i].handler(sock, buf + cmdLen);
532 } 539 }
533 540
534 return 1; 541 if (optDebug) {
542 printMsg("Unknown protocmd: \"%s\"\n", buf);
543 return 0;
544 } else
545 return 1;
535 } 546 }
536 547
537 char * trimLeft(char *buf) 548 char * trimLeft(char *buf)
538 { 549 {
539 while (*buf != 0 && isspace(*buf)) buf++; 550 while (*buf != 0 && isspace(*buf)) buf++;
753 previous = NULL; 764 previous = NULL;
754 } 765 }
755 mode = 2; 766 mode = 2;
756 } 767 }
757 768
758 // printMsg("%d, %d <-> %d : '%s' (%d, %d)\n", startPos, endPos, buf->len, pattern, mode, again); 769 if (optDebug)
770 printMsg("%d, %d <-> %d : '%s' (%d, %d)\n", startPos, endPos, buf->len, pattern, mode, again);
759 771
760 if (pattern) { 772 if (pattern) {
761 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again); 773 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again);
762 774
763 if (user) { 775 if (user) {
764 int i; 776 int i;
765 char *c = user->name; 777 char *c = user->name;
766 // printMsg("match '%s' / prev '%s'\n", user->name, previous); 778 if (optDebug)
779 printMsg("match '%s' / prev '%s'\n", user->name, previous);
767 780
768 for (i = startPos; i <= endPos; i++) 781 for (i = startPos; i <= endPos; i++)
769 nn_editbuf_delete(buf, startPos); 782 nn_editbuf_delete(buf, startPos);
770 783
771 for (i = startPos; *c; i++, c++) 784 for (i = startPos; *c; i++, c++)