home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xmenu / patch1 < prev    next >
Text File  |  1990-07-08  |  11KB  |  381 lines

  1. Path: uunet!tut.cis.ohio-state.edu!cs.utexas.edu!sun-barr!newstop!sun!ukc.ac.uk
  2. From: rlh2@ukc.ac.uk (Richard Hesketh)
  3. Newsgroups: comp.sources.x
  4. Subject: v08i049: xmenu, Patch1, Part01/01
  5. Message-ID: <138565@sun.Eng.Sun.COM>
  6. Date: 9 Jul 90 07:23:33 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 370
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: Richard Hesketh <rlh2@ukc.ac.uk>
  12. Posting-number: Volume 8, Issue 49
  13. Archive-name: xmenu/patch1
  14. Patch-To: xmenu: Volume 8, Issue 8
  15.  
  16. This patches some problems found by JQ Johnson <jqj@rt-jqj.stanford.edu>,
  17. who also offered the extensions.
  18.  
  19. Note that now, by default, the name of the menu item is printed.  To
  20. have nothing printed simply use "item=".  Plus the "line" argument has
  21. been changed to "-line".  Also xmenu now sets the exit status ala xmessage;
  22. the menu items being numbered from 101.
  23.  
  24. Richard Hesketh   :   @nsfnet-relay.ac.uk:rlh2@ukc.ac.uk
  25.           :   rlh2@ukc.ac.uk    ..!mcvax!ukc!rlh2
  26. ---                                               
  27. Computing Lab., University of Kent at Canterbury,
  28. Canterbury, Kent, CT2 7NF, United Kingdom.    Tel: +44 227 764000 ext 7620/3682
  29.  
  30. ----
  31. *** DIST/README    Fri Jun 29 16:52:41 1990
  32. --- README    Fri Jun 29 17:03:31 1990
  33. ***************
  34. *** 4,10 ****
  35.   the command line arguments as menu entries.  If an argument contains
  36.   a non-escaped '=' (equals sign) the string to the left is the name
  37.   displayed in the menu and the string to the right is the text output
  38. ! when this menu button is pressed.
  39.   
  40.   A special argument "line" can be used to draw a dividing line between
  41.   successive menu entries.
  42. --- 4,11 ----
  43.   the command line arguments as menu entries.  If an argument contains
  44.   a non-escaped '=' (equals sign) the string to the left is the name
  45.   displayed in the menu and the string to the right is the text output
  46. ! when this menu button is pressed.  If no equals sign is given the name of
  47. ! the menu button is output.
  48.   
  49.   A special argument "line" can be used to draw a dividing line between
  50.   successive menu entries.
  51.  
  52. *** DIST/patchlevel.h    Fri Jun 29 16:52:42 1990
  53. --- patchlevel.h    Fri Jun 29 17:03:31 1990
  54. ***************
  55. *** 1 ****
  56. ! #define patchlevel 0
  57. --- 1 ----
  58. ! #define patchlevel 1
  59.  
  60. *** DIST/xmenu.c    Fri Jun 29 16:52:43 1990
  61. --- xmenu.c    Fri Jun 29 17:04:06 1990
  62. ***************
  63. *** 1,5 ****
  64.   #ifndef lint
  65. ! static char rcsid[] = "$Header: xmenu.c,v 1.1 90/06/19 16:59:36 rlh2 Rel $";
  66.   #endif !lint
  67.   
  68.   /* 
  69. --- 1,5 ----
  70.   #ifndef lint
  71. ! static char rcsid[] = "$Header: xmenu.c 1.3 90/06/29 17:00:22 rlh2 Rel $";
  72.   #endif !lint
  73.   
  74.   /* 
  75. ***************
  76. *** 38,44 ****
  77.    * displayed in the menu and the string to the right is the text output
  78.    * when this menu button is pressed.
  79.    *
  80. !  * A special argument "line" can be used to draw a dividing line between
  81.    * successive menu entries.
  82.    *
  83.    * A menu title can be given as an argument after a "-heading" flag.
  84. --- 38,44 ----
  85.    * displayed in the menu and the string to the right is the text output
  86.    * when this menu button is pressed.
  87.    *
  88. !  * A special argument "-line" can be used to draw a dividing line between
  89.    * successive menu entries.
  90.    *
  91.    * A menu title can be given as an argument after a "-heading" flag.
  92. ***************
  93. *** 52,62 ****
  94.    *
  95.    *    xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \
  96.    *            "C sources"="*.c" "Headers"="*.h" \
  97. !  *            line line "        Cancel"
  98.    *
  99. !  *    xmenu Hello="Hello World" line " " " " line Goodbye="Goodbye World"
  100.    */
  101.   
  102.   #include <X11/Intrinsic.h>
  103.   #include <X11/StringDefs.h>
  104.   #include <X11/Xaw/SimpleMenu.h>
  105. --- 52,63 ----
  106.    *
  107.    *    xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \
  108.    *            "C sources"="*.c" "Headers"="*.h" \
  109. !  *            -line -line "        Cancel"
  110.    *
  111. !  *    xmenu Hello="Hello World" -line "" "" -line Goodbye="Goodbye World"
  112.    */
  113.   
  114. + #include <stdio.h>
  115.   #include <X11/Intrinsic.h>
  116.   #include <X11/StringDefs.h>
  117.   #include <X11/Xaw/SimpleMenu.h>
  118. ***************
  119. *** 64,71 ****
  120.   #include <X11/Xaw/SmeLine.h>
  121.   
  122.   #define LINE (String)1
  123. ! #define LINE_TOK "line"
  124.   
  125.   static String MTrans = "<EnterWindow>: highlight()\n\
  126.               <LeaveWindow>: unhighlight()\n\
  127.               <MotionNotify>: highlight()\n\
  128. --- 65,78 ----
  129.   #include <X11/Xaw/SmeLine.h>
  130.   
  131.   #define LINE (String)1
  132. ! #define LINE_TOK "-line"
  133. ! #define STATUS_START 101
  134.   
  135. + struct ret {
  136. +     String out_val;
  137. +     Cardinal exit_status;
  138. + };
  139.   static String MTrans = "<EnterWindow>: highlight()\n\
  140.               <LeaveWindow>: unhighlight()\n\
  141.               <MotionNotify>: highlight()\n\
  142. ***************
  143. *** 82,106 ****
  144.   Widget w;
  145.   XtPointer client_data, call_data;
  146.   {
  147. !     if (client_data != NULL)
  148. !         printf("%s\n", client_data);
  149. !     exit(0);
  150.   }
  151.   
  152.   String
  153. ! get_prompt(str, out_val)
  154.   String str;
  155. ! String *out_val;
  156.   {
  157.       int s, t;
  158.       char name[1000];
  159.       Boolean found_escape = FALSE;
  160.   
  161. !     *out_val = NULL;
  162.   
  163.       if (strncmp(str, LINE_TOK, strlen(LINE_TOK)) == 0)
  164.           return (LINE);
  165.   
  166.       for (t = s = 0; str[s] != '\0'; s++) {
  167.           if (str[s] == '\\') {
  168.               if (found_escape) {
  169. --- 89,120 ----
  170.   Widget w;
  171.   XtPointer client_data, call_data;
  172.   {
  173. !     struct ret *values = (struct ret *)client_data;
  174. !     if (values->out_val != NULL)
  175. !         fprintf(stdout, "%s\n", values->out_val);
  176. !     exit(values->exit_status);
  177.   }
  178.   
  179.   String
  180. ! get_prompt(str, values)
  181.   String str;
  182. ! struct ret **values;
  183.   {
  184. +     static Cardinal count = STATUS_START;
  185.       int s, t;
  186.       char name[1000];
  187.       Boolean found_escape = FALSE;
  188.   
  189. !     *values = NULL;
  190.   
  191.       if (strncmp(str, LINE_TOK, strlen(LINE_TOK)) == 0)
  192.           return (LINE);
  193.   
  194. +     *values = XtNew(struct ret);
  195. +     (*values)->out_val = NULL;
  196.       for (t = s = 0; str[s] != '\0'; s++) {
  197.           if (str[s] == '\\') {
  198.               if (found_escape) {
  199. ***************
  200. *** 113,119 ****
  201.                   found_escape = FALSE;
  202.                   name[t++] = '=';
  203.               } else {
  204. !                 *out_val = str + s + 1;
  205.                   break;
  206.               }
  207.           } else
  208. --- 127,133 ----
  209.                   found_escape = FALSE;
  210.                   name[t++] = '=';
  211.               } else {
  212. !                 (*values)->out_val = str + s + 1;
  213.                   break;
  214.               }
  215.           } else
  216. ***************
  217. *** 120,125 ****
  218. --- 134,143 ----
  219.               name[t++] = str[s];
  220.       }
  221.       name[t] = '\0';
  222. +     if ((*values)->out_val == NULL)
  223. +         (*values)->out_val = str;
  224. +     (*values)->exit_status = count++;
  225.       return (XtNewString(name));
  226.   }
  227.   
  228. ***************
  229. *** 136,145 ****
  230.       int junk2;
  231.       unsigned int junk3;
  232.       Display *dpy;
  233. !     String out_val;
  234.       String name, heading;
  235.       char *blank;
  236.       XrmValue value;
  237.   
  238.       x = y = 400; /* just in case XQueryPointer() fails 8-) */
  239.   
  240. --- 154,164 ----
  241.       int junk2;
  242.       unsigned int junk3;
  243.       Display *dpy;
  244. !     struct ret *output_values;
  245.       String name, heading;
  246.       char *blank;
  247.       XrmValue value;
  248. +     Boolean used_callback = FALSE;
  249.   
  250.       x = y = 400; /* just in case XQueryPointer() fails 8-) */
  251.   
  252. ***************
  253. *** 169,179 ****
  254.       if (heading != NULL)
  255.           button = XtVaCreateManagedWidget("menuLine", 
  256.                       smeLineObjectClass, shell,
  257. !                     XtNlineWidth, 3,
  258.                       NULL);
  259.   
  260.       for (i = 1; i < argc; i++) {
  261. !         name = get_prompt(argv[i], &out_val);
  262.   
  263.           if (name == LINE)
  264.               button = XtVaCreateManagedWidget("menuLine",
  265. --- 188,198 ----
  266.       if (heading != NULL)
  267.           button = XtVaCreateManagedWidget("menuLine", 
  268.                       smeLineObjectClass, shell,
  269. !                     XtNlineWidth, 2,
  270.                       NULL);
  271.   
  272.       for (i = 1; i < argc; i++) {
  273. !         name = get_prompt(argv[i], &output_values);
  274.   
  275.           if (name == LINE)
  276.               button = XtVaCreateManagedWidget("menuLine",
  277. ***************
  278. *** 185,192 ****
  279.                       XtNlabel, name,
  280.                       NULL);
  281.               XtAddCallback(button, XtNcallback, button_pressed,
  282. !                     (XtPointer)out_val);
  283.           }
  284.       }
  285.   
  286.       XtRealizeWidget(shell);
  287. --- 204,216 ----
  288.                       XtNlabel, name,
  289.                       NULL);
  290.               XtAddCallback(button, XtNcallback, button_pressed,
  291. !                     (XtPointer)output_values);
  292. !             used_callback = TRUE;
  293.           }
  294. +     }
  295. +     if (!used_callback) {
  296. +         fprintf(stderr, "xmenu: no menu items given.\n");
  297. +         exit(1);
  298.       }
  299.   
  300.       XtRealizeWidget(shell);
  301.  
  302. *** DIST/xmenu.man    Fri Jun 29 16:52:43 1990
  303. --- xmenu.man    Fri Jun 29 17:03:33 1990
  304. ***************
  305. *** 2,8 ****
  306.   .SH NAME
  307.   xmenu \- provide simple popup menus to shell scripts
  308.   .SH SYNOPSIS
  309. ! \fBxmenu\fP [-heading "menu title"] [menu_entry[=output_value] | line]...
  310.   .SH DESCRIPTION
  311.   \fIxmenu\fP provides a quick and easy way of producing a single popup
  312.   menu for use by shell scripts.  The \fI-heading\fP is used to set the menu's
  313. --- 2,8 ----
  314.   .SH NAME
  315.   xmenu \- provide simple popup menus to shell scripts
  316.   .SH SYNOPSIS
  317. ! \fBxmenu\fP [-heading "menu title"] [menu_entry[=output_value] | -line]...
  318.   .SH DESCRIPTION
  319.   \fIxmenu\fP provides a quick and easy way of producing a single popup
  320.   menu for use by shell scripts.  The \fI-heading\fP is used to set the menu's
  321. ***************
  322. *** 9,27 ****
  323.   title, all other arguments are used as items in the menu.  If an argument
  324.   contains an equals sign then the string to the left of the equals is used as
  325.   the displayed menu item and the the string to the right is used as the text
  326. ! output when the item is pressed.  The argument "line" is recognised as
  327. ! denoting a line separating menu items.
  328.   
  329.   By default the menu is popped up to the right and below of the current pointer
  330.   position but this can be overridden using the standard toolkit "-geometry". 
  331.   .SH EXAMPLES
  332.   .DS
  333.   xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \\
  334.                          "C sources"="*.c" "Headers"="*.h" \\
  335. !                        line line "        Cancel"
  336.   
  337. ! xmenu Hello="Hello World" line " " " " line Goodbye="Goodbye World"
  338.   .DE
  339.   .SH AUTHOR
  340.   Richard Hesketh, University of Kent at Canterbury, June 1990
  341.   .br
  342. --- 9,35 ----
  343.   title, all other arguments are used as items in the menu.  If an argument
  344.   contains an equals sign then the string to the left of the equals is used as
  345.   the displayed menu item and the the string to the right is used as the text
  346. ! output when the item is pressed.  If no equals sign is present in the
  347. ! argument then the argument itself is output.  The argument "-line" is
  348. ! recognised as denoting a line separating menu items.
  349.   
  350.   By default the menu is popped up to the right and below of the current pointer
  351.   position but this can be overridden using the standard toolkit "-geometry". 
  352. + Following the example of \fIxmessage\fP the exit status is set to a number
  353. + greater than or equal to 101, indicating which menu item was pressed.
  354.   .SH EXAMPLES
  355.   .DS
  356.   xmenu -heading "Choose Files by Suffix" Compressed="*.Z" \\
  357.                          "C sources"="*.c" "Headers"="*.h" \\
  358. !                        -line -line "        Cancel"
  359.   
  360. ! xmenu Hello="Hello World" -line " " " " -line Goodbye="Goodbye World"
  361.   .DE
  362. + .SH EXIT STATUS
  363. + The exit status is set to a number greater than or equal to 101.  This number
  364. + corresponds to the position of the pressed button in the menu, 101 for the
  365. + first button, 102 for the second and so on.
  366.   .SH AUTHOR
  367.   Richard Hesketh, University of Kent at Canterbury, June 1990
  368.   .br
  369.  
  370.  
  371. dan
  372. ----------------------------------------------------
  373. O'Reilly && Associates   argv@sun.com / argv@ora.com
  374. Opinions expressed reflect those of the author only.
  375.