From 7b287b37280afaabd240f9bb250aa8ae0a722a61 Mon Sep 17 00:00:00 2001 From: reinelt Date: Mon, 3 Apr 2000 04:46:38 +0000 Subject: [lcd4linux @ 2000-04-03 04:46:38 by reinelt] added '-c key=val' option git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@34 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- README | 17 ++++++++++++++++- README.Raster | 6 ++++-- README.X11 | 6 ++++-- cfg.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ cfg.h | 7 ++++++- lcd4linux.c | 16 +++++++++++++--- lcd4linux.conf.sample | 4 ++-- 7 files changed, 88 insertions(+), 17 deletions(-) diff --git a/README b/README index 3840096..6fc58d6 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ # -# $Id: README,v 1.2 2000/03/26 19:03:52 reinelt Exp $ +# $Id: README,v 1.3 2000/04/03 04:46:38 reinelt Exp $ # This is the README file for lcd4linux @@ -14,6 +14,21 @@ It supports displaying text values and different types of bars: Horizontal and vertical bars, logarithmic bars, split bars (two independent bars in one row). +USAGE + +lcd4linux -h +print version number and a small help text, then exit + +lcd4linux -l +list available drivers + +lcd4linux [-c key=val] [-f config-file] [-o output] +run lcd4linux +use configuration from 'config-file' instead of /etc/lcd4linux.conf +write picture to 'output' (raster driver only) +overwrite entries from the config-file with '-c' + + SUPPORTED DISPLAYS * Matrox Orbital diff --git a/README.Raster b/README.Raster index b0e05b4..2ef5172 100644 --- a/README.Raster +++ b/README.Raster @@ -1,5 +1,5 @@ # -# $Id: README.Raster,v 1.1 2000/03/26 20:00:44 reinelt Exp $ +# $Id: README.Raster,v 1.2 2000/04/03 04:46:38 reinelt Exp $ # This is the README file for the Raster display driver for lcd4linux @@ -38,7 +38,9 @@ pixelsize*pixelsize pixels. If you want to, you can emulate the gap between this lcd cells by specifying a pixelgap greater than zero. Sometimes there's a gap between characters, too. You can specify this gap (in pixels again) horizontally and vertically. Usually this gap -is the same size as a cell (which is pixelsize+pixelgap). +is the same size as a cell (which is pixelsize+pixelgap). If you specify +either the row gap or the column gap as -1, this cell size will be used +instead. If you use a font of 5x8, some characters may use the first and the last pixel. So you should specify a column gap, otherwise the caracters may diff --git a/README.X11 b/README.X11 index 0df71a7..7b55624 100644 --- a/README.X11 +++ b/README.X11 @@ -1,5 +1,5 @@ # -# $Id: README.X11,v 1.1 2000/03/28 08:48:33 reinelt Exp $ +# $Id: README.X11,v 1.2 2000/04/03 04:46:38 reinelt Exp $ # This is the README file for the X11 display driver for lcd4linux @@ -34,7 +34,9 @@ pixelsize*pixelsize pixels. If you want to, you can emulate the gap between this lcd cells by specifying a pixelgap greater than zero. Sometimes there's a gap between characters, too. You can specify this gap (in pixels again) horizontally and vertically. Usually this gap -is the same size as a cell (which is pixelsize+pixelgap). +is the same size as a cell (which is pixelsize+pixelgap). If you specify +either the row gap or the column gap as -1, this cell size will be used +instead. If you use a font of 5x8, some characters may use the first and the last pixel. So you should specify a column gap, otherwise the caracters may diff --git a/cfg.c b/cfg.c index 7a9fa14..f44add3 100644 --- a/cfg.c +++ b/cfg.c @@ -1,4 +1,4 @@ -/* $Id: cfg.c,v 1.5 2000/03/28 07:22:15 reinelt Exp $ +/* $Id: cfg.c,v 1.6 2000/04/03 04:46:38 reinelt Exp $ * * config file stuff * @@ -20,6 +20,10 @@ * * * $Log: cfg.c,v $ + * Revision 1.6 2000/04/03 04:46:38 reinelt + * + * added '-c key=val' option + * * Revision 1.5 2000/03/28 07:22:15 reinelt * * version 0.95 released @@ -55,6 +59,13 @@ /* * exported functions: * + * cfg_cmd (arg) + * allows us to overwrite entries in the + * config-file from the command line. + * arg is 'key=value' + * cfg_cmd can be called _before_ cfg_read() + * returns 0 if ok, -1 if arg cannot be parsed + * * cfg_set (key, value) * pre-set key's value * should be called before cfg_read() @@ -85,6 +96,7 @@ typedef struct { char *key; char *val; + int lock; } ENTRY; static char *Config_File=NULL; @@ -92,7 +104,7 @@ static ENTRY *Config=NULL; static int nConfig=0; -static char *strip (char *s) +static char *strip (char *s, int strip_comments) { char *p; @@ -100,7 +112,7 @@ static char *strip (char *s) for (p=s; *p; p++) { if (*p=='"') do p++; while (*p && *p!='\n' && *p!='"'); if (*p=='\'') do p++; while (*p && *p!='\n' && *p!='\''); - if (*p=='\n' || (*p=='#' && (p==s || *(p-1)!='\\'))) { + if (*p=='\n' || (strip_comments && *p=='#' && (p==s || *(p-1)!='\\'))) { *p='\0'; break; } @@ -125,12 +137,13 @@ static char *dequote (char *string) return string; } -void cfg_set (char *key, char *val) +static void cfg_add (char *key, char *val, int lock) { int i; for (i=0; ilock) return; if (Config[i].val) free (Config[i].val); Config[i].val=dequote(strdup(val)); return; @@ -140,6 +153,30 @@ void cfg_set (char *key, char *val) Config=realloc(Config, nConfig*sizeof(ENTRY)); Config[i].key=strdup(key); Config[i].val=dequote(strdup(val)); + Config[i].lock=lock; +} + +int cfg_cmd (char *arg) +{ + char *key, *val; + char buffer[256]; + + strncpy (buffer, arg, sizeof(buffer)); + key=strip(buffer, 0); + for (val=key; *val; val++) { + if (*val=='=') { + *val++='\0'; + break; + } + } + if (*key=='\0' || *val=='\0') return -1; + cfg_add (key, val, 1); + return 0; +} + +void cfg_set (char *key, char *val) +{ + cfg_add (key, val, 0); } char *cfg_get (char *key) @@ -170,14 +207,14 @@ int cfg_read (char *file) Config_File=strdup(file); while ((line=fgets(buffer,256,stream))!=NULL) { - if (*(line=strip(line))=='\0') continue; + if (*(line=strip(line, 1))=='\0') continue; for (p=line; *p; p++) { if (isblank(*p)) { *p++='\0'; break; } } - p=strip(p); + p=strip(p, 1); if (*p) for (s=p; *(s+1); s++); else s=p; if (*p=='"' && *s=='"') { diff --git a/cfg.h b/cfg.h index 1cbad76..0f7d778 100644 --- a/cfg.h +++ b/cfg.h @@ -1,4 +1,4 @@ -/* $Id: cfg.h,v 1.1 2000/03/10 11:40:47 reinelt Exp $ +/* $Id: cfg.h,v 1.2 2000/04/03 04:46:38 reinelt Exp $ * * config file stuff * @@ -20,6 +20,10 @@ * * * $Log: cfg.h,v $ + * Revision 1.2 2000/04/03 04:46:38 reinelt + * + * added '-c key=val' option + * * Revision 1.1 2000/03/10 11:40:47 reinelt * *** empty log message *** * @@ -33,6 +37,7 @@ #ifndef _CFG_H_ #define _CFG_H_ +int cfg_cmd (char *arg); void cfg_set (char *key, char *value); char *cfg_get (char *key); int cfg_read (char *file); diff --git a/lcd4linux.c b/lcd4linux.c index 9bbd28f..bd0fc7f 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.15 2000/04/01 22:40:42 herp Exp $ +/* $Id: lcd4linux.c,v 1.16 2000/04/03 04:46:38 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,10 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.16 2000/04/03 04:46:38 reinelt + * + * added '-c key=val' option + * * Revision 1.15 2000/04/01 22:40:42 herp * geometric correction (too many pixelgaps) * lcd4linux main should return int, not void @@ -108,7 +112,7 @@ int tick, tack; static void usage(void) { printf ("%s\n", release); - printf ("usage: lcd4linux [-h] [-l] [-f config-file] [-o output-file]\n"); + printf ("usage: lcd4linux [-h] [-l] [-c key=value] [-f config-file] [-o output-file]\n"); } int main (int argc, char *argv[]) @@ -117,8 +121,14 @@ int main (int argc, char *argv[]) char *driver; int c, smooth; - while ((c=getopt (argc, argv, "hlf:o:"))!=EOF) { + while ((c=getopt (argc, argv, "c:f:hlo:"))!=EOF) { switch (c) { + case 'c': + if (cfg_cmd (optarg)<0) { + fprintf (stderr, "%s: illegal argument -c %s\n", argv[0], optarg); + exit(2); + } + break; case 'h': usage(); exit(0); diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 526f430..271ca3a 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -7,7 +7,7 @@ #size 20x4 #font 5x8 #pixel 3+0 -#gap 3x3 +#gap -1x-1 #border 10 #foreground \#102000 #halfground \#70c000 @@ -17,7 +17,7 @@ Display X11 size 20x5 font 5x8 pixel 1+0 -gap 1x1 +gap -1x-1 border 1 foreground \#102000 halfground \#90c000 -- cgit v1.2.3