/* Interface to conthelp.dll, conthelp.so, ... */ #include "common.h" #include "datalib.h" /* for curve.h only */ #include "curve.h" /* for TypeHelpInfo() only */ #include "help.h" /* Help-variable names. Must be the same as in help-texts */ #define HLPVAR_CURCLASS "*curclass" /* class */ #define HLPVAR_CURTYPES "*curtypes" /* list of curve types */ #define HLPVAR_CURPOINT "*curpoint" /* type of initial point */ #define HLPVAR_CURCURVE "*curcurve" /* type of curve */ #define HLPVAR_CURSTARTER "*curstarter" #define HLPVAR_CURGENERATOR "*curgenerator" #define HelpLib (LibHandles[LH_HELP]) /****************************************************/ Global(CharPtr) SpecificHelpFiles; typedef EntryPtr(void,HelpFuncPtr0,(void)); typedef EntryPtr(Int2,HelpFuncPtr,(VoidPtr)); typedef EntryPtr(Int2,HelpFuncPtr2,(CharPtr,CharPtr)); Local(HelpFuncPtr) addfile; typedef struct _PendList { struct _PendList PNTR next; CharPtr helpfile; } PendList, PNTR PendListPtr; Local(PendListPtr) PendingList=NULL; Global(void) ReadHelpFile(void) { Char buf[BL]; GetLine(buf); SpecificHelpFiles=_StringSave(buf); } Global(void) FreeHelpFile(Boolean all) { PendListPtr pl; if (all) for ( ; PendingList; PendingList=pl) { _MemFree(PendingList->helpfile); pl=PendingList->next; _MemFree(PendingList); } SpecificHelpFiles=_MemFree(SpecificHelpFiles); } Local(HelpFuncPtr) onkey; Local(HelpFuncPtr) search; Local(HelpFuncPtr2) setvar; Local(HelpFuncPtr0) term; /* Adds filename to the list of help files to be loaded */ Local(void) AddToList(CharPtr helpfile) { PendListPtr pl; for (pl=PendingList; pl; pl=pl->next) if (!StrCmp(pl->helpfile,helpfile)) return; pl=_MemNew(sizeof(PendList)); pl->helpfile=_StringSave(helpfile); pl->next=PendingList; PendingList=pl; } /* Sets help-variables */ Global(void) HelpSetVar(void) { if (HelpLib) { setvar(HLPVAR_CURCLASS,ClassHelpInfo(CH_CLASS)); setvar(HLPVAR_CURTYPES,ClassHelpInfo(CH_TYPES)); setvar(HLPVAR_CURPOINT,TypeHelpInfo(TH_INITPOINT)); setvar(HLPVAR_CURCURVE,TypeHelpInfo(TH_CURVE)); setvar(HLPVAR_CURSTARTER,TypeHelpInfo(TH_STARTER)); setvar(HLPVAR_CURGENERATOR,TypeHelpInfo(TH_GENERATOR)); } } Local(Boolean) LoadHelpLib(void) { HelpFuncPtr init; CharPtr hf; PendListPtr pl; Boolean loaded=FALSE; LibraryUnlockRequested(); if (HelpLib==NULL) { HelpLib=LibraryLock("HELPLIB"); init=(HelpFuncPtr)LibraryFuncAddress(HelpLib,"ConthelpInit"); GetParam(SFS_HELP,"FILES"); StrCat(ParBuf," "); StrCat(ParBuf,SpecificHelpFiles); hf=_StringSave(ParBuf); for (pl=PendingList; pl; pl=pl->next) { hf=_MemMore(hf,StrLen(hf)+1+StrLen(pl->helpfile)+1); StrCat(hf," "); StrCat(hf,pl->helpfile); } init(hf); _MemFree(hf); onkey=(HelpFuncPtr)LibraryFuncAddress(HelpLib,"ConthelpKey"); search=(HelpFuncPtr)LibraryFuncAddress(HelpLib,"ConthelpSearch"); setvar=(HelpFuncPtr2)LibraryFuncAddress(HelpLib,"ConthelpSetVar"); addfile=(HelpFuncPtr)LibraryFuncAddress(HelpLib,"ConthelpAddFile"); term=(HelpFuncPtr0)LibraryFuncAddress(HelpLib,"ConthelpTerm"); loaded=TRUE; } HelpSetVar(); return loaded; } /* Show context help */ Global(void) Help(CharPtr key) { CharPtr pkey; pkey=key ? _StringSave(key) : NULL; /* key may be in ParBuf */ LoadHelpLib(); /* this changes ParBuf */ if (onkey(pkey ? pkey : GetHelpKey())) onkey(HLP_NOTAVAIL); _MemFree(pkey); } /* Show search dialog box */ Global(void) HelpSearch(CharPtr firstkey) { CharPtr pkey; pkey=firstkey ? _StringSave(firstkey) : NULL; /* firstkey may be in ParBuf */ if (LoadHelpLib()) onkey(pkey); _MemFree(pkey); search(NULL); } Global(void) HelpAddFile(CharPtr helpfile) { if (HelpLib) addfile(helpfile); AddToList(helpfile); } Global(void) HelpRemFile(CharPtr helpfile) { PendListPtr pl,pl1; for (pl=PendingList,pl1=NULL; pl; pl1=pl,pl=pl->next) if (!StrCmp(pl->helpfile,helpfile)) { _MemFree(pl->helpfile); if (pl1) pl1->next=pl->next; else PendingList=pl->next; _MemFree(pl); break; } } Global(Boolean) HelpTerm(void) { if (HelpLib) { LibraryUnlockRequest(HelpLib,term); return TRUE; } else return FALSE; }