home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libnet / htmparse.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  156 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*** htmparse.h ***************************************************/
  19. /*   description:    html parser                                      */ 
  20.  
  21.  
  22.  /********************************************************************
  23.  
  24.    The client calls CRAWL_ParserPut, and gets called back with
  25.    a function whose prototype is described by CRAWL_ParseFunc. The
  26.    parser calls this function whenever a begin or end tag, or run of
  27.    character data has been scanned, and does not build a tree.
  28.  
  29.   $Revision: 3.1 $
  30.   $Date: 1998/03/28 03:31:31 $
  31.  
  32.  *********************************************************************/
  33.  
  34.  
  35. #ifndef htmparse_h___
  36. #define htmparse_h___
  37. #include "prtypes.h"
  38.  
  39. /* return values from CRAWL_ParserPut */
  40. #define CRAWL_PARSE_NO_ERROR 0            /* no error */
  41. #define CRAWL_PARSE_ERROR 1            /* syntax error */
  42. #define CRAWL_PARSE_TERMINATE 2        /* don't continue to parse */
  43. #define CRAWL_PARSE_OUT_OF_MEMORY 3    /* out of memory */
  44.  
  45. /* return values for CRAWL_ParseFunc callback function */
  46. #define PARSE_GET_NEXT_TOKEN 0
  47. #define PARSE_STOP 1
  48. #define PARSE_OUT_OF_MEMORY 2
  49.  
  50. typedef struct _CRAWL_TagStruc *CRAWL_Tag;
  51.  
  52. /* 
  53.     The client of this API creates a reference to this with CRAWL_MakeParseObj and provides it as
  54.     a parameter to CRAWL_ParserPut. It is passed as a parameter to the CRAWL_ParseFunc function and
  55.     the parsed data may be extracted from it through the API. It should be considered opaque data.
  56. */
  57. typedef struct _CRAWL_ParseObjStruc *CRAWL_ParseObj;
  58.  
  59. /*
  60.     Typedef for a parse callback. The memory in CRAWL_ParseObj is reused across successive calls.
  61. */
  62. typedef int
  63. (PR_CALLBACK *CRAWL_ParseFunc)(CRAWL_ParseObj obj, PRBool isTag, void *data);
  64.  
  65. /****************************************************************************************/
  66. /* public API                                                                            */
  67. /****************************************************************************************/
  68.  
  69. NSPR_BEGIN_EXTERN_C
  70.  
  71.  /* 
  72.     Returns the tag parsed 
  73.  */
  74. PR_EXTERN(CRAWL_Tag) 
  75. CRAWL_GetTagParsed(CRAWL_ParseObj obj);
  76.  
  77. /* 
  78.     Returns the character data between tags 
  79. */
  80. PR_EXTERN(char*) 
  81. CRAWL_GetDataParsed(CRAWL_ParseObj obj);
  82.  
  83. /* 
  84.     Returns the tag name 
  85. */
  86. PR_EXTERN(char*) 
  87. CRAWL_GetTagName(CRAWL_Tag tag);
  88.  
  89. /* 
  90.     Returns the libparse tag code as defined in pa_tags.h 
  91. */
  92. PR_EXTERN(intn) 
  93. CRAWL_GetTagToken(CRAWL_Tag tag);
  94.  
  95. /* 
  96.     a tag of the form <tagname /> Empty tags are recognized only if the page has been designated as
  97.     containing RDF (the API doesn't support this yet)
  98. */
  99. PR_EXTERN(PRBool) 
  100. CRAWL_IsEmptyTag(CRAWL_Tag tag);
  101.  
  102. /* 
  103.     A tag of the form </tagname>. 
  104. */
  105. PR_EXTERN(PRBool) 
  106. CRAWL_IsEndTag(CRAWL_Tag tag);
  107.  
  108. /*
  109.     Returns the tag attribute given a name
  110. */
  111. PR_EXTERN(char*) 
  112. CRAWL_GetAttributeValue(CRAWL_Tag tag, char *attributeName);
  113.  
  114. /*
  115.     Returns the number of attributes for the tag.
  116. */
  117. PR_EXTERN(uint16) 
  118. CRAWL_GetNumberOfAttributes(CRAWL_Tag tag);
  119.  
  120. /*
  121.     Returns the nth attribute of the tag.
  122. */
  123. PR_EXTERN(char*) 
  124. CRAWL_GetNthAttributeName(CRAWL_Tag tag, uint16 n);
  125.  
  126. /*
  127.     Returns the nth attribute value of the tag.
  128. */
  129. PR_EXTERN(char*) 
  130. CRAWL_GetNthAttributeValue(CRAWL_Tag tag, uint16 n);
  131.  
  132. /*
  133.     Creates a new CRAWL_ParseObj suitable for passing to CRAWL_ParserPut.
  134.     Returns NULL if out of memory.
  135. */
  136. PR_EXTERN(CRAWL_ParseObj) 
  137. CRAWL_MakeParseObj();
  138.  
  139. /*
  140.     Destroys the CRAWL_ParseObj and all associated memory
  141. */
  142. PR_EXTERN(void) 
  143. CRAWL_DestroyParseObj(CRAWL_ParseObj obj);
  144.  
  145. /* 
  146.     Parse characters in buffer and call func when an element (tag or data) has been
  147.     scanned. Returns an error code. The same CRAWL_ParseObj must be provided for successive
  148.     puts in the same buffer. It is up to the caller to create and destroy the CRAWL_ParseObj.
  149. */
  150. PR_EXTERN(int) 
  151. CRAWL_ParserPut(CRAWL_ParseObj obj, char *str, uint32 len, CRAWL_ParseFunc func, void *data);
  152.  
  153. NSPR_END_EXTERN_C
  154.  
  155. #endif /* htmparse_h___ */
  156.