[ekg2-commit] r4108 - in trunk: ekg plugins/gg plugins/logs plugins/ncurses: trunk/ekg/themes.c trunk/ekg/themes.h trunk/plugins/gg/commands.c trunk/plugins/logs/main.c trunk/plugins/ncurses/contacts.c trunk/plugins/ncurses/old.c
SVN commit
svn w toxygen.net
Wto, 15 Lip 2008, 21:31:27 CEST
Author: darkjames
Date: 2008-07-15 21:31:26 +0200 (Tue, 15 Jul 2008)
New Revision: 4108
Modified:
trunk/ekg/themes.c
trunk/ekg/themes.h
trunk/plugins/gg/commands.c
trunk/plugins/logs/main.c
trunk/plugins/ncurses/contacts.c
trunk/plugins/ncurses/old.c
Log:
- new fstring_new_format() [format_string() + fstring_new() ]
- simplify code in ncurses && logs.
Modified: trunk/ekg/themes.c
===================================================================
--- trunk/ekg/themes.c 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/ekg/themes.c 2008-07-15 19:31:26 UTC (rev 4108)
@@ -654,6 +654,28 @@
}
/**
+ * fstring_new_format()
+ *
+ * char *tmp = format_string("format", .....);
+ * fstr = fstring_new(tmp);
+ * xfree(tmp);
+ */
+
+fstring_t *fstring_new_format(const char *format, ...) {
+ fstring_t *fstr;
+ va_list ap;
+ char *tmp;
+
+ va_start(ap, format);
+ tmp = va_format_string(format, ap);
+
+ fstr = fstring_new(tmp);
+
+ xfree(tmp);
+ return fstr;
+}
+
+/**
* fstring_free()
*
* Free memory allocated by @a str
Modified: trunk/ekg/themes.h
===================================================================
--- trunk/ekg/themes.h 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/ekg/themes.h 2008-07-15 19:31:26 UTC (rev 4108)
@@ -66,6 +66,7 @@
void theme_free();
fstring_t *fstring_new(const char *str);
+fstring_t *fstring_new_format(const char *format, ...);
void fstring_free(fstring_t *str);
#endif
Modified: trunk/plugins/gg/commands.c
===================================================================
--- trunk/plugins/gg/commands.c 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/plugins/gg/commands.c 2008-07-15 19:31:26 UTC (rev 4108)
@@ -623,7 +623,7 @@
msg = (unsigned char *) xstrmid(params[1], 0, 1989);
ekg_format = ekg_sent_message_format((char *) msg);
- /* analiz�tekstu zrobimy w osobnym bloku dla porzdku */
+ /* analize tekstu zrobimy w osobnym bloku dla porzdku */
{
unsigned char attr = 0, last_attr = 0;
const unsigned char *p = msg, *end = p + xstrlen((char *) p);
Modified: trunk/plugins/logs/main.c
===================================================================
--- trunk/plugins/logs/main.c 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/plugins/logs/main.c 2008-07-15 19:31:26 UTC (rev 4108)
@@ -453,7 +453,6 @@
static int logs_print_window(session_t *s, window_t *w, const char *line, time_t ts) {
static plugin_t *ui_plugin = NULL;
- char *fline;
fstring_t *fstr;
/* it's enough to look for ui_plugin once */
@@ -464,14 +463,10 @@
return -1;
}
- fline = format_string(line); /* format string */
- fstr = fstring_new(fline); /* create fstring */
+ fstr = fstring_new_format(line);
+ fstr->ts = ts;
- fstr->ts = ts; /* sync timestamp */
-
- query_emit_id(ui_plugin, UI_WINDOW_PRINT, &w, &fstr); /* let's rock */
-
- xfree(fline); /* cleanup */
+ query_emit_id(ui_plugin, UI_WINDOW_PRINT, &w, &fstr);
return 0;
}
Modified: trunk/plugins/ncurses/contacts.c
===================================================================
--- trunk/plugins/ncurses/contacts.c 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/plugins/ncurses/contacts.c 2008-07-15 19:31:26 UTC (rev 4108)
@@ -212,11 +212,8 @@
footer = format_find("contacts_footer");
}
- if (xstrcmp(header, "")) {
- char *tmp = format_string(header, group);
- ncurses_backlog_add(w, fstring_new(tmp));
- xfree(tmp);
- }
+ if (xstrcmp(header, ""))
+ ncurses_backlog_add(w, fstring_new_format(header, group));
if (all == 1) {
userlist_t *l;
@@ -309,8 +306,6 @@
for (j = 0; j < corderlen; /* xstrlen(contacts_order); */ j += 2) {
const char *footer_status = NULL;
int count = 0;
- fstring_t *string;
- char *line;
char tmp[100];
userlist_t *ul;
@@ -319,6 +314,7 @@
const char *status_t;
const char *format;
+ fstring_t *string;
if (!u->nickname || !u->status)
continue;
@@ -341,12 +337,8 @@
if (!count) {
snprintf(tmp, sizeof(tmp), "contacts_%s_header", status_t);
format = format_find(tmp);
- if (xstrcmp(format, "")) {
- line = format_string(format);
- string = fstring_new(line);
- ncurses_backlog_add(w, string);
- xfree(line);
- }
+ if (xstrcmp(format, ""))
+ ncurses_backlog_add(w, fstring_new_format(format));
footer_status = status_t;
}
@@ -362,8 +354,7 @@
if (u->typing)
xstrcat(tmp, "_typing");
- line = format_string(format_find(tmp), u->nickname, u->descr);
- string = fstring_new(line);
+ string = fstring_new_format(format_find(tmp), u->nickname, u->descr);
if (u->private == (void *) 2)
string->private = (void *) xstrdup(u->nickname);
@@ -371,7 +362,6 @@
string->private = (void *) saprintf("%s/%s", (u->private) ? ((session_t *) u->private)->uid : session_current->uid, u->nickname);
ncurses_backlog_add(w, string);
- xfree(line);
count++;
}
@@ -382,12 +372,8 @@
snprintf(tmp, sizeof(tmp), "contacts_%s_footer", footer_status);
format = format_find(tmp);
- if (xstrcmp(format, "")) {
- line = format_string(format);
- string = fstring_new(line);
- ncurses_backlog_add(w, string);
- xfree(line);
- }
+ if (xstrcmp(format, ""))
+ ncurses_backlog_add(w, fstring_new_format(format));
}
if (!config_contacts_orderbystate)
@@ -395,12 +381,8 @@
}
after_loop:
- if (xstrcmp(footer, "")) {
- char *tmp = format_string(footer, group);
- ncurses_backlog_add(w, fstring_new(tmp));
- xfree(tmp);
- }
-
+ if (xstrcmp(footer, ""))
+ ncurses_backlog_add(w, fstring_new_format(footer, group));
if (all)
LIST_DESTROY2(sorted_all, NULL);
Modified: trunk/plugins/ncurses/old.c
===================================================================
--- trunk/plugins/ncurses/old.c 2008-07-14 21:16:49 UTC (rev 4107)
+++ trunk/plugins/ncurses/old.c 2008-07-15 19:31:26 UTC (rev 4108)
@@ -2743,11 +2743,8 @@
if (!w || !(n = w->private))
return items;
- if (config_lastlog_noitems) { /* always add header */
- char *tmp = format_string(header, window_target(w), lastlog->expression);
- ncurses_backlog_add(lastlog_w, fstring_new(tmp));
- xfree(tmp);
- }
+ if (config_lastlog_noitems) /* always add header */
+ ncurses_backlog_add(lastlog_w, fstring_new_format(header, window_target(w), lastlog->expression));
local_config_lastlog_case = (lastlog->casense == -1) ? config_lastlog_case : lastlog->casense;
@@ -2776,12 +2773,9 @@
else found = !!xstrcasestr((char *) n->backlog[i]->str.w, lastlog->expression);
}
- if (!config_lastlog_noitems && found && !items) { /* add header only when found */
- char *tmp = format_string(header, window_target(w), lastlog->expression);
- ncurses_backlog_add(lastlog_w, fstring_new(tmp));
- xfree(tmp);
- }
-
+ if (!config_lastlog_noitems && found && !items) /* add header only when found */
+ ncurses_backlog_add(lastlog_w, fstring_new_format(header, window_target(w), lastlog->expression));
+
if (found) {
fstring_t *dup;
size_t len;
Więcej informacji o liście dyskusyjnej ekg2-commit