comparison libpurple/protocols/myspace/myspace.c @ 18893:cd90423c0a88

Use an array of structs instead of parallel arrays for the emoticon name<=>symbol data structure, for (much better) clarity.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 11 Aug 2007 04:54:13 +0000
parents 138e9be2f917
children daedc9647341
comparison
equal deleted inserted replaced
18892:138e9be2f917 18893:cd90423c0a88
41 /* Loosely based on Miranda plugin by Scott Ellis, formatting.cpp, 41 /* Loosely based on Miranda plugin by Scott Ellis, formatting.cpp,
42 * https://server.scottellis.com.au/websvn/filedetails.php?repname=Miranda+Plugins&path=%2FMySpace%2Fformatting.cpp&rev=0&sc=0 */ 42 * https://server.scottellis.com.au/websvn/filedetails.php?repname=Miranda+Plugins&path=%2FMySpace%2Fformatting.cpp&rev=0&sc=0 */
43 43
44 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding 44 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding
45 * entries in emoticon_symbols (for the ASCII representation of the emoticon). 45 * entries in emoticon_symbols (for the ASCII representation of the emoticon).
46 */ 46 *
47 static const char *emoticon_names[] = { 47 * Multiple emoticon symbols in Pidgin can map to one name. List the
48 "bigsmile", "growl", "growl", "mad", "scared", "scared", "tongue", "tongue",
49 "devil", "devil", "happy", "happy", "happi",
50 "messed", "sidefrown", "upset",
51 "frazzled", "heart", "heart", "nerd", "sinister", "wink", "winc",
52 "geek", "laugh", "laugh", "oops", "smirk", "worried", "worried",
53 "googles", "mohawk", "pirate", "straight", "kiss",
54 NULL};
55
56 /* Multiple emoticon symbols in Pidgin can map to one name. List the
57 * canonical form, as inserted by the "Smile!" dialog, first. For example, 48 * canonical form, as inserted by the "Smile!" dialog, first. For example,
58 * :) comes before :-), because although both are recognized as 'happy', 49 * :) comes before :-), because although both are recognized as 'happy',
59 * the first is inserted by the smiley button. 50 * the first is inserted by the smiley button.
60 * 51 *
61 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */ 52 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */
62 static const char *emoticon_symbols[] = { 53
63 ":D", ">:o", ">:O", ":-[", "=-O", "=-o", ":P", ":p", 54 /* TODO: Use extra smileys not in default theme! Hylke is also working on
64 "O:-)", "o:-)", ":)", ":-)", ":-)", 55 * some new smileys specific to MySpaceIM, use them too! */
65 "8-)", ":-$", ":-$", 56 static struct MSIM_EMOTICON
66 ":-/", ";-)", ";)", "8-)" /*:)*/, ":-D", ";-)", ";-)", 57 {
67 ":-X", ":-D", ":-d", ":'(", "8-)", ":-(", ":(", 58 gchar *name;
68 "8-)", ":-X", ":-)", ":-!", ":-*", 59 gchar *symbol;
69 NULL}; 60 } msim_emoticons[] = {
70 61 { "bigsmile", ":D" },
62 { "growl", ">:o" },
63 { "growl", ">:O" },
64 { "mad", ":-[" },
65 { "scared", "=-O" },
66 { "scared", "=-o" },
67 { "tongue", ":P" },
68 { "tongue", ":p" },
69 { "devil", "O:-)" },
70 { "devil", "o:-)" },
71 { "happy", ":)" },
72 { "happy", ":-)" },
73 { "happi", ":-)" },
74 { "messed", "8-)" },
75 { "sidefrown", ":-$" } ,
76 { "upset", ":-$" },
77 { "frazzled", ":-/" } ,
78 { "heart", ";-)" },
79 { "heart", ";)" },
80 { "nerd", "8-)"},
81 { "sinister", ":-,D" } ,
82 { "wink", ";-)" },
83 { "winc", ";-)" },
84 { "geek", ":-X" },
85 { "laugh", ":-D" },
86 { "laugh", ":-d" },
87 { "oops", ":'(" },
88 { "smirk", "8-)" },
89 { "worried", ":-(" } ,
90 { "worried", ":(" },
91 { "googles", "8-)" },
92 { "mohawk", ":-X" },
93 { "pirate", ":-)" },
94 { "straight", ":-!" },
95 { "kiss", ":-*" },
96 { NULL, NULL }
97 };
71 98
72 /* Internal functions */ 99 /* Internal functions */
73 static void msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr); 100 static void msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr);
74 101
75 #ifdef MSIM_DEBUG_MSG 102 #ifdef MSIM_DEBUG_MSG
1051 static void 1078 static void
1052 msim_markup_i_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end) 1079 msim_markup_i_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
1053 { 1080 {
1054 const gchar *name; 1081 const gchar *name;
1055 guint i; 1082 guint i;
1083 struct MSIM_EMOTICON *emote;
1056 1084
1057 name = xmlnode_get_attrib(root, "n"); 1085 name = xmlnode_get_attrib(root, "n");
1058 if (!name) { 1086 if (!name) {
1059 purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n"); 1087 purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n");
1060 *begin = g_strdup(""); 1088 *begin = g_strdup("");
1061 *end = g_strdup(""); 1089 *end = g_strdup("");
1062 /* TODO: log as unrecognized */ 1090 /* TODO: log as unrecognized */
1063 return; 1091 return;
1064 } 1092 }
1065 1093
1066 for (i = 0; emoticon_names[i] != NULL; ++i) { 1094 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
1067 if (!strcmp(name, emoticon_names[i])) { 1095 gchar *name;
1068 *begin = g_strdup(emoticon_symbols[i]); 1096 gchar *symbol;
1097
1098 name = emote->name;
1099 symbol = emote->symbol;
1100
1101 if (!strcmp(name, name)) {
1102 *begin = g_strdup(symbol);
1069 *end = g_strdup(""); 1103 *end = g_strdup("");
1070 return; 1104 return;
1071 } 1105 }
1072 } 1106 }
1073 1107
1270 static gchar * 1304 static gchar *
1271 msim_convert_smileys_to_markup(gchar *before) 1305 msim_convert_smileys_to_markup(gchar *before)
1272 { 1306 {
1273 gchar *old, *new, *replacement; 1307 gchar *old, *new, *replacement;
1274 guint i; 1308 guint i;
1309 struct MSIM_EMOTICON *emote;
1275 1310
1276 old = before; 1311 old = before;
1277 new = NULL; 1312 new = NULL;
1278 1313
1279 for (i = 0; emoticon_symbols[i] != NULL; ++i) { 1314 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
1280 replacement = g_strdup_printf("<i n=\"%s\"/>", emoticon_names[i]); 1315 gchar *name, *symbol;
1316
1317 name = emote->name;
1318 symbol = emote->symbol;
1319
1320 replacement = g_strdup_printf("<i n=\"%s\"/>", name);
1281 1321
1282 purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n", 1322 purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n",
1283 emoticon_symbols[i] ? emoticon_symbols[i] : "(NULL)", 1323 symbol ? symbol : "(NULL)",
1284 replacement ? replacement : "(NULL)"); 1324 replacement ? replacement : "(NULL)");
1285 new = str_replace(old, emoticon_symbols[i], replacement); 1325 new = str_replace(old, symbol, replacement);
1286 1326
1287 g_free(replacement); 1327 g_free(replacement);
1288 g_free(old); 1328 g_free(old);
1289 1329
1290 old = new; 1330 old = new;