2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
2009-09-12 10:50:51 +00:00
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2009-02-22 16:53:30 +00:00
|
|
|
*
|
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
2009-03-30 04:55:30 +00:00
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
2009-02-22 16:53:30 +00:00
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "conky.h"
|
|
|
|
#include "colours.h"
|
2009-03-17 17:36:46 +00:00
|
|
|
#ifdef X11
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "fonts.h"
|
2009-06-01 10:19:25 +00:00
|
|
|
#endif /* X11 */
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "logging.h"
|
|
|
|
#include "specials.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
|
2009-05-29 03:22:04 +00:00
|
|
|
int max_specials = MAX_SPECIALS_DEFAULT;
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
/* create specials array on heap instead of stack with introduction of
|
|
|
|
* max_specials */
|
|
|
|
struct special_t *specials = NULL;
|
|
|
|
|
2009-05-29 03:22:04 +00:00
|
|
|
int special_count;
|
2009-02-22 16:53:30 +00:00
|
|
|
|
2009-04-09 22:00:40 +00:00
|
|
|
int default_bar_width = 0, default_bar_height = 6;
|
2009-05-17 11:38:51 +00:00
|
|
|
#ifdef X11
|
2009-04-10 02:10:08 +00:00
|
|
|
int default_graph_width = 0, default_graph_height = 25;
|
2009-05-16 20:55:05 +00:00
|
|
|
int default_gauge_width = 40, default_gauge_height = 25;
|
2009-06-01 10:19:25 +00:00
|
|
|
#endif /* X11 */
|
2009-04-09 22:00:40 +00:00
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
/*
|
|
|
|
* Special data typedefs
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct bar {
|
|
|
|
int width, height;
|
|
|
|
};
|
|
|
|
|
2009-10-29 02:13:47 +00:00
|
|
|
struct gauge {
|
|
|
|
int width, height;
|
|
|
|
};
|
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
struct graph {
|
|
|
|
int width, height;
|
|
|
|
unsigned int first_colour, last_colour;
|
|
|
|
unsigned int scale, showaslog;
|
|
|
|
char tempgrad;
|
|
|
|
};
|
|
|
|
|
2009-10-29 02:18:24 +00:00
|
|
|
struct tab {
|
|
|
|
int width, arg;
|
|
|
|
};
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
/*
|
|
|
|
* Scanning arguments to various special text objects
|
|
|
|
*/
|
2009-03-11 00:37:24 +00:00
|
|
|
|
2009-05-16 22:37:22 +00:00
|
|
|
#ifdef X11
|
2009-10-29 02:13:47 +00:00
|
|
|
const char *scan_gauge(struct text_object *obj, const char *args)
|
2009-03-11 00:37:24 +00:00
|
|
|
{
|
2009-10-29 02:13:47 +00:00
|
|
|
struct gauge *g;
|
|
|
|
|
|
|
|
g = malloc(sizeof(struct gauge));
|
|
|
|
memset(g, 0, sizeof(struct gauge));
|
|
|
|
|
2009-03-11 00:37:24 +00:00
|
|
|
/*width and height*/
|
2009-10-29 02:13:47 +00:00
|
|
|
g->width = default_gauge_width;
|
|
|
|
g->height = default_gauge_height;
|
2009-03-11 00:37:24 +00:00
|
|
|
|
|
|
|
/* gauge's argument is either height or height,width */
|
|
|
|
if (args) {
|
|
|
|
int n = 0;
|
|
|
|
|
2009-10-29 02:13:47 +00:00
|
|
|
if (sscanf(args, "%d,%d %n", &g->height, &g->width, &n) <= 1) {
|
|
|
|
if (sscanf(args, "%d %n", &g->height, &n) == 2) {
|
|
|
|
g->width = g->height; /*square gauge*/
|
2009-05-16 20:55:05 +00:00
|
|
|
}
|
2009-03-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
args += n;
|
|
|
|
}
|
|
|
|
|
2009-10-29 02:13:47 +00:00
|
|
|
obj->special_data = g;
|
2009-03-11 00:37:24 +00:00
|
|
|
return args;
|
|
|
|
}
|
2009-06-01 10:19:25 +00:00
|
|
|
#endif /* X11 */
|
2009-03-11 00:37:24 +00:00
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
const char *scan_bar(struct text_object *obj, const char *args)
|
2009-02-22 16:53:30 +00:00
|
|
|
{
|
2009-10-25 20:47:47 +00:00
|
|
|
struct bar *b;
|
|
|
|
|
|
|
|
b = malloc(sizeof(struct bar));
|
|
|
|
memset(b, 0, sizeof(struct bar));
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
/* zero width means all space that is available */
|
2009-10-25 20:47:47 +00:00
|
|
|
b->width = default_bar_width;
|
|
|
|
b->height = default_bar_height;
|
2009-02-22 16:53:30 +00:00
|
|
|
/* bar's argument is either height or height,width */
|
|
|
|
if (args) {
|
|
|
|
int n = 0;
|
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
if (sscanf(args, "%d,%d %n", &b->height, &b->width, &n) <= 1) {
|
|
|
|
sscanf(args, "%d %n", &b->height, &n);
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
args += n;
|
|
|
|
}
|
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
obj->special_data = b;
|
2009-02-22 16:53:30 +00:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2009-06-01 10:19:25 +00:00
|
|
|
#ifdef X11
|
2009-02-22 16:53:30 +00:00
|
|
|
char *scan_font(const char *args)
|
|
|
|
{
|
|
|
|
if (args && *args) {
|
|
|
|
return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
char *scan_graph(struct text_object *obj, const char *args)
|
2009-02-22 16:53:30 +00:00
|
|
|
{
|
2009-10-29 02:08:08 +00:00
|
|
|
struct graph *g;
|
2009-07-05 03:43:45 +00:00
|
|
|
char buf[1024];
|
|
|
|
memset(buf, 0, 1024);
|
2009-02-22 16:53:30 +00:00
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
g = malloc(sizeof(struct graph));
|
|
|
|
memset(g, 0, sizeof(struct graph));
|
|
|
|
obj->special_data = g;
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
/* zero width means all space that is available */
|
2009-10-29 02:08:08 +00:00
|
|
|
g->width = default_graph_width;
|
|
|
|
g->height = default_graph_height;
|
|
|
|
g->first_colour = 0;
|
|
|
|
g->last_colour = 0;
|
|
|
|
g->scale = 0;
|
|
|
|
g->tempgrad = FALSE;
|
|
|
|
g->showaslog = FALSE;
|
2009-02-22 16:53:30 +00:00
|
|
|
if (args) {
|
2009-07-05 04:03:12 +00:00
|
|
|
if (strstr(args, " "TEMPGRAD) || strncmp(args, TEMPGRAD, strlen(TEMPGRAD)) == 0) {
|
2009-10-29 02:08:08 +00:00
|
|
|
g->tempgrad = TRUE;
|
2009-05-24 21:53:32 +00:00
|
|
|
}
|
2009-07-05 04:03:12 +00:00
|
|
|
if (strstr(args, " "LOGGRAPH) || strncmp(args, LOGGRAPH, strlen(LOGGRAPH)) == 0) {
|
2009-10-29 02:08:08 +00:00
|
|
|
g->showaslog = TRUE;
|
2009-07-05 03:43:45 +00:00
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
if (sscanf(args, "%d,%d %x %x %u", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
g->scale = 0;
|
|
|
|
if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
if (sscanf(args, "%1023s %d,%d %x %x %u", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
g->scale = 0;
|
|
|
|
if (sscanf(args, "%1023s %d,%d %x %x", buf, &g->height, &g->width, &g->first_colour, &g->last_colour) == 5) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
|
|
|
buf[0] = '\0';
|
2009-10-29 02:08:08 +00:00
|
|
|
g->height = 25;
|
|
|
|
g->width = 0;
|
|
|
|
if (sscanf(args, "%x %x %u", &g->first_colour, &g->last_colour, &g->scale) == 3) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
g->scale = 0;
|
|
|
|
if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
if (sscanf(args, "%1023s %x %x %u", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
g->scale = 0;
|
|
|
|
if (sscanf(args, "%1023s %x %x", buf, &g->first_colour, &g->last_colour) == 3) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
|
|
|
buf[0] = '\0';
|
2009-10-29 02:08:08 +00:00
|
|
|
g->first_colour = 0;
|
|
|
|
g->last_colour = 0;
|
|
|
|
if (sscanf(args, "%d,%d %u", &g->height, &g->width, &g->scale) == 3) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
g->scale = 0;
|
|
|
|
if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
|
2009-02-22 16:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
if (sscanf(args, "%1023s %d,%d %u", buf, &g->height, &g->width, &g->scale) < 4) {
|
|
|
|
g->scale = 0;
|
2009-02-22 16:53:30 +00:00
|
|
|
//TODO: check the return value and throw an error?
|
2009-10-29 02:08:08 +00:00
|
|
|
sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
#undef g
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == '\0') {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return strndup(buf, text_buffer_size);
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 10:19:25 +00:00
|
|
|
#endif /* X11 */
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Printing various special text objects
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct special_t *new_special(char *buf, enum special_types t)
|
|
|
|
{
|
|
|
|
if (special_count >= max_specials) {
|
2009-07-16 18:28:23 +00:00
|
|
|
CRIT_ERR(NULL, NULL, "too many special things in text");
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = SPECIAL_CHAR;
|
|
|
|
buf[1] = '\0';
|
|
|
|
specials[special_count].type = t;
|
|
|
|
return &specials[special_count++];
|
|
|
|
}
|
|
|
|
|
2009-05-10 12:14:21 +00:00
|
|
|
#ifdef X11
|
2009-10-29 02:13:47 +00:00
|
|
|
void new_gauge(struct text_object *obj, char *buf, int usage)
|
2009-03-11 00:37:24 +00:00
|
|
|
{
|
2009-05-09 17:20:04 +00:00
|
|
|
struct special_t *s = 0;
|
2009-10-29 02:13:47 +00:00
|
|
|
struct gauge *g = obj->special_data;
|
|
|
|
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-29 02:13:47 +00:00
|
|
|
if (!g)
|
|
|
|
return;
|
|
|
|
|
2009-05-09 17:20:04 +00:00
|
|
|
s = new_special(buf, GAUGE);
|
2009-03-11 00:37:24 +00:00
|
|
|
|
|
|
|
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
2009-10-29 02:13:47 +00:00
|
|
|
s->width = g->width;
|
|
|
|
s->height = g->height;
|
2009-03-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
void new_bar(struct text_object *obj, char *buf, int usage)
|
2009-02-22 16:53:30 +00:00
|
|
|
{
|
2009-05-09 17:20:04 +00:00
|
|
|
struct special_t *s = 0;
|
2009-10-25 20:47:47 +00:00
|
|
|
struct bar *b = obj->special_data;
|
2009-05-09 17:20:04 +00:00
|
|
|
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
if (!b)
|
|
|
|
return;
|
|
|
|
|
2009-05-09 17:20:04 +00:00
|
|
|
s = new_special(buf, BAR);
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
2009-10-25 20:47:47 +00:00
|
|
|
s->width = b->width;
|
|
|
|
s->height = b->height;
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void new_font(char *buf, char *args)
|
|
|
|
{
|
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
2009-05-09 12:06:58 +00:00
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
if (args) {
|
|
|
|
struct special_t *s = new_special(buf, FONT);
|
|
|
|
|
|
|
|
if (s->font_added > font_count || !s->font_added || (strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE) != EQUAL) ) {
|
|
|
|
int tmp = selected_font;
|
|
|
|
|
2009-06-07 04:53:40 +00:00
|
|
|
selected_font = s->font_added = add_font(args);
|
2009-02-22 16:53:30 +00:00
|
|
|
selected_font = tmp;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct special_t *s = new_special(buf, FONT);
|
|
|
|
int tmp = selected_font;
|
|
|
|
|
|
|
|
selected_font = s->font_added = 0;
|
|
|
|
selected_font = tmp;
|
|
|
|
}
|
2009-02-22 17:21:15 +00:00
|
|
|
}
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
static void graph_append(struct special_t *graph, double f, char showaslog)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-06-04 20:00:52 +00:00
|
|
|
if (showaslog) {
|
2009-07-11 22:51:17 +00:00
|
|
|
#ifdef MATH
|
2009-02-22 16:53:30 +00:00
|
|
|
f = log10(f + 1);
|
2009-06-04 20:00:52 +00:00
|
|
|
#endif
|
2009-07-11 22:51:17 +00:00
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
if (!graph->scaled && f > graph->graph_scale) {
|
|
|
|
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];
|
2009-05-25 05:16:36 +00:00
|
|
|
if (graph->scaled && graph->graph[i - 1] > graph->graph_scale) {
|
2009-02-22 16:53:30 +00:00
|
|
|
/* check if we need to update the scale */
|
2009-05-25 05:16:36 +00:00
|
|
|
graph->graph_scale = graph->graph[i - 1];
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-25 05:16:36 +00:00
|
|
|
if (graph->scaled && graph->graph[graph->graph_width] > graph->graph_scale) {
|
|
|
|
/* check if we need to update the scale */
|
|
|
|
graph->graph_scale = graph->graph[graph->graph_width];
|
|
|
|
}
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
void new_graph(struct text_object *obj, char *buf, double val)
|
2009-02-22 16:53:30 +00:00
|
|
|
{
|
2009-05-09 17:20:04 +00:00
|
|
|
struct special_t *s = 0;
|
2009-10-29 02:08:08 +00:00
|
|
|
struct graph *g = obj->special_data;
|
2009-05-09 17:20:04 +00:00
|
|
|
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
if (!g)
|
|
|
|
return;
|
|
|
|
|
2009-05-09 17:20:04 +00:00
|
|
|
s = new_special(buf, GRAPH);
|
2009-02-22 16:53:30 +00:00
|
|
|
|
2009-10-29 02:08:08 +00:00
|
|
|
s->width = g->width;
|
2009-02-22 16:53:30 +00:00
|
|
|
if (s->graph == NULL) {
|
|
|
|
if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
|
|
|
|
// subtract 2 for the box
|
|
|
|
s->graph_width = s->width /* - 2 */;
|
|
|
|
} else {
|
|
|
|
s->graph_width = MAX_GRAPH_DEPTH - 2;
|
|
|
|
}
|
|
|
|
s->graph = malloc(s->graph_width * sizeof(double));
|
|
|
|
memset(s->graph, 0, s->graph_width * sizeof(double));
|
|
|
|
s->graph_scale = 100;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
s->height = g->height;
|
|
|
|
s->first_colour = adjust_colours(g->first_colour);
|
|
|
|
s->last_colour = adjust_colours(g->last_colour);
|
|
|
|
if (g->scale != 0) {
|
2009-02-22 16:53:30 +00:00
|
|
|
s->scaled = 0;
|
2009-10-29 02:08:08 +00:00
|
|
|
s->graph_scale = g->scale;
|
2009-02-22 16:53:30 +00:00
|
|
|
s->show_scale = 0;
|
|
|
|
} else {
|
|
|
|
s->scaled = 1;
|
|
|
|
s->graph_scale = 1;
|
|
|
|
s->show_scale = 1;
|
|
|
|
}
|
2009-10-29 02:08:08 +00:00
|
|
|
s->tempgrad = g->tempgrad;
|
2009-02-22 16:53:30 +00:00
|
|
|
/* if (s->width) {
|
|
|
|
s->graph_width = s->width - 2; // subtract 2 for rectangle around
|
|
|
|
} */
|
|
|
|
#ifdef MATH
|
2009-10-29 02:08:08 +00:00
|
|
|
if (g->showaslog) {
|
2009-02-22 16:53:30 +00:00
|
|
|
s->graph_scale = log10(s->graph_scale + 1);
|
|
|
|
}
|
2009-06-04 20:00:52 +00:00
|
|
|
#endif
|
2009-10-29 02:08:08 +00:00
|
|
|
graph_append(s, val, g->showaslog);
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void new_hr(char *buf, int a)
|
|
|
|
{
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
new_special(buf, HORIZONTAL_LINE)->height = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_stippled_hr(char *buf, int a, int b)
|
|
|
|
{
|
2009-05-09 17:20:04 +00:00
|
|
|
struct special_t *s = 0;
|
|
|
|
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-05-09 17:20:04 +00:00
|
|
|
s = new_special(buf, STIPPLED_HR);
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
s->height = b;
|
|
|
|
s->arg = a;
|
|
|
|
}
|
2009-08-03 17:36:47 +00:00
|
|
|
#endif /* X11 */
|
2009-02-22 16:53:30 +00:00
|
|
|
|
|
|
|
void new_fg(char *buf, long c)
|
|
|
|
{
|
2009-08-03 17:36:47 +00:00
|
|
|
#ifdef X11
|
|
|
|
if (output_methods & TO_X)
|
|
|
|
new_special(buf, FG)->arg = c;
|
|
|
|
#endif /* X11 */
|
|
|
|
#ifdef NCURSES
|
|
|
|
if (output_methods & TO_NCURSES)
|
|
|
|
new_special(buf, FG)->arg = c;
|
|
|
|
#endif /* NCURSES */
|
2009-08-04 20:13:06 +00:00
|
|
|
UNUSED(buf);
|
|
|
|
UNUSED(c);
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 17:36:47 +00:00
|
|
|
#ifdef X11
|
2009-02-22 16:53:30 +00:00
|
|
|
void new_bg(char *buf, long c)
|
|
|
|
{
|
2009-05-09 12:06:58 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
new_special(buf, BG)->arg = c;
|
|
|
|
}
|
2009-06-01 10:19:25 +00:00
|
|
|
#endif /* X11 */
|
2009-02-22 16:53:30 +00:00
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
|
2009-06-01 00:23:47 +00:00
|
|
|
{
|
2009-10-25 20:47:47 +00:00
|
|
|
struct bar *b = obj->special_data;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
width = b->width;
|
|
|
|
if (!width)
|
|
|
|
width = DEFAULT_BAR_WIDTH_NO_X;
|
|
|
|
|
2009-06-01 00:23:47 +00:00
|
|
|
if(width<=buf_max_size){
|
|
|
|
int i = 0, j = 0, scaledusage = round_to_int( usage * width / 100);
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENMP
|
2009-07-18 19:46:36 +00:00
|
|
|
#pragma omp parallel for schedule(dynamic,10)
|
2009-06-01 00:23:47 +00:00
|
|
|
#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
|
2009-07-18 19:46:36 +00:00
|
|
|
#pragma omp parallel for schedule(dynamic,10)
|
2009-06-01 00:23:47 +00:00
|
|
|
#endif /* HAVE_OPENMP */
|
|
|
|
for(i = j/* cheats */; i < width; i++) {
|
|
|
|
*(buffer+i)='_';
|
|
|
|
}
|
|
|
|
*(buffer+i)=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 16:53:30 +00:00
|
|
|
void new_outline(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, OUTLINE)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_offset(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, OFFSET)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_voffset(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, VOFFSET)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_alignr(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, ALIGNR)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A postive offset pushes the text further left
|
|
|
|
void new_alignc(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, ALIGNC)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_goto(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, GOTO)->arg = c;
|
|
|
|
}
|
|
|
|
|
2009-10-29 02:18:24 +00:00
|
|
|
void scan_tab(struct text_object *obj, const char *arg)
|
2009-02-22 16:53:30 +00:00
|
|
|
{
|
2009-10-29 02:18:24 +00:00
|
|
|
struct tab *t;
|
|
|
|
|
|
|
|
t = malloc(sizeof(struct tab));
|
|
|
|
memset(t, 0, sizeof(struct tab));
|
|
|
|
|
|
|
|
t->width = 10;
|
|
|
|
t->arg = 0;
|
2009-02-22 16:53:30 +00:00
|
|
|
|
2009-10-29 02:18:24 +00:00
|
|
|
if (arg) {
|
|
|
|
if (sscanf(arg, "%d %d", &t->width, &t->arg) != 2) {
|
|
|
|
sscanf(arg, "%d", &t->arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (t->width <= 0) {
|
|
|
|
t->width = 1;
|
|
|
|
}
|
|
|
|
obj->special_data = t;
|
2009-02-22 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 02:18:24 +00:00
|
|
|
void new_tab(struct text_object *obj, char *buf)
|
|
|
|
{
|
|
|
|
struct special_t *s = 0;
|
|
|
|
struct tab *t = obj->special_data;
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = new_special(buf, TAB);
|
|
|
|
s->width = t->width;
|
|
|
|
s->arg = t->arg;
|
|
|
|
}
|