home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-26 | 1.5 KB | 67 lines | [TEXT/MPS ] |
- 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}.
-