comparison src/log.c @ 7761:946120d41b77

[gaim-migrate @ 8406] This doesn't solve the slowdown, but if nothing else 150,000 allocations are better than 177,000, right? committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Fri, 05 Dec 2003 16:08:33 +0000
parents 68e205e746c9
children 88886239f31e
comparison
equal deleted inserted replaced
7760:7c4fbd9f1aed 7761:946120d41b77
704 static GList *old_logger_list(const char *sn, GaimAccount *account) 704 static GList *old_logger_list(const char *sn, GaimAccount *account)
705 { 705 {
706 FILE *file; 706 FILE *file;
707 char buf[BUF_LONG]; 707 char buf[BUF_LONG];
708 struct tm tm; 708 struct tm tm;
709 char month[4];
709 struct old_logger_data *data = NULL; 710 struct old_logger_data *data = NULL;
710 char month[4];
711 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); 711 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn));
712 char *path = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); 712 char *path = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
713 char *newlog; 713 char *newlog;
714 int logfound = 0;
715 int lastoff = 0;
716 int newlen;
717 time_t lasttime;
714 718
715 GaimLog *log = NULL; 719 GaimLog *log = NULL;
716 GList *list = NULL; 720 GList *list = NULL;
717 721
718 g_free(logfile); 722 g_free(logfile);
736 length = strcspn(temp, "-"); 740 length = strcspn(temp, "-");
737 if (length > 31) length = 31; 741 if (length > 31) length = 31;
738 742
739 offset = ftell(file); 743 offset = ftell(file);
740 744
741 if (data) { 745 if (logfound) {
742 data->length = offset - data->offset - length; 746 newlen = offset - lastoff - length;
743 if(strstr(buf, "----</H3><BR>")) { 747 if(strstr(buf, "----</H3><BR>")) {
744 data->length -= 748 newlen -=
745 strlen("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + 749 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") +
746 strlen("----</H3><BR>"); 750 sizeof("----</H3><BR>") - 2;
747 } else { 751 } else {
748 data->length -= 752 newlen -=
749 strlen("---- New Conversation @ ") + strlen("----"); 753 sizeof("---- New Conversation @ ") + sizeof("----") - 2;
750 } 754 }
751 755
752 if(strchr(buf, '\r')) 756 if(strchr(buf, '\r'))
753 data->length--; 757 data->length--;
754 758
755 if (data->length != 0) 759 if (newlen != 0) {
760 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
761 log->logger = &old_logger;
762 log->time = lasttime;
763 data = g_new0(struct old_logger_data, 1);
764 data->offset = lastoff;
765 data->length = newlen;
766 data->path = g_strdup(path);
767 log->logger_data = data;
756 list = g_list_append(list, log); 768 list = g_list_append(list, log);
757 else 769 }
758 gaim_log_free(log);
759 } 770 }
760 771
761 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); 772 logfound = 1;
762 log->logger = &old_logger; 773 lastoff = offset;
763
764 data = g_new0(struct old_logger_data, 1);
765 data->offset = offset;
766 data->path = g_strdup(path);
767 log->logger_data = data;
768
769 774
770 g_snprintf(convostart, length, "%s", temp); 775 g_snprintf(convostart, length, "%s", temp);
771 sscanf(convostart, "%*s %s %d %d:%d:%d %d", 776 sscanf(convostart, "%*s %s %d %d:%d:%d %d",
772 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); 777 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year);
773 /* Ugly hack, in case current locale is not English */ 778 /* Ugly hack, in case current locale is not English */
795 tm.tm_mon = 10; 800 tm.tm_mon = 10;
796 } else if (strcmp(month, "Dec") == 0) { 801 } else if (strcmp(month, "Dec") == 0) {
797 tm.tm_mon = 11; 802 tm.tm_mon = 11;
798 } 803 }
799 tm.tm_year -= 1900; 804 tm.tm_year -= 1900;
800 log->time = mktime(&tm); 805 lasttime = mktime(&tm);
801 } 806 }
802 } 807 }
803 808
804 if (data) { 809 if (logfound) {
805 data->length = ftell(file) - data->offset; 810 if ((newlen = ftell(file) - lastoff) != 0) {
806 if (data->length != 0) 811 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
812 log->logger = &old_logger;
813 log->time = lasttime;
814 data = g_new0(struct old_logger_data, 1);
815 data->offset = lastoff;
816 data->length = newlen;
817 data->path = g_strdup(path);
818 log->logger_data = data;
807 list = g_list_append(list, log); 819 list = g_list_append(list, log);
808 else 820 }
809 gaim_log_free(log);
810 } 821 }
811 822
812 g_free(path); 823 g_free(path);
813 fclose(file); 824 fclose(file);
814 return list; 825 return list;