gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: --config and --phone options for gnokii


From: Daniele Forsi
Subject: Re: --config and --phone options for gnokii
Date: Wed, 09 Aug 2006 15:52:40 +0200
User-agent: Mozilla Thunderbird 1.5.0.2 (X11/20060420)

Pawel Kot wrote:

everyting seems to work smoothly.

Yes but --config doesn't print an error message if it can't open the file and --phone silently picks values from global if it can't find the section, maybe it should fail or at least warn if the phone section is not found. I also accepts multiple --phone options:
gnokii --phone A --phone B --phone C

It's not so intuitive that in gnokiirc you must write a section like this

[phone_foo]

and use like this
gnokii --phone foo [...]

with an error message: "[phone_foo] section not found" I would have saved looking at the sources ;-)

It works fine and I added these lines to .gnokiirc

[phone_/dev/ttyS0]
port = /dev/ttyS0

[phone_/dev/ttyS1]
port = /dev/ttyS1

and then I can type
gnokii --phone /dev/ttyS0 --identify
or
gnokii --phone /dev/ttyS1 --identify

but it is NOT intuitive that in this instance "/dev/ttyS0" is an opaque string... maybe I should use another name

Since you asked for patches, here is one that makes --phone fail if the section can't be found. I copied and modified the existing gn_cfg_get() to write gn_cfg_find_section().

Index: common/cfgreader.c
===================================================================
RCS file: /sources/gnokii/gnokii/common/cfgreader.c,v
retrieving revision 1.75
diff -u -p -0 -r1.75 cfgreader.c
--- common/cfgreader.c  6 Aug 2006 20:42:20 -0000       1.75
+++ common/cfgreader.c  9 Aug 2006 13:36:21 -0000
@@ -316,0 +317,24 @@ int cfg_file_write(struct gn_cfg_header
+* Find the beginning of a section
+*
+* Return pointer to gn_cfg_header of section or NULL if no such section exists.
+*/
+GNOKII_API struct gn_cfg_header *gn_cfg_find_section(struct gn_cfg_header *cfg, const char *section)
+{
+       struct gn_cfg_header *h;
+
+       if ((cfg == NULL) || (section == NULL)) {
+               return NULL;
+       }
+
+       /* Search for section name */
+       for (h = cfg; h != NULL; h = h->next) {
+               if (strcmp(section, h->section) == 0) {
+                       /* Found! */
+                       return h;
+               }
+       }
+       /* section not found */
+       return NULL;
+}
+
+/*
@@ -672,0 +697,4 @@ GNOKII_API int gn_cfg_phone_load(const c
+               if (!gn_cfg_find_section(gn_cfg_info, section)) {
+ fprintf(stderr, _("Config error - [%s] section not found.\n"), section);
+                       return false;
+               }

--
Daniele




reply via email to

[Prev in Thread] Current Thread [Next in Thread]