int main(int argc, char** argv) { if (argc != 2) { fprintf(stderr, "Usage: %s \"<banner string>\"\n", argv[0]); exit(1); } setupsignals(); setupcurses(); setupscreen(); for (;;) { int x, y; if (g_requireinit) { endwin(); setupcurses(); setupscreen(); g_requireinit = 0; } x = rand() % (COLS - pstrwidth(argv[1])); y = rand() % (LINES - nlines); clear(); printstring(argv[1], x, y, 3, 1); refresh(); sleep(1); } }
void* sender(void *ptr) { struct socketstuff *s = (struct socketstuff *)ptr; int ch; while (1) { if(s->writechan == -1) break; if (i > CHATLEN - 1) i = 0; mybuf[i] = ch = wgetch(me); if (ch == KEY_RESIZE) { clear(); endwin(); setupscreen(); putchars(me,mybuf); putchars(them,tmbuf); refresh(); /* redraw screen on resize */ } else { putch(me, (char)ch); write(s->writechan, &ch, 1); } i++; } pthread_cancel(sendthread); return 0; }
void* sender(void *ptr) { struct stuff *s = (struct stuff *)ptr; /* int r = 0, i = 0, mode = -1; char mybuf[CHATLEN], tmbuf[CHATLEN]; memset(mybuf, 0, CHATLEN); memset(tmbuf, 0, CHATLEN); */ setupscreen(); int ch; while (1) { if (i > CHATLEN - 1) { i = 0; } ch = wgetch(me); mybuf[i] = ch; if (ch == KEY_RESIZE) { clear(); endwin(); setupscreen(); char *p = &mybuf[0]; while (&(*p) < &mybuf[CHATLEN - 1]) { putch(me, (*p)); p++; } p = &tmbuf[0]; while (&(*p) < &tmbuf[CHATLEN - 1]) { putch(them, (*p)); p++; } refresh(); } else { putch(me, mybuf[i]); int writefd = s->bertil.writechan; write(writefd, &mybuf[i], 1); } i++; } pthread_cancel(sendthread); return NULL; }
int main(int argc, char *argv[]) { struct socketstuff bertil; memset(mybuf, 0, CHATLEN); memset(tmbuf, 0, CHATLEN); memset(&bertil, 0, sizeof(struct socketstuff)); switch (argc) { case 2: bertil.port = (uint16_t) atoi(argv[1]); srv1(&bertil); break; case 3: bertil.port = (uint16_t) atoi(argv[1]); memset(bertil.hostname, 0, 256); memcpy(bertil.hostname, argv[2], strlen(argv[2])); cli1(&bertil); break; default: printf("usage %s <port> - will host server on <port>\n", argv[0]); printf("usage %s <port> <host> - connect to <host>:<port>\n" , argv[0]); exit(1); } setlocale(LC_ALL,""); printf("%s\n",red); setupscreen(); signal(SIGINT, controlc); pthread_create(&readthread, NULL, reader, &bertil); pthread_create(&sendthread, NULL, sender, &bertil); pthread_join(readthread, NULL); pthread_join(sendthread, NULL); endwin(); printf("%s\n",white); return 0; }