My Project
Functions
fehelp.h File Reference

Go to the source code of this file.

Functions

void feHelp (char *str=NULL)
 
const char * feHelpBrowser (char *browser=NULL, int warn=-1)
 
void feStringAppendBrowsers (int warn=-1)
 

Function Documentation

◆ feHelp()

void feHelp ( char *  str = NULL)

Definition at line 89 of file fehelp.cc.

90{
91 str = strclean(str);
92 if (str == NULL) {heBrowserHelp(NULL); return;}
93
94 if (strlen(str) > MAX_HE_ENTRY_LENGTH - 2) // need room for extra **
95 str[MAX_HE_ENTRY_LENGTH - 3] = '\0';
96
97 BOOLEAN key_is_regexp = (strchr(str, '*') != NULL);
98
99
100 heEntry_s hentry;
101 memset(&hentry,0,sizeof(hentry));
102 char* idxfile = feResource('x' /*"IdxFile"*/);
103
104 // Try exact match of help string with key in index
105 if (!key_is_regexp && (idxfile != NULL) && heKey2Entry(idxfile, str, &hentry))
106 {
107 heBrowserHelp(&hentry);
108 return;
109 }
110
111 // Try to match approximately with key in index file
112 if (idxfile != NULL)
113 {
116
117 StringSetS("");
118 int found = heReKey2Entry(idxfile, str, &hentry);
119
120
121 if (found == 0)
122 {
123 // try proc help and library help
124 if (! key_is_regexp && heOnlineHelp(str)) return;
125
126 // Try to match with str*
127 char mkey[MAX_HE_ENTRY_LENGTH];
128 strcpy(mkey, str);
129 strcat(mkey, "*");
130 found = heReKey2Entry(idxfile, mkey, &hentry);
131 // Try to match with *str*
132 if (found == 0)
133 {
134 mkey[0] = '*';
135 strcpy(mkey + 1, str);
136 strcat(mkey, "*");
137 found = heReKey2Entry(idxfile, mkey, &hentry);
138 }
139
140 // Print warning and return if nothing found
141 if (found == 0)
142 {
143 Warn("No help for topic '%s' (not even for '*%s*')", str, str);
144 WarnS("Try '?;' for general help");
145 WarnS("or '?Index;' for all available help topics.");
146 return;
147 }
148 }
149
150 // do help if unique match was found
151 if (found == 1)
152 {
153 heBrowserHelp(&hentry);
154 return;
155 }
156 // Print warning about multiple matches and return
157 if (key_is_regexp)
158 Warn("No unique help for '%s'", str);
159 else
160 Warn("No help for topic '%s'", str);
161 WarnS("Try one of");
162 char *matches=StringEndS();
163 PrintS(matches);
164 omFree(matches);
165 PrintLn();
166 return;
167 }
168
169 // no idx file, let Browsers deal with it, if they can
170 strcpy(hentry.key, str);
171 *hentry.node = '\0';
172 *hentry.url = '\0';
173 hentry.chksum = 0;
174 heBrowserHelp(&hentry);
175}
int BOOLEAN
Definition: auxiliary.h:87
#define Warn
Definition: emacs.cc:77
#define WarnS
Definition: emacs.cc:78
bool found
Definition: facFactorize.cc:55
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:236
char url[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:34
static char * strclean(char *str)
Definition: fehelp.cc:363
static void heBrowserHelp(heEntry hentry)
Definition: fehelp.cc:768
static int heReKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:567
char node[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:33
STATIC_VAR heBrowser heCurrentHelpBrowser
Definition: fehelp.cc:71
#define MAX_HE_ENTRY_LENGTH
Definition: fehelp.cc:29
char key[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:32
static BOOLEAN heKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:387
long chksum
Definition: fehelp.cc:35
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:248
static BOOLEAN heOnlineHelp(char *s)
Definition: fehelp.cc:620
#define assume(x)
Definition: mod2.h:387
char * str(leftv arg)
Definition: shared.cc:704
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:12
void StringSetS(const char *st)
Definition: reporter.cc:128
void PrintS(const char *s)
Definition: reporter.cc:284
char * StringEndS()
Definition: reporter.cc:151
void PrintLn()
Definition: reporter.cc:310

◆ feHelpBrowser()

const char * feHelpBrowser ( char *  browser = NULL,
int  warn = -1 
)

Definition at line 248 of file fehelp.cc.

249{
250 int i = 0;
251
252 // if no argument, choose first available help browser
254 if (which == NULL || *which == '\0')
255 {
256 // return, if already set
259
260 // First, try emacs, if emacs-option is set
261 if (feOptValue(FE_OPT_EMACS) != NULL)
262 {
263 while (heHelpBrowsers[i].browser != NULL)
264 {
265 if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
266 (heHelpBrowsers[i].init_proc(0,i)))
267 {
270 goto Finish;
271 }
272 i++;
273 }
274 i=0;
275 }
276 while (heHelpBrowsers[i].browser != NULL)
277 {
278 if (heHelpBrowsers[i].init_proc(0,i))
279 {
282 goto Finish;
283 }
284 i++;
285 }
286 // should never get here
287 dReportBug("should never get here");
288 }
289
290 // with argument, find matching help browser
291 while (heHelpBrowsers[i].browser != NULL &&
292 strcmp(heHelpBrowsers[i].browser, which) != 0)
293 {i++;}
294
295 if (heHelpBrowsers[i].browser == NULL)
296 {
297 if (warn) Warn("No help browser '%s' available.", which);
298 }
299 else
300 {
301 // see whether we can init it
302 if (heHelpBrowsers[i].init_proc(warn,i))
303 {
306 goto Finish;
307 }
308 }
309
310 // something went wrong
312 {
315 if (warn)
316 Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
318 }
319 else
320 {
321 // or, leave as is
322 if (warn)
323 Warn("Help browser stays at '%s'.", heCurrentHelpBrowser->browser);
325 }
326
327 Finish:
328 // update value of Browser Option
329 if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
330 strcmp((char*) feOptSpec[FE_OPT_BROWSER].value,
332 {
333 omfree(feOptSpec[FE_OPT_BROWSER].value);
334 feOptSpec[FE_OPT_BROWSER].value
336 }
338}
int i
Definition: cfEzgcd.cc:132
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
EXTERN_VAR struct fe_option feOptSpec[]
Definition: feOpt.h:17
void * value
Definition: fegetopt.h:93
static void feBrowserFile()
Definition: fehelp.cc:176
STATIC_VAR heBrowser_s * heHelpBrowsers
Definition: fehelp.cc:82
const char * browser
Definition: fehelp.cc:44
STATIC_VAR int heCurrentHelpBrowserIndex
Definition: fehelp.cc:72
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omfree(addr)
Definition: omAllocDecl.h:237
#define dReportBug(s)
Definition: reporter.h:113

◆ feStringAppendBrowsers()

void feStringAppendBrowsers ( int  warn = -1)

Definition at line 340 of file fehelp.cc.

341{
342 int i;
343 StringAppendS("Available HelpBrowsers: ");
344
345 i = 0;
347 while (heHelpBrowsers[i].browser != NULL)
348 {
349 if (heHelpBrowsers[i].init_proc(warn,i))
350 StringAppend("%s, ", heHelpBrowsers[i].browser);
351 i++;
352 }
353 StringAppend("\nCurrent HelpBrowser: %s ", feHelpBrowser());
354}
#define StringAppend
Definition: emacs.cc:79
void StringAppendS(const char *st)
Definition: reporter.cc:107