My Project  debian-1:4.1.1-p2+ds-4
Data Structures | Macros | Typedefs | Functions | Variables
fehelp.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/mylimits.h"
#include "resources/feResource.h"
#include "reporter/reporter.h"
#include "resources/omFindExec.h"
#include "reporter/si_signals.h"
#include "ipid.h"
#include "ipshell.h"
#include "libparse.h"
#include "feOpt.h"
#include "tok.h"
#include "fehelp.h"

Go to the source code of this file.

Data Structures

struct  heEntry_s
 
struct  heBrowser_s
 

Macros

#define MAX_HE_ENTRY_LENGTH   160
 
#define MAX_SYSCMD_LEN   MAXPATHLEN*2
 
#define HELP_OK   0
 
#define FIN_INDEX   '\037'
 
#define HELP_NOT_OPEN   1
 
#define HELP_NOT_FOUND   2
 
#define BUF_LEN   256
 
#define IDX_LEN   256
 

Typedefs

typedef heEntry_sheEntry
 
typedef void(* heBrowserHelpProc) (heEntry hentry, int br)
 
typedef BOOLEAN(* heBrowserInitProc) (int warn, int br)
 
typedef heBrowser_sheBrowser
 

Functions

static char * strclean (char *str)
 
static BOOLEAN heKey2Entry (char *filename, char *key, heEntry hentry)
 
static int heReKey2Entry (char *filename, char *key, heEntry hentry)
 
static BOOLEAN strmatch (char *s, char *re)
 
static BOOLEAN heOnlineHelp (char *s)
 
static void heBrowserHelp (heEntry hentry)
 
static long heKeyChksum (char *key)
 
static BOOLEAN heGenInit (int, int)
 
static void heGenHelp (heEntry hentry, int)
 
static void heBuiltinHelp (heEntry hentry, int)
 
static BOOLEAN heDummyInit (int, int)
 
static void heDummyHelp (heEntry hentry, int)
 
static BOOLEAN heEmacsInit (int, int)
 
static void heEmacsHelp (heEntry hentry, int)
 
void feHelp (char *str)
 
static void feBrowserFile ()
 
const char * feHelpBrowser (char *which, int warn)
 
void feStringAppendBrowsers (int warn)
 
static void hePrintHelpStr (const idhdl hh, const char *id, const char *pa)
 
 Print ("running `%s`\n", sys)
 
void system (sys)
 
static int singular_manual (char *str, BOOLEAN isIndexEntry)
 
static char tolow (char p)
 
static int show (unsigned long offset, char *close)
 

Variables

static heBrowser heCurrentHelpBrowser = NULL
 
static int heCurrentHelpBrowserIndex = -1
 
static heBrowser_sheHelpBrowsers =NULL
 
static BOOLEAN feHelpCalled = FALSE
 

Data Structure Documentation

◆ heEntry_s

struct heEntry_s

Definition at line 33 of file fehelp.cc.

Data Fields
long chksum
char key[MAX_HE_ENTRY_LENGTH]
char node[MAX_HE_ENTRY_LENGTH]
char url[MAX_HE_ENTRY_LENGTH]

◆ heBrowser_s

struct heBrowser_s

Definition at line 45 of file fehelp.cc.

Data Fields
const char * action
const char * browser
heBrowserHelpProc help_proc
heBrowserInitProc init_proc
const char * required

Macro Definition Documentation

◆ BUF_LEN

#define BUF_LEN   256

Definition at line 1046 of file fehelp.cc.

◆ FIN_INDEX

#define FIN_INDEX   '\037'

Definition at line 1043 of file fehelp.cc.

◆ HELP_NOT_FOUND

#define HELP_NOT_FOUND   2

Definition at line 1045 of file fehelp.cc.

◆ HELP_NOT_OPEN

#define HELP_NOT_OPEN   1

Definition at line 1044 of file fehelp.cc.

◆ HELP_OK

#define HELP_OK   0

Definition at line 1042 of file fehelp.cc.

◆ IDX_LEN

#define IDX_LEN   256

Definition at line 1047 of file fehelp.cc.

◆ MAX_HE_ENTRY_LENGTH

#define MAX_HE_ENTRY_LENGTH   160

Definition at line 32 of file fehelp.cc.

◆ MAX_SYSCMD_LEN

#define MAX_SYSCMD_LEN   MAXPATHLEN*2

Definition at line 808 of file fehelp.cc.

Typedef Documentation

◆ heBrowser

Definition at line 53 of file fehelp.cc.

◆ heBrowserHelpProc

typedef void(* heBrowserHelpProc) (heEntry hentry, int br)

Definition at line 42 of file fehelp.cc.

◆ heBrowserInitProc

typedef BOOLEAN(* heBrowserInitProc) (int warn, int br)

Definition at line 43 of file fehelp.cc.

◆ heEntry

typedef heEntry_s* heEntry

Definition at line 40 of file fehelp.cc.

Function Documentation

◆ feBrowserFile()

static void feBrowserFile ( )
static

Definition at line 176 of file fehelp.cc.

181 {
182  FILE *f=feFopen("help.cnf","r",NULL,TRUE);
183  int br=0;
184  if (f!=NULL)
185  {
186  char buf[512];
187  while (fgets( buf, sizeof(buf), f))
188  {
189  if ((buf[0]!='#') && (buf[0]>' ')) br++;
190  }
191  fseek(f,0,SEEK_SET);
192  // for the 4(!) default browsers
194  br = 0;
195  while (fgets( buf, sizeof(buf), f))
196  {
197  if ((buf[0]!='#') && (buf[0]>' '))
198  {
199  char *name=strtok(buf,"!");
200  char *req=strtok(NULL,"!");
201  char *cmd=strtok(NULL,"!");
202  if ((name!=NULL) && (req!=NULL) && (cmd!=NULL))
203  {
204  while ((cmd[0]!='\0') && (cmd[strlen(cmd)-1]<=' '))
205  cmd[strlen(cmd)-1]='\0';
206  //Print("name %d >>%s<<\n\treq:>>%s<<\n\tcmd:>>%s<<\n",br,name,req,cmd);
207  heHelpBrowsers[br].browser=(char *)omStrDup(name);
211  heHelpBrowsers[br].action=omStrDup(cmd);
212  br++;
213  }
214  else
215  {
216  Print("syntax error in help.cnf, at line starting with %s\n",buf);
217  }
218  }
219  }
220  fclose(f);
221  }
222  else
223  {
224  // for the 4(!) default browsers
226  }
227  heHelpBrowsers[br].browser="builtin";
230  heHelpBrowsers[br].required="i";
231  //heHelpBrowsers[br].action=NULL;
232  br++;
233  heHelpBrowsers[br].browser="dummy";
236  //heHelpBrowsers[br].required=NULL;
237  //heHelpBrowsers[br].action=NULL;
238  br++;
239  heHelpBrowsers[br].browser="emacs";
242  //heHelpBrowsers[br].required=NULL;
243  //heHelpBrowsers[br].action=NULL;
244  //br++;
245  //heHelpBrowsers[br].browser=NULL;
246  //heHelpBrowsers[br].init_proc=NULL;

◆ feHelp()

void feHelp ( char *  str)

Definition at line 89 of file fehelp.cc.

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

◆ feHelpBrowser()

const char* feHelpBrowser ( char *  which,
int  warn 
)

Definition at line 248 of file fehelp.cc.

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

◆ feStringAppendBrowsers()

void feStringAppendBrowsers ( int  warn)

Definition at line 340 of file fehelp.cc.

345 {
346  int i;
347  StringAppendS("Available HelpBrowsers: ");
348 
349  i = 0;
351  while (heHelpBrowsers[i].browser != NULL)
352  {
353  if (heHelpBrowsers[i].init_proc(warn,i))
354  StringAppend("%s, ", heHelpBrowsers[i].browser);

◆ heBrowserHelp()

static void heBrowserHelp ( heEntry  hentry)
static

Definition at line 766 of file fehelp.cc.

766  : Help Browsers
767  *
768  *****************************************************************/
769 
770 static BOOLEAN feHelpCalled = FALSE;
771 
772 static void heBrowserHelp(heEntry hentry)
773 {
774  // check checksums of procs
775  int kchksum = (hentry != NULL && hentry->chksum > 0 ?
776  heKeyChksum(hentry->key) : 0);
777  if (kchksum && kchksum != hentry->chksum && heOnlineHelp(hentry->key))
778  return;
779 
782  if (! feHelpCalled)
783  {
784  Warn("Displaying help in browser '%s'.", heCurrentHelpBrowser->browser);
785  //if (strcmp(heCurrentHelpBrowser->browser, "netscape") == 0 &&
786  // feResource('h', 0) == NULL)
787  //{
788  // Warn("Using URL '%s'.", feResource('u', 0));
789  //}
790  WarnS("Use 'system(\"--browser\", <browser>);' to change browser,");
791  StringSetS("where <browser> can be: ");
792  int i = 0;
793  i = 0;
794  while (heHelpBrowsers[i].browser != NULL)
795  {
796  if (heHelpBrowsers[i].init_proc(0,i))
797  StringAppend("\"%s\", ", heHelpBrowsers[i].browser);
798  i++;
799  }
800  char *browsers=StringEndS();
801  if (browsers[strlen(browsers)-2] == ',')
802  {
803  browsers[strlen(browsers)-2] = '.';
804  browsers[strlen(browsers)-1] = '\0';
805  }
806  WarnS(browsers);

◆ heBuiltinHelp()

static void heBuiltinHelp ( heEntry  hentry,
int   
)
static

Definition at line 1029 of file fehelp.cc.

1030  : "Top"));
1031  WarnS("to enter the Singular online help. For general");
1032  WarnS("information on Singular running under Emacs, type C-h m.");
1033 }
1034 static int singular_manual(char *str, BOOLEAN isIndexEntry);
1035 static void heBuiltinHelp(heEntry hentry, int /*br*/)

◆ heDummyHelp()

static void heDummyHelp ( heEntry  hentry,
int   
)
static

Definition at line 1011 of file fehelp.cc.

1014 {

◆ heDummyInit()

static BOOLEAN heDummyInit ( int  ,
int   
)
static

Definition at line 1007 of file fehelp.cc.

1014 {

◆ heEmacsHelp()

static void heEmacsHelp ( heEntry  hentry,
int   
)
static

Definition at line 1020 of file fehelp.cc.

1023 {
1024  return TRUE;
1025 }
1026 static void heEmacsHelp(heEntry hentry, int /*br*/)
1027 {

◆ heEmacsInit()

static BOOLEAN heEmacsInit ( int  ,
int   
)
static

Definition at line 1016 of file fehelp.cc.

1018 {
1019  WerrorS("No functioning help browser available.");

◆ heGenHelp()

static void heGenHelp ( heEntry  hentry,
int  br 
)
static

Definition at line 868 of file fehelp.cc.

875 {
876  char sys[MAX_SYSCMD_LEN];
877  const char *p=heHelpBrowsers[br].action;
878  if (p==NULL) {PrintS("no action ?\n"); return;}
879  memset(sys,0,MAX_SYSCMD_LEN);
880  int i=0;
881  while ((*p>'\0')&& (i<MAX_SYSCMD_LEN))
882  {
883  if ((*p)=='%')
884  {
885  p++;
886  switch (*p)
887  {
888  case 'f': /* local html:file */
889  case 'h': /* local html:URL */
890  case 'H': /* www html */
891  {
892  char temp[256];
893  char *htmldir = feResource('h' /*"HtmlDir"*/);
894  if ((*p=='h')&&(htmldir!=NULL))
895  strcat(sys,"file://localhost");
896  else if ((*p=='H')||(htmldir==NULL))
897  htmldir = feResource('u' /* %H -> "ManualUrl"*/);
898  /* always defined */
899  if (hentry != NULL && *(hentry->url) != '\0')
900  #ifdef HAVE_VSNPRINTF
901  {
902  if (*p=='H')
903  #ifdef SINGULAR_4_2
904  snprintf(temp,256,"%s/%d-%d/%s", htmldir,
905  SINGULAR_VERSION/1000,
906  (SINGULAR_VERSION % 1000)/100,
907  #else
908  snprintf(temp,256,"%s/%d-%d-%d/%s", htmldir,
909  SINGULAR_VERSION/1000,
910  (SINGULAR_VERSION % 1000)/100,
911  (SINGULAR_VERSION % 100)/10,
912  #endif
913  hentry->url);
914  else
915  snprintf(temp,256,"%s/%s", htmldir, hentry->url);
916  }
917  else
918  {
919  if (*p=='H')
920  snprintf(temp,256,"%s/%d-%d-%d/index.htm", htmldir,
921  SINGULAR_VERSION/1000,
922  (SINGULAR_VERSION % 1000)/100,
923  (SINGULAR_VERSION % 100)/10
924  );
925  else
926  snprintf(temp,256,"%s/index.htm", htmldir);
927  }
928  #else
929  {
930  if (*p=='H')
931  sprintf(temp,"%s/%d-%d-%d/%s", htmldir,
932  SINGULAR_VERSION/1000,
933  (SINGULAR_VERSION % 1000)/100,
934  (SINGULAR_VERSION % 100)/10,
935  hentry->url);
936  else
937  sprintf(temp,"%s/%d-%d-%d/%s", htmldir, hentry->url);
938  }
939  else
940  if (*p=='H')
941  sprintf(temp,"%s/%d-%d-%d/index.htm", htmldir,
942  SINGULAR_VERSION/1000,
943  (SINGULAR_VERSION % 1000)/100,
944  (SINGULAR_VERSION % 100)/10
945  );
946  else
947  sprintf(temp,"%s/index.htm", htmldir);
948  }
949  #endif
950  strcat(sys,temp);
951  if ((*p)=='f')
952  { // remove #SEC
953  char *pp=(char *)strchr(sys,'#');
954  if (pp!=NULL)
955  {
956  *pp='\0';
957  i=strlen(sys);
958  memset(pp,0,MAX_SYSCMD_LEN-i);
959  }
960  }
961  i=strlen(sys);
962  break;
963  }
964  case 'i': /* singular.hlp */
965  {
966  char *i_res=feResource('i');
967  if (i_res!=NULL) strcat(sys,i_res);
968  else
969  {
970  WarnS("singular.hlp not found");
971  return;
972  }
973  i=strlen(sys);
974  break;
975  }
976  case 'n': /* info node */
977  {
978  char temp[256];
979  if ((hentry!=NULL) && (*(hentry->node) != '\0'))
980  sprintf(temp,"%s",hentry->node);
981  //else if ((hentry!=NULL) && (hentry->key!=NULL))
982  // sprintf(temp,"Index '%s'",hentry->key);
983  else
984  sprintf(temp,"Top");
985  strcat(sys,temp);
986  i=strlen(sys);
987  break;
988  }
989  case 'v': /* version number*/
990  {
991  char temp[256];
992  sprintf(temp,"%d-%d-%d",SINGULAR_VERSION/1000,
993  (SINGULAR_VERSION % 1000)/100,
994  (SINGULAR_VERSION % 100)/10);
995  strcat(sys,temp);
996  i=strlen(sys);
997  break;
998  }
999  default: break;
1000  }
1001  p++;
1002  }

◆ heGenInit()

static BOOLEAN heGenInit ( int  warn,
int  br 
)
static

Definition at line 809 of file fehelp.cc.

816 {
817  if (heHelpBrowsers[br].required==NULL) return TRUE;
818  const char *p=heHelpBrowsers[br].required;
819  while (*p>'\0')
820  {
821  switch (*p)
822  {
823  case '#': break;
824  case ' ': break;
825  case 'i': /* singular.hlp */
826  case 'x': /* singular.idx */
827  case 'h': /* html dir */
828  if (feResource(*p, warn) == NULL)
829  {
830  if (warn) Warn("resource `%c` not found",*p);
831  return FALSE;
832  }
833  break;
834  case 'D': /* DISPLAY */
835  if (getenv("DISPLAY") == NULL)
836  {
837  if (warn) WarnS("resource `D` not found");
838  return FALSE;
839  }
840  break;
841  case 'E': /* executable: E:xterm: */
842  case 'O': /* OS: O:ix86Mac-darwin/ppcMac-darwin: */
843  {
844  char name[128];
845  char exec[128];
846  char op=*p;
847  memset(name,0,128);
848  int i=0;
849  p++;
850  while (((*p==':')||(*p<=' ')) && (*p!='\0')) p++;
851  while((i<127) && (*p>' ') && (*p!=':'))
852  {
853  name[i]=*p; p++; i++;
854  }
855  if (i==0) return FALSE;
856 
857  if ((op=='O') && (strcmp(name,S_UNAME)!=0))
858  return FALSE;
859  if ((op=='E') && (omFindExec(name,exec)==NULL))
860  {
861  if (warn) Warn("executable `%s` not found",name);
862  return FALSE;
863  }
864  }
865  break;
866  default: Warn("unknown char %c",*p);

◆ heKey2Entry()

static BOOLEAN heKey2Entry ( char *  filename,
char *  key,
heEntry  hentry 
)
static

Definition at line 386 of file fehelp.cc.

392 {
393  FILE* fd;
394  int c, k;
395  int kl, i;
396  *(hentry->key) = '\0';
397  *(hentry->url) = '\0';
398  *(hentry->node) = '\0';
399  hentry->chksum = 0;
400  if (filename == NULL || key == NULL) return FALSE;
401  fd = fopen(filename, "r");
402  if (fd == NULL) return FALSE;
403  kl = strlen(key);
404 
405  k = key[0];
406  i = 0;
407  while ((c = getc(fd)) != EOF)
408  {
409  if (c < k)
410  {
411  /* Skip line */
412  while (getc(fd) != '\n') {};
413  if (i)
414  {
415  i=0;
416  k=key[0];
417  }
418  }
419  else if (c == k)
420  {
421  i++;
422  if (i == kl)
423  {
424  // \t must follow, otherwise only substring match
425  if (getc(fd) != '\t') goto Failure;
426 
427  // Now we found an exact match
428  if (hentry->key != key) strcpy(hentry->key, key);
429  // get node
430  i = 0;
431  while ((c = getc(fd)) != '\t' && c != EOF)
432  {
433  hentry->node[i] = c;
434  i++;
435  }
436  if (c == EOF) goto Failure;
437  if (hentry->node[0]=='\0')
438  strcpy(hentry->node,hentry->key);
439 
440  // get url
441  //hentry->node[i] = '\0';
442  i = 0;
443  while ((c = getc(fd)) != '\t' && c != EOF)
444  {
445  hentry->url[i] = c;
446  i++;
447  }
448  if (c == EOF) goto Failure;
449 
450  // get chksum
451  hentry->url[i] = '\0';
452 
453  if (si_fscanf(fd, "%ld\n", &(hentry->chksum)) != 1)
454  {
455  hentry->chksum = -1;
456  }
457  fclose(fd);
458  return TRUE;
459  }
460  else if (i > kl)
461  {
462  goto Failure;
463  }
464  else
465  {
466  k = key[i];
467  }
468  }
469  else
470  {
471  goto Failure;
472  }

◆ heKeyChksum()

static long heKeyChksum ( char *  key)
static

Definition at line 747 of file fehelp.cc.

753 {
754  if (key == NULL || *key == '\0') return 0;
755  idhdl h=IDROOT->get(key,myynest);
756  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
757  {

◆ heOnlineHelp()

static BOOLEAN heOnlineHelp ( char *  s)
static

Definition at line 619 of file fehelp.cc.

625 {
626  char *ss;
627  idhdl h;
628 
629  if ((ss=strstr(s,"::"))!=NULL)
630  {
631  *ss='\0';
632  ss+=2;
633  h=ggetid(s);
634  if (h!=NULL)
635  {
636  Print("help for %s from package %s\n",ss,s);
637  char s_help[200];
638  strcpy(s_help,ss);
639  strcat(s_help,"_help");
640  idhdl hh=IDPACKAGE(h)->idroot->get(s_help,0);
641  hePrintHelpStr(hh,s_help,s);
642  return TRUE;
643  }
644  else Print("package %s not found\n",s);
645  return TRUE; /* do not search the manual */
646  }
647  h=IDROOT->get(s,myynest);
648  // try help for a procedure
649  if (h!=NULL)
650  {
651  if (IDTYP(h)==PROC_CMD)
652  {
653  char *lib=iiGetLibName(IDPROC(h));
654  if((lib!=NULL)&&(*lib!='\0'))
655  {
656  Print("// proc %s from lib %s\n",s,lib);
657  procinfov pi=IDPROC(h);
658  if (pi->language==LANG_SINGULAR)
659  {
660  s=iiGetLibProcBuffer(pi, 0);
661  if (s!=NULL)
662  {
663  PrintS(s);
664  omFree((ADDRESS)s);
665  }
666  return TRUE;
667  }
668  }
669  }
670  else if (IDTYP(h)==PACKAGE_CMD)
671  {
672  idhdl hh=IDPACKAGE(h)->idroot->get("info",0);
673  hePrintHelpStr(hh,"info",s);
674  return TRUE;
675  }
676  return FALSE;
677  }
678 
679  // try help for a library
680  int ls = strlen(s);
681  char* str = NULL;
682  // check that it ends with "[.,_]lib"
683  if (strlen(s) >=4 && strcmp(&s[ls-3], "lib") == 0)
684  {
685  if (s[ls - 4] == '.') str = s;
686  else
687  {
688  str = omStrDup(s);
689  str[ls - 4] = '.';
690  }
691  }
692  else
693  {
694  return FALSE;
695  }
696 
697  char libnamebuf[1024];
698  FILE *fp=NULL;
699  // first, search for library of that name
700  if ((str[1]!='\0') &&
701  ((iiLocateLib(str, libnamebuf) && (fp=feFopen(libnamebuf, "rb")) !=NULL)
702  ||
703  ((fp=feFopen(str,"rb", libnamebuf))!=NULL)))
704  {
705  extern FILE *yylpin;
706  lib_style_types lib_style; // = OLD_LIBSTYLE;
707 
708  yylpin = fp;
709  yylplex(str, libnamebuf, &lib_style, IDROOT, FALSE, GET_INFO);
710  reinit_yylp();
711  if(lib_style == OLD_LIBSTYLE)
712  {
713  char buf[256];
714  fseek(fp, 0, SEEK_SET);
715  Warn( "library %s has an old format. Please fix it for the next time",
716  str);
717  if (str != s) omFree(str);
719  while (fgets( buf, sizeof(buf), fp))
720  {
721  if (strncmp(buf,"//",2)==0)
722  {
723  if (found) return TRUE;
724  }
725  else if ((strncmp(buf,"proc ",5)==0)||(strncmp(buf,"LIB ",4)==0))
726  {
727  if (!found) WarnS("no help part in library found");
728  return TRUE;
729  }
730  else
731  {
732  found=TRUE;
733  PrintS(buf);
734  }
735  }
736  }
737  else
738  {
739  if (str != s) omFree(str);
740  fclose( yylpin );
744  }
745  return TRUE;

◆ hePrintHelpStr()

static void hePrintHelpStr ( const idhdl  hh,
const char *  id,
const char *  pa 
)
static

Definition at line 606 of file fehelp.cc.

612 {
613  if ((hh!=NULL) && (IDTYP(hh)==STRING_CMD))
614  {
615  PrintS(IDSTRING(hh));

◆ heReKey2Entry()

static int heReKey2Entry ( char *  filename,
char *  key,
heEntry  hentry 
)
static

Definition at line 566 of file fehelp.cc.

572 {
573  int i = 0;
574  FILE* fd;
575  char index_key[MAX_HE_ENTRY_LENGTH];
576 
577  if (filename == NULL || key == NULL) return 0;
578  fd = fopen(filename, "r");
579  if (fd == NULL) return 0;
580  memset(index_key,0,MAX_HE_ENTRY_LENGTH);
581  while (si_fscanf(fd, "%[^\t]\t%*[^\n]\n", index_key) == 1)
582  {
583  if ((index_key[MAX_HE_ENTRY_LENGTH-1]!='\0'))
584  {
585  index_key[MAX_HE_ENTRY_LENGTH-1]='\0';
586  Werror("index file corrupt at line >>%s<<",index_key);
587  break;
588  }
589  else if (strmatch(index_key, key))
590  {
591  i++;
592  if (i == 1)
593  {
594  heKey2Entry(filename, index_key, hentry);
595  }
596  else if (i == 2)
597  {
598  StringAppend("?%s; ?%s;", hentry->key, index_key);
599  }
600  else
601  {
602  StringAppend(" ?%s;", index_key);
603  }

◆ Print()

Print ( "running `%s`\n"  ,
sys   
)

◆ show()

static int show ( unsigned long  offset,
char *  close 
)
static

Definition at line 1056 of file fehelp.cc.

1056 {
1057  if (('A'<=p)&&(p<='Z')) return p | 040;
1058  return p;
1059 }
1060 
1061 /*************************************************/
1062 static int show(unsigned long offset, char *close)
1063 { char buffer[BUF_LEN+1];
1064  int lines = 0;
1065  FILE * help;
1066 
1067  if( (help = fopen(feResource('i'), "rb")) == NULL)
1068  return HELP_NOT_OPEN;
1069 
1070  fseek(help, (long)(offset+1), (int)0);
1071  while( (!feof(help))
1072  && (*fgets(buffer, BUF_LEN, help) != EOF)
1073  && (buffer[0] != FIN_INDEX))
1074  {
1075  printf("%s", buffer);
1076  if(lines++==pagelength)
1077  {
1078  printf("\n Press <RETURN> to continue or x to exit help.\n");
1079  fflush(stdout);
1080  *close = (char)getchar();
1081  if(*close=='x')
1082  {
1083  getchar();
1084  break;
1085  }
1086  lines=0;
1087  }
1088  }
1089  if((*close!='x')&&(pagelength>0))
1090  {
1091  printf("\nEnd of part. Press <RETURN> to continue or x to exit help.\n");
1092  fflush(stdout);
1093  *close = (char)getchar();

◆ singular_manual()

static int singular_manual ( char *  str,
BOOLEAN  isIndexEntry 
)
static

Definition at line 1096 of file fehelp.cc.

1103 { FILE *index=NULL;
1104  unsigned long offset;
1105  char *p,close=' ';
1106  int done = 0;
1107  char buffer[BUF_LEN+1],
1108  Index[IDX_LEN+1],
1109  String[IDX_LEN+1];
1110  Print("HELP >>%s>>\n",str);
1111 
1112  if( (index = fopen(feResource('i'), "rb")) == NULL)
1113  {
1114  return HELP_NOT_OPEN;
1115  }
1116 
1117  if (!isIndexEntry)
1118  {
1119  for(p=str; *p; p++) *p = tolow(*p);/* */
1120  do
1121  {
1122  p--;
1123  }
1124  while ((p != str) && (*p<=' '));
1125  p++;
1126  *p='\0';
1127  (void)sprintf(String, " %s ", str);
1128  }
1129  else
1130  {
1131  (void)sprintf(String, " %s", str);
1132  }
1133 
1134  while(!feof(index)
1135  && (fgets(buffer, BUF_LEN, index) != (char *)0)
1136  && (buffer[0] != FIN_INDEX));
1137 
1138  while(!feof(index))
1139  {
1140  if (fgets(buffer, BUF_LEN, index)==NULL) break; /*fill buffer */
1141  if (si_sscanf(buffer, "Node:%[^\177]\177%ld\n", Index, &offset)!=2)
1142  continue;
1143  if (!isIndexEntry)
1144  {
1145  for(p=Index; *p; p++) *p = tolow(*p);/* */
1146  (void)strcat(Index, " ");
1147  if( strstr(Index, String)!=NULL)
1148  {
1149  done++; (void)show(offset, &close);
1150  }
1151  }
1152  else if( strcmp(Index, String)==0)
1153  {
1154  done++; (void)show(offset, &close);
1155  break;
1156  }
1157  Index[0]='\0';
1158  if(close=='x')
1159  break;
1160  }
1161  if (index != NULL) (void)fclose(index);
1162  if(done==0)

◆ strclean()

static char * strclean ( char *  str)
static

Definition at line 362 of file fehelp.cc.

363  : local function
364  *
365  *****************************************************************/
366 // Remove whitspaces from beginning and end, return NULL if only whitespaces
367 static char* strclean(char* str)
368 {
369  if (str == NULL) return NULL;
370  char *s=str;
371  while ((*s <= ' ') && (*s != '\0')) s++;
372  if (*s == '\0') return NULL;
373  char *ss=s;
374  while (*ss!='\0') ss++;
375  ss--;
376  while ((*ss <= ' ') && (*ss != '\0'))
377  {
378  *ss='\0';

◆ strmatch()

static BOOLEAN strmatch ( char *  s,
char *  re 
)
static

Definition at line 478 of file fehelp.cc.

484 {
485  if (s == NULL || *s == '\0')
486  return (re == NULL || *re == '\0' || strcmp(re, "*") == 0);
487  if (re == NULL || *re == '\0') return FALSE;
488 
489  int i;
490  char ls[MAX_HE_ENTRY_LENGTH + 1];
491  char rs[MAX_HE_ENTRY_LENGTH + 1];
492  char *l, *r, *ll, *rr;
493 
494  // make everything to lower case
495  i=1;
496  ls[0] = '\0';
497  do
498  {
499  if (*s >= 'A' && *s <= 'Z') ls[i] = *s + ('a' - 'A');
500  else ls[i] = *s;
501  i++;
502  s++;
503  } while (*s != '\0');
504  ls[i] = '\0';
505  l = &(ls[1]);
506 
507  i=1;
508  rs[0] = '\0';
509  do
510  {
511  if (*re >= 'A' && *re <= 'Z') rs[i]= *re + ('a' - 'A');
512  else rs[i] = *re;
513  i++;
514  re++;
515  } while (*re != '\0');
516  rs[i] = '\0';
517  r = &(rs[1]);
518 
519  // chopp of exact matches from beginning and end
520  while (*r != '*' && *r != '\0' && *l != '\0')
521  {
522  if (*r != *l) return FALSE;
523  *r = '\0';
524  *s = '\0';
525  r++;
526  l++;
527  }
528  if (*r == '\0') return (*l == '\0');
529  if (*r == '*' && r[1] == '\0') return TRUE;
530  if (*l == '\0') return FALSE;
531 
532  rr = &r[strlen(r) - 1];
533  ll = &l[strlen(l) - 1];
534  while (*rr != '*' && *rr != '\0' && *ll != '\0')
535  {
536  if (*rr != *ll) return FALSE;
537  *rr = '\0';
538  *ll = '\0';
539  rr--;
540  ll--;
541  }
542  if (*rr == '\0') return (*ll == '\0');
543  if (*rr == '*' && rr[-1] == '\0') return TRUE;
544  if (*ll == '\0') return FALSE;
545 
546  // now *r starts with a * and ends with a *
547  r++;
548  *rr = '\0'; rr--;
549  while (*r != '\0')
550  {
551  rr = r + 1;
552  while (*rr != '*' && *rr != '\0') rr++;
553  if (*rr == '*')
554  {
555  *rr = '\0';
556  rr++;
557  }
558  l = strstr(l, r);

◆ system()

void system ( sys  )

◆ tolow()

static char tolow ( char  p)
inlinestatic

Definition at line 1049 of file fehelp.cc.

1056 {

Variable Documentation

◆ feHelpCalled

BOOLEAN feHelpCalled = FALSE
static

Definition at line 764 of file fehelp.cc.

◆ heCurrentHelpBrowser

heBrowser heCurrentHelpBrowser = NULL
static

Definition at line 73 of file fehelp.cc.

◆ heCurrentHelpBrowserIndex

int heCurrentHelpBrowserIndex = -1
static

Definition at line 74 of file fehelp.cc.

◆ heHelpBrowsers

heBrowser_s* heHelpBrowsers =NULL
static

Definition at line 83 of file fehelp.cc.

FALSE
#define FALSE
Definition: auxiliary.h:94
show
static int show(unsigned long offset, char *close)
Definition: fehelp.cc:1056
iiGetLibName
static char * iiGetLibName(const procinfov pi)
find the library of an proc
Definition: ipshell.h:65
getenv
char * getenv()
SEEK_SET
#define SEEK_SET
Definition: mod2.h:112
feHelpCalled
static BOOLEAN feHelpCalled
Definition: fehelp.cc:764
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:106
singular_manual
static int singular_manual(char *str, BOOLEAN isIndexEntry)
Definition: fehelp.cc:1096
f
FILE * f
Definition: checklibs.c:9
feFopen
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:46
omFree
#define omFree(addr)
Definition: omAllocDecl.h:259
heBrowser_s::action
const char * action
Definition: fehelp.cc:51
k
int k
Definition: cfEzgcd.cc:92
heReKey2Entry
static int heReKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:566
LANG_SINGULAR
Definition: subexpr.h:22
feBrowserFile
static void feBrowserFile()
Definition: fehelp.cc:176
feHelp
void feHelp(char *str)
Definition: fehelp.cc:89
pagelength
int pagelength
Definition: febase.cc:37
OLD_LIBSTYLE
Definition: libparse.h:9
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
STRING_CMD
Definition: tok.h:182
heBrowser_s::init_proc
heBrowserInitProc init_proc
Definition: fehelp.cc:48
heBrowser_s::required
const char * required
Definition: fehelp.cc:50
iiLocateLib
BOOLEAN iiLocateLib(const char *lib, char *where)
Definition: iplib.cc:811
yylplex
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
heOnlineHelp
static BOOLEAN heOnlineHelp(char *s)
Definition: fehelp.cc:619
heEntry_s::chksum
long chksum
Definition: fehelp.cc:38
procinfo
Definition: subexpr.h:52
heEmacsInit
static BOOLEAN heEmacsInit(int, int)
Definition: fehelp.cc:1016
heBuiltinHelp
static void heBuiltinHelp(heEntry hentry, int)
Definition: fehelp.cc:1029
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:261
heEntry_s::key
char key[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:35
StringEndS
char * StringEndS()
Definition: reporter.cc:150
heDummyInit
static BOOLEAN heDummyInit(int, int)
Definition: fehelp.cc:1007
lines
int lines
Definition: checklibs.c:13
MAX_HE_ENTRY_LENGTH
#define MAX_HE_ENTRY_LENGTH
Definition: fehelp.cc:32
found
bool found
Definition: facFactorize.cc:56
heBrowser_s::browser
const char * browser
Definition: fehelp.cc:47
pi
#define pi
Definition: libparse.cc:1142
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
fp
CanonicalForm fp
Definition: cfModGcd.cc:4043
buf
int status int void * buf
Definition: si_signals.h:58
PrintS
void PrintS(const char *s)
Definition: reporter.cc:283
heBrowser_s
Definition: fehelp.cc:45
HELP_NOT_OPEN
#define HELP_NOT_OPEN
Definition: fehelp.cc:1044
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
heEntry_s
Definition: fehelp.cc:33
hePrintHelpStr
static void hePrintHelpStr(const idhdl hh, const char *id, const char *pa)
Definition: fehelp.cc:606
PROC_CMD
Definition: grammar.cc:280
Print
Print("running `%s`\n", sys)
iiGetLibProcBuffer
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:191
IDROOT
#define IDROOT
Definition: ipid.h:17
dReportBug
#define dReportBug(s)
Definition: reporter.h:111
heBrowserHelp
static void heBrowserHelp(heEntry hentry)
Definition: fehelp.cc:766
heEmacsHelp
static void heEmacsHelp(heEntry hentry, int)
Definition: fehelp.cc:1020
h
static Poly * h
Definition: janet.cc:972
IDPROC
#define IDPROC(a)
Definition: ipid.h:134
heCurrentHelpBrowser
static heBrowser heCurrentHelpBrowser
Definition: fehelp.cc:73
heGenHelp
static void heGenHelp(heEntry hentry, int)
Definition: fehelp.cc:868
FIN_INDEX
#define FIN_INDEX
Definition: fehelp.cc:1043
heCurrentHelpBrowserIndex
static int heCurrentHelpBrowserIndex
Definition: fehelp.cc:74
SINGULAR_VERSION
#define SINGULAR_VERSION
Definition: mod2.h:85
myynest
int myynest
Definition: febase.cc:40
pp
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:253
IDTYP
#define IDTYP(a)
Definition: ipid.h:113
heKey2Entry
static BOOLEAN heKey2Entry(char *filename, char *key, heEntry hentry)
Definition: fehelp.cc:386
heDummyHelp
static void heDummyHelp(heEntry hentry, int)
Definition: fehelp.cc:1011
heEntry_s::node
char node[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:36
heKeyChksum
static long heKeyChksum(char *key)
Definition: fehelp.cc:747
omFindExec
char * omFindExec(const char *name, char *exec)
Definition: omFindExec.c:251
help
#define help
Definition: libparse.cc:1227
libnamebuf
char libnamebuf[1024]
Definition: libparse.cc:1095
feOptSpec
struct fe_option feOptSpec[]
heBrowser_s::help_proc
heBrowserHelpProc help_proc
Definition: fehelp.cc:49
idrec
Definition: idrec.h:33
feResource
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:254
text_buffer
char * text_buffer
Definition: libparse.cc:1096
IDPACKAGE
#define IDPACKAGE(a)
Definition: ipid.h:133
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:127
lib_style_types
lib_style_types
Definition: libparse.h:8
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:188
PACKAGE_CMD
Definition: tok.h:148
name
char name(const Variable &v)
Definition: factory.h:180
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
WarnS
#define WarnS
Definition: emacs.cc:77
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:9
heHelpBrowsers
static heBrowser_s * heHelpBrowsers
Definition: fehelp.cc:83
fe_option::value
void * value
Definition: fegetopt.h:93
l
int l
Definition: cfEzgcd.cc:93
tolow
static char tolow(char p)
Definition: fehelp.cc:1049
IDSTRING
#define IDSTRING(a)
Definition: ipid.h:130
heGenInit
static BOOLEAN heGenInit(int, int)
Definition: fehelp.cc:809
MAX_SYSCMD_LEN
#define MAX_SYSCMD_LEN
Definition: fehelp.cc:808
Warn
#define Warn
Definition: emacs.cc:76
GET_INFO
Definition: libparse.h:9
StringAppend
#define StringAppend
Definition: emacs.cc:78
heEntry_s::url
char url[MAX_HE_ENTRY_LENGTH]
Definition: fehelp.cc:37
p
int p
Definition: cfModGcd.cc:4019
strmatch
static BOOLEAN strmatch(char *s, char *re)
Definition: fehelp.cc:478
reinit_yylp
void reinit_yylp()
Definition: libparse.cc:3373
ggetid
idhdl ggetid(const char *n)
Definition: ipid.cc:512
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
offset
int offset
Definition: libparse.cc:1090
feOptValue
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:39
IDX_LEN
#define IDX_LEN
Definition: fehelp.cc:1047
fd
int status int fd
Definition: si_signals.h:58
PrintLn
void PrintLn()
Definition: reporter.cc:309
BUF_LEN
#define BUF_LEN
Definition: fehelp.cc:1046
index
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:585
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:209
strclean
static char * strclean(char *str)
Definition: fehelp.cc:362
feHelpBrowser
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:248
omfree
#define omfree(addr)
Definition: omAllocDecl.h:235