/* $Id: parser.c,v 1.19 2003/06/21 05:46:18 reinelt Exp $ * * row definition parser * * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at) * * 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 2, 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * $Log: parser.c,v $ * Revision 1.19 2003/06/21 05:46:18 reinelt * DVB client integrated * * Revision 1.18 2002/12/05 19:23:01 reinelt * fixed undefined operations found by gcc3 * * Revision 1.17 2002/08/19 04:41:20 reinelt * introduced bar.c, moved bar stuff from display.h to bar.h * * Revision 1.16 2001/03/16 16:40:17 ltoetsch * implemented time bar * * Revision 1.15 2001/03/14 13:19:29 ltoetsch * Added pop3/imap4 mail support * * Revision 1.14 2001/03/13 08:34:15 reinelt * * corrected a off-by-one bug with sensors * * Revision 1.13 2001/03/08 15:25:38 ltoetsch * improved exec * * Revision 1.12 2001/03/07 18:10:21 ltoetsch * added e(x)ec commands * * Revision 1.11 2001/03/02 10:18:03 ltoetsch * added /proc/apm battery stat * * Revision 1.10 2001/02/19 00:15:46 reinelt * * integrated mail and seti client * major rewrite of parser and tokenizer to support double-byte tokens * * Revision 1.9 2001/02/16 08:23:09 reinelt * * new token 'ic' (ISDN connected) by Carsten Nau * * Revision 1.8 2001/02/14 07:40:16 reinelt * * first (incomplete) GPO implementation * * Revision 1.7 2000/08/10 09:44:09 reinelt * * new debugging scheme: error(), info(), debug() * uses syslog if in daemon mode * * Revision 1.6 2000/05/21 06:20:35 reinelt * * added ppp throughput * token is '%t[iomt]' at the moment, but this will change in the near future * * Revision 1.5 2000/03/24 11:36:56 reinelt * * new syntax for raster configuration * changed XRES and YRES to be configurable * PPM driver works nice * * Revision 1.4 2000/03/19 08:41:28 reinelt * * documentation available! README, README.MatrixOrbital, README.Drivers * added Skeleton.c as a starting point for new drivers * * Revision 1.3 2000/03/18 10:31:06 reinelt * * added sensor handling (for temperature etc.) * made data collecting happen only if data is used * (reading /proc/meminfo takes a lot of CPU!) * released lcd4linux-0.92 * * Revision 1.2 2000/03/17 09:21:42 reinelt * * various memory statistics added * * Revision 1.1 2000/03/13 15:58:24 reinelt * * release 0.9 * moved row parsing to parser.c * all basic work finished * */ /* * exported functions: * * char *parse_row (char *string, int supported_bars, int usage[]) * converts a row definition from the config file * into the internal form using tokens * sets the array usage[token] to usage count * * char parse_gpo (char *string, int usage[]) * converts a GPO definition from the config file * into the internal form using tokens * sets the array usage[token] to usage count * */ #include #include #include #include #include "debug.h" #include "display.h" #include "bar.h" #include "parser.h" typedef struct { char *symbol; TOKEN token; CLASS class; int bar; } SYMTAB; static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 }, { "$", T_DOLLAR, C_GENERIC, 0 }, { "o", T_OS, C_GENERIC, 0 }, { "v", T_RELEASE, C_GENERIC, 0 }, { "p", T_CPU, C_GENERIC, 0 }, { "r", T_RAM, C_GENERIC, 0 }, { "mt", T_MEM_TOTAL, C_MEM, 1 }, { "mu", T_MEM_USED, C_MEM, 1 }, { "mf", T_MEM_FREE, C_MEM, 1 }, { "ms", T_MEM_SHARED, C_MEM, 1 }, { "mb", T_MEM_BUFFER, C_MEM, 1 }, { "mc", T_MEM_CACHE, C_MEM, 1 }, { "ma", T_MEM_AVAIL, C_MEM, 1 }, { "l1", T_LOAD_1, C_LOAD, 1 }, { "l2", T_LOAD_2, C_LOAD, 1 }, { "l3", T_LOAD_3, C_LOAD, 1 }, { "L", T_OVERLOAD, C_LOAD, 0 }, { "cu", T_CPU_USER, C_CPU, 1 }, { "cn", T_CPU_NICE, C_CPU, 1 }, { "cs", T_CPU_SYSTEM, C_CPU, 1 }, { "cb", T_CPU_BUSY, C_CPU, 1 }, { "ci", T_CPU_IDLE, C_CPU, 1 }, { "dr", T_DISK_READ, C_DISK, 1 }, { "dw", T_DISK_WRITE, C_DISK, 1 }, { "dt", T_DISK_TOTAL, C_DISK, 1 }, { "dm", T_DISK_MAX, C_DISK, 1 }, { "nr", T_ETH_RX, C_ETH, 1 }, { "nw", T_ETH_TX, C_ETH, 1 }, { "nt", T_ETH_TOTAL, C_ETH, 1 }, { "nm", T_ETH_MAX, C_ETH, 1 }, { "ic", T_ISDN_USED, C_ISDN, 0 }, { "ii", T_ISDN_IN, C_ISDN, 1 }, { "io", T_ISDN_OUT, C_ISDN, 1 }, { "it", T_ISDN_TOTAL, C_ISDN, 1 }, { "im", T_ISDN_MAX, C_ISDN, 1 }, { "ti", T_PPP_RX, C_PPP, 1 }, { "to", T_PPP_TX, C_PPP, 1 }, { "tt", T_PPP_TOTAL, C_PPP, 1 }, { "tm", T_PPP_MAX, C_PPP, 1 }, { "hc", T_SETI_PRC, C_SETI, 1 }, { "ht", T_SETI_CPU, C_SETI, 0 }, { "bp", T_BATT_PERC, C_BATT, 1 }, { "bs", T_BATT_STAT, C_BATT, 0 }, { "bd", T_BATT_DUR, C_BATT, 0 }, { "ss", T_DVB_STRENGTH, C_DVB, 1 }, { "sn", T_DVB_SNR, C_DVB, 1 }, { "e*", T_MAIL, C_MAIL, 0 }, { "u*", T_MAIL_UNSEEN,C_MAIL, 0 }, { "s*", T_SENSOR, C_SENSOR, 1 }, { "x*", T_EXEC, C_EXEC, 1 }, { "", -1, 0 }}; static int bar_type (char tag) { switch (tag) { case 'l': return BAR_L; case 'r': return BAR_R; case 'u': return BAR_U; case 'd': return BAR_D; case 't': return BAR_T; default: return 0; } } static int get_token (char *s, char **p, int bar, int usage[]) { char c; int i, l; for (i=0; Symtab[i].token!=-1; i++) { if (bar && !Symtab[i].bar) continue; l=strlen(Symtab[i].symbol); if (Symtab[i].symbol[l-1]=='*') { if (Symtab[i].token='0' && c<='9') { *p=s+l; usage[Symtab[i].token]|=(1<<(c-'0')); usage[Symtab[i].class]=1; return Symtab[i].token+(c<<8); } } else if (strncmp(Symtab[i].symbol, s, l)==0) { *p=s+l; usage[Symtab[i].token]=1; usage[Symtab[i].class]=1; return Symtab[i].token; } } return -1; } char *parse_row (char *string, int supported_bars, int usage[]) { static char buffer[256]; char *s=string; char *p=buffer; int token, token2; int type, len; do { switch (*s) { case '%': if ((token=get_token (++s, &s, 0, usage))==-1) { error ("WARNING: unknown token <%%%c> in <%s>", *s, string); } else { *p++='%'; *p++=token&255; if (token>256) *p++=token>>8; } break; case '$': type=bar_type(tolower(*++s)); if (type==0) { error ("WARNING: invalid bar type <$%c> in <%s>", *s, string); break; } if (!(type & supported_bars)) { error ("WARNING: driver does not support bar type '%c'", *s); break; } if (isupper(*s)) type |= BAR_LOG; len=strtol(s+1, &s, 10); if (len<1 || len>127) { error ("WARNING: invalid bar length in <%s>", string); break; } if ((token=get_token (s, &s, 0, usage))==-1) { error ("WARNING: unknown token <$%c> in <%s>", *s, string); break; } token2=-1; if (*s=='+') { if ((type & BAR_H) && (supported_bars & BAR_H2)) { type |= BAR_H2; } else if ((type & BAR_V) && (supported_bars & BAR_V2)) { type |= BAR_V2; } else { error ("WARNING: driver does not support double bars"); break; } if ((token2=get_token (s+1, &s, 0, usage))==-1) { error ("WARNING: unknown token <$%c> in <%s>", *s, string); break; } } else if (*s == ',' && (type & BAR_T)) token2=strtol(s+1, &s, 10); /* get horizontal length */ *p++='$'; *p++=type; *p++=len; *p++=token&255; if (token>256) *p++=token>>8; if (token2!=-1) { *p++=token2&255; if (token>256 && !(type & BAR_T)) *p++=token2>>8; } break; case '\\': if (*(s+1)=='\\') { *p++='\\'; s++; } else { unsigned int c=0; int n; sscanf (s+1, "%3o%n", &c, &n); if (c==0 || c>255) { error ("WARNING: illegal '\\' in <%s>", string); } else { *p++=c; s+=n+1; } } break; default: if ((*p++=*s)!='\0') s++; } } while (*s); *p='\0'; return buffer; } int parse_gpo (char *string, int usage[]) { char *s=string; int token=-1; if (*s=='%') { if ((token=get_token (++s, &s, 0, usage))==-1) { error ("WARNING: unknown token <%%%c> in <%s>", *s, string); } } if (*s!='\0') { error ("WARNING: error while parsing <%s>", string); } return token; } tle='2004-06-09 06:40:29 +0000'>2004-06-09[lcd4linux @ 2004-06-09 06:40:29 by reinelt]reinelt3-11/+35 splash screen for T6963 driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@471 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-08[lcd4linux @ 2004-06-08 21:46:38 by reinelt]reinelt5-31/+131 splash screen for X11 driver (and generic graphic driver) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@470 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-08[lcd4linux @ 2004-06-08 12:35:24 by reinelt]reinelt6-882/+474 autoconf/automake updates git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@469 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-07[lcd4linux @ 2004-06-07 07:02:13 by reinelt]reinelt1-0/+33 sample debugging widgets added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@468 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-07[lcd4linux @ 2004-06-07 06:56:55 by reinelt]reinelt5-7/+149 added test plugin from Andy Baxter git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@467 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-06[lcd4linux @ 2004-06-06 06:51:59 by reinelt]reinelt16-52/+135 do not display end splash screen if quiet=1 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@466 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-05[lcd4linux @ 2004-06-05 14:56:48 by reinelt]reinelt3-24/+37 Cwlinux splash screen fixed USBLCD splash screen fixed plugin_i2c qprintf("%f") replaced with snprintf() git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@465 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-05[lcd4linux @ 2004-06-05 06:41:39 by reinelt]reinelt11-42/+87 chancged splash screen again git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@464 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-05[lcd4linux @ 2004-06-05 06:13:11 by reinelt]reinelt9-69/+327 splash screen for all text-based display drivers git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@463 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 10:09:22 by reinelt]reinelt4-180/+183 splash screen for HD44780 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@462 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 09:41:19 by reinelt]reinelt18-114/+211 prepared support for startup splash screen git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@461 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 05:56:25 by reinelt]reinelt1-2/+6 extended contrast range for Crystalfontz git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@460 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 05:35:55 by reinelt]reinelt1-0/+20 added i2c_sensors example to lcd4linux.conf.sample git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@459 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 05:27:59 by reinelt]reinelt26-0/+2405 added documentation tree git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@458 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-02[lcd4linux @ 2004-06-02 05:14:16 by reinelt]reinelt2-17/+31 fixed models listing for Beckmann+Egle driver some cosmetic changes git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@457 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-01[lcd4linux @ 2004-06-01 06:45:28 by reinelt]reinelt18-71/+241 some Fixme's processed documented some code git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@456 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-06-01[lcd4linux @ 2004-06-01 06:04:25 by reinelt]reinelt2-25/+25 made README.Plugins and plugin_sample up to date. git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@455 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 21:23:16 by reinelt]reinelt1-37/+49 some cleanups in the MatrixOrbital driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@454 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 21:05:13 by reinelt]reinelt5-77/+111 fixed lots of bugs in the Cwlinux driver do not emit EAGAIN error on the first retry made plugin_i2c_sensors a bit less 'chatty' moved init and exit functions to the bottom of plugin_pop3 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@453 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 16:39:05 by reinelt]reinelt11-180/+535 added NULL display driver (for debugging/profiling purposes) added backlight/contrast initialisation for matrixOrbital added Backlight initialisation for Cwlinux git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@452 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 06:27:34 by reinelt]reinelt1-0/+40 ChangeLog update git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@451 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 06:24:42 by reinelt]reinelt2-7/+29 fixed symlink security issue with the image driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@450 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 05:38:02 by reinelt]reinelt8-42/+94 fixed possible bugs with user-defined chars (clear high bits) thanks to Andy Baxter for debugging the MilfordInstruments driver! git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@449 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-31[lcd4linux @ 2004-05-31 01:31:01 by andy-b]andy-b1-10/+12 fixed bug in Milford Instruments driver which drew extra graphics chars in odd places when drawing double bars. (the display doesn't like it if you put the escape character 0xfe inside a define char sequence). git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@448 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-30[lcd4linux @ 2004-05-30 08:25:50 by reinelt]reinelt2-30/+92 Crystalfontz 631 driver finished git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@447 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-29[lcd4linux @ 2004-05-29 23:30:20 by reinelt]reinelt1-1/+9 fixed a compiler issue with drv_Image.c (thanks to Frank Stratmann) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@446 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-29[lcd4linux @ 2004-05-29 15:53:28 by reinelt]reinelt3-9/+25 M50530: reset parport signals on exit plugin_ppp: ppp() has two parameters, not three lcd4linux.conf.sample: diskstats() corrected git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@445 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-29[lcd4linux @ 2004-05-29 01:07:56 by reinelt]reinelt2-21/+25 bug in plugin_diskstats fixed git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@444 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-29[lcd4linux @ 2004-05-29 00:27:14 by reinelt]reinelt8-11/+214 added plugin_diskstats.c git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@443 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2004-05-28[lcd4linux @ 2004-05-28 14:38:10 by reinelt]reinelt2-1/+41 Status and Changelog Update git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@442 3ae390bd-cb1e-0410-b409-cd5a39f66f1f