comparison pidgin-twitter.c @ 48:42869098eda3

adapted for msn style option (or new line plugin).
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Tue, 13 May 2008 21:25:47 +0900
parents e4f8e5708afd
children 82b2b3767311
comparison
equal deleted inserted replaced
47:6774859df10b 48:42869098eda3
53 #define OPT_COUNTER OPT_PIDGINTWITTER "/counter" 53 #define OPT_COUNTER OPT_PIDGINTWITTER "/counter"
54 #define OPT_SUPPRESS_OOPS OPT_PIDGINTWITTER "/suppress_oops" 54 #define OPT_SUPPRESS_OOPS OPT_PIDGINTWITTER "/suppress_oops"
55 55
56 /* formats and templates */ 56 /* formats and templates */
57 #define RECIPIENT_FORMAT "@<a href='http://twitter.com/%s'>%s</a>" 57 #define RECIPIENT_FORMAT "@<a href='http://twitter.com/%s'>%s</a>"
58 #define SENDER_FORMAT "<a href='http://twitter.com/%s'>%s</a>: " 58 #define SENDER_FORMAT "%s<a href='http://twitter.com/%s'>%s</a>: "
59 #define DEFAULT_LIST "(list of users: separated with ' ,:;')" 59 #define DEFAULT_LIST "(list of users: separated with ' ,:;')"
60 #define OOPS_MESSAGE "<body>Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).<BR></body>" 60 #define OOPS_MESSAGE "<body>Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).<BR></body>"
61 61
62 /* patterns */ 62 /* patterns */
63 #define P_RECIPIENT "@([A-Za-z0-9_]+)" 63 #define P_RECIPIENT "@([A-Za-z0-9_]+)"
64 #define P_SENDER "^([A-Za-z0-9_]+): " 64 #define P_SENDER "^(\\r?\\n?)([A-Za-z0-9_]+): "
65 #define P_COMMAND "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)" 65 #define P_COMMAND "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)"
66 #define P_PSEUDO "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)" 66 #define P_PSEUDO "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)"
67 67
68 /* debug macros */ 68 /* debug macros */
69 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); 69 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__);
343 } 343 }
344 344
345 static gboolean 345 static gboolean
346 eval(const GMatchInfo *match_info, GString *result, gpointer user_data) 346 eval(const GMatchInfo *match_info, GString *result, gpointer user_data)
347 { 347 {
348 int which = *(int *)user_data;
348 gchar sub[128]; 349 gchar sub[128];
349 gchar *match = g_match_info_fetch(match_info, 1); 350
350 351 if(which == RECIPIENT) {
351 int which = *(int *)user_data; 352 gchar *match = g_match_info_fetch(match_info, 1);
352 353
353 snprintf(sub, 128, which ? SENDER_FORMAT : RECIPIENT_FORMAT, 354 snprintf(sub, 128, RECIPIENT_FORMAT, match, match);
354 match, match); 355 g_free(match);
356 }
357 else if(which == SENDER) {
358 gchar *match1 = g_match_info_fetch(match_info, 1); //preceding CR|LF
359 gchar *match2 = g_match_info_fetch(match_info, 2); //sender
360
361 snprintf(sub, 128, SENDER_FORMAT, match1 ? match1: "",
362 match2, match2);
363 g_free(match1);
364 g_free(match2);
365 }
366
367 g_string_append(result, sub);
355 twitter_debug("sub = %s\n", sub); 368 twitter_debug("sub = %s\n", sub);
356 g_string_append(result, sub);
357 g_free(match);
358 369
359 return FALSE; 370 return FALSE;
360 } 371 }
361 372
362 static void 373 static void