/*
 * fish.c:
 *
 * Copyright (c) 2000 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] =
    "$Id: builddb.c,v 1.2 2000/09/24 01:58:26 root Exp $";

/*
 * $Log: builddb.c,v $
 * Revision 1.2  2000/09/24 01:58:26  root
 * #
 *
 * Revision 1.1  2000/09/24 01:44:47  root
 * #
 *
 */

#include "libfiles.h"
#include <stdio.h>
#include <sys/stat.h>




extern char *directory_of(char *);

int main(int argc, char *argv[])
{
  FILE *f;
  char *d;
  struct stat s;
  char *c;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    return -1;
  }

  c = argv[1];

  if (!stat(c, &s)) {
    if (S_ISDIR(s.st_mode)) {
      fprintf(stderr, "%s is a directory\n", c);
      return -1;

    }

  }

  d = directory_of(c);

  unlink(c);

  files_ftw(d);

  f = fopen(c, "w");
  files_dumpdb(f, c);
  fclose(f);

  return 0;
}
