| 1 |
(* Lists.def provides an unordered list manipulation package. |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
DEFINITION MODULE Lists ; |
| 23 |
|
| 24 |
(* |
| 25 |
Author : Gaius Mulley |
| 26 |
Title : Lists |
| 27 |
Date : Tue Dec 12 20:53:36 EST 1989 |
| 28 |
SYSTEM : UNIX (GNU Modula-2) |
| 29 |
Description: Provides an unordered list manipulation package. |
| 30 |
Last update: $Date: 2010/10/03 19:01:05 $ |
| 31 |
Version : $Revision: 1.9 $ |
| 32 |
*) |
| 33 |
|
| 34 |
FROM SYSTEM IMPORT WORD ; |
| 35 |
FROM SymbolKey IMPORT PerformOperation ; |
| 36 |
|
| 37 |
EXPORT QUALIFIED List, |
| 38 |
InitList, KillList, PutItemIntoList, GetItemFromList, |
| 39 |
GetIndexOfList, |
| 40 |
NoOfItemsInList, IsItemInList, IncludeItemIntoList, |
| 41 |
RemoveItemFromList, ForeachItemInListDo, DuplicateList ; |
| 42 |
|
| 43 |
TYPE |
| 44 |
List ; |
| 45 |
|
| 46 |
|
| 47 |
(* |
| 48 |
InitList - creates a new list, l. |
| 49 |
*) |
| 50 |
|
| 51 |
PROCEDURE InitList (VAR l: List) ; |
| 52 |
|
| 53 |
|
| 54 |
(* |
| 55 |
KillList - deletes the complete list, l. |
| 56 |
*) |
| 57 |
|
| 58 |
PROCEDURE KillList (VAR l: List) ; |
| 59 |
|
| 60 |
|
| 61 |
(* |
| 62 |
PutItemIntoList - places a CARDINAL, c, into list, l. |
| 63 |
*) |
| 64 |
|
| 65 |
PROCEDURE PutItemIntoList (l: List; c: WORD) ; |
| 66 |
|
| 67 |
|
| 68 |
(* |
| 69 |
GetItemFromList - retrieves the nth WORD from list, l. |
| 70 |
*) |
| 71 |
|
| 72 |
PROCEDURE GetItemFromList (l: List; n: CARDINAL) : WORD ; |
| 73 |
|
| 74 |
|
| 75 |
(* |
| 76 |
GetIndexOfList - returns the index for WORD, c, in list, l. |
| 77 |
If more than one CARDINAL, c, exists the index |
| 78 |
for the first is returned. |
| 79 |
*) |
| 80 |
|
| 81 |
PROCEDURE GetIndexOfList (l: List; c: WORD) : CARDINAL ; |
| 82 |
|
| 83 |
|
| 84 |
(* |
| 85 |
NoOfItemsInList - returns the number of items in list, l. |
| 86 |
*) |
| 87 |
|
| 88 |
PROCEDURE NoOfItemsInList (l: List) : CARDINAL ; |
| 89 |
|
| 90 |
|
| 91 |
(* |
| 92 |
IncludeItemIntoList - adds a WORD, c, into a list providing |
| 93 |
the value does not already exist. |
| 94 |
*) |
| 95 |
|
| 96 |
PROCEDURE IncludeItemIntoList (l: List; c: WORD) ; |
| 97 |
|
| 98 |
|
| 99 |
(* |
| 100 |
RemoveItemFromList - removes a WORD, c, from a list. |
| 101 |
It assumes that this value only appears once. |
| 102 |
*) |
| 103 |
|
| 104 |
PROCEDURE RemoveItemFromList (l: List; c: WORD) ; |
| 105 |
|
| 106 |
|
| 107 |
(* |
| 108 |
IsItemInList - returns true if a WORD, c, was found in list, l. |
| 109 |
*) |
| 110 |
|
| 111 |
PROCEDURE IsItemInList (l: List; c: WORD) : BOOLEAN ; |
| 112 |
|
| 113 |
|
| 114 |
(* |
| 115 |
ForeachItemInListDo - calls procedure, P, foreach item in list, l. |
| 116 |
*) |
| 117 |
|
| 118 |
PROCEDURE ForeachItemInListDo (l: List; P: PerformOperation) ; |
| 119 |
|
| 120 |
|
| 121 |
(* |
| 122 |
DuplicateList - returns a duplicate list derived from, l. |
| 123 |
*) |
| 124 |
|
| 125 |
PROCEDURE DuplicateList (l: List) : List ; |
| 126 |
|
| 127 |
|
| 128 |
END Lists. |