home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lynx2.8.1dev.10.tar.gz / lynx2.8.1dev.10.tar / lynx2-8 / src / HTML.h < prev    next >
C/C++ Source or Header  |  1998-03-25  |  9KB  |  282 lines

  1. /*                    HTML to rich text converter for libwww
  2. **
  3. **            THE HTML TO RTF OBJECT CONVERTER
  4. **
  5. **  This interprets the HTML semantics.
  6. */
  7. #ifndef HTML_H
  8. #define HTML_H
  9.  
  10. #ifndef HTUTILS_H
  11. #include <HTUtils.h>
  12. #endif /* HTUTILS_H */
  13. #include <UCDefs.h>
  14. #include <UCAux.h>
  15. #include <HTAnchor.h>
  16. #include <HTMLDTD.h>
  17.  
  18. #ifdef SHORT_NAMES
  19. #define HTMLPresentation        HTMLPren
  20. #define HTMLPresent             HTMLPres
  21. #endif /* SHORT_NAMES */
  22.  
  23. /* #define ATTR_CS_IN (me->T.output_utf8 ? me->UCLYhndl : 0) */
  24. #define ATTR_CS_IN me->tag_charset
  25.  
  26. #define TRANSLATE_AND_UNESCAPE_ENTITIES(s, p, h) \
  27.     LYUCFullyTranslateString(s, ATTR_CS_IN, current_char_set, YES, p, h, st_HTML)
  28.  
  29. #define TRANSLATE_AND_UNESCAPE_ENTITIES5(s,cs_from,cs_to,p,h) \
  30.     LYUCFullyTranslateString(s, cs_from, cs_to, YES, p, h, st_HTML)
  31.  
  32. #define TRANSLATE_AND_UNESCAPE_ENTITIES6(s,cs_from,cs_to,spcls,p,h) \
  33.     LYUCFullyTranslateString(s, cs_from, cs_to, spcls, p, h, st_HTML)
  34.  
  35. /*
  36.  *  Strings from attributes which should be converted to some kind
  37.  *  of "standard" representation (character encoding), was Latin-1,
  38.  *  esp. URLs (incl. #fragments) and HTML NAME and ID stuff.
  39.  */
  40. #define TRANSLATE_AND_UNESCAPE_TO_STD(s) \
  41.     LYUCFullyTranslateString(s, ATTR_CS_IN, ATTR_CS_IN, NO, NO, YES, st_URL)
  42. #define UNESCAPE_FIELDNAME_TO_STD(s) \
  43.     LYUCFullyTranslateString(s, ATTR_CS_IN, ATTR_CS_IN, NO, NO, YES, st_HTML)
  44.  
  45. extern CONST HTStructuredClass HTMLPresentation;
  46.  
  47. #ifdef Lynx_HTML_Handler
  48. /*
  49. **    This section is semi-private to HTML.c and it's helper modules. - FM
  50. **    --------------------------------------------------------------------
  51. */
  52.  
  53. typedef struct _stack_element {
  54.     HTStyle *    style;
  55.     int        tag_number;
  56. } stack_element;
  57.  
  58. /*        HTML Object
  59. **        -----------
  60. */
  61. #define MAX_NESTING 800        /* Should be checked by parser */
  62.  
  63. struct _HTStructured {
  64.     CONST HTStructuredClass *     isa;
  65.     HTParentAnchor *         node_anchor;
  66.     HText *             text;
  67.  
  68.     HTStream*            target;            /* Output stream */
  69.     HTStreamClass        targetClass;        /* Output routines */
  70.  
  71.     HTChildAnchor *        CurrentA;    /* current HTML_A anchor */
  72.     int                CurrentANum;    /* current HTML_A number */
  73.     char *            base_href;    /* current HTML_BASE href */
  74.     char *            map_address;    /* current HTML_MAP address */
  75.  
  76.     HTChunk             title;        /* Grow by 128 */
  77.     HTChunk            object;        /* Grow by 128 */
  78.     BOOL            object_started;
  79.     BOOL            object_declare;
  80.     BOOL            object_shapes;
  81.     BOOL            object_ismap;
  82.     char *            object_usemap;
  83.     char *            object_id;
  84.     char *            object_title;
  85.     char *            object_data;
  86.     char *            object_type;
  87.     char *            object_classid;
  88.     char *            object_codebase;
  89.     char *            object_codetype;
  90.     char *            object_name;
  91.     HTChunk            option;        /* Grow by 128 */
  92.     BOOL            first_option;    /* First OPTION in SELECT? */
  93.     char *            LastOptionValue;
  94.     BOOL            LastOptionChecked;
  95.     BOOL            select_disabled;
  96.     HTChunk            textarea;    /* Grow by 128 */
  97.     char *            textarea_name;
  98.     int                textarea_name_cs;
  99.     char *            textarea_accept_cs;
  100.     char *            textarea_cols;
  101.     int             textarea_rows;
  102.     int                textarea_disabled;
  103.     char *            textarea_id;
  104.     HTChunk            math;        /* Grow by 128 */
  105.     HTChunk            style_block;    /* Grow by 128 */
  106.     HTChunk            script;        /* Grow by 128 */
  107.  
  108.     /*
  109.      *  Used for nested lists. - FM
  110.      */
  111.     int        List_Nesting_Level;    /* counter for list nesting level */
  112.     int     OL_Counter[12];        /* counter for ordered lists */
  113.     char     OL_Type[12];        /* types for ordered lists */
  114.     int     Last_OL_Count;        /* last count in ordered lists */
  115.     char     Last_OL_Type;        /* last type in ordered lists */
  116.  
  117.     int                Division_Level;
  118.     short            DivisionAlignments[MAX_NESTING];
  119.     int                Underline_Level;
  120.     int                Quote_Level;
  121.  
  122.     BOOL            UsePlainSpace;
  123.     BOOL            HiddenValue;
  124.     int                lastraw;
  125.  
  126.     char *            comment_start;    /* for literate programming */
  127.     char *            comment_end;
  128.  
  129.     HTTag *            current_tag;
  130.     BOOL            style_change;
  131.     HTStyle *            new_style;
  132.     HTStyle *            old_style;
  133.     int                current_default_alignment;
  134.     BOOL            in_word;  /* Have just had a non-white char */
  135.     stack_element     stack[MAX_NESTING];
  136.     stack_element     *sp;        /* Style stack pointer */
  137.     BOOL        stack_overrun;    /* Was MAX_NESTING exceeded? */
  138.     int            skip_stack; /* flag to skip next style stack operation */
  139.  
  140.     /*
  141.     **  Track if we are in an anchor, paragraph, address, base, etc.
  142.     */
  143.     BOOL        inA;
  144.     BOOL        inAPPLET;
  145.     BOOL        inAPPLETwithP;
  146.     BOOL        inBadBASE;
  147.     BOOL        inBadHREF;
  148.     BOOL        inBadHTML;
  149.     BOOL        inBASE;
  150.     BOOL        inBoldA;
  151.     BOOL        inBoldH;
  152.     BOOL        inCAPTION;
  153.     BOOL        inCREDIT;
  154.     BOOL        inFIG;
  155.     BOOL        inFIGwithP;
  156.     BOOL        inFONT;
  157.     BOOL        inFORM;
  158.     BOOL        inLABEL;
  159.     BOOL        inP;
  160.     BOOL        inPRE;
  161.     BOOL        inSELECT;
  162.     BOOL        inTABLE;
  163.     BOOL        inTEXTAREA;
  164.     BOOL        inUnderline;
  165.  
  166.     BOOL        needBoldH;
  167.  
  168.     /*
  169.     **  UCI and UCLYhndl give the UCInfo and charset registered for
  170.     **  the HTML parser in the node_anchor's UCStages structure.  It
  171.     **  indicates what is fed to the HTML parser as the stream of character
  172.     **  data (not necessarily tags and attributes).  It should currently
  173.     **  always be set to be the same as UCI and UCLhndl for the HTEXT stage
  174.     **  in the node_anchor's UCStages structure, since the HTML parser sends
  175.     **  its input character data to the output without further charset
  176.     **  translation.
  177.     */
  178.     LYUCcharset    *    UCI;
  179.     int            UCLYhndl;
  180.     /*
  181.     **  inUCI and inUCLYhndl indicate the UCInfo and charset which the
  182.     **  HTML parser treats at the input charset.  It is normally set
  183.     **  to the UCI and UCLhndl for the SGML parser in the node_anchor's
  184.     **  UCStages structure (which may be a dummy, based on the MIME
  185.     **  parser's UCI and UCLhndl in that structure, when we are handling
  186.     **  a local file or non-http(s) gateway).  It could be changed
  187.     **  temporarily by the HTML parser, for conversions of attribute
  188.     **  strings, but should be reset once done. - FM
  189.     */
  190.     LYUCcharset    *    inUCI;
  191.     int            inUCLYhndl;
  192.     /*
  193.     **  outUCI and outUCLYhndl indicate the UCInfo and charset which
  194.     **  the HTML parser treats as the output charset.  It is normally
  195.     **  set to its own UCI and UCLhndl.  It could be changed for
  196.     **  conversions of attribute strings, but should be reset once
  197.     **  done. - FM
  198.     */
  199.     LYUCcharset    *    outUCI;
  200.     int            outUCLYhndl;
  201.     /*
  202.     **  T holds the transformation rules for conversions of strings
  203.     **  between the input and output charsets by the HTML parser. - FM
  204.     */
  205.     UCTransParams    T;
  206.  
  207.     int         tag_charset; /* charset for attribute values etc. */
  208. };
  209.  
  210. extern  HTStyle *styles[HTML_ELEMENTS+31]; /* adding 24 nested list styles  */
  211.                        /* and 3 header alignment styles */
  212.                        /* and 3 div alignment styles    */
  213.  
  214. /*
  215.  *    Semi-Private functions. - FM
  216.  */
  217. extern void HTML_put_character PARAMS((HTStructured *me, char c));
  218. extern void HTML_put_string PARAMS((HTStructured *me, CONST char *s));
  219. extern void HTML_write PARAMS((HTStructured *me, CONST char *s, int l));
  220. extern int HTML_put_entity PARAMS((HTStructured *me, int entity_number));
  221. extern void actually_set_style PARAMS((HTStructured * me));
  222.  
  223. /*    Style buffering avoids dummy paragraph begin/ends.
  224. */
  225. #define UPDATE_STYLE if (me->style_change) { actually_set_style(me); }
  226. #endif /* Lynx_HTML_Handler */
  227.  
  228. extern void strtolower PARAMS((char* i));
  229.  
  230. /*                P U B L I C
  231. */
  232.  
  233. /*
  234. **  HTConverter to present HTML
  235. */
  236. extern HTStream* HTMLToPlain PARAMS((
  237.     HTPresentation *    pres,
  238.     HTParentAnchor *    anchor,
  239.     HTStream *        sink));
  240.  
  241. extern HTStream* HTMLParsedPresent PARAMS((
  242.     HTPresentation *    pres,
  243.     HTParentAnchor *    anchor,
  244.     HTStream *        sink));
  245.  
  246. extern HTStream* HTMLToC PARAMS((
  247.     HTPresentation *    pres,
  248.     HTParentAnchor *    anchor,
  249.     HTStream *        sink));
  250.  
  251. extern HTStream* HTMLPresent PARAMS((
  252.     HTPresentation *    pres,
  253.     HTParentAnchor *    anchor,
  254.     HTStream *        sink));
  255.  
  256. extern HTStructured* HTML_new PARAMS((
  257.     HTParentAnchor * anchor,
  258.     HTFormat    format_out,
  259.     HTStream *    target));
  260.  
  261. /*
  262. **  Record error message as a hypertext object.
  263. **
  264. **  The error message should be marked as an error so that it can be
  265. **  reloaded later.  This implementation just throws up an error message
  266. **  and leaves the document unloaded.
  267. **
  268. **  On entry,
  269. **      sink    is a stream to the output device if any
  270. **      number  is the HTTP error number
  271. **      message is the human readable message.
  272. **  On exit,
  273. **      a retrun code like HT_LOADED if object exists else 60; 0
  274. */
  275. extern int HTLoadError PARAMS((
  276.     HTStream *    sink,
  277.     int        number,
  278.     CONST char *    message));
  279.  
  280. #endif /* HTML_H */
  281.  
  282.