~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/packages/extra/amunits/demos/listtest.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
PROGRAM test;
 
2
 
 
3
{
 
4
    A small test of linklist unit.
 
5
 
 
6
    nils.sjoholm@mailbox.swipnet.se
 
7
}
 
8
 
 
9
uses
 
10
{$ifdef Amiga}
 
11
    exec,
 
12
{$endif}
 
13
    linklist, strings;
 
14
 
 
15
    VAR
 
16
 
 
17
    Mylist   : pList;
 
18
    MyNode   : pFPCNode;
 
19
    i        : Longint;
 
20
    temp     : Longint;
 
21
    buffer   : PChar;
 
22
    bufsize  : Longint;
 
23
    templist : pList;
 
24
 
 
25
 
 
26
BEGIN
 
27
    CreateList(Mylist);
 
28
 
 
29
    AddNewNode(Mylist,'Monday');
 
30
    AddNewNode(Mylist,'Tuesday');
 
31
    AddNewNode(Mylist,'Wednesday');
 
32
    AddNewNode(Mylist,'Thursday');
 
33
    AddNewNode(Mylist,'Friday');
 
34
    AddNewNode(Mylist,'Saterday');
 
35
    AddNewNode(Mylist,'Sunday');
 
36
 
 
37
    writeln;
 
38
    WriteLN('This is the list');
 
39
    PrintList(Mylist);
 
40
 
 
41
    writeln;
 
42
    WriteLN('Now we are going to remove the last node');
 
43
    WriteLN('>> Press return');
 
44
    readln;
 
45
    RemoveLastNode(Mylist);
 
46
    PrintList(Mylist);
 
47
    writeln;
 
48
 
 
49
    WriteLN('>> Press return to get the size of the list');
 
50
    writeln;
 
51
    readln;
 
52
    WriteLN('The size of allocated list is ', SizeOfList(Mylist));
 
53
    writeln;
 
54
 
 
55
    writeln('Now we are going to print all strings' +#10+ 'in the list with the internal commands');
 
56
    WriteLN('>> Press return');
 
57
    readln;
 
58
 
 
59
    i := NodesInList(Mylist);
 
60
    MyNode := GetFirstNode(Mylist);
 
61
    FOR temp := 1 TO i DO BEGIN
 
62
        WriteLN(MyNode^.ln_Name);
 
63
        MyNode := GetNextNode(MyNode);
 
64
    END;
 
65
 
 
66
    writeln;
 
67
    WriteLN('We will move the last node to the top');
 
68
    WriteLN('>> Press return');
 
69
    readln;
 
70
    MyNode := GetLastNode(Mylist);
 
71
    MoveNodeTop(Mylist,MyNode);
 
72
    PrintList(Mylist);
 
73
    writeln;
 
74
 
 
75
    WriteLN('We shall change the value in one node');
 
76
    WriteLN('>> Press return');
 
77
    readln;
 
78
    MyNode := GetFirstNode(Mylist);
 
79
    MyNode := GetNextNode(MyNode);
 
80
    UpDateNode(MyNode,'This is the new day');
 
81
    PrintList(Mylist);
 
82
    writeln;
 
83
 
 
84
    MyNode := GetNextNode(MyNode);
 
85
    WriteLN('Now we delete one node');
 
86
    WriteLN('>> Press return');
 
87
    readln;
 
88
    WriteLN('This node is going to be deleted ',GetNodeData(MyNode));
 
89
    DeleteNode(MyNode);
 
90
    PrintList(Mylist);
 
91
 
 
92
    writeln;
 
93
    WriteLN('Sort the list');
 
94
    WriteLN('>> Press return');
 
95
    readln;
 
96
    SortList(Mylist);
 
97
    PrintList(Mylist);
 
98
 
 
99
    writeln;
 
100
    writeln('Search for a node, in this case Friday');
 
101
    WriteLN('>> Press return');
 
102
    readln;
 
103
    MyNode := FindNodeData(Mylist,'Friday');
 
104
    IF MyNode <> NIL THEN BEGIN
 
105
        WriteLN('found the node ',MyNode^.ln_Name);
 
106
        { or writeln('found the node ',GetNodeData(MyNode));  }
 
107
    END ELSE BEGIN
 
108
        WriteLN('Node not found');
 
109
    END;
 
110
 
 
111
    writeln;
 
112
    WriteLN('And now copy the list to a stringbuffer' +#10+ 'and print it');
 
113
    WriteLN('>> Press return');
 
114
    readln;
 
115
    bufsize := SizeOfList(Mylist);
 
116
    buffer := StrAlloc(bufsize);
 
117
    ListToBuffer(Mylist,buffer);
 
118
    WriteLN(buffer);
 
119
 
 
120
    writeln;
 
121
    WriteLN('Now we try to copy the list to a new list');
 
122
    WriteLN('>> Press return');
 
123
    readln;
 
124
    templist := CopyList(Mylist);
 
125
    IF templist <> NIL THEN BEGIN
 
126
        WriteLN('That went well, the new list is here');
 
127
        PrintList(templist);
 
128
        DestroyList(templist);
 
129
    END ELSE BEGIN
 
130
        WriteLN('no copy of list');
 
131
    END;
 
132
 
 
133
    writeln;
 
134
    WriteLN('Press return to destroy the list');
 
135
    readln;
 
136
    DestroyList(Mylist);
 
137
    writeln;
 
138
    WriteLN('All done');
 
139
END.