Home » Archimedes archive » Acorn User » AU 1998-09.adf » Regulars » StarInfo/Kingsley/LnkLstHelp
StarInfo/Kingsley/LnkLstHelp
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
| Tape/disk: | Home » Archimedes archive » Acorn User » AU 1998-09.adf » Regulars |
| Filename: | StarInfo/Kingsley/LnkLstHelp |
| Read OK: | ✔ |
| File size: | 3879 bytes |
| Load address: | 0000 |
| Exec address: | 0000 |
File contents
Linked List Library routine for Easy C/C++ programmers
------------------------------------------------------
Author : Nicholas Kingsley
Version : 1.01
Date : 1/3/98
1. Introduction
----------------
A Linked List is a list of node (allocated areas of memory) which are
connected to other nodes using pointers, so that one node pointers to another,
which (possibly) pointers to another.
This library routine implements Linked List using double pointers, so that a
node always points to the next node (if present), and the previous node (if
present). Using double pointers allows easy access to any node
by going backwards as well as forwards, without the need to always start at
the beginning.
The implementation is graphically like this :
+---------------+
| Control Block |
| (or root) | End
+---------------+ �
| | |
| +------> +------------+ +------+
| | First Node |->| Data |
| +------------+ +------+
| | �
| � |
| +------------+ +------+
| | A Node |->| Data |
| +------------+ +------+
| | �
| � |
+----------> +------------+ +------+
| Last Node |->| Data |
+------------+ +------+
|
�
End
The Control Block or root as it will be called from now on, is the heart of
the Linked List system, and like the nodes, should NEVER be modified without
using the library routines.
Unlike most linked-list routines, this version allows each data section to have
variable lengths. As long as as you don't overwrite any part of unallocated
memory, variable lengths pose no problems.
2. The functions
-----------------
Linked list functions come in different flavours :
A) Initialisation
B) Processing
C) Deleting
D) Modifying and getting user data
E) Counting
F) Status check
G) Renumbering
H) Sorting
I) Getting user data
3. Using the LinkList library
------------------------------
This library routine should work on all Acorn RISC machines from V3.10 upwards
The LinkList data file was only designed for Easy C/C++, and will probably not
work on Acorn's C/C++.
Just copy the LinkList data file into your EasyC/C++ Library directory
(!EasyC.Libraries, or !EasyC++.Libraries), and the header file into the h
directory.
Exit out of EasyC/C++, and go back in. Pressing the left button over the
C/C++ icon will bring up the compiler window. Press the middle button over
this window will bring up a list of options, one of which will be 'Libraries'.
Allow the computer to expand the libraries sub-window, and you should see a
list of library routines that EasyC/C++ use, including LinkList. Press the
left button to put a tick next to LinkList, which now will be used whenever
the LinkList header file is #included into your program.
The files you should have are :
A) LinkList/L - A DATA file, which should go in the library directory.
B) LinkList/H - A HEADER file, which should go in the h directory.
C) Types - A HEADER file, which also should go in the h
directory.
D) LnkLstHelp - This file
E) c.TestLink - A very short test program
F) TestLink - The executable test program (source is in the "c"
subdirectory)
A. Initialisation
------------------
There is only one initialisation command, called "createList". This creates a
unique root structure, and returns a LONG value. This value is needed to pass
to most routines.
It takes 22 parameters, both of type LONG : The first defines where memory is
claimed from - RMA uses the relocatable memory area, while DYNAMIC uses the
dynamic memory area (RISC OS V3.50+).
Each area has it's own advantages and disadvantages : The Dynamic area
allocates memory in blocks of 4096 bytes (this means that, for example the
root structure wastes around 4068 bytes!), but will not fragment. The RMA
allocates memory to the nearest word (possibly wasting less memory for small
items), but will fragment over time.
B. Processing
--------------
There are 4 processing commands :
GetDir, which takes two LONG parameters : The first is the address of the
current node, and the second expects two constants : NEXT (to get the next
node) or PREV (which gets the previous node)
GetFirstLast also takes two LONG parameters : The first is the address of the
root structure, and the second is either FIRST to get the first node, or LAST
to get the last node.
FindAIndexNode. This searches for a given node number, and returns it's
address if one has been found. It expects two parameters, both of type
LONG : The root address and the node number to look for. This number must
not be greater than the highest value currently used.
FindANumberNode. This will return nodes address after traversing through a
given number of nodes. It expects three parameters : The address of the
root, the number of nodes to go through, and the starting position (either
FIRST or LAST). All parameters are of type LONG.
C. Deleting
------------
There are 4 ways of deleting a Linked List :
deleteList deletes the COMPLETE list of memory, and expects the root value to
be passed to it. This should be of type LONG.
deleteCurrentNode deletes the given node, and expects two parameters - the
first is the root value, and the second is the current node address. Both
need to be of type LONG.
deleteNumberNode searches the list looking for the given node number, and if
found, deletes it. This expects two parameters of type LONG - the first is
the root address, and the second is the node number to search for. The node
number must be > 0 and less than the current highest node number so far.
deleteIndexNode traverses through the list (having started from the begining
or the end), and for each node decreases a given parameter. Once this has
reached zero, the node currently pointed to is deleted. It expects three
parameters of type LONG - the first is the root pointer, the second is the
index number, while the last is the movement direction (either FIRST or LAST)
D. Modifying and getting user data
-----------------------------------
There is one function that can get and modify user data. The function is
called getUserData and expects 6 parameters. The first 4, must be of type
LONG and are the root address, the current node address, the starting position
within the user data that you wish to start at and the number of bytes you
want to get or modify. The remaining two are of type char *, and is the
buffer in which all data is read from or written to, and of type int, which
accepts either GET_DATA (to read data into the buffer), or WRITE_DATA to start
writing data from the offset value.
The offset value starts from 0.
* WARNING : *
No check is made to see whether reading or writing starts or stays within the
data block size. If you get any error messages or strange things happning,
then check the values passed to this function.
E. Counting
------------
numberOfNodes (which expects a root parameter of type LONG) returns the number
of nodes in the link list (if any), otherwise it returns 0.
F. Status Check
----------------
The status check is sent to an open file, for example stdout (which sends
everything to the screen), and displays the integrity of the Control Block
followed by each of the nodes. If any warning messages appear you MAY NOT be
able to process or delete that Linked List properly, resulting in wasted
memory. You should check your program to make sure no headers and pointers
are modified.
If any problems are found, then the function will try to continue as long as
possible until either an error message is displayed or some end is found.
It takes two parameters : The root address as type LONG and a file pointer.
G. Renumbering
---------------
renumberNodes renumbers the Linked List in ascending order, removing any gaps
in the nodes number. This function takes one parameter of type LONG, which is
the root address.
H. Sorting
-----------
sortList goes through the Linked List, sorting each node is ascending order.
You must supply the compare function, which must compare the two given nodes
and return a value of 0 if both nodes are EXACTLY equal, 1 if the first node
is greater than the second, and -1 if the first node is less than the second.
This function expects two parameters - the root address (which is of type
LONG), is the name of your compare funtion.
Your compare function expects three parameters - the address of a node, the
address of the next node, and the address of the root. All these are of
type LONG.
4. The Structures
------------------
There are three structures that you will need to declare in your program at
certain times, in order to pass correct sizes and perhaps to store information
:
__CONTROLBLOCK - Header information
__ROOT - Root information
__NODE - Node information
__DATA - Initial data information
YOU MUST NEVER MODIFY ANY OF THESE STRUCTURES YOURSELF. ALWAYS USE ONE OF THE
LIBRARY FUNCTIONS IF SOME PART NEEDS TO CHANGE.
5. Constants
-------------
You should always use these constants where they are needed :
FIRST -
| - Position to start movement - either the first or last node
LAST -
LONG - A variable type
GET_DATA -
| - Either fetch data (GET_DATA) or store data (STORE_DATA)
STORE_DATA -
DYNAMIC -
| - Allocate memory from the RMA (RMA) or dynamic memory
| (DYNAMIC)
RMA -
NEXT -
| - Movement type - either get next node or get previous
PREV -
LNULL - Returned for most routines when the operation has failed.
__NODE_INVALID - Node header is invalid
__NODE_NODATA - Node doesn't contain a valid data pointer
__NODE_INFLOOP - Node points to itself
__DATA_INVALID - Data header is invalid
LNULL denotes failure, and any other value denotes success. This doesn't
apply for deleteList, which returns a value which is ignored.
6. Creating a Linked List
--------------------------
First you need the correct headers :
#include <Types.h>
#include <LinkList.h>
To create a Linked List, you first need to create a Root. You do this using :
LONG root=0;
root=createList(DYNAMIC,sizeof(__ROOT));
if (root==LNULL)
{
printf("\nCan't create a linked list");
return (1);
}
Most functions expect parameter of type LONG.
You then need to create an array (or preferably) a structure to hold your data
:
struct {
int count;
char text[6];
float total;
} example,sort;
And set up the array (or structure accordingly) :
example.count=145;
strcpy(example.text,"Test");
example.total=0.05;
And, if all is well, you can add the example structure into the Linked List :
if (addNode(FIRST,root,
(char *) &example,DYNAMIC,sizeof(example))==LNULL)
{
printf("Can't create a node!");
deleteList(root);
exit(1);
}
The FIRST constants tells the routine to add this node to the begining of the
list, as opposed to the end.
You can keep adding nodes until your blue in the face (or you run out of
memory!)...
To go through each node, you need to start either at the begining or the end :
node=getFirst(root);
or
node=getLast(root);
and then have a simple loop, like :
while (node!=LNULL)
{
<Do your processing here>
node=getDir(node,NEXT); /* or, node=getDir(node,PREV); */
}
To get information out, you need :
if (getUserData(root,node,0,sizeof(dummy),
(char *) &dummy,GET_DATA)==NULL)
{
printf("Can't get hold of user data");
return (1);
}
To sort a Linked List :
sortList(root,sortRoutine);
...
};
(Sort by total)
int sortRoutine(LONG n1,LONG n2,LONG root)
{
char bufferA[8],bufferB[8];
getUserData(root,n1,0,
sizeof(bufferA),(char *) &bufferA,GET_DATA);
getUserData(root,n2,0,
sizeof(bufferB),(char *) &bufferB,GET_DATA);
return (bufferA[5]==bufferB[5] ? 0 : \
bufferA[5]>bufferB[5] ? 1 : -1);
}
And finally, to delete the Linked List :
root=deleteList(root);
7. Full list of commands
-------------------------
The following is a full list of library commands. Those marked by a '*'
are for internal use only, and MUST NOT be used in your own programs.
LONG __allocMemory(LONG,LONG,LONG); (*)
LONG __deleteMemory(LONG); (*)
LONG __addNode(LONG,LONG,LONG,LONG); (*)
LONG __deleteNode(LONG,LONG,LONG,LONG); (*)
LONG __swapNodes(LONG,LONG,LONG); (*)
LONG getDir(LONG,LONG);
LONG getUserData(LONG root,LONG node,LONG offset,LONG size,
char *buffer,int type);
LONG createList(LONG,LONG);
LONG addNode(int where,LONG root,char *text,int type,LONG size);
LONG deleteList(LONG);
LONG deleteCurrentNode(LONG,LONG);
LONG deleteIndexNode(LONG,LONG);
LONG deleteNumberNode(LONG,LONG);
LONG renumberNodes(LONG);
void getStatus(FILE *handle,LONG root);
LONG getDir(LONG,LONG);
LONG getFirstLast(LONG,LONG);
LONG getUserData(LONG root,LONG node,LONG offset,LONG size,char *buffer,
int type);
LONG sortList(LONG root,
int (*routine) (LONG n1,LONG n2,LONG root));
LONG numberOfNodes(LONG);
LONG nodeInfo(LONG root,LONG node_addr,LONG number,FILE *handle);
LONG findANumberNode(LONG,LONG);
LONG findAIndexNode(LONG,LONG,LONG);
The Disclaimer
--------------
I accept no responsibility for any use or misuse this library routine is used
for. Whilst this program is FREEWARE, I retain full copyright over the source
code, library code and documentation.
You may not reverse engineer, modify, append to or remove from any part of
this library routine.
No Martians were harmed in the making of the library routine.
All people mentioned in this documentation are fictitious. Any resemblance to any
persons living, dead or visiting friends on Mars are purely coincidental.
(C) Nicholas J. Kingsley Bsc 1998
Please bug reports and comments to Nicholas Kingsley,
E-Mail address : nichk@argonet.co.uk
At this time no bugs are known to exist.
*** File ends *** 00000000 4c 69 6e 6b 65 64 20 4c 69 73 74 20 4c 69 62 72 |Linked List Libr|
00000010 61 72 79 20 72 6f 75 74 69 6e 65 20 66 6f 72 20 |ary routine for |
00000020 45 61 73 79 20 43 2f 43 2b 2b 20 70 72 6f 67 72 |Easy C/C++ progr|
00000030 61 6d 6d 65 72 73 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d |ammers.---------|
00000040 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------|
*
00000060 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 41 |-------------..A|
00000070 75 74 68 6f 72 20 20 3a 20 4e 69 63 68 6f 6c 61 |uthor : Nichola|
00000080 73 20 4b 69 6e 67 73 6c 65 79 0a 56 65 72 73 69 |s Kingsley.Versi|
00000090 6f 6e 20 3a 20 31 2e 30 31 0a 44 61 74 65 20 20 |on : 1.01.Date |
000000a0 20 20 3a 20 31 2f 33 2f 39 38 0a 0a 31 2e 20 20 | : 1/3/98..1. |
000000b0 49 6e 74 72 6f 64 75 63 74 69 6f 6e 0a 2d 2d 2d |Introduction.---|
000000c0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 41 |-------------..A|
000000d0 20 4c 69 6e 6b 65 64 20 4c 69 73 74 20 69 73 20 | Linked List is |
000000e0 61 20 6c 69 73 74 20 6f 66 20 6e 6f 64 65 20 28 |a list of node (|
000000f0 61 6c 6c 6f 63 61 74 65 64 20 61 72 65 61 73 20 |allocated areas |
00000100 6f 66 20 6d 65 6d 6f 72 79 29 20 77 68 69 63 68 |of memory) which|
00000110 20 61 72 65 0a 63 6f 6e 6e 65 63 74 65 64 20 74 | are.connected t|
00000120 6f 20 6f 74 68 65 72 20 6e 6f 64 65 73 20 75 73 |o other nodes us|
00000130 69 6e 67 20 70 6f 69 6e 74 65 72 73 2c 20 73 6f |ing pointers, so|
00000140 20 74 68 61 74 20 6f 6e 65 20 6e 6f 64 65 20 70 | that one node p|
00000150 6f 69 6e 74 65 72 73 20 74 6f 20 61 6e 6f 74 68 |ointers to anoth|
00000160 65 72 2c 0a 77 68 69 63 68 20 28 70 6f 73 73 69 |er,.which (possi|
00000170 62 6c 79 29 20 70 6f 69 6e 74 65 72 73 20 74 6f |bly) pointers to|
00000180 20 61 6e 6f 74 68 65 72 2e 0a 54 68 69 73 20 6c | another..This l|
00000190 69 62 72 61 72 79 20 72 6f 75 74 69 6e 65 20 69 |ibrary routine i|
000001a0 6d 70 6c 65 6d 65 6e 74 73 20 4c 69 6e 6b 65 64 |mplements Linked|
000001b0 20 4c 69 73 74 20 75 73 69 6e 67 20 64 6f 75 62 | List using doub|
000001c0 6c 65 20 70 6f 69 6e 74 65 72 73 2c 20 73 6f 20 |le pointers, so |
000001d0 74 68 61 74 20 61 0a 6e 6f 64 65 20 61 6c 77 61 |that a.node alwa|
000001e0 79 73 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 |ys points to the|
000001f0 20 6e 65 78 74 20 6e 6f 64 65 20 28 69 66 20 70 | next node (if p|
00000200 72 65 73 65 6e 74 29 2c 20 61 6e 64 20 74 68 65 |resent), and the|
00000210 20 70 72 65 76 69 6f 75 73 20 6e 6f 64 65 20 28 | previous node (|
00000220 69 66 0a 70 72 65 73 65 6e 74 29 2e 20 20 55 73 |if.present). Us|
00000230 69 6e 67 20 64 6f 75 62 6c 65 20 70 6f 69 6e 74 |ing double point|
00000240 65 72 73 20 61 6c 6c 6f 77 73 20 65 61 73 79 20 |ers allows easy |
00000250 61 63 63 65 73 73 20 74 6f 20 61 6e 79 20 6e 6f |access to any no|
00000260 64 65 0a 62 79 20 67 6f 69 6e 67 20 62 61 63 6b |de.by going back|
00000270 77 61 72 64 73 20 61 73 20 77 65 6c 6c 20 61 73 |wards as well as|
00000280 20 66 6f 72 77 61 72 64 73 2c 20 77 69 74 68 6f | forwards, witho|
00000290 75 74 20 74 68 65 20 6e 65 65 64 20 74 6f 20 61 |ut the need to a|
000002a0 6c 77 61 79 73 20 73 74 61 72 74 20 61 74 0a 74 |lways start at.t|
000002b0 68 65 20 62 65 67 69 6e 6e 69 6e 67 2e 0a 0a 54 |he beginning...T|
000002c0 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f |he implementatio|
000002d0 6e 20 69 73 20 67 72 61 70 68 69 63 61 6c 6c 79 |n is graphically|
000002e0 20 6c 69 6b 65 20 74 68 69 73 20 3a 0a 0a 20 20 | like this :.. |
000002f0 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |+---------------|
00000300 2b 20 20 20 20 20 20 0a 20 20 7c 20 43 6f 6e 74 |+ . | Cont|
00000310 72 6f 6c 20 42 6c 6f 63 6b 20 7c 20 20 20 20 20 |rol Block | |
00000320 20 20 20 20 20 20 20 20 20 20 20 20 0a 20 20 7c | . ||
00000330 20 20 20 28 6f 72 20 72 6f 6f 74 29 20 20 20 7c | (or root) ||
00000340 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000350 20 45 6e 64 0a 20 20 2b 2d 2d 2d 2d 2d 2d 2d 2d | End. +--------|
00000360 2d 2d 2d 2d 2d 2d 2d 2b 20 20 20 20 20 20 20 20 |-------+ |
00000370 20 20 20 20 20 20 20 20 20 20 8b 0a 20 20 20 20 | .. |
00000380 20 20 20 20 20 20 20 20 20 7c 20 20 20 7c 20 20 | | | |
00000390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
000003a0 20 7c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 | |. |
000003b0 7c 20 20 20 2b 2d 2d 2d 2d 2d 2d 3e 20 2b 2d 2d || +------> +--|
000003c0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2b 20 20 2b 2d 2d |----------+ +--|
000003d0 2d 2d 2d 2d 2b 0a 20 20 20 20 20 20 20 20 20 20 |----+. |
000003e0 20 20 20 7c 20 20 20 20 20 20 20 20 20 20 20 20 | | |
000003f0 7c 20 46 69 72 73 74 20 4e 6f 64 65 20 7c 2d 3e || First Node |->|
00000400 7c 20 44 61 74 61 20 7c 0a 20 20 20 20 20 20 20 || Data |. |
00000410 20 20 20 20 20 20 7c 20 20 20 20 20 20 20 20 20 | | |
00000420 20 20 20 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d | +------------|
00000430 2b 20 20 2b 2d 2d 2d 2d 2d 2d 2b 0a 20 20 20 20 |+ +------+. |
00000440 20 20 20 20 20 20 20 20 20 7c 20 20 20 20 20 20 | | |
00000450 20 20 20 20 20 20 20 20 7c 20 20 20 20 20 20 20 | | |
00000460 20 8b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 | .. |
00000470 7c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 8a || .|
00000480 20 20 20 20 20 20 20 20 7c 0a 20 20 20 20 20 20 | |. |
00000490 20 20 20 20 20 20 20 7c 20 20 20 20 20 20 20 20 | | |
000004a0 20 20 20 20 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d | +-----------|
000004b0 2d 2b 20 20 2b 2d 2d 2d 2d 2d 2d 2b 0a 20 20 20 |-+ +------+. |
000004c0 20 20 20 20 20 20 20 20 20 20 7c 20 20 20 20 20 | | |
000004d0 20 20 20 20 20 20 20 7c 20 20 20 41 20 4e 6f 64 | | A Nod|
000004e0 65 20 20 20 7c 2d 3e 7c 20 44 61 74 61 20 7c 0a |e |->| Data |.|
000004f0 20 20 20 20 20 20 20 20 20 20 20 20 20 7c 20 20 | | |
00000500 20 20 20 20 20 20 20 20 20 20 2b 2d 2d 2d 2d 2d | +-----|
00000510 2d 2d 2d 2d 2d 2d 2d 2b 20 20 2b 2d 2d 2d 2d 2d |-------+ +-----|
00000520 2d 2b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 |-+. |
00000530 7c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7c || ||
00000540 20 20 20 20 20 20 20 20 8b 0a 20 20 20 20 20 20 | .. |
00000550 20 20 20 20 20 20 20 7c 20 20 20 20 20 20 20 20 | | |
00000560 20 20 20 20 20 20 8a 20 20 20 20 20 20 20 20 7c | . ||
00000570 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 2b 2d |. +-|
00000580 2d 2d 2d 2d 2d 2d 2d 2d 2d 3e 20 2b 2d 2d 2d 2d |---------> +----|
00000590 2d 2d 2d 2d 2d 2d 2d 2d 2b 20 20 2b 2d 2d 2d 2d |--------+ +----|
000005a0 2d 2d 2b 0a 20 20 20 20 20 20 20 20 20 20 20 20 |--+. |
000005b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7c 20 | | |
000005c0 20 4c 61 73 74 20 4e 6f 64 65 20 7c 2d 3e 7c 20 | Last Node |->| |
000005d0 44 61 74 61 20 7c 0a 20 20 20 20 20 20 20 20 20 |Data |. |
000005e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
000005f0 20 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2b 20 | +------------+ |
00000600 20 2b 2d 2d 2d 2d 2d 2d 2b 0a 20 20 20 20 20 20 | +------+. |
00000610 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000620 20 20 20 20 20 20 7c 0a 20 20 20 20 20 20 20 20 | |. |
00000630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000640 20 20 20 20 8a 0a 20 20 20 20 20 20 20 20 20 20 | .. |
00000650 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000660 20 45 6e 64 0a 20 20 20 20 20 20 20 20 20 20 20 | End. |
00000670 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000680 0a 54 68 65 20 43 6f 6e 74 72 6f 6c 20 42 6c 6f |.The Control Blo|
00000690 63 6b 20 6f 72 20 72 6f 6f 74 20 61 73 20 69 74 |ck or root as it|
000006a0 20 77 69 6c 6c 20 62 65 20 63 61 6c 6c 65 64 20 | will be called |
000006b0 66 72 6f 6d 20 6e 6f 77 20 6f 6e 2c 20 69 73 20 |from now on, is |
000006c0 74 68 65 20 68 65 61 72 74 20 6f 66 0a 74 68 65 |the heart of.the|
000006d0 20 4c 69 6e 6b 65 64 20 4c 69 73 74 20 73 79 73 | Linked List sys|
000006e0 74 65 6d 2c 20 61 6e 64 20 6c 69 6b 65 20 74 68 |tem, and like th|
000006f0 65 20 6e 6f 64 65 73 2c 20 73 68 6f 75 6c 64 20 |e nodes, should |
00000700 20 4e 45 56 45 52 20 62 65 20 6d 6f 64 69 66 69 | NEVER be modifi|
00000710 65 64 20 77 69 74 68 6f 75 74 0a 75 73 69 6e 67 |ed without.using|
00000720 20 74 68 65 20 6c 69 62 72 61 72 79 20 72 6f 75 | the library rou|
00000730 74 69 6e 65 73 2e 0a 0a 55 6e 6c 69 6b 65 20 6d |tines...Unlike m|
00000740 6f 73 74 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 |ost linked-list |
00000750 72 6f 75 74 69 6e 65 73 2c 20 74 68 69 73 20 76 |routines, this v|
00000760 65 72 73 69 6f 6e 20 61 6c 6c 6f 77 73 20 65 61 |ersion allows ea|
00000770 63 68 20 64 61 74 61 20 73 65 63 74 69 6f 6e 20 |ch data section |
00000780 74 6f 20 68 61 76 65 0a 76 61 72 69 61 62 6c 65 |to have.variable|
00000790 20 6c 65 6e 67 74 68 73 2e 20 20 41 73 20 6c 6f | lengths. As lo|
000007a0 6e 67 20 61 73 20 61 73 20 79 6f 75 20 64 6f 6e |ng as as you don|
000007b0 27 74 20 6f 76 65 72 77 72 69 74 65 20 61 6e 79 |'t overwrite any|
000007c0 20 70 61 72 74 20 6f 66 20 75 6e 61 6c 6c 6f 63 | part of unalloc|
000007d0 61 74 65 64 0a 6d 65 6d 6f 72 79 2c 20 76 61 72 |ated.memory, var|
000007e0 69 61 62 6c 65 20 6c 65 6e 67 74 68 73 20 70 6f |iable lengths po|
000007f0 73 65 20 6e 6f 20 70 72 6f 62 6c 65 6d 73 2e 0a |se no problems..|
00000800 0a 0a 32 2e 20 20 54 68 65 20 66 75 6e 63 74 69 |..2. The functi|
00000810 6f 6e 73 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |ons.------------|
00000820 2d 2d 2d 2d 2d 0a 0a 4c 69 6e 6b 65 64 20 6c 69 |-----..Linked li|
00000830 73 74 20 66 75 6e 63 74 69 6f 6e 73 20 63 6f 6d |st functions com|
00000840 65 20 69 6e 20 64 69 66 66 65 72 65 6e 74 20 66 |e in different f|
00000850 6c 61 76 6f 75 72 73 20 3a 0a 0a 41 29 20 20 49 |lavours :..A) I|
00000860 6e 69 74 69 61 6c 69 73 61 74 69 6f 6e 0a 42 29 |nitialisation.B)|
00000870 20 20 50 72 6f 63 65 73 73 69 6e 67 0a 43 29 20 | Processing.C) |
00000880 20 44 65 6c 65 74 69 6e 67 0a 44 29 20 20 4d 6f | Deleting.D) Mo|
00000890 64 69 66 79 69 6e 67 20 61 6e 64 20 67 65 74 74 |difying and gett|
000008a0 69 6e 67 20 75 73 65 72 20 64 61 74 61 0a 45 29 |ing user data.E)|
000008b0 20 20 43 6f 75 6e 74 69 6e 67 20 20 0a 46 29 20 | Counting .F) |
000008c0 20 53 74 61 74 75 73 20 63 68 65 63 6b 20 0a 47 | Status check .G|
000008d0 29 20 20 52 65 6e 75 6d 62 65 72 69 6e 67 20 0a |) Renumbering .|
000008e0 48 29 20 20 53 6f 72 74 69 6e 67 20 0a 49 29 20 |H) Sorting .I) |
000008f0 20 47 65 74 74 69 6e 67 20 75 73 65 72 20 64 61 | Getting user da|
00000900 74 61 0a 0a 0a 33 2e 20 20 55 73 69 6e 67 20 74 |ta...3. Using t|
00000910 68 65 20 4c 69 6e 6b 4c 69 73 74 20 6c 69 62 72 |he LinkList libr|
00000920 61 72 79 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |ary.------------|
00000930 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------|
00000940 2d 2d 0a 0a 54 68 69 73 20 6c 69 62 72 61 72 79 |--..This library|
00000950 20 72 6f 75 74 69 6e 65 20 73 68 6f 75 6c 64 20 | routine should |
00000960 77 6f 72 6b 20 6f 6e 20 61 6c 6c 20 41 63 6f 72 |work on all Acor|
00000970 6e 20 52 49 53 43 20 6d 61 63 68 69 6e 65 73 20 |n RISC machines |
00000980 66 72 6f 6d 20 56 33 2e 31 30 20 75 70 77 61 72 |from V3.10 upwar|
00000990 64 73 0a 0a 54 68 65 20 4c 69 6e 6b 4c 69 73 74 |ds..The LinkList|
000009a0 20 64 61 74 61 20 66 69 6c 65 20 77 61 73 20 6f | data file was o|
000009b0 6e 6c 79 20 64 65 73 69 67 6e 65 64 20 66 6f 72 |nly designed for|
000009c0 20 45 61 73 79 20 43 2f 43 2b 2b 2c 20 61 6e 64 | Easy C/C++, and|
000009d0 20 77 69 6c 6c 20 70 72 6f 62 61 62 6c 79 20 6e | will probably n|
000009e0 6f 74 0a 77 6f 72 6b 20 6f 6e 20 41 63 6f 72 6e |ot.work on Acorn|
000009f0 27 73 20 43 2f 43 2b 2b 2e 0a 0a 4a 75 73 74 20 |'s C/C++...Just |
00000a00 63 6f 70 79 20 74 68 65 20 4c 69 6e 6b 4c 69 73 |copy the LinkLis|
00000a10 74 20 64 61 74 61 20 66 69 6c 65 20 69 6e 74 6f |t data file into|
00000a20 20 20 79 6f 75 72 20 45 61 73 79 43 2f 43 2b 2b | your EasyC/C++|
00000a30 20 4c 69 62 72 61 72 79 20 64 69 72 65 63 74 6f | Library directo|
00000a40 72 79 0a 28 21 45 61 73 79 43 2e 4c 69 62 72 61 |ry.(!EasyC.Libra|
00000a50 72 69 65 73 2c 20 6f 72 20 21 45 61 73 79 43 2b |ries, or !EasyC+|
00000a60 2b 2e 4c 69 62 72 61 72 69 65 73 29 2c 20 61 6e |+.Libraries), an|
00000a70 64 20 74 68 65 20 68 65 61 64 65 72 20 66 69 6c |d the header fil|
00000a80 65 20 69 6e 74 6f 20 74 68 65 20 68 0a 64 69 72 |e into the h.dir|
00000a90 65 63 74 6f 72 79 2e 0a 0a 45 78 69 74 20 6f 75 |ectory...Exit ou|
00000aa0 74 20 6f 66 20 45 61 73 79 43 2f 43 2b 2b 2c 20 |t of EasyC/C++, |
00000ab0 61 6e 64 20 67 6f 20 62 61 63 6b 20 69 6e 2e 20 |and go back in. |
00000ac0 20 20 50 72 65 73 73 69 6e 67 20 74 68 65 20 6c | Pressing the l|
00000ad0 65 66 74 20 62 75 74 74 6f 6e 20 6f 76 65 72 20 |eft button over |
00000ae0 74 68 65 0a 43 2f 43 2b 2b 20 69 63 6f 6e 20 77 |the.C/C++ icon w|
00000af0 69 6c 6c 20 62 72 69 6e 67 20 75 70 20 74 68 65 |ill bring up the|
00000b00 20 63 6f 6d 70 69 6c 65 72 20 77 69 6e 64 6f 77 | compiler window|
00000b10 2e 20 20 50 72 65 73 73 20 74 68 65 20 6d 69 64 |. Press the mid|
00000b20 64 6c 65 20 62 75 74 74 6f 6e 20 6f 76 65 72 0a |dle button over.|
00000b30 74 68 69 73 20 77 69 6e 64 6f 77 20 77 69 6c 6c |this window will|
00000b40 20 62 72 69 6e 67 20 75 70 20 61 20 6c 69 73 74 | bring up a list|
00000b50 20 6f 66 20 6f 70 74 69 6f 6e 73 2c 20 6f 6e 65 | of options, one|
00000b60 20 6f 66 20 77 68 69 63 68 20 77 69 6c 6c 20 62 | of which will b|
00000b70 65 20 27 4c 69 62 72 61 72 69 65 73 27 2e 20 0a |e 'Libraries'. .|
00000b80 41 6c 6c 6f 77 20 74 68 65 20 63 6f 6d 70 75 74 |Allow the comput|
00000b90 65 72 20 74 6f 20 65 78 70 61 6e 64 20 74 68 65 |er to expand the|
00000ba0 20 6c 69 62 72 61 72 69 65 73 20 73 75 62 2d 77 | libraries sub-w|
00000bb0 69 6e 64 6f 77 2c 20 61 6e 64 20 79 6f 75 20 73 |indow, and you s|
00000bc0 68 6f 75 6c 64 20 73 65 65 20 61 0a 6c 69 73 74 |hould see a.list|
00000bd0 20 6f 66 20 6c 69 62 72 61 72 79 20 72 6f 75 74 | of library rout|
00000be0 69 6e 65 73 20 74 68 61 74 20 45 61 73 79 43 2f |ines that EasyC/|
00000bf0 43 2b 2b 20 75 73 65 2c 20 69 6e 63 6c 75 64 69 |C++ use, includi|
00000c00 6e 67 20 4c 69 6e 6b 4c 69 73 74 2e 20 20 50 72 |ng LinkList. Pr|
00000c10 65 73 73 20 74 68 65 0a 6c 65 66 74 20 62 75 74 |ess the.left but|
00000c20 74 6f 6e 20 74 6f 20 70 75 74 20 61 20 74 69 63 |ton to put a tic|
00000c30 6b 20 6e 65 78 74 20 74 6f 20 4c 69 6e 6b 4c 69 |k next to LinkLi|
00000c40 73 74 2c 20 77 68 69 63 68 20 6e 6f 77 20 77 69 |st, which now wi|
00000c50 6c 6c 20 62 65 20 75 73 65 64 20 77 68 65 6e 65 |ll be used whene|
00000c60 76 65 72 0a 74 68 65 20 4c 69 6e 6b 4c 69 73 74 |ver.the LinkList|
00000c70 20 68 65 61 64 65 72 20 66 69 6c 65 20 69 73 20 | header file is |
00000c80 23 69 6e 63 6c 75 64 65 64 20 69 6e 74 6f 20 79 |#included into y|
00000c90 6f 75 72 20 70 72 6f 67 72 61 6d 2e 0a 20 0a 54 |our program.. .T|
00000ca0 68 65 20 66 69 6c 65 73 20 79 6f 75 20 73 68 6f |he files you sho|
00000cb0 75 6c 64 20 68 61 76 65 20 61 72 65 20 3a 0a 0a |uld have are :..|
00000cc0 41 29 20 20 4c 69 6e 6b 4c 69 73 74 2f 4c 20 2d |A) LinkList/L -|
00000cd0 09 41 20 44 41 54 41 20 66 69 6c 65 2c 20 77 68 |.A DATA file, wh|
00000ce0 69 63 68 20 73 68 6f 75 6c 64 20 67 6f 20 69 6e |ich should go in|
00000cf0 20 74 68 65 20 6c 69 62 72 61 72 79 20 64 69 72 | the library dir|
00000d00 65 63 74 6f 72 79 2e 0a 42 29 20 20 4c 69 6e 6b |ectory..B) Link|
00000d10 4c 69 73 74 2f 48 09 20 2d 09 41 20 48 45 41 44 |List/H. -.A HEAD|
00000d20 45 52 20 66 69 6c 65 2c 20 77 68 69 63 68 20 73 |ER file, which s|
00000d30 68 6f 75 6c 64 20 67 6f 20 69 6e 20 74 68 65 20 |hould go in the |
00000d40 68 20 64 69 72 65 63 74 6f 72 79 2e 0a 43 29 20 |h directory..C) |
00000d50 20 54 79 70 65 73 09 20 2d 09 41 20 48 45 41 44 | Types. -.A HEAD|
00000d60 45 52 20 66 69 6c 65 2c 20 77 68 69 63 68 20 61 |ER file, which a|
00000d70 6c 73 6f 20 73 68 6f 75 6c 64 20 67 6f 20 69 6e |lso should go in|
00000d80 20 74 68 65 20 68 0a 09 09 09 64 69 72 65 63 74 | the h....direct|
00000d90 6f 72 79 2e 0a 44 29 20 20 4c 6e 6b 4c 73 74 48 |ory..D) LnkLstH|
00000da0 65 6c 70 09 20 2d 09 54 68 69 73 20 66 69 6c 65 |elp. -.This file|
00000db0 0a 45 29 20 20 63 2e 54 65 73 74 4c 69 6e 6b 09 |.E) c.TestLink.|
00000dc0 20 2d 09 41 20 76 65 72 79 20 73 68 6f 72 74 20 | -.A very short |
00000dd0 74 65 73 74 20 70 72 6f 67 72 61 6d 0a 46 29 20 |test program.F) |
00000de0 20 54 65 73 74 4c 69 6e 6b 09 20 2d 09 54 68 65 | TestLink. -.The|
00000df0 20 65 78 65 63 75 74 61 62 6c 65 20 74 65 73 74 | executable test|
00000e00 20 70 72 6f 67 72 61 6d 20 28 73 6f 75 72 63 65 | program (source|
00000e10 20 69 73 20 69 6e 20 74 68 65 20 22 63 22 0a 09 | is in the "c"..|
00000e20 09 09 73 75 62 64 69 72 65 63 74 6f 72 79 29 0a |..subdirectory).|
00000e30 0a 0a 41 2e 20 20 49 6e 69 74 69 61 6c 69 73 61 |..A. Initialisa|
00000e40 74 69 6f 6e 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |tion.-----------|
00000e50 2d 2d 2d 2d 2d 2d 2d 0a 0a 54 68 65 72 65 20 69 |-------..There i|
00000e60 73 20 6f 6e 6c 79 20 6f 6e 65 20 69 6e 69 74 69 |s only one initi|
00000e70 61 6c 69 73 61 74 69 6f 6e 20 63 6f 6d 6d 61 6e |alisation comman|
00000e80 64 2c 20 63 61 6c 6c 65 64 20 22 63 72 65 61 74 |d, called "creat|
00000e90 65 4c 69 73 74 22 2e 20 20 54 68 69 73 20 63 72 |eList". This cr|
00000ea0 65 61 74 65 73 20 61 0a 75 6e 69 71 75 65 20 72 |eates a.unique r|
00000eb0 6f 6f 74 20 73 74 72 75 63 74 75 72 65 2c 20 61 |oot structure, a|
00000ec0 6e 64 20 72 65 74 75 72 6e 73 20 61 20 4c 4f 4e |nd returns a LON|
00000ed0 47 20 76 61 6c 75 65 2e 20 20 54 68 69 73 20 76 |G value. This v|
00000ee0 61 6c 75 65 20 69 73 20 6e 65 65 64 65 64 20 74 |alue is needed t|
00000ef0 6f 20 70 61 73 73 0a 74 6f 20 6d 6f 73 74 20 72 |o pass.to most r|
00000f00 6f 75 74 69 6e 65 73 2e 0a 0a 49 74 20 74 61 6b |outines...It tak|
00000f10 65 73 20 32 32 20 70 61 72 61 6d 65 74 65 72 73 |es 22 parameters|
00000f20 2c 20 62 6f 74 68 20 6f 66 20 74 79 70 65 20 4c |, both of type L|
00000f30 4f 4e 47 20 3a 20 54 68 65 20 66 69 72 73 74 20 |ONG : The first |
00000f40 64 65 66 69 6e 65 73 20 77 68 65 72 65 20 6d 65 |defines where me|
00000f50 6d 6f 72 79 20 69 73 0a 63 6c 61 69 6d 65 64 20 |mory is.claimed |
00000f60 66 72 6f 6d 20 20 2d 20 52 4d 41 20 75 73 65 73 |from - RMA uses|
00000f70 20 74 68 65 20 72 65 6c 6f 63 61 74 61 62 6c 65 | the relocatable|
00000f80 20 6d 65 6d 6f 72 79 20 61 72 65 61 2c 20 77 68 | memory area, wh|
00000f90 69 6c 65 20 44 59 4e 41 4d 49 43 20 75 73 65 73 |ile DYNAMIC uses|
00000fa0 20 74 68 65 0a 64 79 6e 61 6d 69 63 20 6d 65 6d | the.dynamic mem|
00000fb0 6f 72 79 20 61 72 65 61 20 28 52 49 53 43 20 4f |ory area (RISC O|
00000fc0 53 20 56 33 2e 35 30 2b 29 2e 0a 0a 45 61 63 68 |S V3.50+)...Each|
00000fd0 20 61 72 65 61 20 68 61 73 20 69 74 27 73 20 6f | area has it's o|
00000fe0 77 6e 20 61 64 76 61 6e 74 61 67 65 73 20 61 6e |wn advantages an|
00000ff0 64 20 64 69 73 61 64 76 61 6e 74 61 67 65 73 20 |d disadvantages |
00001000 3a 20 54 68 65 20 44 79 6e 61 6d 69 63 20 61 72 |: The Dynamic ar|
00001010 65 61 0a 61 6c 6c 6f 63 61 74 65 73 20 6d 65 6d |ea.allocates mem|
00001020 6f 72 79 20 69 6e 20 62 6c 6f 63 6b 73 20 6f 66 |ory in blocks of|
00001030 20 34 30 39 36 20 62 79 74 65 73 20 20 28 74 68 | 4096 bytes (th|
00001040 69 73 20 6d 65 61 6e 73 20 74 68 61 74 2c 20 66 |is means that, f|
00001050 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 65 0a 72 |or example the.r|
00001060 6f 6f 74 20 73 74 72 75 63 74 75 72 65 20 77 61 |oot structure wa|
00001070 73 74 65 73 20 61 72 6f 75 6e 64 20 34 30 36 38 |stes around 4068|
00001080 20 62 79 74 65 73 21 29 2c 20 62 75 74 20 77 69 | bytes!), but wi|
00001090 6c 6c 20 6e 6f 74 20 66 72 61 67 6d 65 6e 74 2e |ll not fragment.|
000010a0 20 20 54 68 65 20 52 4d 41 0a 61 6c 6c 6f 63 61 | The RMA.alloca|
000010b0 74 65 73 20 6d 65 6d 6f 72 79 20 74 6f 20 74 68 |tes memory to th|
000010c0 65 20 6e 65 61 72 65 73 74 20 77 6f 72 64 20 28 |e nearest word (|
000010d0 70 6f 73 73 69 62 6c 79 20 77 61 73 74 69 6e 67 |possibly wasting|
000010e0 20 6c 65 73 73 20 6d 65 6d 6f 72 79 20 66 6f 72 | less memory for|
000010f0 20 73 6d 61 6c 6c 0a 69 74 65 6d 73 29 2c 20 62 | small.items), b|
00001100 75 74 20 77 69 6c 6c 20 66 72 61 67 6d 65 6e 74 |ut will fragment|
00001110 20 6f 76 65 72 20 74 69 6d 65 2e 0a 0a 20 20 0a | over time... .|
00001120 42 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 0a 2d |B. Processing.-|
00001130 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 54 |-------------..T|
00001140 68 65 72 65 20 61 72 65 20 34 20 70 72 6f 63 65 |here are 4 proce|
00001150 73 73 69 6e 67 20 63 6f 6d 6d 61 6e 64 73 20 3a |ssing commands :|
00001160 0a 0a 47 65 74 44 69 72 2c 20 77 68 69 63 68 20 |..GetDir, which |
00001170 74 61 6b 65 73 20 74 77 6f 20 4c 4f 4e 47 20 70 |takes two LONG p|
00001180 61 72 61 6d 65 74 65 72 73 20 3a 20 20 54 68 65 |arameters : The|
00001190 20 66 69 72 73 74 20 69 73 20 74 68 65 20 61 64 | first is the ad|
000011a0 64 72 65 73 73 20 6f 66 20 74 68 65 0a 63 75 72 |dress of the.cur|
000011b0 72 65 6e 74 20 6e 6f 64 65 2c 20 61 6e 64 20 74 |rent node, and t|
000011c0 68 65 20 73 65 63 6f 6e 64 20 65 78 70 65 63 74 |he second expect|
000011d0 73 20 74 77 6f 20 63 6f 6e 73 74 61 6e 74 73 20 |s two constants |
000011e0 3a 20 4e 45 58 54 20 28 74 6f 20 67 65 74 20 74 |: NEXT (to get t|
000011f0 68 65 20 6e 65 78 74 0a 6e 6f 64 65 29 20 6f 72 |he next.node) or|
00001200 20 50 52 45 56 20 28 77 68 69 63 68 20 67 65 74 | PREV (which get|
00001210 73 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 6e |s the previous n|
00001220 6f 64 65 29 0a 0a 47 65 74 46 69 72 73 74 4c 61 |ode)..GetFirstLa|
00001230 73 74 20 61 6c 73 6f 20 74 61 6b 65 73 20 74 77 |st also takes tw|
00001240 6f 20 4c 4f 4e 47 20 70 61 72 61 6d 65 74 65 72 |o LONG parameter|
00001250 73 20 3a 20 54 68 65 20 66 69 72 73 74 20 69 73 |s : The first is|
00001260 20 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 | the address of |
00001270 74 68 65 0a 72 6f 6f 74 20 73 74 72 75 63 74 75 |the.root structu|
00001280 72 65 2c 20 61 6e 64 20 74 68 65 20 73 65 63 6f |re, and the seco|
00001290 6e 64 20 69 73 20 65 69 74 68 65 72 20 46 49 52 |nd is either FIR|
000012a0 53 54 20 74 6f 20 67 65 74 20 74 68 65 20 66 69 |ST to get the fi|
000012b0 72 73 74 20 6e 6f 64 65 2c 20 6f 72 20 4c 41 53 |rst node, or LAS|
000012c0 54 0a 74 6f 20 67 65 74 20 74 68 65 20 6c 61 73 |T.to get the las|
000012d0 74 20 6e 6f 64 65 2e 0a 0a 46 69 6e 64 41 49 6e |t node...FindAIn|
000012e0 64 65 78 4e 6f 64 65 2e 20 20 54 68 69 73 20 73 |dexNode. This s|
000012f0 65 61 72 63 68 65 73 20 66 6f 72 20 61 20 67 69 |earches for a gi|
00001300 76 65 6e 20 6e 6f 64 65 20 6e 75 6d 62 65 72 2c |ven node number,|
00001310 20 61 6e 64 20 72 65 74 75 72 6e 73 20 69 74 27 | and returns it'|
00001320 73 0a 61 64 64 72 65 73 73 20 69 66 20 6f 6e 65 |s.address if one|
00001330 20 68 61 73 20 62 65 65 6e 20 66 6f 75 6e 64 2e | has been found.|
00001340 20 20 49 74 20 65 78 70 65 63 74 73 20 74 77 6f | It expects two|
00001350 20 70 61 72 61 6d 65 74 65 72 73 2c 20 62 6f 74 | parameters, bot|
00001360 68 20 6f 66 20 74 79 70 65 20 20 0a 4c 4f 4e 47 |h of type .LONG|
00001370 20 3a 20 54 68 65 20 72 6f 6f 74 20 61 64 64 72 | : The root addr|
00001380 65 73 73 20 61 6e 64 20 74 68 65 20 6e 6f 64 65 |ess and the node|
00001390 20 6e 75 6d 62 65 72 20 74 6f 20 6c 6f 6f 6b 20 | number to look |
000013a0 66 6f 72 2e 20 20 54 68 69 73 20 6e 75 6d 62 65 |for. This numbe|
000013b0 72 20 6d 75 73 74 0a 6e 6f 74 20 62 65 20 67 72 |r must.not be gr|
000013c0 65 61 74 65 72 20 74 68 61 6e 20 74 68 65 20 68 |eater than the h|
000013d0 69 67 68 65 73 74 20 76 61 6c 75 65 20 63 75 72 |ighest value cur|
000013e0 72 65 6e 74 6c 79 20 75 73 65 64 2e 0a 0a 46 69 |rently used...Fi|
000013f0 6e 64 41 4e 75 6d 62 65 72 4e 6f 64 65 2e 20 20 |ndANumberNode. |
00001400 54 68 69 73 20 77 69 6c 6c 20 72 65 74 75 72 6e |This will return|
00001410 20 6e 6f 64 65 73 20 61 64 64 72 65 73 73 20 61 | nodes address a|
00001420 66 74 65 72 20 74 72 61 76 65 72 73 69 6e 67 20 |fter traversing |
00001430 74 68 72 6f 75 67 68 20 61 0a 67 69 76 65 6e 20 |through a.given |
00001440 6e 75 6d 62 65 72 20 6f 66 20 6e 6f 64 65 73 2e |number of nodes.|
00001450 20 20 49 74 20 65 78 70 65 63 74 73 20 74 68 72 | It expects thr|
00001460 65 65 20 70 61 72 61 6d 65 74 65 72 73 20 3a 20 |ee parameters : |
00001470 54 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 74 |The address of t|
00001480 68 65 0a 72 6f 6f 74 2c 20 74 68 65 20 6e 75 6d |he.root, the num|
00001490 62 65 72 20 6f 66 20 6e 6f 64 65 73 20 74 6f 20 |ber of nodes to |
000014a0 67 6f 20 74 68 72 6f 75 67 68 2c 20 61 6e 64 20 |go through, and |
000014b0 74 68 65 20 73 74 61 72 74 69 6e 67 20 70 6f 73 |the starting pos|
000014c0 69 74 69 6f 6e 20 28 65 69 74 68 65 72 0a 46 49 |ition (either.FI|
000014d0 52 53 54 20 6f 72 20 4c 41 53 54 29 2e 20 20 41 |RST or LAST). A|
000014e0 6c 6c 20 70 61 72 61 6d 65 74 65 72 73 20 61 72 |ll parameters ar|
000014f0 65 20 6f 66 20 74 79 70 65 20 4c 4f 4e 47 2e 0a |e of type LONG..|
00001500 0a 0a 43 2e 20 20 44 65 6c 65 74 69 6e 67 0a 2d |..C. Deleting.-|
00001510 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 54 68 65 |-----------..The|
00001520 72 65 20 61 72 65 20 34 20 77 61 79 73 20 6f 66 |re are 4 ways of|
00001530 20 64 65 6c 65 74 69 6e 67 20 61 20 4c 69 6e 6b | deleting a Link|
00001540 65 64 20 4c 69 73 74 20 3a 0a 0a 64 65 6c 65 74 |ed List :..delet|
00001550 65 4c 69 73 74 20 64 65 6c 65 74 65 73 20 74 68 |eList deletes th|
00001560 65 20 43 4f 4d 50 4c 45 54 45 20 6c 69 73 74 20 |e COMPLETE list |
00001570 6f 66 20 6d 65 6d 6f 72 79 2c 20 61 6e 64 20 65 |of memory, and e|
00001580 78 70 65 63 74 73 20 74 68 65 20 72 6f 6f 74 20 |xpects the root |
00001590 76 61 6c 75 65 20 74 6f 0a 62 65 20 70 61 73 73 |value to.be pass|
000015a0 65 64 20 74 6f 20 69 74 2e 20 20 54 68 69 73 20 |ed to it. This |
000015b0 73 68 6f 75 6c 64 20 62 65 20 6f 66 20 74 79 70 |should be of typ|
000015c0 65 20 4c 4f 4e 47 2e 0a 0a 64 65 6c 65 74 65 43 |e LONG...deleteC|
000015d0 75 72 72 65 6e 74 4e 6f 64 65 20 64 65 6c 65 74 |urrentNode delet|
000015e0 65 73 20 74 68 65 20 67 69 76 65 6e 20 6e 6f 64 |es the given nod|
000015f0 65 2c 20 61 6e 64 20 65 78 70 65 63 74 73 20 74 |e, and expects t|
00001600 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 2d 20 |wo parameters - |
00001610 74 68 65 0a 66 69 72 73 74 20 69 73 20 74 68 65 |the.first is the|
00001620 20 72 6f 6f 74 20 76 61 6c 75 65 2c 20 61 6e 64 | root value, and|
00001630 20 74 68 65 20 73 65 63 6f 6e 64 20 69 73 20 74 | the second is t|
00001640 68 65 20 63 75 72 72 65 6e 74 20 6e 6f 64 65 20 |he current node |
00001650 61 64 64 72 65 73 73 2e 20 20 42 6f 74 68 0a 6e |address. Both.n|
00001660 65 65 64 20 74 6f 20 62 65 20 6f 66 20 74 79 70 |eed to be of typ|
00001670 65 20 4c 4f 4e 47 2e 0a 0a 64 65 6c 65 74 65 4e |e LONG...deleteN|
00001680 75 6d 62 65 72 4e 6f 64 65 20 73 65 61 72 63 68 |umberNode search|
00001690 65 73 20 74 68 65 20 6c 69 73 74 20 6c 6f 6f 6b |es the list look|
000016a0 69 6e 67 20 66 6f 72 20 74 68 65 20 67 69 76 65 |ing for the give|
000016b0 6e 20 6e 6f 64 65 20 6e 75 6d 62 65 72 2c 20 61 |n node number, a|
000016c0 6e 64 20 69 66 0a 66 6f 75 6e 64 2c 20 64 65 6c |nd if.found, del|
000016d0 65 74 65 73 20 69 74 2e 20 20 54 68 69 73 20 65 |etes it. This e|
000016e0 78 70 65 63 74 73 20 74 77 6f 20 70 61 72 61 6d |xpects two param|
000016f0 65 74 65 72 73 20 6f 66 20 74 79 70 65 20 4c 4f |eters of type LO|
00001700 4e 47 20 2d 20 74 68 65 20 66 69 72 73 74 20 69 |NG - the first i|
00001710 73 0a 74 68 65 20 72 6f 6f 74 20 61 64 64 72 65 |s.the root addre|
00001720 73 73 2c 20 61 6e 64 20 74 68 65 20 73 65 63 6f |ss, and the seco|
00001730 6e 64 20 69 73 20 74 68 65 20 6e 6f 64 65 20 6e |nd is the node n|
00001740 75 6d 62 65 72 20 74 6f 20 73 65 61 72 63 68 20 |umber to search |
00001750 66 6f 72 2e 20 20 54 68 65 20 6e 6f 64 65 0a 6e |for. The node.n|
00001760 75 6d 62 65 72 20 6d 75 73 74 20 62 65 20 3e 20 |umber must be > |
00001770 30 20 61 6e 64 20 6c 65 73 73 20 74 68 61 6e 20 |0 and less than |
00001780 74 68 65 20 63 75 72 72 65 6e 74 20 68 69 67 68 |the current high|
00001790 65 73 74 20 6e 6f 64 65 20 6e 75 6d 62 65 72 20 |est node number |
000017a0 73 6f 20 66 61 72 2e 0a 0a 64 65 6c 65 74 65 49 |so far...deleteI|
000017b0 6e 64 65 78 4e 6f 64 65 20 74 72 61 76 65 72 73 |ndexNode travers|
000017c0 65 73 20 74 68 72 6f 75 67 68 20 74 68 65 20 6c |es through the l|
000017d0 69 73 74 20 28 68 61 76 69 6e 67 20 73 74 61 72 |ist (having star|
000017e0 74 65 64 20 66 72 6f 6d 20 74 68 65 20 62 65 67 |ted from the beg|
000017f0 69 6e 69 6e 67 0a 6f 72 20 74 68 65 20 65 6e 64 |ining.or the end|
00001800 29 2c 20 61 6e 64 20 66 6f 72 20 65 61 63 68 20 |), and for each |
00001810 6e 6f 64 65 20 64 65 63 72 65 61 73 65 73 20 61 |node decreases a|
00001820 20 67 69 76 65 6e 20 70 61 72 61 6d 65 74 65 72 | given parameter|
00001830 2e 20 20 4f 6e 63 65 20 74 68 69 73 20 68 61 73 |. Once this has|
00001840 0a 72 65 61 63 68 65 64 20 7a 65 72 6f 2c 20 74 |.reached zero, t|
00001850 68 65 20 6e 6f 64 65 20 63 75 72 72 65 6e 74 6c |he node currentl|
00001860 79 20 70 6f 69 6e 74 65 64 20 74 6f 20 69 73 20 |y pointed to is |
00001870 64 65 6c 65 74 65 64 2e 20 20 49 74 20 65 78 70 |deleted. It exp|
00001880 65 63 74 73 20 74 68 72 65 65 0a 70 61 72 61 6d |ects three.param|
00001890 65 74 65 72 73 20 6f 66 20 74 79 70 65 20 4c 4f |eters of type LO|
000018a0 4e 47 20 2d 20 74 68 65 20 66 69 72 73 74 20 69 |NG - the first i|
000018b0 73 20 74 68 65 20 72 6f 6f 74 20 70 6f 69 6e 74 |s the root point|
000018c0 65 72 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 69 |er, the second i|
000018d0 73 20 74 68 65 0a 69 6e 64 65 78 20 6e 75 6d 62 |s the.index numb|
000018e0 65 72 2c 20 77 68 69 6c 65 20 74 68 65 20 6c 61 |er, while the la|
000018f0 73 74 20 69 73 20 74 68 65 20 6d 6f 76 65 6d 65 |st is the moveme|
00001900 6e 74 20 64 69 72 65 63 74 69 6f 6e 20 28 65 69 |nt direction (ei|
00001910 74 68 65 72 20 46 49 52 53 54 20 6f 72 20 4c 41 |ther FIRST or LA|
00001920 53 54 29 20 0a 0a 0a 44 2e 20 20 4d 6f 64 69 66 |ST) ...D. Modif|
00001930 79 69 6e 67 20 61 6e 64 20 67 65 74 74 69 6e 67 |ying and getting|
00001940 20 75 73 65 72 20 64 61 74 61 0a 2d 2d 2d 2d 2d | user data.-----|
00001950 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------|
00001960 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a |--------------..|
00001970 54 68 65 72 65 20 69 73 20 6f 6e 65 20 66 75 6e |There is one fun|
00001980 63 74 69 6f 6e 20 74 68 61 74 20 63 61 6e 20 67 |ction that can g|
00001990 65 74 20 61 6e 64 20 6d 6f 64 69 66 79 20 75 73 |et and modify us|
000019a0 65 72 20 64 61 74 61 2e 20 20 54 68 65 20 66 75 |er data. The fu|
000019b0 6e 63 74 69 6f 6e 20 69 73 0a 63 61 6c 6c 65 64 |nction is.called|
000019c0 20 67 65 74 55 73 65 72 44 61 74 61 20 61 6e 64 | getUserData and|
000019d0 20 65 78 70 65 63 74 73 20 36 20 70 61 72 61 6d | expects 6 param|
000019e0 65 74 65 72 73 2e 20 20 54 68 65 20 66 69 72 73 |eters. The firs|
000019f0 74 20 34 2c 20 6d 75 73 74 20 62 65 20 6f 66 20 |t 4, must be of |
00001a00 74 79 70 65 0a 4c 4f 4e 47 20 61 6e 64 20 61 72 |type.LONG and ar|
00001a10 65 20 74 68 65 20 72 6f 6f 74 20 61 64 64 72 65 |e the root addre|
00001a20 73 73 2c 20 74 68 65 20 63 75 72 72 65 6e 74 20 |ss, the current |
00001a30 6e 6f 64 65 20 61 64 64 72 65 73 73 2c 20 74 68 |node address, th|
00001a40 65 20 73 74 61 72 74 69 6e 67 20 70 6f 73 69 74 |e starting posit|
00001a50 69 6f 6e 0a 77 69 74 68 69 6e 20 74 68 65 20 75 |ion.within the u|
00001a60 73 65 72 20 64 61 74 61 20 74 68 61 74 20 79 6f |ser data that yo|
00001a70 75 20 77 69 73 68 20 74 6f 20 73 74 61 72 74 20 |u wish to start |
00001a80 61 74 20 61 6e 64 20 74 68 65 20 6e 75 6d 62 65 |at and the numbe|
00001a90 72 20 6f 66 20 62 79 74 65 73 20 79 6f 75 0a 77 |r of bytes you.w|
00001aa0 61 6e 74 20 74 6f 20 67 65 74 20 6f 72 20 6d 6f |ant to get or mo|
00001ab0 64 69 66 79 2e 20 20 54 68 65 20 72 65 6d 61 69 |dify. The remai|
00001ac0 6e 69 6e 67 20 74 77 6f 20 61 72 65 20 6f 66 20 |ning two are of |
00001ad0 74 79 70 65 20 63 68 61 72 20 2a 2c 20 61 6e 64 |type char *, and|
00001ae0 20 69 73 20 74 68 65 0a 62 75 66 66 65 72 20 69 | is the.buffer i|
00001af0 6e 20 77 68 69 63 68 20 61 6c 6c 20 64 61 74 61 |n which all data|
00001b00 20 69 73 20 72 65 61 64 20 66 72 6f 6d 20 6f 72 | is read from or|
00001b10 20 77 72 69 74 74 65 6e 20 74 6f 2c 20 61 6e 64 | written to, and|
00001b20 20 6f 66 20 74 79 70 65 20 69 6e 74 2c 20 77 68 | of type int, wh|
00001b30 69 63 68 0a 61 63 63 65 70 74 73 20 65 69 74 68 |ich.accepts eith|
00001b40 65 72 20 47 45 54 5f 44 41 54 41 20 28 74 6f 20 |er GET_DATA (to |
00001b50 72 65 61 64 20 64 61 74 61 20 69 6e 74 6f 20 74 |read data into t|
00001b60 68 65 20 62 75 66 66 65 72 29 2c 20 6f 72 20 57 |he buffer), or W|
00001b70 52 49 54 45 5f 44 41 54 41 20 74 6f 20 73 74 61 |RITE_DATA to sta|
00001b80 72 74 0a 77 72 69 74 69 6e 67 20 64 61 74 61 20 |rt.writing data |
00001b90 66 72 6f 6d 20 74 68 65 20 6f 66 66 73 65 74 20 |from the offset |
00001ba0 76 61 6c 75 65 2e 0a 0a 54 68 65 20 6f 66 66 73 |value...The offs|
00001bb0 65 74 20 76 61 6c 75 65 20 73 74 61 72 74 73 20 |et value starts |
00001bc0 66 72 6f 6d 20 30 2e 0a 0a 2a 20 57 41 52 4e 49 |from 0...* WARNI|
00001bd0 4e 47 20 3a 20 2a 0a 0a 4e 6f 20 63 68 65 63 6b |NG : *..No check|
00001be0 20 69 73 20 6d 61 64 65 20 74 6f 20 73 65 65 20 | is made to see |
00001bf0 77 68 65 74 68 65 72 20 72 65 61 64 69 6e 67 20 |whether reading |
00001c00 6f 72 20 77 72 69 74 69 6e 67 20 73 74 61 72 74 |or writing start|
00001c10 73 20 6f 72 20 73 74 61 79 73 20 77 69 74 68 69 |s or stays withi|
00001c20 6e 20 74 68 65 0a 64 61 74 61 20 62 6c 6f 63 6b |n the.data block|
00001c30 20 73 69 7a 65 2e 20 20 49 66 20 79 6f 75 20 67 | size. If you g|
00001c40 65 74 20 61 6e 79 20 65 72 72 6f 72 20 6d 65 73 |et any error mes|
00001c50 73 61 67 65 73 20 6f 72 20 73 74 72 61 6e 67 65 |sages or strange|
00001c60 20 74 68 69 6e 67 73 20 68 61 70 70 6e 69 6e 67 | things happning|
00001c70 2c 0a 74 68 65 6e 20 63 68 65 63 6b 20 74 68 65 |,.then check the|
00001c80 20 76 61 6c 75 65 73 20 70 61 73 73 65 64 20 74 | values passed t|
00001c90 6f 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 2e |o this function.|
00001ca0 0a 0a 0a 45 2e 20 20 43 6f 75 6e 74 69 6e 67 0a |...E. Counting.|
00001cb0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 6e 75 |------------..nu|
00001cc0 6d 62 65 72 4f 66 4e 6f 64 65 73 20 28 77 68 69 |mberOfNodes (whi|
00001cd0 63 68 20 65 78 70 65 63 74 73 20 61 20 72 6f 6f |ch expects a roo|
00001ce0 74 20 70 61 72 61 6d 65 74 65 72 20 6f 66 20 74 |t parameter of t|
00001cf0 79 70 65 20 4c 4f 4e 47 29 20 72 65 74 75 72 6e |ype LONG) return|
00001d00 73 20 74 68 65 20 6e 75 6d 62 65 72 0a 6f 66 20 |s the number.of |
00001d10 6e 6f 64 65 73 20 69 6e 20 74 68 65 20 6c 69 6e |nodes in the lin|
00001d20 6b 20 6c 69 73 74 20 28 69 66 20 61 6e 79 29 2c |k list (if any),|
00001d30 20 6f 74 68 65 72 77 69 73 65 20 69 74 20 72 65 | otherwise it re|
00001d40 74 75 72 6e 73 20 30 2e 0a 0a 0a 46 2e 20 20 53 |turns 0....F. S|
00001d50 74 61 74 75 73 20 43 68 65 63 6b 0a 2d 2d 2d 2d |tatus Check.----|
00001d60 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 54 68 |------------..Th|
00001d70 65 20 73 74 61 74 75 73 20 63 68 65 63 6b 20 69 |e status check i|
00001d80 73 20 73 65 6e 74 20 74 6f 20 61 6e 20 6f 70 65 |s sent to an ope|
00001d90 6e 20 66 69 6c 65 2c 20 66 6f 72 20 65 78 61 6d |n file, for exam|
00001da0 70 6c 65 20 73 74 64 6f 75 74 20 28 77 68 69 63 |ple stdout (whic|
00001db0 68 20 73 65 6e 64 73 0a 65 76 65 72 79 74 68 69 |h sends.everythi|
00001dc0 6e 67 20 74 6f 20 74 68 65 20 73 63 72 65 65 6e |ng to the screen|
00001dd0 29 2c 20 61 6e 64 20 64 69 73 70 6c 61 79 73 20 |), and displays |
00001de0 74 68 65 20 69 6e 74 65 67 72 69 74 79 20 6f 66 |the integrity of|
00001df0 20 74 68 65 20 43 6f 6e 74 72 6f 6c 20 42 6c 6f | the Control Blo|
00001e00 63 6b 0a 66 6f 6c 6c 6f 77 65 64 20 62 79 20 65 |ck.followed by e|
00001e10 61 63 68 20 6f 66 20 74 68 65 20 6e 6f 64 65 73 |ach of the nodes|
00001e20 2e 20 20 49 66 20 61 6e 79 20 77 61 72 6e 69 6e |. If any warnin|
00001e30 67 20 6d 65 73 73 61 67 65 73 20 61 70 70 65 61 |g messages appea|
00001e40 72 20 79 6f 75 20 4d 41 59 20 4e 4f 54 20 62 65 |r you MAY NOT be|
00001e50 0a 61 62 6c 65 20 74 6f 20 70 72 6f 63 65 73 73 |.able to process|
00001e60 20 6f 72 20 64 65 6c 65 74 65 20 74 68 61 74 20 | or delete that |
00001e70 4c 69 6e 6b 65 64 20 4c 69 73 74 20 70 72 6f 70 |Linked List prop|
00001e80 65 72 6c 79 2c 20 72 65 73 75 6c 74 69 6e 67 20 |erly, resulting |
00001e90 69 6e 20 77 61 73 74 65 64 0a 6d 65 6d 6f 72 79 |in wasted.memory|
00001ea0 2e 20 20 59 6f 75 20 73 68 6f 75 6c 64 20 63 68 |. You should ch|
00001eb0 65 63 6b 20 79 6f 75 72 20 70 72 6f 67 72 61 6d |eck your program|
00001ec0 20 74 6f 20 6d 61 6b 65 20 73 75 72 65 20 6e 6f | to make sure no|
00001ed0 20 68 65 61 64 65 72 73 20 61 6e 64 20 70 6f 69 | headers and poi|
00001ee0 6e 74 65 72 73 0a 61 72 65 20 6d 6f 64 69 66 69 |nters.are modifi|
00001ef0 65 64 2e 0a 0a 49 66 20 61 6e 79 20 70 72 6f 62 |ed...If any prob|
00001f00 6c 65 6d 73 20 61 72 65 20 66 6f 75 6e 64 2c 20 |lems are found, |
00001f10 74 68 65 6e 20 74 68 65 20 66 75 6e 63 74 69 6f |then the functio|
00001f20 6e 20 77 69 6c 6c 20 74 72 79 20 74 6f 20 63 6f |n will try to co|
00001f30 6e 74 69 6e 75 65 20 61 73 20 6c 6f 6e 67 20 61 |ntinue as long a|
00001f40 73 0a 70 6f 73 73 69 62 6c 65 20 75 6e 74 69 6c |s.possible until|
00001f50 20 65 69 74 68 65 72 20 61 6e 20 65 72 72 6f 72 | either an error|
00001f60 20 6d 65 73 73 61 67 65 20 69 73 20 64 69 73 70 | message is disp|
00001f70 6c 61 79 65 64 20 6f 72 20 73 6f 6d 65 20 65 6e |layed or some en|
00001f80 64 20 69 73 20 66 6f 75 6e 64 2e 0a 0a 49 74 20 |d is found...It |
00001f90 74 61 6b 65 73 20 74 77 6f 20 70 61 72 61 6d 65 |takes two parame|
00001fa0 74 65 72 73 20 3a 20 20 54 68 65 20 72 6f 6f 74 |ters : The root|
00001fb0 20 61 64 64 72 65 73 73 20 61 73 20 74 79 70 65 | address as type|
00001fc0 20 4c 4f 4e 47 20 61 6e 64 20 61 20 66 69 6c 65 | LONG and a file|
00001fd0 20 70 6f 69 6e 74 65 72 2e 0a 0a 0a 47 2e 20 20 | pointer....G. |
00001fe0 52 65 6e 75 6d 62 65 72 69 6e 67 0a 2d 2d 2d 2d |Renumbering.----|
00001ff0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 72 65 6e |-----------..ren|
00002000 75 6d 62 65 72 4e 6f 64 65 73 20 72 65 6e 75 6d |umberNodes renum|
00002010 62 65 72 73 20 74 68 65 20 4c 69 6e 6b 65 64 20 |bers the Linked |
00002020 4c 69 73 74 20 69 6e 20 61 73 63 65 6e 64 69 6e |List in ascendin|
00002030 67 20 6f 72 64 65 72 2c 20 72 65 6d 6f 76 69 6e |g order, removin|
00002040 67 20 61 6e 79 20 67 61 70 73 0a 69 6e 20 74 68 |g any gaps.in th|
00002050 65 20 6e 6f 64 65 73 20 6e 75 6d 62 65 72 2e 20 |e nodes number. |
00002060 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 74 | This function t|
00002070 61 6b 65 73 20 6f 6e 65 20 70 61 72 61 6d 65 74 |akes one paramet|
00002080 65 72 20 6f 66 20 74 79 70 65 20 4c 4f 4e 47 2c |er of type LONG,|
00002090 20 77 68 69 63 68 20 69 73 0a 74 68 65 20 72 6f | which is.the ro|
000020a0 6f 74 20 61 64 64 72 65 73 73 2e 0a 0a 0a 48 2e |ot address....H.|
000020b0 20 20 53 6f 72 74 69 6e 67 0a 2d 2d 2d 2d 2d 2d | Sorting.------|
000020c0 2d 2d 2d 2d 2d 0a 0a 73 6f 72 74 4c 69 73 74 20 |-----..sortList |
000020d0 67 6f 65 73 20 74 68 72 6f 75 67 68 20 74 68 65 |goes through the|
000020e0 20 4c 69 6e 6b 65 64 20 4c 69 73 74 2c 20 73 6f | Linked List, so|
000020f0 72 74 69 6e 67 20 65 61 63 68 20 6e 6f 64 65 20 |rting each node |
00002100 69 73 20 61 73 63 65 6e 64 69 6e 67 20 6f 72 64 |is ascending ord|
00002110 65 72 2e 20 0a 59 6f 75 20 6d 75 73 74 20 73 75 |er. .You must su|
00002120 70 70 6c 79 20 74 68 65 20 63 6f 6d 70 61 72 65 |pply the compare|
00002130 20 66 75 6e 63 74 69 6f 6e 2c 20 77 68 69 63 68 | function, which|
00002140 20 6d 75 73 74 20 63 6f 6d 70 61 72 65 20 74 68 | must compare th|
00002150 65 20 74 77 6f 20 67 69 76 65 6e 20 6e 6f 64 65 |e two given node|
00002160 73 0a 61 6e 64 20 72 65 74 75 72 6e 20 61 20 76 |s.and return a v|
00002170 61 6c 75 65 20 6f 66 20 30 20 69 66 20 62 6f 74 |alue of 0 if bot|
00002180 68 20 6e 6f 64 65 73 20 61 72 65 20 45 58 41 43 |h nodes are EXAC|
00002190 54 4c 59 20 65 71 75 61 6c 2c 20 31 20 69 66 20 |TLY equal, 1 if |
000021a0 74 68 65 20 66 69 72 73 74 20 6e 6f 64 65 0a 69 |the first node.i|
000021b0 73 20 67 72 65 61 74 65 72 20 74 68 61 6e 20 74 |s greater than t|
000021c0 68 65 20 73 65 63 6f 6e 64 2c 20 61 6e 64 20 2d |he second, and -|
000021d0 31 20 69 66 20 74 68 65 20 66 69 72 73 74 20 6e |1 if the first n|
000021e0 6f 64 65 20 69 73 20 6c 65 73 73 20 74 68 61 6e |ode is less than|
000021f0 20 74 68 65 20 73 65 63 6f 6e 64 2e 20 0a 54 68 | the second. .Th|
00002200 69 73 20 66 75 6e 63 74 69 6f 6e 20 65 78 70 65 |is function expe|
00002210 63 74 73 20 74 77 6f 20 70 61 72 61 6d 65 74 65 |cts two paramete|
00002220 72 73 20 2d 20 74 68 65 20 72 6f 6f 74 20 61 64 |rs - the root ad|
00002230 64 72 65 73 73 20 28 77 68 69 63 68 20 69 73 20 |dress (which is |
00002240 6f 66 20 74 79 70 65 0a 4c 4f 4e 47 29 2c 20 69 |of type.LONG), i|
00002250 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 79 6f |s the name of yo|
00002260 75 72 20 63 6f 6d 70 61 72 65 20 66 75 6e 74 69 |ur compare funti|
00002270 6f 6e 2e 0a 0a 59 6f 75 72 20 63 6f 6d 70 61 72 |on...Your compar|
00002280 65 20 66 75 6e 63 74 69 6f 6e 20 65 78 70 65 63 |e function expec|
00002290 74 73 20 74 68 72 65 65 20 70 61 72 61 6d 65 74 |ts three paramet|
000022a0 65 72 73 20 20 2d 20 74 68 65 20 61 64 64 72 65 |ers - the addre|
000022b0 73 73 20 6f 66 20 61 20 6e 6f 64 65 2c 20 74 68 |ss of a node, th|
000022c0 65 0a 61 64 64 72 65 73 73 20 6f 66 20 74 68 65 |e.address of the|
000022d0 20 6e 65 78 74 20 6e 6f 64 65 2c 20 61 6e 64 20 | next node, and |
000022e0 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 74 |the address of t|
000022f0 68 65 20 72 6f 6f 74 2e 20 20 41 6c 6c 20 74 68 |he root. All th|
00002300 65 73 65 20 61 72 65 20 6f 66 0a 74 79 70 65 20 |ese are of.type |
00002310 4c 4f 4e 47 2e 0a 0a 0a 34 2e 20 20 54 68 65 20 |LONG....4. The |
00002320 53 74 72 75 63 74 75 72 65 73 0a 2d 2d 2d 2d 2d |Structures.-----|
00002330 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 54 |-------------..T|
00002340 68 65 72 65 20 61 72 65 20 74 68 72 65 65 20 73 |here are three s|
00002350 74 72 75 63 74 75 72 65 73 20 74 68 61 74 20 79 |tructures that y|
00002360 6f 75 20 77 69 6c 6c 20 6e 65 65 64 20 74 6f 20 |ou will need to |
00002370 64 65 63 6c 61 72 65 20 69 6e 20 79 6f 75 72 20 |declare in your |
00002380 70 72 6f 67 72 61 6d 20 61 74 0a 63 65 72 74 61 |program at.certa|
00002390 69 6e 20 74 69 6d 65 73 2c 20 69 6e 20 6f 72 64 |in times, in ord|
000023a0 65 72 20 74 6f 20 70 61 73 73 20 63 6f 72 72 65 |er to pass corre|
000023b0 63 74 20 73 69 7a 65 73 20 61 6e 64 20 70 65 72 |ct sizes and per|
000023c0 68 61 70 73 20 74 6f 20 73 74 6f 72 65 20 69 6e |haps to store in|
000023d0 66 6f 72 6d 61 74 69 6f 6e 0a 3a 0a 0a 5f 5f 43 |formation.:..__C|
000023e0 4f 4e 54 52 4f 4c 42 4c 4f 43 4b 09 2d 20 20 20 |ONTROLBLOCK.- |
000023f0 48 65 61 64 65 72 20 69 6e 66 6f 72 6d 61 74 69 |Header informati|
00002400 6f 6e 0a 5f 5f 52 4f 4f 54 20 09 20 20 20 20 09 |on.__ROOT . .|
00002410 2d 20 20 20 52 6f 6f 74 20 69 6e 66 6f 72 6d 61 |- Root informa|
00002420 74 69 6f 6e 0a 5f 5f 4e 4f 44 45 20 09 20 20 20 |tion.__NODE . |
00002430 20 09 2d 20 20 20 4e 6f 64 65 20 69 6e 66 6f 72 | .- Node infor|
00002440 6d 61 74 69 6f 6e 0a 5f 5f 44 41 54 41 20 09 20 |mation.__DATA . |
00002450 20 20 20 09 2d 20 20 20 49 6e 69 74 69 61 6c 20 | .- Initial |
00002460 64 61 74 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e |data information|
00002470 0a 0a 59 4f 55 20 4d 55 53 54 20 4e 45 56 45 52 |..YOU MUST NEVER|
00002480 20 4d 4f 44 49 46 59 20 41 4e 59 20 4f 46 20 54 | MODIFY ANY OF T|
00002490 48 45 53 45 20 53 54 52 55 43 54 55 52 45 53 20 |HESE STRUCTURES |
000024a0 59 4f 55 52 53 45 4c 46 2e 20 20 41 4c 57 41 59 |YOURSELF. ALWAY|
000024b0 53 20 55 53 45 20 4f 4e 45 20 4f 46 20 54 48 45 |S USE ONE OF THE|
000024c0 0a 4c 49 42 52 41 52 59 20 46 55 4e 43 54 49 4f |.LIBRARY FUNCTIO|
000024d0 4e 53 20 49 46 20 53 4f 4d 45 20 50 41 52 54 20 |NS IF SOME PART |
000024e0 4e 45 45 44 53 20 54 4f 20 43 48 41 4e 47 45 2e |NEEDS TO CHANGE.|
000024f0 0a 0a 0a 35 2e 20 20 43 6f 6e 73 74 61 6e 74 73 |...5. Constants|
00002500 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a |.-------------..|
00002510 59 6f 75 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 |You should alway|
00002520 73 20 75 73 65 20 74 68 65 73 65 20 63 6f 6e 73 |s use these cons|
00002530 74 61 6e 74 73 20 77 68 65 72 65 20 74 68 65 79 |tants where they|
00002540 20 61 72 65 20 6e 65 65 64 65 64 20 3a 0a 0a 46 | are needed :..F|
00002550 49 52 53 54 20 20 2d 0a 20 20 20 20 20 20 20 20 |IRST -. |
00002560 7c 09 2d 20 50 6f 73 69 74 69 6f 6e 20 74 6f 20 ||.- Position to |
00002570 73 74 61 72 74 20 6d 6f 76 65 6d 65 6e 74 20 2d |start movement -|
00002580 20 65 69 74 68 65 72 20 74 68 65 20 66 69 72 73 | either the firs|
00002590 74 20 6f 72 20 6c 61 73 74 20 6e 6f 64 65 0a 4c |t or last node.L|
000025a0 41 53 54 20 20 20 2d 0a 0a 4c 4f 4e 47 09 09 2d |AST -..LONG..-|
000025b0 20 41 20 76 61 72 69 61 62 6c 65 20 74 79 70 65 | A variable type|
000025c0 09 0a 0a 47 45 54 5f 44 41 54 41 20 20 20 2d 0a |...GET_DATA -.|
000025d0 20 20 20 20 20 20 20 20 20 20 20 20 7c 09 2d 20 | |.- |
000025e0 45 69 74 68 65 72 20 66 65 74 63 68 20 64 61 74 |Either fetch dat|
000025f0 61 20 28 47 45 54 5f 44 41 54 41 29 20 6f 72 20 |a (GET_DATA) or |
00002600 73 74 6f 72 65 20 64 61 74 61 20 28 53 54 4f 52 |store data (STOR|
00002610 45 5f 44 41 54 41 29 0a 53 54 4f 52 45 5f 44 41 |E_DATA).STORE_DA|
00002620 54 41 20 2d 0a 0a 44 59 4e 41 4d 49 43 20 20 2d |TA -..DYNAMIC -|
00002630 0a 20 20 20 20 20 20 20 20 20 20 7c 09 2d 20 41 |. |.- A|
00002640 6c 6c 6f 63 61 74 65 20 6d 65 6d 6f 72 79 20 66 |llocate memory f|
00002650 72 6f 6d 20 74 68 65 20 52 4d 41 20 28 52 4d 41 |rom the RMA (RMA|
00002660 29 20 6f 72 20 64 79 6e 61 6d 69 63 20 6d 65 6d |) or dynamic mem|
00002670 6f 72 79 0a 09 20 20 7c 09 20 20 28 44 59 4e 41 |ory.. |. (DYNA|
00002680 4d 49 43 29 20 0a 52 4d 41 20 20 20 20 20 20 2d |MIC) .RMA -|
00002690 0a 0a 4e 45 58 54 20 20 2d 0a 20 20 20 20 20 20 |..NEXT -. |
000026a0 20 7c 09 2d 20 4d 6f 76 65 6d 65 6e 74 20 74 79 | |.- Movement ty|
000026b0 70 65 20 2d 20 65 69 74 68 65 72 20 67 65 74 20 |pe - either get |
000026c0 6e 65 78 74 20 6e 6f 64 65 20 6f 72 20 67 65 74 |next node or get|
000026d0 20 70 72 65 76 69 6f 75 73 0a 50 52 45 56 20 20 | previous.PREV |
000026e0 2d 0a 0a 4c 4e 55 4c 4c 09 09 2d 20 52 65 74 75 |-..LNULL..- Retu|
000026f0 72 6e 65 64 20 66 6f 72 20 6d 6f 73 74 20 72 6f |rned for most ro|
00002700 75 74 69 6e 65 73 20 77 68 65 6e 20 74 68 65 20 |utines when the |
00002710 6f 70 65 72 61 74 69 6f 6e 20 68 61 73 20 66 61 |operation has fa|
00002720 69 6c 65 64 2e 0a 0a 5f 5f 4e 4f 44 45 5f 49 4e |iled...__NODE_IN|
00002730 56 41 4c 49 44 09 2d 20 4e 6f 64 65 20 68 65 61 |VALID.- Node hea|
00002740 64 65 72 20 69 73 20 69 6e 76 61 6c 69 64 20 0a |der is invalid .|
00002750 5f 5f 4e 4f 44 45 5f 4e 4f 44 41 54 41 20 09 2d |__NODE_NODATA .-|
00002760 20 4e 6f 64 65 20 64 6f 65 73 6e 27 74 20 63 6f | Node doesn't co|
00002770 6e 74 61 69 6e 20 61 20 76 61 6c 69 64 20 64 61 |ntain a valid da|
00002780 74 61 20 70 6f 69 6e 74 65 72 20 20 0a 5f 5f 4e |ta pointer .__N|
00002790 4f 44 45 5f 49 4e 46 4c 4f 4f 50 09 2d 20 4e 6f |ODE_INFLOOP.- No|
000027a0 64 65 20 70 6f 69 6e 74 73 20 74 6f 20 69 74 73 |de points to its|
000027b0 65 6c 66 20 0a 5f 5f 44 41 54 41 5f 49 4e 56 41 |elf .__DATA_INVA|
000027c0 4c 49 44 20 09 2d 20 44 61 74 61 20 68 65 61 64 |LID .- Data head|
000027d0 65 72 20 69 73 20 69 6e 76 61 6c 69 64 0a 0a 4c |er is invalid..L|
000027e0 4e 55 4c 4c 20 64 65 6e 6f 74 65 73 20 66 61 69 |NULL denotes fai|
000027f0 6c 75 72 65 2c 20 61 6e 64 20 61 6e 79 20 20 6f |lure, and any o|
00002800 74 68 65 72 20 76 61 6c 75 65 20 64 65 6e 6f 74 |ther value denot|
00002810 65 73 20 73 75 63 63 65 73 73 2e 20 20 54 68 69 |es success. Thi|
00002820 73 20 64 6f 65 73 6e 27 74 0a 61 70 70 6c 79 20 |s doesn't.apply |
00002830 66 6f 72 20 64 65 6c 65 74 65 4c 69 73 74 2c 20 |for deleteList, |
00002840 77 68 69 63 68 20 72 65 74 75 72 6e 73 20 61 20 |which returns a |
00002850 76 61 6c 75 65 20 77 68 69 63 68 20 69 73 20 69 |value which is i|
00002860 67 6e 6f 72 65 64 2e 0a 0a 0a 36 2e 20 20 43 72 |gnored....6. Cr|
00002870 65 61 74 69 6e 67 20 61 20 4c 69 6e 6b 65 64 20 |eating a Linked |
00002880 4c 69 73 74 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |List.-----------|
00002890 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a |---------------.|
000028a0 0a 46 69 72 73 74 20 79 6f 75 20 6e 65 65 64 20 |.First you need |
000028b0 74 68 65 20 63 6f 72 72 65 63 74 20 68 65 61 64 |the correct head|
000028c0 65 72 73 20 3a 0a 0a 09 23 69 6e 63 6c 75 64 65 |ers :...#include|
000028d0 20 3c 54 79 70 65 73 2e 68 3e 0a 09 23 69 6e 63 | <Types.h>..#inc|
000028e0 6c 75 64 65 20 3c 4c 69 6e 6b 4c 69 73 74 2e 68 |lude <LinkList.h|
000028f0 3e 0a 09 0a 54 6f 20 63 72 65 61 74 65 20 61 20 |>...To create a |
00002900 4c 69 6e 6b 65 64 20 4c 69 73 74 2c 20 79 6f 75 |Linked List, you|
00002910 20 66 69 72 73 74 20 6e 65 65 64 20 74 6f 20 63 | first need to c|
00002920 72 65 61 74 65 20 61 20 52 6f 6f 74 2e 20 20 59 |reate a Root. Y|
00002930 6f 75 20 64 6f 20 74 68 69 73 20 75 73 69 6e 67 |ou do this using|
00002940 20 3a 0a 0a 09 4c 4f 4e 47 09 72 6f 6f 74 3d 30 | :...LONG.root=0|
00002950 3b 0a 09 0a 09 72 6f 6f 74 3d 63 72 65 61 74 65 |;....root=create|
00002960 4c 69 73 74 28 44 59 4e 41 4d 49 43 2c 73 69 7a |List(DYNAMIC,siz|
00002970 65 6f 66 28 5f 5f 52 4f 4f 54 29 29 3b 0a 09 69 |eof(__ROOT));..i|
00002980 66 20 28 72 6f 6f 74 3d 3d 4c 4e 55 4c 4c 29 0a |f (root==LNULL).|
00002990 09 7b 0a 09 09 70 72 69 6e 74 66 28 22 5c 6e 43 |.{...printf("\nC|
000029a0 61 6e 27 74 20 63 72 65 61 74 65 20 61 20 6c 69 |an't create a li|
000029b0 6e 6b 65 64 20 6c 69 73 74 22 29 3b 0a 09 09 72 |nked list");...r|
000029c0 65 74 75 72 6e 20 28 31 29 3b 0a 09 7d 20 0a 09 |eturn (1);..} ..|
000029d0 0a 4d 6f 73 74 20 66 75 6e 63 74 69 6f 6e 73 20 |.Most functions |
000029e0 65 78 70 65 63 74 20 70 61 72 61 6d 65 74 65 72 |expect parameter|
000029f0 20 6f 66 20 74 79 70 65 20 4c 4f 4e 47 2e 0a 0a | of type LONG...|
00002a00 59 6f 75 20 74 68 65 6e 20 6e 65 65 64 20 74 6f |You then need to|
00002a10 20 63 72 65 61 74 65 20 61 6e 20 61 72 72 61 79 | create an array|
00002a20 20 28 6f 72 20 70 72 65 66 65 72 61 62 6c 79 29 | (or preferably)|
00002a30 20 61 20 73 74 72 75 63 74 75 72 65 20 74 6f 20 | a structure to |
00002a40 68 6f 6c 64 20 79 6f 75 72 20 64 61 74 61 0a 3a |hold your data.:|
00002a50 0a 0a 09 73 74 72 75 63 74 20 7b 0a 09 09 69 6e |...struct {...in|
00002a60 74 20 63 6f 75 6e 74 3b 0a 09 09 63 68 61 72 20 |t count;...char |
00002a70 74 65 78 74 5b 36 5d 3b 0a 09 09 66 6c 6f 61 74 |text[6];...float|
00002a80 20 74 6f 74 61 6c 3b 0a 09 09 7d 20 65 78 61 6d | total;...} exam|
00002a90 70 6c 65 2c 73 6f 72 74 3b 0a 09 0a 41 6e 64 20 |ple,sort;...And |
00002aa0 73 65 74 20 75 70 20 74 68 65 20 61 72 72 61 79 |set up the array|
00002ab0 20 28 6f 72 20 73 74 72 75 63 74 75 72 65 20 61 | (or structure a|
00002ac0 63 63 6f 72 64 69 6e 67 6c 79 29 20 3a 0a 0a 09 |ccordingly) :...|
00002ad0 65 78 61 6d 70 6c 65 2e 63 6f 75 6e 74 3d 31 34 |example.count=14|
00002ae0 35 3b 0a 09 73 74 72 63 70 79 28 65 78 61 6d 70 |5;..strcpy(examp|
00002af0 6c 65 2e 74 65 78 74 2c 22 54 65 73 74 22 29 3b |le.text,"Test");|
00002b00 0a 09 65 78 61 6d 70 6c 65 2e 74 6f 74 61 6c 3d |..example.total=|
00002b10 30 2e 30 35 3b 0a 09 0a 41 6e 64 2c 20 69 66 20 |0.05;...And, if |
00002b20 61 6c 6c 20 69 73 20 77 65 6c 6c 2c 20 79 6f 75 |all is well, you|
00002b30 20 63 61 6e 20 61 64 64 20 74 68 65 20 65 78 61 | can add the exa|
00002b40 6d 70 6c 65 20 73 74 72 75 63 74 75 72 65 20 69 |mple structure i|
00002b50 6e 74 6f 20 74 68 65 20 4c 69 6e 6b 65 64 20 4c |nto the Linked L|
00002b60 69 73 74 20 3a 0a 0a 09 69 66 20 28 61 64 64 4e |ist :...if (addN|
00002b70 6f 64 65 28 46 49 52 53 54 2c 72 6f 6f 74 2c 0a |ode(FIRST,root,.|
00002b80 09 09 09 28 63 68 61 72 20 2a 29 20 26 65 78 61 |...(char *) &exa|
00002b90 6d 70 6c 65 2c 44 59 4e 41 4d 49 43 2c 73 69 7a |mple,DYNAMIC,siz|
00002ba0 65 6f 66 28 65 78 61 6d 70 6c 65 29 29 3d 3d 4c |eof(example))==L|
00002bb0 4e 55 4c 4c 29 09 0a 09 7b 0a 09 09 70 72 69 6e |NULL)...{...prin|
00002bc0 74 66 28 22 43 61 6e 27 74 20 63 72 65 61 74 65 |tf("Can't create|
00002bd0 20 61 20 6e 6f 64 65 21 22 29 3b 0a 09 09 64 65 | a node!");...de|
00002be0 6c 65 74 65 4c 69 73 74 28 72 6f 6f 74 29 3b 0a |leteList(root);.|
00002bf0 09 09 65 78 69 74 28 31 29 3b 0a 09 7d 0a 09 0a |..exit(1);..}...|
00002c00 54 68 65 20 46 49 52 53 54 20 63 6f 6e 73 74 61 |The FIRST consta|
00002c10 6e 74 73 20 74 65 6c 6c 73 20 74 68 65 20 72 6f |nts tells the ro|
00002c20 75 74 69 6e 65 20 74 6f 20 61 64 64 20 74 68 69 |utine to add thi|
00002c30 73 20 6e 6f 64 65 20 74 6f 20 74 68 65 20 62 65 |s node to the be|
00002c40 67 69 6e 69 6e 67 20 6f 66 20 74 68 65 0a 6c 69 |gining of the.li|
00002c50 73 74 2c 20 61 73 20 6f 70 70 6f 73 65 64 20 74 |st, as opposed t|
00002c60 6f 20 74 68 65 20 65 6e 64 2e 0a 0a 59 6f 75 20 |o the end...You |
00002c70 63 61 6e 20 6b 65 65 70 20 61 64 64 69 6e 67 20 |can keep adding |
00002c80 6e 6f 64 65 73 20 75 6e 74 69 6c 20 79 6f 75 72 |nodes until your|
00002c90 20 62 6c 75 65 20 69 6e 20 74 68 65 20 66 61 63 | blue in the fac|
00002ca0 65 20 28 6f 72 20 79 6f 75 20 72 75 6e 20 6f 75 |e (or you run ou|
00002cb0 74 20 6f 66 0a 6d 65 6d 6f 72 79 21 29 2e 2e 2e |t of.memory!)...|
00002cc0 0a 0a 54 6f 20 67 6f 20 74 68 72 6f 75 67 68 20 |..To go through |
00002cd0 65 61 63 68 20 6e 6f 64 65 2c 20 79 6f 75 20 6e |each node, you n|
00002ce0 65 65 64 20 74 6f 20 73 74 61 72 74 20 65 69 74 |eed to start eit|
00002cf0 68 65 72 20 61 74 20 74 68 65 20 62 65 67 69 6e |her at the begin|
00002d00 69 6e 67 20 6f 72 20 74 68 65 20 65 6e 64 20 3a |ing or the end :|
00002d10 0a 0a 09 6e 6f 64 65 3d 67 65 74 46 69 72 73 74 |...node=getFirst|
00002d20 28 72 6f 6f 74 29 3b 0a 0a 6f 72 0a 09 6e 6f 64 |(root);..or..nod|
00002d30 65 3d 67 65 74 4c 61 73 74 28 72 6f 6f 74 29 3b |e=getLast(root);|
00002d40 0a 09 0a 61 6e 64 20 74 68 65 6e 20 68 61 76 65 |...and then have|
00002d50 20 61 20 73 69 6d 70 6c 65 20 6c 6f 6f 70 2c 20 | a simple loop, |
00002d60 6c 69 6b 65 20 3a 0a 0a 09 77 68 69 6c 65 20 28 |like :...while (|
00002d70 6e 6f 64 65 21 3d 4c 4e 55 4c 4c 29 0a 09 7b 0a |node!=LNULL)..{.|
00002d80 09 09 3c 44 6f 20 79 6f 75 72 20 70 72 6f 63 65 |..<Do your proce|
00002d90 73 73 69 6e 67 20 68 65 72 65 3e 0a 09 09 0a 09 |ssing here>.....|
00002da0 09 6e 6f 64 65 3d 67 65 74 44 69 72 28 6e 6f 64 |.node=getDir(nod|
00002db0 65 2c 4e 45 58 54 29 3b 20 2f 2a 20 6f 72 2c 20 |e,NEXT); /* or, |
00002dc0 6e 6f 64 65 3d 67 65 74 44 69 72 28 6e 6f 64 65 |node=getDir(node|
00002dd0 2c 50 52 45 56 29 3b 20 2a 2f 0a 09 7d 0a 09 0a |,PREV); */..}...|
00002de0 54 6f 20 67 65 74 20 69 6e 66 6f 72 6d 61 74 69 |To get informati|
00002df0 6f 6e 20 6f 75 74 2c 20 79 6f 75 20 6e 65 65 64 |on out, you need|
00002e00 20 3a 0a 0a 09 69 66 20 28 67 65 74 55 73 65 72 | :...if (getUser|
00002e10 44 61 74 61 28 72 6f 6f 74 2c 6e 6f 64 65 2c 30 |Data(root,node,0|
00002e20 2c 73 69 7a 65 6f 66 28 64 75 6d 6d 79 29 2c 0a |,sizeof(dummy),.|
00002e30 09 09 09 28 63 68 61 72 20 2a 29 20 26 64 75 6d |...(char *) &dum|
00002e40 6d 79 2c 47 45 54 5f 44 41 54 41 29 3d 3d 4e 55 |my,GET_DATA)==NU|
00002e50 4c 4c 29 0a 20 20 20 20 20 20 20 20 7b 0a 20 20 |LL). {. |
00002e60 20 20 20 20 20 20 09 70 72 69 6e 74 66 28 22 43 | .printf("C|
00002e70 61 6e 27 74 20 67 65 74 20 68 6f 6c 64 20 6f 66 |an't get hold of|
00002e80 20 75 73 65 72 20 64 61 74 61 22 29 3b 0a 20 20 | user data");. |
00002e90 20 20 20 20 20 20 09 72 65 74 75 72 6e 20 28 31 | .return (1|
00002ea0 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 0a 54 6f |);. }..To|
00002eb0 20 73 6f 72 74 20 61 20 4c 69 6e 6b 65 64 20 4c | sort a Linked L|
00002ec0 69 73 74 20 3a 0a 0a 09 73 6f 72 74 4c 69 73 74 |ist :...sortList|
00002ed0 28 72 6f 6f 74 2c 73 6f 72 74 52 6f 75 74 69 6e |(root,sortRoutin|
00002ee0 65 29 3b 0a 09 0a 09 2e 2e 2e 0a 09 0a 09 7d 3b |e);...........};|
00002ef0 0a 09 0a 09 28 53 6f 72 74 20 62 79 20 74 6f 74 |....(Sort by tot|
00002f00 61 6c 29 0a 09 0a 09 69 6e 74 20 73 6f 72 74 52 |al)....int sortR|
00002f10 6f 75 74 69 6e 65 28 4c 4f 4e 47 20 6e 31 2c 4c |outine(LONG n1,L|
00002f20 4f 4e 47 20 6e 32 2c 4c 4f 4e 47 20 72 6f 6f 74 |ONG n2,LONG root|
00002f30 29 0a 09 7b 0a 09 63 68 61 72 20 62 75 66 66 65 |)..{..char buffe|
00002f40 72 41 5b 38 5d 2c 62 75 66 66 65 72 42 5b 38 5d |rA[8],bufferB[8]|
00002f50 3b 0a 09 0a 20 20 20 20 09 09 67 65 74 55 73 65 |;... ..getUse|
00002f60 72 44 61 74 61 28 72 6f 6f 74 2c 6e 31 2c 30 2c |rData(root,n1,0,|
00002f70 0a 20 20 20 20 09 09 09 09 73 69 7a 65 6f 66 28 |. ....sizeof(|
00002f80 62 75 66 66 65 72 41 29 2c 28 63 68 61 72 20 2a |bufferA),(char *|
00002f90 29 20 26 62 75 66 66 65 72 41 2c 47 45 54 5f 44 |) &bufferA,GET_D|
00002fa0 41 54 41 29 3b 0a 20 20 20 20 09 09 67 65 74 55 |ATA);. ..getU|
00002fb0 73 65 72 44 61 74 61 28 72 6f 6f 74 2c 6e 32 2c |serData(root,n2,|
00002fc0 30 2c 0a 20 20 20 20 09 09 09 09 73 69 7a 65 6f |0,. ....sizeo|
00002fd0 66 28 62 75 66 66 65 72 42 29 2c 28 63 68 61 72 |f(bufferB),(char|
00002fe0 20 2a 29 20 26 62 75 66 66 65 72 42 2c 47 45 54 | *) &bufferB,GET|
00002ff0 5f 44 41 54 41 29 3b 09 20 0a 20 20 20 20 09 09 |_DATA);. . ..|
00003000 72 65 74 75 72 6e 20 28 62 75 66 66 65 72 41 5b |return (bufferA[|
00003010 35 5d 3d 3d 62 75 66 66 65 72 42 5b 35 5d 20 3f |5]==bufferB[5] ?|
00003020 20 30 20 3a 20 5c 0a 20 20 20 20 09 20 20 20 20 | 0 : \. . |
00003030 09 09 09 62 75 66 66 65 72 41 5b 35 5d 3e 62 75 |...bufferA[5]>bu|
00003040 66 66 65 72 42 5b 35 5d 20 3f 20 31 20 3a 20 2d |fferB[5] ? 1 : -|
00003050 31 29 3b 0a 09 7d 0a 09 0a 41 6e 64 20 66 69 6e |1);..}...And fin|
00003060 61 6c 6c 79 2c 20 74 6f 20 64 65 6c 65 74 65 20 |ally, to delete |
00003070 74 68 65 20 4c 69 6e 6b 65 64 20 4c 69 73 74 20 |the Linked List |
00003080 3a 0a 0a 09 72 6f 6f 74 3d 64 65 6c 65 74 65 4c |:...root=deleteL|
00003090 69 73 74 28 72 6f 6f 74 29 3b 0a 0a 0a 37 2e 20 |ist(root);...7. |
000030a0 20 46 75 6c 6c 20 6c 69 73 74 20 6f 66 20 63 6f | Full list of co|
000030b0 6d 6d 61 6e 64 73 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d |mmands.---------|
000030c0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------|
000030d0 0a 0a 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 |..The following |
000030e0 69 73 20 61 20 66 75 6c 6c 20 6c 69 73 74 20 6f |is a full list o|
000030f0 66 20 6c 69 62 72 61 72 79 20 63 6f 6d 6d 61 6e |f library comman|
00003100 64 73 2e 20 20 54 68 6f 73 65 20 6d 61 72 6b 65 |ds. Those marke|
00003110 64 20 62 79 20 61 20 27 2a 27 0a 61 72 65 20 66 |d by a '*'.are f|
00003120 6f 72 20 69 6e 74 65 72 6e 61 6c 20 75 73 65 20 |or internal use |
00003130 6f 6e 6c 79 2c 20 61 6e 64 20 4d 55 53 54 20 4e |only, and MUST N|
00003140 4f 54 20 62 65 20 75 73 65 64 20 69 6e 20 79 6f |OT be used in yo|
00003150 75 72 20 6f 77 6e 20 70 72 6f 67 72 61 6d 73 2e |ur own programs.|
00003160 0a 0a 4c 4f 4e 47 20 5f 5f 61 6c 6c 6f 63 4d 65 |..LONG __allocMe|
00003170 6d 6f 72 79 28 4c 4f 4e 47 2c 4c 4f 4e 47 2c 4c |mory(LONG,LONG,L|
00003180 4f 4e 47 29 3b 20 20 20 20 20 20 20 20 20 20 20 |ONG); |
00003190 20 28 2a 29 0a 4c 4f 4e 47 20 5f 5f 64 65 6c 65 | (*).LONG __dele|
000031a0 74 65 4d 65 6d 6f 72 79 28 4c 4f 4e 47 29 3b 20 |teMemory(LONG); |
000031b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
000031c0 20 20 20 20 28 2a 29 0a 4c 4f 4e 47 20 5f 5f 61 | (*).LONG __a|
000031d0 64 64 4e 6f 64 65 28 4c 4f 4e 47 2c 4c 4f 4e 47 |ddNode(LONG,LONG|
000031e0 2c 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b 20 20 20 20 |,LONG,LONG); |
000031f0 20 20 20 20 20 20 20 28 2a 29 0a 4c 4f 4e 47 20 | (*).LONG |
00003200 5f 5f 64 65 6c 65 74 65 4e 6f 64 65 28 4c 4f 4e |__deleteNode(LON|
00003210 47 2c 4c 4f 4e 47 2c 4c 4f 4e 47 2c 4c 4f 4e 47 |G,LONG,LONG,LONG|
00003220 29 3b 20 20 20 20 20 20 20 20 28 2a 29 0a 4c 4f |); (*).LO|
00003230 4e 47 20 5f 5f 73 77 61 70 4e 6f 64 65 73 28 4c |NG __swapNodes(L|
00003240 4f 4e 47 2c 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b 20 |ONG,LONG,LONG); |
00003250 20 20 20 20 20 20 20 20 20 20 20 20 20 28 2a 29 | (*)|
00003260 0a 0a 4c 4f 4e 47 20 67 65 74 44 69 72 28 4c 4f |..LONG getDir(LO|
00003270 4e 47 2c 4c 4f 4e 47 29 3b 0a 4c 4f 4e 47 20 67 |NG,LONG);.LONG g|
00003280 65 74 55 73 65 72 44 61 74 61 28 4c 4f 4e 47 20 |etUserData(LONG |
00003290 72 6f 6f 74 2c 4c 4f 4e 47 20 6e 6f 64 65 2c 4c |root,LONG node,L|
000032a0 4f 4e 47 20 6f 66 66 73 65 74 2c 4c 4f 4e 47 20 |ONG offset,LONG |
000032b0 73 69 7a 65 2c 0a 20 20 20 20 09 20 20 20 20 09 |size,. . .|
000032c0 20 20 20 20 09 20 20 20 20 63 68 61 72 20 2a 62 | . char *b|
000032d0 75 66 66 65 72 2c 69 6e 74 20 74 79 70 65 29 3b |uffer,int type);|
000032e0 0a 20 20 20 20 09 20 20 20 20 09 20 20 20 20 09 |. . . .|
000032f0 20 20 20 20 0a 4c 4f 4e 47 20 63 72 65 61 74 65 | .LONG create|
00003300 4c 69 73 74 28 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b |List(LONG,LONG);|
00003310 0a 4c 4f 4e 47 20 61 64 64 4e 6f 64 65 28 69 6e |.LONG addNode(in|
00003320 74 20 77 68 65 72 65 2c 4c 4f 4e 47 20 72 6f 6f |t where,LONG roo|
00003330 74 2c 63 68 61 72 20 2a 74 65 78 74 2c 69 6e 74 |t,char *text,int|
00003340 20 74 79 70 65 2c 4c 4f 4e 47 20 73 69 7a 65 29 | type,LONG size)|
00003350 3b 0a 4c 4f 4e 47 20 64 65 6c 65 74 65 4c 69 73 |;.LONG deleteLis|
00003360 74 28 4c 4f 4e 47 29 3b 0a 4c 4f 4e 47 20 64 65 |t(LONG);.LONG de|
00003370 6c 65 74 65 43 75 72 72 65 6e 74 4e 6f 64 65 28 |leteCurrentNode(|
00003380 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b 0a 4c 4f 4e 47 |LONG,LONG);.LONG|
00003390 20 64 65 6c 65 74 65 49 6e 64 65 78 4e 6f 64 65 | deleteIndexNode|
000033a0 28 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b 0a 4c 4f 4e |(LONG,LONG);.LON|
000033b0 47 20 64 65 6c 65 74 65 4e 75 6d 62 65 72 4e 6f |G deleteNumberNo|
000033c0 64 65 28 4c 4f 4e 47 2c 4c 4f 4e 47 29 3b 0a 4c |de(LONG,LONG);.L|
000033d0 4f 4e 47 20 72 65 6e 75 6d 62 65 72 4e 6f 64 65 |ONG renumberNode|
000033e0 73 28 4c 4f 4e 47 29 3b 0a 76 6f 69 64 20 67 65 |s(LONG);.void ge|
000033f0 74 53 74 61 74 75 73 28 46 49 4c 45 20 2a 68 61 |tStatus(FILE *ha|
00003400 6e 64 6c 65 2c 4c 4f 4e 47 20 72 6f 6f 74 29 3b |ndle,LONG root);|
00003410 0a 4c 4f 4e 47 20 67 65 74 44 69 72 28 4c 4f 4e |.LONG getDir(LON|
00003420 47 2c 4c 4f 4e 47 29 3b 0a 4c 4f 4e 47 20 67 65 |G,LONG);.LONG ge|
00003430 74 46 69 72 73 74 4c 61 73 74 28 4c 4f 4e 47 2c |tFirstLast(LONG,|
00003440 4c 4f 4e 47 29 3b 0a 4c 4f 4e 47 20 67 65 74 55 |LONG);.LONG getU|
00003450 73 65 72 44 61 74 61 28 4c 4f 4e 47 20 72 6f 6f |serData(LONG roo|
00003460 74 2c 4c 4f 4e 47 20 6e 6f 64 65 2c 4c 4f 4e 47 |t,LONG node,LONG|
00003470 20 6f 66 66 73 65 74 2c 4c 4f 4e 47 20 73 69 7a | offset,LONG siz|
00003480 65 2c 63 68 61 72 20 2a 62 75 66 66 65 72 2c 0a |e,char *buffer,.|
00003490 20 20 20 20 09 20 20 20 20 09 20 69 6e 74 20 74 | . . int t|
000034a0 79 70 65 29 3b 0a 4c 4f 4e 47 20 73 6f 72 74 4c |ype);.LONG sortL|
000034b0 69 73 74 28 4c 4f 4e 47 20 72 6f 6f 74 2c 0a 20 |ist(LONG root,. |
000034c0 20 20 20 09 20 20 20 20 09 20 69 6e 74 20 28 2a | . . int (*|
000034d0 72 6f 75 74 69 6e 65 29 20 28 4c 4f 4e 47 20 6e |routine) (LONG n|
000034e0 31 2c 4c 4f 4e 47 20 6e 32 2c 4c 4f 4e 47 20 72 |1,LONG n2,LONG r|
000034f0 6f 6f 74 29 29 3b 0a 4c 4f 4e 47 20 6e 75 6d 62 |oot));.LONG numb|
00003500 65 72 4f 66 4e 6f 64 65 73 28 4c 4f 4e 47 29 3b |erOfNodes(LONG);|
00003510 0a 4c 4f 4e 47 20 6e 6f 64 65 49 6e 66 6f 28 4c |.LONG nodeInfo(L|
00003520 4f 4e 47 20 72 6f 6f 74 2c 4c 4f 4e 47 20 6e 6f |ONG root,LONG no|
00003530 64 65 5f 61 64 64 72 2c 4c 4f 4e 47 20 6e 75 6d |de_addr,LONG num|
00003540 62 65 72 2c 46 49 4c 45 20 2a 68 61 6e 64 6c 65 |ber,FILE *handle|
00003550 29 3b 0a 4c 4f 4e 47 20 66 69 6e 64 41 4e 75 6d |);.LONG findANum|
00003560 62 65 72 4e 6f 64 65 28 4c 4f 4e 47 2c 4c 4f 4e |berNode(LONG,LON|
00003570 47 29 3b 0a 4c 4f 4e 47 20 66 69 6e 64 41 49 6e |G);.LONG findAIn|
00003580 64 65 78 4e 6f 64 65 28 4c 4f 4e 47 2c 4c 4f 4e |dexNode(LONG,LON|
00003590 47 2c 4c 4f 4e 47 29 3b 0a 09 0a 54 68 65 20 44 |G,LONG);...The D|
000035a0 69 73 63 6c 61 69 6d 65 72 0a 2d 2d 2d 2d 2d 2d |isclaimer.------|
000035b0 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 49 20 61 63 63 65 |--------..I acce|
000035c0 70 74 20 6e 6f 20 72 65 73 70 6f 6e 73 69 62 69 |pt no responsibi|
000035d0 6c 69 74 79 20 66 6f 72 20 61 6e 79 20 75 73 65 |lity for any use|
000035e0 20 6f 72 20 6d 69 73 75 73 65 20 74 68 69 73 20 | or misuse this |
000035f0 6c 69 62 72 61 72 79 20 72 6f 75 74 69 6e 65 20 |library routine |
00003600 69 73 20 75 73 65 64 0a 66 6f 72 2e 20 20 57 68 |is used.for. Wh|
00003610 69 6c 73 74 20 74 68 69 73 20 70 72 6f 67 72 61 |ilst this progra|
00003620 6d 20 69 73 20 46 52 45 45 57 41 52 45 2c 20 49 |m is FREEWARE, I|
00003630 20 72 65 74 61 69 6e 20 66 75 6c 6c 20 63 6f 70 | retain full cop|
00003640 79 72 69 67 68 74 20 6f 76 65 72 20 74 68 65 20 |yright over the |
00003650 73 6f 75 72 63 65 0a 63 6f 64 65 2c 20 6c 69 62 |source.code, lib|
00003660 72 61 72 79 20 63 6f 64 65 20 61 6e 64 20 64 6f |rary code and do|
00003670 63 75 6d 65 6e 74 61 74 69 6f 6e 2e 0a 0a 59 6f |cumentation...Yo|
00003680 75 20 6d 61 79 20 6e 6f 74 20 72 65 76 65 72 73 |u may not revers|
00003690 65 20 65 6e 67 69 6e 65 65 72 2c 20 6d 6f 64 69 |e engineer, modi|
000036a0 66 79 2c 20 61 70 70 65 6e 64 20 74 6f 20 6f 72 |fy, append to or|
000036b0 20 72 65 6d 6f 76 65 20 66 72 6f 6d 20 61 6e 79 | remove from any|
000036c0 20 70 61 72 74 20 6f 66 0a 74 68 69 73 20 6c 69 | part of.this li|
000036d0 62 72 61 72 79 20 72 6f 75 74 69 6e 65 2e 0a 0a |brary routine...|
000036e0 4e 6f 20 4d 61 72 74 69 61 6e 73 20 77 65 72 65 |No Martians were|
000036f0 20 68 61 72 6d 65 64 20 69 6e 20 74 68 65 20 6d | harmed in the m|
00003700 61 6b 69 6e 67 20 6f 66 20 74 68 65 20 6c 69 62 |aking of the lib|
00003710 72 61 72 79 20 72 6f 75 74 69 6e 65 2e 0a 0a 41 |rary routine...A|
00003720 6c 6c 20 70 65 6f 70 6c 65 20 6d 65 6e 74 69 6f |ll people mentio|
00003730 6e 65 64 20 69 6e 20 74 68 69 73 20 64 6f 63 75 |ned in this docu|
00003740 6d 65 6e 74 61 74 69 6f 6e 20 61 72 65 20 66 69 |mentation are fi|
00003750 63 74 69 74 69 6f 75 73 2e 20 20 41 6e 79 20 72 |ctitious. Any r|
00003760 65 73 65 6d 62 6c 61 6e 63 65 20 74 6f 20 61 6e |esemblance to an|
00003770 79 0a 70 65 72 73 6f 6e 73 20 6c 69 76 69 6e 67 |y.persons living|
00003780 2c 20 64 65 61 64 20 6f 72 20 76 69 73 69 74 69 |, dead or visiti|
00003790 6e 67 20 66 72 69 65 6e 64 73 20 6f 6e 20 4d 61 |ng friends on Ma|
000037a0 72 73 20 61 72 65 20 70 75 72 65 6c 79 20 63 6f |rs are purely co|
000037b0 69 6e 63 69 64 65 6e 74 61 6c 2e 0a 0a 28 43 29 |incidental...(C)|
000037c0 20 4e 69 63 68 6f 6c 61 73 20 4a 2e 20 4b 69 6e | Nicholas J. Kin|
000037d0 67 73 6c 65 79 20 20 42 73 63 20 31 39 39 38 0a |gsley Bsc 1998.|
000037e0 0a 50 6c 65 61 73 65 20 62 75 67 20 72 65 70 6f |.Please bug repo|
000037f0 72 74 73 20 61 6e 64 20 63 6f 6d 6d 65 6e 74 73 |rts and comments|
00003800 20 74 6f 20 4e 69 63 68 6f 6c 61 73 20 4b 69 6e | to Nicholas Kin|
00003810 67 73 6c 65 79 2c 20 0a 45 2d 4d 61 69 6c 20 61 |gsley, .E-Mail a|
00003820 64 64 72 65 73 73 20 3a 20 6e 69 63 68 6b 40 61 |ddress : nichk@a|
00003830 72 67 6f 6e 65 74 2e 63 6f 2e 75 6b 0a 0a 41 74 |rgonet.co.uk..At|
00003840 20 74 68 69 73 20 74 69 6d 65 20 6e 6f 20 62 75 | this time no bu|
00003850 67 73 20 61 72 65 20 6b 6e 6f 77 6e 20 74 6f 20 |gs are known to |
00003860 65 78 69 73 74 2e 0a 0a 2a 2a 2a 20 46 69 6c 65 |exist...*** File|
00003870 20 65 6e 64 73 20 2a 2a 2a | ends ***|
00003879
.