X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=common%2Fcfgreader.c;h=df2458bc9be3b1d71e4f54e826008d348edac2dd;hp=1b18760b04ad0538e21935b00f6e756067784518;hb=ecb68c68aeb44fa1ec930d124868e63a64f8cb6d;hpb=9d80f3acb04fd990119dbefc10aaf5a56de13ea9 diff --git a/common/cfgreader.c b/common/cfgreader.c index 1b18760..df2458b 100644 --- a/common/cfgreader.c +++ b/common/cfgreader.c @@ -15,6 +15,17 @@ Modified from code by Tim Potter. $Log$ + Revision 1.1.1.1.8.1 2001/11/25 23:10:58 short + * ... - new cfgreader.c/CFG_GetForeach() + some "const" keywords written - they are missing almost everywhere in Gnokii! + "CFG_info" is now global public symbol + * Global symbols became IMO obsolete: {model,port,initlength,connection,bindir} + stdout/stderr are de-buffered (cfgreading is upon startup) + * I know that it doesn't belong here but currently there is now generic + application init function anywhere. + * stdout/stderr de-buffering is already donw at various weird places all + through the project + Revision 1.1.1.1 2001/11/25 21:58:58 short :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001 @@ -54,6 +65,8 @@ #include "cfgreader.h" +struct CFG_Header *CFG_Info; + /* Read configuration information from a ".INI" style file */ struct CFG_Header *CFG_ReadFile(char *filename) { @@ -208,7 +221,7 @@ int CFG_WriteFile(struct CFG_Header *cfg, char *filename) * with key or NULL if no such key exists. */ -char *CFG_Get(struct CFG_Header *cfg, char *section, char *key) +char *CFG_Get(struct CFG_Header *cfg, const char *section, const char *key) { struct CFG_Header *h; struct CFG_Entry *e; @@ -233,6 +246,29 @@ char *CFG_Get(struct CFG_Header *cfg, char *section, char *key) return NULL; } +/* + * Return all the entries of the fiven section. + */ + +void CFG_GetForeach(struct CFG_Header *cfg, const char *section, CFG_GetForeach_func func) +{ + struct CFG_Header *h; + struct CFG_Entry *e; + + if ((cfg == NULL) || (section == NULL) || (func == NULL)) { + return; + } + + /* Search for section name */ + for (h = cfg; h != NULL; h = h->next) { + if (strcmp(section, h->section) == 0) { + /* Search for key within section */ + for (e = h->entries; e != NULL; e = e->next) + (*func)(section,e->key,e->value); + } + } +} + /* Set the value of a key in a config file. Return the new value if the section/key can be found, else return NULL. */ @@ -269,12 +305,17 @@ char *CFG_Set(struct CFG_Header *cfg, char *section, char *key, int readconfig(char **model, char **port, char **initlength, char **connection, char **bindir) { - struct CFG_Header *cfg_info; char *homedir; char rcfile[200]; char *DefaultConnection = "serial"; char *DefaultBindir = "/usr/local/sbin/"; + /* I know that it doesn't belong here but currently there is now generic + * application init function anywhere. + */ + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + #ifdef WIN32 homedir = getenv("HOMEDRIVE"); strncpy(rcfile, homedir ? homedir : "", 200); @@ -288,34 +329,34 @@ int readconfig(char **model, char **port, char **initlength, #endif /* Try opening .gnokirc from users home directory first */ - if ((cfg_info = CFG_ReadFile(rcfile)) == NULL) { + if ((CFG_Info = CFG_ReadFile(rcfile)) == NULL) { /* It failed so try for /etc/gnokiirc */ - if ((cfg_info = CFG_ReadFile("/etc/gnokiirc")) == NULL) { + if ((CFG_Info = CFG_ReadFile("/etc/gnokiirc")) == NULL) { /* That failed too so exit */ fprintf(stderr, _("Couldn't open %s or /etc/gnokiirc. Exiting now...\n"), rcfile); return -1; } } - (char *)*model = CFG_Get(cfg_info, "global", "model"); + (char *)*model = CFG_Get(CFG_Info, "global", "model"); if (!*model) { fprintf(stderr, _("Config error - no model specified. Exiting now...\n")); return -2; } - (char *)*port = CFG_Get(cfg_info, "global", "port"); + (char *)*port = CFG_Get(CFG_Info, "global", "port"); if (!*port) { fprintf(stderr, _("Config error - no port specified. Exiting now...\n")); return -3; } - (char *)*initlength = CFG_Get(cfg_info, "global", "initlength"); + (char *)*initlength = CFG_Get(CFG_Info, "global", "initlength"); if (!*initlength) (char *)*initlength = "default"; - (char *)*connection = CFG_Get(cfg_info, "global", "connection"); + (char *)*connection = CFG_Get(CFG_Info, "global", "connection"); if (!*connection) (char *)*connection = DefaultConnection; - (char *)*bindir = CFG_Get(cfg_info, "global", "bindir"); + (char *)*bindir = CFG_Get(CFG_Info, "global", "bindir"); if (!*bindir) (char *)*bindir = DefaultBindir; return 0;