-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelp.c
195 lines (172 loc) · 5.73 KB
/
help.c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* XFrisk - The classic board game for X
* Copyright (C) 1993-1999 Elan Feingold ([email protected])
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: help.c,v 1.4 1999/11/13 21:58:31 morphy Exp $
*/
#include <X11/X.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/List.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include "riskgame.h"
#include "network.h"
#include "types.h"
#include "help.h"
#include "client.h"
#include "gui-vars.h"
#include "callbacks.h"
#include "utils.h"
#include "debug.h"
static CString *pstrIndexCStrings;
static CString *pstrHelpCStrings;
static Int32 iNumHelpTopics=0;
/* The first is the default number of topics, and the latter is the
* number of new topics to allocate if we run out room.
*/
#define HELP_TOPICS 32
#define HELP_MORETOPICS 8
/************************************************************************
* FUNCTION: HELP_Init
* HISTORY:
* 04.01.94 ESF Created
* 04.02.94 ESF Added allocation of more memory if needed.
* PURPOSE:
* NOTES:
************************************************************************/
void HELP_Init(CString strHelpFile)
{
FILE *hHelpFile;
struct stat statBuf;
char *pHelpText;
Int32 i, j, iTopicsMemory = HELP_TOPICS;
char buf[256];
/* Allocate the default amount of room for the help topics */
pstrIndexCStrings = (CString *)MEM_Alloc(sizeof(CString)*iTopicsMemory);
pstrHelpCStrings = (CString *)MEM_Alloc(sizeof(CString)*iTopicsMemory);
/* Open the file, and find out its size to allocate memory for it */
if ((hHelpFile=UTIL_OpenFile(HELPFILE, "r"))==NULL)
{
#ifdef ENGLISH
snprintf(buf, sizeof(buf), "HELP: cannot open %s!", HELPFILE);
UTIL_PopupDialog("Fatal Error", buf, 1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
snprintf(buf, sizeof(buf), "HELP: impossible d'ouvrir %s!", HELPFILE);
UTIL_PopupDialog("Erreur fatale", buf, 1, "Ok", NULL, NULL);
#endif
UTIL_ExitProgram(-1);
}
if (fstat(fileno(hHelpFile), &statBuf)!=0)
{
#ifdef ENGLISH
UTIL_PopupDialog("Fatal Error", "HELP: Couldn't get size of file",
#endif
#ifdef FRENCH
UTIL_PopupDialog("Erreur fatale", "HELP: Impossible d'obtenir la "
"taille du fichier",
#endif
1, "Ok", NULL, NULL);
UTIL_ExitProgram(-1);
}
/* Read in the file after allocating room for it */
pHelpText = strHelpFile = (CString)MEM_Alloc(statBuf.st_size);
fread(strHelpFile, statBuf.st_size, 1, hHelpFile);
/* Search through the file for topics, filling out the tables of topic
* pointers as we go, and allocating more memory as needed. When we
* find an end of topic, stick a '\0' in, and erase '\n' since the
* text widget will do the word wrapping for us. This can be sped up!
*/
for (i=0; i!=statBuf.st_size; i++)
{
if (pHelpText[i] == '\n' &&
(pHelpText[i+1] == '\n' || pHelpText[i+1] == '\t'))
i++;
/* Stick in a blank as long as the last character wasn't a space */
else if (pHelpText[i] == '\n' && i>0 && pHelpText[i-1] != ' ')
pHelpText[i] = ' ';
else if (pHelpText[i] == '%' && pHelpText[i+1] == '%')
{
/* We've found the end of a topic */
pHelpText[i] = '\0';
i+=2;
}
else if (pHelpText[i] == '%')
{
/* We've found the beginning of a topic */
pstrIndexCStrings[iNumHelpTopics] = &pHelpText[i+1];
/* Find the beginning of the topic */
for (j=i; pHelpText[j]!='\n'; j++)
; /* TwiddleThumbs() */
pHelpText[j] = '\0';
pstrHelpCStrings[iNumHelpTopics++] = &pHelpText[j+1];
/* Allocate more memory? */
if (iNumHelpTopics > iTopicsMemory)
{
iTopicsMemory += HELP_MORETOPICS;
pstrHelpCStrings = (CString *)realloc(pstrHelpCStrings,
sizeof(CString)*
iTopicsMemory);
pstrIndexCStrings = (CString *)realloc(pstrIndexCStrings,
sizeof(CString)*
iTopicsMemory);
}
}
}
/* Put the index strings in the list widget */
XtVaSetValues(wHelpTopicList,
XtNlist, pstrIndexCStrings,
XtNnumberStrings, iNumHelpTopics,
NULL);
}
/************************************************************************
* FUNCTION:
* HISTORY:
* 04.01.94 ESF Created
* PURPOSE:
* NOTES:
************************************************************************/
void HELP_IndexPopupHelp(Int32 iTopic)
{
if (iTopic<0 || iTopic>=iNumHelpTopics)
{
UTIL_PopupDialog("Warning", "HELP: Topic not available!",
1, "Ok", NULL, NULL);
return;
}
XtVaSetValues(wHelpLabel,
XtNlabel, pstrIndexCStrings[iTopic],
NULL);
XtVaSetValues(wHelpText,
XtNstring, pstrHelpCStrings[iTopic],
NULL);
}
/************************************************************************
* FUNCTION:
* HISTORY:
* 04.01.94 ESF Created
* PURPOSE:
* NOTES:
************************************************************************/
void HELP_CStringPopupHelp(CString strTopic)
{
UNUSED(strTopic);
D_Assert(FALSE, "Not implemented!");
}