home *** CD-ROM | disk | FTP | other *** search
- {****************************************************}
- {GlobalRoutines.p }
- {}
- {Some miscellaneous routines used by the CodeSucker FKEY}
- {}
- {Written using Think Pascal v3.0}
- {Requires at least System 6 to run}
- {}
- {⌐ 1991 Mike van Kleef - All rights Reserved}
- {----------------------------------------------------}
- {Address (mail & network) until September 1992 : }
- { 42 Melford Road, London, E11-4PS, England}
- { vankleef@uk.ac.qmc.dcs [Queen Mary College, London] }
- {Address after September 1992 :}
- { Flat 5, 4 St. Quintin Ave., London, W10-6NU, England}
- {----------------------------------------------------}
- {CodeSucker is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY}
- {Absolutely no-one on Earth accepts responsibility for the consequences of using this program}
- {Everyone is hereby granted permission to delete, copy, modify & redistribute CodeSucker}
- {}
- {Last Change 10/12/91}
- {****************************************************}
-
- unit GlobalRoutines;
-
- interface
-
- const
- OptionKey = $3A; {Keyboard code for the Option-Key}
-
- type
- IntPtr = ^Integer;
- LongPtr = ^LongInt;
-
- function KeyIsDown (theKeyCode: integer): Boolean;
- procedure GetRsrcFile (var fName: Str255; var fRef: Integer; index: Integer);
- procedure SetFont (fStr: Str255; fSize: Integer; fStyle: Style);
- procedure CheckOnlyThisItem (theMenu: MenuHandle; theItem: Integer);
-
- implementation
- {-----------------------------------------}
- const
- FSFCBLen = $3F6; {System Global, Length of each individual FCB (File Control Block)}
- FCBsPtr = $34E; {System Global, Pointer to File Control Block buffer}
- FCBoffset = 2; {Offset from base of FCBsPtr to the FCB's. These leading 2 bytes contain the FCB buffer length}
-
- type
- FileName = string[31]; {Used for the filename in the FCB & FileList}
-
- FCBPtr = ^FCB;
- FCB = record {File Control Block, See Inside Macintosh vol.IV-178}
- fcbFlNum: LongInt; {File number}
- fcbMdRByt: Integer; {Should be byte length, but Pascal can't do this}
- {fcbTypByt: Byte; Edited out to keep FCB length correct}
- fcbSBlk: Integer; {First allocation block of file}
- fcbEOF: LongInt; {Logical End-Of-File}
- fcbPLen: LongInt; {Physical End-Of-File}
- fcbCrPs: LongInt; {Mark}
- fcbVPtr: Ptr; {Pointer to volume control block}
- fcbBfAdr: Ptr; {Pointer to access buffer path}
- fcbFlPos: Integer; {used internally}
- fcbClmpSize: LongInt; {File clump size}
- fcbBTCBPtr: Ptr; {Pointer to B* tree control block}
- fcbExtRec: array[0..2] of LongInt; {First three file extents}
- fcbFType: ResType; {File Type (eg.'APPL', 'TEXT',etc.)}
- fcbCatPos: LongInt; {used internally}
- fcbDirID: LongInt; {File's parent ID}
- fcbCName: FileName; {Name of open file}
- end;
-
- {-----------------------------------------}
- function KeyIsDown (theKeyCode: integer): Boolean;
- var
- theKeys: KeyMap;
- begin
- GetKeys(theKeys);
- KeyIsDown := theKeys[theKeyCode];
- end;
-
- {-----------------------------------------}
- {Will return the entry in the FCB buffer at the given index.}
- {If (1 <= index <= fcbEntries) then index=index, else index=fcbEntries}
- {The function result is the FCB which corresponds with index.}
- {To do this it makes use of the File Control Block buffer, in which various information about}
- {currently open files are stored. This routine makes various assumptions about the}
- {structure of the FCB : Warning -> Apple say that the FCB format may change in the}
- {future (Inside Macintosh vol.IV-181)}
- function ReturnFCB (var index: Integer): FCBPtr;
- var
- fcbLength: Integer; {Length of each FCB entry in the buffer}
- fcbBase: Ptr; {Pointer to the base of the FCB buffer}
- fcbTotalSize: LongInt; {Total size of FCB buffer (=first word of fcbBase)}
- currentFCB: FCBPtr; {FCB currently pointed at}
- localCount: Integer; {loop for going through the items in the FCB buffer}
- endOfList: Boolean; {True=End of FCB buffer reached, else False}
- fcbEntries: Integer; {total number of FCB entries in the FCB list}
- begin
- fcbLength := IntPtr(FSFCBLen)^; {Get length of each entry in the FCB buffer}
- fcbBase := Ptr(LongPtr(FCBsPtr)^ + FCBoffset); {Get base address of the FCB buffer}
- fcbTotalSize := IntPtr(LongPtr(FCBsPtr)^)^; {Get the size of the FCB buffer}
- localCount := 0;
- endOfList := False;
- fcbEntries := fcbTotalSize div fcbLength;
- repeat
- currentFCB := FCBPtr((localCount * fcbLength) + LongInt(fcbBase));
- if (currentFCB^.fcbFlNum = 0) then
- endOfList := True
- else
- localCount := localCount + 1
- until endOfList or (localCount >= fcbEntries) or (localCount = index);
- index := localCount;
- ReturnFCB := currentFCB;
- end;
-
- {-----------------------------------------}
- {This routine returns the open resource file refNum+fileName's at the given index in the FCB}
- {The index takes only the resource files into account. Eg, if there are 3 files in the FCB :}
- {[Rsrc,Data,Rsrc] then index=2 will return with the second resource file in the FCB. OK ?}
- {If the resource file could not be accessed (due to MFinder etc) the routine returns fref=-1}
- {If the index given is larger than the number of resource file entried in the FCB then fref=0}
- procedure GetRsrcFile (var fName: Str255; var fRef: Integer; index: Integer);
- var
- currentFCB: FCBPtr; {Pointer to curent FCB buffer entry}
- totalIndex: Integer; {index counter for entries in teh FCB buffer}
- theFref: Integer; {Reference number of open resource file}
- rsrcIndex: Integer; {Counts through just the resource files in the FCB buffer}
- tmpResFile: Integer; {store the current resource file}
- begin
- tmpResFile := CurResFile;
- totalIndex := 0;
- rsrcIndex := 0;
- repeat
- totalIndex := totalIndex + 1;
- currentFCB := ReturnFCB(totalIndex);
- if BTST(currentFCB^.fcbMdRByt, 9) then {Open file is a resource file}
- begin
- theFref := LoWord(LongInt(currentFCB) - LongInt(LongPtr(FCBsPtr)^)); {Get resource file number}
- UseResFile(theFref);
- if ResError = 0 then
- fRef := theFref {No problem accessing file's resource fork}
- else
- fRef := -1; {Can't access this file's resource fork}
- fName := currentFCB^.fcbCName;
- rsrcIndex := rsrcIndex + 1;
- end;
- until (currentFCB^.fcbFlNum = 0) or (rsrcIndex = index);
- if rsrcIndex <> index then
- fRef := 0; {No file found at the given index}
- UseResFile(tmpResFile);
- end;
-
- {-----------------------------------------}
- {Set up a given font & font size for the current port}
- procedure SetFont (fStr: Str255; fSize: Integer; fStyle: Style);
- var
- fNum: Integer; {Font number}
- begin
- GetFNum(fStr, fNum);
- TextFont(fNum);
- TextSize(fSize);
- TextFace(fStyle);
- end;
-
- {-----------------------------------------}
- {This routine put a tick character in front of the specified menu item, and un-ticks all the}
- {iother items in the given menu}
- procedure CheckOnlyThisItem (theMenu: MenuHandle; theItem: Integer);
- var
- loop: Integer; {Loop through all the menu items}
- begin
- for loop := 1 to CountMItems(theMenu) do
- if loop = theItem then
- CheckItem(theMenu, loop, True)
- else
- CheckItem(theMenu, loop, False);
- end;
-
- end.