wish: jpilot-dump search in phone fields

Joerg Sommer joerg at alea.gnuu.de
Wed Oct 2 09:32:47 EDT 2002


Hi,

I miss the possibility to tell jpilot-dump to search in a category,
something like "email" or "work". I don't know how to determine the type
of a phone entry.

I cleared up the code a little bit. It really looks like a hack. I
couldn't build jpilot-dump without gtk header files. %-)

#v+
--- jpilot-dump.c.orig	2002-10-02 14:31:33.000000000 +0200
+++ jpilot-dump.c	2002-10-02 15:25:49.000000000 +0200
@@ -60,24 +60,19 @@
 /*
  * Parse the string and replace CR and LFs with spaces
  */
-void takeoutfunnies(char *str)
+inline void takeoutfunnies(char *cptr)
 {
-   int i;
-
-   if (!str) {
-      return;
-   }
-   for (i=0; str[i]; i++) {
-      if ((str[i]=='\r') ||
-          (str[i]=='\n') ||
-	  (str[i]=='\\') ||
-	  (str[i]=='\'') ||
-	  (str[i]=='"' ) ||
-	  (str[i]=='`' )
-	 ) {
-	 str[i]=' ';
-      }
-   }
+   for (; cptr != NULL; cptr++)
+     switch (*cptr) {
+      case '\r':
+      case '\n':
+      case '\\':
+      case '\'':
+      case '"':
+      case '`':
+	*cptr = ' ';
+	break;
+     }
 }
 
 int dumpbook();
@@ -705,109 +700,79 @@
 extern int get_addresses(AddressList **address_list, int sort_order);
 extern void free_AddressList(AddressList **al);
 
+inline void print_nn(const void* entry) // print_not_null
+{
+   if (entry != NULL) printf("%s\n", entry);
+}
+
 int dumpaddress()
 {
-   AddressList *tal, *al;
-   int num,i;
+   AddressList *addr, *al=NULL;
    struct AddressAppInfo ai;
    static struct AddressAppInfo *glob_PAddress_app_info;
 
    get_address_app_info(&ai);
    glob_PAddress_app_info = &ai;
 
-   al = NULL;
-   i = 0;
-   num = get_addresses(&al,i);
-
-   for (tal=al; tal; tal = tal->next) {
-    if ( (tal->ma.rt != DELETED_PALM_REC) && (tal->ma.rt != MODIFIED_PALM_REC)) {
+   get_addresses(&al,0);
 
- for ( i=2 ; formatA[i] != '\0' ; i++) {
-  if ( formatA[i] != '%') {
-   printf("%c",formatA[i]);
-  } else {
-   switch (formatA[i+1]) {
-    case '\0':
-         break;
-    case 'n' :
-         printf("\n");
-	 i++;
-	 break;
-    case 't' :
-         printf("\t");
-	 i++;
-	 break;
-    case 'q' :
-	 printf("'");
-	 i++;
-	 break;
-    case 'Q' :
-	 printf("\"");
-	 i++;
-	 break;
-    case 'C' :
-    	 printf("%s",glob_PAddress_app_info->category.name[tal->ma.attrib & 0x0F]);
-	 i++;
-	 break;
-    case 'N' :	/* normal output */
-	 for (num=0; num < 19 ; num++) {
-	 	if (tal->ma.a.entry[num] == NULL) {
-			printf("\n");
-		} else {
-			printf("%s\n",tal->ma.a.entry[num]);
+   for (addr=al; addr != NULL; addr = addr->next)
+     if ( addr->ma.rt != DELETED_PALM_REC && addr->ma.rt != MODIFIED_PALM_REC)
+     {
+	const char* fmt;
+	for (fmt=formatA+2; *fmt != '\0' ; fmt++)
+	   if ( *fmt != '%') {
+	      printf("%c",*fmt);
+	   } else
+	     switch (*++fmt) {
+	      case '\0': break;
+	      case 'n' : printf("\n"); break;
+	      case 't' : printf("\t"); break;
+	      case 'q' : printf("'"); break;
+	      case 'Q' : printf("\""); break;
+	      case 'C' :
+		printf("%s", glob_PAddress_app_info->category.name[addr->ma.attrib & 0x0F]);
+		break;
+	      case 'N' :	/* normal output */
+		for (num=0; num < 19 ; num++)
+		  print_nn(&addr->ma.a.entry[num]);
+		break;
+
+	      case 'l' : print_nn(&addr->ma.a.entry[0]); break;
+	      case 'f' : print_nn(&addr->ma.a.entry[1]); break;
+	      case 'c' : print_nn(&addr->ma.a.entry[2]); break;
+	      case 'p' : 
+		switch  (*++fmt) {
+		 default:
+		 case '1' : print_nn(&addr->ma.a.entry[3]); break;
+		 case '2' : print_nn(&addr->ma.a.entry[4]); break;
+		 case '3' : print_nn(&addr->ma.a.entry[5]); break;
+		 case '4' : print_nn(&addr->ma.a.entry[6]); break;
+		 case '5' : print_nn(&addr->ma.a.entry[7]); break;
 		}
-	 }
-	 i++;
-         break;
-
-#define PRIT if (tal->ma.a.entry[num] != NULL) { printf("%s",tal->ma.a.entry[num]); }
-
-    case 'l' : num=0; PRIT; i++; break;
-    case 'f' : num=1; PRIT; i++; break;
-    case 'c' : num=2; PRIT; i++; break;
-    case 'p' : num=3; 
-    	switch  (formatA[i+2]) {
-	case '1' : num=3; PRIT; i++; break;
-	case '2' : num=4; PRIT; i++; break;
-	case '3' : num=5; PRIT; i++; break;
-	case '4' : num=6; PRIT; i++; break;
-	case '5' : num=7; PRIT; i++; break;
-	}
-	i++;
-	break;
-    case 'a' : num=8; PRIT; i++; break;
-    case 'T' : num=9; PRIT; i++; break;
-    case 's' : num=10; PRIT; i++; break;
-    case 'z' : num=11; PRIT; i++; break;
-    case 'u' : num=12; PRIT; i++; break;
-    case 'm' : num=13; PRIT; i++; break;
-    case 'U' :
-    	switch (formatA[i+2]) {
-	case '1' : num=14; PRIT; i++; break;
-	case '2' : num=15; PRIT; i++; break;
-	case '3' : num=16; PRIT; i++; break;
-	case '4' : num=17; PRIT; i++; break;
-	}
-	i++;
-	break;
-    case 'X' :
-    	 takeoutfunnies(tal->ma.a.entry[18]);
-	 /* fall thru */
-    case 'x' :
-    	 if (tal->ma.a.entry[18] != NULL) printf("%s",tal->ma.a.entry[18]);
-	 i++;
-	 break;
-    default:	/* one letter ones */
-         printf("%c",formatA[i+1]);
-         i++;
-	 break;
-   }/*switch one letter ones*/
-
-  }/*fi*/
- }/*for*/
- printf("\n");
- }/*end if deleted*/
- }/*end for tal=*/
+		break;
+	      case 'a' : print_nn(&addr->ma.a.entry[8]); break;
+	      case 'T' : print_nn(&addr->ma.a.entry[9]); break;
+	      case 's' : print_nn(&addr->ma.a.entry[10]); break;
+	      case 'z' : print_nn(&addr->ma.a.entry[11]); break;
+	      case 'u' : print_nn(&addr->ma.a.entry[12]); break;
+	      case 'm' : print_nn(&addr->ma.a.entry[13]); break;
+	      case 'U' :
+		switch (*++fmt) {
+		 case '1' : print_nn(&addr->ma.a.entry[14]); break;
+		 case '2' : print_nn(&addr->ma.a.entry[15]); break;
+		 case '3' : print_nn(&addr->ma.a.entry[16]); break;
+		 case '4' : print_nn(&addr->ma.a.entry[17]); break;
+		}
+		break;
+	      case 'X' : takeoutfunnies(addr->ma.a.entry[18]);
+		/* Is this correct? You change the string given from the
+		 * database. Is it realy a copy? */
+	      case 'x' : print_nn(&addr->ma.a.entry[18]); break;
+	      default: printf("%c", *fmt); break;
+	     }
+	printf("\n");
+     }
 
    free_AddressList(&al);
    return 0;
#v-

Joerg.



More information about the Jpilot mailing list