$NetBSD: patch-ad,v 1.2 2000/09/09 02:53:10 wiz Exp $

--- src/readsfv.c.orig	Mon May 22 23:57:05 2000
+++ src/readsfv.c	Sat Sep  9 04:43:44 2000
@@ -33,12 +33,13 @@
 
 extern int  verbose;
 
-int readsfv(char *fn, char *dir, int nocase)
+int readsfv(char *fn, char *dir, int nocase, int argc, char **argv)
 {
   FILE          *fd;
   DIR           *dirp = NULL;
   char          buf[512], *end, filename[512], crc[9], path[256];
   int           file, rval = 0;
+  int           i, check;
   unsigned long len, val, sfvcrc;
   struct dirent *dirinfo;
   
@@ -67,17 +68,35 @@
   }
   
   while(fgets(buf, 512, fd)) {
-    if (buf[0] != ';') {                /* comment in the sfv file ignore */
+    if (buf[0] != ';' && buf[0] != '\n') { /* comment or empty line, ignore */
       /* build filename and crc from the sfv file */
       end = strrchr(buf, ' ');
-      if (end == NULL) {
+      if (end == NULL || end-buf > 512-10) {
         fprintf(stderr, "cksfv: %s: incorrect sfv file format\n", fn);
+	continue;
       }
       *end = '\0';
       *(end+9) = '\0';
       strncpy(crc, ++end, 9);
       strncpy(filename, buf, 512);
-      sfvcrc = strtoul(crc, '\0', 16);
+      sfvcrc = strtoul(crc, NULL, 16);
+
+      if (argc) {
+	check = 0;
+        for (i=0; i<argc; i++) {
+	  if (argv[i] == NULL)
+	    continue;
+	  if ((nocase == 1 && strcasecmp(argv[i], filename) == 0)
+	      || (nocase == 0 && strcmp(argv[i], filename) == 0)) {
+	    check = 1;
+	    break;
+	  }
+	}
+	if (check == 0)
+	  continue;
+	else
+	  argv[i] = NULL;
+      }
 
       if (nocase == 1) {
         len = strlen(filename);
@@ -126,6 +145,20 @@
     }
   }
   fclose(fd);
+  if (nocase == 1)
+    closedir(dirp);
+
+  if (argc) {
+    for (i=0; i<argc; i++) {
+      if (argv[i]) {
+        if (verbose == 1)
+          fprintf(stderr, "%-49s not found in sfv\n", argv[i]);
+	else
+	  fprintf(stderr, "cksfv: %s: not found in sfv\n", argv[i]);
+	rval = 1;
+      }
+    }
+  }
 
   if (verbose == 1) {
     if (rval == 0) {
