From: Nathan W. <fac...@us...> - 2003-11-19 05:34:54
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1:/tmp/cvs-serv27710/src Modified Files: gtkconv.c log.c util.c util.h Log Message: /me-ify logs, and maybe fix the random directories problem. maybe. Index: gtkconv.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkconv.c,v retrieving revision 1.232 retrieving revision 1.233 diff -u -d -p -r1.232 -r1.233 --- gtkconv.c 18 Nov 2003 23:24:05 -0000 1.232 +++ gtkconv.c 19 Nov 2003 05:34:50 -0000 1.233 @@ -2896,44 +2896,6 @@ tab_complete(GaimConversation *conv) g_free(partial); } -static gboolean -meify(char *message, size_t len) -{ - /* - * Read /me-ify: If the message (post-HTML) starts with /me, - * remove the "/me " part of it (including that space) and return TRUE. - */ - char *c; - gboolean inside_html = 0; - - /* Umm.. this would be very bad if this happens. */ - g_return_val_if_fail(message != NULL, FALSE); - - if (len == -1) - len = strlen(message); - - for (c = message; *c != '\0'; c++, len--) { - if (inside_html) { - if (*c == '>') - inside_html = FALSE; - } - else { - if (*c == '<') - inside_html = TRUE; - else - break; - } - } - - if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { - memmove(c, c + 4, len - 3); - - return TRUE; - } - - return FALSE; -} - static void save_convo(GtkWidget *save, GaimConversation *c) { @@ -4610,7 +4572,7 @@ gaim_gtkconv_write_conv(GaimConversation str = g_malloc(1024); /* If we're whispering, it's not an autoresponse. */ - if (meify(new_message, length)) { + if (gaim_message_meify(new_message, length)) { g_snprintf(str, 1024, "***%s", who); strcpy(color, "#6C2585"); } @@ -4620,7 +4582,7 @@ gaim_gtkconv_write_conv(GaimConversation } } else { - if (meify(new_message, length)) { + if (gaim_message_meify(new_message, length)) { str = g_malloc(1024); if (flags & GAIM_MESSAGE_AUTO_RESP) Index: log.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/log.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -p -r1.61 -r1.62 --- log.c 18 Nov 2003 06:26:01 -0000 1.61 +++ log.c 19 Nov 2003 05:34:50 -0000 1.62 @@ -358,17 +358,13 @@ static void xml_logger_write(GaimLog *lo char *filename = g_build_filename(dir, date, NULL); g_free(dir); - file = fopen(dir, "r"); - if(!file) - mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); - else - fclose(file); - log->logger_data = fopen(filename, "a"); if (!log->logger_data) { gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); + g_free(filename); return; } + g_free(filename); fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); @@ -437,7 +433,6 @@ static void html_logger_write(GaimLog *l (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); char *dir; char *filename; - FILE *file; if (log->type == GAIM_LOG_CHAT) { chat = g_strdup_printf("%s.chat", guy); @@ -466,15 +461,10 @@ static void html_logger_write(GaimLog *l filename = g_build_filename(dir, date, NULL); g_free(dir); - file = fopen(dir, "r"); - if(!file) - mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); - else - fclose(file); - log->logger_data = fopen(filename, "a"); if (!log->logger_data) { gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); + g_free(filename); return; } g_free(filename); @@ -498,12 +488,25 @@ static void html_logger_write(GaimLog *l fprintf(log->logger_data, _("<font color=\"#16569E\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); else if (type & GAIM_MESSAGE_RECV) fprintf(log->logger_data, _("<font color=\"#A82F2F\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); - } else if (type & GAIM_MESSAGE_RECV) - fprintf(log->logger_data, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", - date, from, gc->prpl->info->name, message); - else if (type & GAIM_MESSAGE_SEND) - fprintf(log->logger_data, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", - date, from, gc->prpl->info->name, message); + } else if (type & GAIM_MESSAGE_RECV) { + char *msg = g_strdup(message); + if(gaim_message_meify(msg, -1)) + fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", + date, from, gc->prpl->info->name, msg); + else + fprintf(log->logger_data, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", + date, from, gc->prpl->info->name, msg); + g_free(msg); + } else if (type & GAIM_MESSAGE_SEND) { + char *msg = g_strdup(message); + if(gaim_message_meify(msg, -1)) + fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", + date, from, gc->prpl->info->name, msg); + else + fprintf(log->logger_data, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", + date, from, gc->prpl->info->name, msg); + g_free(msg); + } fflush(log->logger_data); } @@ -573,7 +576,6 @@ static void txt_logger_write(GaimLog *lo const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); char *dir; - FILE *file; if (log->type == GAIM_LOG_CHAT) { chat = g_strdup_printf("%s.chat", guy); @@ -601,15 +603,10 @@ static void txt_logger_write(GaimLog *lo filename = g_build_filename(dir, date, NULL); g_free(dir); - file = fopen(dir, "r"); - if(!file) - mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); - else - fclose(file); - log->logger_data = fopen(filename, "a"); if (!log->logger_data) { gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); + g_free(filename); return; } g_free(filename); @@ -622,11 +619,17 @@ static void txt_logger_write(GaimLog *lo stripped = gaim_markup_strip_html(message); if (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV) { - if (type & GAIM_MESSAGE_AUTO_RESP) + if (type & GAIM_MESSAGE_AUTO_RESP) { fprintf(log->logger_data, _("(%s) %s <AUTO-REPLY>: %s\n"), date, from, stripped); - else - fprintf(log->logger_data, "(%s) %s: %s\n", date, from, stripped); - } else if (type & GAIM_MESSAGE_SYSTEM) + } else { + if(gaim_message_meify(stripped, -1)) + fprintf(log->logger_data, "(%s) ***%s %s\n", date, from, + stripped); + else + fprintf(log->logger_data, "(%s) %s: %s\n", date, from, + stripped); + } + } else if (type & GAIM_MESSAGE_SYSTEM) fprintf(log->logger_data, "(%s) %s\n", date, stripped); else if (type & GAIM_MESSAGE_NO_LOG) { /* This shouldn't happen */ Index: util.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.c,v retrieving revision 1.235 retrieving revision 1.236 diff -u -d -p -r1.235 -r1.236 --- util.c 11 Nov 2003 20:33:58 -0000 1.235 +++ util.c 19 Nov 2003 05:34:50 -0000 1.236 @@ -2101,3 +2101,33 @@ gaim_utf8_strcasecmp(const char *a, cons return ret; } +gboolean gaim_message_meify(char *message, size_t len) +{ + char *c; + gboolean inside_html = FALSE; + + g_return_val_if_fail(message != NULL, FALSE); + + if(len == -1) + len = strlen(message); + + for (c = message; *c; c++, len--) { + if(inside_html) { + if(*c == '>') + inside_html = FALSE; + } else { + if(*c == '<') + inside_html = TRUE; + else + break; + } + } + + if(*c && !g_ascii_strncasecmp(c, "/me ", 4)) { + memmove(c, c+4, len-3); + return TRUE; + } + + return FALSE; +} + Index: util.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -p -r1.30 -r1.31 --- util.h 11 Nov 2003 20:33:58 -0000 1.30 +++ util.h 19 Nov 2003 05:34:50 -0000 1.31 @@ -507,6 +507,16 @@ char *gaim_utf8_try_convert(const char * */ int gaim_utf8_strcasecmp(const char *a, const char *b); +/** + * Checks for messages starting with "/me " + * + * @param message The message to check + * @param len The message length, or -1 + * + * @return TRUE if it starts with /me, and it has been removed, otherwise FALSE + */ +gboolean gaim_message_meify(char *message, size_t len); + /*@}*/ #ifdef __cplusplus |