-/* $Id: Raster.c,v 1.30 2004/01/30 20:57:55 reinelt Exp $
+/* $Id: Raster.c,v 1.31 2004/03/03 03:47:04 reinelt Exp $
*
* driver for raster formats
*
*
*
* $Log: Raster.c,v $
+ * Revision 1.31 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.30 2004/01/30 20:57:55 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
}
snprintf (path, sizeof(path), output, seq++);
- snprintf (tmp, sizeof(tmp), "%s.tmp", path);
+ qprintf(tmp, sizeof(tmp), "%s.tmp", path);
if ((fd=open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644))<0) {
error ("Raster: open(%s) failed: %s", tmp, strerror(errno));
return -1;
}
- snprintf (buffer, sizeof(buffer), "P6\n%d %d\n255\n", xsize, ysize);
+ qprintf(buffer, sizeof(buffer), "P6\n%d %d\n255\n", xsize, ysize);
if (write (fd, buffer, strlen(buffer))<0) {
error ("Raster: write(%s) failed: %s", tmp, strerror(errno));
return -1;
}
snprintf (path, sizeof(path), output, seq++);
- snprintf (tmp, sizeof(tmp), "%s.tmp", path);
+ qprintf(tmp, sizeof(tmp), "%s.tmp", path);
if ((fp=fopen(tmp, "w")) == NULL) {
error("Png: fopen(%s) failed: %s\n", tmp, strerror(errno));
if (sscanf(s=cfg_get(NULL, "size", "20x4"), "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
error ("Raster: bad size '%s'", s);
return -1;
+ free(s);
}
+ free(s);
if (sscanf(s=cfg_get(NULL, "font", "5x8"), "%dx%d", &xres, &yres)!=2 || xres<5 || yres<7) {
error ("Raster: bad font '%s'", s);
return -1;
+ free(s);
}
+ free(s);
if (sscanf(s=cfg_get(NULL, "pixel", "4+1"), "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
error ("Raster: bad pixel '%s'", s);
return -1;
+ free(s);
}
+ free(s);
if (sscanf(s=cfg_get(NULL, "gap", "3x3"), "%dx%d", &cgap, &rgap)!=2 || cgap<-1 || rgap<-1) {
error ("Raster: bad gap '%s'", s);
return -1;
+ free(s);
}
+ free(s);
+
if (rgap<0) rgap=pixel+pgap;
if (cgap<0) cgap=pixel+pgap;
if (sscanf(s=cfg_get(NULL, "foreground", "#102000"), "#%x", &foreground)!=1) {
error ("Raster: bad foreground color '%s'", s);
return -1;
+ free(s);
}
+ free(s);
+
if (sscanf(s=cfg_get(NULL, "halfground", "#70c000"), "#%x", &halfground)!=1) {
error ("Raster: bad halfground color '%s'", s);
return -1;
+ free(s);
}
+ free(s);
+
if (sscanf(s=cfg_get(NULL, "background", "#80d000"), "#%x", &background)!=1) {
error ("Raster: bad background color '%s'", s);
return -1;
+ free(s);
}
+ free(s);
if (pix_init (rows, cols, xres, yres)!=0) {
error ("Raster: pix_init(%d, %d, %d, %d) failed", rows, cols, xres, yres);
-/* $Id: Text.c,v 1.14 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: Text.c,v 1.15 2004/03/03 03:47:04 reinelt Exp $
*
* pure ncurses based text driver
*
*
*
* $Log: Text.c,v $
+ * Revision 1.15 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.14 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
error ("Text: bad size '%s'", s);
return -1;
}
+ free(s);
Self->rows=rows;
Self->cols=cols;
Self->xres=1;
int Text_bar (int type, int row, int col, int max, int len1, int len2)
{
int len, i;
- if (cfg_get(NULL, "TextBar", NULL))
+ char* s;
+ if (s=cfg_get(NULL, "TextBar", NULL)) {
mvwprintw(w, row+1 , col+1, "%d %d %d", max, len1, len2);
- else {
+ } else {
len = min(len1, len2);
len = min(len, Lcd.cols-col-1);
if (len) {
for (i=0; i<len2;i++)
waddch(w,ACS_S9);
}
-
+ free(s);
return 0;
}
-/* $Id: cfg.c,v 1.35 2004/03/01 04:29:51 reinelt Exp $^
+/* $Id: cfg.c,v 1.36 2004/03/03 03:47:04 reinelt Exp $^
*
* config file stuff
*
*
*
* $Log: cfg.c,v $
+ * Revision 1.36 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.35 2004/03/01 04:29:51 reinelt
* cfg_number() returns -1 on error, 0 if value not found (but default val used),
* and 1 if value was used from the configuration.
char *l4l_cfg_get (char *section, char *key, char *defval)
{
char *expression;
+ char *retval;
RESULT result = {0, 0.0, NULL};
expression=cfg_lookup(section, key);
if (expression!=NULL) {
if (*expression=='\0') return "";
if (Eval(expression, &result)==0) {
- return R2S(&result);
+ retval=strdup(R2S(&result));
+ DelResult(&result);
+ return(retval);
}
+ DelResult(&result);
}
- return strdup(defval);
+ if (defval) return strdup(defval);
+ return NULL;
}
}
if (Eval(expression, &result)!=0) {
+ DelResult(&result);
return -1;
}
*value=R2N(&result);
int l4l_cfg_exit (void)
{
int i;
-
- for (i=0; i<nConfig; i++) {
+ for (i=0; i<nConfig; i++) {
if (Config[i].key) free (Config[i].key);
if (Config[i].val) free (Config[i].val);
}
-/* $Id: drv_HD44780.c,v 1.14 2004/03/01 04:29:51 reinelt Exp $
+/* $Id: drv_HD44780.c,v 1.15 2004/03/03 03:47:04 reinelt Exp $
*
* new style driver for HD44780-based displays
*
*
*
* $Log: drv_HD44780.c,v $
+ * Revision 1.15 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.14 2004/03/01 04:29:51 reinelt
* cfg_number() returns -1 on error, 0 if value not found (but default val used),
* and 1 if value was used from the configuration.
static int drv_HD_start (char *section)
{
- char *model, *s;
+ char *model, *strsize;
int rows=-1, cols=-1, gpos=-1;
model=cfg_get(section, "Model", "generic");
error ("%s: empty '%s.Model' entry from %s", Name, section, cfg_source());
return -1;
}
+ free(model);
- s=cfg_get(section, "Size", NULL);
- if (s==NULL || *s=='\0') {
+ strsize=cfg_get(section, "Size", NULL);
+ if (strsize==NULL || *strsize=='\0') {
error ("%s: no '%s.Size' entry from %s", Name, section, cfg_source());
+ free(strsize);
return -1;
}
- if (sscanf(s,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) {
- error ("%s: bad size '%s'", Name, s);
+ if (sscanf(strsize,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) {
+ error ("%s: bad size '%s'", Name, strsize);
+ free(strsize);
return -1;
}
-
+
if (cfg_number(section, "GPOs", 0, 0, 8, &gpos)<0) return -1;
info ("%s: controlling %d GPO's", Name, gpos);
if (cfg_number(section, "Bits", 8, 4, 8, &Bits)<0) return -1;
if (Bits!=4 && Bits!=8) {
- error ("%s: bad %s.Bits '%s' from %s, should be '4' or '8'", Name, section, s, cfg_source());
+ error ("%s: bad %s.Bits '%s' from %s, should be '4' or '8'", Name, section, strsize, cfg_source());
return -1;
}
info ("%s: using %d bit mode", Name, Bits);
}
info("%s: %susing busy-flag checking", Name, UseBusy?"":"not ");
+ free(strsize);
drv_HD_command (allControllers, 0x01, T_CLEAR); // clear *both* displays
drv_HD_command (allControllers, 0x03, T_CLEAR); // return home
*
*
* $Log: drv_generic_graphic.c,v $
+ * Revision 1.6 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.5 2004/02/29 14:30:59 reinelt
* icon visibility fix for generic graphics from Xavier
*
drv_generic_graphic_FB=NULL;
}
+ widget_unregister();
return (0);
}
-/* $Id: drv_generic_parport.c,v 1.2 2004/01/20 15:32:49 reinelt Exp $
+/* $Id: drv_generic_parport.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* generic driver helper for serial and parport access
*
*
*
* $Log: drv_generic_parport.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/01/20 15:32:49 reinelt
* first version of Next Generation HD44780 (untested! but it compiles...)
* some cleanup in the other drivers
#include "cfg.h"
#include "udelay.h"
#include "drv_generic_parport.h"
+#include "qprintf.h"
static char *Driver="";
Port=0;
PPdev=s;
#else
+ free(s);
error ("%s: bad %s.Port '%s' from %s", Driver, Section, s, cfg_source());
return -1;
#endif
error ("%s: close(%s) failed: %s", Driver, PPdev, strerror(errno));
return -1;
}
+ free(PPdev);
} else
#endif
{
}
}
}
+
return 0;
}
char wire[256];
char *s;
- snprintf (wire, sizeof(wire), "Wire.%s", name);
+ qprintf(wire, sizeof(wire), "Wire.%s", name);
s=cfg_get (Section, wire, deflt);
if (strcasecmp(s,"STROBE")==0) {
w=PARPORT_CONTROL_STROBE;
error ("%s: should be STROBE, AUTOFD, INIT, SELECT or GND", Driver);
return 0xff;
}
+ free(s);
if (w&PARPORT_CONTROL_STROBE) {
info ("%s: wiring: [DISPLAY:%s]<==>[PARPORT:STROBE]", Driver, name);
char wire[256];
char *s;
- snprintf (wire, sizeof(wire), "Wire.%s", name);
+ qprintf(wire, sizeof(wire), "Wire.%s", name);
s=cfg_get (Section, wire, deflt);
if(strlen(s)==3 && strncasecmp(s,"DB",2)==0 && s[2]>='0' && s[2]<='7') {
w=s[2]-'0';
error ("%s: should be DB0..7 or GND", Driver);
return 0xff;
}
-
+ free(s);
if (w==0) {
info ("%s: wiring: [DISPLAY:%s]<==>[PARPORT:GND]", Driver, name);
} else {
-/* $Id: drv_generic_serial.c,v 1.6 2004/02/14 11:56:17 reinelt Exp $
+/* $Id: drv_generic_serial.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
*
* generic driver helper for serial and usbserial displays
*
*
*
* $Log: drv_generic_serial.c,v $
+ * Revision 1.7 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.6 2004/02/14 11:56:17 reinelt
* M50530 driver ported
* changed lots of 'char' to 'unsigned char'
#include "debug.h"
#include "cfg.h"
#include "drv_generic_serial.h"
+#include "qprintf.h"
static char *Driver;
*p='_';
}
- snprintf(lockfile, sizeof(lockfile), LOCK, port);
- snprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
+ qprintf(lockfile, sizeof(lockfile), LOCK, port);
+ qprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
free (port);
*p='_';
}
- snprintf(lockfile, sizeof(lockfile), LOCK, port);
+ qprintf(lockfile, sizeof(lockfile), LOCK, port);
unlink (lockfile);
free (port);
info ("%s: closing port %s", Driver, Port);
close (Device);
drv_generic_serial_unlock_port(Port);
+ free(Port);
return 0;
}
-/* $Id: drv_generic_text.c,v 1.11 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: drv_generic_text.c,v 1.12 2004/03/03 03:47:04 reinelt Exp $
*
* generic driver helper for text-based displays
*
*
*
* $Log: drv_generic_text.c,v $
+ * Revision 1.12 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.11 2004/02/15 21:43:43 reinelt
* T6963 driver nearly finished
* framework for graphic displays done
free (BarFB);
BarFB=NULL;
}
-
+ widget_unregister();
+
return (0);
}
-/* $Id: evaluator.c,v 1.13 2004/02/26 21:42:45 reinelt Exp $
+/* $Id: evaluator.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
*
* expression evaluation
*
* FIXME: GPL or not GPL????
*
* $Log: evaluator.c,v $
+ * Revision 1.14 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.13 2004/02/26 21:42:45 reinelt
* memory leak fixes from Martin
*
V=bsearch(name, Variable, nVariable, sizeof(VARIABLE), v_lookup);
if (V!=NULL) {
FreeResult (V->value);
- V->value=DupResult(value);
+ V->value=(value);
return 1;
}
return 0;
}
+void DeleteVariables(void) {
+ int i;
+
+ for (i=0;i<nVariable;i++) {
+ free(Variable[i].name);
+ FreeResult(Variable[i].value);
+ }
+ free(Variable);
+ Variable=NULL;
+ nVariable=0;
+}
int AddNumericVariable (char *name, double value)
{
return 0;
}
+void DeleteFunctions(void) {
+ int i;
+
+ for (i=0;i<nFunction;i++) {
+ free(Function[i].name);
+ }
+ free(Function);
+ Function=NULL;
+ nFunction=0;
+}
+
// Prototypes
value = (R2N(result)!=0.0) || (R2N(&operand)!=0.0);
SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&operand);
}
// logical 'and'
static void Level05 (RESULT *result)
{
- RESULT operand;
+ RESULT operand = {0, 0.0, NULL};
double value;
Level06(result);
value = (R2N(result)!=0.0) && (R2N(&operand)!=0.0);
SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&operand);
}
value = (R2N(result) == R2N(&operand));
else
value = (R2N(result) != R2N(&operand));
- SetResult(&result, R_NUMBER, &value);
+ SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&operand);
}
Level08 (&operand);
if (operator[0]=='<')
if (operator[1]=='=')
- value = (R2N(result) <= R2N(&operand));
+ value = (R2N(result) <= R2N(&operand));
else
- value = (R2N(result) < R2N(&operand));
+ value = (R2N(result) < R2N(&operand));
else
if (operator[1]=='=')
- value = (R2N(result) >= R2N(&operand));
+ value = (R2N(result) >= R2N(&operand));
else
- value = (R2N(result) > R2N(&operand));
+ value = (R2N(result) > R2N(&operand));
SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&operand);
}
free (s3);
}
}
+ DelResult(&operand);
}
}
SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&operand);
}
value = pow(R2N(result), R2N(&exponent));
SetResult(&result, R_NUMBER, &value);
}
+ DelResult(&exponent);
}
-/* $Id: evaluator.h,v 1.3 2004/01/12 03:51:01 reinelt Exp $
+/* $Id: evaluator.h,v 1.4 2004/03/03 03:47:04 reinelt Exp $
*
* expression evaluation
*
* FIXME: GPL or not GPL????
*
* $Log: evaluator.h,v $
+ * Revision 1.4 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.3 2004/01/12 03:51:01 reinelt
* evaluating the 'Variables' section in the config file
*
int AddNumericVariable (char *name, double value);
int AddStringVariable (char *name, char *value);
int AddFunction (char *name, int args, void (*func)());
+void DeleteVariables (void);
+void DeleteFunctions (void);
RESULT* SetResult (RESULT **result, int type, void *value);
-/* $Id: exec.c,v 1.12 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: exec.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
*
* exec ('x*') functions
*
*
*
* $Log: exec.c,v $
+ * Revision 1.13 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.12 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
static time_t now[EXECS+1];
static int errs[EXECS+1];
static int ticks[EXECS+1];
- char *command, *p;
+ char *command, *strticks;
char xn[20];
char env[EXEC_TXT_LEN];
FILE *pipe;
if (now[index] > 0) {
/* delay in Ticks ? */
sprintf(xn, "Tick_x%d", index);
- p = cfg_get(NULL, xn, NULL);
+ strticks = cfg_get(NULL, xn, NULL);
if (p && *p) {
- if (ticks[index]++ % atoi(p) != 0)
+ if (ticks[index]++ % atoi(strticks) != 0) {
+ free(strticks);
return 0;
+ }
+ free(strticks);
}
else {
+ free(strticks);
sprintf(xn, "Delay_x%d", index);
/* delay in Delay_x* sec ? */
if (time(NULL) <= now[index] + atoi(cfg_get(NULL, xn, "1"))) {
if (!command || !*command) {
error("Empty command for 'x%d'", index);
errs[index]++;
+ if (command) free(command);
return -1;
}
for (i = 1; i < index; i++) {
if (pipe == NULL) {
error("Couldn't run pipe '%s':\n%s", command, strerror(errno));
errs[index]++;
+ free(command);
return -1;
}
len = fread(buff, 1, EXEC_TXT_LEN-1, pipe);
error("Couldn't fread from pipe '%s', len=%d", command, len);
errs[index]++;
*buff = '\0';
+ free(command);
return -1;
}
pclose(pipe);
if (max != min)
*val = (*val - min)/(max - min);
}
+ free(command);
return 0;
}
-/* $Id: hash.c,v 1.13 2004/02/27 06:07:55 reinelt Exp $
+/* $Id: hash.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
*
* hashes (associative arrays)
*
*
*
* $Log: hash.c,v $
+ * Revision 1.14 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.13 2004/02/27 06:07:55 reinelt
* hash improvements from Martin
*
#define DELTA_SLOTS 64
+static timeval __my_time_of_day;
+
+int gettimeofday_ex(timeval *tv, struct timezone *tz) {
+ if (tv==NULL) return -1;
+
+ if (__my_time_of_day.tv_usec == 0 && __my_time_of_day.tv_sec==0) {
+ gettimeofday_update();
+ }
+
+ tv->tv_sec = __my_time_of_day.tv_sec;
+ tv->tv_usec= __my_time_of_day.tv_usec;
+ return 0;
+}
+
+void gettimeofday_update(){
+ gettimeofday(&__my_time_of_day, NULL);
+}
+
// bsearch compare function for hash entries
static int hash_lookup_f (const void *a, const void *b)
hash_got_string:
// set timestamps
- gettimeofday(&Hash->time, NULL);
+ gettimeofday_ex(&Hash->time, NULL);
Item->time=Hash->time;
return Item;
if (--Item->root < 0) Item->root = DELTA_SLOTS-1;
// set first entry
- gettimeofday(&(Item->Slot[Item->root].time), NULL);
+ gettimeofday_ex(&(Item->Slot[Item->root].time), NULL);
Item->Slot[Item->root].val=number;
}
timeval now, *stamp;
int age;
+ gettimeofday_update();
+
if (key!=NULL) {
Item=hash_lookup(Hash, key, 1);
if (value) *value=Item?Item->val:NULL;
stamp=&Hash->time;
}
- gettimeofday(&now, NULL);
+ gettimeofday_ex(&now, NULL);
age = (now.tv_sec - stamp->tv_sec)*1000 + (now.tv_usec - stamp->tv_usec)/1000;
-/* $Id: hash.h,v 1.8 2004/02/27 06:07:55 reinelt Exp $
+/* $Id: hash.h,v 1.9 2004/03/03 03:47:04 reinelt Exp $
*
* hashes (associative arrays)
*
*
*
* $Log: hash.h,v $
+ * Revision 1.9 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.8 2004/02/27 06:07:55 reinelt
* hash improvements from Martin
*
double hash_get_delta (HASH *Hash, char *key, int delay);
double hash_get_regex (HASH *Hash, char *key, int delay);
void hash_destroy (HASH *Hash);
+
+int gettimeofday_ex(struct timeval *tv, struct timezone *tz);
+void gettimeofday_update();
+
#endif
-/* $Id: imon.c,v 1.4 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: imon.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
*
* imond/telmond data processing
*
*
*
* $Log: imon.c,v $
+ * Revision 1.5 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.4 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
int init(){
- char *s, *host;
+ char *pwd, *host, *answer;
int port;
int connect;
connect=service_connect(host,port);
- s=cfg_get (NULL, "Imon_Pass", NULL);
- if ((s!=NULL) && (*s!='\0')) { // Passwort senden
+ pwd=cfg_get (NULL, "Imon_Pass", NULL);
+ if ((pwd!=NULL) && (*pwd!='\0')) { // Passwort senden
char buf[40];
- sprintf(buf,"pass %s",s);
+ sprintf(buf,"pass %s",pwd);
send_command(connect,buf);
- s=get_answer(connect);
+ answer=get_answer(connect);
}
+ free(host);
+ free(pwd):
+
return connect;
}
int ImonCh(int index, struct imonchannel *ch, int token_usage[]) {
static int err[CHANNELS+1];
- char *s;
+ char *cfg_string;
char buf[40];
int result=0;
if ((*ch).max_in == 0){ // not initializied
sprintf(buf, "Imon_%d_Dev", index);
- s=cfg_get(NULL, buf, NULL);
- if (s==NULL) {
+ cfg_string=cfg_get(NULL, buf, NULL);
+ if (cfg_string==NULL) {
error ("Imon: no 'Imon_%i_Dev' entry in %s", index, cfg_source());
err[index]=1;
return -1;
}
- strcpy((*ch).dev,s);
+ strcpy((*ch).dev,cfg_string);
+ free(cfg_string);
sprintf(buf, "Imon_%d_MaxIn", index);
cfg_number(NULL, buf,768,1,65536,&(*ch).max_in);
void phonebook(char *number){
FILE * fp;
char line[256];
+ char* filename;
- fp = fopen (cfg_get (NULL, "Telmon_Phonebook","/etc/phonebook"), "r");
-
+ fp = fopen (filename=cfg_get (NULL, "Telmon_Phonebook","/etc/phonebook"), "r");
+ free(filename);
if (! fp) return;
while (fgets (line, 128, fp)){
return -1;
}
strcpy(host,s);
+ free(s);
if (cfg_number(NULL, "Telmon_Port",5000,1,65536,&port)<0){
telmond_fd=-1;
-/* $Id: layout.c,v 1.9 2004/02/01 19:37:40 reinelt Exp $
+/* $Id: layout.c,v 1.10 2004/03/03 03:47:04 reinelt Exp $
*
* new layouter framework
*
*
*
* $Log: layout.c,v $
+ * Revision 1.10 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.9 2004/02/01 19:37:40 reinelt
* got rid of every strtok() incarnation.
*
if (i==2 && l[n]=='\0') {
widget=cfg_get(section, l, NULL);
if (widget!=NULL && *widget!='\0') {
- layout_addItem (widget, row, col);
+ layout_addItem (widget, row, col);
}
+ free(widget);
}
// next field
l=p?p+1:NULL;
}
free (list);
-
+ free(section);
return 0;
}
-/* $Id: lcd4linux.c,v 1.64 2004/02/27 07:06:25 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.65 2004/03/03 03:47:04 reinelt Exp $
*
* LCD4Linux
*
*
*
* $Log: lcd4linux.c,v $
+ * Revision 1.65 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.64 2004/02/27 07:06:25 reinelt
* new function 'qprintf()' (simple but quick snprintf() replacement)
*
exit (1);
}
- snprintf (section, sizeof(section), "Display:%s", display);
+ qprintf(section, sizeof(section), "Display:%s", display);
+ free(display);
driver=cfg_get(section, "Driver", NULL);
if (driver==NULL || *driver=='\0') {
error ("missing '%s.Driver' entry in %s!", section, cfg_source());
pid_exit(PIDFILE);
exit (1);
}
+ free(driver);
// check for new-style layout
layout=cfg_get(NULL, "Layout", NULL);
}
layout_init(layout);
+ free(layout);
// maybe go into interactive mode
if (interactive) {
if (!quiet) hello();
#endif
drv_quit();
-
pid_exit(PIDFILE);
cfg_exit();
-
+ plugin_exit();
+ timer_exit();
if (got_signal==SIGHUP) {
long fd;
debug ("restarting...");
error ("execv() failed: %s", strerror(errno));
exit(1);
}
+
+ for(c=0;my_argv[c]!=NULL;c++) {
+ free(my_argv[c]);
+ }
+ free(my_argv);
exit (0);
}
-/* $Id: lock.c,v 1.6 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: lock.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
*
* UUCP style locking
*
*
*
* $Log: lock.c,v $
+ * Revision 1.7 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.6 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
#include "debug.h"
#include "lock.h"
+#include "qprintf.h"
pid_t lock_port (char *Port)
*p='_';
}
- snprintf(lockfile, sizeof(lockfile), LOCK, port);
- snprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
+ qprintf(lockfile, sizeof(lockfile), LOCK, port);
+ qprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
free (port);
*p='_';
}
- snprintf(lockfile, sizeof(lockfile), LOCK, port);
+ qprintf(lockfile, sizeof(lockfile), LOCK, port);
unlink (lockfile);
free (port);
-/* $Id: mail.c,v 1.15 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: mail.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
*
* email specific functions
*
*
*
* $Log: mail.c,v $
+ * Revision 1.16 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.15 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
int last_line_blank1; // Was the last line blank?
struct stat fst;
int rc;
+ char *s:
+ int i;
char *txt;
char txt1[100];
}
if (now[index] > 0) { /* not first time, delay */
sprintf(txt1, "Delay_e%d", index);
- if (time(NULL)<=now[index]+atoi(cfg_get(NULL, txt1, "5")))
+ s= cfg_get(NULL, txt1, "5");
+ i=now[index]+atoi(s);
+ free(s);
+ if (time(NULL)<=i)
return 0; // no more then 5/Delay_eX seconds after last check?
}
time(&now[index]); // for Mailbox #index
/*
Build the filename from the config
*/
- snprintf(buffer, sizeof(buffer), "Mailbox%d", index);
+ qprintf(buffer, sizeof(buffer), "Mailbox%d", index);
fnp1=cfg_get(NULL, buffer, NULL);
if (fnp1==NULL || *fnp1=='\0') {
cfgmbx[index]=FALSE; // There is now entry for Mailbox #index
is it pop3, imap4 or nntp?
*/
rc = Mail_pop_imap_news(fnp1, num, unseen);
- if (rc == 0)
- return 0;
+ if (rc == 0) {
+ free(fnp1);
+ return 0;
+ }
else
cfgmbx[index] = FALSE; /* don't try again */
+
error ("Error getting stat of Mailbox%d", index);
return (-1);
}
mbxlt[index]=fst.st_mtime;
fstr=fopen(fnp1,"r");
-
if (fstr != NULL) {
txt=&txt1[0];
last_line_blank1=TRUE;
}
}
}
+ free(fnp1);
/* FIXME look at the Status of Mails */
*unseen = v1 - mbxnum[index];
if (*unseen < 0)
-/* $Id: mail2.c,v 1.12 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: mail2.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
*
* mail: pop3, imap, news functions
*
*
*
* $Log: mail2.c,v $
+ * Revision 1.13 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.12 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
int err;
int totg, unsg;
int first;
+ char *s;
*total = 0;
*unseen = 0;
- strcpy(buf, cfg_get(NULL, "Newsrc", ".newsrc"));
+ strcpy(buf, (s=cfg_get(NULL, "Newsrc", ".newsrc")));
if (*buf == 0 || ((fp = fopen(buf, "r")) == NULL)) {
error("Couldn't open .newsrc-file '%s'", buf);
+ free(s);
return -1;
}
-
+ free(s);
fd = open_socket(machine, port);
if (fd < 0)
{
-/* $Id: pid.c,v 1.3 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: pid.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
*
* PID file handling
*
*
*
* $Log: pid.c,v $
+ * Revision 1.4 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.3 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
#include "debug.h"
#include "pid.h"
-
+#include "qprintf.h"
int pid_init (const char *pidfile)
{
char buffer[16];
int fd, len, pid;
- snprintf(tmpfile, sizeof(tmpfile), "%s.%s", pidfile, "XXXXXX");
+ qprintf(tmpfile, sizeof(tmpfile), "%s.%s", pidfile, "XXXXXX");
if ((fd=mkstemp(tmpfile))==-1) {
error ("mkstemp(%s) failed: %s", tmpfile, strerror(errno));
return -1;
}
- snprintf (buffer, sizeof(buffer), "%d\n", (int)getpid());
+ qprintf(buffer, sizeof(buffer), "%d\n", (int)getpid());
if (write(fd, buffer, strlen(buffer))!=strlen(buffer)) {
error ("write(%s) failed: %s", tmpfile, strerror(errno));
close(fd);
-/* $Id: plugin.c,v 1.19 2004/02/18 14:45:42 nicowallmeier Exp $
+/* $Id: plugin.c,v 1.20 2004/03/03 03:47:04 reinelt Exp $
*
* plugin handler for the Evaluator
*
*
*
* $Log: plugin.c,v $
+ * Revision 1.20 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.19 2004/02/18 14:45:42 nicowallmeier
* Imon/Telmon plugin ported
*
int plugin_init_imon(void);
+void plugin_exit_math (void);
+void plugin_exit_string (void);
+void plugin_exit_cfg (void);
+void plugin_exit_uname (void);
+void plugin_exit_loadavg (void);
+void plugin_exit_proc_stat (void);
+void plugin_exit_cpuinfo (void);
+void plugin_exit_meminfo (void);
+void plugin_exit_netdev (void);
+void plugin_exit_ppp (void);
+void plugin_exit_dvb (void);
+void plugin_exit_i2c_sensors (void);
+void plugin_exit_xmms (void);
+void plugin_exit_imon(void);
+
int plugin_init (void)
{
plugin_init_math();
return 0;
}
-
+void plugin_exit(void) {
+ plugin_exit_math();
+ plugin_exit_string();
+ plugin_exit_cfg();
+ plugin_exit_uname();
+ plugin_exit_loadavg();
+ plugin_exit_proc_stat();
+ plugin_exit_cpuinfo();
+ plugin_exit_meminfo();
+ plugin_exit_netdev();
+ plugin_exit_ppp();
+ plugin_exit_dvb();
+ plugin_exit_i2c_sensors();
+ plugin_exit_xmms();
+ plugin_exit_imon();
+
+ DeleteFunctions();
+ DeleteVariables();
+}
-/* $Id: plugin.h,v 1.1 2003/12/19 05:35:14 reinelt Exp $
+/* $Id: plugin.h,v 1.2 2004/03/03 03:47:04 reinelt Exp $
*
* plugin handler for the Evaluator
*
*
*
* $Log: plugin.h,v $
+ * Revision 1.2 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.1 2003/12/19 05:35:14 reinelt
* renamed 'client' to 'plugin'
*
#define _PLUGIN_H_
int plugin_init (void);
-
+void plugin_exit(void);
#endif
-/* $Id: plugin_cfg.c,v 1.5 2004/02/01 19:37:40 reinelt Exp $
+/* $Id: plugin_cfg.c,v 1.6 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for config file access
*
*
*
* $Log: plugin_cfg.c,v $
+ * Revision 1.6 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.5 2004/02/01 19:37:40 reinelt
* got rid of every strtok() incarnation.
*
} else {
expression=cfg_get_raw (section, l, "");
if (expression!=NULL && *expression!='\0') {
- if (Eval(expression, &result)==0) {
- debug ("Variable %s = '%s' (%f)", l, R2S(&result), R2N(&result));
- SetVariable (l, &result);
- DelResult (&result);
- } else {
- error ("error evaluating variable '%s' from %s", list, cfg_source());
- }
+ if (Eval(expression, &result)==0) {
+ debug ("Variable %s = '%s' (%f)", l, R2S(&result), R2N(&result));
+ SetVariable (l, &result);
+ DelResult (&result);
+ } else {
+ error ("error evaluating variable '%s' from %s", list, cfg_source());
+ }
}
}
l=p?p+1:NULL;
// buffer starts with '.', so cut off first char
value=cfg_get("", buffer+1, "");
-
+
+ // store result
+ SetResult(&result, R_STRING, value);
+
// free buffer again
free (buffer);
- // store result
- SetResult(&result, R_STRING, value);
+ free(value);
}
return 0;
}
+
+void plugin_exit_cfg(void)
+{
+
+}
-/* $Id: plugin_cpuinfo.c,v 1.7 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for /proc/cpuinfo parsing
*
*
*
* $Log: plugin_cpuinfo.c,v $
+ * Revision 1.8 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.7 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
AddFunction ("cpuinfo", 1, my_cpuinfo);
return 0;
}
+
+void plugin_exit_cpuinfo(void)
+{
+ hash_destroy(&CPUinfo);
+}
-/* $Id: plugin_dvb.c,v 1.2 2004/02/16 13:03:37 reinelt Exp $
+/* $Id: plugin_dvb.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for DVB status
*
*
*
* $Log: plugin_dvb.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/02/16 13:03:37 reinelt
* compile problem with missing frontend.h fixed
*
return 0;
}
+void plugin_exit_dvb(void)
+{
+ hash_destroy(&DVB);
+}
-/* $Id: plugin_i2c_sensors.c,v 1.12 2004/02/16 08:19:44 reinelt Exp $
+/* $Id: plugin_i2c_sensors.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
*
* I2C sensors plugin
*
*
*
* $Log: plugin_i2c_sensors.c,v $
+ * Revision 1.13 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.12 2004/02/16 08:19:44 reinelt
* i2c_sensors patch from Xavier
*
debug("if i2c_sensors doesn't work, double check this value !");
path = realloc(path, strlen(path_cfg)+1);
strcpy(path, path_cfg);
- free(path_cfg);
+
}
+ free(path_cfg);
// we activate the function only if there's a possibly path found
if (path!=NULL) {
return 0;
}
+
+void plugin_exit_i2c_sensors(void)
+{
+ hash_destroy(&I2Csensors);
+}
-/* $Id: plugin_imon.c,v 1.2 2004/02/22 17:35:41 reinelt Exp $
+/* $Id: plugin_imon.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* imond/telmond data processing
*
*
*
* $Log: plugin_imon.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/02/22 17:35:41 reinelt
* some fixes for generic graphic driver and T6963
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
#include "plugin.h"
#include "cfg.h"
#include "hash.h"
+#include "qprintf.h"
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h> /* decl of inet_addr() */
#include <sys/socket.h>
+
static HASH TELMON = { 0, };
static HASH IMON = { 0, };
hash_set (&TELMON, "time", time);
date[4]='\0';
date[7]='\0';
- snprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
+ qprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
hash_set (&TELMON, "number", number);
hash_set (&TELMON, "msn", msn);
hash_set (&TELMON, "date", time);
err++;
} else if ((ipass!=NULL) && (*ipass!='\0')) { // Passwort senden
char buf[40];
- snprintf(buf,sizeof(buf),"pass %s",ipass);
+ qprintf(buf,sizeof(buf),"pass %s",ipass);
send_command(fd,buf);
get_answer(fd);
}
char *s;
int age;
- snprintf(buf,sizeof(buf),"rate %s in",channel);
+ qprintf(buf,sizeof(buf),"rate %s in",channel);
// reread every half sec only
age=hash_age(&IMON, buf, NULL);
if (err) return -1;
- snprintf(buf, sizeof(buf), "rate %s", channel);
+ qprintf(buf, sizeof(buf), "rate %s", channel);
s=get_value(buf);
if (sscanf(s,"%s %s",in, out)!=2) return -1;
- snprintf(buf, sizeof(buf), "rate %s in", channel);
+ qprintf(buf, sizeof(buf), "rate %s in", channel);
hash_set (&IMON, buf , in);
- snprintf(buf, sizeof(buf), "rate %s out", channel);
+ qprintf(buf, sizeof(buf), "rate %s out", channel);
hash_set (&IMON, buf , out);
return 0;
return;
}
- snprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
+ qprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
val=hash_get(&IMON, buf);
if (val==NULL) val="";
telmon='\0';
}
strcpy(thost,s);
+ free(s);
if ((telmon=='\01') && (cfg_number("Telmon", "Port",5001,1,65536,&tport)<0)){
error ("[Telmon] no valid port definition");
s=cfg_get ("Telmon", "Phonebook","/etc/phonebook");
strcpy(phoneb,s);
+ free(s);
s=cfg_get ("Imon", "Host", "127.0.0.1");
if (*s=='\0') {
imon='\0';
}
strcpy(ihost,s);
+ free(s);
if ((imon=='\01') && (cfg_number("Imon", "Port",5000,1,65536,&iport)<0)){
error ("[Imon] no valid port definition");
s=cfg_get ("Imon", "Pass", "");
strcpy(ipass,s);
+ free(s);
if (telmon=='\1') AddFunction ("telmon", 1, my_telmon);
if (imon=='\1'){
return 0;
}
+
+void plugin_exit_imon(void)
+{
+ hash_destroy(&TELMON);
+ hash_destroy(&IMON);
+}
-/* $Id: plugin_loadavg.c,v 1.3 2004/01/30 07:12:35 reinelt Exp $
+/* $Id: plugin_loadavg.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for load average
*
*
*
* $Log: plugin_loadavg.c,v $
+ * Revision 1.4 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.3 2004/01/30 07:12:35 reinelt
* HD44780 busy-flag support from Martin Hejl
* loadavg() uClibc replacement from Martin Heyl
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <fcntl.h>
#include "debug.h"
static void my_loadavg (RESULT *result, RESULT *arg1)
{
- int nelem, index;
- double loadavg[3];
+ static int nelem;
+ int index,age;
+ static double loadavg[3];
+ static struct timeval last_value;
+ struct timeval now;
- nelem=getloadavg(loadavg, 3);
- if (nelem<0) {
- error ("getloadavg() failed!");
- SetResult(&result, R_STRING, "");
- return;
+ gettimeofday(&now,NULL);
+
+ age = (now.tv_sec - last_value.tv_sec)*1000 + (now.tv_usec - last_value.tv_usec)/1000;
+ // reread every 10 msec only
+ if (age==0 || age>10) {
+
+ nelem=getloadavg(loadavg, 3);
+ if (nelem<0) {
+ error ("getloadavg() failed!");
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+ last_value=now;
}
index=R2N(arg1);
SetResult(&result, R_STRING, "");
return;
}
+
SetResult(&result, R_NUMBER, &(loadavg[index-1]));
return;
return 0;
}
+void plugin_exit_loadavg(void)
+{
+}
-/* $Id: plugin_math.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_math.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* math plugin
*
*
*
* $Log: plugin_math.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
return 0;
}
+void plugin_exit_math(void)
+{
+}
-/* $Id: plugin_meminfo.c,v 1.5 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_meminfo.c,v 1.6 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for /proc/meminfo parsing
*
*
*
* $Log: plugin_meminfo.c,v $
+ * Revision 1.6 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.5 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
return 0;
}
+
+void plugin_exit_meminfo(void)
+{
+ hash_destroy(&MemInfo);
+}
-/* $Id: plugin_netdev.c,v 1.4 2004/02/15 07:23:04 reinelt Exp $
+/* $Id: plugin_netdev.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for /proc/net/dev parsing
*
*
*
* $Log: plugin_netdev.c,v $
+ * Revision 1.5 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.4 2004/02/15 07:23:04 reinelt
* bug in netdev parsing fixed
*
#include "plugin.h"
#include "hash.h"
+#include "qprintf.h"
static HASH NetDev = { 0, };
{
char key[32];
- snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
+ qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
hash_set_delta (&NetDev, key, val);
}
return 0;
}
+void plugin_exit_netdev(void)
+{
+ hash_destroy(&NetDev);
+}
-/* $Id: plugin_ppp.c,v 1.2 2004/01/28 06:43:31 reinelt Exp $
+/* $Id: plugin_ppp.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for ppp throughput
*
*
*
* $Log: plugin_ppp.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/01/28 06:43:31 reinelt
* plugin_ppp finished.
*
#include "debug.h"
#include "plugin.h"
#include "hash.h"
-
+#include "qprintf.h"
#ifdef HAVE_NET_IF_PPP_H
for (unit=0; unit<8; unit++) {
memset (&req, 0, sizeof (req));
req.stats_ptr = (caddr_t) &req.stats;
- snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit);
+ qprintf(req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit);
if (ioctl(fd, SIOCGPPPSTATS, &req) == 0) {
ibytes=req.stats.p.ppp_ibytes;
} else {
ibytes=obytes=0;
}
- snprintf (key, sizeof(key), "Rx:%d", unit);
- snprintf (val, sizeof(val), "%d", ibytes);
+ qprintf(key, sizeof(key), "Rx:%d", unit);
+ qprintf(val, sizeof(val), "%d", ibytes);
hash_set_delta (&PPP, key, val);
- snprintf (key, sizeof(key), "Tx:%d", unit);
- snprintf (val, sizeof(val), "%d", obytes);
+ qprintf(key, sizeof(key), "Tx:%d", unit);
+ qprintf(val, sizeof(val), "%d", obytes);
hash_set_delta (&PPP, key, val);
}
return 0;
}
+void plugin_exit_ppp(void)
+{
+ hash_destroy(&PPP);
+}
-/* $Id: plugin_proc_stat.c,v 1.15 2004/02/04 19:10:51 reinelt Exp $
+/* $Id: plugin_proc_stat.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for /proc/stat parsing
*
*
*
* $Log: plugin_proc_stat.c,v $
+ * Revision 1.16 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.15 2004/02/04 19:10:51 reinelt
* Crystalfontz driver nearly finished
*
#include "debug.h"
#include "plugin.h"
#include "hash.h"
+#include "qprintf.h"
static HASH Stat = { 0, };
{
char key[32];
- snprintf (key, sizeof(key), "%s.%s", key1, key2);
+ qprintf(key, sizeof(key), "%s.%s", key1, key2);
hash_set1 (key, val);
}
{
char key[32];
- snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
+ qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
hash_set1 (key, val);
}
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
if (i==0)
- snprintf(num, sizeof(num), "sum");
+ strncpy(num,"sum",sizeof(num));
else
- snprintf(num, sizeof(num), "%d", i-1);
+ qprintf(num, sizeof(num), "%d", i-1);
hash_set2 ("intr", num, beg);
beg=end?end+1:NULL;
}
key = R2S(arg2);
delay = R2N(arg3);
- snprintf (buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
+ qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
value = hash_get_regex(&Stat, buffer, delay);
SetResult(&result, R_NUMBER, &value);
AddFunction ("disk", 3, my_disk);
return 0;
}
+
+void plugin_exit_proc_stat(void)
+{
+ hash_destroy(&Stat);
+}
-/* $Id: plugin_sample.c,v 1.4 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: plugin_sample.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
*
* plugin template
*
*
*
* $Log: plugin_sample.c,v $
+ * Revision 1.5 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.4 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
return 0;
}
+void plugin_exit_sample(void)
+{
+
+}
-/* $Id: plugin_string.c,v 1.3 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_string.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
*
* string plugin
*
*
*
* $Log: plugin_string.c,v $
+ * Revision 1.4 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.3 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
return 0;
}
+void plugin_exit_string(void)
+{
+}
-/* $Id: plugin_uname.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_uname.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for uname() syscall
*
*
*
* $Log: plugin_uname.c,v $
+ * Revision 1.3 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.2 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
return 0;
}
+void plugin_exit_uname(void)
+{
+}
-/* $Id: plugin_xmms.c,v 1.8 2004/02/05 23:58:18 mkeil Exp $
+/* $Id: plugin_xmms.c,v 1.9 2004/03/03 03:47:04 reinelt Exp $
*
* XMMS-Plugin for LCD4Linux
* Copyright 2003 Markus Keil <markus_keil@t-online.de>
*
*
* $Log: plugin_xmms.c,v $
+ * Revision 1.9 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.8 2004/02/05 23:58:18 mkeil
* Fixed/Optimized Hashage-timings
*
return 0;
}
+
+void plugin_exit_xmms(void)
+{
+ hash_destroy(&xmms);
+}
-/* $Id: seti.c,v 1.13 2004/01/29 04:40:03 reinelt Exp $
+/* $Id: seti.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
*
* seti@home specific functions
*
*
*
* $Log: seti.c,v $
+ * Revision 1.14 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.13 2004/01/29 04:40:03 reinelt
* every .c file includes "config.h" now
*
if (dir==NULL || *dir=='\0') {
error ("no 'SetiDir' entry in %s!\n", cfg_source());
fd=-1;
+ free(dir);
return -1;
}
if (strlen(dir)>sizeof(fn)-sizeof(STATEFILE)-2) {
error ("entry 'SetiDir' too long in %s!\n", cfg_source());
fd=-1;
+ free(dir);
return -1;
}
strcpy(fn, dir);
strcat(fn, "/");
strcat(fn, STATEFILE);
+ free(dir);
}
fd = open(fn, O_RDONLY);
-/* $Id: timer.c,v 1.4 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: timer.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
*
* generic timer handling
*
*
*
* $Log: timer.c,v $
+ * Revision 1.5 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.4 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
return 0;
}
+
+void timer_exit() {
+ if (nTimers>0) {
+ nTimers=0;
+ free(Timers);;
+ }
+}
-/* $Id: timer.h,v 1.1 2004/01/13 08:18:20 reinelt Exp $
+/* $Id: timer.h,v 1.2 2004/03/03 03:47:04 reinelt Exp $
*
* generic timer handling
*
*
*
* $Log: timer.h,v $
+ * Revision 1.2 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.1 2004/01/13 08:18:20 reinelt
* timer queues added
* liblcd4linux deactivated turing transformation to new layout
int timer_add (void(*callback)(void *data), void *data, int interval, int one_shot);
int timer_process (struct timespec *delay);
-
+void timer_exit();
#endif
-/* $Id: widget.c,v 1.12 2004/02/18 06:39:20 reinelt Exp $
+/* $Id: widget.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
*
* generic widget handling
*
*
*
* $Log: widget.c,v $
+ * Revision 1.13 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.12 2004/02/18 06:39:20 reinelt
* T6963 driver for graphic displays finished
*
return 0;
}
+void widget_unregister(void) {
+ int i;
+ for (i=0;i<nWidgets;i++) {
+ Widgets[i].class->quit(&(Widgets[i]));
+ }
+ free(Widgets);
+
+ free(Classes);
+
+ nWidgets=0;
+ nClasses=0;
+}
int widget_add (char *name, int row, int col)
{
if (class) free (class);
return -1;
}
-
+ free(section);
// lookup widget class
Class=NULL;
for (i=0; i<nClasses; i++) {
-/* $Id: widget.h,v 1.7 2004/01/14 11:33:00 reinelt Exp $
+/* $Id: widget.h,v 1.8 2004/03/03 03:47:04 reinelt Exp $
*
* generic widget handling
*
*
*
* $Log: widget.h,v $
+ * Revision 1.8 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.7 2004/01/14 11:33:00 reinelt
* new plugin 'uname' which does what it's called
* text widget nearly finished
int widget_register (WIDGET_CLASS *widget);
+void widget_unregister (void);
int widget_add (char *name, int row, int col);
#endif
-/* $Id: widget_bar.c,v 1.7 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: widget_bar.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
*
* bar widget handling
*
*
*
* $Log: widget_bar.c,v $
+ * Revision 1.8 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.7 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
int widget_bar_quit (WIDGET *Self) {
-
- if (Self->data) {
- free (Self->data);
- Self->data=NULL;
+ if (Self ) {
+ if (Self->data) free(Self->data);
+ Self->data=NULL;
}
return 0;
-/* $Id: widget_icon.c,v 1.7 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: widget_icon.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
*
* icon widget handling
*
*
*
* $Log: widget_icon.c,v $
+ * Revision 1.8 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.7 2004/02/15 21:43:43 reinelt
* T6963 driver nearly finished
* framework for graphic displays done
#include "timer.h"
#include "widget.h"
#include "widget_icon.h"
+#include "qprintf.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
unsigned char *map;
for (row=0; row<YRES; row++) {
- snprintf (key, sizeof(key), "Bitmap.Row%d", row+1);
+ qprintf(key, sizeof(key), "Bitmap.Row%d", row+1);
val=cfg_get(section, key, "");
map=Icon->bitmap+row;
n=0;
(*map)<<=1;
}
}
+ free(val);
}
}
int widget_icon_quit (WIDGET *Self)
{
- WIDGET_ICON *Icon = Self->data;
+ WIDGET_ICON *Icon;
- if (Self->data) {
- if (Icon->bitmap) free (Icon->bitmap);
- free (Self->data);
- Self->data=NULL;
+ if (Self) {
+ Icon = Self->data;
+ if (Icon) {
+ if (Icon->bitmap) free (Icon->bitmap);
+ free(Self->data);
+ Self->data=NULL;
+ }
}
return 0;
-/* $Id: widget_text.c,v 1.13 2004/02/18 06:39:20 reinelt Exp $
+/* $Id: widget_text.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
*
* simple text widget handling
*
*
*
* $Log: widget_text.c,v $
+ * Revision 1.14 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.13 2004/02/18 06:39:20 reinelt
* T6963 driver for graphic displays finished
*
int widget_text_quit (WIDGET *Self) {
-
- if (Self->data) {
- free (Self->data);
- Self->data=NULL;
+ WIDGET_TEXT *Text;
+ if (Self) {
+ Text=Self->data;
+ if (Self->data) {
+ if (Text->preval) free(Text->preval);
+ if (Text->postval) free(Text->postval);
+ if (Text->value) free(Text->value);
+ if (Text->buffer) free(Text->buffer);
+ free (Self->data);
+ Self->data=NULL;
+ }
}
-
return 0;
}
-/* $Id: wifi.c,v 1.6 2004/01/29 04:40:03 reinelt Exp $
+/* $Id: wifi.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
*
* WIFI specific functions
*
*
*
* $Log: wifi.c,v $
+ * Revision 1.7 2004/03/03 03:47:04 reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
* Revision 1.6 2004/01/29 04:40:03 reinelt
* every .c file includes "config.h" now
*
*signal=ws;
*link=wl;
*noise=wn;
+ free(interface);
return 0;
}