gnokii-users
[Top][All Lists]
Advanced

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

Re: Delete phonebookentry with gnokii


From: Tim Riemenschneider
Subject: Re: Delete phonebookentry with gnokii
Date: Thu, 4 Apr 2002 00:45:08 +0200
User-agent: Mutt/1.3.27i

On Tue, Apr 02, 2002 at 02:30:30AM +0200, address@hidden 
wrote:
> Hi!
>
> Is it possible to delete a phonebookentry with gnokii?
>
> I tried:
> $ gnokii --writephonebook
> ;;SM;1;5
> ^D
> But then I get "Format problem on line 2 [;;SM;1;5]".
>
I investigated this:
The problem is the strtok-function (IMHO):
A string like:
Test;1234;SM;1;5
results in the Tokens:
"Test", "1234", "SM", "1", "5"

but the string:
;;SM;1;5
results in:
"SM", "1", "5"
and not in the expected (at least by me ;-):
(null), (null), "SM", "1", "5"

So I have hacked gnokii.c to archieve this (see patch later on)
Now it deletes entries if the line ";;(mem);(loc);5" is the FIRST line
of input for writephonebook.
This can be solved by moving the memset-call into the loop.

Now my patch:
moving the memset-call is IMHO a good thing (TM), but the rest is only
a hack (and I think it won't be accepted into the CVS...) but maybe
somebody else has an idea to solve it. (Maybe by not using strtok at
all, quoting from man strtok: "BUGS: Never use these function....")

But here is my patch


Index: gnokii.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/gnokii/gnokii.c,v
retrieving revision 1.214
diff -u -r1.214 gnokii.c
--- gnokii.c    3 Apr 2002 01:08:51 -0000       1.214
+++ gnokii.c    3 Apr 2002 15:26:32 -0000
@@ -2682,20 +2682,28 @@

        Line = OLine;

-       memset(&entry, 0, sizeof(GSM_PhonebookEntry));
-
        /* Go through data from stdin. */
        while (GetLine(stdin, Line, 99)) {
+               memset(&entry, 0, sizeof(GSM_PhonebookEntry));
                strcpy(BackLine, Line);
                line_count++;

-               ptr = strtok(Line, ";");
+               if (Line && Line[0]!=';')
+                       ptr = strtok(Line, ";");
+               else
+                       ptr = NULL;
                if (ptr) strncpy(entry.Name, ptr, sizeof(entry.Name) -1);

-               ptr = strtok(NULL, ";");
+               if (Line && Line[0]!=';')
+                       ptr = strtok(NULL, ";");
+               else
+                       ptr = NULL;
                if (ptr) strncpy(entry.Number, ptr, 
sizeof(entry.Number) - 1);

-               ptr = strtok(NULL, ";");
+               if (Line && Line[0]!=';')
+                   ptr = strtok(NULL, ";");
+               else
+                   ptr = strtok(Line, ";");

                if (!ptr) {
                        fprintf(stderr, _("Format problem on line %d [%s]\n"), 
line_count, BackLine);




reply via email to

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