2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2008-12-15 17:31:23 +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
|
2010-01-01 23:46:17 +00:00
|
|
|
* Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
|
2008-12-15 17:31:23 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef _TEXT_OBJECT_H
|
|
|
|
#define _TEXT_OBJECT_H
|
|
|
|
|
2009-11-19 23:25:45 +00:00
|
|
|
#include <stdint.h> /* uint8_t */
|
2008-12-15 17:31:23 +00:00
|
|
|
#include "config.h" /* for the defines */
|
2009-10-25 20:47:47 +00:00
|
|
|
#include "specials.h" /* enum special_types */
|
2008-12-15 17:31:23 +00:00
|
|
|
|
2009-12-10 04:05:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-11-19 23:25:45 +00:00
|
|
|
/* text object callbacks */
|
|
|
|
struct obj_cb {
|
|
|
|
/* text object: print obj's output to p */
|
|
|
|
void (*print)(struct text_object *obj, char *p, int p_max_size);
|
2009-12-04 00:11:57 +00:00
|
|
|
|
2009-11-19 23:25:45 +00:00
|
|
|
/* ifblock object: return zero to trigger jumping */
|
|
|
|
int (*iftest)(struct text_object *obj);
|
2009-12-04 00:11:57 +00:00
|
|
|
|
|
|
|
/* meter objects:
|
|
|
|
* The following functions return the current meter-type value
|
|
|
|
* in a range between 0 and the value passed to the appropriate
|
|
|
|
* scan_* function. Or, if named function has been called with
|
|
|
|
* a value of 0, make use of auto-scaling (i.e., scaling to the
|
|
|
|
* maximum value seen so far). */
|
|
|
|
double (*barval)(struct text_object *obj);
|
|
|
|
double (*gaugeval)(struct text_object *obj);
|
|
|
|
double (*graphval)(struct text_object *obj);
|
|
|
|
|
|
|
|
/* percentage object: return value in range [0, 100] */
|
2009-11-19 23:25:45 +00:00
|
|
|
uint8_t (*percentage)(struct text_object *obj);
|
2009-12-04 00:11:57 +00:00
|
|
|
|
2009-11-19 23:25:45 +00:00
|
|
|
/* free obj's data */
|
|
|
|
void (*free)(struct text_object *obj);
|
|
|
|
};
|
|
|
|
|
2009-11-20 00:43:00 +00:00
|
|
|
/* generic free opaque callback
|
|
|
|
* can be used to simply free obj->data.opaque or obj->data.s */
|
|
|
|
void gen_free_opaque(struct text_object *);
|
|
|
|
|
2009-11-28 21:53:20 +00:00
|
|
|
/* generic iftest returning false (i.e. trigger jumping)
|
|
|
|
* used for the else object */
|
|
|
|
int gen_false_iftest(struct text_object *);
|
|
|
|
|
2009-11-28 22:02:58 +00:00
|
|
|
/* generic nothing printer callback printing nothing
|
|
|
|
* used for the endif object */
|
|
|
|
void gen_print_nothing(struct text_object *, char *, int);
|
|
|
|
|
2009-11-29 19:04:55 +00:00
|
|
|
/* generic obj->data.s printer
|
|
|
|
* used by the $text object */
|
|
|
|
void gen_print_obj_data_s(struct text_object *, char *, int);
|
|
|
|
|
2008-12-15 17:31:23 +00:00
|
|
|
struct text_object {
|
|
|
|
struct text_object *next, *prev; /* doubly linked list of text objects */
|
2008-12-22 17:36:44 +00:00
|
|
|
struct text_object *sub; /* for objects parsing text into objects */
|
2009-11-16 18:52:12 +00:00
|
|
|
struct text_object *ifblock_next; /* jump target for ifblock objects */
|
2008-12-15 17:31:23 +00:00
|
|
|
union {
|
2009-10-03 14:08:33 +00:00
|
|
|
void *opaque; /* new style generic per object data */
|
2008-12-15 17:31:23 +00:00
|
|
|
char *s; /* some string */
|
|
|
|
int i; /* some integer */
|
2009-10-25 21:47:53 +00:00
|
|
|
long l; /* some long integer */
|
2008-12-15 17:31:23 +00:00
|
|
|
} data;
|
2009-10-25 20:47:47 +00:00
|
|
|
|
2009-11-29 19:18:37 +00:00
|
|
|
/* if non-zero, no substitute_newlines() is applied to object's output */
|
|
|
|
char verbatim_output;
|
|
|
|
|
2009-10-25 20:47:47 +00:00
|
|
|
void *special_data;
|
2008-12-15 17:31:23 +00:00
|
|
|
long line;
|
2009-11-19 23:25:45 +00:00
|
|
|
struct obj_cb callbacks;
|
2010-02-10 14:02:00 +00:00
|
|
|
bool parse; //if this true then data.s should still be parsed
|
2008-12-15 17:31:23 +00:00
|
|
|
};
|
|
|
|
|
2008-12-15 18:09:57 +00:00
|
|
|
/* text object list helpers */
|
|
|
|
int append_object(struct text_object *root, struct text_object *obj);
|
|
|
|
|
2008-12-22 16:45:08 +00:00
|
|
|
/* ifblock helpers
|
|
|
|
*
|
|
|
|
* Opaque is a pointer to the address of the ifblock stack's top object.
|
|
|
|
* Calling clients should pass the address of a defined void pointer which
|
|
|
|
* was initialised to NULL (empty stack).
|
|
|
|
* */
|
|
|
|
int obj_be_ifblock_if(void **opaque, struct text_object *);
|
|
|
|
int obj_be_ifblock_else(void **opaque, struct text_object *);
|
|
|
|
int obj_be_ifblock_endif(void **opaque, struct text_object *);
|
|
|
|
int ifblock_stack_empty(void **opaque);
|
2008-12-15 18:09:57 +00:00
|
|
|
|
2009-11-29 19:04:55 +00:00
|
|
|
/* make the given object be a plain text object printing given string */
|
|
|
|
void obj_be_plain_text(struct text_object *, const char *);
|
|
|
|
|
2009-12-10 04:05:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-15 17:31:23 +00:00
|
|
|
#endif /* _TEXT_OBJECT_H */
|