function [label, acc] = menulabel(inlabel)
%MENULABEL Parse menu label for keyboard equivalent and accelerator keys.
%	[LABEL, ACC] = MENULABEL(INLABEL) parses the string INLABEL
%	to determine the appropriate label-setting string to use in
%	a uimenu call.  In the INLABEL string, use a & before a letter
%	to make that letter the keyboard equivalent.  If you
%	really want an '&' in your menu label, put '\&' in INLABEL.
%	Use a '^q' at the end of the string to make 'q' an
%	accelerator key.
%
%	Example:
%	  [label, acc] = menulabel('File')
%	returns with label = 'File' and acc = [].
%
%	Example:
%	  [label, acc] = menulabel('&Quit ^q')
%	returns with label = '&Quit' (computer = PCWIN) or 
%	label = 'Quit' (computer ~= PCWIN), and acc = 'q'.
%
%	Example:
%	  [label, acc] = menulabel('&x \& y')
%	returns with label = '&x && y' (PCWIN), label = 'x & y'
%	(~PCWIN), and acc = [].

%	Steven L. Eddins, 27 May 1994
%	Copyright (c) 1984-1994 by The MathWorks, Inc.
%	$Revision: 1.9 $  $Date: 1994/12/28 17:23:37 $

pc_flag = strcmp(computer, 'PCWIN');
mac_flag = strcmp(computer, 'MAC2');

% First, let's take care of keyboard equivalents.  If we're not
% on a PC, replace '&Q' by 'Q' and '\&' by '&', because keyboard
% equivalents exist only on the PC.

if (~pc_flag)
  index = (inlabel == '&');
  if (any(inlabel == '\'))
    loc = findstr(inlabel, '\&');
    index(loc+1) = zeros(size(loc));
    index(loc) = ones(size(loc));
  end
  inlabel(index) = [];
else
  loc = findstr(inlabel, '\&');
  amp = '&';
  inlabel(loc) = amp(1,ones(1,length(loc)));
end

% Find the accelerator key, if any.
L = length(inlabel);
if (L > 1)
  if (inlabel(L-1) == '^')
    acc = inlabel(L);
    inlabel(L-1:L) = [];
  else
    acc = setstr([]);
  end
else
  acc = setstr([]);
end

% On the Mac, accelerators are case-insensitive and normally 
% indicated by upper-case on the screen, whereas in X they
% are case sensitive and most often use lower case.  So if
% we're on a Mac, convert the desired accelerator key to upper
% case.

if (mac_flag)
  acc = upper(acc);
end

label = inlabel;
