home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
menustuf.sit
/
FindMenuItem.p
< prev
next >
Wrap
Text File
|
1990-04-16
|
2KB
|
67 lines
Program FindMenuItem;
{
This program is an MPW tool which returns the number of a menu item
matching the specified text. Call it from the MPW Shell as follows:
FindMenuItem menuName itemText
where menuName is the name of the menu to be searched, and itemText
is the text of the item to search for. The tool will write the decimal
item number to its standard output, or zero if the text was not found.
Written by LDO 1989 May 26.
Modified 1989 January 4 to initialise QuickDraw (just in case) and
move useful stuff to MenuStuffCommon for use by the other tools in this set.
}
Uses
MemTypes,
QuickDraw,
OSIntf,
ToolIntf,
PackIntf,
IntEnv,
MenuStuffCommon;
Var
TheMenu : MenuHandle;
ThisItem, NrItems : Integer;
ThisItemText : Str255;
Begin
InitGraf(@ThePort);
If ArgC > 2 then
Begin
TheMenu := FindMenu(ArgV^[1]^);
If TheMenu <> Nil then
Begin
NrItems := CountMItems(TheMenu);
ThisItem := 0;
Repeat {until left}
If ThisItem = NrItems then
Begin
ThisItem := 0; { not found }
Leave
End {If};
ThisItem := ThisItem + 1;
GetItem(TheMenu, ThisItem, ThisItemText);
If ThisItemText = ArgV^[2]^ then
Leave { found }
Until
False;
Writeln(Output, ThisItem : 1);
IEExit(0)
End
else
Begin
Writeln(Diagnostic, '### ', ArgV^[0]^, ' - menu "', ArgV^[1]^, '" not found');
IEExit(2)
End
End
else
Begin
Writeln(Diagnostic, '### ', ArgV^[0]^, ' - not enough arguments');
IEExit(1)
End
End {SetMenu}.