AcePerl

 view release on metacpan or  search on metacpan

acelib/helpsubs.c  view on Meta::CPAN


	      sprintf(filename, "%s%s%s", 
		      filGetFullPath(helpGetDir()),
		      SUBDIR_DELIMITER_STR, subject_copy);
	      break;
	    }

	  filDirectoryDestroy (dirList);

	} /* endif dirList */

      /* file didn't exist, whichever way we tried so far,
	 so we try to chop off the last bit of the subject name.
	 In case trySubject was "Tree_Clone_Inside", we now
	 go through the look again with "Tree_Clone" and re-try. */

      if (strchr (subject_copy, '_'))
	{
	  int j;

	  j = strlen (subject_copy);
	  while (subject_copy[j--] != '_') ; /* find the last _ char */
	  subject_copy[j + 1] = '\0';
	}
      else
	{
	  /* If we run out of trailing components, then we exit
	   * anyway.
	   */
	  strcpy (filename, "");
	  break;		/* exit while(true)loop */
	}
    } /* end-while(true) */

  messfree (subject_copy);


  if (strcmp(filename, "") != 0)
    return filename;		/* success */

  if ((strcasecmp(subject, "index") == 0) ||
      (strcasecmp(subject, "home") == 0) ||
      (strcasecmp(subject, "toc") == 0))
    {
      /* we asked for some kind of index-page but couldn't find it,
	 so we can always try to return the question mark '?'
	 which will ask the calling function to display a
	 dynamically created index of help-subjects. */

      strcpy (filename, "?");
      return filename;
    }


  return NULL;			/* failure - no file found */
} /* helpSubjectGetFilename */


/************************************************************/
/* helpPackage utility to find out the filename of a given
   link reference. Absolute filenames are returned unchanged,
   but relative filenames are expanded to be the full path
   of the helpfile. Can be used for html/gif files referred to
   by the HREF of anchor tags or the SRC or IMG tags */

/* NOTE: the pointer returned is a static copy, which is
   re-used everytime it is called. If the calling function
   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)))



( run in 1.029 second using v1.01-cache-2.11-cpan-ceb78f64989 )