home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
251_01
/
pulldown.c
< prev
next >
Wrap
Text File
|
1987-10-29
|
21KB
|
820 lines
/* COPYRIGHT (C) 1986 */
/* BY JAMES L PINSON */
/* ALL RIGHTS RESERVED */
/* Compiled with Lattice C V2.14 */
/* Computer: IBM PC JR */
/* Text editor: Sidekick */
/* Last revision 3/16/1987 */
#include "stdio.h"
#include "ctype.h"
#define void int
#define BLACK 0 /* THESE ARE FOR COLOR CARDS */
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define WHITE 7
#define L_BLUE 9 /* LIGHT-BLUE FOREGROUND ONLY */
#define L_GREEN 10 /* LIGHT-GREEN FOREGROUND ONLY */
#define YELLOW 14
#define IWHITE 15 /* INTENSE-WHITE FOREGROUND ONLY*/
#define UNDERLINE 1 /* THESE ARE FOR MONOCHROME CARDS */
#define NORMAL 7
#define HI_INTEN 15
#define REVERSE 112
#define TRUE 1
#define FALSE 0
unsigned int page; /* extern decl. for functions*/
unsigned int attribute;
unsigned int mon_type;
char wrt_meth= 'f';
#define NU_MAIN 5 /* number of main menu options */
#define NU_SUB 5 /* number of sub menu options */
struct menu_str{ /* change this if you need more options */
char *head;
char *body[NU_SUB];
void (*fun1)();
void (*fun2)();
void (*fun3)();
void (*fun4)();
void (*fun5)();
} ;
main(argc,argv)
int argc;
char **argv;
{
extern unsigned int page;
extern unsigned int attribute;
extern unsigned int mon_type;
char ch,ext;
int i,hi_attr,nor_attr;
int demo();
int help();
static struct menu_str m_menu [NU_MAIN]={
" File ", /* The first menu option */
" Dir ", /* Menu sub options */
" Load ",
" Save ",
" dElete ",
" Path ",
demo, /* The functions each sub-option call */
demo,
demo, /* these all call the same fake function */
demo,
demo,
" fiNd ", /* The second menu option */
" All-words ",
" First-word ",
"\0",
"\0", /* space filler for unused option names */
"\0",
demo,
demo,
0, /* unused function pointer */
0,
0,
" Configure ", /* The third option */
" Modem ",
" Screen ",
" Printer ",
"\0",
"\0",
demo,
demo,
demo,
0,
0,
" Output ", /* The fourth menu option */
" Screen ",
" Printer ",
" Disk ",
" Modem ",
"\0",
demo,
demo,
demo,
demo,
0,
" Help ", /* The fifth option */
" Instant help (really works) ",
"\0",
"\0",
"\0",
"\0",
help,
0,
0,
0,
0,
};
/* was a slow write requested? */
if (tolower (*argv[1])== 's') wrt_meth = 's';
page=0;
mon_type =(what_mon());
if (mon_type==1){ /* FIND OUT IF YOU HAVE A COLOR CARD */
hi_attr= set_color(BLACK,CYAN); /* AND SET ATTRIBUTES ACCORDINGLY */
nor_attr= set_color(WHITE,BLACK);
}
else{
hi_attr = REVERSE;
nor_attr = NORMAL;
}
attribute = nor_attr;
cursor(0); /* hide cursor */
win_save('s');
cls();
if (mon_type==1) make_help();
make_inst(); /* SHOW INSTRUCTIONS */
menu(m_menu,NU_MAIN,NU_SUB,hi_attr,nor_attr);
win_save('r'); /* restore text display*/
cursor(1); /* restore cursor */
}
int menu (m_menu,nu_main,nu_sub,hi_attr,nor_attr)
struct menu_str m_menu[];
int nu_main,nu_sub,hi_attr, nor_attr;
{
extern unsigned int page;
extern unsigned int attribute;
extern unsigned int mon_type;
int i,j,k,cur_x,cur_y,cur_opt,found,expert=1;
char ch, ext, ltr;
ch= ' ';ext=' '; cur_opt=0; found =0;
if (mon_type==1) attribute = set_color(YELLOW,BLACK);
else attribute = nor_attr;
make_window(1,1,78,1,1);
for(;;){ /* endless loop */
for(i=0;i<nu_main;i++){
j=0;
while(ltr = m_menu[i].head[j++]){
if ( ch==ltr && ch != ' '){
found= TRUE;
cur_opt = i;
}
}
}
if (ch==13){
found = TRUE;
expert = FALSE;
}
ch=' ';
cur_x=2;cur_y=2;
for(i=0;i< nu_main;i++){
if(i == cur_opt) attribute= hi_attr;
else attribute= nor_attr;
print(cur_x,cur_y,m_menu[i].head);
cur_x= cur_x+strlen(m_menu[i].head)+3;
}
if (!expert) found = TRUE;
if (found){
ext =(pull_down(m_menu,nu_sub,cur_opt)); /* pull-down options */
if (ext == 27) expert = TRUE;
if (ext == 'r' || ext == 'l') expert = FALSE;
if (ext=='r') cur_opt = cur_opt+1;
if (ext =='l') cur_opt = cur_opt -1;
ch= ' ';
ext= ' ';
}
if(!found){
ch=' ';
get_key(&ch,&ext);
ch=toupper(ch);
}
if (ch==27) return;
if (ext =='r' || ext == 'l') expert = 0;
if (ext == 'r') cur_opt = cur_opt +1;
if (ext == 'l') cur_opt = cur_opt -1;
if (cur_opt >= nu_main) cur_opt =0;
if (cur_opt < 0) cur_opt = nu_main-1;
ext=' ';
found=0;
} /* end for(;;) */
} /* end function */
int pull_down(m_menu,nu_sub,position)
struct menu_str m_menu[];
int position;
{
extern unsigned int page;
extern unsigned int attribute;
char ch=' ',ltr;
int ext=' ',hi_attr,nor_attr;
int i,j,tx,ty,start,width,nu_opt,cur_opt=0, found= FALSE;
nu_opt = nu_sub;
/* nu_sub = number of possible pull-down options */
/* find out how many are in use */
for(i=0;i<nu_opt;i++){
if (m_menu[position].body[i][0] == '\0'){
nu_opt = i;
break;
}
}
if (mon_type==1){
hi_attr= set_color(BLACK,CYAN);
nor_attr= set_color(WHITE,BLACK);
}
else{
hi_attr = REVERSE;
nor_attr = NORMAL;
}
attribute = nor_attr;
start=2; /* figure where to draw pull-down box */
/* 2 is column to start 1st box */
/* add up length of menu heads */
for(i=0; i< position; i++) start= start+strlen(m_menu[i].head)+3;
width=0; /* figure max length of window */
for (i=0;i< nu_opt;i++){
if (strlen(m_menu[position].body[i]) > width){
width= strlen(m_menu[position].body[i]);
}
}
/* move box to left if */
/* it will spill off right side */
if(start+width+1>80) start = 80-width-2;
win_save ('s');
if (mon_type ==1) attribute = set_color (YELLOW,BLACK);
make_window(start++,3,width,nu_opt,0); /*make a window */
attribute = nor_attr;
tx=start;ty=4; /* reposition for writing */
for(;;){
for(i=0;i< nu_opt;i++){
if(i == cur_opt) attribute= hi_attr;
else attribute= nor_attr;
print(tx,ty++,m_menu[position].body[i]);
};
attribute = nor_attr;
if(found ) {
win_save('r'); /* remove box */
/* if you want more than 5 menu options */
/* change this next switch statement */
switch (cur_opt){ /* call function */
case 0: (*m_menu[position].fun1)() ;break;
case 1: (*m_menu[position].fun2)() ;break;