BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
rilinkedlistlib.c File Reference
#include "blitzlib.h"

Data Structures

struct  node

Macros

#define TOK_copybyte   ((LIB_riamosfunclib << 7) + 10)
#define NODESIZE   sizeof(struct node)
#define NODE(a)
#define VARSIZEW(var)
#define TAB(t)

Functions

void _initlist (void)
void _addlistitem (void)
void _setlistitem (void)
void rilinkedlistlib_nextlistitem (void)
void _getlistitem (void)
void _prevlistitem (void)
void _firstlistitem (void)
void _lastlistitem (void)
void _addfirstitem (void)
void _addlastitem (void)
void _dellistitem (void)
void _addrlistitem (void)
void _sizeoflistitem (void)
void rilinkedlistlib_libinit (void)
void rilinkedlistlib_libfinit (void)
void listnumchk (void)
static ULONG globalloc (ULONG size)
static void globfree (ULONG mem, ULONG size)
static void copybyte (ULONG src, ULONG dest, ULONG n)
static ULONG getvarsize (ULONG var)
static void c_libinit (void)
 init: clears the tables.
static ULONG c_libfinit (void)
 finit: nothing (the lists are not freed).
ULONG c_sizeoflistitem (ULONG var)
 SizeOfListItem(var): the size of a variable as the list commands copy it.
ULONG c_addrlistitem (ULONG list)
 AddrListItem(list#): the address of the current node of a list.
static void freelist (void)
BB_BOOL c_initlist (ULONG list, ULONG var)
 InitList list#,var: start a list with one node holding a copy of var.
BB_BOOL c_addlistitem (ULONG list)
 AddListItem list#: a new empty node behind the current one, then the current one.
BB_BOOL c_setlistitem (ULONG list, ULONG var)
 SetListItem list#,var: a new copy of var for the current node.
BB_BOOL c_getlistitem (ULONG list, ULONG var)
 GetListItem list#,var: copy the current node's data into var.
BB_BOOL c_nextlistitem (ULONG list)
 NextListItem list#: make the next node the current one.
BB_BOOL c_prevlistitem (ULONG list)
 PrevListItem list#: make the previous node the current one.
BB_BOOL c_firstlistitem (ULONG list)
 FirstListItem list#: make the first node the current one.
BB_BOOL c_lastlistitem (ULONG list)
 LastListItem list#: make the last node the current one.
BB_BOOL c_addlastitem (ULONG list)
 AddLastListItem list#: a new empty node at the end (LastListItem, then AddListItem).
BB_BOOL c_addfirstitem (ULONG list)
 AddFirstListItem list#: a new node in front of the first one, then the current one.
BB_BOOL c_dellistitem (ULONG list)
 DelListItem list#: delete the current node; the next (or previous) becomes the current one.
static void listnumchk_c (ULONG list)
 The error check of the commands with a list number (debugger only).

Variables

struct { 
   ULONG   first [5] 
   ULONG   last [5] 
   ULONG   sizes [5] 
   ULONG   current [5] 
} tables
static ULONG nodeptr
static ULONG _oldnext
static ULONG _next
static ULONG _prev
static ULONG _data
static ULONG myvar
static ULONG _size
static ULONG listnum

Macro Definition Documentation

◆ NODE

#define NODE ( a)
Value:
((struct node *)(a))
Definition rilinkedlistlib.c:206

◆ NODESIZE

#define NODESIZE   sizeof(struct node)

◆ TAB

#define TAB ( t)
Value:
(*(ULONG *)((UBYTE *)tables.t + listnum))
static struct @356227200227300025147054014106273231161070367227 tables
static ULONG listnum
Definition rilinkedlistlib.c:230

◆ TOK_copybyte

#define TOK_copybyte   ((LIB_riamosfunclib << 7) + 10)

◆ VARSIZEW

#define VARSIZEW ( var)
Value:
(*(UWORD *)((var) - 2))

Function Documentation

◆ _addfirstitem()

void _addfirstitem ( void )

◆ _addlastitem()

void _addlastitem ( void )

◆ _addlistitem()

void _addlistitem ( void )

◆ _addrlistitem()

void _addrlistitem ( void )

◆ _dellistitem()

void _dellistitem ( void )

◆ _firstlistitem()

void _firstlistitem ( void )

◆ _getlistitem()

void _getlistitem ( void )

◆ _initlist()

void _initlist ( void )

◆ _lastlistitem()

void _lastlistitem ( void )

◆ _prevlistitem()

void _prevlistitem ( void )

◆ _setlistitem()

void _setlistitem ( void )

◆ _sizeoflistitem()

void _sizeoflistitem ( void )

◆ c_addfirstitem()

BB_BOOL c_addfirstitem ( ULONG list)

AddFirstListItem list#: a new node in front of the first one, then the current one.

Fixed (#733): without a first node (no list) 0, before anything is allocated; it does not start a list (the manual: "0 indicates failure (no list/no RAM)"; the original wrote the new node to address 0 and left the last node 0). Fixed (#724): the new node becomes the prev of the old first node (the original wrote it into that node's next: the list became a loop). Fixed (#725): the result is -1, as the manual says (the original returned list# * 4, 0 for list 0). Fixed (#726): prev, pad, data and size of the new node are cleared (the original left them as the allocation, flags 0, left them).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE without a list or memory

◆ c_addlastitem()

BB_BOOL c_addlastitem ( ULONG list)

AddLastListItem list#: a new empty node at the end (LastListItem, then AddListItem).

Parameters
listd0: list# (0-4)
Returns
d0: as AddListItem (BB_FALSE without a list, fixed #733)

◆ c_addlistitem()

BB_BOOL c_addlistitem ( ULONG list)

AddListItem list#: a new empty node behind the current one, then the current one.

list# is checked by listnumchk (#732). Fixed (#733): without a current node (no list) 0, before anything is allocated (the original read and wrote from address 0 on). Fixed (#727): the prev of the node behind the new one is the new node (the original left it pointing to the current one). Fixed (#735): the new node's data and size are 0 (the original's size field was the last size any command looked at).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE without a list or memory

◆ c_addrlistitem()

ULONG c_addrlistitem ( ULONG list)

AddrListItem(list#): the address of the current node of a list.

A list# outside 0..4 is refused by listnumchk with runtime error checking (fixed, #732); the release code does not check it.

Parameters
listd0: list# (0-4)
Returns
d0: the current node (struct node), 0 if there is none

◆ c_dellistitem()

BB_BOOL c_dellistitem ( ULONG list)

DelListItem list#: delete the current node; the next (or previous) becomes the current one.

It sets the last size to that of the node, which no node takes over since #735 (AddListItem stores 0). Fixed (#729): it reads the node of v0.91 and frees the copy with the node (the original read the node of v0.9: its data was the long at +8, the pad and the upper word of the data pointer, so it freed a wrong address, memlib: "Unable to Free Memory", and the copy was lost); the only node is not deleted and keeps its copy: 0 (no defect; the original freed the "data" before it looked). Fixed (#728): deleting the first node clears the prev of the node behind it (the original cleared its next: the list ended there).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE without a current node or for the only node

◆ c_firstlistitem()

BB_BOOL c_firstlistitem ( ULONG list)

FirstListItem list#: make the first node the current one.

Fixed (#733): without a list 0, as the manual says ("0 indicates failure (no list)"; the original returned -1 always).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE without a list

◆ c_getlistitem()

BB_BOOL c_getlistitem ( ULONG list,
ULONG var )

GetListItem list#,var: copy the current node's data into var.

Fixed (#733): without a current node (no list) 0 (the original copied from the pointer at address 10). Fixed (#730): it copies the smaller of the variable's size and the node's size field, the rest of a larger variable stays as it is (the original copied as many bytes as the variable has, also what lay behind the copy).

Parameters
listd0: list# (0-4)
vard1: the variable (BL_VARPTR)
Returns
d0: BB_TRUE, BB_FALSE without a list or if the node has no data

◆ c_initlist()

BB_BOOL c_initlist ( ULONG list,
ULONG var )

InitList list#,var: start a list with one node holding a copy of var.

The node and the copy are memlib globalloc'ed (flags 0), the copy is made by RIAmosFuncLib's CopyByte; list# is checked by listnumchk (#732), the size as in SizeOfListItem (#736). Fixed (#731): a list that is already there is freed first, its nodes and their copies (the original overwrote the entries: they were lost until the end).

Parameters
listd0: list# (0-4)
vard1: the variable (BL_VARPTR)
Returns
d0: BB_TRUE, BB_FALSE if there is no memory (the node is freed again, the list cleared)

◆ c_lastlistitem()

BB_BOOL c_lastlistitem ( ULONG list)

LastListItem list#: make the last node the current one.

Fixed (#733): without a list 0, as the manual says ("0 indicates failure (no list)"; the original returned -1 always).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE without a list

◆ c_libfinit()

ULONG c_libfinit ( void )
static

finit: nothing (the lists are not freed).

Returns
d0: 0

◆ c_libinit()

void c_libinit ( void )
static

init: clears the tables.

Fixed (#733): the original's init did nothing, and its tables keep the nodes of a run before (memlib frees them at its end) when a program is run again with the library still loaded; the commands that now test for a list would take those freed nodes for one.

◆ c_nextlistitem()

BB_BOOL c_nextlistitem ( ULONG list)

NextListItem list#: make the next node the current one.

Fixed (#733): without a current node (no list) 0 (the original took the long at address 0 as the next node).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE at the end (the current node stays) or without a list

◆ c_prevlistitem()

BB_BOOL c_prevlistitem ( ULONG list)

PrevListItem list#: make the previous node the current one.

Fixed (#733): without a current node (no list) 0 (the original took the long at address 4, ExecBase, as the previous node).

Parameters
listd0: list# (0-4)
Returns
d0: BB_TRUE, BB_FALSE at the start (the current node stays) or without a list

◆ c_setlistitem()

BB_BOOL c_setlistitem ( ULONG list,
ULONG var )

SetListItem list#,var: a new copy of var for the current node.

Fixed (#733): without a current node (no list) 0, before anything is allocated (the original wrote the copy's address to address 10). Fixed (#734): the node's old copy is freed once the new one is allocated (the original did not free it; without memory the old copy stays). Fixed (#735): the size field is the new copy's size (the original left it as it was).

Parameters
listd0: list# (0-4)
vard1: the variable (BL_VARPTR)
Returns
d0: BB_TRUE, BB_FALSE without a list or memory

◆ c_sizeoflistitem()

ULONG c_sizeoflistitem ( ULONG var)

SizeOfListItem(var): the size of a variable as the list commands copy it.

The word in front of the variable minus 8 (getvarsize); also sets the "last size" the other commands use. No defect (#736, see the file's head): a word of less than 8 would give almost 4 GB, but no NEWTYPE variable has one; exactly 8 gives a size of 0, for which CopyByte copies nothing (since #492).

Parameters
vard0: the variable (BL_VARPTR)
Returns
d0: the size

◆ copybyte()

void copybyte ( ULONG src,
ULONG dest,
ULONG n )
static

◆ freelist()

void freelist ( void )
static

◆ getvarsize()

ULONG getvarsize ( ULONG var)
static

◆ globalloc()

ULONG globalloc ( ULONG size)
static

◆ globfree()

void globfree ( ULONG mem,
ULONG size )
static

◆ listnumchk()

void listnumchk ( void )

◆ listnumchk_c()

void listnumchk_c ( ULONG list)
static

The error check of the commands with a list number (debugger only).

Fixed (#732), not in the original (rilinkedlistlib had no error check area): list# * 4 indexes the tables of five longs without a check, so a list number outside 0..4 made the commands read and write the other tables and the data behind them (the manual: "Do NOT use list numbers of 5 or higher!"). The release code is unchanged (an invalid argument).

Errors: "List number must be 0 to 4".

Parameters
listd0: list#

◆ rilinkedlistlib_libfinit()

void rilinkedlistlib_libfinit ( void )

◆ rilinkedlistlib_libinit()

void rilinkedlistlib_libinit ( void )

◆ rilinkedlistlib_nextlistitem()

void rilinkedlistlib_nextlistitem ( void )

Variable Documentation

◆ _data

ULONG _data
static

◆ _next

ULONG _next
static

◆ _oldnext

ULONG _oldnext
static

◆ _prev

ULONG _prev
static

◆ _size

ULONG _size
static

◆ current

ULONG current[5]

◆ first

ULONG first[5]

◆ last

ULONG last[5]

◆ listnum

ULONG listnum
static

◆ myvar

ULONG myvar
static

◆ nodeptr

ULONG nodeptr
static

◆ sizes

ULONG sizes[5]

◆ [struct]

struct { ... } tables