📄 help.c
字号:
/****************************************************************
* File : help.c
* Function : On-line help for QAMLink Development software.
* Author : P.J. Michalewicz
* History :
****************************************************************/
/* include files */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <dos.h>
#include <alloc.h>
#include "qam3118.h"
#define HELP_FILE "help.hlp"
#define TOPICS_PER_LINE 20
#define MAX_TITLE 132
#define MAX_TOPIC 8096
#define UP_ARROW 0x48
#define DOWN_ARROW 0x50
#define PAGE_UP 0x49
#define PAGE_DOWN 0x51
#define RETURN 0x0d
#define TOPIC_XSTART 4
#define TOPIC_YSTART 3
#define MAX_TOPICS 256
/******************************************************************
* draw_box - draws a box on screen while in test mode.
******************************************************************/
void draw_box(char *title,int xpos,int ypos,int xsiz, int ysiz,int color)
{
int i,x;
/* draw the box */
textbackground(BLUE);
textcolor(color);
gotoxy(xpos,ypos);
cprintf("%c",201);
for (i=2; i<xsiz; i++) cprintf("%c",205);
cprintf("%c",187);
gotoxy(xpos,ypos+ysiz-1);
cprintf("%c",200);
for (i=2; i<xsiz; i++) cprintf("%c",205);
cprintf("%c",188);
for (i=1; i<ysiz-1; i++) {
gotoxy(xpos,ypos+i);
cprintf("%c",186);
gotoxy(xpos+xsiz-1,ypos+i);
cprintf("%c",186);
}
/* draw the title */
x = strlen(title);
if (x < xsiz) {
x = xpos + (xsiz/2) - (x/2);
gotoxy(x,ypos);
cprintf(title);
}
}
/******************************************************************
* help_code - this routine provides on_line help to the user. Help
* prints a list of available topics to the screen. The user selects
* topics using the arrow keys. Once a topic has been selected, the
* user hits a return.
******************************************************************/
int help_code(void)
{
int i,c,line,ntopics,cur_topic,handle;
long *topic_ptr,done;
int title_length;
int topic_length;
int start,stop,tline,more,less,redraw,delta;
char *title;
char *topic;
char *cp;
/* allocate memory */
title = (char *) malloc(MAX_TITLE * sizeof(char));
topic = (char *) malloc(MAX_TOPIC * sizeof(char));
/* open the help file and read in the topics pointers */
if ((handle = open(HELP_FILE, O_RDONLY | O_BINARY)) < 0) return QAM_ERROR;
read(handle,(char *) &ntopics, sizeof(int));
if (ntopics > MAX_TOPICS) return QAM_ERROR;
topic_ptr = (long *) malloc(ntopics * sizeof(long));
read(handle,(char *) topic_ptr, ntopics * sizeof(long));
/* setup current topic */
cur_topic = start = 0;
if (ntopics > TOPICS_PER_LINE) stop = TOPICS_PER_LINE-1;
else stop = ntopics-1;
redraw = 1;
delta = 0;
while (1) {
/* determine topics to be displayed */
if (delta == 1 || delta == -1) {
if (cur_topic < start) {
stop--;
start--;
}
else {
if (cur_topic > stop ) {
stop++;
start++;
}
}
} else {
start += delta;
stop += delta;
if (start < 0) start = 0;
if (stop < 0) {
stop = TOPICS_PER_LINE - 1;
if (stop >= ntopics) stop = ntopics-1;
}
if (start >= ntopics) {
start = ntopics - TOPICS_PER_LINE;
if (start < 0) start = 0;
}
if (stop >= ntopics) stop = ntopics-1;
}
/* make sure screen is filled up */
i = TOPICS_PER_LINE - (1 + stop - start);
if (i > 0) {
if (start > 0) start -= i;
if (stop < ntopics-1) stop += i;
}
/* display the topics */
if (redraw) {
clrscr();
draw_box(" QAMLink Help Menu ",1,1,79,24,WHITE);
for (i=start; i <= stop; i++) {
lseek(handle,topic_ptr[i],SEEK_SET);
read(handle,(char *) &title_length, sizeof(int));
read(handle,(char *) &topic_length, sizeof(int));
if (topic_length > MAX_TOPIC) topic_length = MAX_TOPIC-4;
read(handle,(char *) title, title_length);
if (i == cur_topic) {
textcolor(BLUE);
textbackground(WHITE);
} else {
textcolor(WHITE);
textbackground(BLUE);
}
gotoxy(TOPIC_XSTART,TOPIC_YSTART + i - start);
for (cp=title,c=0; *cp != '\0'; cp++,c++) {
if (*cp == '\t') while (((++c) % 8) != 0) putch(' ');
else putch(*cp);
}
}
textcolor(WHITE);
textbackground(BLUE);
gotoxy(12,24);
printf("Hit <Up> <Down> to select topic. Hit <esc> to exit help");
}
/* display more prompts */
if (stop < (ntopics-1)) { gotoxy(35,23); cprintf("-- more --"); }
if (start > 0) { gotoxy(35,2); cprintf("-- more --"); }
/* wait for a key to be pressed */
c = getch();
if (c == 0) c = getch();
done=0;
while (!done) {
switch (c) {
case 0x1b:
done=1;
break;
case UP_ARROW:
if (cur_topic > 0) {
cur_topic--;
redraw = 1;
delta = -1;
}
done = 1;
break;
case DOWN_ARROW:
if (cur_topic < ntopics-1) {
cur_topic++;
redraw = 1;
delta = 1;
}
done=1;
break;
case PAGE_UP:
cur_topic -= TOPICS_PER_LINE;
if (cur_topic < 0) cur_topic = 0;
redraw = 1;
delta = -TOPICS_PER_LINE;
done = 1;
break;
case PAGE_DOWN:
cur_topic += TOPICS_PER_LINE;
if (cur_topic >= ntopics) cur_topic = ntopics-1;
redraw = 1;
delta = TOPICS_PER_LINE;
done = 1;
break;
case RETURN: /* display selected topic */
redraw = 1;
/* read in the topic */
lseek(handle,topic_ptr[cur_topic],SEEK_SET);
read(handle,(char *) &title_length, sizeof(int));
read(handle,(char *) &topic_length, sizeof(int));
if (title_length > MAX_TITLE || topic_length > MAX_TOPIC) goto help_exit;
read(handle,(char *) title, title_length);
read(handle,(char *) topic, topic_length);
tline = 0; /* starting line */
while (1) {
clrscr();
draw_box(" QAMLink Help Menu ",1,1,79,24,WHITE);
/* locate the requested tline */
for (i=0,cp=topic; *cp != '\0' && i < tline; cp++) {
if (*cp == 0x0a) i++;
}
if (*cp == 0x09) cp++;
/* display the topic */
gotoxy(TOPIC_XSTART,TOPIC_YSTART);
for (i=c=0; i<TOPICS_PER_LINE && *cp != '\0'; cp++) {
if (*cp == 0x0a) {
gotoxy(TOPIC_XSTART,TOPIC_YSTART + i++);
c = 0;
/* nuke extra space after newlines */
if (*(cp+1) == ' ') cp++;
} else
if (*cp == 0x09) {
putch(' ');
c++;
while ((c++ % 8) != 0) putch(' ');
} else {
putch(*cp);
c++;
}
}
/* display more prompts */
if (cp < (topic + topic_length - 1)) {
gotoxy(35,23); cprintf("-- more --");
more = 1;
} else more = 0;
if (tline > 0) {
gotoxy(35,2); cprintf("-- more --");
less = 1;
} else less = 0;
/* wait for input */
if (more || less) {
gotoxy(16,24);
printf("<Up><Down><PgUp><PgDn> to move, <esc> to exit");
} else {
gotoxy(32,24);
printf("<esc> to exit");
}
while (1) {
c = getch();
if (c == 0) c = getch();
if (c == 0x1b) goto bail_topic;
if (c == PAGE_UP) {
tline -= (TOPICS_PER_LINE - 1);
if (tline < 0) tline = 0;
break;
}
if (more && c == PAGE_DOWN) {
tline += (TOPICS_PER_LINE - 1);
break;
}
if (more && c == DOWN_ARROW) {
tline++;
break;
}
if (less && c == UP_ARROW) {
tline--;
break;
}
}
}
bail_topic:
done=1;
c = ' ';
break;
} /* end switch */
if (!done) {
c = getch();
if (c == 0) c = getch();
}
}
if (c == 0x1b) break;
}
help_exit:
close(handle);
free(title);
free(topic);
free(topic_ptr);
return (QAM_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -