chiark / gitweb /
new -t option for putting tab before filename
[chiark-utils.git] / cprogs / summer.c
index 4f42e608a7774f3636c173690bd0641b8b3e0345..ee396c6f56f644ef9fdeda7cb52fb22680ee2e26 100644 (file)
 #include <stdarg.h>
 #include <limits.h>
 #include <assert.h>
+#include <stdlib.h>
 
-#include "md5.h"
+#include "nettle/md5-compat.h"
 
 #define MAXFN 2048
 #define MAXDEPTH 1024
 #define CSUMXL 32
 
-static int quiet=0;
+static int quiet=0, hidectime=0, filenamefieldsep=' ';
 static FILE *errfile;
 
 static void fn_escaped(FILE *f, const char *fn) {
@@ -79,7 +80,7 @@ static void problem(const char *path, int padto, const char *fmt, ...) {
 
 static void csum_file(const char *path) {
   FILE *f;
-  struct MD5Context mc;
+  MD5_CTX mc;
   char db[65536];
   unsigned char digest[16];
   size_t r;
@@ -159,15 +160,18 @@ static int item(const char *path, const struct stat *stab,
     else linktarg[r]= 0;
   }
 
-  printf(" %10lu %4d %4o %10ld %10ld %10lu %10lu %10lu ",
+  printf(" %10lu %4d %4o %10ld %10ld %10lu %10lu",
         (unsigned long)stab->st_size,
         (int)stab->st_nlink,
         (unsigned)stab->st_mode & 07777U,
         (unsigned long)stab->st_uid,
         (unsigned long)stab->st_gid,
         (unsigned long)stab->st_atime,
-        (unsigned long)stab->st_mtime,
-        (unsigned long)stab->st_ctime);
+        (unsigned long)stab->st_mtime);
+  if (!hidectime)
+    printf(" %10lu",
+          (unsigned long)stab->st_ctime);
+  putchar(filenamefieldsep);
   fn_escaped(stdout, path);
 
   if (S_ISLNK(stab->st_mode)) {
@@ -225,6 +229,12 @@ int main(int argc, const char *const *argv) {
       case 'q':
        quiet= 1;
        break;
+      case 't':
+       filenamefieldsep= '\t';
+       break;
+      case 'C':
+       hidectime= 1;
+       break;
       case 'f':
        errfile= stdout;
        break;