Debian Codegraph @

gcc/testsuite/gm2/run/fail/list.mod

raw
1 (* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17 MODULE list ;
18
19
20 FROM FIO IMPORT OpenToRead, OpenToWrite, Close, EOF, WriteLine,
21 ReadString, WriteString, File, WriteChar;
22 FROM NumberIO IMPORT WriteInt,ReadInt,StrToInt,IntToStr;
23 FROM FpuIO IMPORT ReadReal,WriteReal,StrToReal,RealToStr;
24 FROM StdIO IMPORT Write;
25 IMPORT StrIO; (* WriteString,WriteLn,ReadString; *)
26 FROM StrLib IMPORT StrLen,StrLess,StrEqual;
27
28 TYPE
29 string4 = ARRAY[0..3] OF CHAR;
30 string8 = ARRAY[0..7] OF CHAR;
31 string10 = ARRAY[0..9] OF CHAR;
32 string20 = ARRAY[0..19] OF CHAR;
33 string40 = ARRAY[0..39] OF CHAR;
34
35 employeeRecordType = RECORD
36 Forename : string20;
37 Surname : string40;
38 EmpNumber: string10;
39 Address1 : string20;
40 Address2 : string20;
41 Address3 : string20;
42 Address4 : string20;
43 END;(*record*)
44
45 VAR
46 filehandle: File ;
47 crlf : ARRAY[0..1] OF CHAR;
48
49
50 PROCEDURE getRecord(VAR employeeRec: employeeRecordType);
51 BEGIN
52 WITH employeeRec DO
53 (*Read in each field in turn.*)
54 ReadString(filehandle,Surname);
55 ReadString(filehandle,Forename);
56 ReadString(filehandle,EmpNumber);
57 ReadString(filehandle,Address1);
58 ReadString(filehandle,Address2);
59 ReadString(filehandle,Address3);
60 ReadString(filehandle,Address4);
61 ReadString(filehandle,crlf);
62 END
63 END getRecord;
64
65
66 PROCEDURE getFile (nameOfFile : ARRAY OF CHAR) ;
67 VAR
68 inRec : employeeRecordType;
69 BEGIN
70 (*Reset the file to read it all in.*)
71 filehandle := OpenToRead(nameOfFile) ;
72
73 (*Process all the lines in the file.*)
74 WHILE NOT EOF(filehandle ) DO
75 getRecord(inRec);
76 printEntry(inRec);
77 END ; (* WHILE NOT EOF() *)
78 Close(filehandle);
79 END getFile ;
80
81 PROCEDURE printEntry(which : employeeRecordType) ;
82 BEGIN
83 WITH which DO
84 (*print each field in turn.*)
85 StrIO.WriteString(Forename);
86 StrIO.WriteString(" ");
87 StrIO.WriteString(Surname);
88 StrIO.WriteString(" ");
89 StrIO.WriteString(EmpNumber);
90 StrIO.WriteLn;
91 StrIO.WriteString(Address1);
92 StrIO.WriteLn;
93 StrIO.WriteString(Address2);
94 StrIO.WriteLn;
95 StrIO.WriteString(Address3);
96 StrIO.WriteLn;
97 StrIO.WriteString(Address4);
98 END ; (*with*)
99 StrIO.WriteLn;
100 END printEntry; (*printEntry*)
101
102
103 BEGIN
104 getFile('employee.txt')
105 END list.