home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
pcpursut
/
pisrc.ark
/
MENU.C
< prev
next >
Wrap
Text File
|
1988-07-14
|
8KB
|
322 lines
/**********************************************************
* menu.c - contains the menus for selecting city
* and bbs
********************************************************/
#include "stdio.h"
#include "cpcp.h"
#define NUMLINES 13 /* number of lines in menu for city */
/* limited by letters a-z as choices */
#define ESC 27
#define TAB '\t'
#define WIDTH 30 /* width for each city name */
#define BACKSPACE 0x08
#define DEL 0x7f
extern struct cityrec *cities;
extern char *pad();
/* get pointer to city that has been chosen from list
* return null if ESC (exit) was selected
* supports 2 page list for up to 52 cities
*/
struct cityrec *citymenu(citylist)
struct cityrec *citylist; /* city list to use for menu */
{
static struct cityrec *leftptr;
static struct cityrec *rtptr;
static struct cityrec *tempptr;
static int page_num = 0;
static int line_num;
static int i;
static char last_let; /* last valid letter in the list */
static char c;
static char *(mesg[10]);
line_num = 0;
last_let = 'a'; /* start at beginning of the list */
/* get pointers to left and right side of list */
rtptr = leftptr = citylist;
for (i = 0; i < NUMLINES; i++)
if (rtptr)
rtptr = rtptr->nextcity;
mesg[0] = "CITY SELECTION";
mesg[1] = NULL;
makehdr(mesg);
while (line_num < NUMLINES) {
if (leftptr) {
printf(" %c-%s ", line_num + 'A', pad(leftptr->cityname, WIDTH));
last_let++;
leftptr = leftptr->nextcity;;
}
if (rtptr) {
printf("%c-%s\n", line_num + 'A' + NUMLINES, pad(rtptr->cityname, WIDTH));
last_let++;
rtptr = rtptr->nextcity;;
}
else
printf("\n");
line_num++;
}
printf("\n");
if (page_num)
printf(" Press the <TAB> key to see the first page of cities.\n");
else if (rtptr)
printf(" Press the <TAB> key to see second page of cities.\n");
printf(" Press the <ESC> key to disconnect and abort this program.\n");
/* check for more cites that can be displayed on two pages */
if (rtptr && page_num) {
printf(" !!! To many cities in database !!!!\n");
}
printf("\n Enter the letter beside the");
printf("\n city of your choice: -> ");
do {
c = tolower(getch());
} while (!((c >= 'a' && c < last_let) || ((c == TAB) && !page_num && rtptr)
|| ((c == TAB) && page_num) || (c == ESC)));
if ( c >= 'a' && c < last_let)
putchar(toupper(c));
/* check if page switch */
if (c == TAB) {
if (page_num) {
return (-1);
}
else {
page_num++;
tempptr = citymenu(rtptr);
page_num--;
/* check if we want to put page 1 up again */
if (tempptr == -1)
return(citymenu(citylist));
else
return (tempptr);
}
}
else if (c == ESC)
return (NULL);
else {
tempptr = citylist;
for (i = 0; i < c - 'a'; i++)
tempptr = tempptr->nextcity;
return (tempptr);
}
}
/* display menu for bbs selection ,
* return NULL if Escape pressed and support 2 pages
* */
struct bbs_rec *bbsmenu(bbslist, titlestring, area_code)
struct bbs_rec *bbslist;
char *titlestring;
char *area_code;
{
static struct bbs_rec *leftptr;
static struct bbs_rec *rtptr;
static struct bbs_rec *tempptr;
static int page_num = 0;
static int line_num;
static int i;
static char last_let; /* last valid letter in the list */
static char c;
static char *sptr;
static char *(mesg[10]);
static char *string;
char str[80];
string = str;
line_num = 0;
last_let = 'a'; /* start at beginning of the list */
/* get pointers to left and right side of list */
rtptr = leftptr = bbslist;
for (i = 0; i < NUMLINES; i++)
if (rtptr)
rtptr = rtptr->next_bbs;
sprintf(string, "BBS list for %s.", titlestring);
mesg[0] = string;
mesg[1] = NULL;
makehdr(mesg);
printf("\n");
while (line_num < NUMLINES) {
if (leftptr) {
printf(" %c-%s ", line_num + 'A', pad(leftptr->bbs_name, WIDTH));
last_let++;
leftptr = leftptr->next_bbs;;
}
if (rtptr) {
printf("%c-%s\n", line_num + 'A' + NUMLINES, pad(rtptr->bbs_name, WIDTH));
last_let++;
rtptr = rtptr->next_bbs;;
}
else
printf("\n");
line_num++;
}
printf("\n");
if (page_num)
printf(" Press the <TAB> key to see the first page of bbs's.\n");
else if (rtptr)
printf(" Press the <TAB> key to see second page of bbs's.\n");
printf(" Press the <ESC> key to return to Cities Menu.\n");
printf(" Press the </> key for manual dial entry.\n");
/* check for more cites that can be displayed on two pages */
if (rtptr && page_num) {
printf(" !!! To many phone numbers in database for this city!!!!\n");
}
/* prompt for selection */
printf("\n Enter the letter beside the \n");
printf(" bbs of your choice -> ");
do {
c = tolower(getch());
} while (!((c >= 'a' && c < last_let) || ((c == TAB) && !page_num && rtptr)
|| ((c == TAB) && page_num) || (c == ESC) || (c == '/')));
if ( c >= 'a' && c < last_let)
putchar(toupper(c));
/* check if page switch */
if (c == TAB) {
if (page_num) {
return (-1);
}
else {
page_num++;
tempptr = bbsmenu(rtptr, titlestring, area_code);
page_num--;
/* check if we want to put page 1 up again */
if (tempptr == -1)
return(bbsmenu(bbslist, titlestring, area_code));
else
return (tempptr);
}
}
else if (c == ESC)
return (NULL);
else if (c == '/') {
if (tempptr = mdial())
return(tempptr);
else
return(bbsmenu(bbslist, titlestring, area_code)); /* <- recursive so watch stack */
}
else {
tempptr = bbslist;
for (i = 0; i < c - 'a'; i++)
tempptr = tempptr->next_bbs;
return (tempptr);
}
}
/* prompt user for manual dial number */
struct bbs_rec *mdial()
{
static char areacode[4] = "???";
static int count;
static int c;
static char *(mesg[10]);
static struct bbs_rec bbs;
static char *prompt = "Enter number to be dialed -> ";
static char temp[15];
count = 0;
mesg[0] = "Manual Dial Mode";
mesg[1] = " ";
mesg[2] = "Press Escape to abort or Return to enter Number";
mesg[3] = NULL;
makehdr(mesg);
printf("\n");
printf(prompt);
printf("%3s-", areacode);
printf("___-____\015");
printf(prompt);
printf("%3s-", areacode);
strncpy(bbs.bbs_number, areacode, 3);
count = 3;
for (;;) {
c = getch();
if (c == ESC)
return (NULL);
else if (c == '\015' && count == 10) {
bbs.bbs_name = "Manual Dial";
bbs.next_bbs = NULL;
if (!strncmp(areacode, &(bbs.bbs_number[0]), 3)) {
strncpy(&(bbs.bbs_number[0]), &(bbs.bbs_number[3]), 7);
bbs.bbs_number[7] = NULL;
}
else bbs.bbs_number[10] = NULL;
/* check for 1 at beginning of area code */
printf("\n\n Add 1 to begining of area code? ");
c = getch();
if (toupper(c) == 'Y') {
strcpy(temp, bbs.bbs_number);
strcpy(bbs.bbs_number, "1");
strcat(bbs.bbs_number, temp);
}
printf("\n\n 1 - 300\n");
printf(" 2 - 1200\n");
printf(" 3 - 2400\n");
printf("Enter baud rate (1-3) -> ");
do {
c = getch();
} while ((c < '1') && (c > '3'));
putchar(c);
bbs.bbs_baud = c - '0';
return(&bbs);
} else if (isdigit(c) && count < 10) {
bbs.bbs_number[count] = c;
putchar(c);
count++;
if ((count == 3) || (count == 6))
putchar('-');
} else if (c == BACKSPACE || c == DEL) {
if (count == 0)
;
else if ((count == 3) || (count == 6)) {
putchar(BACKSPACE);
putchar(BACKSPACE);
putchar('_');
putchar(BACKSPACE);
count--;
} else {
putchar(BACKSPACE);
putchar('_');
putchar(BACKSPACE);
count--;
}
}
}
}