(* ProgramArgs.mod implement the ISO ProgramArgs specification. Copyright (C) 2008-2024 Free Software Foundation, Inc. Contributed by Gaius Mulley . 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. Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . *) IMPLEMENTATION MODULE ProgramArgs ; FROM RTgen IMPORT ChanDev, InitChanDev, DeviceType, doLook, doSkip, doSkipLook, doReadText, doReadLocs ; FROM SYSTEM IMPORT ADDRESS, ADR ; FROM UnixArgs IMPORT GetArgC, GetArgV ; FROM RTgenif IMPORT GenDevIF, InitGenDevIF ; FROM RTdata IMPORT ModuleId, MakeModuleId, InitData, GetData ; FROM IOLink IMPORT DeviceId, DeviceTablePtr, DeviceTablePtrValue, AllocateDeviceId, MakeChan, RAISEdevException ; FROM IOChan IMPORT ChanExceptions ; FROM IOConsts IMPORT ReadResults ; FROM ChanConsts IMPORT read, text ; FROM Storage IMPORT ALLOCATE, DEALLOCATE ; FROM ASCII IMPORT nul, lf ; TYPE PtrToChar = POINTER TO CHAR ; ArgInfo = POINTER TO RECORD currentPtr: PtrToChar ; currentPos: CARDINAL ; currentArg: CARDINAL ; argLength : CARDINAL ; argc : CARDINAL ; END ; VAR mid : ModuleId ; did : DeviceId ; cid : ChanId ; ArgData : PtrToChar ; ArgLength: CARDINAL ; gen : GenDevIF ; dev : ChanDev ; PROCEDURE look (d: DeviceTablePtr; VAR ch: CHAR; VAR r: ReadResults) ; BEGIN doLook(dev, d, ch, r) END look ; PROCEDURE skip (d: DeviceTablePtr) ; BEGIN doSkip(dev, d) END skip ; PROCEDURE skiplook (d: DeviceTablePtr; VAR ch: CHAR; VAR r: ReadResults) ; BEGIN doSkipLook(dev, d, ch, r) END skiplook ; PROCEDURE textread (d: DeviceTablePtr; to: ADDRESS; maxChars: CARDINAL; VAR charsRead: CARDINAL) ; BEGIN doReadText(dev, d, to, maxChars, charsRead) END textread ; PROCEDURE rawread (d: DeviceTablePtr; to: ADDRESS; maxLocs: CARDINAL; VAR locsRead: CARDINAL) ; BEGIN doReadLocs(dev, d, to, maxLocs, locsRead) END rawread ; PROCEDURE getname (d: DeviceTablePtr; VAR a: ARRAY OF CHAR) ; BEGIN d^.doGetName(d, a) END getname ; PROCEDURE flush (d: DeviceTablePtr) ; BEGIN END flush ; PROCEDURE handlefree (d: DeviceTablePtr) ; BEGIN END handlefree ; PROCEDURE reset (d: DeviceTablePtr) ; VAR a : ArgInfo ; BEGIN a := GetData(d, mid) ; WITH a^ DO currentPtr := ArgData ; currentPos := 0 ; currentArg := 0 ; argLength := strlen(currentPtr)+1 ; argc := GetArgC () END END reset ; (* doreadchar - returns a CHAR from the file associated with, g. *) PROCEDURE doreadchar (g: GenDevIF; d: DeviceTablePtr) : CHAR ; VAR a : ArgInfo ; ch: CHAR ; BEGIN d := DeviceTablePtrValue(cid, did) ; a := GetData(d, mid) ; WITH a^ DO IF currentPos0 THEN DEC(currentPtr) ; DEC(currentPos) END END ; RETURN( ch ) END dounreadchar ; (* dogeterrno - returns the errno relating to the generic device. *) PROCEDURE dogeterrno (g: GenDevIF; d: DeviceTablePtr) : INTEGER ; BEGIN RETURN 0 END dogeterrno ; (* dorbytes - reads upto, max, bytes setting, actual, and returning FALSE if an error (not due to eof) occurred. *) PROCEDURE dorbytes (g: GenDevIF; d: DeviceTablePtr; to: ADDRESS; max: CARDINAL; VAR actual: CARDINAL) : BOOLEAN ; VAR p: PtrToChar ; i: CARDINAL ; BEGIN WITH d^ DO p := to ; i := 0 ; WHILE (i