home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource5
/
315_01
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-16
|
22KB
|
715 lines
/* mgetch() and mgets() were added 9/89 by T Clune. */
/* clear_input_devices() made externally-visible 9/89 by T Clune */
/* print_headline() added 8/89, because I always use this construct anyway. */
/* added by T Clune. */
/* menu_mouse_config() added 8/89 by T. Clune to support user-configuration */
/* of mouse parameters, as per Frans VdV request. */
/* get_file() was added to menu.c [it was formerly in grabmain.c] and */
/* dir_menu() was eliminated 12/88, and get_dir() in dos_func.c was */
/* rewritten to use string pointers instead of character arrays. Now */
/* get_dir() is compatible with menu(), so dir_menu() is superfluous. */
/* Modified by T Clune. */
/* Modified by T Clune 12/88 to support mouse selection of menu items. */
/* menu.obj must be linked with mouselib.obj and sound.obj and the */
/* Microsoft library mouse.lib now. Sound.obj is used to generate the */
/* pause between mouse queries to give a pause between menu */
/* selections, analogous to the pause in keyboard repeats. Mouselib.obj */
/* is my mouse library front end. */
/* pathprint() added to menu.c 11/20/88 by T. Clune. Moved from */
/* tmbr_gp.c for conceptual unity. */
/* c_dir fname_unused() and get_dir() functions moved to dos_func.c */
/* 11/88 by T. Clune. */
/* c_dir.c functions added to menu.c 6/88 by T. Clune. */
/* the dir_menu() function supports a menu() -style selection of */
/* directory files. */
/* written by T. Clune for R. Webb, 5/18/88. */
/* Copyright (c) 1988, Eye Research Institute, 20 Staniford St., Boston, MA */
/* All rights reserved. */
/* menu.c is a menu-creation utility for use with large memory model */
/* Microsoft C routines. It expects to run on an IBM PC or At with */
/* either monchrome (including Hercules in text mode) or CGA adaptor */
/* menu() and reset_menu() are externally visible, highlight() is an */
/* internal routine called by menu() only. Written by Thomas Clune */
/* for the Eye Research Institute, 20 Staniford St., Boston, MA 02114 */
/* Copyright 1987, E.R.I. All rights reserved. */
#include "msc_hdrs.h" /* the usual gang of MS C headers */
#include "menu.h"
#include "ansi.h"
#include "mouselib.h"
#include "keys.h"
#include "sound.h"
#include "dos_func.h"
#define HERC_BASE 0XB0000000 /* base address of mono card */
#define CGA_BASE 0XB8000000 /* base address of color card */
static unsigned char off = 7; /* unlit character attribute code */
static unsigned char on = 112; /* lit character attribute code */
static int mouse_flag=KEYBOARD_ONLY; /* flag for whether mouse-based selection is */
/* active. Set to NO for compatibility with old version of menu.c */
/* See mouse_flag_toggle() for mouse_flag values */
static double off_time=OFF_TIME;
static double duty_time=DUTY_TIME;
static int mouse_sensitivity=MOUSE_SENSITIVITY;
static char *screen_ptr; /* base of screen memory to be named later */
static char *mode_ptr = (char *)0X00000410; /* mode memory address */
static void highlight(); /* local function for turning reverse */
/* video on and off */
static int get_response(); /* the operator-selection function, added 12/88 */
/* to support mouse input option as well as keyboard input */
static int mouse_read(); /* mouse support function for get_response() */
/* +++++++++++++++++ clear_input_devices() +++++++++++++++++++++++++ */
/* clear_input_devices() makes sure that no keypresses are pending */
/* or mouse buttons depressed before the menu selection is active */
void clear_input_devices()
{
int delay=0;
/* clear the keyboard bufffer */
if((mouse_flag != MOUSE_ONLY) && kbhit())
while(kbhit())
getch();
/* if the mouse is active, make sure the buttons are not depressed on entry */
if((mouse_flag !=KEYBOARD_ONLY) && (button_read().status != 0))
{
do
{
pause(0.1);
delay++;
}while((button_read().status != 0) && (delay<20));
/* after 2 secs, tell 'em to get their finger off the damn button */
if(delay>=20)
{
while(button_read().status !=0)
mouse_warning_sound();
}
}
}
/* +++++++++++++++++++++ get_file() +++++++++++++++++++++++++++++++++ */
/* get a filename by selecting from highlighting menu. Val returned is 0 */
/* unless there are too many files for this routine to process, in which case */
/* the f.error_flag is -1, or unless QUIT is the menu item selected, in which */
/* case f.error_flag is set to 1. The memory freed in get_file() was allocated */
/* in get_dir() (ind dos_func.c) except for the QUIT string area, which was */
/* allocated here. */
string_struc get_file()
{
int i,j,k;
int length;
static char *fnames[MAX_FILES+1];
static string_struc f;
static char dir_name[40]="";
int default_flag=0;
static char spec[14]="*.*";
char search_name[54];
static int last_choice=0;
char c;
f.error_flag=0;
CLS;
if(!strlen(dir_name))
{
strcpy(search_name, "Default directory");
default_flag=1;
}
else
strcpy(search_name, dir_name);
printf("Current search path is %s\n",search_name);
printf("Enter new path, or <CR> to keep current path\n");
if(mouse_flag != KEYBOARD_ONLY)
mouse_gets(dir_name);
else
gets(dir_name);
if((!strlen(dir_name)) && (default_flag == 0))
strcpy(dir_name, search_name);
printf("Enter file format for search, or <CR> to keep default %s\n", spec);
if(mouse_flag != KEYBOARD_ONLY)
mouse_gets(f.string);
else
gets(f.string);
if(strlen(f.string))
strcpy(spec, f.string);
strcpy(search_name, dir_name);
length=strlen(search_name);
if(length && (!(search_name[length-1]=='\\')))
strcat(search_name, "\\");
strcat(search_name, spec);
i=get_dir(search_name,fnames,MAX_FILES);
if(i>MAX_FILES)
{
printf("Too many files for array size\n");
printf("Maximum number of file entries supported=%d\n", MAX_FILES);
printf("Try using a more restrictive file format for the search\n");
printf("Press any key to return to menu\n");
if(mouse_flag != KEYBOARD_ONLY)
inpause();
else
getch();
f.error_flag=-1;
i=MAX_FILES-1; /* the number of buffers to free() */
}
else
{
k=MAX_FILES/20; /* 20 lines for display */
fnames[i]=malloc(5);
if(fnames[i]==NULL)
{
printf("Error allocating menu buffer memory. Program aborting.\n");
exit(-1);
}
strcpy(fnames[i], "Quit"); /* add an ABORT option to menu */
CLS;
printf("Number of matching files: %d\n",i);
/* 80/k=number of spaces per field width */
reset_menu(last_choice);
j=menu(2,0,80/k,k,1,i+1,0,fnames);
last_choice=j;
CLS;
if(j != i) /* if not QUIT */
{
strcpy(f.string, dir_name);
if((strlen(f.string))&&(!(f.string[strlen(f.string)-1]=='\\')))
strcat(f.string, "\\");
strcat(f.string, fnames[j]);
}
else
f.error_flag=1;
}
for(j=0;j<=i;j++)
free(fnames[j]);
return(f);
}
/* ++++++++++++++++ get_mouse_flag() +++++++++++++++++++++++++++ */
/* get_mouse_flag() returns the current status of the mouse flag. */
/* it is useful in making other i/o operations conform to the menu */
/* style, i.e., if the mouse is active for the menu, you may want */
/* other input options to support mouse input, etc. Any non-zero */
/* value means that the mouse is active. Any value >=0 means that */
/* the keyboard is active. */
int get_mouse_flag()
{
return mouse_flag;
}
/* +++++++++++++++++++ menu() +++++++++++++++++++++++++++++++++++++++++ */
/* */
/* top_mar = top margin spacing (0<=t_m<=24) */
/* left_mar = left margin spacing (0<=l_m<=79) */
/* tab = total spaces per column */
/* columns = number of columns in menu */
/* line_feed = number of spaces between lines in menu */