tron1@tronsbox.xei.com (Kenneth Jamieson) (02/10/91)
X_List is a library of doubly linked list routines in C and C++. C++ is fully supported with classes and overloaded [] operators. This source has makefiles for Amiga, DOS, SYSV and SUNOS and Berkley. It is VERY portable. In addition, there is a tutorial on lists and an example. Submitted by: tron1@tronsbox Archive-name: X_List/part01 ---- Cut Here and unpack ---- #!/bin/sh # This is X_List, a shell archive (shar 3.10) # made 02/10/1991 02:43 UTC by tron1@tronsbox # Source directory /u1/home/tron1/src/tron1/shareware # # existing files WILL be overwritten # # This is part 1 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 0 -rw-r----- lib/foo # 0 -rw-r----- include/foo # 234 -r--r----- x_list/src/copyr.h # 3101 -r--r----- x_list/src/make.cpp # 1359 -r--r----- x_list/src/make.sas # 1393 -r--r----- x_list/src/make.tcc # 1453 -r--r----- x_list/src/make.unx # 3480 -r--r----- x_list/src/sharew.h # 9151 -r--r----- x_list/src/testit.c # 9468 -r--r----- x_list/src/x_list.c # 3423 -r--r----- x_list/src/x_list.h # 3602 -rw-r----- x_list/distrib # 10905 -rw-r----- x_list/docs # 5022 -rw-r----- x_list/install # 2856 -rw-r----- x_list/readme # 9972 -rw-r----- x_list/lists # touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$ if [ -s /tmp/s3_touch$$ ] then TOUCH=can else TOUCH=cannot fi rm -f /tmp/s3_touch$$ if test -r s3_seq_.tmp then echo "Must unpack archives in sequence!" next=`cat s3_seq_.tmp`; echo "Please unpack part $next next" exit 1; fi # ============= lib/foo ============== if test ! -d 'lib' ; then echo "x - creating directory lib" mkdir 'lib' fi echo "x - extracting lib/foo (Binary)" sed 's/^X//' << 'SHAR_EOF' > s3_temp_.tmp && Xbegin 600 lib/foo X` Xend SHAR_EOF echo "uudecoding file lib/foo" uudecode < s3_temp_.tmp && rm -f s3_temp_.tmp && chmod 0640 lib/foo || echo "restore of lib/foo fails" if [ $TOUCH = can ] then touch -am 0209185491 lib/foo fi set `wc -c lib/foo`;Wc_c=$1 if test "$Wc_c" != "0" then echo original size 0, current size $Wc_c;fi # ============= include/foo ============== if test ! -d 'include' ; then echo "x - creating directory include" mkdir 'include' fi echo "x - extracting include/foo (Binary)" sed 's/^X//' << 'SHAR_EOF' > s3_temp_.tmp && Xbegin 600 include/foo X` Xend SHAR_EOF echo "uudecoding file include/foo" uudecode < s3_temp_.tmp && rm -f s3_temp_.tmp && chmod 0640 include/foo || echo "restore of include/foo fails" if [ $TOUCH = can ] then touch -am 0209185391 include/foo fi set `wc -c include/foo`;Wc_c=$1 if test "$Wc_c" != "0" then echo original size 0, current size $Wc_c;fi # ============= x_list/src/copyr.h ============== if test ! -d 'x_list' ; then echo "x - creating directory x_list" mkdir 'x_list' fi if test ! -d 'x_list/src' ; then echo "x - creating directory x_list/src" mkdir 'x_list/src' fi echo "x - extracting x_list/src/copyr.h (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/copyr.h && X/* X Copyright include notice : copyr.h 1.2 2/9/91 X*/ X X/* XAll text in this file is copyright (c) 1991 by Kenneth Jamieson X*/ X#ifndef X_COPYRIGHT X#define X_COPYRIGHT "Compiled from source (c) 1991 Kenneth Jamieson" X#endif SHAR_EOF chmod 0440 x_list/src/copyr.h || echo "restore of x_list/src/copyr.h fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/copyr.h fi set `wc -c x_list/src/copyr.h`;Wc_c=$1 if test "$Wc_c" != "234" then echo original size 234, current size $Wc_c;fi # ============= x_list/src/make.cpp ============== echo "x - extracting x_list/src/make.cpp (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/make.cpp && X# Amiga "C++" Makefile for the x_list library X# X# Amiga "C++" Makefile for x_list functions. make.cpp 1.2 2/9/91 X# X# Set the CC variable to any compiler that can take ANSI C XCC=lc X# Set the CPP variable to the C++ pre-processor XCPP=cpp X# Set the CFRONT variable to the C++ to C translator XCFRONT=cfront X X# Set any other flags you want the C compiler to honor XCFLAGS=-O -i//include -i/src -i/include -dNULL=0 -c+ X X# Set any other flags you want the CPP to honor XCPPFLAGS= -i//include -i/src -i/include -iCPINCLUDE: -iINCLUDE: -dNULL=0 X X# The command that is used to make an archive XARCHIVE=oml X X# Un-comment this if you DO want to build the C++ routines as well XBUILD_CPP=-dIS_CPP X Xall: x_list.lib testit X @echo " " X @echo "=======================================================" X @echo "= Done building x_list list manager system... =" X @echo "= Run the program 'testit' to see if it works. =" X @echo "= Remember to type 'lmk install' if all went well. =" X @echo "= Then you can 'lmk clean' to get rid of temp files. =" X @echo "= - - - - - - - - - - - - - - - - - - - - - - - - - - =" X @echo "= Please don't forget that this is is shareware! =" X @echo "=======================================================" X @echo " " X Xinstall: X copy x_list.lib //lib X copy x_list.h //include X Xx_list.lib: _x_list.o X $(ARCHIVE) x_list.lib r _x_list.o X X_x_list.o: x_list.cp x_list.h X @echo " " X @echo "=======================================================" X @echo "= We have to take the long way around for this... =" X @echo "= the 'cc' command alone did not give enough control. =" X @echo "= Please ignore the warnings, they are ok. =" X @echo "= They ONLY show up under C++, and ONLY on the Amiga! =" X @echo "= I suspect it is a C++ bug in Lattice. =" X @echo "=======================================================" X @echo " " X -delete x_list.p X $(CPP) <x_list.cp >x_list.p $(CPPFLAGS) $(BUILD_CPP) X $(CFRONT) <x_list.p >_x_list.c +L X $(CC) $(CFLAGS) $(BUILD_CPP) _x_list.c X Xtestit: testit.cp x_list.lib x_list.h X @echo " " X @echo "=======================================================" X @echo "= We have to take the long way around for this... =" X @echo "= the 'cc' command alone did not give enough control. =" X @echo "= Please ignore the warnings, they are ok. =" X @echo "= They ONLY show up under C++, and ONLY on the Amiga! =" X @echo "= I suspect it is a C++ bug in Lattice. =" X @echo "=======================================================" X @echo " " X -delete testit.p X $(CPP) <testit.cp >testit.p $(CPPFLAGS) $(BUILD_CPP) X $(CFRONT) <testit.p >_testit.c +L X $(CC) $(CFLAGS) $(BUILD_CPP) -L+LIB:CPLUS.lib+x_list.lib _testit.c X rename _testit testit X rename _testit.info testit.info X Xx_list.cp: x_list.c X copy x_list.c x_list.cp X Xtestit.cp: testit.c X copy testit.c testit.cp X Xclean: X -delete _x_list.o X -delete _testit.o X -delete _x_list.c X -delete x_list.p X -delete testit.p X -delete x_list.cp X -delete testit.cp X -delete x_list.lib X -delete testit X -delete testit.info X -delete _testit.lnk X -delete _testit.c SHAR_EOF chmod 0440 x_list/src/make.cpp || echo "restore of x_list/src/make.cpp fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/make.cpp fi set `wc -c x_list/src/make.cpp`;Wc_c=$1 if test "$Wc_c" != "3101" then echo original size 3101, current size $Wc_c;fi # ============= x_list/src/make.sas ============== echo "x - extracting x_list/src/make.sas (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/make.sas && X# Amiga "C" Makefile for the x_list library X# X# Amiga "C" Makefile for x_list functions. make.sas 1.2 2/9/91 X# X# Set the CC variable to any compiler that can take ANSI C XCC=lc X X# Set any other flags you want the compiler to honor XCFLAGS=-O -i//include -i/src -i/include X X# The command that is used to make an archive XARCHIVE=oml X X# Un-comment this if you DO NOT want to build the C++ routines as well X#BUILD_CPP= X Xall: x_list.lib testit X @echo " " X @echo "=======================================================" X @echo "= Done building x_list list manager system... =" X @echo "= Run the program 'testit' to see if it works. =" X @echo "= Remember to type 'lmk install' if all went well. =" X @echo "= Then you can 'lmk clean' to get rid of temp files. =" X @echo "= - - - - - - - - - - - - - - - - - - - - - - - - - - =" X @echo "= Please don't forget that this is is shareware! =" X @echo "=======================================================" X @echo " " X Xinstall: X copy x_list.lib //lib X copy x_list.h //include X Xx_list.lib: x_list.o X $(ARCHIVE) x_list.lib r x_list.o X Xx_list.o: x_list.c x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) x_list.c X Xtestit: testit.c x_list.lib x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) -L+x_list.lib testit.c X Xclean: X -delete x_list.o X -delete x_list.lib X -delete testit.o X -delete testit X -delete testit.lnk SHAR_EOF chmod 0440 x_list/src/make.sas || echo "restore of x_list/src/make.sas fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/make.sas fi set `wc -c x_list/src/make.sas`;Wc_c=$1 if test "$Wc_c" != "1359" then echo original size 1359, current size $Wc_c;fi # ============= x_list/src/make.tcc ============== echo "x - extracting x_list/src/make.tcc (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/make.tcc && X# Turbo C++ Makefile for the x_list library X# X# Turbo C++ Makefile for x_list functions. make.tcc 1.3 2/9/91 X# X# Set the CC variable to any compiler that can take ANSI C XCC=tcc.exe X# Set any other flags you want the compiler to honor XCFLAGS=-O -P -I. -Qx X# The command that is used to make an archive XARCHIVE=tlib X# Un-comment this if you want to build the C++ routines as well XBUILD_CPP=-DIS_CPP X# Un-comment this if you DO NOT want to build the C++ routines as well X#BUILD_CPP= Xall: x_list.lib testit.exe X @echo . X @echo ======================================================= X @echo = Done building x_list list manager system... = X @echo = Run the program 'testit' to see if it works. = X @echo = Remember to type 'make install' if all went well. = X @echo = Then you can 'make clean' to get rid of temp files. = X @echo = - - - - - - - - - - - - - - - - - - - - - - - - - - = X @echo = Please don't forget that this is is shareware! = X @echo ======================================================= X @echo . X Xinstall: X copy x_list.lib ..\..\lib X copy *.h ..\..\include X Xx_list.lib: x_list.obj X $(ARCHIVE) x_list.lib +x_list.obj X Xx_list.obj: x_list.c x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) -c x_list.c X Xtestit.exe: testit.c x_list.lib x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) testit.c x_list.lib X Xclean: X del x_list.obj X del testit.obj X del x_list.lib X del testit.exe X SHAR_EOF chmod 0440 x_list/src/make.tcc || echo "restore of x_list/src/make.tcc fails" if [ $TOUCH = can ] then touch -am 0209205991 x_list/src/make.tcc fi set `wc -c x_list/src/make.tcc`;Wc_c=$1 if test "$Wc_c" != "1393" then echo original size 1393, current size $Wc_c;fi # ============= x_list/src/make.unx ============== echo "x - extracting x_list/src/make.unx (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/make.unx && X# UNIX Makefile for the x_list library X# X# Unix Makefile for x_list functions. make.unx 1.2 2/9/91 X# X# Set the CC variable to any compiler that can take ANSI C XCC=CC X X# Set any other flags you want the compiler to honor XCFLAGS=-O -I.. -I. -I../include X X# The command that is used to make an archive XARCHIVE=ar -cr X X# Un-comment this if you want to build the C++ routines as well XBUILD_CPP=-DIS_CPP X# Un-comment this if you DO NOT want to build the C++ routines as well X#BUILD_CPP= X Xall: x_list.a testit X @echo " " X @echo "=======================================================" X @echo "= Done building x_list list manager system... =" X @echo "= Run the program 'testit' to see if it works. =" X @echo "= Remember to type 'make install' if all went well. =" X @echo "= Then you can 'make clean' to get rid of temp files. =" X @echo "= - - - - - - - - - - - - - - - - - - - - - - - - - - =" X @echo "= Please don't forget that this is is shareware! =" X @echo "=======================================================" X @echo " " X Xinstall: X cp x_list.a ../../lib X chmod 644 ../../lib/x_list.a X cp x_list.h ../../include X chmod 644 ../../include/x_list.h X Xx_list.a: x_list.o X $(ARCHIVE) x_list.a x_list.o X Xx_list.o: x_list.c x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) -c x_list.c X Xtestit: testit.c x_list.a x_list.h X $(CC) $(CFLAGS) $(BUILD_CPP) -o testit testit.c x_list.a X Xclean: X -rm x_list.o X -rm x_list.a X -rm testit.o X -rm testit SHAR_EOF chmod 0440 x_list/src/make.unx || echo "restore of x_list/src/make.unx fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/make.unx fi set `wc -c x_list/src/make.unx`;Wc_c=$1 if test "$Wc_c" != "1453" then echo original size 1453, current size $Wc_c;fi # ============= x_list/src/sharew.h ============== echo "x - extracting x_list/src/sharew.h (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/sharew.h && X/* X Shareware license document : sharew.h 1.1 2/3/91 X*/ X/* X XThis text in this file is copyright (c) 1991 by Kenneth Jamieson. X XThe author may be reached at the US MAIL address listed below, or Xby sending unix mail to ... X X tron1@tronsbox.xei.com or X ...!uunet!tronsbox.xei.com!tron1 or X yelling "Hey Ken!" if you happen to be close enough. X X XAll rights are reserved by Kenneth Jamieson. X XYou are granted permission to use this code under the following Xrestrictions: X XNOTE: All occurrences of the word "code" below will apply to X all files, text, program source code and documentation. X X1) This code cannot be used in any program that is to be distributed X to anyone other than that program's author without the X written permission of Kenneth Jamieson. This permission will be granted X under the terms of registration listed below. X X2) This code may be used for a trial period of thirty (30) days. X At that time, you mus either register the code as below or X discontinue it's use. X X3) UNDER NO CIRCUMSTANCES may this code (registered or not) be used or X distributed in any way that will prevent it's future distribution X under the terms of this license. X X This specifically includes (but is not limited to) any code that X is to be distributed under the terms of the Free Software X Foundation's General Public License. X X4) Kenneth Jamieson reserves all rights to this code. X X5) NO WARRANTY is given or implied as to the usefulness or correctness of X this code for any purpose at all, whether this code is registered or not. X X XREGISTRATION: X X You are encouraged to register this code no matter what you use it for, X but you MUST register this code if you need written permission under X the terms above for distribution or intend to use it after the X trial period expires. X X In order to register this code, just send $15 US to the author at the X address listed below. X X Kenneth Jamieson X P.o. Box 387 X Kearny NJ 07023 X USA X X Once registered you will receive permission to use this code in your own X programs under the following restrictions: X X 1) Your program or documentation must mention that this code is in use, X and provide your user with information about where to obtain this X code. This information must be provided as part of the initial X cost (if any) of your software. X X 2) If you distribute the source to your program, then the source X for this code must accompany your code complete and unaltered. X X 3) UNDER NO CIRCUMSTANCES may this code (registered or not) be used or X distributed in any way that will prevent it's future distribution X under the terms of this license except by Kenneth Jamieson. X X This specifically includes (but is not limited to) any code that X is to be distributed under the terms of the Free Software X Foundation's General Public License. X X 4) Kenneth Jamieson reserves all rights to this code. X X 5) NO WARRANTY is given or implied as to the usefulness or correctness of X this code for any purpose at all, whether this code is registered or not. X X In addition, you will get a list of any known bugs and work-arounds, X notice of the next update (if any), and at least one "thank you". X X X X----------------------------------------------------- X* UNIX is a trademark of AT&T X* Amiga is a trademark of Commodore Business Machines X* MS-DOS is a trademark of Microsoft Inc X X*/ SHAR_EOF chmod 0440 x_list/src/sharew.h || echo "restore of x_list/src/sharew.h fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/sharew.h fi set `wc -c x_list/src/sharew.h`;Wc_c=$1 if test "$Wc_c" != "3480" then echo original size 3480, current size $Wc_c;fi # ============= x_list/src/testit.c ============== echo "x - extracting x_list/src/testit.c (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/testit.c && X/* X X Doubly linked list test file : X X testit.c : testit.c 1.2 2/9/91 X X*/ X X/* X XThis text in this file is copyright (c) 1991 by Kenneth Jamieson. X XThe author may be reached at the US MAIL address listed below, or Xby sending unix mail to ... X X tron1@tronsbox.xei.com or X ...!uunet!tronsbox.xei.com!tron1 or X yelling "Hey Ken!" if you happen to be close enough. X X X SEE THE FILE "sharew.h" for details before you X use this code !!! X X*/ X X#include <copyr.h> X#include <x_list.h> X#include <stdio.h> X#include <stdlib.h> X X#ifndef IS_CPP X X/* Not C++ -- so test the regular C functions */ X Xint main(){ X struct x_list * test_xlist; X int loop; X int * foo; X X printf("\ntestit - a testing program for the x_list list\n"); X printf(" manager. testit.c testit.c 1.2 2/9/91 \n\n"); X X X /* Let's create the list that we will play with */ X test_xlist = init_xlist(); X if( test_xlist == NULL ){ X fprintf(stderr,"There is an error in the init_xlist() function!\n"); X return( FALSE ); X }else{ X printf("\nOk.... init_xlist() seems to be working ok!\n"); X } X X /* Let's set the user pointer just to play with ! */ X if( set_user_xlist( test_xlist, "User data test!" ) == FALSE ){ X fprintf(stderr,"Error in the set_user_xlist() function!\n"); X }else{ X printf("Ok.... set_user_xlist() seems to be working ok!\n"); X } X X /* Let's get the user pointer just to play with ! */ X if( get_user_xlist( test_xlist ) == NULL ){ X fprintf(stderr,"Error in the get_user_xlist() function!\n"); X return( FALSE ); X }else{ X printf("Ok.... get_user_xlist() seems to be working ok!\n"); X } X X /* Add 100 integers to the list just for fun ! */ X for( loop = 0; loop < 100; loop++ ){ X foo = (int *)malloc( sizeof(int) ); X if( foo == NULL ){ X fprintf(stderr,"Malloc error on test insert #%d !\n", loop); X return( FALSE ); X } X *foo = loop; X if( add_xlist( test_xlist, foo ) == FALSE ){ X fprintf(stderr,"add_xlist() error on test insert #%d !\n", loop); X return( FALSE ); X } X } X X /* Now .. see that the counter got set right! */ X if( get_count_xlist( test_xlist ) != 100 ){ X fprintf(stderr,"get_count_xlist() error! Said #%d, should be 100 !\n", X get_count_xlist( test_xlist ) ); X return( FALSE ); X }else{ X printf("Ok.... get_count_xlist() seams to be working ok!\n"); X } X X /* Now, reset the list to the end ! */ X if( tail_xlist( test_xlist ) == FALSE ){ X fprintf(stderr,"tail_xlist() error !\n", loop); X return( FALSE ); X }else{ X printf("Ok.... tail_xlist() seems to be working!\n"); X } X X /* Now, reset the list to the top ! */ X if( head_xlist( test_xlist ) == FALSE ){ X fprintf(stderr,"head_xlist() error !\n", loop); X return( FALSE ); X }else{ X printf("Ok.... head_xlist() seems to be working!\n"); X } X X /* Now, let's retrieve all that data and make sure that it is right ! */ X for( loop = 0; loop < 100; loop++ ){ X foo = (int *)get_xlist( test_xlist ); X if( foo == NULL ){ X fprintf(stderr,"get_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( *foo != loop ){ X fprintf(stderr,"get_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( get_nodenum_xlist( test_xlist ) != loop ){ X fprintf(stderr, X "get_nodenum_xlist() error on test retrieve #%d !\n", loop); X } X if( next_xlist( test_xlist ) == FALSE && loop != 99 ){ X fprintf(stderr,"next_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X } X X printf("Ok.... 100 retrieves went ok, next_xlist() is working fine !\n"); X X /* Now, let's retrieve all that data and make sure that it is right ! */ X for( loop = 99; loop > -1; loop-- ){ X foo = (int *)get_xlist( test_xlist ); X if( foo == NULL ){ X fprintf(stderr,"get_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( *foo != loop ){ X fprintf(stderr,"get_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( get_nodenum_xlist( test_xlist ) != loop ){ X fprintf(stderr, X "get_nodenum_xlist() error on test retrieve #%d !\n", loop); X } X if( prev_xlist( test_xlist ) == FALSE && loop != 0 ){ X fprintf(stderr,"prev_xlist() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X } X X printf("Ok.... 100 retrieves went ok, prev_xlist() is working fine !\n"); X X if( goto_xlist( test_xlist, 50 ) == FALSE ){ X fprintf(stderr,"goto_xlist() error !\n"); X return( FALSE ); X } X foo = (int *)get_xlist( test_xlist ); X if( foo == NULL ){ X fprintf(stderr, X "get_xlist() error on retrieve for goto_xlist() !\n"); X return( FALSE ); X } X if( *foo != 50 ){ X fprintf(stderr, X "get_xlist() error on retrieve for goto_xlist() !\n"); X return( FALSE ); X } X printf("Ok.... goto_xlist() seems to be working fine !\n"); X X if( get_nodenum_xlist( test_xlist ) != 50 ){ X fprintf(stderr, X "get_nodenum_xlist() error (does not match)! \n"); X return( FALSE ); X } X printf("Ok.... get_nodenum_xlist() seems to be working ok! \n"); X X X if( free_xlist( test_xlist ) == FALSE ){ X fprintf(stderr,"free_xlist() error !!! \n"); X return( FALSE ); X }else{ X printf("Ok.... free_xlist() seems to be working! \n"); X } X X printf("\nAll tests passed ! Congratulations !\n\n"); X return( TRUE ); X} X X#endif X X#ifdef IS_CPP X X/* C++ -- so test the C++ functions */ X Xint main(){ X X_List test_xlist; X int loop; X int * foo; X X printf("\ntestit - a testing program for the x_list list\n"); X printf(" manager (C++ version). testit.c testit.c 1.2 2/9/91\n\n"); X X /* Let's set the user pointer just to play with ! */ X if( test_xlist.set_user( "User data test!" ) == FALSE ){ X fprintf(stderr,"Error in the X_List.set_user() function!\n"); X }else{ X printf("Ok.... X_List.set_user() seems to be working ok!\n"); X } X X /* Let's get the user pointer just to play with ! */ X if( test_xlist.get_user() == NULL ){ X fprintf(stderr,"Error in the X_List.get_user() function!\n"); X return( FALSE ); X }else{ X printf("Ok.... X_List.get_user() seems to be working ok!\n"); X } X X /* Add 100 integers to the list just for fun ! */ X for( loop = 0; loop < 100; loop++ ){ X foo = (int *)malloc( sizeof(int) ); X if( foo == NULL ){ X fprintf(stderr,"Malloc error on test insert #%d !\n", loop); X return( FALSE ); X } X *foo = loop; X if( test_xlist.add( foo ) == FALSE ){ X fprintf(stderr,"X_List.add() error on test insert #%d !\n", loop); X return( FALSE ); X } X } X X /* Now .. see that the counter got set right! */ X if( test_xlist.count() != 100 ){ X fprintf(stderr,"X_List.count() error! Said #%d, should be 100 !\n", X test_xlist.count() ); X return( FALSE ); X }else{ X printf("Ok.... X_List.count() seams to be working ok!\n"); X } X X /* Now, reset the list to the top ! */ X if( test_xlist.head() == FALSE ){ X fprintf(stderr,"X_List.head() error !\n", loop); X return( FALSE ); X }else{ X printf("Ok.... X_List.head() seems to be working!\n"); X } X X /* Now, let's retrieve all that data and make sure that it is right ! */ X for( loop = 0; loop < 100; loop++ ){ X foo = (int *)test_xlist.get(); X if( foo == NULL ){ X fprintf(stderr,"X_List.get() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( *foo != loop ){ X fprintf(stderr,"X_List.get() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( test_xlist.next() == FALSE && loop != 99 ){ X fprintf(stderr,"X_List.next() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X } X X printf("Ok.... 100 retrieves went ok, X_List.next() is working fine !\n"); X X /* Now, let's retrieve all that data and make sure that it is right ! */ X for( loop = 99; loop > -1; loop-- ){ X foo = (int *)test_xlist.get(); X if( foo == NULL ){ X fprintf(stderr,"X_List.get() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( *foo != loop ){ X fprintf(stderr,"X_List.get() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X if( test_xlist.prev() == FALSE && loop != 0 ){ X fprintf(stderr,"X_List.prev() error on test retrieve #%d !\n", loop); X return( FALSE ); X } X } X X printf("Ok.... 100 retrieves went ok, X_List.prev() is working fine !\n"); X X /* Now, let's retrieve it with the [] operator ! */ X for( loop = 99; loop > -1; loop-- ){ X foo = (int *)test_xlist[loop]; X if( foo == NULL ){ X fprintf(stderr,"X_List operator [] error on #%d !\n", loop); X return( FALSE ); X } X if( *foo != loop ){ X fprintf(stderr,"X_List operator [] error on #%d !\n", loop); X return( FALSE ); X } X if( test_xlist.nodenum() != loop ){ X fprintf(stderr,"X_List.nodenum() error on #%d!\n", loop); X } X } X printf("Ok.... X_List.goto_node() seems to work ok!\n"); X printf("Ok.... X_List.nodenum() seems to work ok!\n"); X printf("Ok.... the operator [] seems to work ok!\n"); X X printf("\nAll tests passed ! Congratulations !\n\n"); X return( TRUE ); X} X X#endif X X SHAR_EOF chmod 0440 x_list/src/testit.c || echo "restore of x_list/src/testit.c fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/testit.c fi set `wc -c x_list/src/testit.c`;Wc_c=$1 if test "$Wc_c" != "9151" then echo original size 9151, current size $Wc_c;fi # ============= x_list/src/x_list.c ============== echo "x - extracting x_list/src/x_list.c (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/x_list.c && X/* X X Doubly linked list function file : X X x_list.c : x_list.c 1.2 2/9/91 X X*/ X X/* X XThis text in this file is copyright (c) 1991 by Kenneth Jamieson. X XThe author may be reached at the US MAIL address listed below, or Xby sending unix mail to ... X X tron1@tronsbox.xei.com or X ...!uunet!tronsbox.xei.com!tron1 or X yelling "Hey Ken!" if you happen to be close enough. X X X SEE THE FILE "sharew.h" for details before you X use this code !!! X X*/ X X X#include <copyr.h> X#include <sharew.h> X#include <x_list.h> X#include <stdlib.h> X Xstruct x_list_entry * init_xlist_entry(){ X struct x_list_entry * foo; X foo = (struct x_list_entry *)malloc( sizeof(struct x_list_entry) ); X if( foo == NULL ){ X return( foo ); X } X foo->data = NULL; X foo->prev = NULL; X foo->next = NULL; X X return( foo ); X} X Xstruct x_list * init_xlist(){ X struct x_list * foo; X foo = (struct x_list *)malloc( sizeof(struct x_list) ); X if( foo == NULL ){ X return( foo ); X } X foo->data = NULL; X foo->first = NULL; X foo->current = NULL; X foo->last = NULL; X foo->count = 0; X foo->node = 0; X X return( foo ); X} X Xint add_xlist( struct x_list * xlist, void * new_data ){ X if( xlist == NULL ){ X return( (int)FALSE ); X } X if( xlist->first == NULL ){ /* Is this the first entry ??? */ X xlist->first = init_xlist_entry(); /* Create a entry to add to list */ X if( xlist->first == NULL ){ X return( (int)FALSE ); /* If we can't, fail */ X } X xlist->first->data = new_data; /* Set the data pointer for the user */ X xlist->current = xlist->first; /* The first item is the current one!*/ X xlist->last = xlist->first; /* It is also the last !! */ X xlist->count = 1; /* There is one item in the list */ X xlist->node = 0; /* Just to be sure ! */ X return( (int)TRUE ); X } X X xlist->last->next = init_xlist_entry(); /* Add a new node at end of list */ X if( xlist->first == NULL ){ X return( (int)FALSE ); /* If we can't, fail */ X } X xlist->last->next->prev = xlist->last; /* Set parent of new node */ X xlist->last->next->data = new_data; /* Set data of new node */ X xlist->last = xlist->last->next; /* Set pointer to last node*/ X xlist->current = xlist->last; /* Set the current pointer */ X xlist->count = xlist->count+1; /* Set the counter */ X xlist->node = xlist->count - 1; /* Hehehehe */ X return( (int)TRUE ); X} X Xvoid * get_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ X return( NULL ); /* if list pointer is bad */ X } X if( xlist->current == NULL ){ X return( NULL ); /* if list is empty */ X } X return( xlist->current->data ); /* Return the data */ X} X Xint head_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->first == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X xlist->current = xlist->first; /* reset the current pointer*/ X xlist->node = 0; /* Reset node number */ X return( (int)TRUE ); X} X Xint put_xlist( struct x_list * xlist, void * new_data ){ X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->current == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X xlist->current->data = new_data; /* replace the data */ X return( (int)TRUE ); X} X Xint del_xlist( struct x_list * xlist ){ X struct x_list_entry * foo; X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->current == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X foo = xlist->current; X if( foo->prev != NULL ){ /* Is this the head ? */ X foo->prev->next = foo->next; /* Set the child of our parent to pur child */ X }else{ X xlist->first = foo->next; /* We are the head, reset first when we go */ X } X if( foo->next != NULL ){ /* Are we the tail ? */ X foo->next->prev = foo->prev; /* Set childs parent to our parent */ X xlist->current = foo->next; /* Set the current to our child */ X }else{ X xlist->current = foo->prev; /* Set current to parent if no child*/ X xlist->last = foo->next; /* Reset the last pointer */ X } X xlist->count = xlist->count -1; /* Decrement the counter */ X free((char *)foo); /* Free the data */ X return( (int)TRUE ); X} X Xint next_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->current == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X if( xlist->current->next == NULL ){ X return( (int)FALSE ); /* At end of list, can't advance */ X } X xlist->current = xlist->current->next; /* Advance current pointer */ X xlist->node = xlist->node + 1; X return( (int)TRUE ); X} X Xint prev_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->current == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X if( xlist->current->prev == NULL ){ X return( (int)FALSE ); /* If we are at the start */ X } X xlist->current = xlist->current->prev; /* Move the pointer back */ X xlist->node = xlist->node - 1; /* Decrement the node */ X return( (int)TRUE ); X} X Xint get_count_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ /* If the list pointer is bad */ X return( 0 ); X } X return( xlist->count ); /* Return the current count */ X} X Xint free_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ /* If the list pointer is bad */ X return( (int)FALSE ); X } X while( get_count_xlist( xlist ) != 0 ){ X del_xlist( xlist ); X } X free((char *) xlist ); X return( (int)TRUE ); X} X Xint set_user_xlist( struct x_list * xlist, void * data ){ X if( xlist == NULL ){ /* If the list pointer is bad */ X return( (int)FALSE ); X } X xlist->data = data; X return( (int)TRUE ); X} X Xvoid * get_user_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ /* If the list pointer is bad */ X return( (int)FALSE ); X } X return( xlist->data ); X} X Xint tail_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ X return( (int)FALSE ); /* if list pointer is bad */ X } X if( xlist->last == NULL ){ X return( (int)FALSE ); /* if list is empty */ X } X xlist->current = xlist->last; /* reset the current pointer*/ X xlist->node = xlist->count - 1; /* Reset node number */ X return( (int)TRUE ); X} X Xint get_nodenum_xlist( struct x_list * xlist ){ X if( xlist == NULL ){ /* If the list pointer is bad */ X return( (int)FALSE ); X } X return( xlist->node ); X} X Xint goto_xlist( struct x_list * xlist, int target ){ X int count; X if( xlist == NULL ){ /* If the list pointer is bad */ X return( (int)FALSE ); X } X if( target < 0 ){ X return( (int)FALSE ); X } X count = get_count_xlist( xlist ); X if( target > count ){ X return( (int)FALSE ); X } X count = get_nodenum_xlist( xlist ); /* Re-use the count integer */ X if( target > count ){ X while( target > get_nodenum_xlist( xlist ) ){ X if( next_xlist( xlist ) == FALSE ){ X return( (int)FALSE ); /* Error ? */ X } X } X return( (int)TRUE ); X } X if( target < count ){ X while( target < get_nodenum_xlist( xlist ) ){ X if( prev_xlist( xlist ) == FALSE ){ X return( (int)FALSE ); /* Error ? */ X } X } X return( (int)TRUE ); X } X if( target == count ){ X return( (int)TRUE ); /* Error ? */ X } X return( (int)FALSE ); /* No idea what happened! */ X /* I mean, if it is not > < or = ! */ X} X X#ifdef IS_CPP X XX_List::X_List(){ X list = init_xlist(); X} X XX_List::X_List( void * name ){ X list = init_xlist(); X set_user( name ); X} X Xint X_List::add( void * data ){ X return( add_xlist( list, data ) ); X} X Xvoid * X_List::get(){ X return( get_xlist( list ) ); X} X Xint X_List::head(){ X return( head_xlist( list ) ); X} X Xint X_List::tail(){ X return( tail_xlist( list ) ); X} X Xint X_List::put( void * data ){ X return( put_xlist( list, data ) ); X} X Xint X_List::del(){ X return( del_xlist( list ) ); X} X Xint X_List::next(){ X return( next_xlist( list ) ); X} X Xint X_List::prev(){ X return( prev_xlist( list ) ); X} X Xint X_List::count(){ X return( get_count_xlist( list ) ); X} X Xint X_List::set_user( void * name ){ X return( set_user_xlist( list, name ) ); X} X Xvoid * X_List::get_user(){ X return( get_user_xlist( list ) ); X} X Xint X_List::nodenum(){ X return( (int)get_nodenum_xlist( list ) ); X} X Xint X_List::goto_node( int target ){ X return( goto_xlist( list, target ) ); X} X Xvoid * X_List::operator[]( int target ){ X if( this->goto_node( target ) == FALSE ){ X return( NULL ); X } X return( this->get() ); X} X XX_List::~X_List(){ X free_xlist( list ); X} X X X X#endif X X SHAR_EOF chmod 0440 x_list/src/x_list.c || echo "restore of x_list/src/x_list.c fails" if [ $TOUCH = can ] then touch -am 0209182491 x_list/src/x_list.c fi set `wc -c x_list/src/x_list.c`;Wc_c=$1 if test "$Wc_c" != "9468" then echo original size 9468, current size $Wc_c;fi # ============= x_list/src/x_list.h ============== echo "x - extracting x_list/src/x_list.h (Text)" sed 's/^X//' << 'SHAR_EOF' > x_list/src/x_list.h && X/* X X Doubly linked list header file : X X x_list.h : x_list.h 1.2 2/9/91 X X*/ X X/* X XThis text in this file is copyright (c) 1991 by Kenneth Jamieson. X XThe author may be reached at the US MAIL address listed below, or Xby sending unix mail to ... X X tron1@tronsbox.xei.com or X ...!uunet!tronsbox.xei.com!tron1 or X yelling "Hey Ken!" if you happen to be close enough. X X X SEE THE FILE "sharew.h" for details before you X use this code !!! X X*/ X X X X#ifndef _x_list_h /* To solve any double defined errors */ X#define _x_list_h X X#ifndef TRUE /* Just a standard define of mine */ X#define TRUE 1 X#endif X#ifndef FALSE /* Just a standard define of mine */ X#define FALSE 0 X#endif X X/* Below, we will define the structures we need for this code.... */ X Xstruct x_list_entry { /* Just a generic entry in out list */ X void * data; /* The data pointer to store */ X struct x_list_entry * prev; /* The pointer to the previous entry */ X struct x_list_entry * next; /* The pointer to the next entry */ X}; X Xstruct x_list { /* The header that will start every list */ X void * data; /* A user pointer so you can name it */ X struct x_list_entry * first; /* Pointer to the first entry in list */ X struct x_list_entry * current; /* Pointer to the current entry in list */ X struct x_list_entry * last; /* Pointer to the last entry in the list */ X int node; /* The number of the current node */ X int count; /* A count of the number of nodes in list*/ X}; X X Xstruct x_list_entry * init_xlist_entry(); X/* Create and init a new entry struct */ X Xstruct x_list * init_xlist(); X/* create and init a new list head */ X Xint add_xlist( struct x_list * xlist , void * new_data ); X/* Add a new data item to the list */ X Xvoid * get_xlist(struct x_list * xlist ); X/* Get the data pointer from current entry in the list */ X Xint head_xlist( struct x_list * xlist ); X/* Go to the top of the list */ X Xint put_xlist( struct x_list * xlist, void * new_data ); X/* Replace data for current node */ X Xint del_xlist( struct x_list * xlist ); X/* Kill the current item and re-weave the list */ X Xint next_xlist( struct x_list * xlist ); X/* Goto next node */ X Xint prev_xlist( struct x_list * xlist ); X/* Go to prev node */ X Xint get_count_xlist( struct x_list * xlist ); X/* get the counter */ X Xint free_xlist( struct x_list * xlist ); X/* Delete the entire list */ X Xint set_user_xlist( struct x_list * xlist, void * data ); X/* Set the user pointer for a xlist */ X Xvoid * get_user_xlist( struct x_list * xlist ); X/* Get the user pointer for a xlist */ X Xint tail_xlist( struct x_list * ); X/* Sets the current node to the last node in list */ X Xint goto_xlist( struct x_list * xlist, int target ); X/* Sets the current node to the target'th node in list if possible */ X Xint get_nodenum_xlist( struct x_list * xlist ); SHAR_EOF echo "End of X_List part 1" echo "File x_list/src/x_list.h is continued in part 2" echo "2" > s3_seq_.tmp exit 0 -- ========[ Xanadu Enterprises Inc. Amiga & Unix Software Development]======= = "I know how you feel, you don't know if you want to hit me or kiss me - = = --- I get a lot of that." Madonna as Breathless Mahoney (Dick Tracy) = =========== Ken Jamieson: uunet!tronsbox.xei.com!tron1 =================== = NONE of the opinions represented here are endorsed by anybody. = === The Romantic Encounters BBS 201-759-8450(PEP) / 201-759-8568(2400) ====