home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
dev
/
obero
/
oberon-a
/
source
/
fpe
/
data.mod
< prev
next >
Wrap
Text File
|
1994-08-08
|
17KB
|
640 lines
(***************************************************************************
$RCSfile: Data.mod $
Description: Global data declarations and operations for the FPE utility
program.
Created by: fjc (Frank Copeland)
$Revision: 1.8 $
$Author: fjc $
$Date: 1994/08/08 16:13:09 $
Copyright © 1993-1994, Frank Copeland.
This file is part of FPE.
See FPE.doc for conditions of use and distribution.
Log entries are at the end of the file.
***************************************************************************)
MODULE Data;
(*
** $C= CaseChk $I= IndexChk $L= LongAdr $N- NilChk
** $P- PortableCode $R= RangeChk $S= StackChk $T= TypeChk
** $V= OvflChk $Z= ZeroVars
**
** Compiler NIL checking is replaced by ASSERTs at the appropriate places.
*)
IMPORT
E := Exec, EU := ExecUtil, U := Utility, D := Dos, DU := DosUtil, ARP,
ISup := IntuiSup, ISU := IntuiSupUtil, Str := Strings, Args,
SYS := SYSTEM;
CONST
NumFiles * = 4;
NumTools * = 12;
FileChars * = 32;
ExtensionChars * = 4;
PathChars * = 254;
ButtonChars * = 10;
ConsoleChars * = 60;
Notice = "FPE Notice";
TYPE
FileName * = ARRAY FileChars + 1 OF CHAR;
Path * = ARRAY PathChars + 1 OF CHAR;
Extension * = ARRAY ExtensionChars + 1 OF CHAR;
ModuleNodePtr * = CPOINTER TO ModuleNode;
ModuleNode = RECORD (E.Node)
modName : FileName;
END; (* ModuleNode *)
ButtonText = ARRAY ButtonChars + 1 OF CHAR;
Console = ARRAY ConsoleChars + 1 OF CHAR;
ToolInfo * = RECORD
title * : ButtonText;
command *,
arguments * : Path;
isActive *,
hasConsole * : BOOLEAN;
console * : Console;
stack * : LONGINT;
END; (* ToolInfo *)
FileSet = SYS.BYTESET;
ToolsArray = ARRAY NumTools OF ToolInfo;
SkeletonsArray = ARRAY NumFiles OF Path;
ExtensionsArray = ARRAY NumFiles OF Extension;
SetupRecPtr = POINTER TO SetupRec;
SetupRec = RECORD
tools : ToolsArray;
(*skeletons : SkeletonsArray;*)
extensions : ExtensionsArray;
(*icon : Path;*)
END; (* SetupRec *)
VAR
currentPath * : Path;
programName * : FileName;
moduleList * : E.List;
currentModule * : ModuleNodePtr;
currentModuleNo * : LONGINT;
currentFiles * : FileSet;
tools * : ToolsArray;
extensions * : ExtensionsArray;
currentDir * : D.FileLockPtr;
DefSetupPath : Path;
AltSetupPath : Path;
(*skeletons : SkeletonsArray;*)
(*icon : Path;*)
(*------------------------------------*)
(* $D- disable copying of open arrays *)
PROCEDURE ChangeDirectory * ( newDir : ARRAY OF CHAR );
VAR result : LONGINT; dirLock : D.FileLockPtr;
BEGIN (* ChangeDirectory *)
dirLock := D.base.Lock (newDir, D.sharedLock);
IF dirLock # NIL THEN
IF currentDir # NIL THEN D.base.UnLock( currentDir ) END;
currentDir := dirLock;
dirLock := D.base.CurrentDir (dirLock);
IF D.base.version >= 37 THEN
IF D.base.NameFromLock (currentDir, currentPath, PathChars)
THEN END
ELSE
result := ARP.base.PathName (currentDir, currentPath, 10);
END;
ELSE
ISU.DoNotice (NIL, SYS.ADR (Notice), "Could not lock new directory");
END
END ChangeDirectory;
(*------------------------------------*)
(* $D- disable copying of open arrays *)
PROCEDURE MakeModule * ( module : ARRAY OF CHAR );
VAR
newNode : ModuleNodePtr;
BEGIN (* MakeModule *)
NEW (newNode); ASSERT (newNode # NIL, 137);
newNode.name := SYS.ADR(newNode.modName);
COPY (module, newNode.modName);
E.base.AddTail (moduleList, newNode);
IF currentModule = NIL THEN
currentModule := SYS.VAL (ModuleNodePtr, moduleList.head);
currentModuleNo := 0
END
END MakeModule;
(*------------------------------------*)
PROCEDURE RemoveModule * ();
VAR module : ModuleNodePtr;
BEGIN (* RemoveModule *)
IF currentModule # NIL THEN
module := currentModule;
IF module.succ.succ = NIL THEN
currentModule := SYS.VAL (ModuleNodePtr, moduleList.head);
currentModuleNo := 0
ELSE
currentModule := SYS.VAL (ModuleNodePtr, module.succ);
END;
E.base.Remove (module);
SYS.DISPOSE (module)
END
END RemoveModule;
(*------------------------------------*)
PROCEDURE ScanModules * () : BOOLEAN;
VAR
module : FileName;
fileInfo : D.FileInfoBlockPtr;
file, fileLength, dotPos : INTEGER;
extLength : ARRAY NumFiles OF INTEGER;
extension : Extension;
result : BOOLEAN;
thisModule : E.MinNodePtr;
BEGIN (* ScanModules *)
result := TRUE;
NEW (fileInfo); ASSERT (fileInfo # NIL, 137);
thisModule := E.base.RemHead (moduleList);
WHILE thisModule # NIL DO
SYS.DISPOSE (thisModule); thisModule := E.base.RemHead (moduleList)
END;
currentModule := NIL; currentModuleNo := 0;
file := 0;
WHILE file < NumFiles DO
extLength [file] := SHORT (Str.Length (extensions [file])); INC (file)
END;
IF D.base.Examine (currentDir, fileInfo^) THEN
WHILE D.base.ExNext (currentDir, fileInfo^) DO
IF fileInfo.dirEntryType < 0 THEN
file := 0;
LOOP
IF file >= NumFiles THEN EXIT; END;
fileLength := SHORT (Str.Length (fileInfo.fileName));
dotPos := fileLength - extLength [file] - 1;
IF (dotPos >= 0) & (fileInfo.fileName [dotPos] = ".") THEN
Str.CopySubString
( extension, fileInfo.fileName, dotPos + 1,
extLength [file] );
IF Str.CompareCAP (extension, extensions [file]) = 0 THEN
Str.CopySubString (module, fileInfo.fileName, 0, dotPos);
IF E.base.FindName (moduleList, module) = NIL THEN
MakeModule (module);
END;
EXIT
END;
END;
INC (file)
END; (* LOOP *)
END; (* IF *)
END; (* WHILE *)
ELSE
result := FALSE
END;
SYS.DISPOSE (fileInfo);
RETURN result;
END ScanModules;
(*------------------------------------*)
(* $D- disable copying of open arrays *)
PROCEDURE LoadProgram * ( program : ARRAY OF CHAR ) : BOOLEAN;
VAR
progFile : ISup.FileDataPtr;
prgName : Path;
module : FileName;
thisModule : E.MinNodePtr;
fileResult : INTEGER;
result : BOOLEAN;
BEGIN (* LoadProgram *)
result := TRUE;
thisModule := E.base.RemHead (moduleList);
WHILE thisModule # NIL DO
SYS.DISPOSE (thisModule); thisModule := E.base.RemHead (moduleList)
END;
currentModule := NIL; currentModuleNo := 0;
COPY (program, programName);
COPY (program, prgName);
Str.Append( prgName, ".prg" );
progFile :=
ISup.base.OpenTextFile
( prgName, 1000, 100, {ISup.tfTrimLine .. ISup.tfSkipEmptyLines});
IF progFile # NIL THEN
module := "";
LOOP
fileResult := ISup.base.ReadTextLine (progFile);
IF fileResult # ISup.normal THEN EXIT END;
COPY (progFile.line^, module);
IF module [0] # 0X THEN MakeModule (module) END
END;
ISup.base.CloseTextFile (progFile)
ELSE
result := FALSE
END;
RETURN result;
END LoadProgram;
(*------------------------------------*)
PROCEDURE SaveProgram * () : BOOLEAN;
VAR
progFile : D.FileHandlePtr;
prgName : Path;
module : ModuleNodePtr;
result : BOOLEAN;
(* $D- disable copying of open arrays *)
PROCEDURE WriteLine ( string : ARRAY OF CHAR );
VAR ch : CHAR;
fileResult : LONGINT;
BEGIN (* WriteLine *)
fileResult := D.base.Write (progFile, string, Str.Length (string));
ch := "\n"; fileResult := D.base.Write (progFile, ch, 1);
END WriteLine;
BEGIN (* SaveProgram *)
result := TRUE;
COPY (programName, prgName);
Str.Append( prgName, ".prg" );
progFile := D.base.Open (prgName, D.modeNewFile);
IF progFile # NIL THEN
module := SYS.VAL (ModuleNodePtr, EU.GetHead (moduleList));
WHILE module # NIL DO
WriteLine (module.modName);
module := SYS.VAL (ModuleNodePtr, EU.GetSucc (module))
END;
D.base.OldClose( progFile );
ELSE
result := FALSE;
END;
RETURN result;
END SaveProgram;
(*------------------------------------*)
(* $D- disable copying of open arrays *)
PROCEDURE LoadSetup * ( setupDir, setupFile : ARRAY OF CHAR );
VAR
file : D.FileHandlePtr; setupPath : Path; setup : SetupRecPtr;
BEGIN (* LoadSetup *)
COPY (setupDir, setupPath);
IF D.base.version >= 37 THEN
IF D.base.AddPart (setupPath, setupFile, PathChars) THEN END
ELSE
ARP.base.TackOn (setupPath, setupFile);
END;
file := D.base.Open (setupPath, D.modeOldFile);
IF file # NIL THEN
NEW (setup); ASSERT (setup # NIL, 137);
IF
D.base.Read (file, setup^, SIZE (SetupRec)) # SIZE (SetupRec)
THEN
ISU.DoNotice (NIL, SYS.ADR (Notice), "Error reading setup file")
ELSE
tools := setup.tools;
(*skeletons := setup.skeletons;*)
extensions := setup.extensions;
(*icon := setup.icon;*)
END;
D.base.OldClose (file);
SYS.DISPOSE (setup);
ELSE
ISU.DoNotice (NIL, SYS.ADR (Notice), "Could not open setup file for load")
END;
END LoadSetup;
(*------------------------------------*)
PROCEDURE LoadDefSetup * (defSetup : BOOLEAN);
VAR
searchPaths : ARRAY 4 OF E.STRPTR; baseName : E.STRPTR;
fileName : FileName; path : Path;
BEGIN (* LoadDefSetup *)
searchPaths [0] := SYS.ADR ("S/");
searchPaths [1] := SYS.ADR ("FPE:S/");
searchPaths [2] := SYS.ADR ("S:");
searchPaths [3] := NIL;
IF defSetup THEN fileName := "Default.fpe"
ELSE fileName := "Alternate.fpe"
END;
IF DU.Search (searchPaths, fileName, path) THEN
IF defSetup THEN COPY (path, DefSetupPath)
ELSE COPY (path, AltSetupPath)
END;
LoadSetup ("", path);
ELSE
LoadSetup ("", fileName);
END;
END LoadDefSetup;
(*------------------------------------*)
(* $D- disable copying of open arrays *)
PROCEDURE SaveSetup * ( setupDir, setupFile : ARRAY OF CHAR );
VAR file : D.FileHandlePtr; setupPath : Path; setup : SetupRecPtr;
BEGIN (* SaveSetup *)
COPY (setupDir, setupPath);
IF D.base.version >= 37 THEN
IF D.base.AddPart (setupPath, setupFile, PathChars) THEN END
ELSE
ARP.base.TackOn (setupPath, setupFile)
END;
file := D.base.Open (setupPath, D.modeNewFile);
IF file # NIL THEN
NEW (setup); ASSERT (setup # NIL, 137);
setup.tools := tools;
(*setup.skeletons := skeletons;*)
setup.extensions := extensions;
(*setup.icon := icon;*)
IF
D.base.Write (file, setup^, SIZE (SetupRec)) # SIZE (SetupRec)
THEN
ISU.DoNotice (NIL, SYS.ADR (Notice), "Error writing setup file")
END;
D.base.OldClose (file);
SYS.DISPOSE (setup);
ELSE
ISU.DoNotice
(NIL, SYS.ADR (Notice), "Could not open setup file for save")
END;
END SaveSetup;
(*------------------------------------*)
PROCEDURE SaveDefSetup * (defSetup : BOOLEAN);
BEGIN (* SaveDefSetup *)
IF defSetup THEN
SaveSetup ("", DefSetupPath);
ELSE
SaveSetup ("", AltSetupPath)
END
END SaveDefSetup;
(*------------------------------------*)
PROCEDURE DoTool * ( which : INTEGER );
CONST
NoInput = "Failed to open input for tool";
NoOutput = "Failed to open output for tool";
LoadError = "Error loading tool";
VAR
tempCommand, tempArgs : Path;
console : Console;
result : LONGINT;
(* $D- disable copying of open arrays *)
PROCEDURE Expand
( VAR newString : ARRAY OF CHAR; oldString : ARRAY OF CHAR );
VAR oldIndex, newIndex, file : INTEGER;
BEGIN (* Expand *)
oldIndex := 0;
newIndex := 0;
newString [0] := 0X;
LOOP
IF
(newIndex >= (LEN(newString) - 1)) OR (oldString [oldIndex] = 0X)
THEN
newString [newIndex] := 0X; EXIT
END; (* IF *)
IF oldString [oldIndex] = "!" THEN
INC( oldIndex );
CASE oldString [oldIndex] OF
"D" :
newString [newIndex] := 0X;
Str.Append (newString, currentPath);
newIndex := SHORT (Str.Length (newString));
|
"F" :
newString [newIndex] := 0X;
file := 0;
WHILE file < NumFiles DO
IF file IN currentFiles THEN
Str.Append (newString, currentModule.modName );
Str.Append (newString, "." );
Str.Append (newString, extensions [file] );
Str.Append (newString, " " );
END; (* IF *)
INC (file)
END; (* WHILE *)
newIndex := SHORT (Str.Length (newString));
|
"M" :
newString [newIndex] := 0X;
Str.Append (newString, currentModule.modName);
newIndex := SHORT (Str.Length (newString));
|
"P" :
newString [newIndex] := 0X;
Str.Append (newString, programName);
newIndex := SHORT (Str.Length (newString));
|
ELSE
newString [newIndex] := oldString [oldIndex];
INC( newIndex );
END; (* CASE oldString *)
INC( oldIndex );
ELSE
newString [newIndex] := oldString [oldIndex];
INC( oldIndex ); INC( newIndex )
END;
END; (* LOOP *)
END Expand;
(*------------------------------------*)
PROCEDURE ArpCall ();
VAR
PCB : ARP.ProcessControlBlock;
BEGIN (* ArpCall *)
(* Zero unused fields of PCB *)
PCB.pri := 0;
PCB.trapCode := NIL;
PCB.input := NIL;
PCB.output := NIL;
PCB.loadedCode := NIL;
PCB.lastGasp := NIL;
PCB.wbProcess := NIL;
IF tools [which].hasConsole THEN
PCB.console := SYS.VAL (LONGINT, SYS.ADR (console));
PCB.control := {ARP.prStdIO};
ELSE
PCB.console := 0;
IF Args.IsCLI THEN
PCB.control := {}
ELSE
PCB.control := {ARP.prSaveIO}
END
END;
PCB.stackSize := tools [which].stack;
result := ARP.base.ASyncRun (tempCommand, SYS.ADR (tempArgs), PCB);
IF result < 0 THEN ISU.DoNotice (NIL, SYS.ADR (Notice), LoadError) END;
END ArpCall;
(*------------------------------------*)
PROCEDURE DosCall ();
VAR file : D.FileHandlePtr;
BEGIN (* DosCall *)
IF tools [which].hasConsole THEN
file := D.base.Open (console, D.modeOldFile);
IF file = NIL THEN
ISU.DoNotice (NIL, SYS.ADR (Notice), "Could not open console");
RETURN
END
ELSE
file := NIL
END;
Str.Append (tempCommand, " ");
Str.Append (tempCommand, tempArgs);
IF
D.base.SystemTags
( tempCommand,
D.sysInput, file,
D.sysOutput, NIL,
D.sysAsynch, D.TRUE,
D.npStackSize, tools [which].stack,
U.tagDone )
= -1
THEN
IF file # NIL THEN D.base.OldClose (file) END;
ISU.DoNotice (NIL, SYS.ADR (Notice), LoadError)
END;
END DosCall;
BEGIN (* DoTool *)
Expand (tempCommand, tools [which].command);
Expand (tempArgs, tools [which].arguments);
IF tools [which].hasConsole THEN
Expand (console, tools [which].console);
END;
IF D.base.version >= 37 THEN DosCall ()
ELSE ArpCall ()
END
END DoTool;
(*------------------------------------*)
PROCEDURE* CleanupProc ();
BEGIN (* CleanupProc *)
IF currentDir # NIL THEN D.base.UnLock (currentDir) END
END CleanupProc;
(*------------------------------------*)
PROCEDURE Init * ();
BEGIN (* Init *)
SYS.SETCLEANUP (CleanupProc);
tools [0].title := "Button0";
tools [1].title := "Button1";
tools [2].title := "Button2";
tools [3].title := "Button3";
tools [4].title := "Button4";
tools [5].title := "Button5";
tools [6].title := "Button6";
tools [7].title := "Button7";
tools [8].title := "Button8";
tools [9].title := "Button9";
tools [10].title := "Button10";
tools [11].title := "Button11";
extensions [0] := "ex0";
extensions [1] := "ex1";
extensions [2] := "ex2";
extensions [3] := "ex3";
EU.NewList (moduleList);
LoadDefSetup (TRUE);
END Init;
BEGIN
DefSetupPath := "FPE:S/Default.fpe"; AltSetupPath := "FPE:S/Alternate.fpe"
END Data.
(***************************************************************************
$Log: Data.mod $
Revision 1.8 1994/08/08 16:13:09 fjc
Release 1.4
Revision 1.7 1994/06/21 22:03:49 fjc
- Added code to conditionally use V37+ dos.library instead
of arp.library.
Revision 1.6 1994/06/17 17:26:27 fjc
- Updated for release
Revision 1.5 1994/06/09 13:33:46 fjc
- Incorporated changes in Amiga interface
Revision 1.4 1994/06/04 23:49:52 fjc
- Changed to use new Amiga interface
Revision 1.3 1994/05/12 21:26:09 fjc
- Prepared for release
Revision 1.2 1994/01/24 14:33:33 fjc
Changed version control header
Revision 1.1 1994/01/15 17:32:38 fjc
Start of revision control
***************************************************************************)