[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[giFTcurs-commits] giFTcurs/src format.c giftcurs.h list.c list.h ...
From: |
Christian Häggström |
Subject: |
[giFTcurs-commits] giFTcurs/src format.c giftcurs.h list.c list.h ... |
Date: |
Mon, 15 Sep 2003 17:28:20 -0400 |
CVSROOT: /cvsroot/giftcurs
Module name: giFTcurs
Branch:
Changes by: Christian Häggström <address@hidden> 03/09/15 17:28:20
Modified files:
src : format.c giftcurs.h list.c list.h ui_draw.c
ui_draw.h ui.c ui.h ui_main.c
Log message:
Use format string for stats data
Patches:
Index: giFTcurs/src/format.c
diff -u giFTcurs/src/format.c:1.67 giFTcurs/src/format.c:1.68
--- giFTcurs/src/format.c:1.67 Mon Sep 8 13:52:06 2003
+++ giFTcurs/src/format.c Mon Sep 15 17:28:17 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: format.c,v 1.67 2003/09/08 17:52:06 saturn Exp $
+ * $Id: format.c,v 1.68 2003/09/15 21:28:17 saturn Exp $
*/
#include "giftcurs.h"
@@ -343,7 +343,7 @@
case ATTR_NONE:
return 0;
}
- abort();
+ assert_not_reached();
}
static guint64 value_to_long(enum attr_type t, attr_value * v)
@@ -368,7 +368,7 @@
case ATTR_NONE:
return 0;
}
- abort();
+ assert_not_reached();
}
static const char *value_to_string(enum attr_type t, attr_value * v)
@@ -385,7 +385,7 @@
case ATTR_NONE:
return "";
}
- abort();
+ assert_not_reached();
}
static unsigned int attribute_int(char *attr, struct format_ctrl *k);
@@ -486,7 +486,7 @@
/* parse string backwards */
format_t pos = NULL, endif = NULL, pending = NULL, fixedpos = NULL;
int n = strlen(src);
- char buf[256];
+ char buf[9256];
char *bufp = buf + sizeof buf - 1;
int progress_on = 0;
int fixed_on = 0;
@@ -529,13 +529,20 @@
return NULL;
}
if (command[0] == '%') {
- int color = get_item_number(command + 1);
+ int color;
- if (color < 0) {
- DEBUG("No color named %s", command + 1);
- format_unref(pos);
- format_unref(fixedpos);
- return NULL;
+ if (!strcmp(command + 1, "prev")) {
+ /* pop a color from the stack */
+ color = -1;
+ } else {
+ color = get_item_number(command + 1);
+
+ if (color < 0) {
+ DEBUG("No color named %s", command + 1);
+ format_unref(pos);
+ format_unref(fixedpos);
+ return NULL;
+ }
}
if (progress_on) {
DEBUG("Colors not allowed inside
{progress}{endprogress}");
@@ -840,7 +847,8 @@
}
/* Fill str with the actual data. All rendering info is provided in k */
-static int format_produce(format_t n, struct format_ctrl *k, char *str, int
produced)
+static int format_produce(format_t n, struct format_ctrl *k, char *str, int
produced,
+ dynarray *color_stack)
{
char *progress_mark = NULL;
float progress_start = 0.0;
@@ -853,7 +861,7 @@
return k->total_len;
}
switch (n->type) {
- int i, width, valwidth;
+ int i, width, valwidth, color;
char mode;
char *s;
const char *string;
@@ -978,10 +986,22 @@
break;
case COLOR:
str[0] = '\v';
+ color = n->u.color.color;
+ if (color == -1) {
+ /* pop a color from the stack */
+ if (color_stack->num)
+ dynarray_pop(color_stack);
+ if (color_stack->num)
+ color =
GPOINTER_TO_INT(list_index(color_stack, color_stack->num - 1));
+ else
+ color = 0; /* quietly fallback to
{standard} */
+ } else {
+ dynarray_append(color_stack,
GINT_TO_POINTER(color));
+ }
if (n->u.color.bold)
- str[1] = 'A' + n->u.color.color;
+ str[1] = 'A' + color;
else
- str[1] = 'a' + n->u.color.color;
+ str[1] = 'a' + color;
str[2] = '\0';
break;
case SPACE:
@@ -992,7 +1012,7 @@
produced += width;
break;
case MAKRO:
- produced = format_produce(n->u.macro, k, str, produced);
+ produced = format_produce(n->u.macro, k, str, produced,
color_stack);
break;
case FIXED:
{
@@ -1023,6 +1043,7 @@
struct format_counters c;
char *str;
int slack;
+ dynarray color_stack = { 0 };
morot.getattr = getattr;
morot.udata = udata;
@@ -1046,7 +1067,8 @@
str[0] = '\0';
/* Fill the string with actual stuff */
- format_produce(format, &morot, str, 0);
+ format_produce(format, &morot, str, 0, &color_stack);
+ dynarray_removeall(&color_stack);
g_assert(maxlen + c.nonprint >= strlen(str));
Index: giFTcurs/src/giftcurs.h
diff -u giFTcurs/src/giftcurs.h:1.62 giFTcurs/src/giftcurs.h:1.63
--- giFTcurs/src/giftcurs.h:1.62 Mon Sep 8 13:52:06 2003
+++ giFTcurs/src/giftcurs.h Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: giftcurs.h,v 1.62 2003/09/08 17:52:06 saturn Exp $
+ * $Id: giftcurs.h,v 1.63 2003/09/15 21:28:19 saturn Exp $
*/
#ifndef _GIFTCURS_H
#define _GIFTCURS_H
@@ -27,6 +27,12 @@
# include <config.h>
#endif
+/* Turn off debugging if told so */
+#ifdef NDEBUG
+# define G_DISABLE_ASSERT
+# define G_DISABLE_CHECKS
+#endif
+
#define G_DISABLE_DEPRECATED
#include <glib.h>
@@ -84,5 +90,8 @@
#ifndef G_LIKELY
# define G_LIKELY(x) (x)
#endif
+
+/* Tell gcc this does not return */
+#define assert_not_reached() G_STMT_START{ g_assert_not_reached(); abort();
}G_STMT_END
#endif
Index: giFTcurs/src/list.c
diff -u giFTcurs/src/list.c:1.85 giFTcurs/src/list.c:1.86
--- giFTcurs/src/list.c:1.85 Fri Jul 25 20:47:40 2003
+++ giFTcurs/src/list.c Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: list.c,v 1.85 2003/07/26 00:47:40 weinholt Exp $
+ * $Id: list.c,v 1.86 2003/09/15 21:28:19 saturn Exp $
*/
#include "giftcurs.h"
@@ -38,6 +38,16 @@
list_resize(arry, 1 + arry->num * 2);
arry->entries[arry->num++] = (void *) item;
+}
+
+void *dynarray_pop(dynarray *arry)
+{
+ void *ret;
+
+ g_assert(arry->num > 0);
+ ret = arry->entries[arry->num - 1];
+ dynarray_remove_index_fast(arry, arry->num - 1);
+ return ret;
}
void dynarray_remove(dynarray *arry, const void *item)
Index: giFTcurs/src/list.h
diff -u giFTcurs/src/list.h:1.51 giFTcurs/src/list.h:1.52
--- giFTcurs/src/list.h:1.51 Tue Jul 22 20:26:25 2003
+++ giFTcurs/src/list.h Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: list.h,v 1.51 2003/07/23 00:26:25 weinholt Exp $
+ * $Id: list.h,v 1.52 2003/09/15 21:28:19 saturn Exp $
*/
#ifndef _LIST_H
#define _LIST_H
@@ -105,5 +105,6 @@
void dynarray_foreach(const dynarray *arry, LFunc func);
void dynarray_removeall(dynarray *arry);
int dynarray_find(const dynarray *arry, const void *item);
+void *dynarray_pop(dynarray *arry);
#endif
Index: giFTcurs/src/ui.c
diff -u giFTcurs/src/ui.c:1.112 giFTcurs/src/ui.c:1.113
--- giFTcurs/src/ui.c:1.112 Sat Aug 23 16:01:44 2003
+++ giFTcurs/src/ui.c Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui.c,v 1.112 2003/08/23 20:01:44 weinholt Exp $
+ * $Id: ui.c,v 1.113 2003/09/15 21:28:19 saturn Exp $
*/
#include "giftcurs.h"
@@ -39,7 +39,11 @@
static void ui_draw_buttonbar(void);
/* FIXME: This should be a private variable */
+#ifndef NDEBUG
int active_screen; /* 0-based, so that F3 is
screen 2 */
+#else
+static int active_screen;
+#endif
static int nr_screens = 0;
gboolean show_buttonbar = 0;
Index: giFTcurs/src/ui.h
diff -u giFTcurs/src/ui.h:1.43 giFTcurs/src/ui.h:1.44
--- giFTcurs/src/ui.h:1.43 Fri Jul 25 20:47:40 2003
+++ giFTcurs/src/ui.h Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui.h,v 1.43 2003/07/26 00:47:40 weinholt Exp $
+ * $Id: ui.h,v 1.44 2003/09/15 21:28:19 saturn Exp $
*/
#ifndef _UI_H
#define _UI_H
@@ -39,7 +39,10 @@
} ui_methods;
extern gboolean show_buttonbar;
+
+#ifndef NDEBUG
extern int active_screen; /* only for debugging! */
+#endif
void ui_init(void);
void ui_destroy(void);
Index: giFTcurs/src/ui_draw.c
diff -u giFTcurs/src/ui_draw.c:1.106 giFTcurs/src/ui_draw.c:1.107
--- giFTcurs/src/ui_draw.c:1.106 Sun Aug 31 14:45:42 2003
+++ giFTcurs/src/ui_draw.c Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui_draw.c,v 1.106 2003/08/31 18:45:42 saturn Exp $
+ * $Id: ui_draw.c,v 1.107 2003/09/15 21:28:19 saturn Exp $
*/
#include "giftcurs.h"
@@ -58,15 +58,6 @@
clear_area(x + 1, y + 1, w - 2, h - 2);
}
-void draw_header(int x, int y, const char *header)
-{
- move(y, x);
- attrset(COLOR_PAIR(COLOR_HEADER) | A_BOLD);
- addstr(header);
- addstr(": ");
- attrset(COLOR_PAIR(COLOR_STANDARD));
-}
-
void draw_printfmt(int w, const char *fmt, ...)
{
char *s;
@@ -86,8 +77,12 @@
{
int p = 3;
- if (header)
- draw_header(x, y, header);
+ if (header) {
+ move(y, x);
+ attrset(COLOR_PAIR(COLOR_HEADER) | A_BOLD);
+ addstr(header);
+ addstr(": ");
+ }
attrset(attr);
addch('[');
@@ -244,7 +239,7 @@
)
{
int len = vstrlen(str);
-
+
x -= (len + 4) / 2;
move(y, x);
Index: giFTcurs/src/ui_draw.h
diff -u giFTcurs/src/ui_draw.h:1.41 giFTcurs/src/ui_draw.h:1.42
--- giFTcurs/src/ui_draw.h:1.41 Sun Aug 31 14:45:42 2003
+++ giFTcurs/src/ui_draw.h Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui_draw.h,v 1.41 2003/08/31 18:45:42 saturn Exp $
+ * $Id: ui_draw.h,v 1.42 2003/09/15 21:28:19 saturn Exp $
*/
#ifndef _UI_DRAW_H
#define _UI_DRAW_H
@@ -45,7 +45,6 @@
#ifndef MOUSE
# define draw_button(x,y,str,attr,cb,data) draw_button(x,y,str,attr)
#endif
-void draw_header(int x, int y, const char *header);
void draw_string(int x, int y, int w, const char *header);
void draw_fmt_str(int x, int y, int w, int selected, const char *str);
Index: giFTcurs/src/ui_main.c
diff -u giFTcurs/src/ui_main.c:1.345 giFTcurs/src/ui_main.c:1.346
--- giFTcurs/src/ui_main.c:1.345 Mon Sep 8 13:47:23 2003
+++ giFTcurs/src/ui_main.c Mon Sep 15 17:28:19 2003
@@ -18,7 +18,7 @@
* along with giFTcurs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: ui_main.c,v 1.345 2003/09/08 17:47:23 saturn Exp $
+ * $Id: ui_main.c,v 1.346 2003/09/15 21:28:19 saturn Exp $
*/
#include "giftcurs.h"
@@ -78,6 +78,7 @@
static enum attr_type hit_getattr(const hit *h, const char *key, attr_value *
v);
static char *subhit_present(subhit *foo);
static enum attr_type subhit_getattr(const subhit *h, const char *key,
attr_value * v);
+static enum attr_type stats_getattr(const gift_stat * s, const char *key,
attr_value * v);
static guint my_screen_nr;
@@ -247,8 +248,7 @@
interface_append(&packet, "query", user);
if (node)
interface_append(&packet, "node", node);
- q->id = gift_write_register(&packet, "BROWSE",
- (EventCallback) search_result_item_handler, q);
+ q->id = gift_write_register(&packet, "BROWSE", (EventCallback)
search_result_item_handler, q);
if (!q->id)
g_message(_("Couldn't start search!"));
else
@@ -558,7 +558,7 @@
static void main_screen_draw(void)
{
- int y = 1, attr;
+ int attr;
g_assert(active_screen == my_screen_nr);
@@ -595,11 +595,6 @@
/* Statbox */
attr = COLOR_PAIR(COLOR_STAT_BOX) | A_BOLD;
draw_box(max_x - STAT_BOX_W - 2, 0, STAT_BOX_W + 2, STAT_BOX_H,
_("Statistics"), attr);
- attrset(COLOR_PAIR(COLOR_HEADER) | A_BOLD);
- draw_header(STAT_COL1, y++, _("Users online"));
- draw_header(STAT_COL1, y++, _("Total shared"));
- draw_header(STAT_COL1, y++, _("Local shares"));
- draw_header(STAT_COL1, y++, _(" Shared/user"));
main_screen_update_stats();
move(curs_y, curs_x);
@@ -740,44 +735,39 @@
draw_list(2, 1, SEARCH_BOX_W - 4, STAT_BOX_H - 2, FALSE,
&info->infobox);
}
-static void draw_critic_stat(int x, int y, int w, unsigned int val)
-{
- if (val) {
- attrset(COLOR_PAIR(COLOR_STAT_DATA));
- move(y, x);
- draw_printfmt(w, "\vf%u", val);
- } else {
- attrset(COLOR_PAIR(COLOR_STAT_DATA_BAD));
- mvaddch(y, x, '0');
- }
-}
-
static void main_screen_update_stats(void)
{
- char tmp[15];
int i, y = 1;
- int width = max_x - STAT_COL2 - 1;
-
- clear_area(STAT_COL2, y, width, STAT_BOX_H - 2);
-
- draw_critic_stat(STAT_COL2, y++, width, stats.users);
+ int width = max_x - STAT_COL1 - 2;
+ char tmp[15];
+ static struct {
+ const char *format;
+ format_t compiled;
+ } statlines[] = {
+ /* *INDENT-OFF* */
+ { N_("{%header:B}Users online: {if
users}{%stat-data}{else}{%stat-bad}{endif}{users}"), NULL},
+ { N_("{%header:B}Total shared:
{%stat-data}{bytes:bi}B{%stat-box}/{%stat-data}{files:b}"), NULL},
+ { N_("{%header:B}Local shares: {%stat-data}{if
sharing}{own_bytes:bi}B{%stat-box}/{%stat-data}{own_files:b}{else}Hidden{endif}"),
NULL},
+ { N_("{%header:B} Shared/user: {%stat-data}{if
users}{shared_per_user:bi}B{else} - {endif}"), NULL},
+ /* *INDENT-ON* */
+ };
- move(y++, STAT_COL2);
- draw_printfmt(width, _("\vf%sB\vE/\vf%s"), humanify(stats.bytes),
humanify_1000(stats.files));
+ clear_area(STAT_COL1, y, width, STAT_BOX_H - 2);
- move(y++, STAT_COL2);
- if (sharing)
- draw_printfmt(width, _("\vf%sB\vE/\vf%s"),
humanify(stats.own_bytes),
- humanify_1000(stats.own_files));
- else
- draw_printfmt(width, _("Hidden"));
+ for (i = 0; i < G_N_ELEMENTS(statlines); i++) {
+ char *s;
- move(y++, STAT_COL2);
- if (stats.users)
- draw_printfmt(width, _("\vf%sB"), humanify(stats.bytes /
stats.users));
- else
- draw_printfmt(width, "\vf -");
+ if (!statlines[i].compiled) {
+ statlines[i].compiled =
format_compile(_(statlines[i].format));
+ g_assert(statlines[i].compiled);
+ }
+ s = format_expand(statlines[i].compiled, (getattrF)
stats_getattr, width, &stats);
+ move(y++, STAT_COL1);
+ draw_printfmt(width, "%s", s);
+ g_free(s);
+ }
+ /* Show the protocol on the bottom frame */
attrset(COLOR_PAIR(COLOR_STAT_BOX) | A_BOLD);
g_snprintf(tmp, sizeof tmp, stats.network ? " %s " : "", stats.network);
mvaddstr(y, STAT_COL1, tmp);
@@ -971,6 +961,7 @@
#endif
#define RETURN_INT(x) return v->intval = (x), ATTR_INT
+#define RETURN_LONG(x) return v->longval = (x), ATTR_LONG
#define RETURN_STR(x) return v->string = (x), ATTR_STRING
static enum attr_type hit_getattr(const hit *h, const char *key, attr_value *
v)
@@ -1059,6 +1050,28 @@
static char *subhit_present(subhit *foo)
{
return format_expand(subhit_fmt, (getattrF) subhit_getattr, max_x - 4,
foo);
+}
+
+static enum attr_type stats_getattr(const gift_stat * s, const char *key,
attr_value * v)
+{
+ if (!strcmp(key, "users"))
+ RETURN_INT(s->users);
+ if (!strcmp(key, "files"))
+ RETURN_INT(s->files);
+ if (!strcmp(key, "bytes"))
+ RETURN_LONG(s->bytes);
+ if (!strcmp(key, "own_files"))
+ RETURN_INT(s->own_files);
+ if (!strcmp(key, "own_bytes"))
+ RETURN_LONG(s->own_bytes);
+ if (!strcmp(key, "network"))
+ RETURN_STR(s->network);
+ if (!strcmp(key, "sharing"))
+ RETURN_INT(sharing);
+ if (!strcmp(key, "shared_per_user"))
+ if (s->users)
+ RETURN_LONG(s->bytes / s->users);
+ RETURN_STR("");
}
static const ui_methods main_screen_methods = {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [giFTcurs-commits] giFTcurs/src format.c giftcurs.h list.c list.h ...,
Christian Häggström <=