home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_01 / cmenu.exe / RCMENU.H < prev    next >
Text File  |  1991-11-12  |  5KB  |  215 lines

  1. /************************************************************
  2.  *    Program: RMENU Menu Interpreter
  3.  *  Module: rcmenu.h -- Interpreter Module header file
  4.  *    Written by: Leor Zolman, 7/91
  5.  ************************************************************/
  6.  
  7. #include <curses.h>
  8.  
  9. /********************** Extern control **********************/
  10.  
  11. #ifndef MASTER
  12. #    define Extern extern
  13. #else
  14. #    define Extern
  15. #endif
  16.  
  17. #define min(x,y) ((x) < (y) ? (x) : (y))
  18.  
  19.  
  20. /********************* Curses Configuration *****************/
  21.  
  22. #ifndef KEY_UP
  23. #    define    OLD_CURSES 1
  24. #else
  25. #    define    OLD_CURSES 0
  26. #endif
  27.  
  28. #if OLD_CURSES
  29. #    define    INIT_FAIL    ERR
  30. #    ifdef CTRL
  31. #        undef CTRL
  32. #    endif
  33. #    define CTRL(x)        ((x) & 037)
  34. #    define    KEY_UP        CTRL('P')
  35. #    define    KEY_DOWN    CTRL('N')
  36. #    define    KEY_LEFT    CTRL('B')
  37. #    define    KEY_RIGHT    CTRL('F')
  38. #    define    beep()        write(1, "\007", 1);
  39. #    define    keypad(a,b)
  40. #else
  41. #    define    INIT_FAIL    NULL
  42. #endif 
  43.  
  44. #if XENIX
  45. #define    resetty reset_tty
  46. #endif
  47.  
  48.  
  49. /*************** Default menu control options ***************/
  50.  
  51. #define    ON_ERROR        50        /* prompt option            */
  52.  
  53. #define    SHELL_PROMPT    FALSE    /* Prompt for shell escape? */
  54.  
  55. #define DEF_PRECLEAR    YES
  56. #define    DEF_POSTCLEAR    NO
  57. #define DEF_PROMPT        ON_ERROR  /*  YES, NO or ON_ERROR    */
  58. #define    DEF_ESCAPE        YES
  59.  
  60. #define    DEF_COLUMNS        1
  61. #define    DEF_SPACING        2
  62.  
  63.  
  64. /************** Screen layout characteristics ***************/
  65.  
  66. #define MAX_IROWS    18        /* # of item rows MUST BE EVEN) */
  67. #define    HOME_Y        2        /* upper left y for 1st Item    */
  68. #define HOME_X        1        /* upper left x for 1st Item    */
  69. #define    SCREEN_COLS    80        /* # of columns on the screen    */
  70.  
  71. #define TITLE_ROW    0        /* row on screen for menu title    */
  72. #define HELP_ROW0    20        /* row that "HELP" sign goes on    */
  73. #define    HELP_COL0    36        /* column that "HELP" sign goes    */
  74. #define HELP_ROW    21        /* row on screen for HELP text    */
  75. #define PROMPT_ROW    23        /* row for prompt text            */
  76.  
  77. /** System/hardware-dependent Key codes and line numbers: ***/
  78.  
  79. #if DOS
  80. #    define LAST_ROW       24    /* last row of screen        */
  81. #    define MAX_PATH_STACK 5        /* maximum nested submenus    */
  82. #else
  83. #    define LAST_ROW     23        /* last row of screen        */
  84. #endif
  85.  
  86. #define ERR_ROW        (PROMPT_ROW - 1)
  87.  
  88.  
  89. /************** Shell Escape Control Parameters *************/
  90.  
  91. #define    SH_PROMPT_STR \
  92.     " Press Enter for sub-shell, ESC to abort\
  93.  ('exit' returns from shell): "
  94.  
  95. #define    MENU_OPTS \
  96.  " Space/arrows/item#=Choose  ENTER=Run\
  97.   'e'=Previous  'x'=Exit "
  98.  
  99. #define MENU_SHELL    " !=shell "
  100. #define MENU_PROMPT " -> "
  101.  
  102. #if DOS
  103. #    define    SHELL_ESC    "command"
  104. #else
  105. #    define SHELL_ESC    "PS1=\"\n('exit' returns to\
  106.  Menu)\n$ \"; export PS1; exec sh -"
  107. #endif
  108.  
  109.  
  110. /********** Other Miscellaneous constants: *****************/
  111.  
  112. #define ESC            033        /* ESC key                        */
  113. #define EXITALL        2        /* "super exit" code            */
  114.  
  115. #define KEY_RUN        '\r'    /* raw-mode Enter key        */
  116.  
  117. #define K_DIRECT    (-2)    /* values returned by get_cmd()    */
  118. #define    K_EXIT        (-3)
  119. #define    K_EXITALL    (-4)
  120. #define    K_SHELL        (-5)
  121. #define    K_UNKNOWN    (-6)
  122. #define    K_VERSION    (-7)    /* report version number        */
  123.  
  124. #define    STANDOUT    1        /* video mode codes passed to    */
  125. #define    NORMAL        2        /* the draw_item() function        */
  126.  
  127.  
  128. /********************* Global data **************************/
  129.  
  130. Extern struct levels {
  131.     int n_menus;                /* # currently active    */
  132.     int max_menus;                /* highest ever active    */
  133.     struct menu2 {
  134.         int most_items;            /* most Items allocated    */
  135.         MENU Menu;                /* the header structure    */
  136.         ITEM *Items[MAX_ITEMS];    /* the actual items        */
  137.  
  138.         int field_len;            /* length of item field    */
  139.         struct coord {            /* coords of each item    */
  140.             int ypos, xpos;
  141.             int spaces_needed;    /* # of spaces to fill    */
  142.         } coords[MAX_ITEMS];
  143.  
  144.     } *Menus[MAX_MENUS];
  145. } LMenus[MAX_NEST];
  146.  
  147. typedef struct levels LEVELS;
  148. typedef struct menu2 MENU2;
  149. typedef struct coord COORDS;
  150.  
  151. Extern    int        nestlev;        /* current nesting level        */
  152. Extern    int        echox, echoy;    /* Location of item # echo area */
  153. Extern    int        debug;            /* true to display sys commands    */
  154.  
  155. /********************* Prototypes: **************************/
  156.  
  157. #if __STDC__ || XENIX        /* Standard C, supporting prototypes: */
  158.  
  159. void    init_win(void);
  160. void    close_win(void);
  161. void    pre_shell(void);
  162. void    post_shell(void);
  163. void    tty_curses(void);
  164. void    tty_shell(void);
  165. void    push_path(void);
  166. void    pop_path(void);
  167.  
  168. int     ld_menu(char *);
  169. void    placement(MENU *);
  170. void    free_menus(void);
  171. int        do_menu(char *, char *);
  172. int        sub_menu(int, char *);
  173. void    draw_menu(MENU2 *, int);
  174. int        get_cmd(int, int, int *);
  175. int        put_msg(int, char *, ...);
  176. int        do_item(MENU2 *, int, char *);
  177. void    draw_item(MENU2 *, int, int, int);
  178. int     fatal(char *, ...);
  179. void    do_cmnd(ITEM *, char *);
  180. int        do_emenu(ITEM *, char *);
  181. int        system0(char *);
  182. char *    make_path( char *, char *);
  183. char *    make_cmd( char *, char *);
  184.  
  185. #else        /* K&R C, minimal "prototypes:" */
  186.  
  187. int        init_win();
  188. int        close_win();
  189. int        pre_shell();
  190. int        post_shell();
  191. int        tty_curses();
  192. int        tty_shell();
  193. int        push_path();
  194. int        pop_path();
  195.  
  196. int     ld_menu();
  197. int        placement();
  198. int        free_menus();
  199. int        do_menu();
  200. int        sub_menu();
  201. int        draw_menu();
  202. int        get_cmd();
  203. int        put_msg();
  204. int        do_item();
  205. int        draw_item();
  206. int     fatal();
  207. int        do_cmnd();
  208. int        do_emenu();
  209. int        system0();
  210. char *    make_path();
  211. char *    make_cmd();
  212.  
  213. #endif
  214.  
  215.