home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
coders
/
tooltypes
/
tooltypes.mod
< prev
next >
Wrap
Text File
|
1996-07-15
|
12KB
|
408 lines
(****************************************************************
:Program. ToolTypes.mod
:Contents. To get "ToolTypes" from the programm Icon
:Contents. or CLI-Line
:Contents. or ENV-Variable
:Contents. or Config-File
:Author. Matthias Taube
:Copyright. PublicDomain
:Language. Oberon
:Translator. Oberon 3.00d
:History. 1.5 [Taube] 10-Oct-1993 include Config-File support
:History. 1.4 [Taube] 30-Sep-1993 include env-support
:History. 1.3 [Taube] 29-Sep-1993 fixed Bug using empty ToolType
:History. 1.2 [Taube] 16-May-1993 fixed Bug using Icon.GetToolType (pointer odd)
:History. 1.1 [Taube] 02-May-1993 include Cli-Support
:Address. D-50858 Köln, Ricarda Huch Str. 8
:Phone. 02234/49233
:Remark. ONLY TESTET ON A3000 - KS/WB 37.x und KS/WB 39.x
*****************************************************************)
MODULE ToolTypes;
IMPORT Arguments, Conversions, Dos, Exec, FileSystem, Icon, io,
OberonLib, Requests, Strings, SYSTEM, Workbench;
TYPE ConfigLinePtr = UNTRACED POINTER TO ConfigLine;
(* Konfig File wird im Ram gehalten, um es nur einmal einlesen zu
muessen *)
ConfigLine = RECORD
Next:ConfigLinePtr;
Text:Exec.STRING;
END;
VAR wbs-: Workbench.WBStartupPtr;
MeinIcon-: Workbench.DiskObjectPtr;
Config,ConfigW: ConfigLinePtr;
PROCEDURE CopyStr(Von:ARRAY OF CHAR;VAR Nach:ARRAY OF CHAR;AbPos:INTEGER);
(* Kopiert einen String ab einer Position bis zum Ende in einen anderen String *)
VAR VonPos,NachPos:INTEGER;
BEGIN
VonPos:=AbPos;NachPos:=0;
WHILE (NachPos<LEN(Nach)) AND (Von[VonPos]#00X) DO
Nach[NachPos]:=Von[VonPos];
INC(NachPos);INC(VonPos);
END;
Nach[NachPos]:=00X;
END CopyStr;
(****i* StripQuote ********************************************************
*
* NAME
* StripQuote - Strips of the Quotes of a String
*
* SYNOPSIS
* StripQuote(VAR String:ARRAY OF CHAR);
*
* FUNCTION
* Strips of the Quotes and leading or finishing spaces of an
* given String
*
* INPUTS
* String: an ARRAY OF CHAR with the String
*
* RESULT
* String: the String without Spaces
*
*****************************************************************************
*
*)
PROCEDURE StripQuote(VAR String:ARRAY OF CHAR);
(* Entfernt die Anführungszeichen und die führenden und endenden Leerzeichen
aus einem String *)
VAR Pos:INTEGER;
Quote:CHAR;
BEGIN
Pos:=0;
(* führende Leerzeichen entfernen *)
WHILE (String[Pos]=" ") DO
INC(Pos);
END;
(* führendes Anführungszeichen entfernen *)
IF (String[Pos]="'") OR (String[Pos]='"') THEN
Quote:=String[Pos]; INC(Pos);
ELSE Quote:=" ";
END;
CopyStr(String,String,Pos);
Pos:=SHORT(Strings.Length(String));
WHILE ((String[Pos]=" ") OR (String[Pos]=00X)) AND (Pos>0) DO
DEC(Pos);
END;
IF String[Pos]=Quote THEN DEC(Pos); END;
String[Pos+1]:=00X;
END StripQuote;
(****** GetToolRawStr* ********************************************************
*
* NAME
* GetToolRawStr - to get the String after a Congiguration Keyword without
* any change
* SYNOPSIS
* GetToolRawStr* (Pattern:ARRAY OF CHAR;VAR in: Exec.STRING):BOOLEAN;
*
* FUNCTION
* Searches for the ToolType in the Icon (or the commandline,
* if CLI-startet) and, if there not found, for an env: Variable
* with the name of the ToolType. If not there, it searches for
* the Keyword in the Configuration-file (named Progname.cfg or
* like the String in the "CONFIG" Keyword.
* The entry in the configfile must start with an "#" at the first
* column, like #TOOLTYPE=...
*
* INPUTS
* Pattern: an ARRAY OF CHAR with the searched ToolType in it
*
* RESULT
* in: an Exec.STRING with the raw String after the ToolType
* FuncResult: FALSE if tooltype was not found
*
* EXAMPLE
*
* NOTES
*
* BUGS
*
* SEE ALSO
*
*****************************************************************************
*
*)
PROCEDURE GetToolRawStr* (Pattern:ARRAY OF CHAR;VAR in: Exec.STRING):BOOLEAN;
(* Liefert das Argument in der Variable in den String, so wie es in den ToolTypes
steht.
Beim Start vom Cli werden die Argumente nach dem String "Pattern=..."
durchsucht und danach String hinter dem Gleichheitszeichen ausgewertet.
Wenn nicht gefunden, wird nach einer env: Variable mit dem Namen gesucht. *)
VAR i: INTEGER;
Ok: BOOLEAN;
Temp: Exec.STRPTR;
Config: ConfigLinePtr;
PROCEDURE Vergleich(Pattern,String:ARRAY OF CHAR;VAR In:Exec.STRING):BOOLEAN;
VAR TempString:Exec.STRING;
Pos :LONGINT;
BEGIN
In:="";
COPY(String,TempString);
Strings.Upper(TempString);
Pos:=Strings.Occurs(TempString,Pattern);
IF Pos = 0 THEN
Pos:=Strings.Length(Pattern);
WHILE (String[Pos]#"=") AND (String[Pos]#00X) DO
INC(Pos);
END;
IF String[Pos]="=" THEN
CopyStr(String,In,SHORT(Pos)+1);
RETURN TRUE;
ELSE
RETURN FALSE;
END;
END;
RETURN FALSE;
END Vergleich;
BEGIN
Strings.Upper(Pattern);
IF MeinIcon#NIL THEN
(* $OddChk- *)
Temp:=Icon.FindToolType(MeinIcon.toolTypes,Pattern);
IF Temp#NIL THEN
Exec.CopyMemAPTR(Temp,SYSTEM.ADR(in),SIZE(in));
RETURN(TRUE);
END;
(* $OddChk= *)
ELSE (* Programm hat kein Icon oder wurde über den Cli gestartet *)
IF NOT OberonLib.wbStarted THEN
i:=Arguments.NumArgs();
REPEAT
Arguments.GetArg(i,in);
IF Vergleich(Pattern,in,in) THEN RETURN TRUE; END;
DEC(i);
UNTIL (i<1);
END;
END;
IF (Dos.GetVar(Pattern,in,LEN(in),LONGSET{Dos.globalOnly})#-1) THEN
RETURN TRUE;
END;
Config:=ConfigW;
WHILE Config#NIL DO
IF Vergleich(Pattern,Config^.Text,in) THEN RETURN TRUE; END;
Config:=Config^.Next;
END;
RETURN FALSE;
END GetToolRawStr;
(****** GetToolStr* ********************************************************
*
* NAME
* GetToolStr - to get the String after the tooltype without the "" or ''
*
* SYNOPSIS
* GetToolStr* (Pattern:ARRAY OF CHAR;VAR in: ARRAY OF CHAR):BOOLEAN;
*
* FUNCTION
* Searches for the ToolType in the Icon (or the commandline,
* if CLI-startet) and, if there not found, for an env: Variable
* with the name of the ToolType.
* If not found, the Configfile (named ProgName.cfg) is used and
* scanned for an parameter like #TOOLTYPE = ...
* THIS IS NEEDET IN FIRST COLUMN--^
* The name of the configfile may be changed by using the CONFIG=
* ToolType
*
* INPUTS
* Pattern: an ARRAY OF CHAR with the searched ToolType in it
*
* RESULT
* in: an ARRAY OF CHAR with the String after the ToolType without "" or ''
* FuncResult: FALSE if tooltype was not found
*
* EXAMPLE
*
* NOTES
*
* BUGS
*
* SEE ALSO
*
*****************************************************************************
*
*)
PROCEDURE GetToolString*(Pattern:ARRAY OF CHAR;VAR in:ARRAY OF CHAR):BOOLEAN;
(* von dem String hinter ToolType werden die Tüttelchen entfernt, er
wird in einen beliebigen String kopiert. *)
VAR TMPStr:Exec.STRING;
BEGIN
IF GetToolRawStr(Pattern,TMPStr) THEN
StripQuote(TMPStr);
CopyStr(TMPStr,in,0);
RETURN(TRUE);
END;
in:="";
RETURN(FALSE);
END GetToolString;
(****** GetToolInt* ********************************************************
*
* NAME
* GetToolInt - to get integer ToolTypes
*
* SYNOPSIS
* GetToolInt*(Pattern:ARRAY OF CHAR;Default:LONGINT):LONGINT
*
* FUNCTION
* Searches for the ToolType in the Icon (or the commandline,
* if CLI-startet) and, if there not found, for an env: Variable
* with the name of the ToolType or an entry in the Configfile
* and converts the String to an INTEGER-value.
* If not found, uses the given default.
*
* INPUTS
* Pattern: an ARRAY OF CHAR with the searched ToolType in it
* Default: the default-value if tooltype not found
*
* RESULT
* The value after tooltype (or default, if not found or not convertable)
*
* EXAMPLE
*
* NOTES
*
* BUGS
*
* SEE ALSO
*
*****************************************************************************
*
*)
PROCEDURE GetToolInt*(Pattern:ARRAY OF CHAR;Default:LONGINT):LONGINT;
(* Wertet Tools aus, die Integerargumente beinhalten *)
VAR Temp:Exec.STRING;
Aus:LONGINT;
BEGIN
IF GetToolString(Pattern,Temp) THEN
IF Conversions.StringToInt(Temp,Aus) THEN RETURN(Aus); END;
END;
RETURN(Default);
END GetToolInt;
PROCEDURE OpenCfg():ConfigLinePtr;
VAR
oldLock,dirLock: Dos.FileLockPtr;
file: FileSystem.File;
Pos:INTEGER;
open: BOOLEAN;
Config,ConfigNeu,ConfigWurzel:ConfigLinePtr;
BaseName,
NameExt,setting,Zeile: Exec.STRING;
BEGIN
Arguments.GetArg(0,BaseName);
IF BaseName = "" THEN HALT(20); END;
Pos:=SHORT(Strings.Length(BaseName));
WHILE ((BaseName[Pos]#"/") AND (BaseName[Pos]#":")) AND (Pos>0) DO
DEC(Pos);
END;
IF Pos>0 THEN CopyStr(BaseName, BaseName,Pos+1); END;
NameExt:=BaseName;
Strings.Append(NameExt,".cfg");
(* $IFNOT ClearVars *)
lock := NIL; oldLock := NIL; return := FALSE;Config:=NIL;ConfigWurzel:=NIL;
(* $END *)
IF GetToolString("CONFIG",setting) THEN (* are any setting given? *)
open:=FileSystem.Open(file,setting,FALSE);
ELSE
setting:="ENV:";
Strings.Append(setting,NameExt);
open:=FileSystem.Open(file,setting,FALSE); (* ENV: *)
IF NOT open THEN
setting:="ENV:";
Strings.Append(setting,BaseName);
Strings.AppendChar(setting,"/");
Strings.Append(setting,NameExt);
open:=FileSystem.Open(file,setting,FALSE);
END;
IF NOT open THEN
dirLock := Dos.GetProgramDir();
IF dirLock # NIL THEN
oldLock := Dos.CurrentDir(dirLock);
open:=FileSystem.Open(file,NameExt,FALSE); (* programms home *)
END;
END;
IF NOT open THEN
oldLock:=Dos.CurrentDir(Arguments.oldCurrentDir);
open:=FileSystem.Open(file,NameExt,FALSE); (* current *)
END;
END;
IF open THEN
Pos:=0;
WHILE FileSystem.ReadString(file,Zeile) DO
IF Zeile[0]="#" THEN
REPEAT
NEW(ConfigNeu);
IF ConfigNeu=NIL THEN
IF ~ Requests.Request(BaseName,"Speichermangel",
" Nochmal versuchen "," Abbruch ") THEN HALT(20)
END;
END;
UNTIL(ConfigNeu#NIL);
IF Config#NIL THEN (* Neues Element in die Liste einhaengen *)
Config^.Next:=ConfigNeu;
ELSE
ConfigWurzel:=ConfigNeu; (* war erste Zeile *)
END;
Config:=ConfigNeu; (* und Liste weiterschalten *)
Config^.Next:=NIL;
Pos:=1;
WHILE(Zeile[Pos]#"=") AND (Zeile[Pos]#00X) DO
Zeile[Pos]:=Strings.CapIntl(Zeile[Pos]);
INC(Pos);
END;
CopyStr(Zeile,Config^.Text,1);
END;
Zeile:="";
END;
open:=NOT FileSystem.Close(file);
END;
IF oldLock # NIL THEN
IF Dos.CurrentDir(oldLock) = NIL THEN END;
END;
RETURN ConfigWurzel;
END OpenCfg;
BEGIN
(* $IFNOT ClearVars *)
Config:=NIL;
ConfigW:=NIL;
(* $END *)
Requests.Assert(Dos.dos.lib.version>=36,"Programm benötigt dos.library V36 (OS 2.0)!");
IF OberonLib.wbStarted THEN
wbs := OberonLib.wbenchMsg; (* wird von Arguments nicht exportiert *)
MeinIcon := Icon.GetDiskObject(wbs.argList[0].name^);
ELSE MeinIcon:=NIL;wbs:=NIL;
END;
ConfigW:=OpenCfg();
CLOSE
IF MeinIcon#NIL THEN Icon.FreeDiskObject(MeinIcon);END;
WHILE ConfigW#NIL DO
Config:=ConfigW^.Next;
DISPOSE(ConfigW);
ConfigW:=Config;
END;
END ToolTypes.