iam-git / ArLan (public) (License: MIT) (since 2021-11-13) (hash sha1)
ArLan is an gopher client for Amiga flavour OSes (originally for AROS). Written in freepascal.

/doublelinked.pas (6c8ad90e7583d80c442f3e6d2abbfeeba6ce016a) (2379 bytes) (mode 100755) (type blob)

// Simplified DoubleLinkedList of Records
// I am <ger-alex@seznam.cz>
//
// LICENSE: both BSD or MIT
//
// Have no idea how exactly Pascal
// handles AnsiStrings
// and if there is any point to
// implement DoubleLinkedList
// whereas Pascal anyway will run throught
// to count references
unit doublelinked;
{$mode objfpc}{$H+}

interface

type
  // copypasted from arlan.pas
  TItem = record
    ItemType: char;
    DisplayString: string;
    Selector: string;
    HostName: string;
    Port: UInt16;
  end;

  PNode = ^TNode;
  TNode = Record
    Item: TItem;
    PreviousNodePtr: PNode;
    NextNodePtr: PNode;
  End;

  TDLinkedList = class
  public
    FirstNodePtr: PNode;
    CurrentNodePtr: PNode;
    procedure Insert(const Item: TItem);
    function MoveBack: TItem;
    function MoveForward: TItem;
    constructor Create(const Item: TItem);
    destructor Destroy;
  end;



implementation

constructor TDLinkedList.Create(const Item: TItem);
begin
  New(CurrentNodePtr);
  CurrentNodePtr^.Item := Item;
  CurrentNodePtr^.PreviousNodePtr := nil;
  CurrentNodePtr^.NextNodePtr := nil;
  FirstNodePtr := CurrentNodePtr;
end;

destructor TDLinkedList.Destroy;
var
NodePtr: PNode;
NextPtr: PNode;
begin
  NodePtr := FirstNodePtr;
  NextPtr := NodePtr^.NextNodePtr;
  while Assigned(NextPtr) do
  begin
    //cz zvladne Pascal se v tom vyznat?
    //cz Skutecne vynulovat retezce
    //cz a uvolnit pamet?
    Dispose(NodePtr);
    NodePtr := NextPtr;
    NextPtr := NodePtr^.NextNodePtr;
  end;
  Dispose(NodePtr);
end;

procedure TDLinkedList.Insert(const Item: TItem);
var
  NodePtr: PNode;
begin
  New(NodePtr);
  NodePtr^.Item := Item;
  NodePtr^.PreviousNodePtr := CurrentNodePtr;
  NodePtr^.NextNodePtr := CurrentNodePtr^.NextNodePtr;
  CurrentNodePtr^.NextNodePtr := NodePtr;
  CurrentNodePtr := NodePtr;
  NodePtr := CurrentNodePtr^.NextNodePtr;
  NodePtr^.PreviousNodePtr := CurrentNodePtr;
end;

function TDLinkedList.MoveBack: TItem;
var
  PreviousPtr: PNode;
begin
  PreviousPtr := CurrentNodePtr^.PreviousNodePtr;
  if Assigned(PreviousPtr) then
    CurrentNodePtr := PreviousPtr;
  Result := CurrentNodePtr^.Item
end;

function TDLinkedList.MoveForward: TItem;
var
  NextPtr: PNode;
begin
  NextPtr := CurrentNodePtr^.NextNodePtr;
  if Assigned(NextPtr) then
    CurrentNodePtr := CurrentNodePtr^.NextNodePtr;
  Result := CurrentNodePtr^.Item
end;

end.



Mode Type Size Ref File
100755 blob 541 4b340345c4ae30c28b68b5d45dd255e6c6531ed2 ReadMe
100755 blob 17800 0978a58982f582f25a7ecf07180e5e291bc5f8e3 arlan.pas
100755 blob 2379 6c8ad90e7583d80c442f3e6d2abbfeeba6ce016a doublelinked.pas
100755 blob 3123 9f5f66755008c22abc8d9d706be723bed977474b misc.pas
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/ArLan

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/ArLan

Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/ArLan

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main