]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2003-09-09 06:54:43 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 9 Sep 2003 06:54:43 +0000 (06:54 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 9 Sep 2003 06:54:43 +0000 (06:54 +0000)
new function 'cfg_number()'

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@233 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

15 files changed:
Crystalfontz.c
Cwlinux.c
HD44780.c
M50530.c
MatrixOrbital.c
PalmPilot.c
Raster.c
USBLCD.c
XWindow.c
cfg.c
cfg.h
filter.c
lcd4linux.c
parport.c
processor.c

index 8e11d3590718647390b01b72934cdd460ac7a649..5b4fe6f25fd809e1e706ff5b524d2d79d6f18dad 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: Crystalfontz.c,v 1.13 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: Crystalfontz.c,v 1.14 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for display modules from Crystalfontz
  *
@@ -19,6 +19,9 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  * $Log: Crystalfontz.c,v $
+ * Revision 1.14  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.13  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -145,7 +148,7 @@ static int CF_backlight (void)
   char buffer[3];
   int  backlight;
 
-  backlight=atoi(cfg_get("Backlight","0"));
+  if (cfg_number("Backlight", 0, 0, 100, &backlight)<0) return -1;
   snprintf (buffer, 3, "\016%c", backlight);
   CF_write (buffer, 2);
   return 0;
@@ -157,7 +160,7 @@ static int CF_contrast (void)
   char buffer[3];
   int  contrast;
 
-  contrast=atoi(cfg_get("Contrast","50"));
+  if (cfg_number("Contrast", 50, 0, 100, &contrast)<0) return -1;
   snprintf (buffer, 3, "\017%c", contrast);
   CF_write (buffer, 2);
   return 0;
@@ -192,7 +195,7 @@ static int CF_clear (int full)
 static int CF_init (LCD *Self)
 {
   char *port;
-  char *speed;
+  int speed;
 
   Lcd=*Self;
 
@@ -216,9 +219,10 @@ static int CF_init (LCD *Self)
   }
   Port=strdup(port);
 
-  speed=cfg_get("Speed","19200");
   
-  switch (atoi(speed)) {
+  if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1;
+  
+  switch (speed) {
   case 1200:
     Speed=B1200;
     break;
@@ -232,11 +236,11 @@ static int CF_init (LCD *Self)
     Speed=B19200;
     break;
   default:
-    error ("Crystalfontz: unsupported speed '%s' in %s", speed, cfg_source());
+    error ("Crystalfontz: unsupported speed '%d' in %s", speed, cfg_source());
     return -1;
   }    
 
-  debug ("using port %s at %d baud", Port, atoi(speed));
+  debug ("using port %s at %d baud", Port, speed);
 
   Device=CF_open();
   if (Device==-1) return -1;
index bd61317ccc1a257b06ec227412e2366803bc415a..affffc9eca5c7bfa71a110487d48ac688a1247e5 100644 (file)
--- a/Cwlinux.c
+++ b/Cwlinux.c
@@ -1,4 +1,4 @@
-/* $Id: Cwlinux.c,v 1.12 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: Cwlinux.c,v 1.13 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for Cwlinux serial display modules
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: Cwlinux.c,v $
+ * Revision 1.13  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.12  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -242,10 +245,8 @@ static void CW_Brightness(void)
 {
   int level;
   char cmd[5]="\376A_\375";
-
-  level=atoi(cfg_get("Brightness","8"));
-  if (level<0) level=0;
-  if (level>8) level=8;
+  
+  if (cfg_number("Brightness", 8, 0, 8, &level)<0) return;
   
   switch (level) {
   case 0:
@@ -268,7 +269,7 @@ static void CW_Brightness(void)
 int CW_init(LCD * Self)
 {
   char *port;
-  char *speed;
+  int speed;
   // char buffer[16];
   
   Lcd = *Self;
@@ -293,9 +294,8 @@ int CW_init(LCD * Self)
   }
   Port = strdup(port);
 
-  speed = cfg_get("Speed","19200");
-
-  switch (atoi(speed)) {
+  if (cfg_number("Speed", 19200, 9600,19200, &speed)<0) return -1;
+  switch (speed) {
   case 9600:
     Speed = B9600;
     break;
@@ -303,11 +303,11 @@ int CW_init(LCD * Self)
     Speed = B19200;
     break;
   default:
-    error("Cwlinux: unsupported speed '%s' in %s", speed, cfg_source());
+    error("Cwlinux: unsupported speed '%d' in %s", speed, cfg_source());
     return -1;
   }
 
-  debug("using port %s at %d baud", Port, atoi(speed));
+  debug("using port %s at %d baud", Port, speed);
 
   Device = CW_open();
   if (Device == -1)
index 5ba23589f81d3abe34a20902f31ebc29be859176..0fe36a58c510125756fad1c474b419937e0ba36a 100644 (file)
--- a/HD44780.c
+++ b/HD44780.c
@@ -1,4 +1,4 @@
-/* $Id: HD44780.c,v 1.36 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: HD44780.c,v 1.37 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for display modules based on the HD44780 chip
  *
@@ -27,6 +27,9 @@
  *
  *
  * $Log: HD44780.c,v $
+ * Revision 1.37  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.36  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -400,7 +403,7 @@ int HD_clear (int full)
 int HD_init (LCD *Self)
 {
   int rows=-1, cols=-1, gpos=-1;
-  char *s, *e;
+  char *s;
   
   s=cfg_get("Size",NULL);
   if (s==NULL || *s=='\0') {
@@ -411,30 +414,16 @@ int HD_init (LCD *Self)
     error ("HD44780: bad size '%s'",s);
     return -1;
   }
-
-  s=cfg_get ("GPOs",NULL);
-  if (s==NULL) {
-    gpos=0;
-  }
-  else {
-    gpos=strtol(s, &e, 0);
-    if (*e!='\0' || gpos<0 || gpos>8) {
-      error ("HD44780: bad GPOs '%s' in %s", s, cfg_source());
-      return -1;
-    }    
-  }
   
-  s=cfg_get("Controllers", "1");
-  Controllers=strtol(s, &e, 0);
-  if (*e!='\0' || Controllers<1 || Controllers>2) {
-    error ("HD44780: bad Controllers '%s' in %s, should be '1' or '2'", s, cfg_source());
-    return -1;
-  }    
+  if (cfg_number("GPOs", 0, 0, 8, &gpos)<0) return -1;
+  info ("HD44780: controlling %d GPO's", gpos);
+
+  if (cfg_number("Controllers", 1, 1, 2, &Controllers)<0) return -1;
   info ("wiring: using display with %d controllers", Controllers);
   
   // current controller
   Controller=1;
-
+  
   Self->rows=rows;
   Self->cols=cols;
   Self->gpos=gpos;
@@ -447,15 +436,14 @@ int HD_init (LCD *Self)
     error ("HD44780: framebuffer could not be allocated: malloc() failed");
     return -1;
   }
-
-  s=cfg_get("Bits", "8");
-  Bits=strtol(s, &e, 0);
-  if (*e!='\0' || (Bits!=4 && Bits!=8)) {
+  
+  if (cfg_number("Bits", 8, 4, 8, &Bits)<0) return -1;
+  if (Bits!=4 && Bits!=8) {
     error ("HD44780: bad Bits '%s' in %s, should be '4' or '8'", s, cfg_source());
     return -1;
   }    
   info ("wiring: using %d bit mode", Bits);
-
+  
   if (Bits==8) {
     if ((SIGNAL_RS      = parport_wire_ctrl ("RS",      "AUTOFD"))==0xff) return -1;
     if ((SIGNAL_RW      = parport_wire_ctrl ("RW",      "GND")   )==0xff) return -1;
index 1544a252b9ecfd8facb0ff70f603f7c7d76f3223..0fa506d150d1c48b4fc2f284372e330feee6a1f5 100644 (file)
--- a/M50530.c
+++ b/M50530.c
@@ -1,4 +1,4 @@
-/* $Id: M50530.c,v 1.12 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: M50530.c,v 1.13 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for display modules based on the M50530 chip
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: M50530.c,v $
+ * Revision 1.13  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.12  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -179,7 +182,7 @@ int M5_clear (int full)
 int M5_init (LCD *Self)
 {
   int rows=-1, cols=-1, gpos=-1;
-  char *s, *e;
+  char *s;
   
   s=cfg_get("Size",NULL);
   if (s==NULL || *s=='\0') {
@@ -191,16 +194,7 @@ int M5_init (LCD *Self)
     return -1;
   }
 
-  s=cfg_get ("GPOs",NULL);
-  if (s==NULL) {
-    gpos=0;
-  } else {
-    gpos=strtol(s, &e, 0);
-    if (*e!='\0' || gpos<0 || gpos>8) {
-      error ("M50530: bad GPOs '%s' in %s", s, cfg_source());
-      return -1;
-    }    
-  }
+  if (cfg_number("GPOs", 0, 0, 8, &gpos)<0) return -1;
   
   Self->rows=rows;
   Self->cols=cols;
index f27b04a0ca372e210580fe79dae0ec8f516ab96d..2c0a193735c0cb223b08a11c5c0d975b91c6beaa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: MatrixOrbital.c,v 1.36 2003/09/09 05:30:33 reinelt Exp $
+/* $Id: MatrixOrbital.c,v 1.37 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for Matrix Orbital serial display modules
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: MatrixOrbital.c,v $
+ * Revision 1.37  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.36  2003/09/09 05:30:33  reinelt
  * even more icons stuff
  *
@@ -255,7 +258,7 @@ static int MO_contrast (void)
   char buffer[4];
   int  contrast;
 
-  contrast=atoi(cfg_get("Contrast","160"));
+  if (cfg_number("Contrast", 160, 0, 255, &contrast)<0) return -1;
   snprintf (buffer, 4, "\376P%c", contrast);
   MO_write (buffer, 3);
   return 0;
@@ -317,7 +320,7 @@ int MO_clear2 (int full)
 static int MO_init (LCD *Self, int protocol)
 {
   char *port;
-  char *s, *e;
+  int speed;
 
   Lcd=*Self;
 
@@ -341,9 +344,8 @@ static int MO_init (LCD *Self, int protocol)
   }
   Port=strdup(port);
 
-  s=cfg_get("Speed","19200");
-  
-  switch (atoi(s)) {
+  if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1;
+  switch (speed) {
   case 1200:
     Speed=B1200;
     break;
@@ -357,28 +359,23 @@ static int MO_init (LCD *Self, int protocol)
     Speed=B19200;
     break;
   default:
-    error ("MatrixOrbital: unsupported speed '%s' in %s", s, cfg_source());
+    error ("MatrixOrbital: unsupported speed '%d' in %s", speed, cfg_source());
     return -1;
   }    
-
-  debug ("using port %s at %d baud", Port, atoi(s));
-
+  
+  debug ("using port %s at %d baud", Port, speed);
+  
   Device=MO_open();
   if (Device==-1) return -1;
 
-  s=cfg_get("Icons", "0");
-  Icons=strtol(s, &e, 0);
-  if (*e!='\0' || Icons<0 || Icons>8) {
-    error ("MatrixOrbital: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source());
-    return -1;
-  }    
+  if (cfg_number("Icons", 0, 0, 8, &Icons)<0) return -1;
   if (Icons>0) {
     info ("reserving %d of %d user-defined characters for icons", Icons, CHARS);
     icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, MO_define_char);
     Self->icons=Icons;
     Lcd.icons=Icons;
   }
-
+  
   bar_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS-Icons);
   bar_add_segment(  0,  0,255, 32); // ASCII  32 = blank
   bar_add_segment(255,255,255,255); // ASCII 255 = block
index 7b1a8bba9de412163be05446d7a035d531cbe248..502374f904dd3916237a7733f7a9dcf225ed08b9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: PalmPilot.c,v 1.11 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: PalmPilot.c,v 1.12 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for 3Com Palm Pilot
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: PalmPilot.c,v $
+ * Revision 1.12  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.11  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -214,7 +217,8 @@ int Palm_clear (int full)
 
 int Palm_init (LCD *Self)
 {
-  char *port, *speed, *s;
+  char *port, *s;
+  int speed;
   int rows=-1, cols=-1;
   int xres=1, yres=-1;
 
@@ -230,9 +234,9 @@ int Palm_init (LCD *Self)
   }
   Port=strdup(port);
 
-  speed=cfg_get("Speed","19200");
+  if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1;
   
-  switch (atoi(speed)) {
+  switch (speed) {
   case 1200:
     Speed=B1200;
     break;
@@ -249,11 +253,11 @@ int Palm_init (LCD *Self)
     Speed=B19200;
     break;
   default:
-    error ("PalmPilot: unsupported speed '%s' in %s", speed, cfg_source());
+    error ("PalmPilot: unsupported speed '%d' in %s", speed, cfg_source());
     return -1;
   }    
 
-  debug ("using port %s at %d baud", Port, atoi(speed));
+  debug ("using port %s at %d baud", Port, speed);
 
   if (sscanf(s=cfg_get("size","20x4"), "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
     error ("PalmPilot: bad size '%s'", s);
@@ -277,7 +281,7 @@ int Palm_init (LCD *Self)
   if (rgap<0) rgap=pixel+pgap;
   if (cgap<0) cgap=pixel+pgap;
 
-  border=atoi(cfg_get("border","0"));
+  if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1;
 
   if (pix_init (rows, cols, xres, yres)!=0) {
     error ("PalmPilot: pix_init(%d, %d, %d, %d) failed", rows, cols, xres, yres);
index 631074bf23737a6dad51693ecdeae535effe472b..99a63c1845c9674e120c19b53bbd629f5ba575fe 100644 (file)
--- a/Raster.c
+++ b/Raster.c
@@ -1,4 +1,4 @@
-/* $Id: Raster.c,v 1.25 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: Raster.c,v 1.26 2003/09/09 06:54:43 reinelt Exp $
  *
  * driver for raster formats
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: Raster.c,v $
+ * Revision 1.26  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.25  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -369,7 +372,7 @@ int Raster_init (LCD *Self)
   if (rgap<0) rgap=pixel+pgap;
   if (cgap<0) cgap=pixel+pgap;
 
-  border=atoi(cfg_get("border","0"));
+  if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1;
 
   if (sscanf(s=cfg_get("foreground","#102000"), "#%x", &foreground)!=1) {
     error ("Raster: bad foreground color '%s'", s);
index 54a0c02ff36fb2d3daa8f38797c28746562136b4..bad43a125e85cc49f27e3c2c3c2caa55b9a60dde 100644 (file)
--- a/USBLCD.c
+++ b/USBLCD.c
@@ -1,4 +1,4 @@
-/* $Id: USBLCD.c,v 1.13 2003/09/09 05:30:34 reinelt Exp $
+/* $Id: USBLCD.c,v 1.14 2003/09/09 06:54:43 reinelt Exp $
  *
  * Driver for USBLCD ( see http://www.usblcd.de )
  * This Driver is based on HD44780.c
@@ -22,6 +22,9 @@
  *
  *
  * $Log: USBLCD.c,v $
+ * Revision 1.14  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.13  2003/09/09 05:30:34  reinelt
  * even more icons stuff
  *
@@ -224,7 +227,7 @@ int USBLCD_clear (int full)
 int USBLCD_init (LCD *Self)
 {
   int rows=-1, cols=-1 ;
-  char *port, *s, *e;
+  char *port, *s;
 
   if (Port) {
     free(Port);
@@ -275,13 +278,7 @@ int USBLCD_init (LCD *Self)
   if (USBLCD_open()!=0)
     return -1;
   
-  s=cfg_get("Icons", "0");
-  Icons=strtol(s, &e, 0);
-  if (*e!='\0' || Icons<0 || Icons>8) {
-    debug ("Icons=%d e=<%s>", Icons, e);
-    error ("USBLCD: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source());
-    return -1;
-  }    
+  if (cfg_number("Icons", 0, 0, 8, &Icons)<0) return -1;
   if (Icons>0) {
     info ("reserving %d of %d user-defined characters for icons", Icons, CHARS);
     icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, USBLCD_define_char);
@@ -335,7 +332,6 @@ int USBLCD_flush (void)
 {
   int row, col, pos1, pos2;
   int c, equal;
-  static int junk=0; //Fixme
 
   bar_process(USBLCD_define_char);
 
index 2902ebfd9d02032bbf9589ce5bcc878fa379c08f..5ff05a35986928082baf4d05e75f91eee24e35c8 100644 (file)
--- a/XWindow.c
+++ b/XWindow.c
@@ -1,4 +1,4 @@
-/* $Id: XWindow.c,v 1.32 2003/07/24 04:48:09 reinelt Exp $
+/* $Id: XWindow.c,v 1.33 2003/09/09 06:54:43 reinelt Exp $
  *
  * X11 Driver for LCD4Linux 
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: XWindow.c,v $
+ * Revision 1.33  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.32  2003/07/24 04:48:09  reinelt
  * 'soft clear' needed for virtual rows
  *
@@ -414,7 +417,9 @@ int xlcdinit(LCD *Self)
   }
   if (rgap<0) rgap=pixel+pgap;
   if (cgap<0) cgap=pixel+pgap;
-  border=atoi(cfg_get("border","0"));
+
+  if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1;
+
   rgbfg=cfg_get("foreground","#000000");
   rgbbg=cfg_get("background","#80d000");
   rgbhg=cfg_get("halfground","#70c000");
diff --git a/cfg.c b/cfg.c
index 708bf5901d0a37279bef5ae2fd57727a4c50184a..0689ce6b61b14bc6ca1beac64c50894662d88cc9 100644 (file)
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.15 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: cfg.c,v 1.16 2003/09/09 06:54:43 reinelt Exp $
  *
  * config file stuff
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: cfg.c,v $
+ * Revision 1.16  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.15  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
 #include "debug.h"
 #include "cfg.h"
 
+
 typedef struct {
   char *key;
   char *val;
   int lock;
 } ENTRY;
 
+
 static char  *Config_File=NULL;
 static ENTRY *Config=NULL;
 static int   nConfig=0;
@@ -156,6 +161,7 @@ static char *strip (char *s, int strip_comments)
   return s;
 }
 
+
 static char *dequote (char *string)
 {
   char *s=string;
@@ -172,6 +178,7 @@ static char *dequote (char *string)
   return string;
 }
 
+
 static void cfg_add (char *key, char *val, int lock)
 {
   int i;
@@ -191,6 +198,7 @@ static void cfg_add (char *key, char *val, int lock)
   Config[i].lock=lock;
 }
 
+
 int l4l_cfg_cmd (char *arg)
 {
   char *key, *val;
@@ -209,6 +217,7 @@ int l4l_cfg_cmd (char *arg)
   return 0;
 }
 
+
 char *l4l_cfg_get (char *key, char *defval)
 {
   int i;
@@ -221,6 +230,38 @@ char *l4l_cfg_get (char *key, char *defval)
   return defval;
 }
 
+
+int l4l_cfg_number (char *key, int defval, int min, int max, int *value) 
+{
+  
+  char *s, *e;
+  
+  s=cfg_get(key, NULL);
+  if (s==NULL) {
+    *value=defval;
+    return 0;
+  }
+  
+  *value=strtol(s, &e, 0);
+  if (*e!='\0') {
+    error ("bad %s entry '%s' in %s", key, s, cfg_source());
+    return -1;
+  }
+  
+  if (*value<min) {
+    error ("bad %s value '%s' in %s, minimum is %d", key, s, cfg_source(), min);
+    return -1;
+  }
+  
+  if (*value>max) {
+    error ("bad %s value '%s' in %s, maximum is %d", key, s, cfg_source(), max);
+    return -1;
+  }
+
+  return 0;
+}
+
+
 static int check_cfg_source(char *file)
 {
   /* as passwords and commands are stored in the config file,
@@ -261,6 +302,7 @@ static int check_cfg_source(char *file)
   return error;
 }
 
+
 int l4l_cfg_init (char *file)
 {
   FILE *stream;
@@ -306,6 +348,7 @@ int l4l_cfg_init (char *file)
   return 0;
 }
 
+
 char *l4l_cfg_source (void)
 {
   if (Config_File)
@@ -315,8 +358,9 @@ char *l4l_cfg_source (void)
 }
 
 
-int   (*cfg_init)   (char *source)            = l4l_cfg_init;
-char *(*cfg_source) (void)                    = l4l_cfg_source;
-int   (*cfg_cmd)    (char *arg)               = l4l_cfg_cmd;
-char *(*cfg_get)    (char *key, char *defval) = l4l_cfg_get;
-
+int   (*cfg_init)   (char *source)                 = l4l_cfg_init;
+char *(*cfg_source) (void)                         = l4l_cfg_source;
+int   (*cfg_cmd)    (char *arg)                    = l4l_cfg_cmd;
+char *(*cfg_get)    (char *key, char *defval)      = l4l_cfg_get;
+int   (*cfg_number) (char *key, int   defval, 
+                    int min, int max, int *value) = l4l_cfg_number;
diff --git a/cfg.h b/cfg.h
index cb4b86a916fc2c212c6edd01e0934ac237f6a3de..fc35a4d4926846f6835a270ab16273a39bfea142 100644 (file)
--- a/cfg.h
+++ b/cfg.h
@@ -1,4 +1,4 @@
-/* $Id: cfg.h,v 1.4 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: cfg.h,v 1.5 2003/09/09 06:54:43 reinelt Exp $
  *
  * config file stuff
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: cfg.h,v $
+ * Revision 1.5  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.4  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -47,10 +50,14 @@ extern int   (*cfg_init)   (char *source);
 extern char *(*cfg_source) (void);
 extern int   (*cfg_cmd)    (char *arg);
 extern char *(*cfg_get)    (char *key, char *defval);
+extern int   (*cfg_number) (char *key, int   defval, 
+                           int min, int max, int *value);
 
 int   l4l_cfg_init   (char *file);
 char *l4l_cfg_source (void);
 int   l4l_cfg_cmd    (char *arg);
 char *l4l_cfg_get    (char *key, char *defval);
+int   l4l_cfg_number (char *key, int   defval, 
+                     int min, int max, int *value);
 
 #endif
index 32af53dfc96b306cf607a2fd65acd9016f21cb26..a9aa8afe09a33cb09ee7210493e780f3fee2e659 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -1,4 +1,4 @@
-/* $Id: filter.c,v 1.6 2003/02/22 07:53:10 reinelt Exp $
+/* $Id: filter.c,v 1.7 2003/09/09 06:54:43 reinelt Exp $
  *
  *  smooth and damp functions
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: filter.c,v $
+ * Revision 1.7  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.6  2003/02/22 07:53:10  reinelt
  * cfg_get(key,defval)
  *
@@ -138,9 +141,9 @@ double damp(char *name, double value)
   double max;
   int i, j;
   
-  if (tau==-1)
-    tau=atoi(cfg_get("tau","500"));
-
+  if (tau==-1) 
+    if (cfg_number("tau", 500, 0, 1000000, &tau)<0) tau=0.0;
+  
   if (tau==0.0)
     return value;
   
index 400fdd0411930296f6884575882a93c5a8c13c90..a95d14858fff8acf49b8ce64af5b97f9ccba3890 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.45 2003/09/09 05:30:34 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.46 2003/09/09 06:54:43 reinelt Exp $
  *
  * LCD4Linux
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.46  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.45  2003/09/09 05:30:34  reinelt
  * even more icons stuff
  *
 
 char *release="LCD4Linux " VERSION " (c) 2003 Michael Reinelt <reinelt@eunet.at>";
 char **my_argv;
+int tick;
 int got_signal=0;
 
 extern char* output;
@@ -321,9 +325,7 @@ int main (int argc, char *argv[])
 {
   char *cfg="/etc/lcd4linux.conf";
   char *driver;
-  char *s, *e;
   int c;
-  int tick;
   int quiet=0;
   
   // save arguments for restart
@@ -466,10 +468,7 @@ int main (int argc, char *argv[])
   signal(SIGQUIT, handler);
   signal(SIGTERM, handler);
   
-  s=cfg_get("tick", "100");
-  tick=strtol(s, &e, 0);
-  if (*e!='\0' || tick<0) {
-    error ("bad tick entry '%s' in %s", s, cfg_source());
+  if (cfg_number("Tick", 100, 1, 1000000, &tick)<0) {
     pid_exit(PIDFILE);
     exit (1);
   }
index 5c9956d895e88bd4c9124390e50dcd6b775a2fa9..204ba203c4faff8304134cadac56b5e617941c1d 100644 (file)
--- a/parport.c
+++ b/parport.c
@@ -1,4 +1,4 @@
-/* $Id: parport.c,v 1.7 2003/08/24 05:17:58 reinelt Exp $
+/* $Id: parport.c,v 1.8 2003/09/09 06:54:43 reinelt Exp $
  *
  * generic parallel port handling
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: parport.c,v $
+ * Revision 1.8  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.7  2003/08/24 05:17:58  reinelt
  * liblcd4linux patch from Patrick Schemitz
  *
@@ -143,17 +146,9 @@ static int PPfd=-1;
 int parport_open (void)
 {
   char *s, *e;
-
+  
 #ifdef USE_OLD_UDELAY
-  s=cfg_get ("Delay",NULL);
-  if (s==NULL || *s=='\0') {
-    error ("parport: no 'Delay' entry in %s", cfg_source());
-    return -1;
-  }
-  if ((loops_per_usec=strtol(s, &e, 0))==0 || *e!='\0') {
-    error ("parport: bad delay '%s' in %s", s, cfg_source());
-    return -1;
-  }    
+  if (cfg_number("Delay", 0, 1, 1000000000, &loops_per_usec)<0) return -1;
 #else
   udelay_init();
 #endif
index 67e1129b1b17773d192eec0c8db54f9daa7f2b11..481c4eb29cc99fc13d18825f4819d667d19e51d2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: processor.c,v 1.39 2003/09/09 05:30:34 reinelt Exp $
+/* $Id: processor.c,v 1.40 2003/09/09 06:54:43 reinelt Exp $
  *
  * main data processing
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: processor.c,v $
+ * Revision 1.40  2003/09/09 06:54:43  reinelt
+ * new function 'cfg_number()'
+ *
  * Revision 1.39  2003/09/09 05:30:34  reinelt
  * even more icons stuff
  *
@@ -769,29 +772,26 @@ void process_init (void)
   debug ("Display: %d rows, %d columns, %dx%d pixels, %d icons, %d GPOs", rows, cols, xres, yres, icons, gpos);
 
 
-  lines=atoi(cfg_get("Rows","1"));
-  if (lines<1) {
-    error ("bad 'Rows' entry in %s, ignoring.", cfg_source());
+  if (cfg_number("Rows", 1, 1, 1000, &lines)<0) {
     lines=1;
+    error ("ignoring bad 'Rows' value and using '%d'", lines);
   }
   if (lines>ROWS) {
     error ("%d virtual rows exceeds limit, reducing to %d rows", lines, ROWS);
     lines=ROWS;
   }
   if (lines>rows) {
-    scroll=atoi(cfg_get("Scroll","1"));
-    if (scroll<1) {
-      error ("bad 'Scroll' entry in %s, ignoring and using '1'", cfg_source());
+    if (cfg_number("Scroll", 1, 1, 1000, &scroll)<0) {
       scroll=1;
+      error ("ignoring bad 'Scroll' value and using '%d'", scroll);
     }
     if (scroll>rows) {
       error ("'Scroll' entry in %s is %d, > %d display rows.", cfg_source(), scroll, rows);
       error ("This may lead to unexpected results!");
     }
-    turn=atoi(cfg_get("Turn","1000"));
-    if (turn<1) {
-      error ("bad 'Turn' entry in %s, ignoring and using '1000'", cfg_source());
-      turn=1;
+    if (cfg_number("Turn", 1000, 1, 1000000, &turn)<0) {
+      turn=1000;
+      error ("ignoring bad 'Scroll' value and using '%d'", turn);
     }
     debug ("Virtual: %d rows, scroll %d lines every %d msec", lines, scroll, turn);
   } else {
@@ -826,6 +826,9 @@ void process (void)
   char *txt;
   static int offset=0;
   
+  // Fixme: smooth has gone...
+  int smooth=0;
+  
   collect_data();
 
   if (smooth==0 && Turn()) {