[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] gnokii --writephonebook incrementaly
From: |
Ladislav Michl |
Subject: |
[PATCH] gnokii --writephonebook incrementaly |
Date: |
Tue, 10 Jun 2003 12:44:21 +0200 |
User-agent: |
Mutt/1.5.4i |
Hi,
while migrating phonebook to another sim card (with less phonebook
entries) I was forced to delete some entries. after doing that I was
left with some locations above 100 which "new" sim card doesn't like. I
decided to add new option to --writephonebook which will cause gnokii to
ignore location from phonebook and fill it incrementally from first
location. I'm not sure if it is a good idea to do it in gnokii and also
I don't know what should be a name for such option. I'd appreciate
comments and suggestions to following patch.
Index: gnokii/gnokii.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/gnokii/gnokii.c,v
retrieving revision 1.347
diff -u -r1.347 gnokii.c
--- gnokii/gnokii.c 29 May 2003 17:26:11 -0000 1.347
+++ gnokii/gnokii.c 10 Jun 2003 10:20:14 -0000
@@ -254,7 +254,8 @@
fprintf(f, _(" usage: gnokii [--help|--monitor|--version]\n"
" gnokii --getphonebook memory_type start_number
[end_number|end]\n"
" [-r|--raw]\n"
- " gnokii --writephonebook [-iv]\n"
+ " gnokii --writephonebook [-i|--interactive]
[-v|--vcard]\n"
+ " [-o|--overwhelm]\n"
" gnokii --getwapbookmark number\n"
" gnokii --writewapbookmark name URL\n"
" gnokii --deletewapbookmark number\n"
@@ -3178,21 +3179,47 @@
/* Read data from stdin, parse and write to phone. The parsing is relatively
crude and doesn't allow for much variation from the stipulated format. */
/* FIXME: I guess there's *very* similar code in xgnokii */
-static int writephonebook(int argc, char *args[])
+static int writephonebook(int argc, char *argv[])
{
gn_phonebook_entry entry;
gn_error error = GN_ERR_NOTSUPPORTED;
char *memory_type_string = NULL;
char *line, oline[MAX_INPUT_LINE_LEN];
+ int interactive = 0;
int vcard = 0;
+ int overwhelm = 0;
+ int i;
- /* Check argument */
- if (argc && (strcmp("-i", args[0])) && (strcmp("-v", args[0])))
- usage(stderr, -1);
+ struct option options[] = {
+ { "interactive", no_argument, NULL, 'i'},
+ { "vcard", no_argument, NULL, 'v'},
+ { "overwhelm", no_argument, NULL, 'o'},
+ { NULL, 0, NULL, 0}
+ };
+
+ optarg = NULL;
+ optind = 0;
+ argc--;
+ argv++;
- if (argc && !strcmp("-v", args[0]))
- vcard = 1;
+ while ((i = getopt_long(argc, argv, "ivo", options, NULL)) != -1) {
+ switch (i) {
+ case 'i':
+ interactive = 1;
+ break;
+ case 'v':
+ vcard = 1;
+ break;
+ case 'o':
+ overwhelm = 1;
+ break;
+ default:
+ usage(stderr, -1); /* FIXME */
+ return -1;
+ }
+ }
+ i = 0;
line = oline;
/* Go through data from stdin. */
@@ -3207,7 +3234,10 @@
break;
}
- if (argc) {
+ if (overwhelm)
+ entry.location = ++i;
+
+ if (interactive) {
gn_phonebook_entry aux;
memcpy(&aux, &entry, sizeof(gn_phonebook_entry));
@@ -3239,12 +3269,11 @@
error = gn_sm_functions(GN_OP_WritePhonebook, &data, &state);
if (error == GN_ERR_NONE)
- fprintf (stderr,
- _("Write Succeeded: memory type: %s, loc: %d,
name: %s, number: %s\n"),
- memory_type_string, entry.location,
entry.name, entry.number);
+ fprintf(stderr, _("Write Succeeded: memory type: %s,
loc: %d, name: %s, number: %s\n"),
+ memory_type_string, entry.location, entry.name,
entry.number);
else
- fprintf (stderr, _("Write FAILED (%s): memory type: %s,
loc: %d, name: %s, number: %s\n"),
- gn_error_print(error), memory_type_string,
entry.location, entry.name, entry.number);
+ fprintf(stderr, _("Write FAILED (%s): memory type: %s,
loc: %d, name: %s, number: %s\n"),
+ gn_error_print(error), memory_type_string,
entry.location, entry.name, entry.number);
}
return error;
}
@@ -4629,7 +4658,7 @@
{ OPT_SETRINGTONE, 1, 5, 0 },
{ OPT_RESET, 0, 1, 0 },
{ OPT_GETPROFILE, 0, 3, 0 },
- { OPT_WRITEPHONEBOOK, 0, 1, 0 },
+ { OPT_WRITEPHONEBOOK, 0, 3, 0 },
{ OPT_DIVERT, 6, 10, 0 },
{ OPT_GETWAPBOOKMARK, 1, 1, 0 },
{ OPT_WRITEWAPBOOKMARK, 2, 2, 0 },
@@ -4733,7 +4762,7 @@
rc = pmon();
break;
case OPT_WRITEPHONEBOOK:
- rc = writephonebook(nargc, nargv);
+ rc = writephonebook(argc, argv);
break;
/* Now, options with arguments */
case OPT_SETDATETIME:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] gnokii --writephonebook incrementaly,
Ladislav Michl <=