AcePerl

 view release on metacpan or  search on metacpan

acelib/helpsubs.c  view on Meta::CPAN


  /* the length of everything between the 
     end of <IMG and the end of the args or the next > */
  len = (*cp-start) - numspaces ;

  if (**cp)
    *cp += 1 ;			/* skip '>' */

  /* now find the SRC= argument */

  s = start ;
  while (*s)
    {
      if (strncasecmp (s, "src=", 4) == 0)
	{
	  HAVE_SRC = TRUE ;
	  break ;
	}
      ++s ;
    }
  if (HAVE_SRC)
    {
      s += 4 ;			/* skip 'src=' */
      len -= 4;

      start = s ;
      srclen = 0 ;

      if (s[0] == '"')	/* if src in quotes then link ends with quote */
	{
	  s++ ; start++ ;
	  while (*s && ++srclen < len && *s != '"')
	    { ++(s) ; }
	  --srclen;		/* discard the quote */
	}
      else
	{ 
	  while (*s && ++srclen < len && !isspace((int)*s))
	    { ++(s) ; }
	}

      node = makeNode (HTML_GIFIMAGE, handle) ;

      /* save the file name of the image */
      node->link = (char*)halloc((srclen+1) * sizeof(char), handle);

      strncpy (node->link, start, srclen) ;
      node->link[srclen] = 0 ;
    }
  else
    {
      node = makeNode (HTML_UNKNOWN, handle) ;
    }

  *resultnode = node ;

  return TRUE ;
} /* parseImage */
/************************************************************/

static BOOL parseListItem (HtmlListType   style,
			   char		**cp, 
			   HtmlNode     **resultnode,
			   STORE_HANDLE   handle)
{
  HtmlNode *node, *leftnode, *rightnode ;
  int lstyle = style ;

  skipSpaces (cp) ;

  /* check, whether the next tag is a valid listitem tag */
  
  /* with <DL> list <LI> and <DD> items are allowed */
  if (lstyle == HTML_LIST_NOINDENT &&
      !(strncasecmp (*cp, "<dd>", 4) == 0 ||
	strncasecmp (*cp, "<li>", 4) == 0 ||
	strncasecmp (*cp, "<dt>", 4) == 0))
    {
      *resultnode = 0 ;
      return FALSE ;
    }
  /* only <LI> items in <UL> or <OL> lists */
  else if ((lstyle == HTML_LIST_BULLET || lstyle == HTML_LIST_NUMBER) &&
	   !(strncasecmp (*cp, "<li>", 4) == 0))
    {
      *resultnode = 0 ;
      return FALSE ;
    }

  if (lstyle == HTML_LIST_NOINDENT)
    {
      /* in <DL> list a <DD> item becomes indented but no bullet */
      if (strncasecmp (*cp, "<dd>", 4) == 0)
	lstyle = HTML_LIST_NOBULLET ;
      else if (strncasecmp (*cp, "<dt>", 4) == 0)
	lstyle = HTML_LIST_NOINDENT_NOBULLET ;
    }
  *cp += 4 ;
  /* now cp stands right after an <LI> and parses the following
     as a normal section */
  
  parseSection (cp, &leftnode, handle) ;
  
  node = makeNode (HTML_LISTITEM, handle) ;
  
  node->left = leftnode ;
  node->lstyle = lstyle ;

  if (parseListItem (style, cp, &rightnode, handle))
    {
      node->right = rightnode ;
    }
  else
    {
      node->right = 0 ;		/* no further list items */
    }

  *resultnode = node ;

  return TRUE ;
} /* parseListItem */
/************************************************************/

static BOOL parseList (int style, char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
  HtmlNode *node, *leftnode ;

  *cp += 4 ;			/* skip <UL> */

#ifdef ALLOW_SECONDLEVEL_LIST_LIST_DOESN_T_YET_WORK
  if (strncasecmp (*cp, "<ul>", 4) == 0 ||
      strncasecmp (*cp, "<ol>", 4) == 0 ||
      strncasecmp (*cp, "<dl>", 4) == 0)
    {
      /* create list item for this list-in-list */
      node = makeNode (HTML_LISTITEM, handle) ;
      
      node->left = leftnode ;
      node->lstyle = lstyle ;

    }
#endif

  parseListItem (style, cp, &leftnode, handle);
  
  skipSpaces (cp) ;
  
  if ((style == HTML_LIST_BULLET && strncasecmp (*cp, "</ul>", 5) == 0) ||
      (style == HTML_LIST_NOINDENT && strncasecmp (*cp, "</dl>", 5) == 0) ||
      (style == HTML_LIST_NUMBER && strncasecmp (*cp, "</ol>", 5) == 0))
    {
      *cp += 5 ;		/* skip </ul> */
    }
  else
    {
      if (style == HTML_LIST_BULLET)
	printf ("Warning : found <UL> without closing </UL> tag !!\n") ;
      else if (style == HTML_LIST_NOINDENT)
	printf ("Warning : found <DL> without closing </DL> tag !!\n") ;
      else if (style == HTML_LIST_NUMBER)
	printf ("Warning : found <OL> without closing </OL> tag !!\n") ;
    }

  node = makeNode (HTML_LIST, handle) ;

  node->left = leftnode ;
  node->lstyle = style ;

  *resultnode = node ;

  return TRUE ;
} /* parseList */
/************************************************************/

static BOOL parseSection (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
  HtmlNode *node, *leftnode, *rightnode ;
  static BOOL MODE_PREFORMAT=FALSE, MODE_BLOCKQUOTE=FALSE ;

  if (!MODE_PREFORMAT)
    skipSpaces (cp) ;

  if (!**cp)			/* EOF */
    {
      if (MODE_PREFORMAT)
	printf ("Warning : found <PRE> tag "
		"without closing </PRE> tag !!\n") ;
      if (MODE_BLOCKQUOTE)
	printf ("Warning : found <BLOCKQUOTE> tag "
		"without closing </BLOCKQUOTE> tag !!\n") ;

      *resultnode = 0 ;
      return TRUE ;
    }

  if (strncasecmp (*cp, "<!--", 4) == 0)
    {
      if (!parseComment (cp, &leftnode, handle))
	{
	  *resultnode = 0 ;
	  return FALSE ;
	}
    }
  else if (strncasecmp (*cp, "<html>", 6) == 0)
    {
      if (!(parseHtml (cp, &leftnode, handle)))
	{
	  *resultnode = 0 ;
	  return FALSE ;
	}
    }
  else if (strncasecmp (*cp, "</html>", 7) == 0)
    {
      *resultnode = 0 ;
      return TRUE ;
    }
  else if (strncasecmp (*cp, "<head>", 6) == 0)
    {
      if (!(parseHead (cp, &leftnode, handle)))
	{
	  *resultnode = 0 ;
	  return FALSE ;
	}
    }
  else if (strncasecmp (*cp, "</head>", 7) == 0)
    {
      *resultnode = 0 ;



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