/* ==== fc.h ============================================================
 * Copyright (c) 1995 by Chris Provenzano, proven@mit.edu
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *  This product includes software developed by Chris Provenzano.
 * 4. The name of Chris Provenzano may not be used to endorse or promote 
 *	  products derived from this software without specific prior written
 *	  permission.
 *
 * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 * SUCH DAMAGE.
 *
 * Description : Main fc header.
 *
 *  1.00 95/06/28  proven
 *      -Started coding this file.
 */

#include "cdefs.h"

#define FC_KEY_FILE		".fckeys"
#define FC_KEY_BKUP		".fckeys~"
#define FC_FILE_FILE	".fcfiles"
#define FC_FILE_BKUP	".fcfiles~"
#define FC_GROUP_FILE	".fcgroups"
#define FC_GROUP_BKUP	".fcgroups~"
#define FC_DIR			"/mit/proven/.filecabnit"

/* Errors */
enum fc_error {
#define __fc_defstate(S,NAME)   S,
#include "fc_error.h"
#undef __fc_defstate
	FC_STATE_MAX
};

enum alloctype {
	UN_ALLOCED		= 0,
	IND_ALLOCED,
	BLOCK_ALLOCED,
	OTHER_ALLOCED
};

struct fc_keys {
	enum alloctype		  alloctype;
	char				* key_name;
	int					  key_num;

	int					  file_count;
	struct fc_files		* file_first;
#ifndef SPACE_OPTOMIZE
	struct fc_filekeys	* filekey_first;
#endif

	/* TTT optomize with a binary tree. -- proven */
	struct fc_keys		* key_next;
};

struct fc_files {
	enum alloctype		  alloctype;
	char				* file_name;

	/* TTT optomize filekey search with binary search -- proven */
	struct fc_filekeys	* filekey_first;	/* Array of filekeys */
	int				  	  filekey_count;

	struct fc_files		* file_next;
};

struct fc_groups {
	enum alloctype		  alloctype;
	char				* group_name;

	/* TTT optomize groupkey search with binary search -- proven */
	struct fc_keys	   ** groupkey_first;	/* Array of key pointers */
	int				  	  groupkey_count;

	struct fc_groups	* group_next;
};

struct fc_listkeys {
	struct fc_keys		* key;
	struct fc_files		* file_last;
	struct fc_files		* file_first;
	int					  file_count;
};

struct fc_filekeys {
	struct fc_keys		* key;
	struct fc_files		* file_next;
#ifndef SPACE_OPTOMIZE
	struct fc_filekeys	* filekey_next;
#endif
};

struct fc {
	int			 		  keycount;
	char				* keydata;
	struct fc_keys  	* keys;

	int			 		  filecount;
	char				* filedata;
	struct fc_files 	* files;

	int			 		  groupcount;
	char				* groupdata;
	struct fc_groups 	* groups;

	struct fc_listkeys  * listkeys_current;		/* An array of listkeys */
	int					  count_current;
};

#define FC_INITIALIZER	{ 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL, 0 }

__BEGIN_DECLS

int 				fc_key_init		__P((void));
struct fc_keys * 	fc_key_alloc	__P((unsigned int));
void				fc_key_free		__P((struct fc_keys *));

int					fc_key_insert	__P((char *, struct fc_keys **, 
										 struct fc_keys **));

int 				fc_file_init	__P((void));
struct fc_files * 	fc_file_alloc	__P((unsigned int));
void				fc_file_free	__P((struct fc_files *));

int 				fc_group_init	__P((void));
struct fc_groups * 	fc_group_alloc	__P((unsigned int));
void				fc_group_free	__P((struct fc_groups *));

void				fc_display		__P((char **, int));

__END_DECLS
