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

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  // try proc help and library help
114  if (! key_is_regexp && heOnlineHelp(str)) return;
115 
116  heEntry_s hentry;
117  memset(&hentry,0,sizeof(hentry));
118  char* idxfile = feResource('x' /*"IdxFile"*/);
119 
120  // Try exact match of help string with key in index
121  if (!key_is_regexp && (idxfile != NULL) && heKey2Entry(idxfile, str, &hentry))
122  {
123  heBrowserHelp(&hentry);
124  return;
125  }
126 
127  // Try to match approximately with key in index file
128  if (idxfile != NULL)
129  {
132 
133  StringSetS("");
134  int found = heReKey2Entry(idxfile, str, &hentry);
135 
136  // Try to match with str*
137  if (found == 0)
138  {
139  char mkey[MAX_HE_ENTRY_LENGTH];
140  strcpy(mkey, str);
141  strcat(mkey, "*");
142  found = heReKey2Entry(idxfile, mkey, &hentry);
143  // Try to match with *str*
144  if (found == 0)
145  {
146  mkey[0] = '*';
147  strcpy(mkey + 1, str);
148  strcat(mkey, "*");
149  found = heReKey2Entry(idxfile, mkey, &hentry);
150  }
151 
152  // Print warning and return if nothing found
153  if (found == 0)
154  {
155  Warn("No help for topic '%s' (not even for '*%s*')", str, str);
156  WarnS("Try '?;' for general help");
157  WarnS("or '?Index;' for all available help topics.");
158  return;
159  }
160  }
161 
162  // do help if unique match was found
163  if (found == 1)
164  {
165  heBrowserHelp(&hentry);
166  return;
167  }
168  // Print warning about multiple matches and return
169  if (key_is_regexp)
170  Warn("No unique help for '%s'", str);
171  else
172  Warn("No help for topic '%s'", str);
173  Warn("Try one of");
174  char *matches=StringEndS();
175  PrintS(matches);
176  omFree(matches);
177  PrintLn();
178  return;
179  }
180 
181  // no idx file, let Browsers deal with it, if they can
182  strcpy(hentry.key, str);
183  *hentry.node = '\0';
184  *hentry.url = '\0';
185  hentry.chksum = 0;
186  heBrowserHelp(&hentry);
187 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:260
char url[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:48
long chksum
Definition: fehelp.cc:49
void PrintLn()
Definition: reporter.cc:327
static BOOLEAN heOnlineHelp(char *s)
Definition: fehelp.cc:632
#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:579
char * StringEndS()
Definition: reporter.cc:151
static void heBrowserHelp(heEntry hentry)
Definition: fehelp.cc:780
#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:405
void StringSetS(const char *st)
Definition: reporter.cc:128
static BOOLEAN heKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:399
static heBrowser heCurrentHelpBrowser
Definition: fehelp.cc:85
void PrintS(const char *s)
Definition: reporter.cc:294
#define NULL
Definition: omList.c:10
static char * strclean(char *str)
Definition: fehelp.cc:375
int BOOLEAN
Definition: auxiliary.h:131
#define Warn
Definition: emacs.cc:80
const char* feHelpBrowser ( char *  browser = NULL,
int  warn = -1 
)

Definition at line 260 of file fehelp.cc.

261 {
262  int i = 0;
263 
264  // if no argument, choose first available help browser
266  if (which == NULL || *which == '\0')
267  {
268  // return, if already set
269  if (heCurrentHelpBrowser != NULL)
271 
272  // First, try emacs, if emacs-option is set
273  if (feOptValue(FE_OPT_EMACS) != NULL)
274  {
275  while (heHelpBrowsers[i].browser != NULL)
276  {
277  if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
278  (heHelpBrowsers[i].init_proc(0,i)))
279  {
282  goto Finish;
283  }
284  i++;
285  }
286  i=0;
287  }
288  while (heHelpBrowsers[i].browser != NULL)
289  {
290  if (heHelpBrowsers[i].init_proc(0,i))
291  {
294  goto Finish;
295  }
296  i++;
297  }
298  // should never get here
299  dReportBug("should never get here");
300  }
301 
302  // with argument, find matching help browser
303  while (heHelpBrowsers[i].browser != NULL &&
304  strcmp(heHelpBrowsers[i].browser, which) != 0)
305  {i++;}
306 
307  if (heHelpBrowsers[i].browser == NULL)
308  {
309  if (warn) Warn("No help browser '%s' available.", which);
310  }
311  else
312  {
313  // see whether we can init it
314  if (heHelpBrowsers[i].init_proc(warn,i))
315  {
318  goto Finish;
319  }
320  }
321 
322  // something went wrong
323  if (heCurrentHelpBrowser == NULL)
324  {
325  feHelpBrowser();
327  if (warn)
328  Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
330  }
331  else
332  {
333  // or, leave as is
334  if (warn)
335  Warn("Help browser stays at '%s'.", heCurrentHelpBrowser->browser);
337  }
338 
339  Finish:
340  // update value of Browser Option
341  if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
342  strcmp((char*) feOptSpec[FE_OPT_BROWSER].value,
344  {
345  omfree(feOptSpec[FE_OPT_BROWSER].value);
346  feOptSpec[FE_OPT_BROWSER].value
348  }
350 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:260
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
static void feBrowserFile()
Definition: fehelp.cc:188
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:405
#define omfree(addr)
Definition: omAllocDecl.h:237
struct fe_option feOptSpec[]
#define dReportBug(s)
Definition: reporter.h:110
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
void feStringAppendBrowsers ( int  warn = -1)

Definition at line 352 of file fehelp.cc.

353 {
354  int i;
355  StringAppendS("Available HelpBrowsers: ");
356 
357  i = 0;
359  while (heHelpBrowsers[i].browser != NULL)
360  {
361  if (heHelpBrowsers[i].init_proc(warn,i))
362  StringAppend("%s, ", heHelpBrowsers[i].browser);
363  i++;
364  }
365  StringAppend("\nCurrent HelpBrowser: %s ", feHelpBrowser());
366 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:260
static void feBrowserFile()
Definition: fehelp.cc:188
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