Index: Makefile.am
===================================================================
RCS file: /sources/chmspec/chmtests/Makefile.am,v
retrieving revision 1.2
diff -bu2 -r1.2 Makefile.am
--- Makefile.am
+++ Makefile.am
@@ -14,4 +14,5 @@
 system.c system.h \
 bssc.c bssc.h \
+itbits.c itbits.h \
 md5.c md5.h
 
Index: chmtests.c
===================================================================
RCS file: /sources/chmspec/chmtests/chmtests.c,v
retrieving revision 1.5
diff -bu2 -r1.5 chmtests.c
--- chmtests.c
+++ chmtests.c
@@ -28,5 +28,6 @@
 #include <ftw.h>
 #include <libgen.h>
-
+#include <unistd.h>
+#include <ctype.h>
 
 
@@ -36,6 +37,8 @@
 #include "chmtests.h"
 
+/* test_* functions: */
 #include "system.h"
 #include "bssc.h"
+#include "itbits.h"
 
 #include "md5.h"
@@ -92,6 +95,9 @@
 };
 
+int verbose = 0;
+
 int main( int argc, char* argv[] ){
-	unsigned int argi;
+	unsigned int argi = 1;
+    int c;
 	
 #if REOPEN_STDIN
@@ -102,7 +108,34 @@
 #endif
 	
-	if( argc <= 1 ) return recurse_directory(".");
+    /* parse command line: */
+    while ((c = getopt (argc, argv, "hv::")) != -1) {
+        switch (c) {
+        case 'v':
+            verbose = 1;
+            break;
+
+        case 'h':
+            printf("Usage: %s [-v] [-h] [FILE/DIRECTORY] ...\n", argv[0]);
+            printf("Runs a set of tests on the internal files found in the given CHM file(s).\n");
+            printf("Given directories are recursively walked.\n");
+            printf("If no arguments are given, then the current directory will be recursively walked.\n");
+            printf("\nOptions:\n");
+            printf(" -h\tShow this help.\n");
+            printf(" -v\tBe verbose.\n");
+            printf("\nCopyright (C) 2004 Pabs <pabs@zip.to>\n");
+            return 0;
+
+        default:
+            break;
+        }
+
+        argi++;    /* this argument has been processed: skip it later */
+    }
 	
-	for( argi = 1; argi < argc; argi++ ){
+    /* if there are no arguments, recurse current folder */
+	if( argc - argi <= 1 ) return recurse_directory(".");
+	
+    /* if there are un-processed arguments, consider them as files/dirs to be tested */
+	for( ; argi < argc; argi++ ){
 		recurse_directory(argv[argi]);
 	}
@@ -119,4 +152,7 @@
 	int ret = BORING;
 	
+    if( flag != FTW_F )
+        return 0;       /* skip non-files */
+	
 	current_chm = (char*)file;
 	current_chm_len = strlen(current_chm);
@@ -124,9 +160,31 @@
 	current_file_len = strlen(current_file);
 	
-	ret = perform_tests(file,current_chm_len);
-	/* if( result == ERROR ) return ERROR; */
+    /* provide feedback to the user */
+    if( verbose )
+        printf("Processing '%s': ", file);
+
+    /* do all tests on this file */
+	ret = perform_tests(file, current_chm_len);
+
+    if( verbose )
+        switch (ret)
+        {
+        case BORING:
+            printf(" ...well, it was boring.\n");
+            break;
+        case INTERESTING:
+            printf(" ...interesting!\n");
+            break;
+        case ERROR:
+            printf(" ...ERROR\n");
+            break;
+        case EARLY:
+            printf(" ...early??\n");
+            break;
+        }
+
 	if( ret == INTERESTING ) md5((char*)file);
 
-	return 0;
+	return 0;      /* continue walking */
 }
 
@@ -254,4 +312,6 @@
 		if( test_SYSTEM(chmf) == INTERESTING )
 			ret = INTERESTING;
+        if( test_ITBITS(chmf) == INTERESTING )
+            ret = INTERESTING;
 		if( test_BSSC(chmf) == INTERESTING )
 			ret = INTERESTING;
Index: itbits.c
--- /dev/null
+++ itbits.c
@@ -0,0 +1,56 @@
+/* /#ITBITS file tester */
+
+#include <stdlib.h>
+#include <malloc.h>
+#include <chm_lib.h>
+
+#include "chmtests.h"
+
+static BYTE* buf = NULL;
+static uint buflen = 0;
+
+int test_ITBITS( struct chmFile* chmf )
+{
+	int ret = BORING;
+	struct chmUnitInfo ui;
+	LONGUINT64 gotlen, i;
+
+	if( chm_resolve_object(chmf, "/#ITBITS", &ui) != CHM_RESOLVE_SUCCESS ){
+		return ret;
+	}
+
+    if( ui.length == 0 ){
+        // #ITBITS section can be empty:
+        return ret;
+    }
+
+	if( buflen < ui.length ){
+		BYTE* t = (BYTE*)realloc( buf, ui.length+1 );
+		if( !t ){
+			error( "not enough memory" );
+			return ERROR;
+		}
+		buf = t;
+		buflen = ui.length;
+	}
+
+	gotlen = chm_retrieve_object(chmf, &ui, buf, 0, ui.length);
+	if( gotlen != ui.length ){
+		if( gotlen != 0 )
+			warning( ITBITS, "couldn't get file (got %llu bytes, expected 4)", gotlen );
+		else
+			warning( ITBITS, "empty file (expected non-empty file)" );
+		return INTERESTING;
+	}
+
+	buf[buflen] = 0;
+
+	for( i = 0; i < ui.length; i++ ){
+		if( buf[i] != '0' ){
+			warning( ITBITS, "contains non-null character:  %c [0x%02x]", buf[i], buf[i] );
+			return INTERESTING;
+		}
+	}
+
+	return BORING;
+}
Index: itbits.h
--- /dev/null
+++ itbits.h
@@ -0,0 +1,2 @@
+#include <chm_lib.h>
+int test_ITBITS(struct chmFile* chmf);
