Mercurial > hg > nnchat
comparison main.c @ 700:f3ec1cb11cea
Trim whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 17 Jan 2020 20:03:41 +0200 |
parents | e9232ce52bf8 |
children | 46efb0b16339 |
comparison
equal
deleted
inserted
replaced
699:e9232ce52bf8 | 700:f3ec1cb11cea |
---|---|
171 printf(" %-8s - %s (port %d)\n", | 171 printf(" %-8s - %s (port %d)\n", |
172 rdata->name, | 172 rdata->name, |
173 rdata->desc, | 173 rdata->desc, |
174 rdata->port); | 174 rdata->port); |
175 } | 175 } |
176 | 176 |
177 printf("\n"); | 177 printf("\n"); |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 BOOL argSplitStr(const char *src, const char *at, char **res1, char **res2) | 181 BOOL argSplitStr(const char *src, const char *at, char **res1, char **res2) |
385 { | 385 { |
386 char *msg; | 386 char *msg; |
387 | 387 |
388 if (str == NULL) | 388 if (str == NULL) |
389 return FALSE; | 389 return FALSE; |
390 | 390 |
391 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str); | 391 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str); |
392 | 392 |
393 if (msg != NULL) | 393 if (msg != NULL) |
394 { | 394 { |
395 int ret = th_conn_send_buf(conn, msg, strlen(msg) + 1); | 395 int ret = th_conn_send_buf(conn, msg, strlen(msg) + 1); |
470 void printMsgConst(nn_window_t *win, int flags, const char *msg) | 470 void printMsgConst(nn_window_t *win, int flags, const char *msg) |
471 { | 471 { |
472 char tmpStr[128]; | 472 char tmpStr[128]; |
473 nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); | 473 nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); |
474 | 474 |
475 // Only the main window | 475 // Only the main window |
476 if (win == NULL && tmpwin != NULL && (flags & LOG_RECURSIVE) == 0) | 476 if (win == NULL && tmpwin != NULL && (flags & LOG_RECURSIVE) == 0) |
477 { | 477 { |
478 time_t currTime = time(NULL); | 478 time_t currTime = time(NULL); |
479 struct tm *currTm, *prevTm; | 479 struct tm *currTm, *prevTm; |
480 | 480 |
630 | 630 |
631 | 631 |
632 BOOL nn_check_name_list(th_llist_t *list, const char *name) | 632 BOOL nn_check_name_list(th_llist_t *list, const char *name) |
633 { | 633 { |
634 th_llist_t *node; | 634 th_llist_t *node; |
635 | 635 |
636 for (node = list; node != NULL; node = node->next) | 636 for (node = list; node != NULL; node = node->next) |
637 { | 637 { |
638 if (th_strcasecmp(name, (char *) node->data) == 0) | 638 if (th_strcasecmp(name, (char *) node->data) == 0) |
639 return TRUE; | 639 return TRUE; |
640 } | 640 } |
656 | 656 |
657 // Find end of the message | 657 // Find end of the message |
658 t = th_conn_buf_strstr(conn, "<MESSAGE>"); | 658 t = th_conn_buf_strstr(conn, "<MESSAGE>"); |
659 if (!t) return 2; | 659 if (!t) return 2; |
660 msg = conn->base.ptr; | 660 msg = conn->base.ptr; |
661 | 661 |
662 t = th_conn_buf_strstr(conn, "</MESSAGE>"); | 662 t = th_conn_buf_strstr(conn, "</MESSAGE>"); |
663 if (!t) return 3; | 663 if (!t) return 3; |
664 *t = 0; | 664 *t = 0; |
665 | 665 |
666 // Decode message string | 666 // Decode message string |
698 { | 698 { |
699 char *in_name, *tmp, *in_msg, *h; | 699 char *in_name, *tmp, *in_msg, *h; |
700 nn_window_t *win; | 700 nn_window_t *win; |
701 h = nn_decode_str2(t + 1); | 701 h = nn_decode_str2(t + 1); |
702 | 702 |
703 // Check type of | 703 // Check type of |
704 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0) | 704 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0) |
705 in_name = nn_decode_str2(t + 10); | 705 in_name = nn_decode_str2(t + 10); |
706 else | 706 else |
707 in_name = nn_decode_str2(t + 8); | 707 in_name = nn_decode_str2(t + 8); |
708 | 708 |
730 { | 730 { |
731 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), | 731 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
732 "½11½%s½0½\n", h); | 732 "½11½%s½0½\n", h); |
733 } | 733 } |
734 } | 734 } |
735 | 735 |
736 th_free(in_name); | 736 th_free(in_name); |
737 th_free(h); | 737 th_free(h); |
738 } | 738 } |
739 else | 739 else |
740 { | 740 { |
769 { | 769 { |
770 colorNick = 15; | 770 colorNick = 15; |
771 colorText = 0; | 771 colorText = 0; |
772 } | 772 } |
773 } | 773 } |
774 | 774 |
775 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), | 775 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
776 "½5½<½%d½%s½5½>½%d½ %s½0½\n", colorNick, name, colorText, h); | 776 "½5½<½%d½%s½5½>½%d½ %s½0½\n", colorNick, name, colorText, h); |
777 th_free(h); | 777 th_free(h); |
778 th_free(t); | 778 th_free(t); |
779 } | 779 } |
967 { | 967 { |
968 case BMT_NEW_FIREFOX: | 968 case BMT_NEW_FIREFOX: |
969 // Newer method, supported by new-ish versions of Firefox | 969 // Newer method, supported by new-ish versions of Firefox |
970 execlp(setBrowser, setBrowser, "-new-tab", uri, (void *)NULL); | 970 execlp(setBrowser, setBrowser, "-new-tab", uri, (void *)NULL); |
971 break; | 971 break; |
972 | 972 |
973 default: | 973 default: |
974 // Default old method | 974 // Default old method |
975 { | 975 { |
976 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); | 976 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); |
977 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); | 977 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); |
1009 char *enc_name = nn_encode_str1(name); | 1009 char *enc_name = nn_encode_str1(name); |
1010 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name); | 1010 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name); |
1011 (void) conn; | 1011 (void) conn; |
1012 | 1012 |
1013 printMsg(currWin, "Opening profile for: '%s'\n", name); | 1013 printMsg(currWin, "Opening profile for: '%s'\n", name); |
1014 | 1014 |
1015 nn_open_uri(uri); | 1015 nn_open_uri(uri); |
1016 | 1016 |
1017 th_free(uri); | 1017 th_free(uri); |
1018 th_free(enc_name); | 1018 th_free(enc_name); |
1019 return 0; | 1019 return 0; |
1223 color = 1; | 1223 color = 1; |
1224 else | 1224 else |
1225 color = 3; | 1225 color = 3; |
1226 | 1226 |
1227 snprintf(name, sizeof(name), "[½%d½%-20s½0½] ", color, user->name); | 1227 snprintf(name, sizeof(name), "[½%d½%-20s½0½] ", color, user->name); |
1228 | 1228 |
1229 d->total++; | 1229 d->total++; |
1230 if (d->i >= NAME_NUM_PER_LINE) | 1230 if (d->i >= NAME_NUM_PER_LINE) |
1231 { | 1231 { |
1232 printMsgQ(currWin, "%s\n", d->buf); | 1232 printMsgQ(currWin, "%s\n", d->buf); |
1233 d->i = 0; | 1233 d->i = 0; |
1234 d->offs = 0; | 1234 d->offs = 0; |
1235 } | 1235 } |
1236 | 1236 |
1237 len = strlen(name); | 1237 len = strlen(name); |
1238 memcpy(d->buf + d->offs, name, len + 1); | 1238 memcpy(d->buf + d->offs, name, len + 1); |
1239 d->offs += len; | 1239 d->offs += len; |
1240 d->i++; | 1240 d->i++; |
1241 | 1241 |
1394 if (!th_strncasecmp(buf, cmd->name, cmd->len)) | 1394 if (!th_strncasecmp(buf, cmd->name, cmd->len)) |
1395 { | 1395 { |
1396 char *nbuf; | 1396 char *nbuf; |
1397 if (buf[cmd->len] != 0 && !th_isspace(buf[cmd->len])) | 1397 if (buf[cmd->len] != 0 && !th_isspace(buf[cmd->len])) |
1398 continue; | 1398 continue; |
1399 | 1399 |
1400 nbuf = str_trim_left(buf + cmd->len); | 1400 nbuf = str_trim_left(buf + cmd->len); |
1401 | 1401 |
1402 switch (cmd->flags) | 1402 switch (cmd->flags) |
1403 { | 1403 { |
1404 case CMDARG_NICK: | 1404 case CMDARG_NICK: |
1407 { | 1407 { |
1408 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name); | 1408 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name); |
1409 return 1; | 1409 return 1; |
1410 } | 1410 } |
1411 break; | 1411 break; |
1412 | 1412 |
1413 case CMDARG_NONE: | 1413 case CMDARG_NONE: |
1414 if (nbuf[0]) | 1414 if (nbuf[0]) |
1415 { | 1415 { |
1416 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name); | 1416 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name); |
1417 return 1; | 1417 return 1; |
1438 th_free(tmp); | 1438 th_free(tmp); |
1439 return result ? 0 : -1; | 1439 return result ? 0 : -1; |
1440 } | 1440 } |
1441 } | 1441 } |
1442 } | 1442 } |
1443 | 1443 |
1444 printMsgQ(currWin, "Unknown command: %s\n", buf); | 1444 printMsgQ(currWin, "Unknown command: %s\n", buf); |
1445 return 1; | 1445 return 1; |
1446 } | 1446 } |
1447 | 1447 |
1448 | 1448 |
1465 size_t len; | 1465 size_t len; |
1466 | 1466 |
1467 if (list == NULL || pattern == NULL) return NULL; | 1467 if (list == NULL || pattern == NULL) return NULL; |
1468 | 1468 |
1469 len = strlen(pattern); | 1469 len = strlen(pattern); |
1470 | 1470 |
1471 if (current != NULL) | 1471 if (current != NULL) |
1472 { | 1472 { |
1473 th_llist_t *node; | 1473 th_llist_t *node; |
1474 for (node = list; node != NULL; node = node->next) | 1474 for (node = list; node != NULL; node = node->next) |
1475 { | 1475 { |
1546 | 1546 |
1547 | 1547 |
1548 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) | 1548 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) |
1549 { | 1549 { |
1550 size_t i; | 1550 size_t i; |
1551 | 1551 |
1552 for (i = startPos; i <= endPos; i++) | 1552 for (i = startPos; i <= endPos; i++) |
1553 nn_editbuf_delete(buf, startPos); | 1553 nn_editbuf_delete(buf, startPos); |
1554 | 1554 |
1555 for (i = startPos; *c; i++, c++) | 1555 for (i = startPos; *c; i++, c++) |
1556 nn_editbuf_insert(buf, i, *c); | 1556 nn_editbuf_insert(buf, i, *c); |
1557 | 1557 |
1558 *pi = i; | 1558 *pi = i; |
1559 } | 1559 } |
1560 | 1560 |
1561 | 1561 |
1562 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) | 1562 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) |
1788 break; | 1788 break; |
1789 | 1789 |
1790 case 0x09: // Tab = complete username or command | 1790 case 0x09: // Tab = complete username or command |
1791 nn_tabcomplete_buffer(editBuf); | 1791 nn_tabcomplete_buffer(editBuf); |
1792 break; | 1792 break; |
1793 | 1793 |
1794 default: | 1794 default: |
1795 return FALSE; | 1795 return FALSE; |
1796 } | 1796 } |
1797 | 1797 |
1798 return TRUE; | 1798 return TRUE; |
1800 | 1800 |
1801 | 1801 |
1802 BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) | 1802 BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) |
1803 { | 1803 { |
1804 (void) editBuf; | 1804 (void) editBuf; |
1805 | 1805 |
1806 switch (c) | 1806 switch (c) |
1807 { | 1807 { |
1808 case KEY_ENTER: | 1808 case KEY_ENTER: |
1809 editState->done = TRUE; | 1809 editState->done = TRUE; |
1810 break; | 1810 break; |
1811 | 1811 |
1812 case KEY_F(9): // F9 = Quit | 1812 case KEY_F(9): // F9 = Quit |
1813 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); | 1813 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); |
1814 appQuitFlag = TRUE; | 1814 appQuitFlag = TRUE; |
1815 break; | 1815 break; |
1816 | 1816 |
1817 default: | 1817 default: |
1818 return FALSE; | 1818 return FALSE; |
1819 } | 1819 } |
1820 | 1820 |
1821 return TRUE; | 1821 return TRUE; |
1872 else | 1872 else |
1873 { | 1873 { |
1874 // PRV chat log | 1874 // PRV chat log |
1875 size_t pos; | 1875 size_t pos; |
1876 char *cleaned; | 1876 char *cleaned; |
1877 | 1877 |
1878 if ((cleaned = th_strdup(win->id)) == NULL) | 1878 if ((cleaned = th_strdup(win->id)) == NULL) |
1879 return FALSE; | 1879 return FALSE; |
1880 | 1880 |
1881 for (pos = 0; cleaned[pos] != 0; pos++) | 1881 for (pos = 0; cleaned[pos] != 0; pos++) |
1882 { | 1882 { |
1887 win->logFilename = th_strdup_printf("%s%s%s", | 1887 win->logFilename = th_strdup_printf("%s%s%s", |
1888 path != NULL ? path : "", cleaned, optLogExtension); | 1888 path != NULL ? path : "", cleaned, optLogExtension); |
1889 | 1889 |
1890 th_free(cleaned); | 1890 th_free(cleaned); |
1891 } | 1891 } |
1892 | 1892 |
1893 // Try to open the file for appending | 1893 // Try to open the file for appending |
1894 if (win->logFilename == NULL) | 1894 if (win->logFilename == NULL) |
1895 goto error; | 1895 goto error; |
1896 | 1896 |
1897 #ifdef TH_PLAT_WINDOWS | 1897 #ifdef TH_PLAT_WINDOWS |
2198 if (conn == NULL) | 2198 if (conn == NULL) |
2199 { | 2199 { |
2200 errorMsg("Could not create connection structure.\n"); | 2200 errorMsg("Could not create connection structure.\n"); |
2201 goto err_exit; | 2201 goto err_exit; |
2202 } | 2202 } |
2203 | 2203 |
2204 editState.conn = conn; | 2204 editState.conn = conn; |
2205 | 2205 |
2206 // Are we using a proxy? | 2206 // Are we using a proxy? |
2207 if (optProxyEnable && optProxyType != TH_PROXY_NONE && optProxyServer != NULL) | 2207 if (optProxyEnable && optProxyType != TH_PROXY_NONE && optProxyServer != NULL) |
2208 { | 2208 { |
2263 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); | 2263 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
2264 th_free(tmpStr); | 2264 th_free(tmpStr); |
2265 | 2265 |
2266 // Initialize user commands | 2266 // Initialize user commands |
2267 nn_usercmd_init(); | 2267 nn_usercmd_init(); |
2268 | 2268 |
2269 // Initialize random numbers | 2269 // Initialize random numbers |
2270 editState.prevKeepAlive = time(NULL); | 2270 editState.prevKeepAlive = time(NULL); |
2271 srand((int) editState.prevKeepAlive); | 2271 srand((int) editState.prevKeepAlive); |
2272 | 2272 |
2273 // Enter mainloop | 2273 // Enter mainloop |
2333 if (!colorSet) | 2333 if (!colorSet) |
2334 { | 2334 { |
2335 colorSet = TRUE; | 2335 colorSet = TRUE; |
2336 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 2336 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
2337 } | 2337 } |
2338 | 2338 |
2339 if (appCursesInit && !flushed) | 2339 if (appCursesInit && !flushed) |
2340 { | 2340 { |
2341 nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor); | 2341 nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor); |
2342 } | 2342 } |
2343 | 2343 |