My Project
Loading...
Searching...
No Matches
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)
 
 if (!FE_OPT_NO_SHELL_FLAG)
 
static int singular_manual (char *str, BOOLEAN isIndexEntry, heEntry hentry)
 
static char tolow (char p)
 
static int show (unsigned long offset, char *close)
 

Variables

STATIC_VAR heBrowser heCurrentHelpBrowser = NULL
 
STATIC_VAR int heCurrentHelpBrowserIndex = -1
 
STATIC_VAR heBrowser_sheHelpBrowsers =NULL
 
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
 
STATIC_VAR BOOLEAN feHelpCalled = FALSE
 

Data Structure Documentation

◆ heEntry_s

struct heEntry_s

Definition at line 30 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 42 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 29 of file fehelp.cc.

◆ MAX_SYSCMD_LEN

#define MAX_SYSCMD_LEN   MAXPATHLEN*2

Definition at line 811 of file fehelp.cc.

Typedef Documentation

◆ heBrowser

Definition at line 50 of file fehelp.cc.

◆ heBrowserHelpProc

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

Definition at line 39 of file fehelp.cc.

◆ heBrowserInitProc

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

Definition at line 40 of file fehelp.cc.

◆ heEntry

typedef heEntry_s* heEntry

Definition at line 37 of file fehelp.cc.

Function Documentation

◆ feBrowserFile()

static void feBrowserFile ( )
static

Definition at line 177 of file fehelp.cc.

178{
179 FILE *f=feFopen("help.cnf","r",NULL,TRUE);
180 int br=0;
181 if (f!=NULL)
182 {
183 char buf[512];
184 while (fgets( buf, sizeof(buf), f))
185 {
186 if ((buf[0]!='#') && (buf[0]>' ')) br++;
187 }
188 fseek(f,0,SEEK_SET);
189 // for the 4(!) default browsers
191 br = 0;
192 while (fgets( buf, sizeof(buf), f))
193 {
194 if ((buf[0]!='#') && (buf[0]>' '))
195 {
196 char *name=strtok(buf,"!");
197 char *req=strtok(NULL,"!");
198 char *cmd=strtok(NULL,"!");
199 if ((name!=NULL) && (req!=NULL) && (cmd!=NULL))
200 {
201 while ((cmd[0]!='\0') && (cmd[strlen(cmd)-1]<=' '))
202 cmd[strlen(cmd)-1]='\0';
203 //Print("name %d >>%s<<\n\treq:>>%s<<\n\tcmd:>>%s<<\n",br,name,req,cmd);
204 heHelpBrowsers[br].browser=(char *)omStrDup(name);
205 heHelpBrowsers[br].init_proc=heGenInit;
206 heHelpBrowsers[br].help_proc=heGenHelp;
207 heHelpBrowsers[br].required=omStrDup(req);
208 heHelpBrowsers[br].action=omStrDup(cmd);
209 br++;
210 }
211 else
212 {
213 Print("syntax error in help.cnf, at line starting with %s\n",buf);
214 }
215 }
216 }
217 fclose(f);
218 }
219 else
220 {
221 // for the 4(!) default browsers
223 }
224 heHelpBrowsers[br].browser="builtin";
225 heHelpBrowsers[br].init_proc=heGenInit;
226 heHelpBrowsers[br].help_proc=heBuiltinHelp;
227 heHelpBrowsers[br].required="i";
228 //heHelpBrowsers[br].action=NULL;
229 br++;
230 heHelpBrowsers[br].browser="dummy";
231 heHelpBrowsers[br].init_proc=heDummyInit;
232 heHelpBrowsers[br].help_proc=heDummyHelp;
233 //heHelpBrowsers[br].required=NULL;
234 //heHelpBrowsers[br].action=NULL;
235 br++;
236 heHelpBrowsers[br].browser="emacs";
237 heHelpBrowsers[br].init_proc=heEmacsInit;
238 heHelpBrowsers[br].help_proc=heEmacsHelp;
239 //heHelpBrowsers[br].required=NULL;
240 //heHelpBrowsers[br].action=NULL;
241 //br++;
242 //heHelpBrowsers[br].browser=NULL;
243 //heHelpBrowsers[br].init_proc=NULL;
244 //heHelpBrowsers[br].help_proc=NULL;
245 //heHelpBrowsers[br].required=NULL;
246 //heHelpBrowsers[br].action=NULL;
247}
#define TRUE
Definition auxiliary.h:101
FILE * f
Definition checklibs.c:9
#define Print
Definition emacs.cc:80
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
static BOOLEAN heDummyInit(int, int)
Definition fehelp.cc:1007
static BOOLEAN heGenInit(int, int)
Definition fehelp.cc:812
static BOOLEAN heEmacsInit(int, int)
Definition fehelp.cc:1016
STATIC_VAR heBrowser_s * heHelpBrowsers
Definition fehelp.cc:82
static void heDummyHelp(heEntry hentry, int)
Definition fehelp.cc:1011
static void heEmacsHelp(heEntry hentry, int)
Definition fehelp.cc:1020
static void heBuiltinHelp(heEntry hentry, int)
Definition fehelp.cc:1029
static void heGenHelp(heEntry hentry, int)
Definition fehelp.cc:871
#define SEEK_SET
Definition mod2.h:115
#define omStrDup(s)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
int status int void * buf
Definition si_signals.h:69
int name
New type name for int.

◆ feHelp()

void feHelp ( char * str)

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:88
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
bool found
static char * feResource(feResourceConfig config, int warn)
char url[MAX_HE_ENTRY_LENGTH]
Definition fehelp.cc:34
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
const char * feHelpBrowser(char *which, int warn)
Definition fehelp.cc:249
static BOOLEAN heOnlineHelp(char *s)
Definition fehelp.cc:621
#define assume(x)
Definition mod2.h:389
char * str(leftv arg)
Definition shared.cc:699
#define omFree(addr)
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 * which,
int warn )

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
259 return heCurrentHelpBrowser->browser;
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
313 {
316 if (warn)
317 Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
318 return heCurrentHelpBrowser->browser;
319 }
320 else
321 {
322 // or, leave as is
323 if (warn)
324 Warn("Help browser stays at '%s'.", heCurrentHelpBrowser->browser);
325 return 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,
332 heCurrentHelpBrowser->browser) != 0)
333 {
334 omfree(feOptSpec[FE_OPT_BROWSER].value);
335 feOptSpec[FE_OPT_BROWSER].value
336 = (void*) omStrDup(heCurrentHelpBrowser->browser);
337 }
338 return heCurrentHelpBrowser->browser;
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
static void feBrowserFile()
Definition fehelp.cc:177
STATIC_VAR int heCurrentHelpBrowserIndex
Definition fehelp.cc:72
#define omfree(addr)
#define dReportBug(s)
Definition reporter.h:113

◆ feStringAppendBrowsers()

void feStringAppendBrowsers ( int warn)

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

◆ heBrowserHelp()

static void heBrowserHelp ( heEntry hentry)
static

Definition at line 769 of file fehelp.cc.

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

◆ heBuiltinHelp()

static void heBuiltinHelp ( heEntry hentry,
int  )
static

Definition at line 1029 of file fehelp.cc.

1030{
1031 char* node = omStrDup(hentry != NULL && *(hentry->key) != '\0' ?
1032 hentry->key : "Top");
1033 singular_manual(node,(hentry != NULL) && *(hentry->url)!='\0',hentry);
1034 omFree(node);
1035}
static int singular_manual(char *str, BOOLEAN isIndexEntry, heEntry hentry)
Definition fehelp.cc:1096

◆ heDummyHelp()

static void heDummyHelp ( heEntry hentry,
int  )
static

Definition at line 1011 of file fehelp.cc.

1012{
1013 WerrorS("No functioning help browser available.");
1014}
void WerrorS(const char *s)
Definition feFopen.cc:24

◆ heDummyInit()

static BOOLEAN heDummyInit ( int ,
int  )
static

Definition at line 1007 of file fehelp.cc.

1008{
1009 return TRUE;
1010}

◆ heEmacsHelp()

static void heEmacsHelp ( heEntry hentry,
int  )
static

Definition at line 1020 of file fehelp.cc.

1021{
1022 WarnS("Your help command could not be executed. Use");
1023 Warn("C-h C-s %s",
1024 (hentry != NULL && *(hentry->node) != '\0' ? hentry->node : "Top"));
1025 WarnS("to enter the Singular online help. For general");
1026 WarnS("information on Singular running under Emacs, type C-h m.");
1027}

◆ heEmacsInit()

static BOOLEAN heEmacsInit ( int ,
int  )
static

Definition at line 1016 of file fehelp.cc.

1017{
1018 return TRUE;
1019}

◆ heGenHelp()

static void heGenHelp ( heEntry hentry,
int br )
static

Definition at line 871 of file fehelp.cc.

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

◆ heGenInit()

static BOOLEAN heGenInit ( int warn,
int br )
static

Definition at line 812 of file fehelp.cc.

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

◆ heKey2Entry()

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

Definition at line 388 of file fehelp.cc.

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

◆ heKeyChksum()

static long heKeyChksum ( char * key)
static

Definition at line 749 of file fehelp.cc.

750{
751 if (key == NULL || *key == '\0') return 0;
752 idhdl h=IDROOT->get(key,myynest);
753 if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
754 {
755 procinfo *pi = IDPROC(h);
756 if (pi != NULL) return pi->data.s.help_chksum;
757 }
758 return 0;
759}
VAR int myynest
Definition febase.cc:41
@ PROC_CMD
Definition grammar.cc:281
#define IDPROC(a)
Definition ipid.h:140
#define IDROOT
Definition ipid.h:19
#define IDTYP(a)
Definition ipid.h:119
STATIC_VAR Poly * h
Definition janet.cc:971
#define pi
Definition libparse.cc:1145
idrec * idhdl
Definition ring.h:22

◆ heOnlineHelp()

static BOOLEAN heOnlineHelp ( char * s)
static

Definition at line 621 of file fehelp.cc.

622{
623 char *ss;
624 idhdl h;
625
626 if ((ss=strstr(s,"::"))!=NULL)
627 {
628 *ss='\0';
629 ss+=2;
630 h=ggetid(s);
631 if (h!=NULL)
632 {
633 Print("help for %s from package %s\n",ss,s);
634 char s_help[200];
635 strcpy(s_help,ss);
636 strcat(s_help,"_help");
637 idhdl hh=IDPACKAGE(h)->idroot->get(s_help,0);
638 hePrintHelpStr(hh,s_help,s);
639 return TRUE;
640 }
641 else Print("package %s not found\n",s);
642 return TRUE; /* do not search the manual */
643 }
644 h=IDROOT->get(s,myynest);
645 // try help for a procedure
646 if (h!=NULL)
647 {
648 if (IDTYP(h)==PROC_CMD)
649 {
650 char *lib=iiGetLibName(IDPROC(h));
651 if((lib!=NULL)&&(*lib!='\0'))
652 {
653 Print("// proc %s from lib %s\n",s,lib);
655 if (pi->language==LANG_SINGULAR)
656 {
658 if (s!=NULL)
659 {
660 PrintS(s);
661 omFree((ADDRESS)s);
662 }
663 return TRUE;
664 }
665 }
666 }
667 else if (IDTYP(h)==PACKAGE_CMD)
668 {
669 idhdl hh=IDPACKAGE(h)->idroot->get("info",0);
670 hePrintHelpStr(hh,"info",s);
671 return TRUE;
672 }
673 return FALSE;
674 }
675
676 // try help for a library
677 int ls = strlen(s);
678 char* str = NULL;
679 // check that it ends with "[.,_]lib"
680 if (strlen(s) >=4 && strcmp(&s[ls-3], "lib") == 0)
681 {
682 if (s[ls - 4] == '.') str = s;
683 else
684 {
685 str = omStrDup(s);
686 str[ls - 4] = '.';
687 }
688 }
689 else
690 {
691 return FALSE;
692 }
693
694 char libnamebuf[1024];
695 FILE *fp=NULL;
696 // first, search for library of that name
697 if ((str[1]!='\0') &&
698 ((iiLocateLib(str, libnamebuf) && (fp=feFopen(libnamebuf, "rb")) !=NULL)
699 ||
700 ((fp=feFopen(str,"rb", libnamebuf))!=NULL)))
701 {
702 EXTERN_VAR FILE *yylpin;
703 lib_style_types lib_style; // = OLD_LIBSTYLE;
704
705 yylpin = fp;
706 yylplex(str, libnamebuf, &lib_style, IDROOT, FALSE, GET_INFO);
707 reinit_yylp();
708 if(lib_style == OLD_LIBSTYLE)
709 {
710 char buf[256];
711 fseek(fp, 0, SEEK_SET);
712 Warn( "library %s has an old format. Please fix it for the next time",
713 str);
714 if (str != s) omFree(str);
716 while (fgets( buf, sizeof(buf), fp))
717 {
718 if (strncmp(buf,"//",2)==0)
719 {
720 if (found) return TRUE;
721 }
722 else if ((strncmp(buf,"proc ",5)==0)||(strncmp(buf,"LIB ",4)==0))
723 {
724 if (!found) WarnS("no help part in library found");
725 return TRUE;
726 }
727 else
728 {
729 found=TRUE;
730 PrintS(buf);
731 }
732 }
733 }
734 else
735 {
736 if (str != s) omFree(str);
737 fclose( yylpin );
741 }
742 return TRUE;
743 }
744
745 if (str != s) omFree(str);
746 return FALSE;
747}
void * ADDRESS
Definition auxiliary.h:120
CanonicalForm fp
Definition cfModGcd.cc:4110
const CanonicalForm int s
Definition facAbsFact.cc:51
static void hePrintHelpStr(const idhdl hh, const char *id, const char *pa)
Definition fehelp.cc:608
#define EXTERN_VAR
Definition globaldefs.h:6
idhdl ggetid(const char *n)
Definition ipid.cc:558
#define IDPACKAGE(a)
Definition ipid.h:139
BOOLEAN iiLocateLib(const char *lib, char *where)
Definition iplib.cc:880
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition iplib.cc:197
static char * iiGetLibName(const procinfov pi)
find the library of an proc
Definition ipshell.h:66
void reinit_yylp()
Definition libparse.cc:3376
VAR char * text_buffer
Definition libparse.cc:1099
VAR char libnamebuf[1024]
Definition libparse.cc:1098
lib_style_types
Definition libparse.h:9
@ OLD_LIBSTYLE
Definition libparse.h:9
@ GET_INFO
Definition libparse.h:10
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
procinfo * procinfov
Definition structs.h:56
@ LANG_SINGULAR
Definition subexpr.h:22
@ PACKAGE_CMD
Definition tok.h:150

◆ hePrintHelpStr()

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

Definition at line 608 of file fehelp.cc.

609{
610 if ((hh!=NULL) && (IDTYP(hh)==STRING_CMD))
611 {
612 PrintS(IDSTRING(hh));
613 PrintLn();
614 }
615 else
616 Print("`%s` not found in package %s\n",id,pa);
617}
static BOOLEAN pa(leftv res, leftv args)
Definition cohomo.cc:3770
#define IDSTRING(a)
Definition ipid.h:136
@ STRING_CMD
Definition tok.h:187

◆ heReKey2Entry()

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

Definition at line 568 of file fehelp.cc.

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

◆ if()

if ( ! FE_OPT_NO_SHELL_FLAG)

Definition at line 1000 of file fehelp.cc.

1001 {
1002 int err=system(sys);
1003 if (err!=0) Warn("exit code: %d\n",err);
1004 }

◆ Print()

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

◆ show()

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

Definition at line 1056 of file fehelp.cc.

1057{ char buffer[BUF_LEN+1];
1058 int lines = 0;
1059 FILE * help;
1060
1061 if( (help = fopen(feResource('i'), "rb")) == NULL)
1062 return HELP_NOT_OPEN;
1063
1064 fseek(help, (long)(offset+1), (int)0);
1065 while( (!feof(help))
1066 && (*fgets(buffer, BUF_LEN, help) != EOF)
1067 && (buffer[0] != FIN_INDEX))
1068 {
1069 printf("%s", buffer);
1070 if(lines++==pagelength)
1071 {
1072 printf("\n Press <RETURN> to continue or x to exit help.\n");
1073 fflush(stdout);
1074 *close = (char)getchar();
1075 if(*close=='x')
1076 {
1077 getchar();
1078 break;
1079 }
1080 lines=0;
1081 }
1082 }
1083 if((*close!='x')&&(pagelength>0))
1084 {
1085 printf("\nEnd of part. Press <RETURN> to continue or x to exit help.\n");
1086 fflush(stdout);
1087 *close = (char)getchar();
1088 if(*close=='x')
1089 getchar();
1090 }
1091 fclose(help);
1092 return HELP_OK;
1093}
int lines
Definition checklibs.c:13
#define HELP_OK
Definition fehelp.cc:1042
#define BUF_LEN
Definition fehelp.cc:1046
#define FIN_INDEX
Definition fehelp.cc:1043
#define HELP_NOT_OPEN
Definition fehelp.cc:1044
STATIC_VAR int offset
Definition janet.cc:29
#define help
Definition libparse.cc:1230
EXTERN_VAR int pagelength
Definition reporter.h:17

◆ singular_manual()

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

Definition at line 1096 of file fehelp.cc.

1097{ FILE *index=NULL;
1098 unsigned long offset;
1099 char *p,close=' ';
1100 int done = 0;
1101 char buffer[BUF_LEN+1],
1102 Index[IDX_LEN+1],
1103 String[IDX_LEN+1];
1104 Print("HELP >>%s>>\n",str);
1105
1106 if( (index = fopen(feResource('i'), "rb")) == NULL)
1107 {
1108 return HELP_NOT_OPEN;
1109 }
1110
1111 if (!isIndexEntry)
1112 {
1113 for(p=str; *p; p++) *p = tolow(*p);/* */
1114 do
1115 {
1116 p--;
1117 }
1118 while ((p != str) && (*p<=' '));
1119 p++;
1120 *p='\0';
1121 snprintf(String,IDX_LEN+1, " %s ", str);
1122 }
1123 else
1124 {
1125 snprintf(String,IDX_LEN+1, " %s", str);
1126 }
1127
1128 while(!feof(index)
1129 && (fgets(buffer, BUF_LEN, index) != (char *)0)
1130 && (buffer[0] != FIN_INDEX)); // skip to FIN_INDEX
1131 char temp[256];temp[0]='\0';
1132 char *htmldir = feResource('u'); /* always defined */
1133 if (hentry != NULL && *(hentry->url) != '\0')
1134 #ifdef HAVE_VSNPRINTF
1135 {
1136 snprintf(temp,256,"%s/%d-%d/%s", htmldir,
1137 SINGULAR_VERSION/10000,
1138 (SINGULAR_VERSION % 10000)/1000,
1139 hentry->url);
1140 }
1141 #else
1142 {
1143 snprintf(temp,256,"%s/%d-%d/%s", htmldir,
1144 SINGULAR_VERSION/10000,
1145 (SINGULAR_VERSION % 10000)/1000,
1146 hentry->url);
1147 }
1148 #endif
1149 Print("url: %s\n",temp);
1150
1151 while(!feof(index))
1152 {
1153 if (fgets(buffer, BUF_LEN, index)==NULL) break; /*fill buffer */
1154 if (si_sscanf(buffer, "Node:%[^\177]\177%ld\n", Index, &offset)!=2)
1155 continue;
1156 if (!isIndexEntry)
1157 {
1158 for(p=Index; *p; p++) *p = tolow(*p);/* */
1159 (void)strcat(Index, " ");
1160 if( strstr(Index, String)!=NULL)
1161 {
1162 done++; (void)show(offset, &close);
1163 }
1164 }
1165 else if( strcmp(Index, String)==0)
1166 {
1167 done++; (void)show(offset, &close);
1168 break;
1169 }
1170 Index[0]='\0';
1171 if(close=='x')
1172 break;
1173 }
1174 if (index != NULL) (void)fclose(index);
1175 if(done==0)
1176 {
1177 Warn("`%s` not found",String);
1178 return HELP_NOT_FOUND;
1179 }
1180 return HELP_OK;
1181}
static int show(unsigned long offset, char *close)
Definition fehelp.cc:1056
#define IDX_LEN
Definition fehelp.cc:1047
#define HELP_NOT_FOUND
Definition fehelp.cc:1045
static char tolow(char p)
Definition fehelp.cc:1049
static int index(p_Length length, p_Ord ord)

◆ strclean()

static char * strclean ( char * str)
static

Definition at line 364 of file fehelp.cc.

365{
366 if (str == NULL) return NULL;
367 char *s=str;
368 while ((*s <= ' ') && (*s != '\0')) s++;
369 if (*s == '\0') return NULL;
370 char *ss=s;
371 while (*ss!='\0') ss++;
372 ss--;
373 while ((*ss <= ' ') && (*ss != '\0'))
374 {
375 *ss='\0';
376 ss--;
377 }
378 if (*ss == '\0') return NULL;
379 return s;
380}

◆ strmatch()

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

Definition at line 480 of file fehelp.cc.

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

◆ tolow()

static char tolow ( char p)
inlinestatic

Definition at line 1049 of file fehelp.cc.

1050{
1051 if (('A'<=p)&&(p<='Z')) return p | 040;
1052 return p;
1053}

Variable Documentation

◆ FE_OPT_NO_SHELL_FLAG

EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG

Definition at line 89 of file fehelp.cc.

◆ feHelpCalled

STATIC_VAR BOOLEAN feHelpCalled = FALSE

Definition at line 767 of file fehelp.cc.

◆ heCurrentHelpBrowser

STATIC_VAR heBrowser heCurrentHelpBrowser = NULL

Definition at line 71 of file fehelp.cc.

◆ heCurrentHelpBrowserIndex

STATIC_VAR int heCurrentHelpBrowserIndex = -1

Definition at line 72 of file fehelp.cc.

◆ heHelpBrowsers

STATIC_VAR heBrowser_s* heHelpBrowsers =NULL

Definition at line 82 of file fehelp.cc.