76 #include "X11workbench.h" 79 #include "debug_helper.h" 80 #include "file_help.h" 83 #include "context_help.h" 86 static char * InternalMan2Html(
const char *szTerm,
const char *szText);
112 void DoContextSensitiveHelp(
const char *szTerm)
114 char szDocFilePath[PATH_MAX * 2], szName[PATH_MAX];
117 void *pSettings, *pDirList;
119 unsigned long dwAttr;
121 WB_FILE_HANDLE hProcess;
122 static char szLineBuf[4096], szDoxyTag[PATH_MAX * 2 + 512], szHelpBrowser[PATH_MAX];
128 bzero(szDocFilePath,
sizeof(szDocFilePath));
135 if(0 >=
CHGetConfFileString(pSettings,
"paths",
"browser", szHelpBrowser,
sizeof(szHelpBrowser)))
137 WB_ERROR_PRINT(
"ERROR did not find 'paths' 'browser', using default\n");
138 goto find_url_opener;
145 i1 =
CHGetConfFileString(pSettings,
"paths",
"documentation",szDocFilePath,
sizeof(szDocFilePath) - 2);
159 if(!p1 || *p1 <=
' ')
172 !memcmp(p1 + strlen(p1) - 8,
".desktop", 8))
185 p2 = p1 + strlen(p1);
187 while(p2 > p1 && *(p2 - 1) <=
' ')
192 if(p2 >= p1 + 2 && *(p2 - 2) ==
'%' &&
193 (*(p2 - 1) ==
'u' || *(p2 - 1) ==
'U' || *(p2 - 1) ==
'f' || *(p2 - 1) ==
'F'))
198 while(p2 > p1 && *(p2 - 1) <=
' ')
208 strcpy(szHelpBrowser, p1);
218 WB_ERROR_PRINT(
"%s - \"%s\" - No default browser available!\n", __FUNCTION__, p1);
224 WB_ERROR_PRINT(
"%s - No default browser available!\n", __FUNCTION__);
228 "Context Help",
"No default browser available for displaying help");
238 strncpy(szDocFilePath, p1,
sizeof(szDocFilePath) - 2);
243 strcpy(szDocFilePath,
"doc/html/");
247 if(szDocFilePath[strlen(szDocFilePath) - 1] !=
'/')
249 strcat(szDocFilePath,
"/");
255 p1 = szDocFilePath + strlen(szDocFilePath);
260 strcpy(p1,
"group__*.html");
269 WB_ERROR_PRINT(
"ERROR: %s no dir list \"%s\"\n", __FUNCTION__, szDocFilePath);
282 pTemp = fopen(szDocFilePath,
"r");
285 WB_ERROR_PRINT(
"ERROR: %s - unable to open \"%s\"\n", __FUNCTION__, szDocFilePath);
293 if(!fgets(szLineBuf,
sizeof(szLineBuf), pTemp))
304 if(NULL != (p2 = strstr(szLineBuf,
"class=\"el\"")))
306 while(p2 > szLineBuf && *p2 !=
'<')
311 if(p2 >= szLineBuf && *p2 ==
'<')
321 if(!memcmp(p4 + 1, szTerm, strlen(szTerm)) &&
322 !memcmp(p4 + 1 + strlen(szTerm),
"</a>", 4))
328 for(p2=p3; *p2; p2 += strlen(p2) + 1)
330 if(!strncmp(p2,
"href=", 5))
332 strcpy(szDoxyTag,
"file://");
333 strcat(szDoxyTag, szDocFilePath);
334 strcat(szDoxyTag, p2 + 5);
351 if(strstr(szLineBuf,
"doxytag"))
353 p2 = strstr(szLineBuf, szTerm);
355 if(p2 && p2 > szLineBuf + 10 && *(p2 - 1) ==
':' && *(p2 - 2) ==
':' &&
356 (p2[strlen(szTerm)] ==
'"' || p2[strlen(szTerm)] ==
'\''))
359 while(p2 > szLineBuf && (*p2 !=
'<' || p2[1] !=
'!' || p2[2] !=
'-' || p2[3] !=
'-'))
364 if(*p2 ==
'<' && p2[1] ==
'!' && p2[2] ==
'-' && p2[3] ==
'-')
374 for(p2=p3; *p2; p2 += strlen(p2) + 1)
376 if(!strncmp(p2,
"ref=", 4))
378 strcpy(szDoxyTag,
"file://");
379 strcat(szDoxyTag, szDocFilePath);
380 strcat(szDoxyTag,
"#");
381 strcat(szDoxyTag, p2 + 4);
412 hProcess =
WBRunAsync(szHelpBrowser, szDoxyTag, NULL);
416 if(hProcess != WB_INVALID_FILE_HANDLE)
423 goto fail_to_run_help;
434 p2 =
WBRunResult(
"man",
"-S",
"2:3", szTerm, NULL);
443 fail_to_run_man2html:
446 goto fail_to_run_help;
461 p3 = InternalMan2Html(szTerm, p2);
468 WB_ERROR_PRINT(
"Failed to run InternalMan2Html in %s\n", __FUNCTION__);
469 goto fail_to_run_man2html;
481 goto fail_to_run_man2html;
492 goto fail_to_run_man2html;
497 hProcess =
WBRunAsync(szHelpBrowser, p2, NULL);
506 if(hProcess != WB_INVALID_FILE_HANDLE)
530 static char * CreateNBSPString(
const char *szRef,
int nLen)
532 static const char szNBSP[]=
" ";
536 #define NBSP_TAB_WIDTH 8 543 pRval =
WBAlloc(nLen * 8 * (
sizeof(szNBSP) - 1) + 2);
548 const char *p1 = szRef;
550 for(i1=0, i2=0; i1 < nLen; p1++, i1++, i2 = (i2 + 1) % NBSP_TAB_WIDTH)
554 for(; i2 < NBSP_TAB_WIDTH; i2++)
556 memcpy(p2, szNBSP,
sizeof(szNBSP) - 1);
557 p2 +=
sizeof(szNBSP) - 1;
559 i2 = NBSP_TAB_WIDTH - 1;
563 memcpy(p2, szNBSP,
sizeof(szNBSP) - 1);
564 p2 +=
sizeof(szNBSP) - 1;
585 static char * InternalMan2Html(
const char *szTerm,
const char *szText)
587 char *pRval, *p1, *p2, *pTemp, *pHyphenBuf = NULL;
588 const char *p3, *p4, *p5;
589 int i1, i2, cbLineLen, nTabTwist, bNoHyphen = 0;
590 static const char szNBSP[]=
" ";
593 pRval =
WBCopyString(
"<HTML><HEAD><TITLE>X11workbench Help - man ");
600 WBCatString(&pRval,
"</TITLE></HEAD><BODY><TT>\r\n");
617 while(*p3 && *p3 <=
' ')
619 if(*p3 ==
'\r' || *p3 ==
'\n' || *p3 ==
'\f')
622 pTemp = CreateNBSPString(p4, p3 - p4);
659 nTabTwist = nTabTwist % NBSP_TAB_WIDTH;
663 pTemp = CreateNBSPString(p4, p3 - p4);
682 while(*p3 && *p3 !=
'\r' && *p3 !=
'\n' && *p3 !=
'\f')
689 if(*p3 ==
'\r' && p3[1] ==
'\n')
696 if(!cbLineLen || pHyphenBuf)
704 nTabTwist = (nTabTwist + strlen(pHyphenBuf)) % NBSP_TAB_WIDTH;
725 #define STRSEGCMP(X,Y) strncmp(X,Y,strlen(Y)) 728 (!STRSEGCMP(p4,
"SEE ALSO") ||
729 !STRSEGCMP(p4,
"S\x08""SE\x08""EE\x08""E A\x08""AL\x08""LS\x08""SO\x08""O") ||
730 !STRSEGCMP(p4,
"S\x08""SE\x08""EE\x08""E \x08 A\x08""AL\x08""LS\x08""SO\x08""O")))
737 while(p5 < p3 && *p5 !=
'\x08' && *p5 !=
'<' && *p5 !=
'>')
742 if(p5 >= p3 || !cbLineLen)
768 pTemp =
WBAlloc(i1 * NBSP_TAB_WIDTH * (
sizeof(szNBSP) - 1) + cbLineLen + 4);
777 for(p1=pTemp, p5 = p4, i1 = 0, i2=nTabTwist; i1 < cbLineLen;
778 i1++, p5++, i2 = (i2 + 1) % NBSP_TAB_WIDTH)
782 for(; i2 < NBSP_TAB_WIDTH; i2++)
784 memcpy(p1, szNBSP,
sizeof(szNBSP) - 1);
785 p1 +=
sizeof(szNBSP) - 1;
788 i2 = NBSP_TAB_WIDTH - 1;
808 p2 = pRval + strlen(pRval);
817 while(p2 > pRval && *(p2 - 1) >
' ' && *(p2 - 1) !=
'.' 818 && *(p2 - 1) !=
',' && *(p2 - 1) !=
')' && *(p2 - 1) !=
']' && *(p2 - 1) !=
'}')
828 else if(p2 > pRval + 3 && *(p2 - 3) ==
'\xe2' && *(p2 - 2) ==
'\x80' && *(p2 - 1) ==
'\x90')
836 while(p2 > pRval && *(p2 - 1) >
' ' && *(p2 - 1) !=
'.' 837 && *(p2 - 1) !=
',' && *(p2 - 1) !=
')' && *(p2 - 1) !=
']' && *(p2 - 1) !=
'}')
848 else if(p2 > pRval + 3 && *(p2 - 3) ==
'\xe2' && *(p2 - 2) ==
'\x80' && *(p2 - 1) ==
'\x90')
882 pTemp =
WBAlloc(i1 * NBSP_TAB_WIDTH * (
sizeof(szNBSP) - 1) + cbLineLen * 12 + 4);
891 memcpy(pTemp, p4, cbLineLen);
892 pTemp[cbLineLen] = 0;
913 memmove(p2 + 1, p2, strlen(p2) + 1);
914 memcpy(p2,
"<B>", 3);
919 if(*p2 ==
'<' || *p2 ==
'>')
923 memmove(p2 + 3, p2, strlen(p2) + 1);
927 memcpy(p2,
"<", 4);
931 memcpy(p2,
">", 4);
941 while(*p2 && p2[1] ==
'\x8' && *p2 == p2[2])
943 if(*p2 ==
'<' || *p2 ==
'>')
947 memmove(p2 + 1, p2, strlen(p2) + 1);
951 memcpy(p2,
"<", 4);
955 memcpy(p2,
">", 4);
962 memcpy(p2, p2 + 2, strlen(p2 + 2) + 1);
969 memmove(p2 + 4, p2, strlen(p2) + 1);
970 memcpy(p2,
"</B>", 4);
975 else if(*p2 ==
'_' || p2[2] ==
'_')
979 memmove(p2 + 1, p2, strlen(p2) + 1);
984 memcpy(p2,
"<U>", 3);
989 if(*p2 ==
'<' || *p2 ==
'>')
993 memmove(p2 + 3, p2, strlen(p2) + 1);
997 memcpy(p2,
"<", 4);
1001 memcpy(p2,
">", 4);
1012 while(*p2 && p2[1] ==
'\x8' && (*p2 ==
'_' || p2[2] ==
'_'))
1019 if(*p2 ==
'<' || *p2 ==
'>')
1023 memmove(p2 + 1, p2, strlen(p2) + 1);
1027 memcpy(p2,
"<", 4);
1031 memcpy(p2,
">", 4);
1038 memcpy(p2, p2 + 2, strlen(p2 + 2) + 1);
1045 memmove(p2 + 4, p2, strlen(p2) + 1);
1046 memcpy(p2,
"</U>", 4);
1052 else if(*p2 ==
'<' || *p2 ==
'>')
1054 memmove(p2 + 3, p2, strlen(p2) + 1);
1058 memcpy(p2,
"<", 4);
1062 memcpy(p2,
">", 4);
1072 p2 += (
sizeof(szNBSP) - 1) * (NBSP_TAB_WIDTH - i2);
1076 memmove(p2, p1 + 1, strlen(p1 + 1) + 1);
1083 for(; i2 < NBSP_TAB_WIDTH; i2++)
1085 memcpy(p1, szNBSP,
sizeof(szNBSP) - 1);
1086 p1 +=
sizeof(szNBSP) - 1;
1094 i2 = (i2 + 1) % NBSP_TAB_WIDTH;
1101 p2 = pTemp + strlen(pTemp);
1105 if(*pTemp && *(p2 - 1) ==
'-')
1110 while(p2 > pTemp && *(p2 - 1) >
' ' && *(p2 - 1) !=
'.' 1111 && *(p2 - 1) !=
',' && *(p2 - 1) !=
')' && *(p2 - 1) !=
']' && *(p2 - 1) !=
'}')
1121 else if(p2 > pTemp + 3 && *(p2 - 3) ==
'\xe2' && *(p2 - 2) ==
'\x80' && *(p2 - 1) ==
'\x90')
1129 while(p2 > pTemp && *(p2 - 1) >
' ' && *(p2 - 1) !=
'.' 1130 && *(p2 - 1) !=
',' && *(p2 - 1) !=
')' && *(p2 - 1) !=
']' && *(p2 - 1) !=
'}')
1141 else if(p2 > pTemp + 3 && *(p2 - 3) ==
'\xe2' && *(p2 - 2) ==
'\x80' && *(p2 - 1) ==
'\x90')
1153 strcat(pTemp,
"<br>\r\n");
1167 WBCatString(&pRval,
"<br>\r\n<hr size=2>\r\n<p align=\"center\">Generated internally by X11workbench</p>\r\n" 1168 "</TT></BODY></HTML>\r\n");
char * CHGetMimeDefaultApp(const char *szMimeType)
Get the default application for a particular MIME type.
void WBCatStringN(char **ppDest, const char *pSrc, unsigned int nMaxChars)
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string up t...
char * WBRunResult(const char *szAppName,...)
Run an application synchronously, returning 'stdout' output in a character buffer.
void * WBAllocDirectoryList(const char *szDirSpec)
Allocate a 'Directory List' object for a specified directory spec.
const char * CHFindEndOfXMLTag(const char *pTagContents, int cbLength)
Parses contents of an XML tag to find the end of it.
void * CHOpenConfFile(const char *szAppName, int iFlags)
open configuration file for read/write, optionally creating it, based on application name
int CHGetConfFileString(void *hFile, const char *szSection, const char *szIdentifier, char *szData, int cbData)
obtain a string from a configuration file
'configuration helper' main header file for the X11 Work Bench Toolkit API
Icon - white 'middle finger' on red triangle.
void CHCloseConfFile(void *pFile)
close configuration file opened by CHOpenConfFile(), but does NOT free memory resources
void * WBAlloc(int nSize)
High performance memory sub-allocator 'allocate'.
WB_PROCESS_ID WBRunAsync(const char *szAppName,...)
Run an application asynchronously.
#define WB_ERROR_PRINT(...)
Preferred method of implementing an 'error level' debug message for all subsystems.
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
int WBNextDirectoryEntry(void *pDirectoryList, char *szNameReturn, int cbNameReturn, unsigned long *pdwModeAttrReturn)
Obtain information about the next entry in a 'Directory List'.
static __inline__ int FBWriteFileFromBuffer(const char *szFileName, const char *pBuf, unsigned int cbBuf)
Write a file from a regular buffer using a file name.
char * WBGetCanonicalPath(const char *szFileName)
Return the canonical path for a file name (similar to POSIX 'realpath()' funtion)
char * WBCopyString(const char *pSrc)
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string.
char * CHGetDesktopFileInfo(const char *szDesktopFile, const char *szInfo)
Get the default application for a particular MIME type.
int DLGMessageBox(int iType, Window wIDOwner, const char *szTitle, const char *szMessage)
Display a modal 'message box' dialog window with a specific title, message, and button combination.
char * CHParseXMLTagContents(const char *pTagContents, int cbLength)
Parses contents of a single XML tag, returning as WBAlloc'd string list similar to environment string...
void WBCatString(char **ppDest, const char *pSrc)
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string.