(* Dynamic list library for pointers.
Copyright (C) 2015-2025 Free Software Foundation, Inc.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
. *)
IMPLEMENTATION MODULE lists ;
FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
CONST
MaxnoOfelements = 5 ;
TYPE
list = POINTER TO RECORD
noOfelements: CARDINAL ;
elements : ARRAY [1..MaxnoOfelements] OF ADDRESS ;
next : list ;
END ;
(*
initList - creates a new list, l.
*)
PROCEDURE initList () : list ;
VAR
l: list ;
BEGIN
NEW (l) ;
WITH l^ DO
noOfelements := 0 ;
next := NIL
END ;
RETURN l
END initList ;
(*
killList - deletes the complete list, l.
*)
PROCEDURE killList (VAR l: list) ;
BEGIN
IF l#NIL
THEN
IF l^.next#NIL
THEN
killList (l^.next)
END ;
DISPOSE (l)
END
END killList ;
(*
putItemIntoList - places an ADDRESS, c, into list, l.
*)
PROCEDURE putItemIntoList (l: list; c: ADDRESS) ;
BEGIN
WITH l^ DO
IF noOfelements