v08i049: xmenu, Patch1, Part01/01

Richard Hesketh rlh2 at ukc.ac.uk
Mon Jul 9 17:23:33 AEST 1990


Submitted-by: Richard Hesketh <rlh2 at ukc.ac.uk>
Posting-number: Volume 8, Issue 49
Archive-name: xmenu/patch1
Patch-To: xmenu: Volume 8, Issue 8

This patches some problems found by JQ Johnson <jqj at rt-jqj.stanford.edu>,
who also offered the extensions.

Note that now, by default, the name of the menu item is printed.  To
have nothing printed simply use "item=".  Plus the "line" argument has
been changed to "-line".  Also xmenu now sets the exit status ala xmessage;
the menu items being numbered from 101.

Richard Hesketh   :   @nsfnet-relay.ac.uk:rlh2 at ukc.ac.uk
		  :   rlh2 at ukc.ac.uk    ..!mcvax!ukc!rlh2
---                                               
Computing Lab., University of Kent at Canterbury,
Canterbury, Kent, CT2 7NF, United Kingdom.    Tel: +44 227 764000 ext 7620/3682

----
*** DIST/README	Fri Jun 29 16:52:41 1990
--- README	Fri Jun 29 17:03:31 1990
***************
*** 4,10 ****
  the command line arguments as menu entries.  If an argument contains
  a non-escaped '=' (equals sign) the string to the left is the name
  displayed in the menu and the string to the right is the text output
! when this menu button is pressed.
  
  A special argument "line" can be used to draw a dividing line between
  successive menu entries.
--- 4,11 ----
  the command line arguments as menu entries.  If an argument contains
  a non-escaped '=' (equals sign) the string to the left is the name
  displayed in the menu and the string to the right is the text output
! when this menu button is pressed.  If no equals sign is given the name of
! the menu button is output.
  
  A special argument "line" can be used to draw a dividing line between
  successive menu entries.

*** DIST/patchlevel.h	Fri Jun 29 16:52:42 1990
--- patchlevel.h	Fri Jun 29 17:03:31 1990
***************
*** 1 ****
! #define patchlevel 0
--- 1 ----
! #define patchlevel 1

*** DIST/xmenu.c	Fri Jun 29 16:52:43 1990
--- xmenu.c	Fri Jun 29 17:04:06 1990
***************
*** 1,5 ****
  #ifndef lint
! static char rcsid[] = "$Header: xmenu.c,v 1.1 90/06/19 16:59:36 rlh2 Rel $";
  #endif !lint
  
  /* 
--- 1,5 ----
  #ifndef lint
! static char rcsid[] = "$Header: xmenu.c 1.3 90/06/29 17:00:22 rlh2 Rel $";
  #endif !lint
  
  /* 
***************
*** 38,44 ****
   * displayed in the menu and the string to the right is the text output
   * when this menu button is pressed.
   *
!  * A special argument "line" can be used to draw a dividing line between
   * successive menu entries.
   *
   * A menu title can be given as an argument after a "-heading" flag.
--- 38,44 ----
   * displayed in the menu and the string to the right is the text output
   * when this menu button is pressed.
   *
!  * A special argument "-line" can be used to draw a dividing line between
   * successive menu entries.
   *
   * A menu title can be given as an argument after a "-heading" flag.
***************
*** 52,62 ****
   *
   *	xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \
   *			"C sources"="*.c" "Headers"="*.h" \
!  *			line line "        Cancel"
   *
!  *	xmenu Hello="Hello World" line " " " " line Goodbye="Goodbye World"
   */
  
  #include <X11/Intrinsic.h>
  #include <X11/StringDefs.h>
  #include <X11/Xaw/SimpleMenu.h>
--- 52,63 ----
   *
   *	xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \
   *			"C sources"="*.c" "Headers"="*.h" \
!  *			-line -line "        Cancel"
   *
!  *	xmenu Hello="Hello World" -line "" "" -line Goodbye="Goodbye World"
   */
  
+ #include <stdio.h>
  #include <X11/Intrinsic.h>
  #include <X11/StringDefs.h>
  #include <X11/Xaw/SimpleMenu.h>
***************
*** 64,71 ****
  #include <X11/Xaw/SmeLine.h>
  
  #define LINE (String)1
! #define LINE_TOK "line"
  
  static String MTrans = "<EnterWindow>: highlight()\n\
  			<LeaveWindow>: unhighlight()\n\
  			<MotionNotify>: highlight()\n\
--- 65,78 ----
  #include <X11/Xaw/SmeLine.h>
  
  #define LINE (String)1
! #define LINE_TOK "-line"
! #define STATUS_START 101
  
+ struct ret {
+ 	String out_val;
+ 	Cardinal exit_status;
+ };
+ 
  static String MTrans = "<EnterWindow>: highlight()\n\
  			<LeaveWindow>: unhighlight()\n\
  			<MotionNotify>: highlight()\n\
***************
*** 82,106 ****
  Widget w;
  XtPointer client_data, call_data;
  {
! 	if (client_data != NULL)
! 		printf("%s\n", client_data);
! 	exit(0);
  }
  
  String
! get_prompt(str, out_val)
  String str;
! String *out_val;
  {
  	int s, t;
  	char name[1000];
  	Boolean found_escape = FALSE;
  
! 	*out_val = NULL;
  
  	if (strncmp(str, LINE_TOK, strlen(LINE_TOK)) == 0)
  		return (LINE);
  
  	for (t = s = 0; str[s] != '\0'; s++) {
  		if (str[s] == '\\') {
  			if (found_escape) {
--- 89,120 ----
  Widget w;
  XtPointer client_data, call_data;
  {
! 	struct ret *values = (struct ret *)client_data;
! 
! 	if (values->out_val != NULL)
! 		fprintf(stdout, "%s\n", values->out_val);
! 	exit(values->exit_status);
  }
  
+ 
  String
! get_prompt(str, values)
  String str;
! struct ret **values;
  {
+ 	static Cardinal count = STATUS_START;
  	int s, t;
  	char name[1000];
  	Boolean found_escape = FALSE;
  
! 	*values = NULL;
  
  	if (strncmp(str, LINE_TOK, strlen(LINE_TOK)) == 0)
  		return (LINE);
  
+ 	*values = XtNew(struct ret);
+ 	(*values)->out_val = NULL;
+ 
  	for (t = s = 0; str[s] != '\0'; s++) {
  		if (str[s] == '\\') {
  			if (found_escape) {
***************
*** 113,119 ****
  				found_escape = FALSE;
  				name[t++] = '=';
  			} else {
! 				*out_val = str + s + 1;
  				break;
  			}
  		} else
--- 127,133 ----
  				found_escape = FALSE;
  				name[t++] = '=';
  			} else {
! 				(*values)->out_val = str + s + 1;
  				break;
  			}
  		} else
***************
*** 120,125 ****
--- 134,143 ----
  			name[t++] = str[s];
  	}
  	name[t] = '\0';
+ 	if ((*values)->out_val == NULL)
+ 		(*values)->out_val = str;
+ 
+ 	(*values)->exit_status = count++;
  	return (XtNewString(name));
  }
  
***************
*** 136,145 ****
  	int junk2;
  	unsigned int junk3;
  	Display *dpy;
! 	String out_val;
  	String name, heading;
  	char *blank;
  	XrmValue value;
  
  	x = y = 400; /* just in case XQueryPointer() fails 8-) */
  
--- 154,164 ----
  	int junk2;
  	unsigned int junk3;
  	Display *dpy;
! 	struct ret *output_values;
  	String name, heading;
  	char *blank;
  	XrmValue value;
+ 	Boolean used_callback = FALSE;
  
  	x = y = 400; /* just in case XQueryPointer() fails 8-) */
  
***************
*** 169,179 ****
  	if (heading != NULL)
  		button = XtVaCreateManagedWidget("menuLine", 
  					smeLineObjectClass, shell,
! 					XtNlineWidth, 3,
  					NULL);
  
  	for (i = 1; i < argc; i++) {
! 		name = get_prompt(argv[i], &out_val);
  
  		if (name == LINE)
  			button = XtVaCreateManagedWidget("menuLine",
--- 188,198 ----
  	if (heading != NULL)
  		button = XtVaCreateManagedWidget("menuLine", 
  					smeLineObjectClass, shell,
! 					XtNlineWidth, 2,
  					NULL);
  
  	for (i = 1; i < argc; i++) {
! 		name = get_prompt(argv[i], &output_values);
  
  		if (name == LINE)
  			button = XtVaCreateManagedWidget("menuLine",
***************
*** 185,192 ****
  					XtNlabel, name,
  					NULL);
  			XtAddCallback(button, XtNcallback, button_pressed,
! 					(XtPointer)out_val);
  		}
  	}
  
  	XtRealizeWidget(shell);
--- 204,216 ----
  					XtNlabel, name,
  					NULL);
  			XtAddCallback(button, XtNcallback, button_pressed,
! 					(XtPointer)output_values);
! 			used_callback = TRUE;
  		}
+ 	}
+ 	if (!used_callback) {
+ 		fprintf(stderr, "xmenu: no menu items given.\n");
+ 		exit(1);
  	}
  
  	XtRealizeWidget(shell);

*** DIST/xmenu.man	Fri Jun 29 16:52:43 1990
--- xmenu.man	Fri Jun 29 17:03:33 1990
***************
*** 2,8 ****
  .SH NAME
  xmenu \- provide simple popup menus to shell scripts
  .SH SYNOPSIS
! \fBxmenu\fP [-heading "menu title"] [menu_entry[=output_value] | line]...
  .SH DESCRIPTION
  \fIxmenu\fP provides a quick and easy way of producing a single popup
  menu for use by shell scripts.  The \fI-heading\fP is used to set the menu's
--- 2,8 ----
  .SH NAME
  xmenu \- provide simple popup menus to shell scripts
  .SH SYNOPSIS
! \fBxmenu\fP [-heading "menu title"] [menu_entry[=output_value] | -line]...
  .SH DESCRIPTION
  \fIxmenu\fP provides a quick and easy way of producing a single popup
  menu for use by shell scripts.  The \fI-heading\fP is used to set the menu's
***************
*** 9,27 ****
  title, all other arguments are used as items in the menu.  If an argument
  contains an equals sign then the string to the left of the equals is used as
  the displayed menu item and the the string to the right is used as the text
! output when the item is pressed.  The argument "line" is recognised as
! denoting a line separating menu items.
  
  By default the menu is popped up to the right and below of the current pointer
  position but this can be overridden using the standard toolkit "-geometry". 
  .SH EXAMPLES
  .DS
  xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \\
                         "C sources"="*.c" "Headers"="*.h" \\
!                        line line "        Cancel"
  
! xmenu Hello="Hello World" line " " " " line Goodbye="Goodbye World"
  .DE
  .SH AUTHOR
  Richard Hesketh, University of Kent at Canterbury, June 1990
  .br
--- 9,35 ----
  title, all other arguments are used as items in the menu.  If an argument
  contains an equals sign then the string to the left of the equals is used as
  the displayed menu item and the the string to the right is used as the text
! output when the item is pressed.  If no equals sign is present in the
! argument then the argument itself is output.  The argument "-line" is
! recognised as denoting a line separating menu items.
  
  By default the menu is popped up to the right and below of the current pointer
  position but this can be overridden using the standard toolkit "-geometry". 
+ 
+ Following the example of \fIxmessage\fP the exit status is set to a number
+ greater than or equal to 101, indicating which menu item was pressed.
  .SH EXAMPLES
  .DS
  xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \\
                         "C sources"="*.c" "Headers"="*.h" \\
!                        -line -line "        Cancel"
  
! xmenu Hello="Hello World" -line " " " " -line Goodbye="Goodbye World"
  .DE
+ .SH EXIT STATUS
+ The exit status is set to a number greater than or equal to 101.  This number
+ corresponds to the position of the pressed button in the menu, 101 for the
+ first button, 102 for the second and so on.
  .SH AUTHOR
  Richard Hesketh, University of Kent at Canterbury, June 1990
  .br


dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list