home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / menustuf.sit / FindMenuItem.p < prev    next >
Text File  |  1990-04-16  |  2KB  |  67 lines

  1. Program FindMenuItem;
  2. {
  3.     This program is an MPW tool which returns the number of a menu item
  4.     matching the specified text. Call it from the MPW Shell as follows:
  5.  
  6.         FindMenuItem menuName itemText
  7.  
  8.     where menuName is the name of the menu to be searched, and itemText
  9.     is the text of the item to search for. The tool will write the decimal
  10.     item number to its standard output, or zero if the text was not found.
  11.  
  12.     Written by LDO 1989 May 26.
  13.     Modified 1989 January 4 to initialise QuickDraw (just in case) and
  14.     move useful stuff to MenuStuffCommon for use by the other tools in this set.
  15. }
  16.  
  17.     Uses
  18.         MemTypes,
  19.         QuickDraw,
  20.         OSIntf,
  21.         ToolIntf,
  22.         PackIntf,
  23.         IntEnv,
  24.         MenuStuffCommon;
  25.  
  26.     Var
  27.         TheMenu : MenuHandle;
  28.         ThisItem, NrItems : Integer;
  29.         ThisItemText : Str255;
  30.  
  31.   Begin
  32.     InitGraf(@ThePort);
  33.     If ArgC > 2 then
  34.       Begin
  35.         TheMenu := FindMenu(ArgV^[1]^);
  36.         If TheMenu <> Nil then
  37.           Begin
  38.             NrItems := CountMItems(TheMenu);
  39.             ThisItem := 0;
  40.             Repeat {until left}
  41.                 If ThisItem = NrItems then
  42.                   Begin
  43.                     ThisItem := 0; { not found }
  44.                     Leave
  45.                   End {If};
  46.                 ThisItem := ThisItem + 1;
  47.                 GetItem(TheMenu, ThisItem, ThisItemText);
  48.                 If ThisItemText = ArgV^[2]^ then
  49.                     Leave { found }
  50.             Until
  51.                 False;
  52.             Writeln(Output, ThisItem : 1);
  53.             IEExit(0)
  54.           End
  55.         else
  56.           Begin
  57.             Writeln(Diagnostic, '### ', ArgV^[0]^, ' - menu "', ArgV^[1]^, '" not found');
  58.             IEExit(2)
  59.           End
  60.       End
  61.     else
  62.       Begin
  63.         Writeln(Diagnostic, '### ', ArgV^[0]^, ' - not enough arguments');
  64.         IEExit(1)
  65.       End
  66.   End {SetMenu}.
  67.