AcePerl
view release on metacpan or search on metacpan
acelib/helpsubs.c view on Meta::CPAN
wants to mess about with the returned string, a copy
has to be made.
NULL is returned if the resulting file can't be opened.
the calling function can inspect the result of
messSysErrorText(), the report the resaon for failure */
/************************************************************/
UTIL_FUNC_DEF char *helpLinkGetFilename (char *link)
{
static char link_path_array[MAXPATHLEN] = "";
char *link_path = &link_path_array[0];
if (link[0] == SUBDIR_DELIMITER) /* absolute path (UNIX) */
{
strcpy (link_path, link);
}
else /* relative path */
{
strcpy (link_path, helpGetDir());
strcat (link_path, SUBDIR_DELIMITER_STR);
strcat (link_path, link);
}
if (filName(link_path, "", "r"))
return link_path;
return NULL;
} /* helpLinkGetFilename */
/************************************************************/
/****************** ***********************/
/************** private helpPackage functions ***************/
/****************** ***********************/
/************************************************************/
HtmlPage *htmlPageCreate (char *helpFilename)
/* complemeted by htmlPageDestroy */
{
FILE *fil;
HtmlPage *page = 0;
if (!helpFilename) /* we could get a NULL filename */
return 0; /* here, which might come from
helpSubjectGetFilename() that couldn't
find a file matching the subject */
/* create a page with a marked up directory listing */
if (strcmp(helpFilename, "?") == 0)
{
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
page->htmlText = makeHtmlIndex(page->handle);
if (!(page->root = parseHtmlText(page->htmlText, page->handle)))
htmlPageDestroy(page);
return page;
}
if (!(filName(helpFilename, "", "r")))
return 0; /* prevent error caused
by unsucsessful filopen */
/* create a page inlining the image */
if (strcasecmp (helpFilename + (strlen(helpFilename)-4), ".gif") == 0)
{
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
page->htmlText = makeHtmlImagePage(helpFilename, page->handle);
if (!(page->root = parseHtmlText(page->htmlText, page->handle)))
htmlPageDestroy(page);
return page;
}
/* assume HTML page */
if ((fil = filopen(helpFilename, "", "r")))
{
page = htmlPageCreateFromFile (fil);
filclose (fil);
}
return page;
} /* htmlPageCreate */
/************************************************************/
HtmlPage *htmlPageCreateFromFile (FILE *fil)
{
HtmlPage *page;
int fileSize;
if (!fil)
return (HtmlPage*)0;
/* determine filesize */
rewind (fil);
fseek (fil, 0, SEEK_END);
fileSize = ftell (fil);
rewind (fil);
if (fileSize == 0)
return (HtmlPage*)0;
/* if we have a positive fileSize, we are pretty much
guaranteed, that we'll get some HTML text and a parsetree */
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
/* grab the contents of the file */
page->htmlText = halloc ((fileSize + 1) * sizeof(char), page->handle);
fread (page->htmlText, sizeof (char), fileSize, fil);
page->htmlText[fileSize] = '\0'; /* add string terminator */
/* get parsetree */
page->root = parseHtmlText(page->htmlText, page->handle);
return page;
( run in 2.098 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )