/
helpsys.cpp
123 lines (117 loc) · 2.96 KB
/
helpsys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* $Id$
* MegaZeux
*
* Copyright (C) 1996 Greg Janson
* Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// internal help system
#include "mod.h"
#include "cursor.h"
#include <string.h>
#include "scrdisp.h"
#include <stdio.h>
#include "meminter.h"
#include "beep.h"
#include "helpsys.h"
#include "data.h"
int context=72;//72="No" context link
unsigned char far *help=NULL;
int contexts[20];
int curr_context=0;
void set_context(int con) {
contexts[curr_context++]=context;
context=con;
}
void pop_context(void) {
context=contexts[--curr_context];
}
void help_system(void) {
FILE *fp;
unsigned int t1,t2;
unsigned char old_cmode=cursor_mode;
long where;
long offs;
long size;
char file[13];
char file2[13];
char label[20];
//Reserve memory (24k)
help=(char far *)farmalloc(24576);
if(help==NULL) {
//Try to free up mem
free_sam_cache(1);
help=(char far *)farmalloc(24576);
if(help==NULL) {
beep();
return;
}
}
//Search context links
fp=fopen(help_file,"rb");
if(fp==NULL) {
beep();
farfree(help);
return;
}
fread(&t1,1,2,fp);
fseek(fp,t1*21+4+context*12,SEEK_SET);
//At proper context info
fread(&where,1,4,fp);//Where file to load is
fread(&size,1,4,fp);//Size of file to load
fread(&offs,1,4,fp);//Offset within file of link
//Jump to file
fseek(fp,where,SEEK_SET);
//Read it in
fread(help,1,size,fp);
//Display it
cursor_off();
labelled:
help_display(help,offs,file,label);
//File?
if(file[0]) {
//Yep. Search for file.
fseek(fp,2,SEEK_SET);
for(t2=0;t2<t1;t2++) {
fread(file2,1,13,fp);
if(!_fstricmp(file,file2)) break;
fseek(fp,8,SEEK_CUR);
}
if(t2<t1) {
//Found file.
fread(&where,1,4,fp);
fread(&size,1,4,fp);
fseek(fp,where,SEEK_SET);
fread(help,1,size,fp);
//Search for label
for(t2=0;t2<size;t2++) {
if(help[t2]!=255) continue;
if(help[t2+1]!=':') continue;
if(!_fstricmp(&help[t2+3],label)) break;//Found label!
}
if(t2<size) {
//Found label. t2 is offset.
offs=t2;
goto labelled;
}
}
}
//All done!
fclose(fp);
farfree(help);
if(old_cmode==CURSOR_UNDERLINE) cursor_underline();
else if(old_cmode==CURSOR_BLOCK) cursor_solid();
}