Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tektronix!reed!maclab
From: maclab@reed.UUCP (S.Gillespie/Mac Dev. Lab)
Newsgroups: net.sources.mac
Subject: Switch.src
Message-ID: <2092@reed.UUCP>
Date: Fri, 1-Nov-85 18:17:46 EST
Article-I.D.: reed.2092
Posted: Fri Nov  1 18:17:46 1985
Date-Received: Sun, 3-Nov-85 05:56:13 EST
Organization: Reed College, Portland, Oregon
Lines: 98


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);
};