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 103 of file fehelp.cc.

104 {
105  str = strclean(str);
106  if (str == NULL) {heBrowserHelp(NULL); return;}
107 
108  if (strlen(str) > MAX_HE_ENTRY_LENGTH - 2) // need room for extra **
109  str[MAX_HE_ENTRY_LENGTH - 3] = '\0';
110 
111  BOOLEAN key_is_regexp = (strchr(str, '*') != NULL);
112 
113 
114  heEntry_s hentry;
115  memset(&hentry,0,sizeof(hentry));
116  char* idxfile = feResource('x' /*"IdxFile"*/);
117 
118  // Try exact match of help string with key in index
119  if (!key_is_regexp && (idxfile != NULL) && heKey2Entry(idxfile, str, &hentry))
120  {
121  heBrowserHelp(&hentry);
122  return;
123  }
124 
125  // Try to match approximately with key in index file
126  if (idxfile != NULL)
127  {
130 
131  StringSetS("");
132  int found = heReKey2Entry(idxfile, str, &hentry);
133 
134 
135  if (found == 0)
136  {
137  // try proc help and library help
138  if (! key_is_regexp && heOnlineHelp(str)) return;
139 
140  // Try to match with str*
141  char mkey[MAX_HE_ENTRY_LENGTH];
142  strcpy(mkey, str);
143  strcat(mkey, "*");
144  found = heReKey2Entry(idxfile, mkey, &hentry);
145  // Try to match with *str*
146  if (found == 0)
147  {
148  mkey[0] = '*';
149  strcpy(mkey + 1, str);
150  strcat(mkey, "*");
151  found = heReKey2Entry(idxfile, mkey, &hentry);
152  }
153 
154  // Print warning and return if nothing found
155  if (found == 0)
156  {
157  Warn("No help for topic '%s' (not even for '*%s*')", str, str);
158  WarnS("Try '?;' for general help");
159  WarnS("or '?Index;' for all available help topics.");
160  return;
161  }
162  }
163 
164  // do help if unique match was found
165  if (found == 1)
166  {
167  heBrowserHelp(&hentry);
168  return;
169  }
170  // Print warning about multiple matches and return
171  if (key_is_regexp)
172  Warn("No unique help for '%s'", str);
173  else
174  Warn("No help for topic '%s'", str);
175  Warn("Try one of");
176  char *matches=StringEndS();
177  PrintS(matches);
178  omFree(matches);
179  PrintLn();
180  return;
181  }
182 
183  // no idx file, let Browsers deal with it, if they can
184  strcpy(hentry.key, str);
185  *hentry.node = '\0';
186  *hentry.url = '\0';
187  hentry.chksum = 0;
188  heBrowserHelp(&hentry);
189 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:262
char url[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:48
long chksum
Definition: fehelp.cc:49
void PrintLn()
Definition: reporter.cc:310
static BOOLEAN heOnlineHelp(char *s)
Definition: fehelp.cc:634
#define MAX_HE_ENTRY_LENGTH
Definition: fehelp.cc:43
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
char key[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:46
static int heReKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:581
char * StringEndS()
Definition: reporter.cc:151
static void heBrowserHelp(heEntry hentry)
Definition: fehelp.cc:782
#define WarnS
Definition: emacs.cc:81
bool found
Definition: facFactorize.cc:56
char node[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:47
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:394
void StringSetS(const char *st)
Definition: reporter.cc:128
static BOOLEAN heKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:401
static heBrowser heCurrentHelpBrowser
Definition: fehelp.cc:85
void PrintS(const char *s)
Definition: reporter.cc:284
#define NULL
Definition: omList.c:10
static char * strclean(char *str)
Definition: fehelp.cc:377
int BOOLEAN
Definition: auxiliary.h:85
#define Warn
Definition: emacs.cc:80

◆ feHelpBrowser()

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

Definition at line 262 of file fehelp.cc.

263 {
264  int i = 0;
265 
266  // if no argument, choose first available help browser
268  if (which == NULL || *which == '\0')
269  {
270  // return, if already set
271  if (heCurrentHelpBrowser != NULL)
273 
274  // First, try emacs, if emacs-option is set
275  if (feOptValue(FE_OPT_EMACS) != NULL)
276  {
277  while (heHelpBrowsers[i].browser != NULL)
278  {
279  if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
280  (heHelpBrowsers[i].init_proc(0,i)))
281  {
284  goto Finish;
285  }
286  i++;
287  }
288  i=0;
289  }
290  while (heHelpBrowsers[i].browser != NULL)
291  {
292  if (heHelpBrowsers[i].init_proc(0,i))
293  {
296  goto Finish;
297  }
298  i++;
299  }
300  // should never get here
301  dReportBug("should never get here");
302  }
303 
304  // with argument, find matching help browser
305  while (heHelpBrowsers[i].browser != NULL &&
306  strcmp(heHelpBrowsers[i].browser, which) != 0)
307  {i++;}
308 
309  if (heHelpBrowsers[i].browser == NULL)
310  {
311  if (warn) Warn("No help browser '%s' available.", which);
312  }
313  else
314  {
315  // see whether we can init it
316  if (heHelpBrowsers[i].init_proc(warn,i))
317  {
320  goto Finish;
321  }
322  }
323 
324  // something went wrong
325  if (heCurrentHelpBrowser == NULL)
326  {
327  feHelpBrowser();
329  if (warn)
330  Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
332  }
333  else
334  {
335  // or, leave as is
336  if (warn)
337  Warn("Help browser stays at '%s'.", heCurrentHelpBrowser->browser);
339  }
340 
341  Finish:
342  // update value of Browser Option
343  if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
344  strcmp((char*) feOptSpec[FE_OPT_BROWSER].value,
346  {
347  omfree(feOptSpec[FE_OPT_BROWSER].value);
348  feOptSpec[FE_OPT_BROWSER].value
350  }
352 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:262
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
static void feBrowserFile()
Definition: fehelp.cc:190
void * value
Definition: fegetopt.h:93
const char * browser
Definition: fehelp.cc:58
static int heCurrentHelpBrowserIndex
Definition: fehelp.cc:86
#define assume(x)
Definition: mod2.h:394
#define omfree(addr)
Definition: omAllocDecl.h:237
struct fe_option feOptSpec[]
#define dReportBug(s)
Definition: reporter.h:112
int i
Definition: cfEzgcd.cc:123
static heBrowser heCurrentHelpBrowser
Definition: fehelp.cc:85
#define NULL
Definition: omList.c:10
static heBrowser_s * heHelpBrowsers
Definition: fehelp.cc:96
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ feStringAppendBrowsers()

void feStringAppendBrowsers ( int  warn = -1)

Definition at line 354 of file fehelp.cc.

355 {
356  int i;
357  StringAppendS("Available HelpBrowsers: ");
358 
359  i = 0;
361  while (heHelpBrowsers[i].browser != NULL)
362  {
363  if (heHelpBrowsers[i].init_proc(warn,i))
364  StringAppend("%s, ", heHelpBrowsers[i].browser);
365  i++;
366  }
367  StringAppend("\nCurrent HelpBrowser: %s ", feHelpBrowser());
368 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:262
static void feBrowserFile()
Definition: fehelp.cc:190
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
static heBrowser_s * heHelpBrowsers
Definition: fehelp.cc:96