[net.sources.mac] Switch.src

maclab@reed.UUCP (S.Gillespie/Mac Dev. Lab) (11/02/85)

Program Switch;

(*
  Switch
   Written By Scott Gillespie
    With the Rascal Development System

  Desk Accessory which switches the Finder name in low memory.
*)  

Uses __ToolTraps, __QuickDraw, __OSTraps,
(*$U+*) uOSIntf ;

Link __NoSysCall, __OSTraps :;

Const
  MenuID = -2001;
  FNameLoc = $2E0L; (* Location of Finder Name in low memory *)
  BootDrive = $210L;(* System Vref location in low memory *)
  
Type
  Fptr = ^Byte[16];

Var
  Menu: PtrL;
  AppName: Byte[256];
  Param: ParamBlockRec;
  
PROCEDURE getfinfo(ind,vref: integer; err: ^OSErr);
{
      Param.IONamePtr := @AppName;
      Param.IOVRefNum := vref;
      Param.IOFDirIndex := ind;
      Param.IOVersNum := 0;
      err^ := PBGetFInfo(Param,False);
};

Proc Make(Name: Byte[16]);  (* Put a new name in low mem *)
{
  If Name[0]>15 Then Return; (* There's only room for 15 characters *)
  Fptr(FNameLoc)^ := Name;
};
  
Proc SetUpMenu();
Var
 Err,i: OSErr;
 Appl: Longint;
{
  Appl := PtrL(" APPL"+2)^;
  Menu := NewMenu(MenuID,"Switch");
  InsertMenu(Menu,0);
  AppendMenu(Menu,"Finder");
  Loop(,i:=1,++i,) {			(* Get all of the applications on
					   the System disk *)
    GetFInfo(i,Ptrw(BootDrive)^,@Err);
    If Err Then Break;                  (* Assume the index is too high, so
					   no more files to check *)
    If Appl = PtrL(@Param.ioFlFndrInfo.FDType)^ Then
      AppendMenu(Menu,AppName);
    };
    
  DrawMenuBar();
};

Proc _Init();
{
  MoveTo(0,2);
  Writeln();
  
  SetUpMenu();
  
  DrawString(FnameLoc);
};

Proc _Halt();
{
  DeleteMenu(MenuID);
  DisposeMenu(Menu);
  DrawMenuBar();
};

Proc _Menu(id,item: Integer);
Var P: Ptrl;
{
  GetPort(@P);
  SelectWindow(P);
  
  GetItem(Menu,item,@AppName);
  Make(AppName);
  
  Writeln();
  DrawString(FnameLoc);

  ReqHalt();
  HiliteMenu(0);
};