comparison nnchat.c @ 21:29098addfa65

Added a "daemon" mode.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 12 Jun 2008 23:55:41 +0300
parents e80072e26178
children ccf302dae898
comparison
equal deleted inserted replaced
20:323c98360d8b 21:29098addfa65
29 char *optServer = "www11.servemedata.com", 29 char *optServer = "www11.servemedata.com",
30 *optUserName = NULL, 30 *optUserName = NULL,
31 *optUserName2 = NULL, 31 *optUserName2 = NULL,
32 *optPassword = NULL, 32 *optPassword = NULL,
33 *optLogFilename = NULL; 33 *optLogFilename = NULL;
34 34 BOOL optDaemon = FALSE;
35 FILE *optLogFile = NULL; 35 FILE *optLogFile = NULL;
36 36
37 37
38 /* Arguments 38 /* Arguments
39 */ 39 */
42 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, 42 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
43 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, 43 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
44 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, 44 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
45 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, 45 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ },
46 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, 46 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
47 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE },
47 }; 48 };
48 49
49 const int optListN = (sizeof(optList) / sizeof(optarg_t)); 50 const int optListN = (sizeof(optList) / sizeof(optarg_t));
50 51
51 52
96 THMSG(1, "Using color #%06x\n", optUserColor); 97 THMSG(1, "Using color #%06x\n", optUserColor);
97 break; 98 break;
98 99
99 case 5: 100 case 5:
100 optLogFilename = optArg; 101 optLogFilename = optArg;
102 break;
103
104 case 6:
105 optDaemon = TRUE;
106 THMSG(1, "Running in pseudo-daemon mode.\n");
101 break; 107 break;
102 108
103 default: 109 default:
104 THERR("Unknown option '%s'.\n", currArg); 110 THERR("Unknown option '%s'.\n", currArg);
105 return FALSE; 111 return FALSE;
198 vfprintf(optLogFile, fmt, ap); 204 vfprintf(optLogFile, fmt, ap);
199 va_end(ap); 205 va_end(ap);
200 fflush(optLogFile); 206 fflush(optLogFile);
201 } 207 }
202 208
203 fputs(tmpStr, stdout); 209 if (!optDaemon) {
204 va_start(ap, fmt); 210 fputs(tmpStr, stdout);
205 vfprintf(stdout, fmt, ap); 211 va_start(ap, fmt);
206 va_end(ap); 212 vfprintf(stdout, fmt, ap);
207 fflush(stdout); 213 va_end(ap);
214 fflush(stdout);
215 }
208 } 216 }
209 217
210 218
211 BOOL bufRealloc(char **buf, size_t *size, size_t add) 219 BOOL bufRealloc(char **buf, size_t *size, size_t add)
212 { 220 {
677 fd_set sockfds; 685 fd_set sockfds;
678 fd_set inputfds; 686 fd_set inputfds;
679 char *tmpStr; 687 char *tmpStr;
680 688
681 /* Initialize */ 689 /* Initialize */
682 th_init("NNChat", "Newbie Nudes chat client", "0.3", 690 th_init("NNChat", "Newbie Nudes chat client", "0.4",
683 "Written and designed by Anonymous Finnish Guy (C) 2008", 691 "Written and designed by Anonymous Finnish Guy (C) 2008",
684 "This software is freeware, use and distribute as you wish."); 692 "This software is freeware, use and distribute as you wish.");
685 th_verbosityLevel = 0; 693 th_verbosityLevel = 0;
686 694
687 /* Parse arguments */ 695 /* Parse arguments */
796 } 804 }
797 } 805 }
798 } 806 }
799 807
800 /* Check for user input */ 808 /* Check for user input */
809 if (!optDaemon) {
801 tv.tv_sec = 0; 810 tv.tv_sec = 0;
802 tv.tv_usec = SET_SELECT_USEC; 811 tv.tv_usec = SET_SELECT_USEC;
803 tmpfds = inputfds; 812 tmpfds = inputfds;
804 if ((result = select(1, &tmpfds, NULL, NULL, &tv)) == -1) { 813 if ((result = select(1, &tmpfds, NULL, NULL, &tv)) == -1) {
805 printMsg("Error occured in select(inputfds): %s\n", strerror(errno)); 814 printMsg("Error occured in select(inputfds): %s\n", strerror(errno));
818 tmpBuf); 827 tmpBuf);
819 exitProg = TRUE; 828 exitProg = TRUE;
820 } 829 }
821 } 830 }
822 } 831 }
832 } /* !optDaemon */
823 833
824 if (!colorSet) { 834 if (!colorSet) {
825 colorSet = TRUE; 835 colorSet = TRUE;
826 sendUserMsg(tmpSocket, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); 836 sendUserMsg(tmpSocket, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
827 } 837 }