wilde: utils/admin validate-skiplist.c,1.4,1.5

cvs at intevation.de cvs at intevation.de
Sun Mar 26 16:12:55 CEST 2006


Author: wilde

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv21473

Modified Files:
	validate-skiplist.c 
Log Message:
Bug Fix: correct handling of files where last node is not COMMIT.
Beautified warning messages.


Index: validate-skiplist.c
===================================================================
RCS file: /kolabrepository/utils/admin/validate-skiplist.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- validate-skiplist.c	26 Mar 2006 11:22:04 -0000	1.4
+++ validate-skiplist.c	26 Mar 2006 14:12:53 -0000	1.5
@@ -70,6 +70,15 @@
   return addr;
 }
 
+inline int
+peek (FILE *file)
+{
+  int c;
+  if ((c = getc (file)) != EOF)
+    ungetc (c, file);
+  return c;
+}
+
 int32_t
 read_word (FILE *file)
 {
@@ -97,12 +106,13 @@
 void
 commit_maybe (FILE *file)
 {
-  if (read_word (file) == COMMIT)
-    {
+  if (peek (file) != EOF)
+    if (read_word (file) == COMMIT)
       ++commit;
-    }
+    else
+      fseek (file, -4, SEEK_CUR);
   else
-    fseek (file, -4, SEEK_CUR);
+    WARN (puts ("Warning: Last skipnode is not COMMIT"););
 }
 
 
@@ -138,7 +148,7 @@
 void
 validate_file (char* filename)
 {
-  int i,c;
+  int i;
   int32_t word;
   long logstart;
   FILE *file;
@@ -150,7 +160,7 @@
 
   WARN (word = read_word (file); /* magic number */
 	if (word != MAGICNUM)
-	  printf ("Strange magic number %X expected %X\n", word, MAGICNUM);
+	  printf ("Warning: Strange magic number %X expected %X\n", word, MAGICNUM);
 	);
 
   INFO (jump_to_position (file, 20); /* jump to version numbers */
@@ -176,11 +186,8 @@
   jump_to_position (file, logstart);
   INFO (puts ("Checking log part..."););
 
-  while ((c = getc (file)) != EOF)
-    {
-      ungetc (c, file);
-      add_delete (file);
-    }
+  while (peek (file) != EOF)
+    add_delete (file);
 
   INFO (printf ("Found %i ADD, %i DELETE and %i COMMIT nodes in log.\n\n",
 		add, delete, commit);





More information about the commits mailing list