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

static char rcsid[] =
    "$Id: user.c,v 1.6 2002/06/23 17:16:39 root Exp root $";

/*
 * $Log: user.c,v $
 * Revision 1.6  2002/06/23 17:16:39  root
 * #
 *
 * Revision 1.5  2001/10/12 13:51:11  root
 * #
 *
 * Revision 1.4  2001/10/04 18:00:36  root
 * #
 *
 * Revision 1.3  2001/01/30 06:16:18  root
 * #
 *
 * Revision 1.2  2000/12/01 04:13:42  root
 * #
 *
 * Revision 1.1  2000/11/23 23:45:19  root
 * #
 *
 */

#include "project.h"

EXTERNAL Files files_user_init(void)
{
  Collection c = NULL;
  Files ret = files_init();
  FILE *f;
  char buf[1024], *ptr;
  int i;

  sprintf(buf, "%s/.hifi/collections", getenv("HOME"));

  f = fopen(buf, "r");

  if (!f)
    return ret;


  while (!feof(f)) {

    bzero(buf, sizeof(buf));
    fgets(buf, sizeof(buf) - 1, f);
    buf[sizeof(buf) - 1] = 0;

    i = strlen(buf) - 1;
    if (i < 0)
      i = 0;
    buf[i] = 0;

    ptr = index(buf, ':');

    if ((ptr) && (buf[0] != '#')) {
      *ptr = 0;


      if (strcmp(buf, "files") == 0) {
        fprintf(stderr, "Querying %s...\n", ptr + 1);

        c = files_filesystem_collection(ptr + 1);
        if (c)
          files_add_collection(ret, c);

      } else if (strcmp(buf, "http") == 0) {
        fprintf(stderr, "Querying %s...\n", ptr + 1);

        c = files_http_collection(ptr + 1);
        if (c)
          files_add_collection(ret, c);


      } else if (strcmp(buf, "rwork") == 0) {
        files_work_reset();
      }

    }
  }

  fclose(f);
  return ret;
}
