#ifndef _RULESET_H_
#define _RULESET_H_

#include <sys/types.h>
#include <sysdep.h>
#include <flags.h>

#include "rule.h"

#define RSST_NEW	BIT(0)
#define RSST_DEL	BIT(1)
#define RSST_MOD	BIT(2)
#define RSST_SEQ	BIT(3)

typedef struct st_AlRuleSet	*AlRuleSet;

typedef int	rs_st;

#ifdef __STDC__
extern AlRuleSet	AlRuleSet_create(const char *, const char *, time_t, time_t, Darray);
extern NORET		AlRuleSet_destroy(AlRuleSet);
extern NORET		AlRuleSet_set_ctime(AlRuleSet, time_t);
extern NORET		AlRuleSet_set_utime(AlRuleSet, time_t);
extern NORET		AlRuleSet_mark_unmod(AlRuleSet);
extern const char *	AlRuleSet_get_desc(AlRuleSet);
extern NORET		AlRuleSet_set_desc(AlRuleSet, const char *);
extern const char *	AlRuleSet_get_internal_name(AlRuleSet);
extern unsigned		AlRuleSet_number_of_rules(AlRuleSet);
extern unsigned		AlRuleSet_add_rule_to_end(AlRuleSet, AlRule);
extern unsigned		AlRuleSet_put_rule_at_index(AlRuleSet, AlRule, unsigned);
extern AlRule		AlRuleSet_remove_rule(AlRuleSet, unsigned);
extern Bool		AlRuleSet_modp(AlRuleSet);
extern Bool		AlRuleSet_delp(AlRuleSet);
extern Bool		AlRuleSet_newp(AlRuleSet);
extern Bool		AlRuleSet_seqp(AlRuleSet);
extern time_t		AlRuleSet_get_create(AlRuleSet);
extern time_t		AlRuleSet_get_update(AlRuleSet);
extern AlRule		AlRuleSet_get_rule(AlRuleSet, unsigned);
extern NORET		AlRuleSet_get_rules(AlRuleSet, Darray);
extern Bool		AlRuleSet_deletable_on_diskp(AlRuleSet);
#else
extern AlRuleSet	AlRuleSet_create();
extern NORET		AlRuleSet_destroy();
extern NORET		AlRuleSet_set_ctime();
extern NORET		AlRuleSet_set_utime();
extern NORET		AlRuleSet_mark_unmod();
extern char *		AlRuleSet_get_desc();
extern NORET		AlRuleSet_set_desc();
extern char *		AlRuleSet_get_internal_name();
extern unsigned		AlRuleSet_number_of_rules();
extern unsigned		AlRuleSet_add_rule_to_end();
extern unsigned		AlRuleSet_put_rule_at_index();
extern AlRule		AlRuleSet_remove_rule();
extern Bool		AlRuleSet_modp();
extern Bool		AlRuleSet_delp();
extern Bool		AlRuleSet_newp();
extern Bool		AlRuleSet_seqp();
extern time_t		AlRuleSet_get_create();
extern time_t		AlRuleSet_get_update();
extern AlRule		AlRuleSet_get_rule();
extern NORET		AlRuleSet_get_rules();
extern Bool		AlRuleSet_deletable_on_diskp();
#endif

#endif

/* ----- Selected comments -----
 * AlRuleSet_create(description_str, internal_name, create_time, update_time
 *		    darray_of_rules)
 * Arguments: description_str is a string which the user should be able to
 * set.  It plays no functional role.  internal_name is a string which is the
 * name the ruleset is refernced by.  It is the name under which the ruleset
 * will be registered and saved to disk.  create_time and update_time should
 * be passed as (time_t)0 if the ruleset to be created is trueley new (not
 * from disk); the times will be set inside _create.  If create_time is
 * suplied the ruleset will not be marked as new and the create and update
 * times will be set by create_time and update_time.  darray_of_rules is a
 * darray of AlRule's.  This value can be (Darray)NULL if there are no
 * rules at the time of creation.
 * Returns: an AlRuleSet which is the new ruleset.
 * See _add_rule_to_end, _put_rule_at_index, _get_rule, _remove_rule,
 * and _destroy.
 * NOTE: The two string args are copied.
 *
 * AlRuleSet_destroy(ruleset)
 * Takes: a ruleset.  Destroys all the rules therewithin and then the
 * ruleset structure itself.
 * NOTE: See AlRSreg_remove().  Do not destroy a ruleset in this way if it
 * has been registered.  This is for unregistered rulesets only.
 *
 * AlRuleSet_set_ctime
 *
 * AlRuleSet_set_utime
 *
 * AlRuleSet_mark_unmod(ruleset)
 * Takes: a ruleset.  Unsets the modified flag.  Does not do anything to
 * update time.
 *
 * AlRuleSet_get_desc(ruleset)
 * Takes: a ruleset.
 * Returns: the description string suplied at creation time (or modified
 * since).
 *
 * AlRuleSet_set_desc(ruleset, new_desc)
 * Takes: a ruleset and a string which is the new description for the ruleset.
 * The string is copied.
 *
 * AlRuleSet_get_internal_name(ruleset)
 * Takes: a ruleset.
 * Returns: a string which is the internal name of the ruleset.
 * See: _create
 *
 * AlRuleSet_number_of_rules
 *
 * AlRuleSet_add_rule_to_end(ruleset, rule)
 * Takes: a ruleset and an AlRule.  Tacks the rule to the end of the set.
 * Returns: the new number of rules in the ruleset (as an unsigned int).
 *
 * AlRuleSet_put_rule_at_index(ruleset, rule, index)
 * Takes: a ruleset, an AlRule, and an unsigned int which is the index into
 * the list of rules in the ruleset where the rule should go.  The rule will
 * become the index'th rule (starting at 0).
 * Returns: the new number of rules in the ruleset (as an unsigned int).
 *
 * AlRuleSet_remove_rule(ruleset, index-of-rule)
 * Takes: a ruleset and an unsigned int which is the number of the rule in
 * the ruleset to be deleted (starting at 0).
 * Returns: the removed rule as AlRule.
 *
 * AlRuleSet_modp(ruleset)
 * Returns: Bool_TRUE if the ruleset has been changed since last save or
 * since read-in.
 *
 * AlRuleSet_delp
 *
 * AlRuleSet_newp
 *
 * AlRuleSet_seqp
 *
 * AlRuleSet_get_create
 *
 * AlRuleSet_get_update
 *
 * AlRuleSet_get_rule(ruleset, index-of-rule)
 * Arguments: the same as for _remove_rule.
 * Returns: the AlRule in the same way as _remove_rule but doesn't remove it.
 *
 * AlRuleSet_get_rules(ruleset, result-darray)
 * Takes: a ruleset and a created but empty Darray.  It puts the rules in
 * order into the result-darray.
 *
 * AlRuleSet_deletable_on_diskp
 *
 */
