* Make-mc.in: Eliminate ubiqx.
* samba/Makefile.in: Likewise. Remove some unused variables. * samba/include/includes.h: Eliminate dependency on ubiqx. * samba/include/nameserv.h: Likewise. * samba/include/proto.h: Remove prototypes from nmbd/*. * samba/ubiqx/*: Remove.
Этот коммит содержится в:
родитель
47a538a968
Коммит
90096c49b9
@ -1,5 +1,12 @@
|
||||
2001-02-09 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* Make-mc.in: Eliminate ubiqx.
|
||||
* samba/Makefile.in: Likewise. Remove some unused variables.
|
||||
* samba/include/includes.h: Eliminate dependency on ubiqx.
|
||||
* samba/include/nameserv.h: Likewise.
|
||||
* samba/include/proto.h: Remove prototypes from nmbd/*.
|
||||
* samba/ubiqx/*: Remove.
|
||||
|
||||
* samba/configure.in: More useless stuff removed.
|
||||
* samba/Makefile.in: Likewise.
|
||||
* Make-mc.in: Remove samba/smbwrapper directory.
|
||||
|
@ -10,7 +10,7 @@ top_builddir = ..
|
||||
|
||||
@MCF@
|
||||
|
||||
SAMBA_INCLUDES = -I$(srcdir)/samba/ubiqx
|
||||
SAMBA_INCLUDES =
|
||||
|
||||
CFLAGS = $(XCFLAGS)
|
||||
CPPFLAGS = $(XCPPFLAGS) -I. $(SAMBA_INCLUDES)
|
||||
@ -146,17 +146,6 @@ SAMBA_DIST_TESTS = \
|
||||
sysv_ipc.c \
|
||||
trivial.c
|
||||
|
||||
SAMBA_DIST_UBIQX = \
|
||||
COPYING.LIB \
|
||||
README.UBI \
|
||||
debugparse.h \
|
||||
sys_include.h \
|
||||
ubi_BinTree.h \
|
||||
ubi_Cache.h \
|
||||
ubi_SplayTree.h \
|
||||
ubi_dLinkList.h \
|
||||
ubi_sLinkList.h
|
||||
|
||||
NONETFILES = \
|
||||
cpio.o \
|
||||
direntry.o \
|
||||
@ -306,7 +295,6 @@ distdir:
|
||||
mkdir $(distdir)/samba/libsmb
|
||||
mkdir $(distdir)/samba/param
|
||||
mkdir $(distdir)/samba/tests
|
||||
mkdir $(distdir)/samba/ubiqx
|
||||
for I in $(SAMBA_DIST_TOPLEVEL); do \
|
||||
cp -p $(srcdir)/samba/$$I $(distdir)/samba \
|
||||
|| exit 1; done
|
||||
@ -325,9 +313,6 @@ distdir:
|
||||
for I in $(SAMBA_DIST_TESTS); do \
|
||||
cp -p $(srcdir)/samba/tests/$$I $(distdir)/samba/tests \
|
||||
|| exit 1; done
|
||||
for I in $(SAMBA_DIST_UBIQX); do \
|
||||
cp -p $(srcdir)/samba/ubiqx/$$I $(distdir)/samba/ubiqx \
|
||||
|| exit 1; done
|
||||
|
||||
depend dep: mcdep
|
||||
|
||||
|
@ -7,7 +7,6 @@ prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
mandir=@mandir@
|
||||
|
||||
LIBS=@LIBS@
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@
|
||||
CPPFLAGS=@CPPFLAGS@
|
||||
@ -65,13 +64,12 @@ SMBRUN = $(BINDIR)/smbrun
|
||||
|
||||
|
||||
PASSWD_FLAGS = -DPASSWD_PROGRAM=\"$(PASSWD_PROGRAM)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\"
|
||||
FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx $(CPPFLAGS) -DSMBLOGFILE=\"$(SMBLOGFILE)\" -DNMBLOGFILE=\"$(NMBLOGFILE)\"
|
||||
FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include $(CPPFLAGS) -DSMBLOGFILE=\"$(SMBLOGFILE)\" -DNMBLOGFILE=\"$(NMBLOGFILE)\"
|
||||
FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"
|
||||
FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\"
|
||||
FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" -DBINDIR=\"$(BINDIR)\"
|
||||
FLAGS5 = $(FLAGS1) $(FLAGS2) $(FLAGS3) $(FLAGS4) -DHAVE_INCLUDES_H
|
||||
FLAGS = $(ISA) $(FLAGS5) $(PASSWD_FLAGS)
|
||||
FLAGS32 = $(ISA32) $(FLAGS5) $(PASSWD_FLAGS)
|
||||
|
||||
SCRIPTS = $(srcdir)/script/smbtar $(srcdir)/script/addtosmbpass $(srcdir)/script/convert_smbpasswd
|
||||
|
||||
@ -121,108 +119,6 @@ LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \
|
||||
lib/util_unistr.o lib/util_file.o \
|
||||
lib/util.o lib/util_sock.o lib/util_sec.o smbd/ssl.o
|
||||
|
||||
UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
|
||||
ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o ubiqx/debugparse.o
|
||||
|
||||
PARAM_OBJ = param/loadparm.o param/params.o
|
||||
|
||||
LIBSMB_OBJ = libsmb/clientgen.o libsmb/namequery.o libsmb/nmblib.o \
|
||||
libsmb/nterr.o libsmb/smbdes.o libsmb/smbencrypt.o \
|
||||
libsmb/smberr.o libsmb/credentials.o libsmb/pwd_cache.o \
|
||||
libsmb/passchange.o
|
||||
|
||||
RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_misc.o \
|
||||
rpc_parse/parse_net.o rpc_parse/parse_prs.o \
|
||||
rpc_parse/parse_reg.o rpc_parse/parse_rpc.o \
|
||||
rpc_parse/parse_samr.o rpc_parse/parse_srv.o \
|
||||
rpc_parse/parse_wks.o rpc_parse/parse_sec.o
|
||||
|
||||
RPC_CLIENT_OBJ = \
|
||||
rpc_client/cli_login.o \
|
||||
rpc_client/cli_netlogon.o \
|
||||
rpc_client/cli_pipe.o \
|
||||
rpc_client/cli_lsarpc.o \
|
||||
rpc_client/cli_wkssvc.o \
|
||||
rpc_client/cli_srvsvc.o \
|
||||
rpc_client/cli_reg.o \
|
||||
rpc_client/cli_samr.o
|
||||
|
||||
|
||||
LOCKING_OBJ = locking/locking.o locking/locking_shm.o locking/locking_slow.o \
|
||||
locking/shmem.o locking/shmem_sysv.o
|
||||
|
||||
PASSDB_OBJ = passdb/passdb.o passdb/smbpassfile.o passdb/smbpass.o \
|
||||
passdb/pass_check.o passdb/ldap.o passdb/nispass.o passdb/smbpasschange.o
|
||||
|
||||
PRINTING_OBJ = printing/pcap.o printing/print_svid.o printing/printing.o
|
||||
|
||||
SMBRUN_OBJ = utils/smbrun.o lib/util_sec.o
|
||||
|
||||
MAKE_SMBCODEPAGE_OBJ = utils/make_smbcodepage.o $(PARAM_OBJ) \
|
||||
$(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
MAKE_PRINTERDEF_OBJ = utils/make_printerdef.o $(PARAM_OBJ) \
|
||||
$(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
STATUS_OBJ = utils/status.o $(LOCKING_OBJ) $(PARAM_OBJ) \
|
||||
$(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
TESTPARM_OBJ = utils/testparm.o \
|
||||
$(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(PRINTING_OBJ) $(UBIQX_OBJ) \
|
||||
$(LIB_OBJ)
|
||||
|
||||
SMBPASSWD_OBJ = utils/smbpasswd.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(PASSDB_OBJ) \
|
||||
$(UBIQX_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(LIB_OBJ)
|
||||
|
||||
RPCCLIENT_OBJ = rpcclient/rpcclient.o \
|
||||
rpcclient/display.o \
|
||||
rpcclient/cmd_lsarpc.o \
|
||||
rpcclient/cmd_wkssvc.o \
|
||||
rpcclient/cmd_samr.o \
|
||||
rpcclient/cmd_reg.o \
|
||||
rpcclient/cmd_srvsvc.o \
|
||||
rpcclient/cmd_netlogon.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) \
|
||||
$(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(PASSDB_OBJ)
|
||||
|
||||
CLIENT_OBJ = client/client.o client/clitar.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
MOUNT_OBJ = client/smbmount.o client/clientutil.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
MNT_OBJ = client/smbmnt.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
UMOUNT_OBJ = client/smbumount.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
NMBLOOKUP_OBJ = utils/nmblookup.o $(PARAM_OBJ) $(UBIQX_OBJ) \
|
||||
$(LIBSMB_OBJ) $(LIB_OBJ)
|
||||
|
||||
SMBTORTURE_OBJ = utils/torture.o utils/nbio.o $(LIBSMB_OBJ) $(PARAM_OBJ) \
|
||||
$(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
RPCTORTURE_OBJ = utils/rpctorture.o \
|
||||
rpcclient/display.o \
|
||||
rpcclient/cmd_lsarpc.o \
|
||||
rpcclient/cmd_wkssvc.o \
|
||||
rpcclient/cmd_samr.o \
|
||||
rpcclient/cmd_srvsvc.o \
|
||||
rpcclient/cmd_netlogon.o \
|
||||
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) \
|
||||
$(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(PASSDB_OBJ)
|
||||
|
||||
DEBUG2HTML_OBJ = utils/debug2html.o ubiqx/debugparse.o
|
||||
|
||||
SMBFILTER_OBJ = utils/smbfilter.o $(LIBSMB_OBJ) $(PARAM_OBJ) \
|
||||
$(UBIQX_OBJ) $(LIB_OBJ)
|
||||
|
||||
PROTO_OBJ = $(CLIENT_OBJ) \
|
||||
$(RPCCLIENT_OBJ) $(SMBTORTURE_OBJ)
|
||||
|
||||
######################################################################
|
||||
# now the rules...
|
||||
######################################################################
|
||||
@ -234,8 +130,6 @@ all : CHECK $(SAMBAFILES)
|
||||
|
||||
CHECK:
|
||||
@echo "Using FLAGS = $(FLAGS)"
|
||||
@echo "Using FLAGS32 = $(FLAGS32)"
|
||||
@echo "Using LIBS = $(LIBS)"
|
||||
|
||||
MAKEDIR = || exec false; \
|
||||
if test -d "$$dir"; then :; else \
|
||||
@ -274,10 +168,6 @@ uninstall:
|
||||
clean:
|
||||
-rm -f core */*~ *~ */*.o */*.so bin/*
|
||||
|
||||
proto:
|
||||
@echo rebuilding include/proto.h
|
||||
@cd $(srcdir) && $(AWK) -f script/mkproto.awk `echo $(PROTO_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u | egrep -v 'ubiqx/|wrapped'` > include/proto.h
|
||||
|
||||
etags:
|
||||
etags `find . -name "*.[ch]"`
|
||||
|
||||
|
@ -611,16 +611,8 @@ extern int errno;
|
||||
|
||||
|
||||
/* Lists, trees, caching, datbase... */
|
||||
#include "ubi_sLinkList.h"
|
||||
#include "ubi_dLinkList.h"
|
||||
#include "dlinklist.h"
|
||||
|
||||
#ifndef UBI_BINTREE_H
|
||||
#include "ubi_Cache.h"
|
||||
#endif /* UBI_BINTREE_H */
|
||||
|
||||
#include "debugparse.h"
|
||||
|
||||
#include "version.h"
|
||||
#include "smb.h"
|
||||
#include "nameserv.h"
|
||||
|
@ -182,26 +182,6 @@ struct nmb_data
|
||||
time_t refresh_time; /* The time the record should be refreshed. */
|
||||
};
|
||||
|
||||
/* This structure represents an entry in a local netbios name list. */
|
||||
struct name_record
|
||||
{
|
||||
ubi_trNode node[1];
|
||||
struct subnet_record *subnet;
|
||||
struct nmb_name name; /* The netbios name. */
|
||||
struct nmb_data data; /* The netbios data. */
|
||||
};
|
||||
|
||||
/* Browser cache for synchronising browse lists. */
|
||||
struct browse_cache_record
|
||||
{
|
||||
ubi_dlNode node[1];
|
||||
pstring lmb_name;
|
||||
pstring work_group;
|
||||
struct in_addr ip;
|
||||
time_t sync_time;
|
||||
time_t death_time; /* The time the record must be removed. */
|
||||
};
|
||||
|
||||
/* This is used to hold the list of servers in my domain, and is
|
||||
contained within lists of domains. */
|
||||
|
||||
@ -389,28 +369,6 @@ enum subnet_type {
|
||||
WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
|
||||
};
|
||||
|
||||
struct subnet_record
|
||||
{
|
||||
struct subnet_record *next;
|
||||
struct subnet_record *prev;
|
||||
|
||||
char *subnet_name; /* For Debug identification. */
|
||||
enum subnet_type type; /* To catagorize the subnet. */
|
||||
|
||||
struct work_record *workgrouplist; /* List of workgroups. */
|
||||
ubi_trRoot namelist[1]; /* List of netbios names. */
|
||||
struct response_record *responselist; /* List of responses expected. */
|
||||
|
||||
BOOL namelist_changed;
|
||||
BOOL work_changed;
|
||||
|
||||
struct in_addr bcast_ip;
|
||||
struct in_addr mask_ip;
|
||||
struct in_addr myip;
|
||||
int nmb_sock; /* socket to listen for unicast 137. */
|
||||
int dgram_sock; /* socket to listen for unicast 138. */
|
||||
};
|
||||
|
||||
/* A resource record. */
|
||||
struct res_rec {
|
||||
struct nmb_name rr_name;
|
||||
|
@ -620,344 +620,6 @@ struct shmem_ops *smb_shm_open(int ronly);
|
||||
|
||||
struct shmem_ops *sysv_shm_open(int ronly);
|
||||
|
||||
/*The following definitions come from nmbd/asyncdns.c */
|
||||
|
||||
int asyncdns_fd(void);
|
||||
void kill_async_dns_child(void);
|
||||
void start_async_dns(void);
|
||||
void run_dns_queue(void);
|
||||
BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
|
||||
struct name_record **n);
|
||||
BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
|
||||
struct name_record **n);
|
||||
void kill_async_dns_child(void);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd.c */
|
||||
|
||||
BOOL reload_services(BOOL test);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_become_dmb.c */
|
||||
|
||||
void add_domain_names(time_t t);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_become_lmb.c */
|
||||
|
||||
void insert_permanent_name_into_unicast( struct subnet_record *subrec,
|
||||
struct nmb_name *nmbname, uint16 nb_type );
|
||||
void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work,
|
||||
BOOL force_new_election);
|
||||
void become_local_master_browser(struct subnet_record *subrec, struct work_record *work);
|
||||
void set_workgroup_local_master_browser_name( struct work_record *work, char *newname);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_browserdb.c */
|
||||
|
||||
void update_browser_death_time( struct browse_cache_record *browc );
|
||||
struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
|
||||
char *browser_name,
|
||||
struct in_addr ip );
|
||||
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
|
||||
void expire_lmb_browsers( time_t t );
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_browsesync.c */
|
||||
|
||||
void dmb_expire_and_sync_browser_lists(time_t t);
|
||||
void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec,
|
||||
struct work_record *work);
|
||||
void collect_all_workgroup_names_from_wins_server(time_t t);
|
||||
void sync_all_dmbs(time_t t);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_elections.c */
|
||||
|
||||
void check_master_browser_exists(time_t t);
|
||||
void run_elections(time_t t);
|
||||
void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
BOOL check_elections(void);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_incomingdgrams.c */
|
||||
|
||||
void tell_become_backup(void);
|
||||
void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
void process_master_browser_announce(struct subnet_record *subrec,
|
||||
struct packet_struct *p,char *buf);
|
||||
void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
void process_get_backup_list_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p,char *buf);
|
||||
void process_reset_browser(struct subnet_record *subrec,
|
||||
struct packet_struct *p,char *buf);
|
||||
void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_incomingrequests.c */
|
||||
|
||||
void process_name_release_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void process_name_refresh_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void process_name_registration_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p);
|
||||
void process_name_query_request(struct subnet_record *subrec, struct packet_struct *p);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_lmhosts.c */
|
||||
|
||||
void load_lmhosts_file(char *fname);
|
||||
BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_logonnames.c */
|
||||
|
||||
void add_logon_names(void);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_mynames.c */
|
||||
|
||||
BOOL register_my_workgroup_and_names(void);
|
||||
void release_my_names(void);
|
||||
void refresh_my_names(time_t t);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_namelistdb.c */
|
||||
|
||||
void set_samba_nb_type(void);
|
||||
void remove_name_from_namelist( struct subnet_record *subrec,
|
||||
struct name_record *namerec );
|
||||
struct name_record *find_name_on_subnet( struct subnet_record *subrec,
|
||||
struct nmb_name *nmbname,
|
||||
BOOL self_only );
|
||||
struct name_record *find_name_for_remote_broadcast_subnet(
|
||||
struct nmb_name *nmbname,
|
||||
BOOL self_only );
|
||||
void update_name_ttl( struct name_record *namerec, int ttl );
|
||||
struct name_record *add_name_to_subnet( struct subnet_record *subrec,
|
||||
char *name,
|
||||
int type,
|
||||
uint16 nb_flags,
|
||||
int ttl,
|
||||
enum name_source source,
|
||||
int num_ips,
|
||||
struct in_addr *iplist);
|
||||
void standard_success_register(struct subnet_record *subrec,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname, uint16 nb_flags, int ttl,
|
||||
struct in_addr registered_ip);
|
||||
void standard_fail_register( struct subnet_record *subrec,
|
||||
struct response_record *rrec,
|
||||
struct nmb_name *nmbname );
|
||||
BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip );
|
||||
void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip );
|
||||
void remove_ip_from_name_record( struct name_record *namerec,
|
||||
struct in_addr remove_ip );
|
||||
void standard_success_release( struct subnet_record *subrec,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname,
|
||||
struct in_addr released_ip );
|
||||
void expire_names_on_subnet(struct subnet_record *subrec, time_t t);
|
||||
void expire_names(time_t t);
|
||||
void add_samba_names_to_subnet( struct subnet_record *subrec );
|
||||
void dump_all_namelists(void);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_namequery.c */
|
||||
|
||||
BOOL query_name(struct subnet_record *subrec, char *name, int type,
|
||||
query_name_success_function success_fn,
|
||||
query_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
BOOL query_name_from_wins_server(struct in_addr ip_to,
|
||||
char *name, int type,
|
||||
query_name_success_function success_fn,
|
||||
query_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_nameregister.c */
|
||||
|
||||
BOOL register_name(struct subnet_record *subrec,
|
||||
char *name, int type, uint16 nb_flags,
|
||||
register_name_success_function success_fn,
|
||||
register_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
BOOL refresh_name(struct subnet_record *subrec, struct name_record *namerec,
|
||||
refresh_name_success_function success_fn,
|
||||
refresh_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_namerelease.c */
|
||||
|
||||
BOOL release_name(struct subnet_record *subrec, struct name_record *namerec,
|
||||
release_name_success_function success_fn,
|
||||
release_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_nodestatus.c */
|
||||
|
||||
BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname,
|
||||
struct in_addr send_ip, node_status_success_function success_fn,
|
||||
node_status_fail_function fail_fn, struct userdata_struct *userdata);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_packets.c */
|
||||
|
||||
uint16 get_nb_flags(char *buf);
|
||||
void set_nb_flags(char *buf, uint16 nb_flags);
|
||||
struct response_record *queue_register_name( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
register_name_success_function success_fn,
|
||||
register_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname,
|
||||
uint16 nb_flags);
|
||||
struct response_record *queue_register_multihomed_name( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
register_name_success_function success_fn,
|
||||
register_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname,
|
||||
uint16 nb_flags,
|
||||
struct in_addr register_ip);
|
||||
struct response_record *queue_release_name( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
release_name_success_function success_fn,
|
||||
release_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname,
|
||||
uint16 nb_flags,
|
||||
struct in_addr release_ip);
|
||||
struct response_record *queue_refresh_name( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
refresh_name_success_function success_fn,
|
||||
refresh_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct name_record *namerec,
|
||||
struct in_addr refresh_ip);
|
||||
struct response_record *queue_query_name( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
query_name_success_function success_fn,
|
||||
query_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname);
|
||||
struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
query_name_success_function success_fn,
|
||||
query_name_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname);
|
||||
struct response_record *queue_node_status( struct subnet_record *subrec,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
node_status_success_function success_fn,
|
||||
node_status_fail_function fail_fn,
|
||||
struct userdata_struct *userdata,
|
||||
struct nmb_name *nmbname,
|
||||
struct in_addr send_ip);
|
||||
void reply_netbios_packet(struct packet_struct *orig_packet,
|
||||
int rcode, enum netbios_reply_type_code rcv_code, int opcode,
|
||||
int ttl, char *data,int len);
|
||||
void run_packet_queue(void);
|
||||
void retransmit_or_expire_response_records(time_t t);
|
||||
BOOL listen_for_packets(BOOL run_election);
|
||||
BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len,
|
||||
char *srcname, int src_type,
|
||||
char *dstname, int dest_type,
|
||||
struct in_addr dest_ip,struct in_addr src_ip,
|
||||
int dest_port);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_processlogon.c */
|
||||
|
||||
void process_logon_packet(struct packet_struct *p,char *buf,int len,
|
||||
char *mailslot);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_responserecordsdb.c */
|
||||
|
||||
void remove_response_record(struct subnet_record *subrec,
|
||||
struct response_record *rrec);
|
||||
struct response_record *make_response_record( struct subnet_record *subrec,
|
||||
struct packet_struct *p,
|
||||
response_function resp_fn,
|
||||
timeout_response_function timeout_fn,
|
||||
success_function success_fn,
|
||||
fail_function fail_fn,
|
||||
struct userdata_struct *userdata);
|
||||
struct response_record *find_response_record(struct subnet_record **ppsubrec,
|
||||
uint16 id);
|
||||
BOOL is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_sendannounce.c */
|
||||
|
||||
void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_addr to_ip);
|
||||
void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work);
|
||||
void announce_my_server_names(time_t t);
|
||||
void announce_my_lm_server_names(time_t t);
|
||||
void reset_announce_timer(void);
|
||||
void announce_myself_to_domain_master_browser(time_t t);
|
||||
void announce_my_servers_removed(void);
|
||||
void announce_remote(time_t t);
|
||||
void browse_sync_remote(time_t t);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_serverlistdb.c */
|
||||
|
||||
void remove_all_servers(struct work_record *work);
|
||||
struct server_record *find_server_in_workgroup(struct work_record *work, char *name);
|
||||
void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec);
|
||||
struct server_record *create_server_on_workgroup(struct work_record *work,
|
||||
char *name,int servertype,
|
||||
int ttl,char *comment);
|
||||
void update_server_ttl(struct server_record *servrec, int ttl);
|
||||
void expire_servers(struct work_record *work, time_t t);
|
||||
void write_browse_list(time_t t, BOOL force_write);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_subnetdb.c */
|
||||
|
||||
BOOL create_subnets(void);
|
||||
BOOL we_are_a_wins_client(void);
|
||||
struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec);
|
||||
struct subnet_record *get_next_subnet_maybe_unicast_or_wins_server(struct subnet_record *subrec);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_synclists.c */
|
||||
|
||||
void sync_browse_lists(struct work_record *work,
|
||||
char *name, int nm_type,
|
||||
struct in_addr ip, BOOL local, BOOL servers);
|
||||
void sync_check_completion(void);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_winsproxy.c */
|
||||
|
||||
void make_wins_proxy_name_query_request( struct subnet_record *subrec,
|
||||
struct packet_struct *incoming_packet,
|
||||
struct nmb_name *question_name);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_winsserver.c */
|
||||
|
||||
BOOL packet_is_for_wins_server(struct packet_struct *packet);
|
||||
BOOL initialise_wins(void);
|
||||
void wins_process_name_refresh_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void wins_process_name_registration_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void wins_process_multihomed_name_registration_request( struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void send_wins_name_query_response(int rcode, struct packet_struct *p,
|
||||
struct name_record *namerec);
|
||||
void wins_process_name_query_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void wins_process_name_release_request(struct subnet_record *subrec,
|
||||
struct packet_struct *p);
|
||||
void initiate_wins_processing(time_t t);
|
||||
void wins_write_database(BOOL background);
|
||||
|
||||
/*The following definitions come from nmbd/nmbd_workgroupdb.c */
|
||||
|
||||
struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec,
|
||||
fstring name);
|
||||
struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec,
|
||||
fstring name, int ttl);
|
||||
void update_workgroup_ttl(struct work_record *work, int ttl);
|
||||
void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_record *work);
|
||||
void dump_workgroups(BOOL force_write);
|
||||
void expire_workgroups_and_servers(time_t t);
|
||||
|
||||
/*The following definitions come from param/loadparm.c */
|
||||
|
||||
char *lp_logfile(void);
|
||||
|
@ -1,481 +0,0 @@
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
675 Mass Ave, Cambridge, MA 02139, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Appendix: How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
@ -1,18 +0,0 @@
|
||||
Fri Apr 17 10:21:56 CDT 1998
|
||||
|
||||
The C code files in the samba/source/ubiqx directory are licensed under
|
||||
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL). A copy of the
|
||||
LGPL should also be included in this directory under the name COPYING.LIB.
|
||||
If this file is not present, you can obtain a copy of the LGPL by writing
|
||||
to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
||||
USA.
|
||||
|
||||
The versions of the ubiqx modules distributed with Samba may have been
|
||||
modified for inclusion with Samba. The main distribution, which contains
|
||||
additional available modules, can be found at:
|
||||
|
||||
http://www.interads.co.uk/~crh/ubiqx/
|
||||
|
||||
Chris Hertel
|
||||
Samba Team
|
||||
ubiqx@ubiqx.mn.org
|
@ -1,127 +0,0 @@
|
||||
#ifndef DEBUGPARSE_H
|
||||
#define DEBUGPARSE_H
|
||||
/* ========================================================================== **
|
||||
* debugparse.c
|
||||
*
|
||||
* Copyright (C) 1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This module is a very simple parser for Samba debug log files.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
* The important function in this module is dbg_char2token(). The rest is
|
||||
* basically fluff. (Potentially useful fluff, but still fluff.)
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "sys_include.h"
|
||||
|
||||
/* This module compiles quite nicely outside of the Samba environment.
|
||||
* You'll need the following headers:
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* These are the tokens returned by dbg_char2token().
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
dbg_null = 0,
|
||||
dbg_ignore,
|
||||
dbg_header,
|
||||
dbg_timestamp,
|
||||
dbg_level,
|
||||
dbg_sourcefile,
|
||||
dbg_function,
|
||||
dbg_lineno,
|
||||
dbg_message,
|
||||
dbg_eof
|
||||
} dbg_Token;
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Function prototypes...
|
||||
*/
|
||||
|
||||
char *dbg_token2string( dbg_Token tok );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given a token, return a string describing the token.
|
||||
*
|
||||
* Input: tok - One of the set of dbg_Tokens defined in debugparse.h.
|
||||
*
|
||||
* Output: A string identifying the token. This is useful for debugging,
|
||||
* etc.
|
||||
*
|
||||
* Note: If the token is not known, this function will return the
|
||||
* string "<unknown>".
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
dbg_Token dbg_char2token( dbg_Token *state, int c );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Parse input one character at a time.
|
||||
*
|
||||
* Input: state - A pointer to a token variable. This is used to
|
||||
* maintain the parser state between calls. For
|
||||
* each input stream, you should set up a separate
|
||||
* state variable and initialize it to dbg_null.
|
||||
* Pass a pointer to it into this function with each
|
||||
* character in the input stream. See dbg_test()
|
||||
* for an example.
|
||||
* c - The "current" character in the input stream.
|
||||
*
|
||||
* Output: A token.
|
||||
* The token value will change when delimiters are found,
|
||||
* which indicate a transition between syntactical objects.
|
||||
* Possible return values are:
|
||||
*
|
||||
* dbg_null - The input character was an end-of-line.
|
||||
* This resets the parser to its initial state
|
||||
* in preparation for parsing the next line.
|
||||
* dbg_eof - Same as dbg_null, except that the character
|
||||
* was an end-of-file.
|
||||
* dbg_ignore - Returned for whitespace and delimiters.
|
||||
* These lexical tokens are only of interest
|
||||
* to the parser.
|
||||
* dbg_header - Indicates the start of a header line. The
|
||||
* input character was '[' and was the first on
|
||||
* the line.
|
||||
* dbg_timestamp - Indicates that the input character was part
|
||||
* of a header timestamp.
|
||||
* dbg_level - Indicates that the input character was part
|
||||
* of the debug-level value in the header.
|
||||
* dbg_sourcefile - Indicates that the input character was part
|
||||
* of the sourcefile name in the header.
|
||||
* dbg_function - Indicates that the input character was part
|
||||
* of the function name in the header.
|
||||
* dbg_lineno - Indicates that the input character was part
|
||||
* of the DEBUG call line number in the header.
|
||||
* dbg_message - Indicates that the input character was part
|
||||
* of the DEBUG message text.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* DEBUGPARSE_H */
|
@ -1,51 +0,0 @@
|
||||
#ifndef SYS_INCLUDE_H
|
||||
#define SYS_INCLUDE_H
|
||||
/* ========================================================================== **
|
||||
* sys_include.h
|
||||
*
|
||||
* Copyright (C) 1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This header provides system declarations and data types used internally
|
||||
* by the ubiqx modules.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Samba version of sys_include.h
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDES_H
|
||||
|
||||
/* Block the inclusion of some Samba headers so that ubiqx types won't be
|
||||
* used before the headers that define them. These headers are not needed
|
||||
* in the ubiqx modules anyway.
|
||||
*/
|
||||
#define _PROTO_H_
|
||||
#define _NAMESERV_H_
|
||||
|
||||
/* The main Samba system-adaptive header file.
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
#endif /* _INCLUDES_H */
|
||||
|
||||
/* ================================ The End ================================= */
|
||||
#endif /* SYS_INCLUDE_H */
|
@ -1,828 +0,0 @@
|
||||
#ifndef UBI_BINTREE_H
|
||||
#define UBI_BINTREE_H
|
||||
/* ========================================================================== **
|
||||
* ubi_BinTree.h
|
||||
*
|
||||
* Copyright (C) 1991-1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This module implements a simple binary tree.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Log: ubi_BinTree.h,v
|
||||
* Revision 4.7 1998/10/21 06:15:07 crh
|
||||
* Fixed bugs in FirstOf() and LastOf() reported by Massimo Campostrini.
|
||||
* See function comments.
|
||||
*
|
||||
* Revision 4.6 1998/07/25 17:02:10 crh
|
||||
* Added the ubi_trNewTree() macro.
|
||||
*
|
||||
* Revision 4.5 1998/06/04 21:29:27 crh
|
||||
* Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
|
||||
* This is more "standard", and is what people expect. Weird, eh?
|
||||
*
|
||||
* Revision 4.4 1998/06/03 17:42:46 crh
|
||||
* Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is
|
||||
* included by all of the binary tree files.
|
||||
*
|
||||
* Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in
|
||||
* ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping
|
||||
* of tree types by simply changing a header. Unfortunately, the
|
||||
* macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will
|
||||
* conflict if used together. You must either choose a single tree
|
||||
* type, or use the underlying function calls directly. Compare
|
||||
* the two header files for more information.
|
||||
*
|
||||
* Revision 4.3 1998/06/02 01:28:43 crh
|
||||
* Changed ubi_null.h to sys_include.h to make it more generic.
|
||||
*
|
||||
* Revision 4.2 1998/05/20 04:32:36 crh
|
||||
* The C file now includes ubi_null.h. See ubi_null.h for more info.
|
||||
* Also, the balance and gender fields of the node were declared as
|
||||
* signed char. As I understand it, at least one SunOS or Solaris
|
||||
* compiler doesn't like "signed char". The declarations were
|
||||
* wrong anyway, so I changed them to simple "char".
|
||||
*
|
||||
* Revision 4.1 1998/03/31 06:13:47 crh
|
||||
* Thomas Aglassinger sent E'mail pointing out errors in the
|
||||
* dereferencing of function pointers, and a missing typecast.
|
||||
* Thanks, Thomas!
|
||||
*
|
||||
* Revision 4.0 1998/03/10 03:16:04 crh
|
||||
* Added the AVL field 'balance' to the ubi_btNode structure. This means
|
||||
* that all BinTree modules now use the same basic node structure, which
|
||||
* greatly simplifies the AVL module.
|
||||
* Decided that this was a big enough change to justify a new major revision
|
||||
* number. 3.0 was an error, so we're at 4.0.
|
||||
*
|
||||
* Revision 2.6 1998/01/24 06:27:30 crh
|
||||
* Added ubi_trCount() macro.
|
||||
*
|
||||
* Revision 2.5 1997/12/23 03:59:21 crh
|
||||
* In this version, all constants & macros defined in the header file have
|
||||
* the ubi_tr prefix. Also cleaned up anything that gcc complained about
|
||||
* when run with '-pedantic -fsyntax-only -Wall'.
|
||||
*
|
||||
* Revision 2.4 1997/07/26 04:11:14 crh
|
||||
* + Just to be annoying I changed ubi_TRUE and ubi_FALSE to ubi_trTRUE
|
||||
* and ubi_trFALSE.
|
||||
* + There is now a type ubi_trBool to go with ubi_trTRUE and ubi_trFALSE.
|
||||
* + There used to be something called "ubi_TypeDefs.h". I got rid of it.
|
||||
* + Added function ubi_btLeafNode().
|
||||
*
|
||||
* Revision 2.3 1997/06/03 05:15:27 crh
|
||||
* Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid conflicts.
|
||||
* Also changed the interface to function InitTree(). See the comments
|
||||
* for this function for more information.
|
||||
*
|
||||
* Revision 2.2 1995/10/03 22:00:40 CRH
|
||||
* Ubisized!
|
||||
*
|
||||
* Revision 2.1 95/03/09 23:43:46 CRH
|
||||
* Added the ModuleID static string and function. These modules are now
|
||||
* self-identifying.
|
||||
*
|
||||
* Revision 2.0 95/02/27 22:00:33 CRH
|
||||
* Revision 2.0 of this program includes the following changes:
|
||||
*
|
||||
* 1) A fix to a major typo in the RepaceNode() function.
|
||||
* 2) The addition of the static function Border().
|
||||
* 3) The addition of the public functions FirstOf() and LastOf(), which
|
||||
* use Border(). These functions are used with trees that allow
|
||||
* duplicate keys.
|
||||
* 4) A complete rewrite of the Locate() function. Locate() now accepts
|
||||
* a "comparison" operator.
|
||||
* 5) Overall enhancements to both code and comments.
|
||||
*
|
||||
* I decided to give this a new major rev number because the interface has
|
||||
* changed. In particular, there are two new functions, and changes to the
|
||||
* Locate() function.
|
||||
*
|
||||
* Revision 1.0 93/10/15 22:55:04 CRH
|
||||
* With this revision, I have added a set of #define's that provide a single,
|
||||
* standard API to all existing tree modules. Until now, each of the three
|
||||
* existing modules had a different function and typedef prefix, as follows:
|
||||
*
|
||||
* Module Prefix
|
||||
* ubi_BinTree ubi_bt
|
||||
* ubi_AVLtree ubi_avl
|
||||
* ubi_SplayTree ubi_spt
|
||||
*
|
||||
* To further complicate matters, only those portions of the base module
|
||||
* (ubi_BinTree) that were superceeded in the new module had the new names.
|
||||
* For example, if you were using ubi_SplayTree, the locate function was
|
||||
* called "ubi_sptLocate", but the next and previous functions remained
|
||||
* "ubi_btNext" and "ubi_btPrev".
|
||||
*
|
||||
* This was not too terrible if you were familiar with the modules and knew
|
||||
* exactly which tree model you wanted to use. If you wanted to be able to
|
||||
* change modules (for speed comparisons, etc), things could get messy very
|
||||
* quickly.
|
||||
*
|
||||
* So, I have added a set of defined names that get redefined in any of the
|
||||
* descendant modules. To use this standardized interface in your code,
|
||||
* simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with
|
||||
* "ubi_tr". The "ubi_tr" names will resolve to the correct function or
|
||||
* datatype names for the module that you are using. Just remember to
|
||||
* include the header for that module in your program file. Because these
|
||||
* names are handled by the preprocessor, there is no added run-time
|
||||
* overhead.
|
||||
*
|
||||
* Note that the original names do still exist, and can be used if you wish
|
||||
* to write code directly to a specific module. This should probably only be
|
||||
* done if you are planning to implement a new descendant type, such as
|
||||
* red/black trees. CRH
|
||||
*
|
||||
* V0.0 - June, 1991 - Written by Christopher R. Hertel (CRH).
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "sys_include.h" /* Global include file, used to adapt the ubiqx
|
||||
* modules to the host environment and the project
|
||||
* with which the modules will be used. See
|
||||
* sys_include.h for more info.
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Macros and constants.
|
||||
*
|
||||
* General purpose:
|
||||
* ubi_trTRUE - Boolean TRUE.
|
||||
* ubi_trFALSE - Boolean FALSE.
|
||||
*
|
||||
* Flags used in the tree header:
|
||||
* ubi_trOVERWRITE - This flag indicates that an existing node may be
|
||||
* overwritten by a new node with a matching key.
|
||||
* ubi_trDUPKEY - This flag indicates that the tree allows duplicate
|
||||
* keys. If the tree does allow duplicates, the
|
||||
* overwrite flag is ignored.
|
||||
*
|
||||
* Node link array index constants: (Each node has an array of three
|
||||
* pointers. One to the left, one to the right, and one back to the
|
||||
* parent.)
|
||||
* ubi_trLEFT - Left child pointer.
|
||||
* ubi_trPARENT - Parent pointer.
|
||||
* ubi_trRIGHT - Right child pointer.
|
||||
* ubi_trEQUAL - Synonym for PARENT.
|
||||
*
|
||||
* ubi_trCompOps: These values are used in the ubi_trLocate() function.
|
||||
* ubi_trLT - request the first instance of the greatest key less than
|
||||
* the search key.
|
||||
* ubi_trLE - request the first instance of the greatest key that is less
|
||||
* than or equal to the search key.
|
||||
* ubi_trEQ - request the first instance of key that is equal to the
|
||||
* search key.
|
||||
* ubi_trGE - request the first instance of a key that is greater than
|
||||
* or equal to the search key.
|
||||
* ubi_trGT - request the first instance of the first key that is greater
|
||||
* than the search key.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
|
||||
#define ubi_trTRUE 0xFF
|
||||
#define ubi_trFALSE 0x00
|
||||
|
||||
#define ubi_trOVERWRITE 0x01 /* Turn on allow overwrite */
|
||||
#define ubi_trDUPKEY 0x02 /* Turn on allow duplicate keys */
|
||||
|
||||
/* Pointer array index constants... */
|
||||
#define ubi_trLEFT 0x00
|
||||
#define ubi_trPARENT 0x01
|
||||
#define ubi_trRIGHT 0x02
|
||||
#define ubi_trEQUAL ubi_trPARENT
|
||||
|
||||
typedef enum {
|
||||
ubi_trLT = 1,
|
||||
ubi_trLE,
|
||||
ubi_trEQ,
|
||||
ubi_trGE,
|
||||
ubi_trGT
|
||||
} ubi_trCompOps;
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* These three macros allow simple manipulation of pointer index values (LEFT,
|
||||
* RIGHT, and PARENT).
|
||||
*
|
||||
* Normalize() - converts {LEFT, PARENT, RIGHT} into {-1, 0 ,1}. C
|
||||
* uses {negative, zero, positive} values to indicate
|
||||
* {less than, equal to, greater than}.
|
||||
* AbNormal() - converts {negative, zero, positive} to {LEFT, PARENT,
|
||||
* RIGHT} (opposite of Normalize()). Note: C comparison
|
||||
* functions, such as strcmp(), return {negative, zero,
|
||||
* positive} values, which are not necessarily {-1, 0,
|
||||
* 1}. This macro uses the the ubi_btSgn() function to
|
||||
* compensate.
|
||||
* RevWay() - converts LEFT to RIGHT and RIGHT to LEFT. PARENT (EQUAL)
|
||||
* is left as is.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
#define ubi_trNormalize(W) ((char)( (W) - ubi_trEQUAL ))
|
||||
#define ubi_trAbNormal(W) ((char)( ((char)ubi_btSgn( (long)(W) )) \
|
||||
+ ubi_trEQUAL ))
|
||||
#define ubi_trRevWay(W) ((char)( ubi_trEQUAL - ((W) - ubi_trEQUAL) ))
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* These macros allow us to quickly read the values of the OVERWRITE and
|
||||
* DUPlicate KEY bits of the tree root flags field.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
#define ubi_trDups_OK(A) \
|
||||
((ubi_trDUPKEY & ((A)->flags))?(ubi_trTRUE):(ubi_trFALSE))
|
||||
#define ubi_trOvwt_OK(A) \
|
||||
((ubi_trOVERWRITE & ((A)->flags))?(ubi_trTRUE):(ubi_trFALSE))
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Additional Macros...
|
||||
*
|
||||
* ubi_trCount() - Given a pointer to a tree root, this macro returns the
|
||||
* number of nodes currently in the tree.
|
||||
*
|
||||
* ubi_trNewTree() - This macro makes it easy to declare and initialize a
|
||||
* tree header in one step. The line
|
||||
*
|
||||
* static ubi_trNewTree( MyTree, cmpfn, ubi_trDUPKEY );
|
||||
*
|
||||
* is equivalent to
|
||||
*
|
||||
* static ubi_trRoot MyTree[1]
|
||||
* = {{ NULL, cmpfn, 0, ubi_trDUPKEY }};
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
|
||||
#define ubi_trCount( R ) (((ubi_trRootPtr)(R))->count)
|
||||
|
||||
#define ubi_trNewTree( N, C, F ) ubi_trRoot (N)[1] = {{ NULL, (C), 0, (F) }}
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Typedefs...
|
||||
*
|
||||
* ubi_trBool - Your typcial true or false...
|
||||
*
|
||||
* Item Pointer: The ubi_btItemPtr is a generic pointer. It is used to
|
||||
* indicate a key that is being searched for within the tree.
|
||||
* Searching occurs whenever the ubi_trFind(), ubi_trLocate(),
|
||||
* or ubi_trInsert() functions are called.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
|
||||
typedef unsigned char ubi_trBool;
|
||||
|
||||
typedef void *ubi_btItemPtr; /* A pointer to key data within a node. */
|
||||
|
||||
/* ------------------------------------------------------------------------- **
|
||||
* Binary Tree Node Structure: This structure defines the basic elements of
|
||||
* the tree nodes. In general you *SHOULD NOT PLAY WITH THESE FIELDS*!
|
||||
* But, of course, I have to put the structure into this header so that
|
||||
* you can use it as a building block.
|
||||
*
|
||||
* The fields are as follows:
|
||||
* Link - an array of pointers. These pointers are manipulated by
|
||||
* the BT routines. The pointers indicate the left and right
|
||||
* child nodes and the parent node. By keeping track of the
|
||||
* parent pointer, we avoid the need for recursive routines or
|
||||
* hand-tooled stacks to keep track of our path back to the
|
||||
* root. The use of these pointers is subject to change without
|
||||
* notice.
|
||||
* gender - a one-byte field indicating whether the node is the RIGHT or
|
||||
* LEFT child of its parent. If the node is the root of the
|
||||
* tree, gender will be PARENT.
|
||||
* balance - only used by the AVL tree module. This field indicates
|
||||
* the height balance at a given node. See ubi_AVLtree for
|
||||
* details.
|
||||
*
|
||||
* ------------------------------------------------------------------------- **
|
||||
*/
|
||||
typedef struct ubi_btNodeStruct {
|
||||
struct ubi_btNodeStruct *Link[ 3 ];
|
||||
char gender;
|
||||
char balance;
|
||||
} ubi_btNode;
|
||||
|
||||
typedef ubi_btNode *ubi_btNodePtr; /* Pointer to an ubi_btNode structure. */
|
||||
|
||||
/* ------------------------------------------------------------------------- **
|
||||
* The next three typedefs define standard function types used by the binary
|
||||
* tree management routines. In particular:
|
||||
*
|
||||
* ubi_btCompFunc is a pointer to a comparison function. Comparison
|
||||
* functions are passed an ubi_btItemPtr and an
|
||||
* ubi_btNodePtr. They return a value that is (<0), 0,
|
||||
* or (>0) to indicate that the Item is (respectively)
|
||||
* "less than", "equal to", or "greater than" the Item
|
||||
* contained within the node. (See ubi_btInitTree()).
|
||||
* ubi_btActionRtn is a pointer to a function that may be called for each
|
||||
* node visited when performing a tree traversal (see
|
||||
* ubi_btTraverse()). The function will be passed two
|
||||
* parameters: the first is a pointer to a node in the
|
||||
* tree, the second is a generic pointer that may point to
|
||||
* anything that you like.
|
||||
* ubi_btKillNodeRtn is a pointer to a function that will deallocate the
|
||||
* memory used by a node (see ubi_btKillTree()). Since
|
||||
* memory management is left up to you, deallocation may
|
||||
* mean anything that you want it to mean. Just remember
|
||||
* that the tree *will* be destroyed and that none of the
|
||||
* node pointers will be valid any more.
|
||||
* ------------------------------------------------------------------------- **
|
||||
*/
|
||||
|
||||
typedef int (*ubi_btCompFunc)( ubi_btItemPtr, ubi_btNodePtr );
|
||||
|
||||
typedef void (*ubi_btActionRtn)( ubi_btNodePtr, void * );
|
||||
|
||||
typedef void (*ubi_btKillNodeRtn)( ubi_btNodePtr );
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Tree Root Structure: This structure gives us a convenient handle for
|
||||
* accessing whole binary trees. The fields are:
|
||||
* root - A pointer to the root node of the tree.
|
||||
* count - A count of the number of nodes stored in the tree.
|
||||
* cmp - A pointer to the comparison routine to be used when building or
|
||||
* searching the tree.
|
||||
* flags - A set of bit flags. Two flags are currently defined:
|
||||
*
|
||||
* ubi_trOVERWRITE - If set, this flag indicates that a new node should
|
||||
* (bit 0x01) overwrite an old node if the two have identical
|
||||
* keys (ie., the keys are equal).
|
||||
* ubi_trDUPKEY - If set, this flag indicates that the tree is
|
||||
* (bit 0x02) allowed to contain nodes with duplicate keys.
|
||||
*
|
||||
* NOTE: ubi_trInsert() tests ubi_trDUPKEY before ubi_trOVERWRITE.
|
||||
*
|
||||
* All of these values are set when you initialize the root structure by
|
||||
* calling ubi_trInitTree().
|
||||
* -------------------------------------------------------------------------- **
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
ubi_btNodePtr root; /* A pointer to the root node of the tree */
|
||||
ubi_btCompFunc cmp; /* A pointer to the tree's comparison function */
|
||||
unsigned long count; /* A count of the number of nodes in the tree */
|
||||
char flags; /* Overwrite Y|N, Duplicate keys Y|N... */
|
||||
} ubi_btRoot;
|
||||
|
||||
typedef ubi_btRoot *ubi_btRootPtr; /* Pointer to an ubi_btRoot structure. */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Function Prototypes.
|
||||
*/
|
||||
|
||||
long ubi_btSgn( long x );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Return the sign of x; {negative,zero,positive} ==> {-1, 0, 1}.
|
||||
*
|
||||
* Input: x - a signed long integer value.
|
||||
*
|
||||
* Output: the "sign" of x, represented as follows:
|
||||
* -1 == negative
|
||||
* 0 == zero (no sign)
|
||||
* 1 == positive
|
||||
*
|
||||
* Note: This utility is provided in order to facilitate the conversion
|
||||
* of C comparison function return values into BinTree direction
|
||||
* values: {LEFT, PARENT, EQUAL}. It is INCORPORATED into the
|
||||
* AbNormal() conversion macro!
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btInitNode( ubi_btNodePtr NodePtr );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Initialize a tree node.
|
||||
*
|
||||
* Input: a pointer to a ubi_btNode structure to be initialized.
|
||||
* Output: a pointer to the initialized ubi_btNode structure (ie. the
|
||||
* same as the input pointer).
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btRootPtr ubi_btInitTree( ubi_btRootPtr RootPtr,
|
||||
ubi_btCompFunc CompFunc,
|
||||
char Flags );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Initialize the fields of a Tree Root header structure.
|
||||
*
|
||||
* Input: RootPtr - a pointer to an ubi_btRoot structure to be
|
||||
* initialized.
|
||||
* CompFunc - a pointer to a comparison function that will be used
|
||||
* whenever nodes in the tree must be compared against
|
||||
* outside values.
|
||||
* Flags - One bytes worth of flags. Flags include
|
||||
* ubi_trOVERWRITE and ubi_trDUPKEY. See the header
|
||||
* file for more info.
|
||||
*
|
||||
* Output: a pointer to the initialized ubi_btRoot structure (ie. the
|
||||
* same value as RootPtr).
|
||||
*
|
||||
* Note: The interface to this function has changed from that of
|
||||
* previous versions. The <Flags> parameter replaces two
|
||||
* boolean parameters that had the same basic effect.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_btInsert( ubi_btRootPtr RootPtr,
|
||||
ubi_btNodePtr NewNode,
|
||||
ubi_btItemPtr ItemPtr,
|
||||
ubi_btNodePtr *OldNode );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function uses a non-recursive algorithm to add a new element to the
|
||||
* tree.
|
||||
*
|
||||
* Input: RootPtr - a pointer to the ubi_btRoot structure that indicates
|
||||
* the root of the tree to which NewNode is to be added.
|
||||
* NewNode - a pointer to an ubi_btNode structure that is NOT
|
||||
* part of any tree.
|
||||
* ItemPtr - A pointer to the sort key that is stored within
|
||||
* *NewNode. ItemPtr MUST point to information stored
|
||||
* in *NewNode or an EXACT DUPLICATE. The key data
|
||||
* indicated by ItemPtr is used to place the new node
|
||||
* into the tree.
|
||||
* OldNode - a pointer to an ubi_btNodePtr. When searching
|
||||
* the tree, a duplicate node may be found. If
|
||||
* duplicates are allowed, then the new node will
|
||||
* be simply placed into the tree. If duplicates
|
||||
* are not allowed, however, then one of two things
|
||||
* may happen.
|
||||
* 1) if overwritting *is not* allowed, this
|
||||
* function will return FALSE (indicating that
|
||||
* the new node could not be inserted), and
|
||||
* *OldNode will point to the duplicate that is
|
||||
* still in the tree.
|
||||
* 2) if overwritting *is* allowed, then this
|
||||
* function will swap **OldNode for *NewNode.
|
||||
* In this case, *OldNode will point to the node
|
||||
* that was removed (thus allowing you to free
|
||||
* the node).
|
||||
* ** If you are using overwrite mode, ALWAYS **
|
||||
* ** check the return value of this parameter! **
|
||||
* Note: You may pass NULL in this parameter, the
|
||||
* function knows how to cope. If you do this,
|
||||
* however, there will be no way to return a
|
||||
* pointer to an old (ie. replaced) node (which is
|
||||
* a problem if you are using overwrite mode).
|
||||
*
|
||||
* Output: a boolean value indicating success or failure. The function
|
||||
* will return FALSE if the node could not be added to the tree.
|
||||
* Such failure will only occur if duplicates are not allowed,
|
||||
* nodes cannot be overwritten, AND a duplicate key was found
|
||||
* within the tree.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btRemove( ubi_btRootPtr RootPtr,
|
||||
ubi_btNodePtr DeadNode );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function removes the indicated node from the tree.
|
||||
*
|
||||
* Input: RootPtr - A pointer to the header of the tree that contains
|
||||
* the node to be removed.
|
||||
* DeadNode - A pointer to the node that will be removed.
|
||||
*
|
||||
* Output: This function returns a pointer to the node that was removed
|
||||
* from the tree (ie. the same as DeadNode).
|
||||
*
|
||||
* Note: The node MUST be in the tree indicated by RootPtr. If not,
|
||||
* strange and evil things will happen to your trees.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btLocate( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr FindMe,
|
||||
ubi_trCompOps CompOp );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* The purpose of ubi_btLocate() is to find a node or set of nodes given
|
||||
* a target value and a "comparison operator". The Locate() function is
|
||||
* more flexible and (in the case of trees that may contain dupicate keys)
|
||||
* more precise than the ubi_btFind() function. The latter is faster,
|
||||
* but it only searches for exact matches and, if the tree contains
|
||||
* duplicates, Find() may return a pointer to any one of the duplicate-
|
||||
* keyed records.
|
||||
*
|
||||
* Input:
|
||||
* RootPtr - A pointer to the header of the tree to be searched.
|
||||
* FindMe - An ubi_btItemPtr that indicates the key for which to
|
||||
* search.
|
||||
* CompOp - One of the following:
|
||||
* CompOp Return a pointer to the node with
|
||||
* ------ ---------------------------------
|
||||
* ubi_trLT - the last key value that is less
|
||||
* than FindMe.
|
||||
* ubi_trLE - the first key matching FindMe, or
|
||||
* the last key that is less than
|
||||
* FindMe.
|
||||
* ubi_trEQ - the first key matching FindMe.
|
||||
* ubi_trGE - the first key matching FindMe, or the
|
||||
* first key greater than FindMe.
|
||||
* ubi_trGT - the first key greater than FindMe.
|
||||
* Output:
|
||||
* A pointer to the node matching the criteria listed above under
|
||||
* CompOp, or NULL if no node matched the criteria.
|
||||
*
|
||||
* Notes:
|
||||
* In the case of trees with duplicate keys, Locate() will behave as
|
||||
* follows:
|
||||
*
|
||||
* Find: 3 Find: 3
|
||||
* Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6
|
||||
* ^ ^ ^ ^ ^
|
||||
* LT EQ GT LE GE
|
||||
*
|
||||
* That is, when returning a pointer to a node with a key that is LESS
|
||||
* THAN the target key (FindMe), Locate() will return a pointer to the
|
||||
* LAST matching node.
|
||||
* When returning a pointer to a node with a key that is GREATER
|
||||
* THAN the target key (FindMe), Locate() will return a pointer to the
|
||||
* FIRST matching node.
|
||||
*
|
||||
* See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf().
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btFind( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr FindMe );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function performs a non-recursive search of a tree for any node
|
||||
* matching a specific key.
|
||||
*
|
||||
* Input:
|
||||
* RootPtr - a pointer to the header of the tree to be searched.
|
||||
* FindMe - a pointer to the key value for which to search.
|
||||
*
|
||||
* Output:
|
||||
* A pointer to a node with a key that matches the key indicated by
|
||||
* FindMe, or NULL if no such node was found.
|
||||
*
|
||||
* Note: In a tree that allows duplicates, the pointer returned *might
|
||||
* not* point to the (sequentially) first occurance of the
|
||||
* desired key. In such a tree, it may be more useful to use
|
||||
* ubi_btLocate().
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btNext( ubi_btNodePtr P );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given the node indicated by P, find the (sorted order) Next node in the
|
||||
* tree.
|
||||
* Input: P - a pointer to a node that exists in a binary tree.
|
||||
* Output: A pointer to the "next" node in the tree, or NULL if P pointed
|
||||
* to the "last" node in the tree or was NULL.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btPrev( ubi_btNodePtr P );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given the node indicated by P, find the (sorted order) Previous node in
|
||||
* the tree.
|
||||
* Input: P - a pointer to a node that exists in a binary tree.
|
||||
* Output: A pointer to the "previous" node in the tree, or NULL if P
|
||||
* pointed to the "first" node in the tree or was NULL.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btFirst( ubi_btNodePtr P );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given the node indicated by P, find the (sorted order) First node in the
|
||||
* subtree of which *P is the root.
|
||||
* Input: P - a pointer to a node that exists in a binary tree.
|
||||
* Output: A pointer to the "first" node in a subtree that has *P as its
|
||||
* root. This function will return NULL only if P is NULL.
|
||||
* Note: In general, you will be passing in the value of the root field
|
||||
* of an ubi_btRoot structure.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btLast( ubi_btNodePtr P );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given the node indicated by P, find the (sorted order) Last node in the
|
||||
* subtree of which *P is the root.
|
||||
* Input: P - a pointer to a node that exists in a binary tree.
|
||||
* Output: A pointer to the "last" node in a subtree that has *P as its
|
||||
* root. This function will return NULL only if P is NULL.
|
||||
* Note: In general, you will be passing in the value of the root field
|
||||
* of an ubi_btRoot structure.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btFirstOf( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr MatchMe,
|
||||
ubi_btNodePtr p );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given a tree that a allows duplicate keys, and a pointer to a node in
|
||||
* the tree, this function will return a pointer to the first (traversal
|
||||
* order) node with the same key value.
|
||||
*
|
||||
* Input: RootPtr - A pointer to the root of the tree.
|
||||
* MatchMe - A pointer to the key value. This should probably
|
||||
* point to the key within node *p.
|
||||
* p - A pointer to a node in the tree.
|
||||
* Output: A pointer to the first node in the set of nodes with keys
|
||||
* matching <FindMe>.
|
||||
* Notes: Node *p MUST be in the set of nodes with keys matching
|
||||
* <FindMe>. If not, this function will return NULL.
|
||||
*
|
||||
* 4.7: Bug found & fixed by Massimo Campostrini,
|
||||
* Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btLastOf( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr MatchMe,
|
||||
ubi_btNodePtr p );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Given a tree that a allows duplicate keys, and a pointer to a node in
|
||||
* the tree, this function will return a pointer to the last (traversal
|
||||
* order) node with the same key value.
|
||||
*
|
||||
* Input: RootPtr - A pointer to the root of the tree.
|
||||
* MatchMe - A pointer to the key value. This should probably
|
||||
* point to the key within node *p.
|
||||
* p - A pointer to a node in the tree.
|
||||
* Output: A pointer to the last node in the set of nodes with keys
|
||||
* matching <FindMe>.
|
||||
* Notes: Node *p MUST be in the set of nodes with keys matching
|
||||
* <FindMe>. If not, this function will return NULL.
|
||||
*
|
||||
* 4.7: Bug found & fixed by Massimo Campostrini,
|
||||
* Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_btTraverse( ubi_btRootPtr RootPtr,
|
||||
ubi_btActionRtn EachNode,
|
||||
void *UserData );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Traverse a tree in sorted order (non-recursively). At each node, call
|
||||
* (*EachNode)(), passing a pointer to the current node, and UserData as the
|
||||
* second parameter.
|
||||
* Input: RootPtr - a pointer to an ubi_btRoot structure that indicates
|
||||
* the tree to be traversed.
|
||||
* EachNode - a pointer to a function to be called at each node
|
||||
* as the node is visited.
|
||||
* UserData - a generic pointer that may point to anything that
|
||||
* you choose.
|
||||
* Output: A boolean value. FALSE if the tree is empty, otherwise TRUE.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_btKillTree( ubi_btRootPtr RootPtr,
|
||||
ubi_btKillNodeRtn FreeNode );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Delete an entire tree (non-recursively) and reinitialize the ubi_btRoot
|
||||
* structure. Note that this function will return FALSE if either parameter
|
||||
* is NULL.
|
||||
*
|
||||
* Input: RootPtr - a pointer to an ubi_btRoot structure that indicates
|
||||
* the root of the tree to delete.
|
||||
* FreeNode - a function that will be called for each node in the
|
||||
* tree to deallocate the memory used by the node.
|
||||
*
|
||||
* Output: A boolean value. FALSE if either input parameter was NULL, else
|
||||
* TRUE.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_btLeafNode( ubi_btNodePtr leader );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Returns a pointer to a leaf node.
|
||||
*
|
||||
* Input: leader - Pointer to a node at which to start the descent.
|
||||
*
|
||||
* Output: A pointer to a leaf node selected in a somewhat arbitrary
|
||||
* manner.
|
||||
*
|
||||
* Notes: I wrote this function because I was using splay trees as a
|
||||
* database cache. The cache had a maximum size on it, and I
|
||||
* needed a way of choosing a node to sacrifice if the cache
|
||||
* became full. In a splay tree, less recently accessed nodes
|
||||
* tend toward the bottom of the tree, meaning that leaf nodes
|
||||
* are good candidates for removal. (I really can't think of
|
||||
* any other reason to use this function.)
|
||||
* + In a simple binary tree or an AVL tree, the most recently
|
||||
* added nodes tend to be nearer the bottom, making this a *bad*
|
||||
* way to choose which node to remove from the cache.
|
||||
* + Randomizing the traversal order is probably a good idea. You
|
||||
* can improve the randomization of leaf node selection by passing
|
||||
* in pointers to nodes other than the root node each time. A
|
||||
* pointer to any node in the tree will do. Of course, if you
|
||||
* pass a pointer to a leaf node you'll get the same thing back.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
|
||||
int ubi_btModuleID( int size, char *list[] );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Returns a set of strings that identify the module.
|
||||
*
|
||||
* Input: size - The number of elements in the array <list>.
|
||||
* list - An array of pointers of type (char *). This array
|
||||
* should, initially, be empty. This function will fill
|
||||
* in the array with pointers to strings.
|
||||
* Output: The number of elements of <list> that were used. If this value
|
||||
* is less than <size>, the values of the remaining elements are
|
||||
* not guaranteed.
|
||||
*
|
||||
* Notes: Please keep in mind that the pointers returned indicate strings
|
||||
* stored in static memory. Don't free() them, don't write over
|
||||
* them, etc. Just read them.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Masquarade...
|
||||
*
|
||||
* This set of defines allows you to write programs that will use any of the
|
||||
* implemented binary tree modules (currently BinTree, AVLtree, and SplayTree).
|
||||
* Instead of using ubi_bt..., use ubi_tr..., and select the tree type by
|
||||
* including the appropriate module header.
|
||||
*/
|
||||
|
||||
#define ubi_trItemPtr ubi_btItemPtr
|
||||
|
||||
#define ubi_trNode ubi_btNode
|
||||
#define ubi_trNodePtr ubi_btNodePtr
|
||||
|
||||
#define ubi_trRoot ubi_btRoot
|
||||
#define ubi_trRootPtr ubi_btRootPtr
|
||||
|
||||
#define ubi_trCompFunc ubi_btCompFunc
|
||||
#define ubi_trActionRtn ubi_btActionRtn
|
||||
#define ubi_trKillNodeRtn ubi_btKillNodeRtn
|
||||
|
||||
#define ubi_trSgn( x ) ubi_btSgn( x )
|
||||
|
||||
#define ubi_trInitNode( Np ) ubi_btInitNode( (ubi_btNodePtr)(Np) )
|
||||
|
||||
#define ubi_trInitTree( Rp, Cf, Fl ) \
|
||||
ubi_btInitTree( (ubi_btRootPtr)(Rp), (ubi_btCompFunc)(Cf), (Fl) )
|
||||
|
||||
#define ubi_trInsert( Rp, Nn, Ip, On ) \
|
||||
ubi_btInsert( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Nn), \
|
||||
(ubi_btItemPtr)(Ip), (ubi_btNodePtr *)(On) )
|
||||
|
||||
#define ubi_trRemove( Rp, Dn ) \
|
||||
ubi_btRemove( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Dn) )
|
||||
|
||||
#define ubi_trLocate( Rp, Ip, Op ) \
|
||||
ubi_btLocate( (ubi_btRootPtr)(Rp), \
|
||||
(ubi_btItemPtr)(Ip), \
|
||||
(ubi_trCompOps)(Op) )
|
||||
|
||||
#define ubi_trFind( Rp, Ip ) \
|
||||
ubi_btFind( (ubi_btRootPtr)(Rp), (ubi_btItemPtr)(Ip) )
|
||||
|
||||
#define ubi_trNext( P ) ubi_btNext( (ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trPrev( P ) ubi_btPrev( (ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trFirst( P ) ubi_btFirst( (ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trLast( P ) ubi_btLast( (ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trFirstOf( Rp, Ip, P ) \
|
||||
ubi_btFirstOf( (ubi_btRootPtr)(Rp), \
|
||||
(ubi_btItemPtr)(Ip), \
|
||||
(ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trLastOf( Rp, Ip, P ) \
|
||||
ubi_btLastOf( (ubi_btRootPtr)(Rp), \
|
||||
(ubi_btItemPtr)(Ip), \
|
||||
(ubi_btNodePtr)(P) )
|
||||
|
||||
#define ubi_trTraverse( Rp, En, Ud ) \
|
||||
ubi_btTraverse((ubi_btRootPtr)(Rp), (ubi_btActionRtn)(En), (void *)(Ud))
|
||||
|
||||
#define ubi_trKillTree( Rp, Fn ) \
|
||||
ubi_btKillTree( (ubi_btRootPtr)(Rp), (ubi_btKillNodeRtn)(Fn) )
|
||||
|
||||
#define ubi_trLeafNode( Nd ) \
|
||||
ubi_btLeafNode( (ubi_btNodePtr)(Nd) )
|
||||
|
||||
#define ubi_trModuleID( s, l ) ubi_btModuleID( s, l )
|
||||
|
||||
/* ========================================================================== */
|
||||
#endif /* UBI_BINTREE_H */
|
@ -1,409 +0,0 @@
|
||||
#ifndef UBI_CACHE_H
|
||||
#define UBI_CACHE_H
|
||||
/* ========================================================================== **
|
||||
* ubi_Cache.h
|
||||
*
|
||||
* Copyright (C) 1997 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This module implements a generic cache.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This module uses a splay tree to implement a simple cache. The cache
|
||||
* module adds a thin layer of functionality to the splay tree. In
|
||||
* particular:
|
||||
*
|
||||
* - The tree (cache) may be limited in size by the number of
|
||||
* entries permitted or the amount of memory used. When either
|
||||
* limit is exceeded cache entries are removed until the cache
|
||||
* conforms.
|
||||
* - Some statistical information is kept so that an approximate
|
||||
* "hit ratio" can be calculated.
|
||||
* - There are several functions available that provide access to
|
||||
* and management of cache size limits, hit ratio, and tree
|
||||
* trimming.
|
||||
*
|
||||
* The splay tree is used because recently accessed items tend toward the
|
||||
* top of the tree and less recently accessed items tend toward the bottom.
|
||||
* This makes it easy to purge less recently used items should the cache
|
||||
* exceed its limits.
|
||||
*
|
||||
* To use this module, you will need to supply a comparison function of
|
||||
* type ubi_trCompFunc and a node-freeing function of type
|
||||
* ubi_trKillNodeTrn. See ubi_BinTree.h for more information on
|
||||
* these. (This is all basic ubiqx tree management stuff.)
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* - Cache performance will start to suffer dramatically if the
|
||||
* cache becomes large enough to force the OS to start swapping
|
||||
* memory to disk. This is because the nodes of the underlying tree
|
||||
* will be scattered across memory in an order that is completely
|
||||
* unrelated to their traversal order. As more and more of the
|
||||
* cache is placed into swap space, more and more swaps will be
|
||||
* required for a simple traversal (...and then there's the splay
|
||||
* operation).
|
||||
*
|
||||
* In one simple test under Linux, the load and dump of a cache of
|
||||
* 400,000 entries took only 1min, 40sec of real time. The same
|
||||
* test with 450,000 records took 2 *hours* and eight minutes.
|
||||
*
|
||||
* - In an effort to save memory, I considered using an unsigned
|
||||
* short to save the per-entry entry size. I would have tucked this
|
||||
* value into some unused space in the tree node structure. On
|
||||
* 32-bit word aligned systems this would have saved an additional
|
||||
* four bytes per entry. I may revisit this issue, but for now I've
|
||||
* decided against it.
|
||||
*
|
||||
* Using an unsigned short would limit the size of an entry to 64K
|
||||
* bytes. That's probably more than enough for most applications.
|
||||
* The key word in that last sentence, however, is "probably". I
|
||||
* really dislike imposing such limits on things.
|
||||
*
|
||||
* - Each entry keeps track of the amount of memory it used and the
|
||||
* cache header keeps the total. This information is provided via
|
||||
* the EntrySize parameter in ubi_cachePut(), so it is up to you to
|
||||
* make sure that the numbers are accurate. (The numbers don't even
|
||||
* have to represent bytes used.)
|
||||
*
|
||||
* As you consider this, note that the strdup() function--as an
|
||||
* example--will call malloc(). The latter generally allocates a
|
||||
* multiple of the system word size, which may be more than the
|
||||
* number of bytes needed to store the string.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Log: ubi_Cache.h,v
|
||||
* Revision 0.3 1998/06/03 18:00:15 crh
|
||||
* Further fiddling with sys_include.h, which is no longer explicitly
|
||||
* included by this module since it is inherited from ubi_BinTree.h.
|
||||
*
|
||||
* Revision 0.2 1998/06/02 01:36:18 crh
|
||||
* Changed include name from ubi_null.h to sys_include.h to make it
|
||||
* more generic.
|
||||
*
|
||||
* Revision 0.1 1998/05/20 04:36:02 crh
|
||||
* The C file now includes ubi_null.h. See ubi_null.h for more info.
|
||||
*
|
||||
* Revision 0.0 1997/12/18 06:25:23 crh
|
||||
* Initial Revision.
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "ubi_SplayTree.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Typedefs...
|
||||
*
|
||||
* ubi_cacheRoot - Cache header structure, which consists of a binary
|
||||
* tree root and other required housekeeping fields, as
|
||||
* listed below.
|
||||
* ubi_cacheRootPtr - Pointer to a Cache.
|
||||
*
|
||||
* ubi_cacheEntry - A cache Entry, which consists of a tree node
|
||||
* structure and the size (in bytes) of the entry
|
||||
* data. The entry size should be supplied via
|
||||
* the EntrySize parameter of the ubi_cachePut()
|
||||
* function.
|
||||
*
|
||||
* ubi_cacheEntryPtr - Pointer to a ubi_cacheEntry.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ubi_trRoot root; /* Splay tree control structure. */
|
||||
ubi_trKillNodeRtn free_func; /* Function used to free entries. */
|
||||
unsigned long max_entries; /* Max cache entries. 0 == unlimited */
|
||||
unsigned long max_memory; /* Max memory to use. 0 == unlimited */
|
||||
unsigned long mem_used; /* Memory currently in use (bytes). */
|
||||
unsigned short cache_hits; /* Incremented on succesful find. */
|
||||
unsigned short cache_trys; /* Incremented on cache lookup. */
|
||||
} ubi_cacheRoot;
|
||||
|
||||
typedef ubi_cacheRoot *ubi_cacheRootPtr;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ubi_trNode node; /* Tree node structure. */
|
||||
unsigned long entry_size; /* Entry size. Used when managing
|
||||
* caches with maximum memory limits.
|
||||
*/
|
||||
} ubi_cacheEntry;
|
||||
|
||||
typedef ubi_cacheEntry *ubi_cacheEntryPtr;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Macros...
|
||||
*
|
||||
* ubi_cacheGetMaxEntries() - Report the current maximum number of entries
|
||||
* allowed in the cache. Zero indicates no
|
||||
* maximum.
|
||||
* ubi_cacheGetMaxMemory() - Report the current maximum amount of memory
|
||||
* that may be used in the cache. Zero
|
||||
* indicates no maximum.
|
||||
* ubi_cacheGetEntryCount() - Report the current number of entries in the
|
||||
* cache.
|
||||
* ubi_cacheGetMemUsed() - Report the amount of memory currently in use
|
||||
* by the cache.
|
||||
*/
|
||||
|
||||
#define ubi_cacheGetMaxEntries( Cptr ) (((ubi_cacheRootPtr)(Cptr))->max_entries)
|
||||
#define ubi_cacheGetMaxMemory( Cptr ) (((ubi_cacheRootPtr)(Cptr))->max_memory)
|
||||
|
||||
#define ubi_cacheGetEntryCount( Cptr ) (((ubi_cacheRootPtr)(Cptr))->root.count)
|
||||
#define ubi_cacheGetMemUsed( Cptr ) (((ubi_cacheRootPtr)(Cptr))->mem_used)
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
ubi_cacheRootPtr ubi_cacheInit( ubi_cacheRootPtr CachePtr,
|
||||
ubi_trCompFunc CompFunc,
|
||||
ubi_trKillNodeRtn FreeFunc,
|
||||
unsigned long MaxEntries,
|
||||
unsigned long MaxMemory );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Initialize a cache header structure.
|
||||
*
|
||||
* Input: CachePtr - A pointer to a ubi_cacheRoot structure that is
|
||||
* to be initialized.
|
||||
* CompFunc - A pointer to the function that will be called
|
||||
* to compare two cache values. See the module
|
||||
* comments, above, for more information.
|
||||
* FreeFunc - A pointer to a function that will be called
|
||||
* to free a cache entry. If you allocated
|
||||
* the cache entry using malloc(), then this
|
||||
* will likely be free(). If you are allocating
|
||||
* cache entries from a free list, then this will
|
||||
* likely be a function that returns memory to the
|
||||
* free list, etc.
|
||||
* MaxEntries - The maximum number of entries that will be
|
||||
* allowed to exist in the cache. If this limit
|
||||
* is exceeded, then existing entries will be
|
||||
* removed from the cache. A value of zero
|
||||
* indicates that there is no limit on the number
|
||||
* of cache entries. See ubi_cachePut().
|
||||
* MaxMemory - The maximum amount of memory, in bytes, to be
|
||||
* allocated to the cache (excluding the cache
|
||||
* header). If this is exceeded, existing entries
|
||||
* in the cache will be removed until enough memory
|
||||
* has been freed to meet the condition. See
|
||||
* ubi_cachePut().
|
||||
*
|
||||
* Output: A pointer to the initialized cache (i.e., the same as CachePtr).
|
||||
*
|
||||
* Notes: Both MaxEntries and MaxMemory may be changed after the cache
|
||||
* has been created. See
|
||||
* ubi_cacheSetMaxEntries()
|
||||
* ubi_cacheSetMaxMemory()
|
||||
* ubi_cacheGetMaxEntries()
|
||||
* ubi_cacheGetMaxMemory() (the latter two are macros).
|
||||
*
|
||||
* - Memory is allocated in multiples of the word size. The
|
||||
* return value of the strlen() function does not reflect
|
||||
* this; it will allways be less than or equal to the amount
|
||||
* of memory actually allocated. Keep this in mind when
|
||||
* choosing a value for MaxMemory.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_cacheRootPtr ubi_cacheClear( ubi_cacheRootPtr CachePtr );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Remove and free all entries in an existing cache.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache that is to be cleared.
|
||||
*
|
||||
* Output: A pointer to the cache header (i.e., the same as CachePtr).
|
||||
* This function re-initializes the cache header.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
void ubi_cachePut( ubi_cacheRootPtr CachePtr,
|
||||
unsigned long EntrySize,
|
||||
ubi_cacheEntryPtr EntryPtr,
|
||||
ubi_trItemPtr Key );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Add an entry to the cache.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache into which the entry
|
||||
* will be added.
|
||||
* EntrySize - The size, in bytes, of the memory block indicated
|
||||
* by EntryPtr. This will be copied into the
|
||||
* EntryPtr->entry_size field.
|
||||
* EntryPtr - A pointer to a memory block that begins with a
|
||||
* ubi_cacheEntry structure. The entry structure
|
||||
* should be followed immediately by the data to be
|
||||
* cached (even if that is a pointer to yet more data).
|
||||
* Key - Pointer used to identify the lookup key within the
|
||||
* Entry.
|
||||
*
|
||||
* Output: None.
|
||||
*
|
||||
* Notes: After adding the new node, the cache is "trimmed". This
|
||||
* removes extra nodes if the tree has exceeded it's memory or
|
||||
* entry count limits. It is unlikely that the newly added node
|
||||
* will be purged from the cache (assuming a reasonably large
|
||||
* cache), since new nodes in a splay tree (which is what this
|
||||
* module was designed to use) are moved to the top of the tree
|
||||
* and the cache purge process removes nodes from the bottom of
|
||||
* the tree.
|
||||
* - The underlying splay tree is opened in OVERWRITE mode. If
|
||||
* the input key matches an existing key, the existing entry will
|
||||
* be politely removed from the tree and freed.
|
||||
* - Memory is allocated in multiples of the word size. The
|
||||
* return value of the strlen() function does not reflect
|
||||
* this; it will allways be less than or equal to the amount
|
||||
* of memory actually allocated.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_cacheEntryPtr ubi_cacheGet( ubi_cacheRootPtr CachePtr,
|
||||
ubi_trItemPtr FindMe );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Attempt to retrieve an entry from the cache.
|
||||
*
|
||||
* Input: CachePtr - A ponter to the cache that is to be searched.
|
||||
* FindMe - A ubi_trItemPtr that indicates the key for which
|
||||
* to search.
|
||||
*
|
||||
* Output: A pointer to the cache entry that was found, or NULL if no
|
||||
* matching entry was found.
|
||||
*
|
||||
* Notes: This function also updates the hit ratio counters.
|
||||
* The counters are unsigned short. If the number of cache tries
|
||||
* reaches 32768, then both the number of tries and the number of
|
||||
* hits are divided by two. This prevents the counters from
|
||||
* overflowing. See the comments in ubi_cacheHitRatio() for
|
||||
* additional notes.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_cacheDelete( ubi_cacheRootPtr CachePtr, ubi_trItemPtr DeleteMe );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Find and delete the specified cache entry.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache.
|
||||
* DeleteMe - The key of the entry to be deleted.
|
||||
*
|
||||
* Output: TRUE if the entry was found & freed, else FALSE.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_cacheReduce( ubi_cacheRootPtr CachePtr, unsigned long count );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Remove <count> entries from the bottom of the cache.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache which is to be reduced in
|
||||
* size.
|
||||
* count - The number of entries to remove.
|
||||
*
|
||||
* Output: The function will return TRUE if <count> entries were removed,
|
||||
* else FALSE. A return value of FALSE should indicate that
|
||||
* there were less than <count> entries in the cache, and that the
|
||||
* cache is now empty.
|
||||
*
|
||||
* Notes: This function forces a reduction in the number of cache entries
|
||||
* without requiring that the MaxMemory or MaxEntries values be
|
||||
* changed.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
unsigned long ubi_cacheSetMaxEntries( ubi_cacheRootPtr CachePtr,
|
||||
unsigned long NewSize );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Change the maximum number of entries allowed to exist in the cache.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache to be modified.
|
||||
* NewSize - The new maximum number of cache entries.
|
||||
*
|
||||
* Output: The maximum number of entries previously allowed to exist in
|
||||
* the cache.
|
||||
*
|
||||
* Notes: If the new size is less than the old size, this function will
|
||||
* trim the cache (remove excess entries).
|
||||
* - A value of zero indicates an unlimited number of entries.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
unsigned long ubi_cacheSetMaxMemory( ubi_cacheRootPtr CachePtr,
|
||||
unsigned long NewSize );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Change the maximum amount of memory to be used for storing cache
|
||||
* entries.
|
||||
*
|
||||
* Input: CachePtr - A pointer to the cache to be modified.
|
||||
* NewSize - The new cache memory size.
|
||||
*
|
||||
* Output: The previous maximum memory size.
|
||||
*
|
||||
* Notes: If the new size is less than the old size, this function will
|
||||
* trim the cache (remove excess entries).
|
||||
* - A value of zero indicates that the cache has no memory limit.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
int ubi_cacheHitRatio( ubi_cacheRootPtr CachePtr );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Returns a value that is 10,000 times the slightly weighted average hit
|
||||
* ratio for the cache.
|
||||
*
|
||||
* Input: CachePtr - Pointer to the cache to be queried.
|
||||
*
|
||||
* Output: An integer that is 10,000 times the number of successful
|
||||
* cache hits divided by the number of cache lookups, or:
|
||||
* (10000 * hits) / trys
|
||||
* You can easily convert this to a float, or do something
|
||||
* like this (where i is the return value of this function):
|
||||
*
|
||||
* printf( "Hit rate : %d.%02d%%\n", (i/100), (i%100) );
|
||||
*
|
||||
* Notes: I say "slightly-weighted", because the numerator and
|
||||
* denominator are both accumulated in locations of type
|
||||
* 'unsigned short'. If the number of cache trys becomes
|
||||
* large enough, both are divided by two. (See function
|
||||
* ubi_cacheGet().)
|
||||
* Dividing both numerator and denominator by two does not
|
||||
* change the ratio (much...it is an integer divide), but it
|
||||
* does mean that subsequent increments to either counter will
|
||||
* have twice as much significance as previous ones.
|
||||
*
|
||||
* - The value returned by this function will be in the range
|
||||
* [0..10000] because ( 0 <= cache_hits <= cache_trys ) will
|
||||
* always be true.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ubi_CACHE_H */
|
@ -1,371 +0,0 @@
|
||||
#ifndef UBI_SPLAYTREE_H
|
||||
#define UBI_SPLAYTREE_H
|
||||
/* ========================================================================== **
|
||||
* ubi_SplayTree.h
|
||||
*
|
||||
* Copyright (C) 1993-1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This module implements "splay" trees. Splay trees are binary trees
|
||||
* that are rearranged (splayed) whenever a node is accessed. The
|
||||
* splaying process *tends* to make the tree bushier (improves balance),
|
||||
* and the nodes that are accessed most frequently *tend* to be closer to
|
||||
* the top.
|
||||
*
|
||||
* References: "Self-Adjusting Binary Search Trees", by Daniel Sleator and
|
||||
* Robert Tarjan. Journal of the Association for Computing
|
||||
* Machinery Vol 32, No. 3, July 1985 pp. 652-686
|
||||
*
|
||||
* See also: http://www.cs.cmu.edu/~sleator/
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Log: ubi_SplayTree.h,v
|
||||
* Revision 4.4 1998/06/04 21:29:27 crh
|
||||
* Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
|
||||
* This is more "standard", and is what people expect. Weird, eh?
|
||||
*
|
||||
* Revision 4.3 1998/06/03 17:45:05 crh
|
||||
* Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is
|
||||
* included by all of the binary tree files.
|
||||
*
|
||||
* Also fixed some warnings produced by lint on Irix 6.2, which doesn't seem
|
||||
* to like syntax like this:
|
||||
*
|
||||
* if( (a = b) )
|
||||
*
|
||||
* The fix was to change lines like the above to:
|
||||
*
|
||||
* if( 0 != (a=b) )
|
||||
*
|
||||
* Which means the same thing.
|
||||
*
|
||||
* Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in
|
||||
* ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping
|
||||
* of tree types by simply changing a header. Unfortunately, the
|
||||
* macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will
|
||||
* conflict if used together. You must either choose a single tree
|
||||
* type, or use the underlying function calls directly. Compare
|
||||
* the two header files for more information.
|
||||
*
|
||||
* Revision 4.2 1998/06/02 01:29:14 crh
|
||||
* Changed ubi_null.h to sys_include.h to make it more generic.
|
||||
*
|
||||
* Revision 4.1 1998/05/20 04:37:54 crh
|
||||
* The C file now includes ubi_null.h. See ubi_null.h for more info.
|
||||
*
|
||||
* Revision 4.0 1998/03/10 03:40:57 crh
|
||||
* Minor comment changes. The revision number is now 4.0 to match the
|
||||
* BinTree and AVLtree modules.
|
||||
*
|
||||
* Revision 2.7 1998/01/24 06:37:57 crh
|
||||
* Added a URL for more information.
|
||||
*
|
||||
* Revision 2.6 1997/12/23 04:02:20 crh
|
||||
* In this version, all constants & macros defined in the header file have
|
||||
* the ubi_tr prefix. Also cleaned up anything that gcc complained about
|
||||
* when run with '-pedantic -fsyntax-only -Wall'.
|
||||
*
|
||||
* Revision 2.5 1997/07/26 04:15:46 crh
|
||||
* + Cleaned up a few minor syntax annoyances that gcc discovered for me.
|
||||
* + Changed ubi_TRUE and ubi_FALSE to ubi_trTRUE and ubi_trFALSE.
|
||||
*
|
||||
* Revision 2.4 1997/06/03 05:22:56 crh
|
||||
* Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid causing
|
||||
* problems.
|
||||
*
|
||||
* Revision 2.3 1995/10/03 22:19:37 CRH
|
||||
* Ubisized!
|
||||
* Also, added the function ubi_sptSplay().
|
||||
*
|
||||
* Revision 2.1 95/03/09 23:55:04 CRH
|
||||
* Added the ModuleID static string and function. These modules are now
|
||||
* self-identifying.
|
||||
*
|
||||
* Revision 2.0 95/02/27 22:34:55 CRH
|
||||
* This module was updated to match the interface changes made to the
|
||||
* ubi_BinTree module. In particular, the interface to the Locate() function
|
||||
* has changed. See ubi_BinTree for more information on changes and new
|
||||
* functions.
|
||||
*
|
||||
* The revision number was also upped to match ubi_BinTree.
|
||||
*
|
||||
*
|
||||
* Revision 1.0 93/10/15 22:59:36 CRH
|
||||
* With this revision, I have added a set of #define's that provide a single,
|
||||
* standard API to all existing tree modules. Until now, each of the three
|
||||
* existing modules had a different function and typedef prefix, as follows:
|
||||
*
|
||||
* Module Prefix
|
||||
* ubi_BinTree ubi_bt
|
||||
* ubi_AVLtree ubi_avl
|
||||
* ubi_SplayTree ubi_spt
|
||||
*
|
||||
* To further complicate matters, only those portions of the base module
|
||||
* (ubi_BinTree) that were superceeded in the new module had the new names.
|
||||
* For example, if you were using ubi_SplayTree, the locate function was
|
||||
* called "ubi_sptLocate", but the next and previous functions remained
|
||||
* "ubi_btNext" and "ubi_btPrev".
|
||||
*
|
||||
* This was not too terrible if you were familiar with the modules and knew
|
||||
* exactly which tree model you wanted to use. If you wanted to be able to
|
||||
* change modules (for speed comparisons, etc), things could get messy very
|
||||
* quickly.
|
||||
*
|
||||
* So, I have added a set of defined names that get redefined in any of the
|
||||
* descendant modules. To use this standardized interface in your code,
|
||||
* simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with
|
||||
* "ubi_tr". The "ubi_tr" names will resolve to the correct function or
|
||||
* datatype names for the module that you are using. Just remember to
|
||||
* include the header for that module in your program file. Because these
|
||||
* names are handled by the preprocessor, there is no added run-time
|
||||
* overhead.
|
||||
*
|
||||
* Note that the original names do still exist, and can be used if you wish
|
||||
* to write code directly to a specific module. This should probably only be
|
||||
* done if you are planning to implement a new descendant type, such as
|
||||
* red/black trees. CRH
|
||||
*
|
||||
* Revision 0.0 93/04/21 23:07:13 CRH
|
||||
* Initial version, written by Christopher R. Hertel.
|
||||
* This module implements Splay Trees using the ubi_BinTree module as a basis.
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "ubi_BinTree.h" /* Base binary tree functions, types, etc. */
|
||||
|
||||
/* ========================================================================== **
|
||||
* Function prototypes...
|
||||
*/
|
||||
|
||||
ubi_trBool ubi_sptInsert( ubi_btRootPtr RootPtr,
|
||||
ubi_btNodePtr NewNode,
|
||||
ubi_btItemPtr ItemPtr,
|
||||
ubi_btNodePtr *OldNode );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function uses a non-recursive algorithm to add a new element to the
|
||||
* splay tree.
|
||||
*
|
||||
* Input: RootPtr - a pointer to the ubi_btRoot structure that indicates
|
||||
* the root of the tree to which NewNode is to be added.
|
||||
* NewNode - a pointer to an ubi_btNode structure that is NOT
|
||||
* part of any tree.
|
||||
* ItemPtr - A pointer to the sort key that is stored within
|
||||
* *NewNode. ItemPtr MUST point to information stored
|
||||
* in *NewNode or an EXACT DUPLICATE. The key data
|
||||
* indicated by ItemPtr is used to place the new node
|
||||
* into the tree.
|
||||
* OldNode - a pointer to an ubi_btNodePtr. When searching
|
||||
* the tree, a duplicate node may be found. If
|
||||
* duplicates are allowed, then the new node will
|
||||
* be simply placed into the tree. If duplicates
|
||||
* are not allowed, however, then one of two things
|
||||
* may happen.
|
||||
* 1) if overwritting *is not* allowed, this
|
||||
* function will return FALSE (indicating that
|
||||
* the new node could not be inserted), and
|
||||
* *OldNode will point to the duplicate that is
|
||||
* still in the tree.
|
||||
* 2) if overwritting *is* allowed, then this
|
||||
* function will swap **OldNode for *NewNode.
|
||||
* In this case, *OldNode will point to the node
|
||||
* that was removed (thus allowing you to free
|
||||
* the node).
|
||||
* ** If you are using overwrite mode, ALWAYS **
|
||||
* ** check the return value of this parameter! **
|
||||
* Note: You may pass NULL in this parameter, the
|
||||
* function knows how to cope. If you do this,
|
||||
* however, there will be no way to return a
|
||||
* pointer to an old (ie. replaced) node (which is
|
||||
* a problem if you are using overwrite mode).
|
||||
*
|
||||
* Output: a boolean value indicating success or failure. The function
|
||||
* will return FALSE if the node could not be added to the tree.
|
||||
* Such failure will only occur if duplicates are not allowed,
|
||||
* nodes cannot be overwritten, AND a duplicate key was found
|
||||
* within the tree.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_sptRemove( ubi_btRootPtr RootPtr, ubi_btNodePtr DeadNode );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function removes the indicated node from the tree.
|
||||
*
|
||||
* Input: RootPtr - A pointer to the header of the tree that contains
|
||||
* the node to be removed.
|
||||
* DeadNode - A pointer to the node that will be removed.
|
||||
*
|
||||
* Output: This function returns a pointer to the node that was removed
|
||||
* from the tree (ie. the same as DeadNode).
|
||||
*
|
||||
* Note: The node MUST be in the tree indicated by RootPtr. If not,
|
||||
* strange and evil things will happen to your trees.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_sptLocate( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr FindMe,
|
||||
ubi_trCompOps CompOp );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* The purpose of ubi_btLocate() is to find a node or set of nodes given
|
||||
* a target value and a "comparison operator". The Locate() function is
|
||||
* more flexible and (in the case of trees that may contain dupicate keys)
|
||||
* more precise than the ubi_btFind() function. The latter is faster,
|
||||
* but it only searches for exact matches and, if the tree contains
|
||||
* duplicates, Find() may return a pointer to any one of the duplicate-
|
||||
* keyed records.
|
||||
*
|
||||
* Input:
|
||||
* RootPtr - A pointer to the header of the tree to be searched.
|
||||
* FindMe - An ubi_btItemPtr that indicates the key for which to
|
||||
* search.
|
||||
* CompOp - One of the following:
|
||||
* CompOp Return a pointer to the node with
|
||||
* ------ ---------------------------------
|
||||
* ubi_trLT - the last key value that is less
|
||||
* than FindMe.
|
||||
* ubi_trLE - the first key matching FindMe, or
|
||||
* the last key that is less than
|
||||
* FindMe.
|
||||
* ubi_trEQ - the first key matching FindMe.
|
||||
* ubi_trGE - the first key matching FindMe, or the
|
||||
* first key greater than FindMe.
|
||||
* ubi_trGT - the first key greater than FindMe.
|
||||
* Output:
|
||||
* A pointer to the node matching the criteria listed above under
|
||||
* CompOp, or NULL if no node matched the criteria.
|
||||
*
|
||||
* Notes:
|
||||
* In the case of trees with duplicate keys, Locate() will behave as
|
||||
* follows:
|
||||
*
|
||||
* Find: 3 Find: 3
|
||||
* Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6
|
||||
* ^ ^ ^ ^ ^
|
||||
* LT EQ GT LE GE
|
||||
*
|
||||
* That is, when returning a pointer to a node with a key that is LESS
|
||||
* THAN the target key (FindMe), Locate() will return a pointer to the
|
||||
* LAST matching node.
|
||||
* When returning a pointer to a node with a key that is GREATER
|
||||
* THAN the target key (FindMe), Locate() will return a pointer to the
|
||||
* FIRST matching node.
|
||||
*
|
||||
* See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf().
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_btNodePtr ubi_sptFind( ubi_btRootPtr RootPtr,
|
||||
ubi_btItemPtr FindMe );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function performs a non-recursive search of a tree for any node
|
||||
* matching a specific key.
|
||||
*
|
||||
* Input:
|
||||
* RootPtr - a pointer to the header of the tree to be searched.
|
||||
* FindMe - a pointer to the key value for which to search.
|
||||
*
|
||||
* Output:
|
||||
* A pointer to a node with a key that matches the key indicated by
|
||||
* FindMe, or NULL if no such node was found.
|
||||
*
|
||||
* Note: In a tree that allows duplicates, the pointer returned *might
|
||||
* not* point to the (sequentially) first occurance of the
|
||||
* desired key. In such a tree, it may be more useful to use
|
||||
* ubi_sptLocate().
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
void ubi_sptSplay( ubi_btRootPtr RootPtr,
|
||||
ubi_btNodePtr SplayMe );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* This function allows you to splay the tree at a given node, thus moving
|
||||
* the node to the top of the tree.
|
||||
*
|
||||
* Input:
|
||||
* RootPtr - a pointer to the header of the tree to be splayed.
|
||||
* SplayMe - a pointer to a node within the tree. This will become
|
||||
* the new root node.
|
||||
* Output: None.
|
||||
*
|
||||
* Notes: This is an uncharacteristic function for this group of modules
|
||||
* in that it provides access to the internal balancing routines,
|
||||
* which would normally be hidden.
|
||||
* Splaying the tree will not damage it (assuming that I've done
|
||||
* *my* job), but there is overhead involved. I don't recommend
|
||||
* that you use this function unless you understand the underlying
|
||||
* Splay Tree principles involved.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
int ubi_sptModuleID( int size, char *list[] );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Returns a set of strings that identify the module.
|
||||
*
|
||||
* Input: size - The number of elements in the array <list>.
|
||||
* list - An array of pointers of type (char *). This array
|
||||
* should, initially, be empty. This function will fill
|
||||
* in the array with pointers to strings.
|
||||
* Output: The number of elements of <list> that were used. If this value
|
||||
* is less than <size>, the values of the remaining elements are
|
||||
* not guaranteed.
|
||||
*
|
||||
* Notes: Please keep in mind that the pointers returned indicate strings
|
||||
* stored in static memory. Don't free() them, don't write over
|
||||
* them, etc. Just read them.
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Masquarade...
|
||||
*
|
||||
* This set of defines allows you to write programs that will use any of the
|
||||
* implemented binary tree modules (currently BinTree, AVLtree, and SplayTree).
|
||||
* Instead of using ubi_bt..., use ubi_tr..., and select the tree type by
|
||||
* including the appropriate module header.
|
||||
*/
|
||||
|
||||
#undef ubi_trInsert
|
||||
#undef ubi_trRemove
|
||||
#undef ubi_trLocate
|
||||
#undef ubi_trFind
|
||||
#undef ubi_trModuleID
|
||||
|
||||
#define ubi_trInsert( Rp, Nn, Ip, On ) \
|
||||
ubi_sptInsert( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Nn), \
|
||||
(ubi_btItemPtr)(Ip), (ubi_btNodePtr *)(On) )
|
||||
|
||||
#define ubi_trRemove( Rp, Dn ) \
|
||||
ubi_sptRemove( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Dn) )
|
||||
|
||||
#define ubi_trLocate( Rp, Ip, Op ) \
|
||||
ubi_sptLocate( (ubi_btRootPtr)(Rp), \
|
||||
(ubi_btItemPtr)(Ip), \
|
||||
(ubi_trCompOps)(Op) )
|
||||
|
||||
#define ubi_trFind( Rp, Ip ) \
|
||||
ubi_sptFind( (ubi_btRootPtr)(Rp), (ubi_btItemPtr)(Ip) )
|
||||
|
||||
#define ubi_trModuleID( s, l ) ubi_sptModuleID( s, l )
|
||||
|
||||
/* ================================ The End ================================= */
|
||||
#endif /* UBI_SPLAYTREE_H */
|
@ -1,236 +0,0 @@
|
||||
#ifndef UBI_DLINKLIST_H
|
||||
#define UBI_DLINKLIST_H
|
||||
/* ========================================================================== **
|
||||
* ubi_dLinkList.h
|
||||
*
|
||||
* Copyright (C) 1997, 1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This module implements simple doubly-linked lists.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Log: ubi_dLinkList.h,v
|
||||
* Revision 0.10 1998/07/24 07:30:20 crh
|
||||
* Added the ubi_dlNewList() macro.
|
||||
*
|
||||
* Revision 0.9 1998/06/04 21:29:27 crh
|
||||
* Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
|
||||
* This is more "standard", and is what people expect. Weird, eh?
|
||||
*
|
||||
* Revision 0.8 1998/06/03 18:06:03 crh
|
||||
* Further fiddling with sys_include.h, which has been moved from the .c file
|
||||
* to the .h file.
|
||||
*
|
||||
* Revision 0.7 1998/06/02 01:38:47 crh
|
||||
* Changed include file name from ubi_null.h to sys_include.h to make it
|
||||
* more generic.
|
||||
*
|
||||
* Revision 0.6 1998/05/20 04:38:05 crh
|
||||
* The C file now includes ubi_null.h. See ubi_null.h for more info.
|
||||
*
|
||||
* Revision 0.5 1998/03/10 02:54:04 crh
|
||||
* Simplified the code and added macros for stack & queue manipulations.
|
||||
*
|
||||
* Revision 0.4 1998/01/03 01:53:44 crh
|
||||
* Added ubi_dlCount() macro.
|
||||
*
|
||||
* Revision 0.3 1997/10/15 03:04:31 crh
|
||||
* Added some handy type casting to the macros. Added AddHere and RemThis
|
||||
* macros.
|
||||
*
|
||||
* Revision 0.2 1997/10/08 03:08:16 crh
|
||||
* Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
|
||||
* macro, which was passing the wrong value for <After> to Insert().
|
||||
*
|
||||
* Revision 0.1 1997/10/07 04:34:38 crh
|
||||
* Initial Revision.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This module is similar to the ubi_sLinkList module, but it is neither a
|
||||
* descendant type nor an easy drop-in replacement for the latter. One key
|
||||
* difference is that the ubi_dlRemove() function removes the indicated node,
|
||||
* while the ubi_slRemove() function (in ubi_sLinkList) removes the node
|
||||
* *following* the indicated node.
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "sys_include.h" /* System-specific includes. */
|
||||
|
||||
/* ========================================================================== **
|
||||
* Typedefs...
|
||||
*
|
||||
* ubi_dlNode - This is the basic node structure.
|
||||
* ubi_dlNodePtr - Pointer to a node.
|
||||
* ubi_dlList - This is the list header structure.
|
||||
* ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct ubi_dlListNode
|
||||
{
|
||||
struct ubi_dlListNode *Next;
|
||||
struct ubi_dlListNode *Prev;
|
||||
} ubi_dlNode;
|
||||
|
||||
typedef ubi_dlNode *ubi_dlNodePtr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ubi_dlNodePtr Head;
|
||||
ubi_dlNodePtr Tail;
|
||||
unsigned long count;
|
||||
} ubi_dlList;
|
||||
|
||||
typedef ubi_dlList *ubi_dlListPtr;
|
||||
|
||||
/* ========================================================================== **
|
||||
* Macros...
|
||||
*
|
||||
* ubi_dlNewList - Macro used to declare and initialize a new list in one
|
||||
* swell foop. It is used when defining a variable of
|
||||
* type ubi_dlList. The definition
|
||||
* static ubi_dlNewList( gerbil );
|
||||
* is translated to
|
||||
* static ubi_dlList gerbil[1] = {{ NULL, NULL, 0 }};
|
||||
*
|
||||
* ubi_dlCount - Return the number of entries currently in the list.
|
||||
*
|
||||
* ubi_dlAddHead - Add a new node at the head of the list.
|
||||
* ubi_dlAddNext - Add a node following the given node.
|
||||
* ubi_dlAddTail - Add a new node at the tail of the list.
|
||||
* Note: AddTail evaluates the L parameter twice.
|
||||
*
|
||||
* ubi_dlRemHead - Remove the node at the head of the list, if any.
|
||||
* Note: RemHead evaluates the L parameter twice.
|
||||
* ubi_dlRemThis - Remove the indicated node.
|
||||
* ubi_dlRemTail - Remove the node at the tail of the list, if any.
|
||||
* Note: RemTail evaluates the L parameter twice.
|
||||
*
|
||||
* ubi_dlFirst - Return a pointer to the first node in the list, if any.
|
||||
* ubi_dlLast - Return a pointer to the last node in the list, if any.
|
||||
* ubi_dlNext - Given a node, return a pointer to the next node.
|
||||
* ubi_dlPrev - Given a node, return a pointer to the previous node.
|
||||
*
|
||||
* ubi_dlPush - Add a node at the head of the list (synonym of AddHead).
|
||||
* ubi_dlPop - Remove a node at the head of the list (synonym of RemHead).
|
||||
* ubi_dlEnqueue - Add a node at the tail of the list (sysnonym of AddTail).
|
||||
* ubi_dlDequeue - Remove a node at the head of the list (synonym of RemHead).
|
||||
*
|
||||
* Note that all of these provide type casting of the parameters. The
|
||||
* Add and Rem macros are nothing more than nice front-ends to the
|
||||
* Insert and Remove operations.
|
||||
*
|
||||
* Also note that the First, Next and Last macros do no parameter checking!
|
||||
*
|
||||
*/
|
||||
|
||||
#define ubi_dlNewList( L ) ubi_dlList (L)[1] = {{ NULL, NULL, 0 }}
|
||||
|
||||
#define ubi_dlCount( L ) (((ubi_dlListPtr)(L))->count)
|
||||
|
||||
#define ubi_dlAddHead( L, N ) \
|
||||
ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL )
|
||||
|
||||
#define ubi_dlAddNext( L, N, A ) \
|
||||
ubi_dlInsert( (ubi_dlListPtr)(L), \
|
||||
(ubi_dlNodePtr)(N), \
|
||||
(ubi_dlNodePtr)(A) )
|
||||
|
||||
#define ubi_dlAddTail( L, N ) \
|
||||
ubi_dlInsert( (ubi_dlListPtr)(L), \
|
||||
(ubi_dlNodePtr)(N), \
|
||||
(((ubi_dlListPtr)(L))->Tail) )
|
||||
|
||||
#define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
|
||||
(((ubi_dlListPtr)(L))->Head) )
|
||||
|
||||
#define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \
|
||||
(ubi_dlNodePtr)(N) )
|
||||
|
||||
#define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
|
||||
(((ubi_dlListPtr)(L))->Tail) )
|
||||
|
||||
#define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head)
|
||||
|
||||
#define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail)
|
||||
|
||||
#define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next)
|
||||
|
||||
#define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev)
|
||||
|
||||
#define ubi_dlPush ubi_dlAddHead
|
||||
#define ubi_dlPop ubi_dlRemHead
|
||||
#define ubi_dlEnqueue ubi_dlAddTail
|
||||
#define ubi_dlDequeue ubi_dlRemHead
|
||||
|
||||
/* ========================================================================== **
|
||||
* Function prototypes...
|
||||
*/
|
||||
|
||||
ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Initialize a doubly-linked list header.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list structure that is to be
|
||||
* initialized for use.
|
||||
*
|
||||
* Output: A pointer to the initialized list header (i.e., same as
|
||||
* <ListPtr>).
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
|
||||
ubi_dlNodePtr New,
|
||||
ubi_dlNodePtr After );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Insert a new node into the list.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list into which the node is to
|
||||
* be inserted.
|
||||
* New - Pointer to the new node.
|
||||
* After - NULL, or a pointer to a node that is already in the
|
||||
* list.
|
||||
* If NULL, then <New> will be added at the head of the
|
||||
* list, else it will be added following <After>.
|
||||
*
|
||||
* Output: A pointer to the node that was inserted into the list (i.e.,
|
||||
* the same as <New>).
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Remove a node from the list.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list from which <Old> is to be
|
||||
* removed.
|
||||
* Old - A pointer to the node that is to be removed from the
|
||||
* list.
|
||||
*
|
||||
* Output: A pointer to the node that was removed (i.e., <Old>).
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
/* ================================ The End ================================= */
|
||||
#endif /* UBI_DLINKLIST_H */
|
@ -1,248 +0,0 @@
|
||||
#ifndef UBI_SLINKLIST_H
|
||||
#define UBI_SLINKLIST_H
|
||||
/* ========================================================================== **
|
||||
* ubi_sLinkList.h
|
||||
*
|
||||
* Copyright (C) 1997, 1998 by Christopher R. Hertel
|
||||
*
|
||||
* Email: crh@ubiqx.mn.org
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This module implements a simple singly-linked list.
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
* Log: ubi_sLinkList.h,v
|
||||
* Revision 0.9 1998/07/24 07:30:20 crh
|
||||
* Added the ubi_slNewList() macro.
|
||||
*
|
||||
* Revision 0.8 1998/06/04 21:29:27 crh
|
||||
* Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
|
||||
* This is more "standard", and is what people expect. Weird, eh?
|
||||
*
|
||||
* Revision 0.7 1998/06/03 18:06:03 crh
|
||||
* Further fiddling with sys_include.h, which has been moved from the .c file
|
||||
* to the .h file.
|
||||
*
|
||||
* Revision 0.6 1998/06/02 01:38:47 crh
|
||||
* Changed include file name from ubi_null.h to sys_include.h to make it
|
||||
* more generic.
|
||||
*
|
||||
* Revision 0.5 1998/05/20 04:38:05 crh
|
||||
* The C file now includes ubi_null.h. See ubi_null.h for more info.
|
||||
*
|
||||
* Revision 0.4 1998/03/10 02:22:39 crh
|
||||
* Combined ubi_StackQueue and ubi_sLinkList into one module. Redesigned
|
||||
* the functions and macros. Not a complete rewrite but close to it.
|
||||
*
|
||||
* Revision 0.3 1998/01/03 02:00:02 crh
|
||||
* Added ubi_slCount() macro.
|
||||
*
|
||||
* Revision 0.2 1997/10/21 03:36:14 crh
|
||||
* Added parameter <After> in function Insert(). Made necessary changes
|
||||
* to macro AddHead() and added macro AddHere().
|
||||
*
|
||||
* Revision 0.1 1997/10/16 02:54:08 crh
|
||||
* Initial Revision.
|
||||
*
|
||||
* -------------------------------------------------------------------------- **
|
||||
* This module implements a singly-linked list which may also be used as a
|
||||
* queue or a stack. For a queue, entries are added at the tail and removed
|
||||
* from the head of the list. For a stack, the entries are entered and
|
||||
* removed from the head of the list. A traversal of the list will always
|
||||
* start at the head of the list and proceed toward the tail. This is all
|
||||
* mind-numbingly simple, but I'm surprised by the number of programs out
|
||||
* there which re-implement this a dozen or so times.
|
||||
*
|
||||
* Note: When the list header is initialized, the Tail pointer is set to
|
||||
* point to the Head pointer. This simplifies things a great deal,
|
||||
* except that you can't initialize a stack or queue by simply
|
||||
* zeroing it out. One sure way to initialize the header is to call
|
||||
* ubi_slInit(). Another option would be something like this:
|
||||
*
|
||||
* ubi_slNewList( MyList );
|
||||
*
|
||||
* Which translates to:
|
||||
*
|
||||
* ubi_slList MyList[1] = { NULL, (ubi_slNodePtr)MyList, 0 };
|
||||
*
|
||||
* See ubi_slInit(), ubi_slNewList(), and the ubi_slList structure
|
||||
* for more info.
|
||||
*
|
||||
* + Also, note that this module is similar to the ubi_dLinkList
|
||||
* module. There are three key differences:
|
||||
* - This is a singly-linked list, the other is a doubly-linked
|
||||
* list.
|
||||
* - In this module, if the list is empty, the tail pointer will
|
||||
* point back to the head of the list as described above. This
|
||||
* is not done in ubi_dLinkList.
|
||||
* - The ubi_slRemove() function, by necessity, removed the 'next'
|
||||
* node. In ubi_dLinkList, the ubi_dlRemove() function removes
|
||||
* the 'current' node.
|
||||
*
|
||||
* ========================================================================== **
|
||||
*/
|
||||
|
||||
#include "sys_include.h" /* System-specific includes. */
|
||||
|
||||
/* ========================================================================== **
|
||||
* Typedefs...
|
||||
*
|
||||
* ubi_slNode - This is the basic node structure.
|
||||
* ubi_slNodePtr - Pointer to a node.
|
||||
* ubi_slList - This is the list header structure.
|
||||
* ubi_slListPtr - Pointer to a List (i.e., a list header structure).
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct ubi_slListNode
|
||||
{
|
||||
struct ubi_slListNode *Next;
|
||||
} ubi_slNode;
|
||||
|
||||
typedef ubi_slNode *ubi_slNodePtr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ubi_slNodePtr Head;
|
||||
ubi_slNodePtr Tail;
|
||||
unsigned long count;
|
||||
} ubi_slList;
|
||||
|
||||
typedef ubi_slList *ubi_slListPtr;
|
||||
|
||||
|
||||
/* ========================================================================== **
|
||||
* Macros...
|
||||
*
|
||||
* ubi_slNewList - Macro used to declare and initialize a list header in
|
||||
* one step.
|
||||
*
|
||||
* ubi_slCount - Returns the current number of entries in the list.
|
||||
*
|
||||
* ubi_slAddHead - Add a new node at the head of the list.
|
||||
* ubi_slAddNext - Add a new node following the indicated node.
|
||||
* ubi_slAddTail - Add a new node to the tail of the list.
|
||||
* Note: AddTail evaluates the L parameter twice.
|
||||
*
|
||||
* ubi_slRemHead - Remove the node at the head of the list, if any.
|
||||
* ubi_slRemNext - Remove the node following the given node.
|
||||
*
|
||||
* ubi_slFirst - Return a pointer to the first node in the list, if any.
|
||||
* ubi_slNext - Given a node, return a pointer to the next node.
|
||||
* ubi_slLast - Return a pointer to the last node in the list, if any.
|
||||
*
|
||||
* ubi_slPush - Add a node at the head of the list (synonym of AddHead).
|
||||
* ubi_slPop - Remove a node at the head of the list (synonym of RemHead).
|
||||
* ubi_slEnqueue - Add a node at the tail of the list (sysnonym of AddTail).
|
||||
* ubi_slDequeue - Remove a node at the head of the list (synonym of RemHead).
|
||||
*
|
||||
* Note that all of these provide type casting of the parameters. The
|
||||
* Add and Rem macros are nothing more than nice front-ends to the
|
||||
* Insert and Remove functions.
|
||||
*
|
||||
* Also note that the First, Next and Last macros do no parameter checking!
|
||||
*
|
||||
*/
|
||||
|
||||
#define ubi_slNewList( L ) ubi_slList (L)[1] = {{ NULL, (ubi_slNodePtr)(L), 0 }}
|
||||
|
||||
#define ubi_slCount( L ) (((ubi_slListPtr)(L))->count)
|
||||
|
||||
#define ubi_slAddHead( L, N ) \
|
||||
ubi_slInsert( (ubi_slListPtr)(L), (ubi_slNodePtr)(N), NULL )
|
||||
|
||||
#define ubi_slAddNext( L, N, A ) \
|
||||
ubi_slInsert( (ubi_slListPtr)(L), \
|
||||
(ubi_slNodePtr)(N), \
|
||||
(ubi_slNodePtr)(A) )
|
||||
|
||||
#define ubi_slAddTail( L, N ) \
|
||||
ubi_slInsert( (ubi_slListPtr)(L), \
|
||||
(ubi_slNodePtr)(N), \
|
||||
((ubi_slListPtr)(L))->Tail )
|
||||
|
||||
#define ubi_slRemHead( L ) ubi_slRemove( (ubi_slListPtr)(L), NULL )
|
||||
|
||||
#define ubi_slRemNext( L, N ) \
|
||||
ubi_slRemove( (ubi_slListPtr)(L), (ubi_slNodePtr)(N) )
|
||||
|
||||
#define ubi_slFirst( L ) (((ubi_slListPtr)(L))->Head)
|
||||
|
||||
#define ubi_slNext( N ) (((ubi_slNodePtr)(N))->Next)
|
||||
|
||||
#define ubi_slLast( L ) (((ubi_slListPtr)(L))->Tail)
|
||||
|
||||
#define ubi_slPush ubi_slAddHead
|
||||
#define ubi_slPop ubi_slRemHead
|
||||
#define ubi_slEnqueue ubi_slAddTail
|
||||
#define ubi_slDequeue ubi_slRemHead
|
||||
|
||||
/* ========================================================================== **
|
||||
* Function prototypes...
|
||||
*/
|
||||
|
||||
ubi_slListPtr ubi_slInitList( ubi_slListPtr ListPtr );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Initialize a singly-linked list header.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list structure that is to be
|
||||
* initialized for use.
|
||||
*
|
||||
* Output: A pointer to the initialized list header (i.e., same as
|
||||
* <ListPtr>).
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_slNodePtr ubi_slInsert( ubi_slListPtr ListPtr,
|
||||
ubi_slNodePtr New,
|
||||
ubi_slNodePtr After );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Add a node to the list.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list into which the node is to
|
||||
* be inserted.
|
||||
* New - Pointer to the node that is to be added to the list.
|
||||
* After - Pointer to a list in a node after which the new node
|
||||
* will be inserted. If NULL, then the new node will
|
||||
* be added at the head of the list.
|
||||
*
|
||||
* Output: A pointer to the node that was inserted into the list (i.e.,
|
||||
* the same as <New>).
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
ubi_slNodePtr ubi_slRemove( ubi_slListPtr ListPtr, ubi_slNodePtr After );
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Remove the node followng <After>. If <After> is NULL, remove from the
|
||||
* head of the list.
|
||||
*
|
||||
* Input: ListPtr - A pointer to the list from which the node is to be
|
||||
* removed.
|
||||
* After - Pointer to the node preceeding the node to be
|
||||
* removed.
|
||||
*
|
||||
* Output: A pointer to the node that was removed, or NULL if the list is
|
||||
* empty.
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
|
||||
/* ================================ The End ================================= */
|
||||
#endif /* UBI_SLINKLIST_H */
|
Загрузка…
x
Ссылка в новой задаче
Block a user