home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / tests / test_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  2.6 KB  |  125 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: test_menu.c,v 4.1 88/06/21 14:02:08 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/tests/RCS/test_menu.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/tests/RCS/test_menu.c,v $$Revision: 4.1 $";
  12.  
  13.  
  14. /* test out menus */
  15.  
  16. #include <stdio.h>
  17. #include "term.h"
  18. #include <signal.h>
  19.  
  20. #define TERM        "mgr"            /* name of valid terminal id */
  21. #define MAX        3            /* # of menus */
  22.  
  23. char foo[25];
  24.  
  25. struct menu_entry menu1[] = {
  26.     "menu 1","1",
  27.     foo,"g",
  28.     "cat","c",
  29.     "mouse","m",
  30.     "elephant","e",
  31.     };
  32.  
  33. struct menu_entry menu2[] = {
  34.     "menu 2","1",
  35.     foo,"g",
  36.     "slate","s",
  37.     "sand","m",
  38.     "quartz","q",
  39.     };
  40.  
  41. struct menu_entry menu3[] = {
  42.     "menu 3","3",
  43.     foo,"g",
  44.     "carrot","c",
  45.     "egg plant","e",
  46.     "string beans","q",
  47.     };
  48.  
  49. struct menus {
  50.    struct menu_entry *menu;
  51.    int count;
  52.    };
  53.  
  54. struct menus menus[] = {
  55.    menu1, 5,
  56.    menu2, 5,
  57.    menu3, 5,
  58.    (struct menu_entry *) 0, 0
  59.    };
  60.  
  61.  
  62. main(argc,argv)
  63. int argc;
  64. char **argv;
  65.    {
  66.    char *getenv();
  67.    char *term = getenv("TERM");
  68.    char line[80];            /* event input buffer */
  69.    register char c;
  70.    register int i, n;
  71.    int x,y;
  72.    int clean();
  73.    
  74.    /* make sure environment is ok */
  75.  
  76.    if (term!=NULL && strcmp(term,TERM)!=0) {
  77.       fprintf(stderr,"%s only runs on %s terminals\n",argv[0],TERM);
  78.       exit(1);
  79.       }
  80.  
  81.    signal(SIGINT,clean);
  82.    signal(SIGTERM,clean);
  83.  
  84.    m_setup(M_FLUSH);
  85.    m_ttyset();
  86.    m_push(P_MENU|P_EVENT);
  87.  
  88.    m_nomenu();
  89.    m_setevent(BUTTON_2,"[%p]");
  90.    m_setevent(BUTTON_2U,"$");
  91.    m_setraw();
  92.  
  93.    fprintf(stderr,"Use the middle button to activate a menu\r\n");
  94.    while ((c=getc(m_termin)) != 'q') {
  95.      switch(c) {
  96.         case '[':                /* button down */
  97.            fscanf(m_termin,"%d %d]",&x,&y);
  98.            fprintf(stderr,"got %d %d selecting %d\t",x,y,x*MAX/1000+1);
  99.            n = x * MAX/1000;
  100.            sprintf(foo,"at %d,%d\n",x,y);
  101.            menu_load(n+1,menus[n].count,menus[n].menu);
  102.            m_selectmenu(n+1);
  103.            break;
  104.         case '$':                /* button up */
  105.            fprintf(stderr,"done\r\n");
  106.            m_nomenu();
  107.            break;
  108.         default:                /* menu selection */
  109.            fprintf(stderr,"got %c\t",c);
  110.            break;
  111.         }
  112.      }
  113.    clean(0);
  114.    }
  115.  
  116. /* clean up and exit */
  117.  
  118. clean(n)
  119. int n;
  120.    {
  121.    m_pop();
  122.    m_ttyreset();
  123.    exit(n);
  124.    }
  125.