b279f097601548fd9a144ffc20642979fb75db91
kent
  Tue Mar 26 21:50:57 2013 -0700
Making function that puts an md5sum file into a hash.
diff --git src/lib/md5.c src/lib/md5.c
index a2da909..fed2e93 100644
--- src/lib/md5.c
+++ src/lib/md5.c
@@ -1,24 +1,26 @@
 /*
  * RFC 1321 compliant MD5 implementation,
  * by Christophe Devine <devine@cr0.net>;
  * this program is licensed under the GPL.
  */
 
 #include "common.h"
 #include "md5.h"
 #include "hex.h"
+#include "linefile.h"
+#include "hash.h"
 
 
 #define GET_UINT32(n,b,i)					\
 {								\
     (n) = (uint32) ((uint8 *) b)[(i)]				\
       | (((uint32) ((uint8 *) b)[(i)+1]) <<  8)			\
       | (((uint32) ((uint8 *) b)[(i)+2]) << 16)			\
       | (((uint32) ((uint8 *) b)[(i)+3]) << 24);		\
 }
 
 #define PUT_UINT32(n,b,i)					\
 {								\
     (((uint8 *) b)[(i)]  ) = (uint8) (((n)      ) & 0xFF);	\
     (((uint8 *) b)[(i)+1]) = (uint8) (((n) >>  8) & 0xFF);	\
     (((uint8 *) b)[(i)+2]) = (uint8) (((n) >> 16) & 0xFF);	\
@@ -249,30 +251,42 @@
     byteToHex( md5[i], h++);  // note h is incremented here and also at the top of the loop
     }
 hex[32] = 0;
 return cloneString(hex);
 }
 
 char *md5HexForFile(char * fileName)
 /* read f in buffer pieces and return hex string for md5sum */
 {
 // MD5 COMPUTE
 unsigned char md5[16];       /* Keep the md5 checksum here. */
 md5ForFile(fileName,md5);
 return md5ToHex(md5);
 }
 
+struct hash *md5FileHash(char *fileName)
+/* Read md5sum file and return a hash keyed by file names with md5sum values. */
+{
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[2];
+struct hash *hash = hashNew(0);
+while (lineFileRow(lf, row))
+    hashAdd(hash, row[1], cloneString(row[0]));
+lineFileClose(&lf);
+return hash;
+}
+
 #ifdef TEST
 
 #include <stdio.h>
 
 /*
  * those are the standard RFC 1321 test vectors
  */
 
 static char *msg[] =
 {
     "",
     "a",
     "abc",
     "message digest",
     "abcdefghijklmnopqrstuvwxyz",