/* Copyright 2007 Vince Busam */ /* Distributable under GPLv2 */ /* Version 0.4 */ /* This does a bit of a brute force decoding of the file, as I haven't */ /* figured out some of the inconsistencies between different files. */ #include #include #include #include #define NUMSTR 4 /* Name, Mobile, Home, Work, Junk */ #define STRLEN 128 void print_record(char strings[NUMSTR][STRLEN]) { int i; if (strlen(strings[0]) < 1) return; /* Prettify an all-caps record */ if ((strlen(strings[0])>1) && isupper(strings[0][1])) for (i=1;i 1) { /* If we've just finished off a string of type non-zero (a name) */ /* of more than one character, we're seeing a new name */ if ((charcount > 1) && (type != 0)) { type = 0; charcount = 0; } else if (charcount > 1) { /* If we see something after the zeros after the name, it's */ /* either the type marker for the next string, or the sequence */ /* number of the record, which may or may not be preceded by a 1 */ type = NUMSTR-1; /* Put this junk in an unprinted string */ } } zero = 0; /* A 1,2 or 3 marks the beginning of a phone number */ if ((c > 0) && (c < (NUMSTR-1))) { type = c; //printf("(0x%0x,%i)",c,zero); strcpy(strings[type],""); charcount = 0; } if (!isprint(c)) break; /* If we're seeing the first character of a name, print the last */ /* record and wipe the slate clean */ if ((type==0) && (charcount==0)) { print_record(strings); memset(strings,0,sizeof(strings)); } charcount++; sprintf(t,"%c",c); if (strlen(strings[type]) < (STRLEN-1)) strcat(strings[type],t); break; } } print_record(strings); fclose(fp); return 0; }