Mercurial > hg > nnchat
comparison nnchat.c @ 398:c345a8efb1d4
Rename another function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 May 2012 05:00:32 +0300 |
parents | 932829a556c7 |
children | 06a1c1db5bbb |
comparison
equal
deleted
inserted
replaced
397:932829a556c7 | 398:c345a8efb1d4 |
---|---|
219 return FALSE; | 219 return FALSE; |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 | 223 |
224 char * str_trim_left(char *buf) | |
225 { | |
226 while (*buf != 0 && th_isspace(*buf)) buf++; | |
227 return buf; | |
228 } | |
229 | |
230 int compareUsername(const void *s1, const void *s2) | |
231 { | |
232 return th_strcasecmp((char *) s1, (char *) s2); | |
233 } | |
234 | |
224 nn_window_t *findWindow(const char *id) | 235 nn_window_t *findWindow(const char *id) |
225 { | 236 { |
226 int i; | 237 int i; |
227 | 238 |
228 for (i = 0; i < SET_MAX_WINDOWS; i++) | 239 for (i = 0; i < SET_MAX_WINDOWS; i++) |
913 } | 924 } |
914 else if (!th_strncasecmp(buf, "/color ", 7)) | 925 else if (!th_strncasecmp(buf, "/color ", 7)) |
915 { | 926 { |
916 /* Change color */ | 927 /* Change color */ |
917 int tmpInt; | 928 int tmpInt; |
918 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) | 929 if ((tmpInt = th_get_hex_triplet(str_trim_left(buf + 7))) < 0) |
919 { | 930 { |
920 printMsgQ(currWin, "Invalid color value '%s'\n", buf+7); | 931 printMsgQ(currWin, "Invalid color value '%s'\n", buf+7); |
921 return 1; | 932 return 1; |
922 } | 933 } |
923 optUserColor = tmpInt; | 934 optUserColor = tmpInt; |
925 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 936 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
926 return 0; | 937 return 0; |
927 } | 938 } |
928 else if (!th_strncasecmp(buf, "/ignore", 7)) | 939 else if (!th_strncasecmp(buf, "/ignore", 7)) |
929 { | 940 { |
930 char *name = trimLeft(buf + 7); | 941 char *name = str_trim_left(buf + 7); |
931 if (strlen(name) > 0) | 942 if (strlen(name) > 0) |
932 { | 943 { |
933 /* Add or remove someone to/from ignore */ | 944 /* Add or remove someone to/from ignore */ |
934 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername); | 945 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername); |
935 if (user != NULL) | 946 if (user != NULL) |
964 } | 975 } |
965 return 0; | 976 return 0; |
966 } | 977 } |
967 else if (!th_strncasecmp(buf, "/query", 6)) | 978 else if (!th_strncasecmp(buf, "/query", 6)) |
968 { | 979 { |
969 char *name = trimLeft(buf + 6); | 980 char *name = str_trim_left(buf + 6); |
970 if (strlen(name) > 0) | 981 if (strlen(name) > 0) |
971 { | 982 { |
972 nn_user_t *user = nn_user_find(nnUsers, nn_username_encode(name)); | 983 nn_user_t *user = nn_user_find(nnUsers, nn_username_encode(name)); |
973 if (user != NULL) | 984 if (user != NULL) |
974 { | 985 { |
988 return 0; | 999 return 0; |
989 } | 1000 } |
990 else if (!th_strncasecmp(buf, "/win", 4)) | 1001 else if (!th_strncasecmp(buf, "/win", 4)) |
991 { | 1002 { |
992 /* Change color */ | 1003 /* Change color */ |
993 char *tmp = trimLeft(buf + 4); | 1004 char *tmp = str_trim_left(buf + 4); |
994 if (strlen(tmp) > 0) | 1005 if (strlen(tmp) > 0) |
995 { | 1006 { |
996 int val = atoi(tmp); | 1007 int val = atoi(tmp); |
997 if (val >= 1 && val < SET_MAX_WINDOWS) | 1008 if (val >= 1 && val < SET_MAX_WINDOWS) |
998 { | 1009 { |
1012 } | 1023 } |
1013 return 0; | 1024 return 0; |
1014 } | 1025 } |
1015 else if (!th_strncasecmp(buf, "/close", 6)) | 1026 else if (!th_strncasecmp(buf, "/close", 6)) |
1016 { | 1027 { |
1017 char *name = trimLeft(buf + 6); | 1028 char *name = str_trim_left(buf + 6); |
1018 if (strlen(name) > 0) | 1029 if (strlen(name) > 0) |
1019 { | 1030 { |
1020 nn_window_t *win = findWindow(name); | 1031 nn_window_t *win = findWindow(name); |
1021 if (win != NULL) | 1032 if (win != NULL) |
1022 { | 1033 { |
1056 return 0; | 1067 return 0; |
1057 } | 1068 } |
1058 else if (!th_strncasecmp(buf, "/w ", 3)) | 1069 else if (!th_strncasecmp(buf, "/w ", 3)) |
1059 { | 1070 { |
1060 /* Open given username's profile via firefox in a new tab */ | 1071 /* Open given username's profile via firefox in a new tab */ |
1061 char *name = trimLeft(buf + 3); | 1072 char *name = str_trim_left(buf + 3); |
1062 | 1073 |
1063 printMsg(currWin, "Opening profile for: '%s'\n", name); | 1074 printMsg(currWin, "Opening profile for: '%s'\n", name); |
1064 | 1075 |
1065 tmpStr = nn_encode_str1(name); | 1076 tmpStr = nn_encode_str1(name); |
1066 #ifdef __WIN32 | 1077 #ifdef __WIN32 |
1381 curs_set(curVis); | 1392 curs_set(curVis); |
1382 | 1393 |
1383 for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) | 1394 for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) |
1384 tmpBuf[pos] = 0; | 1395 tmpBuf[pos] = 0; |
1385 | 1396 |
1386 ptr = trimLeft(tmpBuf); | 1397 ptr = str_trim_left(tmpBuf); |
1387 | 1398 |
1388 if (allowEmpty || strlen(ptr) > 0) | 1399 if (allowEmpty || strlen(ptr) > 0) |
1389 return th_strdup(ptr); | 1400 return th_strdup(ptr); |
1390 else | 1401 else |
1391 return NULL; | 1402 return NULL; |