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

91 {
92  str = strclean(str);
93  if (str == NULL) {heBrowserHelp(NULL); return;}
94 
95  if (strlen(str) > MAX_HE_ENTRY_LENGTH - 2) // need room for extra **
96  str[MAX_HE_ENTRY_LENGTH - 3] = '\0';
97 
98  BOOLEAN key_is_regexp = (strchr(str, '*') != NULL);
99 
100 
101  heEntry_s hentry;
102  memset(&hentry,0,sizeof(hentry));
103  char* idxfile = feResource('x' /*"IdxFile"*/);
104 
105  // Try exact match of help string with key in index
106  if (!key_is_regexp && (idxfile != NULL) && heKey2Entry(idxfile, str, &hentry))
107  {
108  heBrowserHelp(&hentry);
109  return;
110  }
111 
112  // Try to match approximately with key in index file
113  if (idxfile != NULL)
114  {
117 
118  StringSetS("");
119  int found = heReKey2Entry(idxfile, str, &hentry);
120 
121 
122  if (found == 0)
123  {
124  // try proc help and library help
125  if (! key_is_regexp && heOnlineHelp(str)) return;
126 
127  // Try to match with str*
128  char mkey[MAX_HE_ENTRY_LENGTH];
129  strcpy(mkey, str);
130  strcat(mkey, "*");
131  found = heReKey2Entry(idxfile, mkey, &hentry);
132  // Try to match with *str*
133  if (found == 0)
134  {
135  mkey[0] = '*';
136  strcpy(mkey + 1, str);
137  strcat(mkey, "*");
138  found = heReKey2Entry(idxfile, mkey, &hentry);
139  }
140 
141  // Print warning and return if nothing found
142  if (found == 0)
143  {
144  Warn("No help for topic '%s' (not even for '*%s*')", str, str);
145  WarnS("Try '?;' for general help");
146  WarnS("or '?Index;' for all available help topics.");
147  return;
148  }
149  }
150 
151  // do help if unique match was found
152  if (found == 1)
153  {
154  heBrowserHelp(&hentry);
155  return;
156  }
157  // Print warning about multiple matches and return
158  if (key_is_regexp)
159  Warn("No unique help for '%s'", str);
160  else
161  Warn("No help for topic '%s'", str);
162  WarnS("Try one of");
163  char *matches=StringEndS();
164  PrintS(matches);
165  omFree(matches);
166  PrintLn();
167  return;
168  }
169 
170  // no idx file, let Browsers deal with it, if they can
171  strcpy(hentry.key, str);
172  *hentry.node = '\0';
173  *hentry.url = '\0';
174  hentry.chksum = 0;
175  heBrowserHelp(&hentry);
176 }
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
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:249
static char * strclean(char *str)
Definition: fehelp.cc:364
static void heBrowserHelp(heEntry hentry)
Definition: fehelp.cc:769
static int heReKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:568
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:388
long chksum
Definition: fehelp.cc:35
static BOOLEAN heOnlineHelp(char *s)
Definition: fehelp.cc:621
#define assume(x)
Definition: mod2.h:389
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 249 of file fehelp.cc.

250 {
251  int i = 0;
252 
253  // if no argument, choose first available help browser
255  if (which == NULL || *which == '\0')
256  {
257  // return, if already set
258  if (heCurrentHelpBrowser != NULL)
260 
261  // First, try emacs, if emacs-option is set
262  if (feOptValue(FE_OPT_EMACS) != NULL)
263  {
264  while (heHelpBrowsers[i].browser != NULL)
265  {
266  if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
267  (heHelpBrowsers[i].init_proc(0,i)))
268  {
271  goto Finish;
272  }
273  i++;
274  }
275  i=0;
276  }
277  while (heHelpBrowsers[i].browser != NULL)
278  {
279  if (heHelpBrowsers[i].init_proc(0,i))
280  {
283  goto Finish;
284  }
285  i++;
286  }
287  // should never get here
288  dReportBug("should never get here");
289  }
290 
291  // with argument, find matching help browser
292  while (heHelpBrowsers[i].browser != NULL &&
293  strcmp(heHelpBrowsers[i].browser, which) != 0)
294  {i++;}
295 
296  if (heHelpBrowsers[i].browser == NULL)
297  {
298  if (warn) Warn("No help browser '%s' available.", which);
299  }
300  else
301  {
302  // see whether we can init it
303  if (heHelpBrowsers[i].init_proc(warn,i))
304  {
307  goto Finish;
308  }
309  }
310 
311  // something went wrong
312  if (heCurrentHelpBrowser == NULL)
313  {
314  feHelpBrowser();
316  if (warn)
317  Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
319  }
320  else
321  {
322  // or, leave as is
323  if (warn)
324  Warn("Help browser stays at '%s'.", heCurrentHelpBrowser->browser);
326  }
327 
328  Finish:
329  // update value of Browser Option
330  if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
331  strcmp((char*) feOptSpec[FE_OPT_BROWSER].value,
333  {
334  omfree(feOptSpec[FE_OPT_BROWSER].value);
335  feOptSpec[FE_OPT_BROWSER].value
337  }
339 }
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:177
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 341 of file fehelp.cc.

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