In some dbf file, there is an extra char (0x00) after the header trailing
0x0d, some not. So this patch check the first char after the 0x0d and 
skip if not space or star (second chunk in the patch).

This patch include a new feature too. The -D or --deleted option make
dbview to show the deleted records. In browse mode add a simple column
with space or star, or print a ' _Deleted_ :' field before the first.

Here is the patch:

diff -uNr dbview-1.0.3/db_dump.c dbview-1.0.3.new/db_dump.c
--- dbview-1.0.3/db_dump.c      2006-09-25 14:05:32.000000000 +0100
+++ dbview-1.0.3.new/db_dump.c  2006-09-25 14:38:22.000000000 +0100
@@ -224,6 +224,7 @@
 {
     int             fields;
     DBASE_FIELD     *fld;
+    unsigned char   tmp;
 
     if(dbfile==NULL) {
         printf("open failed");
@@ -269,6 +270,9 @@
        stack_field(fld);
     }
     fseek(dbfile, 1, SEEK_CUR);  /* read the silly little \r 0x0d character */
#  I hav some dbf file, where after the header trailing char 0x0d has a 0x00??
+    fread(&tmp, 1, 1, dbfile);  /* check not space or star */
+    if(tmp == ' ' or tmp == '*')
+      fseek(dbfile, -1, SEEK_CUR);
 
     return;
 }
@@ -291,8 +295,8 @@
         if(bytes!=dbhead.lrecl)
             break;
        /* Check if deleted == '*' */
-        if(Buffer[0]==' ') {
-            db3_print(flags, delim);
+       if(flags & DB_FL_DELETED || Buffer[0]==' ') {
+            db3_print(flags, delim, Buffer[0]);
             cnt--;
             }
         }
@@ -306,13 +310,20 @@
 ******************************************************/
  
 void
-db3_print(flags, delim)
+db3_print(flags, delim, deleted)
 int    flags;
 char   delim;
+char    deleted;
 {
     FLD_LIST    *temp;
  
     temp=db_fld_root;
+    if(flags & DB_FL_DELETED) {
+       if (flags & DB_FL_BROWSE)
+           printf("%c%c", deleted, delim);
+       else
+           printf(" _Deleted_ : %c\n", deleted);
+       }
     while (temp) {
         memcpy(buf_work,temp->data,temp->fld->length);
         buf_work[temp->fld->length] = '\0';
diff -uNr dbview-1.0.3/db_dump.h dbview-1.0.3.new/db_dump.h
--- dbview-1.0.3/db_dump.h      2006-09-25 14:05:32.000000000 +0100
+++ dbview-1.0.3.new/db_dump.h  2006-09-25 14:31:18.000000000 +0100
@@ -48,6 +48,7 @@
 #define DB_FL_RESERVE  0x08
 #define DB_FL_OMIT     0x10
 #define DB_FL_TRIM     0x20
+#define DB_FL_DELETED  0x40
 
 typedef struct dbase_head { 
     uint8_t    version;                /* 03 for dbIII and 83 for dbIII w/memo 
file */
@@ -112,7 +113,7 @@
 ******************************************************/
  
 void
-db3_print(int, char);
+db3_print(int, char, char);
  
 /******************************************************
                                          stack_field()
diff -uNr dbview-1.0.3/dbview.c dbview-1.0.3.new/dbview.c
--- dbview-1.0.3/dbview.c       2006-09-25 14:05:32.000000000 +0100
+++ dbview-1.0.3.new/dbview.c   2006-09-25 14:35:09.000000000 +0100
@@ -38,7 +38,7 @@
 {
     printf ("%s %s - %s, (c) 1996 by Martin Schulze\n", progname, version, 
longname);
     printf ("\n");
-    printf ("%s [-b [-t]] [-d delim] [-e] [-h] [-i] [-o] [-o] [-v] dbfile\n", 
progname);
+    printf ("%s [-b [-t]] [-d delim] [-e] [-h] [-i] [-D] [-o] [-v] dbfile\n", 
progname);
 }
 
 void help_long()
@@ -50,6 +50,7 @@
     printf ("  --description, -e      display field description\n");
     printf ("  --help, -h             display help\n");
     printf ("  --info, -i             display db information\n");
+    printf ("  --deleted, -D          display deleted records\n");
     printf ("  --omit, -o             omit db records\n");
     printf ("  --reserve, -r          reserve fieldnames from beeing 
translated\n");
     printf ("  --trim, -t             trim browse fields\n");
@@ -68,6 +69,7 @@
        {"help", no_argument, 0, 'H'},
        {"info", no_argument, 0, 'i'},
        {"omit", no_argument, 0, 'o'},
+       {"deleted", no_argument, 0, 'D'},
        {"reserve", no_argument, 0, 'r'},
        {"trim", no_argument, 0, 't'},
        {"version", no_argument, 0, 'v'},
@@ -78,7 +80,7 @@
     char delim = ':';
 
     optind = 0;
-    while ( (c = getopt_long(argc, argv, "Hbd:ehiortv", long_options, 
&opt_index)) != -1 ) {
+    while ( (c = getopt_long(argc, argv, "Hbd:ehiDortv", long_options, 
&opt_index)) != -1 ) {
        switch (c) {
        case 'H':       /* --help */
            help_long (); exit (0);
@@ -100,6 +102,9 @@
        case 'i':
            flags |= DB_FL_INFO;
            break;
+       case 'D':
+           flags |= DB_FL_DELETED;
+           break;
        case 'o':
            flags |= DB_FL_OMIT;
            break;


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to