| 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 arrayindirect ; |
| 18 |
|
| 19 |
FROM SYSTEM IMPORT ADR, TSIZE, SIZE, WORD, ADDRESS ; |
| 20 |
|
| 21 |
CONST |
| 22 |
UNIXREADONLY = 0 ; |
| 23 |
CreatePermissions = 666B; |
| 24 |
MaxNoOfFiles = 100 ; |
| 25 |
MaxBufferLength = 1024*16 ; |
| 26 |
MaxErrorString = 1024* 8 ; |
| 27 |
|
| 28 |
TYPE |
| 29 |
FileUsage = (unused, openedforread, openedforwrite, openedforrandom) ; |
| 30 |
FileStatus = (successful, outofmemory, toomanyfilesopen, failed, connectionfailure) ; |
| 31 |
|
| 32 |
NameInfo = RECORD |
| 33 |
address: ADDRESS ; |
| 34 |
size : CARDINAL ; |
| 35 |
END ; |
| 36 |
|
| 37 |
Buffer = POINTER TO buf ; |
| 38 |
buf = RECORD |
| 39 |
position: CARDINAL ; (* where are we through this buffer *) |
| 40 |
address : ADDRESS ; (* dynamic buffer address *) |
| 41 |
filled : CARDINAL ; (* length of the buffer filled *) |
| 42 |
size : CARDINAL ; (* maximum space in this buffer *) |
| 43 |
left : CARDINAL ; (* number of bytes left to read *) |
| 44 |
contents: POINTER TO ARRAY [0..MaxBufferLength] OF CHAR ; |
| 45 |
END ; |
| 46 |
|
| 47 |
FileDescriptors = POINTER TO fds ; |
| 48 |
fds = RECORD |
| 49 |
unixfd: INTEGER ; |
| 50 |
name : NameInfo ; |
| 51 |
state : FileStatus ; |
| 52 |
usage : FileUsage ; |
| 53 |
buffer: Buffer ; |
| 54 |
END ; |
| 55 |
File = CARDINAL ; |
| 56 |
|
| 57 |
VAR |
| 58 |
FileInfo: ARRAY [0..MaxNoOfFiles] OF FileDescriptors ; |
| 59 |
|
| 60 |
|
| 61 |
(* |
| 62 |
GetUnixFileDescriptor - returns the UNIX file descriptor of a file. |
| 63 |
*) |
| 64 |
|
| 65 |
PROCEDURE GetUnixFileDescriptor (f: File) : INTEGER ; |
| 66 |
BEGIN |
| 67 |
IF (f<MaxNoOfFiles) AND (FileInfo[f]#NIL) |
| 68 |
THEN |
| 69 |
RETURN( FileInfo[f]^.unixfd ) |
| 70 |
ELSE |
| 71 |
HALT |
| 72 |
END |
| 73 |
END GetUnixFileDescriptor ; |
| 74 |
|
| 75 |
BEGIN |
| 76 |
IF GetUnixFileDescriptor(File(1))=0 |
| 77 |
THEN |
| 78 |
HALT |
| 79 |
END |
| 80 |
END arrayindirect. |