* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
int default_bar_width = 0, default_bar_height = 6;
#ifdef X11
int default_graph_width = 0, default_graph_height = 25;
-int default_gauge_width = 40, default_gauge_height = 25;
#endif /* X11 */
+int default_gauge_width = 40, default_gauge_height = 25;
/*
* Special data typedefs
char tempgrad;
};
+struct stippled_hr {
+ int height, arg;
+};
+
struct tab {
int width, arg;
};
* Scanning arguments to various special text objects
*/
-#ifdef X11
const char *scan_gauge(struct text_object *obj, const char *args)
{
struct gauge *g;
obj->special_data = g;
return args;
}
-#endif /* X11 */
const char *scan_bar(struct text_object *obj, const char *args)
{
return NULL;
}
-char *scan_graph(struct text_object *obj, const char *args)
+char *scan_graph(struct text_object *obj, const char *args, int defscale)
{
struct graph *g;
char buf[1024];
g->height = default_graph_height;
g->first_colour = 0;
g->last_colour = 0;
- g->scale = 0;
+ g->scale = defscale;
g->tempgrad = FALSE;
g->showaslog = FALSE;
if (args) {
if (sscanf(args, "%d,%d %x %x %u", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
return NULL;
}
- g->scale = 0;
+ g->scale = defscale;
if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
return NULL;
}
if (sscanf(args, "%1023s %d,%d %x %x %u", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
return strndup(buf, text_buffer_size);
}
- g->scale = 0;
+ g->scale = defscale;
if (sscanf(args, "%1023s %d,%d %x %x", buf, &g->height, &g->width, &g->first_colour, &g->last_colour) == 5) {
return strndup(buf, text_buffer_size);
}
if (sscanf(args, "%x %x %u", &g->first_colour, &g->last_colour, &g->scale) == 3) {
return NULL;
}
- g->scale = 0;
+ g->scale = defscale;
if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
return NULL;
}
if (sscanf(args, "%1023s %x %x %u", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
return strndup(buf, text_buffer_size);
}
- g->scale = 0;
+ g->scale = defscale;
if (sscanf(args, "%1023s %x %x", buf, &g->first_colour, &g->last_colour) == 3) {
return strndup(buf, text_buffer_size);
}
if (sscanf(args, "%d,%d %u", &g->height, &g->width, &g->scale) == 3) {
return NULL;
}
- g->scale = 0;
+ g->scale = defscale;
if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
return NULL;
}
if (sscanf(args, "%1023s %d,%d %u", buf, &g->height, &g->width, &g->scale) < 4) {
- g->scale = 0;
+ g->scale = defscale;
//TODO: check the return value and throw an error?
sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
}
+
+ /* escape quotes at end in case of execgraph */
+ if (*buf == '"') {
+ char *_ptr;
+ size_t _size;
+ if (_ptr = strrchr(args, '"')) {
+ _size = _ptr - args - 1;
+ }
+ _size = _size < 1024 ? _size : 1023;
+ strncpy(buf, args + 1, _size);
+ buf[_size] = 0;
+ }
+
#undef g
return strndup(buf, text_buffer_size);
return &specials[special_count++];
}
+void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, int usage)
+{
+ static const char *gaugevals[] = { "_. ", "\\. ", " | ", " ./", " ._" };
+ (void)obj;
+
+ snprintf(p, p_max_size, "%s", gaugevals[round_to_int((double)usage * 4 / 255)]);
+}
+
#ifdef X11
-void new_gauge(struct text_object *obj, char *buf, int usage)
+void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
{
struct special_t *s = 0;
struct gauge *g = obj->special_data;
s = new_special(buf, GAUGE);
- s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
+ s->arg = usage;
s->width = g->width;
s->height = g->height;
}
+#endif /* X11 */
-void new_bar(struct text_object *obj, char *buf, int usage)
+void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
{
- struct special_t *s = 0;
- struct bar *b = obj->special_data;
-
- if ((output_methods & TO_X) == 0)
- return;
-
- if (!b)
+ if (!p_max_size)
return;
- s = new_special(buf, BAR);
+ usage = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
- s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
- s->width = b->width;
- s->height = b->height;
+#ifdef X11
+ if (output_methods & TO_X)
+ new_gauge_in_x11(obj, p, usage);
+ else
+#endif /* X11 */
+ new_gauge_in_shell(obj, p, p_max_size, usage);
}
+#ifdef X11
void new_font(char *buf, char *args)
{
if ((output_methods & TO_X) == 0)
f = graph->graph_scale;
}
- graph->graph[0] = f; /* add new data */
/* shift all the data by 1 */
for (i = graph->graph_width - 1; i > 0; i--) {
graph->graph[i] = graph->graph[i - 1];
graph->graph_scale = graph->graph[i - 1];
}
}
- if (graph->scaled && graph->graph[graph->graph_width] > graph->graph_scale) {
+ graph->graph[0] = f; /* add new data */
+ if (graph->scaled && graph->graph[0] > graph->graph_scale) {
/* check if we need to update the scale */
- graph->graph_scale = graph->graph[graph->graph_width];
+ graph->graph_scale = graph->graph[0];
}
}
-void new_graph(struct text_object *obj, char *buf, double val)
+void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val)
{
struct special_t *s = 0;
struct graph *g = obj->special_data;
if ((output_methods & TO_X) == 0)
return;
- if (!g)
+ if (!g || !buf_max_size)
return;
s = new_special(buf, GRAPH);
new_special(buf, HORIZONTAL_LINE)->height = a;
}
-void new_stippled_hr(char *buf, int a, int b)
+void scan_stippled_hr(struct text_object *obj, const char *arg)
+{
+ struct stippled_hr *sh;
+
+ sh = malloc(sizeof(struct stippled_hr));
+ memset(sh, 0, sizeof(struct stippled_hr));
+
+ sh->arg = get_stippled_borders();
+ sh->height = 1;
+
+ if (arg) {
+ if (sscanf(arg, "%d %d", &sh->arg, &sh->height) != 2) {
+ sscanf(arg, "%d", &sh->height);
+ }
+ }
+ if (sh->arg <= 0) {
+ sh->arg = 1;
+ }
+ obj->special_data = sh;
+}
+
+void new_stippled_hr(struct text_object *obj, char *buf)
{
struct special_t *s = 0;
+ struct stippled_hr *sh = obj->special_data;
if ((output_methods & TO_X) == 0)
return;
+ if (!sh)
+ return;
+
s = new_special(buf, STIPPLED_HR);
- s->height = b;
- s->arg = a;
+ s->height = sh->height;
+ s->arg = sh->arg;
}
#endif /* X11 */
}
#endif /* X11 */
-void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
+static void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
{
struct bar *b = obj->special_data;
- int width;
+ int width, i, scaledusage;
if (!b)
return;
if (!width)
width = DEFAULT_BAR_WIDTH_NO_X;
- if(width<=buf_max_size){
- int i = 0, j = 0, scaledusage = round_to_int( usage * width / 100);
+ if (width > buf_max_size)
+ width = buf_max_size;
- #ifdef HAVE_OPENMP
- #pragma omp parallel for schedule(dynamic,10)
- #endif /* HAVE_OPENMP */
- for(i=0; i<(int)scaledusage; i++) {
- *(buffer+i)='#';
- }
- /* gcc seems to think i is not initialized properly :/ */
- j = i;
- #ifdef HAVE_OPENMP
- #pragma omp parallel for schedule(dynamic,10)
- #endif /* HAVE_OPENMP */
- for(i = j/* cheats */; i < width; i++) {
- *(buffer+i)='_';
- }
- *(buffer+i)=0;
- }
+ scaledusage = round_to_int( usage * width / 255);
+
+ for (i = 0; i < scaledusage; i++)
+ buffer[i] = '#';
+
+ for (; i < width; i++)
+ buffer[i] = '_';
+
+ buffer[i] = 0;
+}
+
+#ifdef X11
+static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
+{
+ struct special_t *s = 0;
+ struct bar *b = obj->special_data;
+
+ s = new_special(buf, BAR);
+
+ s->arg = usage;
+ s->width = b ? b->width : default_bar_width;
+ s->height = b ? b->height : default_bar_height;
+}
+#endif /* X11 */
+
+/* usage is in range [0,255] */
+void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
+{
+ if (!p_max_size)
+ return;
+
+ usage = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
+
+#ifdef X11
+ if ((output_methods & TO_X))
+ new_bar_in_x11(obj, p, usage);
+ else
+#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, usage);
}
void new_outline(char *buf, long c)