home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / HTMLformat.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  130.9 KB  |  6,278 lines

  1. // MDF - PORT FROM NCSA VERSION 2.1
  2.  
  3. /****************************************************************************
  4.  * NCSA Mosaic for the X Window System                                      *
  5.  * Software Development Group                                               *
  6.  * National Center for Supercomputing Applications                          *
  7.  * University of Illinois at Urbana-Champaign                               *
  8.  * 605 E. Springfield, Champaign IL 61820                                   *
  9.  * mosaic@ncsa.uiuc.edu                                                     *
  10.  *                                                                          *
  11.  * Copyright (C) 1993, Board of Trustees of the University of Illinois      *
  12.  *                                                                          *
  13.  * NCSA Mosaic software, both binary and source (hereafter, Software) is    *
  14.  * copyrighted by The Board of Trustees of the University of Illinois       *
  15.  * (UI), and ownership remains with the UI.                                 *
  16.  *                                                                          *
  17.  * The UI grants you (hereafter, Licensee) a license to use the Software    *
  18.  * for academic, research and internal business purposes only, without a    *
  19.  * fee.  Licensee may distribute the binary and source code (if released)   *
  20.  * to third parties provided that the copyright notice and this statement   *
  21.  * appears on all copies and that no charge is associated with such         *
  22.  * copies.                                                                  *
  23.  *                                                                          *
  24.  * Licensee may make derivative works.  However, if Licensee distributes    *
  25.  * any derivative work based on or derived from the Software, then          *
  26.  * Licensee will (1) notify NCSA regarding its distribution of the          *
  27.  * derivative work, and (2) clearly notify users that such derivative       *
  28.  * work is a modified version and not the original NCSA Mosaic              *
  29.  * distributed by the UI.                                                   *
  30.  *                                                                          *
  31.  * Any Licensee wishing to make commercial use of the Software should       *
  32.  * contact the UI, c/o NCSA, to negotiate an appropriate license for such   *
  33.  * commercial use.  Commercial use includes (1) integration of all or       *
  34.  * part of the source code into a product for sale or license by or on      *
  35.  * behalf of Licensee to third parties, or (2) distribution of the binary   *
  36.  * code or source code to third parties that need it to utilize a           *
  37.  * commercial product sold or licensed by or on behalf of Licensee.         *
  38.  *                                                                          *
  39.  * UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR   *
  40.  * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED          *
  41.  * WARRANTY.  THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE    *
  42.  * USERS OF THIS SOFTWARE.                                                  *
  43.  *                                                                          *
  44.  * By using or copying this Software, Licensee agrees to abide by the       *
  45.  * copyright law and all other applicable laws of the U.S. including, but   *
  46.  * not limited to, export control laws, and the terms of this license.      *
  47.  * UI shall have the right to terminate this license immediately by         *
  48.  * written notice upon Licensee's breach of, or non-compliance with, any    *
  49.  * of its terms.  Licensee may be held legally responsible for any          *
  50.  * copyright infringement that is caused or encouraged by Licensee's        *
  51.  * failure to abide by the terms of this license.                           *
  52.  *                                                                          *
  53.  * Comments and questions are welcome and can be sent to                    *
  54.  * mosaic-x@ncsa.uiuc.edu.                                                  *
  55.  ****************************************************************************/
  56.  
  57. #ifdef _AMIGA
  58. #include <exec/types.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61. #include <intuition/intuitionbase.h>
  62. #include <clib/graphics_protos.h>
  63. #include <graphics/gfxmacros.h>
  64. #include "includes.h"
  65. #include "HTML.h"
  66. #include "mosaic.h"
  67. #include "protos.h"
  68. #include "XtoI.h"
  69. extern struct Library *GfxBase;
  70. extern AppData Rdata;
  71. #endif /* _AMIGA */
  72.  
  73. #ifdef TIMING
  74. #include <sys/time.h>
  75. struct timeval Tv;
  76. struct timezone Tz;
  77. #endif
  78.  
  79. #include <stdio.h>
  80. #include <ctype.h>
  81. /* This stuff can only be called by the widget itself! */
  82. #include "HTMLP.h"
  83.  
  84.  
  85. /*
  86.  * I need my own is ispunct function because I need a closing paren
  87.  * immediately after a word to act like punctuation.
  88.  */
  89. #define    MY_ISPUNCT(val)    (ispunct((int)(val)) || ((val) == ')'))
  90.  
  91. #define INDENT_SPACES    3
  92. #define IMAGE_BORDER    1
  93.  
  94. #define D_NONE        0
  95. #define D_TITLE        1
  96. #define D_TEXT        2
  97. #define D_OLIST        3
  98. #define D_ULIST        4
  99.  
  100. #define ALIGN_BOTTOM    0
  101. #define ALIGN_MIDDLE    1
  102. #define ALIGN_TOP    2
  103.  
  104.  
  105. extern struct ele_rec *AddEle(struct ele_rec **, struct ele_rec *, struct ele_rec *);
  106. extern void FreeLineList(struct ele_rec *);
  107. extern void FreeObjList(struct mark_up *);
  108. extern int SwapElements(struct ele_rec *, struct ele_rec *, int, int);
  109. extern struct ele_rec **MakeLineList(struct ele_rec *, int);
  110. extern char *ParseMarkTag(char *, char *, char *);
  111. extern char *MaxTextWidth(char *, int *);
  112. extern char *IsMapForm(HTMLGadClData *);
  113. extern int IsIsMapForm(HTMLGadClData *, char *);
  114. extern char *DelayedHRef(HTMLGadClData *);
  115. extern int IsDelayedHRef(HTMLGadClData *, char *);
  116. extern int AnchoredHeight(HTMLGadClData *);
  117. extern struct mark_up *HTMLParse();
  118. extern struct ref_rec *FindHRef(struct ref_rec *, char *);
  119. extern struct delay_rec *FindDelayedImage();
  120. extern ImageInfo *NoImageData(HTMLGadClData *);
  121. extern ImageInfo *DelayedImageData(HTMLGadClData *, Boolean);
  122. extern Pixmap NoImage(HTMLGadClData *);
  123. extern Pixmap DelayedImage(HTMLGadClData *, Boolean);
  124. extern Pixmap InfoToImage(HTMLGadClData *, ImageInfo *);
  125. extern int caseless_equal(char *, char *);
  126. extern void clean_white_space(char *);
  127. extern void WidgetRefresh();
  128. extern WidgetInfo *MakeWidget();
  129. extern XFontStruct *GetWidgetFont();
  130. extern void AddNewForm();
  131. extern void PrepareFormEnd();
  132. extern char *ComposeCommaList(char **, int);
  133. extern void FreeCommaList(char **, int);
  134.  
  135.  
  136. /*
  137.  * To allow arbitrary nesting of lists
  138.  */
  139. typedef struct dtype_rec {
  140.     int type;        /* D_NONE, D_TITLE, D_TEXT, D_OLIST, D_ULIST */
  141.     int count;
  142.     int compact;
  143.     struct dtype_rec *next;
  144. } DescRec;
  145.  
  146.  
  147. /*
  148.  * To allow arbitrary nesting of font changes
  149.  */
  150. typedef struct font_rec {
  151.     XFontStruct *font;
  152.     struct font_rec *next;
  153. } FontRec;
  154.  
  155. static DescRec BaseDesc;
  156. static DescRec *DescType;
  157. static DescRec *ListData;
  158. static FontRec FontBase;
  159. static FontRec *FontStack;
  160. static XFontStruct *currentFont;
  161. static XFontStruct *saveFont;
  162. static unsigned long Fg;
  163. static unsigned long Bg;
  164. static int Width;
  165. static int MaxWidth;
  166. static int ElementId;
  167. static int WidgetId;
  168. static int LineNumber;
  169. static int LineHeight;
  170. static int LineBottom;
  171. static int BaseLine;
  172. static int TextIndent;
  173. static int MarginW;
  174. static int Ignore;
  175. static int Preformat;
  176. static int PF_LF_State; /* Pre-formatted linefeed state.  Hack for bad HTMLs */
  177. static int NeedSpace;
  178. static Boolean Internal;
  179. static Boolean DashedUnderlines;
  180. static Boolean Strikeout;
  181. static int Underlines;
  182. static int CharsInLine;
  183. static int IndentLevel;
  184. static struct ele_rec *Current;
  185. static char *AnchorText;
  186. static char *TitleText;
  187. static char *TextAreaBuf;
  188. static struct mark_up *Last;
  189. static FormInfo *CurrentForm;
  190. static SelectInfo *CurrentSelect;
  191.  
  192. /*
  193.  * Turned out we were taking WAY too much time mallocing and freeing
  194.  * memory when composing the lines into elements.  So this inteligent
  195.  * method minimizes all that.
  196.  */
  197. #define COMP_LINE_BUF_LEN    1024
  198. static char *CompLine = NULL;
  199. static int CompLineLen = 0;
  200. static char *CompWord = NULL;
  201. static int CompWordLen = 0;
  202.  
  203.  
  204.  
  205. /*
  206.  * Create a formatted element
  207.  */
  208. struct ele_rec *
  209. CreateElement(HTMLGadClData * HTML_Data, int type, XFontStruct *fp, int x, int y,
  210.           char *edata)
  211. {
  212.     struct ele_rec *eptr;
  213.     int baseline;
  214.  
  215.     if (fp != NULL)
  216.     {
  217. //        baseline = fp->max_bounds.ascent;
  218.         baseline = fp->tf_Baseline;
  219.     }
  220.     else
  221.     {
  222.         baseline = LineHeight;
  223.     }
  224.  
  225.     eptr = (struct ele_rec *)malloc(sizeof(struct ele_rec));
  226.     if (eptr == NULL)
  227.     {
  228.         fprintf(stderr, "Cannot allocate space for element buffer\n");
  229.         exit(1);
  230.     }
  231.  
  232.     eptr->type = type;
  233.     eptr->pic_data = NULL;
  234.     eptr->widget_data = NULL;
  235.     eptr->font = fp;
  236.     eptr->alignment = ALIGN_BOTTOM;
  237.     eptr->selected = False;
  238.     eptr->internal = Internal;
  239.     eptr->strikeout = Strikeout;
  240.     eptr->x = x;
  241.     eptr->y = y;
  242.     eptr->y_offset = 0;
  243.     eptr->width = 0;
  244.     eptr->line_number = LineNumber;
  245.     eptr->line_height = LineHeight;
  246.     eptr->fg = Fg;
  247.     eptr->bg = Bg;
  248.     eptr->underline_number = Underlines;
  249.     eptr->dashed_underline = DashedUnderlines;
  250.     eptr->indent_level = IndentLevel;
  251. //    eptr->next=NULL; /* This cannot hurt /sb */
  252. //    eptr->prev=NULL;
  253.  
  254.     switch(type)
  255.     {
  256.         case E_TEXT:
  257.             /*
  258.              * get a unique element id
  259.              */
  260.             ElementId++;
  261.             eptr->ele_id = ElementId;
  262.  
  263.             eptr->y_offset = 0;
  264.  
  265.             eptr->edata_len = strlen(edata) + 1;
  266.             eptr->edata = (char *)malloc(eptr->edata_len);
  267.             if (eptr->edata == NULL)
  268.             {
  269.                 eptr->edata_len = 0;
  270.                 fprintf(stderr, "Cannot allocate space for copy of text element data\n");
  271.                 exit(1);
  272.             }
  273.             strcpy(eptr->edata, edata);
  274.  
  275.             /*
  276.              * if this is an anchor, puts its href value into
  277.              * the element.
  278.              */
  279.             if (AnchorText != NULL)
  280.             {
  281.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  282.                     MT_ANCHOR, AT_HREF);
  283.                 eptr->anchorName = ParseMarkTag(AnchorText,
  284.                     MT_ANCHOR, AT_NAME);
  285.             }
  286.             else
  287.             {
  288.                 eptr->anchorHRef = NULL;
  289.                 eptr->anchorName = NULL;
  290.             }
  291.             break;
  292.         case E_BULLET:
  293.             eptr->ele_id = ElementId;
  294.  
  295.             if (BaseLine == -100)
  296.             {
  297.                 BaseLine = baseline;
  298.                 if (LineBottom == 0)
  299.                 {
  300.                     LineBottom = LineHeight - baseline;
  301.                 }
  302.                 else
  303.                 {
  304.                     /*
  305.                      * It is possible (with the first item
  306.                      * in a line being a top aligned image)
  307.                      * for LineBottom to have already been
  308.                      * set. It now needs to be
  309.                      * corrected as we set a real
  310.                      * BaseLine
  311.                      */
  312.                     if ((LineHeight - baseline) >
  313.                         (LineBottom - baseline))
  314.                     {
  315.                         LineBottom = LineHeight -
  316.                             baseline;
  317.                     }
  318.                     else
  319.                     {
  320.                         LineBottom = LineBottom -
  321.                             baseline;
  322.                     }
  323.                 }
  324.             }
  325.             else if (baseline < BaseLine)
  326.             {
  327.                 eptr->y_offset = BaseLine - baseline;
  328.             }
  329.  
  330.             /*
  331.              * Bullets can't be underlined!
  332.              */
  333.             eptr->underline_number = 0;
  334.  
  335.             eptr->edata = NULL;
  336.             eptr->edata_len = 0;
  337.             eptr->anchorHRef = NULL;
  338.             eptr->anchorName = NULL;
  339.             break;
  340.         case E_HRULE:
  341.             /*
  342.              * get a unique element id
  343.              */
  344.             ElementId++;
  345.             eptr->ele_id = ElementId;
  346.  
  347.             if (BaseLine == -100)
  348.             {
  349.                 BaseLine = baseline;
  350.                 if (LineBottom == 0)
  351.                 {
  352.                     LineBottom = LineHeight - baseline;
  353.                 }
  354.                 else
  355.                 {
  356.                     /*
  357.                      * It is possible (with the first item
  358.                      * in a line being a top aligned image)
  359.                      * for LineBottom to have already been
  360.                      * set. It now needs to be
  361.                      * corrected as we set a real
  362.                      * BaseLine
  363.                      */
  364.                     if ((LineHeight - baseline) >
  365.                         (LineBottom - baseline))
  366.                     {
  367.                         LineBottom = LineHeight -
  368.                             baseline;
  369.                     }
  370.                     else
  371.                     {
  372.                         LineBottom = LineBottom -
  373.                             baseline;
  374.                     }
  375.                 }
  376.             }
  377.             else if (baseline < BaseLine)
  378.             {
  379.                 eptr->y_offset = BaseLine - baseline;
  380.             }
  381.  
  382.             /*
  383.              * Rules can't be underlined!
  384.              */
  385.             eptr->underline_number = 0;
  386.  
  387.             eptr->edata = NULL;
  388.             eptr->edata_len = 0;
  389.             eptr->anchorHRef = NULL;
  390.             eptr->anchorName = NULL;
  391.             break;
  392.         case E_LINEFEED:
  393.             eptr->ele_id = ElementId;
  394.  
  395.             eptr->y_offset = 0;
  396.  
  397.             if (BaseLine == -100)
  398.             {
  399.                 BaseLine = baseline;
  400.                 if (LineBottom == 0)
  401.                 {
  402.                     LineBottom = LineHeight - baseline;
  403.                 }
  404.                 else
  405.                 {
  406.                     /*
  407.                      * It is possible (with the first item
  408.                      * in a line being a top aligned image)
  409.                      * for LineBottom to have already been
  410.                      * set. It now needs to be
  411.                      * corrected as we set a real
  412.                      * BaseLine
  413.                      */
  414.                     if ((LineHeight - baseline) >
  415.                         (LineBottom - baseline))
  416.                     {
  417.                         LineBottom = LineHeight -
  418.                             baseline;
  419.                     }
  420.                     else
  421.                     {
  422.                         LineBottom = LineBottom -
  423.                             baseline;
  424.                     }
  425.                 }
  426.             }
  427.  
  428.             /*
  429.              * Linefeeds have to use the maximum line height.
  430.              * Deal with bad Lucidia descents.
  431.              */
  432. #ifdef NO_EXTRA_FILLS
  433.             eptr->line_height = eptr->font->ascent +
  434.                 eptr->font->descent;
  435. #else
  436.             eptr->line_height = LineHeight;
  437. #endif /* NO_EXTRA_FILLS */
  438.             if ((BaseLine + LineBottom) > eptr->line_height)
  439.             {
  440.                 eptr->line_height = BaseLine + LineBottom;
  441.             }
  442.  
  443.             /*
  444.              * Linefeeds can't be underlined!
  445.              */
  446.             eptr->underline_number = 0;
  447.  
  448.             eptr->edata = NULL;
  449.             eptr->edata_len = 0;
  450.             /*
  451.              * if this linefeed is part of a broken anchor put
  452.              * its href value into the element so we can reconnect
  453.              * it when activated.
  454.              * If it at the beginning of an anchor, don't put
  455.              * the href in, and change the color back.
  456.              */
  457.             if (AnchorText != NULL)
  458.             {
  459.                 char *tptr;
  460.  
  461.                 tptr = ParseMarkTag(AnchorText,
  462.                     MT_ANCHOR, AT_HREF);
  463.                 if ((Current != NULL)&&
  464.                     ((Current->anchorHRef == NULL)||
  465.                      (tptr == NULL)||
  466.                      (strcmp(Current->anchorHRef, tptr) != 0)))
  467.                 {
  468.                                         if (tptr)
  469.                                           free(tptr);
  470.                     eptr->anchorHRef = NULL;
  471.                     eptr->anchorName = NULL;
  472.                     eptr->fg = HTML_Data->foreground;
  473.                 }
  474.                 else
  475.                 {
  476.                     eptr->anchorHRef = tptr;
  477.                     eptr->anchorName =
  478.                         ParseMarkTag(AnchorText,
  479.                         MT_ANCHOR, AT_NAME);
  480.                 }
  481.             }
  482.             else
  483.             {
  484.                 eptr->anchorHRef = NULL;
  485.                 eptr->anchorName = NULL;
  486.             }
  487.             break;
  488.         case E_IMAGE:
  489.             /*
  490.              * get a unique element id
  491.              */
  492.             ElementId++;
  493.             eptr->ele_id = ElementId;
  494.  
  495.             /*
  496.              * Images can't be underlined!
  497.              */
  498.             eptr->underline_number = 0;
  499.  
  500.             if (edata != NULL)
  501.             {
  502.                 eptr->edata_len = strlen(edata) + 1;
  503.                 eptr->edata = (char *)malloc(eptr->edata_len);
  504.                 if (eptr->edata == NULL)
  505.                 {
  506.                     eptr->edata_len = 0;
  507.                     fprintf(stderr, "Cannot allocate space for copy of image element data\n");
  508.                     exit(1);
  509.                 }
  510.                 strcpy(eptr->edata, edata);
  511.             }
  512.             else
  513.             {
  514.                 eptr->edata_len = 0;
  515.                 eptr->edata = NULL;
  516.             }
  517.  
  518.             /*
  519.              * if this image is part of an anchor put
  520.              * its href and name values into the element
  521.              * so we can reconnect it when activated.
  522.              */
  523.             if (AnchorText != NULL)
  524.             {
  525.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  526.                     MT_ANCHOR, AT_HREF);
  527.                 eptr->anchorName = ParseMarkTag(AnchorText,
  528.                     MT_ANCHOR, AT_NAME);
  529.             }
  530.             else
  531.             {
  532.                 eptr->anchorHRef = NULL;
  533.                 eptr->anchorName = NULL;
  534.             }
  535.  
  536.             /*
  537.              * Picture stuff
  538.              */
  539.             /*
  540.              * if we have an image resolver, use it.
  541.              */
  542.             if (HTML_Data->resolveImage != NULL)
  543.             {
  544.                 int internal;
  545.  
  546.                 /*
  547.                  * See if this is a special internal image
  548.                  */
  549.                 if ((edata != NULL)&&
  550.                     (strncmp(edata, INTERNAL_IMAGE,
  551.                     strlen(INTERNAL_IMAGE)) == 0))
  552.                 {
  553.                     internal = 1;
  554.                 }
  555.                 else
  556.                 {
  557.                     internal = 0;
  558.                 }
  559.  
  560.                 /*
  561.                  * if we delay image fetching
  562.                  * internal images are not delayed.
  563.                  */
  564.                 if ((HTML_Data->delay_images == True)&&
  565.                     (!internal))
  566.                 {
  567.                     /*
  568.                      * see if already cached.
  569.                      */
  570.                     eptr->pic_data = (*(resolveImageProc)
  571.                     (HTML_Data->resolveImage))(HTML_Data, edata, 1);
  572.                     if (eptr->pic_data != NULL)
  573.                     {
  574.                     eptr->pic_data->delayed = 0;
  575.                     /*
  576.                      * Mark images we have sucessfully
  577.                      * loaded at least once
  578.                      */
  579.                     if (eptr->pic_data->image_data != NULL)
  580.                     {
  581.                         eptr->pic_data->fetched = 1;
  582.                     }
  583.                     }
  584.                     /*
  585.                      * else, not cached.
  586.                      */
  587.                     else
  588.                     {
  589.                       /*
  590.                        * just image
  591.                        */
  592.                       if (eptr->anchorHRef == NULL)
  593.                       {
  594.                     eptr->pic_data = DelayedImageData(HTML_Data,
  595.                         False);
  596.                     eptr->pic_data->delayed = 1;
  597.                     eptr->anchorHRef = DelayedHRef(HTML_Data);
  598.                     eptr->fg = HTML_Data->anchor_fg;
  599.                       }
  600.                       /*
  601.                        * else anchor and image
  602.                        */
  603.                       else
  604.                       {
  605.                     eptr->pic_data = DelayedImageData(HTML_Data,
  606.                         True);
  607.                     eptr->pic_data->delayed = 1;
  608.                       }
  609.                     }
  610.                 }
  611.                 else
  612.                 {
  613.                     eptr->pic_data = (*(resolveImageProc)
  614.                     (HTML_Data->resolveImage))(HTML_Data, edata, 0);
  615.                     if (eptr->pic_data != NULL)
  616.                     {
  617.                     eptr->pic_data->delayed = 0;
  618.                     /*
  619.                      * Mark images we have sucessfully
  620.                      * loaded at least once
  621.                      */
  622.                     if (eptr->pic_data->image_data != NULL)
  623.                     {
  624.                         eptr->pic_data->fetched = 1;
  625.                     }
  626.                     }
  627.                 }
  628.                 if (eptr->pic_data != NULL)
  629.                 {
  630.                     eptr->pic_data->internal = internal;
  631.                 }
  632.             }
  633.             if (eptr->pic_data == NULL)
  634.             {
  635.                 eptr->pic_data = NoImageData(HTML_Data);
  636.                 eptr->pic_data->delayed = 0;
  637.                 eptr->pic_data->internal = 0;
  638.             }
  639.  
  640.             break;
  641.         case E_WIDGET:
  642. // #ifndef _AMIGA
  643.             /*
  644.              * get a unique element id
  645.              */
  646.             WidgetId++;
  647.             ElementId++;
  648.             eptr->ele_id = ElementId;
  649.  
  650.             /*
  651.              * Widgets can't be underlined!
  652.              */
  653.             eptr->underline_number = 0;
  654.  
  655.             eptr->edata = NULL;
  656.             eptr->edata_len = 0;
  657.  
  658.             /*
  659.              * if this widget is part of an anchor put
  660.              * its href and name values into the element
  661.              * so we can reconnect it when activated.
  662.              */
  663.             if (AnchorText != NULL)
  664.             {
  665.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  666.                     MT_ANCHOR, AT_HREF);
  667.                 eptr->anchorName = ParseMarkTag(AnchorText,
  668.                     MT_ANCHOR, AT_NAME);
  669.             }
  670.             else
  671.             {
  672.                 eptr->anchorHRef = NULL;
  673.                 eptr->anchorName = NULL;
  674.             }
  675.  
  676.             /*
  677.              * Widget stuff
  678.              */
  679.             eptr->widget_data = MakeWidget(HTML_Data, edata,
  680.                 (x + IMAGE_BORDER), (y + IMAGE_BORDER),
  681.                 WidgetId, CurrentForm);
  682.  
  683.             /*
  684.              * I have no idea what to do if we can't create the
  685.              * widget.  It probably means we are so messed up we
  686.              * will soon be crashing.
  687.              */
  688.             if (eptr->widget_data == NULL)
  689.             {
  690.             }
  691.  
  692. // #endif /*_AMIGA */
  693.             break;
  694.         default:
  695.             fprintf(stderr, "CreateElement:  Unknown type %d\n", type);
  696.             eptr->ele_id = ElementId;
  697.  
  698.             eptr->edata = NULL;
  699.             eptr->edata_len = 0;
  700.             eptr->anchorHRef = NULL;
  701.             eptr->anchorName = NULL;
  702.             break;
  703.     }
  704.     return(eptr);
  705. }
  706.  
  707.  
  708. /*
  709.  * Set the formatted element into the format list.  Use a pre-allocated
  710.  * list position if possible, otherwise allocate a new list position.
  711.  */
  712. void
  713. SetElement(HTMLGadClData * HTML_Data, int type, XFontStruct *fp, int x, int y, char *edata)
  714. {
  715.     struct ele_rec *eptr;
  716.     int len;
  717.     int baseline;
  718.  
  719.     if (fp != NULL)
  720.     {
  721.         baseline = fp->tf_Baseline;
  722.     }
  723.     else
  724.     {
  725.         baseline = LineHeight;
  726.     }
  727.  
  728.     /*
  729.      * There is not pre-allocated format list, or we have reached
  730.      * the end of the pre-allocated list.  Create a new element, and
  731.      * add it.
  732.      */
  733.     if ((HTML_Data->formatted_elements == NULL)||
  734.         ((Current != NULL)&&(Current->next == NULL)))
  735.     {
  736.         eptr = CreateElement(HTML_Data, type, fp, x, y, edata);
  737.         Current = AddEle(&(HTML_Data->formatted_elements), Current, eptr);
  738.         return;
  739.     }
  740.  
  741.     /*
  742.      * If current is null, but we have a pre-allocated format list, then
  743.      * this is the first SetElement() call for this formated text, and
  744.      * we must set current to the head of the formatted list.  Otherwise
  745.      * we move current to the next pre-allocated list position.
  746.      */
  747.     if (Current == NULL)
  748.     {
  749.         Current = HTML_Data->formatted_elements;
  750.     }
  751.     else
  752.     {
  753.         Current = Current->next;
  754.     }
  755.  
  756.     eptr = Current;
  757.     if (eptr == NULL)
  758.     {
  759.         fprintf(stderr, "SetElement: Error, setting a null element\n");
  760.         exit(1);
  761.     }
  762.  
  763.     eptr->type = type;
  764.     eptr->pic_data = NULL;
  765.     eptr->widget_data = NULL;
  766.     eptr->font = fp;
  767.     eptr->alignment = ALIGN_BOTTOM;
  768.     eptr->selected = False;
  769.     eptr->internal = Internal;
  770.     eptr->strikeout = Strikeout;
  771.     eptr->x = x;
  772.     eptr->y = y;
  773.     eptr->y_offset = 0;
  774.     eptr->width = 0;
  775.     eptr->line_number = LineNumber;
  776.     eptr->line_height = LineHeight;
  777.     eptr->fg = Fg;
  778.     eptr->bg = Bg;
  779.     eptr->underline_number = Underlines;
  780.     eptr->dashed_underline = DashedUnderlines;
  781.     eptr->indent_level = IndentLevel;
  782. //    eptr->next=NULL; /* This cannot hurt /sb */
  783. //    eptr->prev=NULL;
  784.  
  785.     switch(type)
  786.     {
  787.         case E_TEXT:
  788.             /*
  789.              * get a unique element id
  790.              */
  791.             ElementId++;
  792.             eptr->ele_id = ElementId;
  793.  
  794.             eptr->y_offset = 0;
  795.  
  796.             len = strlen(edata) + 1;
  797.             if (len > eptr->edata_len)
  798.             {
  799.                 if (eptr->edata != NULL)
  800.                 {
  801.                     free((char *)eptr->edata);
  802.                 }
  803.                 eptr->edata = (char *)malloc(len);
  804.                 if (eptr->edata == NULL)
  805.                 {
  806.                     eptr->edata_len = 0;
  807.                     fprintf(stderr, "Cannot allocate space for copy of text element data\n");
  808.                     exit(1);
  809.                 }
  810.             }
  811.             eptr->edata_len = len;
  812. //            kprintf("edata %lx\n",edata);
  813.             strcpy(eptr->edata, edata);
  814.  
  815.             /*
  816.              * if this is an anchor, puts its href and name
  817.              * values into the element.
  818.              */
  819.             if (eptr->anchorHRef != NULL)
  820.             {
  821.                 free((char *)eptr->anchorHRef);
  822.             }
  823.             if (eptr->anchorName != NULL)
  824.             {
  825.                 free((char *)eptr->anchorName);
  826.             }
  827.             if (AnchorText != NULL)
  828.             {
  829.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  830.                     MT_ANCHOR, AT_HREF);
  831.                 eptr->anchorName = ParseMarkTag(AnchorText,
  832.                     MT_ANCHOR, AT_NAME);
  833.             }
  834.             else
  835.             {
  836.                 eptr->anchorHRef = NULL;
  837.                 eptr->anchorName = NULL;
  838.             }
  839.             break;
  840.         case E_BULLET:
  841.             eptr->ele_id = ElementId;
  842.  
  843.             if (BaseLine == -100)
  844.             {
  845.                 BaseLine = baseline;
  846.                 if (LineBottom == 0)
  847.                 {
  848.                     LineBottom = LineHeight - baseline;
  849.                 }
  850.                 else
  851.                 {
  852.                     /*
  853.                      * It is possible (with the first item
  854.                      * in a line being a top aligned image)
  855.                      * for LineBottom to have already been
  856.                      * set. It now needs to be
  857.                      * corrected as we set a real
  858.                      * BaseLine
  859.                      */
  860.                     if ((LineHeight - baseline) >
  861.                         (LineBottom - baseline))
  862.                     {
  863.                         LineBottom = LineHeight -
  864.                             baseline;
  865.                     }
  866.                     else
  867.                     {
  868.                         LineBottom = LineBottom -
  869.                             baseline;
  870.                     }
  871.                 }
  872.             }
  873.             else if (baseline < BaseLine)
  874.             {
  875.                 eptr->y_offset = BaseLine - baseline;
  876.             }
  877.  
  878.             /*
  879.              * Bullets can't be underlined!
  880.              */
  881.             eptr->underline_number = 0;
  882.  
  883.             if (eptr->edata != NULL)
  884.             {
  885.                 free((char *)eptr->edata);
  886.             }
  887.             eptr->edata = NULL;
  888.             eptr->edata_len = 0;
  889.             if (eptr->anchorHRef != NULL)
  890.             {
  891.                 free((char *)eptr->anchorHRef);
  892.             }
  893.             if (eptr->anchorName != NULL)
  894.             {
  895.                 free((char *)eptr->anchorName);
  896.             }
  897.             eptr->anchorHRef = NULL;
  898.             eptr->anchorName = NULL;
  899.             break;
  900.         case E_HRULE:
  901.             /*
  902.              * get a unique element id
  903.              */
  904.             ElementId++;
  905.             eptr->ele_id = ElementId;
  906.  
  907.             if (BaseLine == -100)
  908.             {
  909.                 BaseLine = baseline;
  910.                 if (LineBottom == 0)
  911.                 {
  912.                     LineBottom = LineHeight - baseline;
  913.                 }
  914.                 else
  915.                 {
  916.                     /*
  917.                      * It is possible (with the first item
  918.                      * in a line being a top aligned image)
  919.                      * for LineBottom to have already been
  920.                      * set. It now needs to be
  921.                      * corrected as we set a real
  922.                      * BaseLine
  923.                      */
  924.                     if ((LineHeight - baseline) >
  925.                         (LineBottom - baseline))
  926.                     {
  927.                         LineBottom = LineHeight -
  928.                             baseline;
  929.                     }
  930.                     else
  931.                     {
  932.                         LineBottom = LineBottom -
  933.                             baseline;
  934.                     }
  935.                 }
  936.             }
  937.             else if (baseline < BaseLine)
  938.             {
  939.                 eptr->y_offset = BaseLine - baseline;
  940.             }
  941.  
  942.             /*
  943.              * Rules can't be underlined!
  944.              */
  945.             eptr->underline_number = 0;
  946.  
  947.             if (eptr->edata != NULL)
  948.             {
  949.                 free((char *)eptr->edata);
  950.             }
  951.             eptr->edata = NULL;
  952.             eptr->edata_len = 0;
  953.             if (eptr->anchorHRef != NULL)
  954.             {
  955.                 free((char *)eptr->anchorHRef);
  956.             }
  957.             if (eptr->anchorName != NULL)
  958.             {
  959.                 free((char *)eptr->anchorName);
  960.             }
  961.             eptr->anchorHRef = NULL;
  962.             eptr->anchorName = NULL;
  963.             break;
  964.         case E_LINEFEED:
  965.             eptr->ele_id = ElementId;
  966.  
  967.             eptr->y_offset = 0;
  968.  
  969.             if (BaseLine == -100)
  970.             {
  971.                 BaseLine = baseline;
  972.                 if (LineBottom == 0)
  973.                 {
  974.                     LineBottom = LineHeight - baseline;
  975.                 }
  976.                 else
  977.                 {
  978.                     /*
  979.                      * It is possible (with the first item
  980.                      * in a line being a top aligned image)
  981.                      * for LineBottom to have already been
  982.                      * set. It now needs to be
  983.                      * corrected as we set a real
  984.                      * BaseLine
  985.                      */
  986.                     if ((LineHeight - baseline) >
  987.                         (LineBottom - baseline))
  988.                     {
  989.                         LineBottom = LineHeight -
  990.                             baseline;
  991.                     }
  992.                     else
  993.                     {
  994.                         LineBottom = LineBottom -
  995.                             baseline;
  996.                     }
  997.                 }
  998.             }
  999.  
  1000.             /*
  1001.              * Linefeeds have to use the maximum line height.
  1002.              * Deal with bad Lucidia descents.
  1003.              */
  1004. #ifdef NO_EXTRA_FILLS
  1005.             eptr->line_height = eptr->font->ascent +
  1006.                 eptr->font->descent;
  1007. #else
  1008.             eptr->line_height = LineHeight;
  1009. #endif /* NO_EXTRA_FILLS */
  1010.             if ((BaseLine + LineBottom) > eptr->line_height)
  1011.             {
  1012.                 eptr->line_height = (BaseLine + LineBottom);
  1013.             }
  1014.  
  1015.             /*
  1016.              * Linefeeds can't be underlined!
  1017.              */
  1018.             eptr->underline_number = 0;
  1019.  
  1020.             if (eptr->edata != NULL)
  1021.             {
  1022.                 free((char *)eptr->edata);
  1023.             }
  1024.             eptr->edata = NULL;
  1025.             eptr->edata_len = 0;
  1026.             /*
  1027.              * if this linefeed is part of a broken anchor put
  1028.              * its href and name values into the element
  1029.              * so we can reconnect it when activated.
  1030.              * If it at the beginning of an anchor, don't put
  1031.              * the href in and change the color back.
  1032.              */
  1033.             if (eptr->anchorHRef != NULL)
  1034.             {
  1035.                 free((char *)eptr->anchorHRef);
  1036.             }
  1037.             if (eptr->anchorName != NULL)
  1038.             {
  1039.                 free((char *)eptr->anchorName);
  1040.             }
  1041.             if (AnchorText != NULL)
  1042.             {
  1043.                 char *tptr;
  1044.  
  1045.                 tptr = ParseMarkTag(AnchorText,
  1046.                     MT_ANCHOR, AT_HREF);
  1047.                 if ((eptr->prev != NULL)&&
  1048.                    ((eptr->prev->anchorHRef == NULL)||
  1049.                    (tptr == NULL)||
  1050.                    (strcmp(eptr->prev->anchorHRef, tptr) != 0)))
  1051.                 {
  1052.                                         if (tptr)
  1053.                                           free(tptr);
  1054.                     eptr->anchorHRef = NULL;
  1055.                     eptr->anchorName = NULL;
  1056. /*
  1057.  * Without motif we use our own foreground resource instead of
  1058.  * using the manager's
  1059.  */
  1060. #ifdef MOTIF
  1061.                     eptr->fg = HTML_Data->manager.foreground;
  1062. #else
  1063.                     eptr->fg = HTML_Data->foreground;
  1064. #endif /* MOTIF */
  1065.                 }
  1066.                 else
  1067.                 {
  1068.                     eptr->anchorHRef = tptr;
  1069.                     eptr->anchorName =
  1070.                         ParseMarkTag(AnchorText,
  1071.                         MT_ANCHOR, AT_NAME);
  1072.                 }
  1073.             }
  1074.             else
  1075.             {
  1076.                 eptr->anchorHRef = NULL;
  1077.                 eptr->anchorName = NULL;
  1078.             }
  1079.             break;
  1080.         case E_IMAGE:
  1081.             /*
  1082.              * get a unique element id
  1083.              */
  1084.             ElementId++;
  1085.             eptr->ele_id = ElementId;
  1086.  
  1087.             /*
  1088.              * Images can't be underlined!
  1089.              */
  1090.             eptr->underline_number = 0;
  1091.  
  1092.             if (edata != NULL)
  1093.             {
  1094.                 len = strlen(edata) + 1;
  1095.                 if (len > eptr->edata_len)
  1096.                 {
  1097.                     if (eptr->edata != NULL)
  1098.                     {
  1099.                         free((char *)eptr->edata);
  1100.                     }
  1101.                     eptr->edata = (char *)malloc(len);
  1102.                     if (eptr->edata == NULL)
  1103.                     {
  1104.                         eptr->edata_len = 0;
  1105.                         fprintf(stderr, "Cannot allocate space for copy of text element data\n");
  1106.                         exit(1);
  1107.                     }
  1108.                 }
  1109.                 eptr->edata_len = len;
  1110.                 strcpy(eptr->edata, edata);
  1111.             }
  1112.             else
  1113.             {
  1114.                 eptr->edata_len = 0;
  1115.                 if (eptr->edata != NULL)
  1116.                 {
  1117.                     free((char *)eptr->edata);
  1118.                 }
  1119.                 eptr->edata = NULL;
  1120.             }
  1121.  
  1122.             /*
  1123.              * if this image is part of an anchor put
  1124.              * its href and name values into the element
  1125.              * so we can reconnect it when activated.
  1126.              */
  1127.             if (eptr->anchorHRef != NULL)
  1128.             {
  1129.                 free((char *)eptr->anchorHRef);
  1130.             }
  1131.             if (eptr->anchorName != NULL)
  1132.             {
  1133.                 free((char *)eptr->anchorName);
  1134.             }
  1135.             if (AnchorText != NULL)
  1136.             {
  1137.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  1138.                     MT_ANCHOR, AT_HREF);
  1139.                 eptr->anchorName = ParseMarkTag(AnchorText,
  1140.                     MT_ANCHOR, AT_NAME);
  1141.             }
  1142.             else
  1143.             {
  1144.                 eptr->anchorHRef = NULL;
  1145.                 eptr->anchorName = NULL;
  1146.             }
  1147.  
  1148.             /*
  1149.              * Picture stuff
  1150.              */
  1151.             /*
  1152.              * if we have an image resolver, use it.
  1153.              */
  1154.             if (HTML_Data->resolveImage != NULL)
  1155.             {
  1156.                 int internal;
  1157.  
  1158.                 /*
  1159.                  * See if this is a special internal image
  1160.                  */
  1161.                 if ((edata != NULL)&&
  1162.                     (strncmp(edata, INTERNAL_IMAGE,
  1163.                     strlen(INTERNAL_IMAGE)) == 0))
  1164.                 {
  1165.                     internal = 1;
  1166.                 }
  1167.                 else
  1168.                 {
  1169.                     internal = 0;
  1170.                 }
  1171.  
  1172.                 /*
  1173.                  * if we delay image fetching
  1174.                  * internal images are not delayed.
  1175.                  */
  1176.                 if ((HTML_Data->delay_images == True)&&
  1177.                     (!internal))
  1178.                 {
  1179.                     /*
  1180.                      * see if already cached.
  1181.                      */
  1182.                     eptr->pic_data = (*(resolveImageProc)
  1183.                     (HTML_Data->resolveImage))(HTML_Data, edata, 1);
  1184.                     if (eptr->pic_data != NULL)
  1185.                     {
  1186.                     eptr->pic_data->delayed = 0;
  1187.                     /*
  1188.                      * Mark images we have sucessfully
  1189.                      * loaded at least once
  1190.                      */
  1191.                     if (eptr->pic_data->image_data != NULL)
  1192.                     {
  1193.                         eptr->pic_data->fetched = 1;
  1194.                     }
  1195.                     }
  1196.                     /*
  1197.                      * else, not cached.
  1198.                      */
  1199.                     else
  1200.                     {
  1201.                       /*
  1202.                        * just image
  1203.                        */
  1204.                       if (eptr->anchorHRef == NULL)
  1205.                       {
  1206.                     eptr->pic_data = DelayedImageData(HTML_Data,
  1207.                         False);
  1208.                     eptr->pic_data->delayed = 1;
  1209.                     eptr->anchorHRef = DelayedHRef(HTML_Data);
  1210.                     eptr->fg = HTML_Data->anchor_fg;
  1211.                       }
  1212.                       /*
  1213.                        * else anchor and image
  1214.                        */
  1215.                       else
  1216.                       {
  1217.                     eptr->pic_data = DelayedImageData(HTML_Data,
  1218.                         True);
  1219.                     eptr->pic_data->delayed = 1;
  1220.                       }
  1221.                     }
  1222.                 }
  1223.                 else
  1224.                 {
  1225.                     eptr->pic_data = (*(resolveImageProc)
  1226.                     (HTML_Data->resolveImage))(HTML_Data, edata, 0);
  1227.                     if (eptr->pic_data != NULL)
  1228.                     {
  1229.                     eptr->pic_data->delayed = 0;
  1230.                     /*
  1231.                      * Mark images we have sucessfully
  1232.                      * loaded at least once
  1233.                      */
  1234.                     if (eptr->pic_data->image_data != NULL)
  1235.                     {
  1236.                         eptr->pic_data->fetched = 1;
  1237.                     }
  1238.                     }
  1239.                 }
  1240.                 if (eptr->pic_data != NULL)
  1241.                 {
  1242.                     eptr->pic_data->internal = internal;
  1243.                 }
  1244.             }
  1245.             if (eptr->pic_data == NULL)
  1246.             {
  1247.                 eptr->pic_data = NoImageData(HTML_Data);
  1248.                 eptr->pic_data->delayed = 0;
  1249.                 eptr->pic_data->internal = 0;
  1250.             }
  1251.  
  1252.             break;
  1253.         case E_WIDGET:
  1254. // #ifndef _AMIGA
  1255.             /*
  1256.              * get a unique element id
  1257.              */
  1258.             WidgetId++;
  1259.             ElementId++;
  1260.             eptr->ele_id = ElementId;
  1261.  
  1262.             /*
  1263.              * Widgets can't be underlined!
  1264.              */
  1265.             eptr->underline_number = 0;
  1266.  
  1267.             if (eptr->edata != NULL)
  1268.             {
  1269.                 free((char *)eptr->edata);
  1270.             }
  1271.             eptr->edata = NULL;
  1272.             eptr->edata_len = 0;
  1273.  
  1274.             /*
  1275.              * if this widget is part of an anchor put
  1276.              * its href and name values into the element
  1277.              * so we can reconnect it when activated.
  1278.              */
  1279.             if (eptr->anchorHRef != NULL)
  1280.             {
  1281.                 free((char *)eptr->anchorHRef);
  1282.             }
  1283.             if (eptr->anchorName != NULL)
  1284.             {
  1285.                 free((char *)eptr->anchorName);
  1286.             }
  1287.             if (AnchorText != NULL)
  1288.             {
  1289.                 eptr->anchorHRef = ParseMarkTag(AnchorText,
  1290.                     MT_ANCHOR, AT_HREF);
  1291.                 eptr->anchorName = ParseMarkTag(AnchorText,
  1292.                     MT_ANCHOR, AT_NAME);
  1293.             }
  1294.             else
  1295.             {
  1296.                 eptr->anchorHRef = NULL;
  1297.                 eptr->anchorName = NULL;
  1298.             }
  1299.  
  1300.             /*
  1301.              * Widget stuff
  1302.              */
  1303.             eptr->widget_data = MakeWidget(HTML_Data, edata,
  1304.                 (x + IMAGE_BORDER), (y + IMAGE_BORDER),
  1305.                 WidgetId, CurrentForm);
  1306.  
  1307.             /*
  1308.              * I have no idea what to do if we can't create the
  1309.              * widget.  It probably means we are so messed up we
  1310.              * will soon be crashing.
  1311.              */
  1312.             if (eptr->widget_data == NULL)
  1313.             {
  1314.             }
  1315. // #endif /* _AMIGA */
  1316.  
  1317.             break;
  1318.         default:
  1319.             fprintf(stderr, "SetElement:  Unknown type %d\n", type);
  1320.             eptr->ele_id = ElementId;
  1321.  
  1322.             if (eptr->edata != NULL)
  1323.             {
  1324.                 free((char *)eptr->edata);
  1325.             }
  1326.             eptr->edata = NULL;
  1327.             eptr->edata_len = 0;
  1328.             if (eptr->anchorHRef != NULL)
  1329.             {
  1330.                 free((char *)eptr->anchorHRef);
  1331.             }
  1332.             if (eptr->anchorName != NULL)
  1333.             {
  1334.                 free((char *)eptr->anchorName);
  1335.             }
  1336.             eptr->anchorHRef = NULL;
  1337.             eptr->anchorName = NULL;
  1338.             break;
  1339.     }
  1340. }
  1341.  
  1342.  
  1343. /*
  1344.  * Change our drawing font 
  1345.  */
  1346. void
  1347. NewFont(XFontStruct *fp)
  1348. {
  1349. #ifdef _AMIGA
  1350.   LineHeight = fp->tf_YSize;
  1351. #else /* _AMIGA */
  1352.     /*
  1353.      * Deal with bad Lucidia descents.
  1354.      */
  1355.     if (fp->descent > fp->max_bounds.descent)
  1356.     {
  1357.         LineHeight = fp->tf_YSize + fp->descent;
  1358.     }
  1359.     else
  1360.     {
  1361.         LineHeight = fp->tf_YSize + fp->max_bounds.descent;
  1362.     }
  1363. #endif /* AMIGA */
  1364. }
  1365.  
  1366.  
  1367. /*
  1368.  * Place a linefeed at the end of a line.
  1369.  * Create and add the element record for it.
  1370.  */
  1371. void
  1372. LinefeedPlace(HTMLGadClData * HTML_Data, int *x, int *y)
  1373. {
  1374.     /*
  1375.      * At the end of every line check if we have a new MaxWidth
  1376.      */
  1377.     if ((*x + HTML_Data->margin_width) > MaxWidth)
  1378.     {
  1379.         MaxWidth = *x + HTML_Data->margin_width;
  1380.     }
  1381.  
  1382.     SetElement(HTML_Data, E_LINEFEED, currentFont, *x, *y, (char *)NULL);
  1383. }
  1384.  
  1385.  
  1386. /*
  1387.  * We have encountered a line break.  Incrment the line counter,
  1388.  * and move down some space.
  1389.  */
  1390. void
  1391. LineFeed(HTMLGadClData * HTML_Data, int *x, int *y)
  1392. {
  1393.     /*
  1394.      * Manipulate linefeed state for special pre-formatted linefeed
  1395.      * hack for broken HTMLs
  1396.      */
  1397.     if (Preformat)
  1398.     {
  1399.         switch(PF_LF_State)
  1400.         {
  1401.             /*
  1402.              * First soft linefeed
  1403.              */
  1404.             case 0:
  1405.                 PF_LF_State = 1;
  1406.                 break;
  1407.             /*
  1408.              * Collapse multiple soft linefeeds within a pre
  1409.              */
  1410.             case 1:
  1411.                 return;
  1412.                 break;
  1413.             /*
  1414.              * Ignore soft linefeeds after hard linefeeds
  1415.              * within a pre
  1416.              */
  1417.             case 2:
  1418.                 return;
  1419.                 break;
  1420.             default:
  1421.                 PF_LF_State = 1;
  1422.                 break;
  1423.         }
  1424.     }
  1425.     /*
  1426.      * No blank lines allowed at the start of a document.
  1427.      */
  1428.     else if (ElementId == 0)
  1429.     {
  1430.         return;
  1431.     }
  1432.     /*
  1433.      * For formatted documents there are 3 linefeed states.
  1434.      * 0 = in the middle of a line.
  1435.      * 1 = at left margin
  1436.      * 2 = at left margin with blank line above
  1437.      */
  1438.     else
  1439.     {
  1440.         PF_LF_State++;
  1441.         if (PF_LF_State > 2)
  1442.         {
  1443.             PF_LF_State = 2;
  1444.         }
  1445.     }
  1446.  
  1447.     /*
  1448.      * sanity check to set some line height if none was specified.
  1449.      */
  1450.     if (BaseLine <= 0)
  1451.     {
  1452.         BaseLine = LineHeight;
  1453.     }
  1454.  
  1455.     LinefeedPlace(HTML_Data, x, y);
  1456.  
  1457.     CharsInLine = 0;
  1458.     *x = TextIndent;
  1459.     *y = *y + BaseLine + LineBottom;
  1460.  
  1461.     LineBottom = 0;
  1462.     BaseLine = -100;
  1463.  
  1464.     NeedSpace = 0;
  1465.     LineNumber++;
  1466. }
  1467.  
  1468.  
  1469. /*
  1470.  * We want to make sure that future text starts at the left margin.
  1471.  * But if we are already there, don't put in a new line.
  1472.  */
  1473. void
  1474. ConditionalLineFeed(HTMLGadClData * HTML_Data, int *x, int *y, int state)
  1475. {
  1476.     if (PF_LF_State < state)
  1477.     {
  1478.         /*
  1479.          * If this funtion is being used to insert a blank line,
  1480.          * we need to look at the percentVerticalSpace resource
  1481.          * to see how high to make the line.
  1482.          */
  1483.         if ((state == 2)&&(HTML_Data->percent_vert_space > 0))
  1484.         {
  1485.             int l_height;
  1486.  
  1487.             l_height = LineHeight;
  1488.             LineHeight = LineHeight *
  1489.                 HTML_Data->percent_vert_space / 100;
  1490.             LineFeed(HTML_Data, x, y);
  1491.             LineHeight = l_height;
  1492.         }
  1493.         else
  1494.         {
  1495.             LineFeed(HTML_Data, x, y);
  1496.         }
  1497.     }
  1498. }
  1499.  
  1500.  
  1501. /*
  1502.  * hack to make broken HTMLs within pre-formatted text have nice
  1503.  * looking linefeeds.
  1504.  */
  1505. void
  1506. HardLineFeed(HTMLGadClData * HTML_Data, int *x, int *y)
  1507. {
  1508.     /*
  1509.      * Manipulate linefeed state for special pre-formatted linefeed
  1510.      * hack for broken HTMLs
  1511.      */
  1512.     if (Preformat)
  1513.     {
  1514.         switch(PF_LF_State)
  1515.         {
  1516.             /*
  1517.              * First hard linefeed
  1518.              */
  1519.             case 0:
  1520.                 PF_LF_State = 2;
  1521.                 break;
  1522.             /*
  1523.              * Previous soft linefeed should have been ignored, so
  1524.              * ignore this hard linefeed, but set state like it
  1525.              * was not ignored.
  1526.              */
  1527.             case 1:
  1528.                 PF_LF_State = 2;
  1529.                 return;
  1530.                 break;
  1531.             /*
  1532.              * Honor multiple hard linefeeds.
  1533.              */
  1534.             case 2:
  1535.                 break;
  1536.             default:
  1537.                 PF_LF_State = 2;
  1538.                 break;
  1539.         }
  1540.     }
  1541.  
  1542.     /*
  1543.      * sanity check to set some line height if none was specified.
  1544.      */
  1545.     if (BaseLine <= 0)
  1546.     {
  1547.         BaseLine = LineHeight;
  1548.     }
  1549.  
  1550.     LinefeedPlace(HTML_Data, x, y);
  1551.  
  1552.     CharsInLine = 0;
  1553.     *x = TextIndent;
  1554.     *y = *y + BaseLine + LineBottom;
  1555.  
  1556.     LineBottom = 0;
  1557.     BaseLine = -100;
  1558.  
  1559.     NeedSpace = 0;
  1560.     LineNumber++;
  1561. }
  1562.  
  1563.  
  1564. static void
  1565. AdjustBaseLine(void)
  1566. {
  1567.     int baseline;
  1568.  
  1569.     baseline = Current->font->tf_Baseline;
  1570.  
  1571.     if (BaseLine == -100)
  1572.     {
  1573.         BaseLine = baseline;
  1574.         Current->y_offset = 0;
  1575.         if (LineBottom == 0)
  1576.         {
  1577.             LineBottom = LineHeight - baseline;
  1578.         }
  1579.         else
  1580.         {
  1581.             /*
  1582.              * It is possible (with the first item
  1583.              * in a line being a top aligned image)
  1584.              * for LineBottom to have already been
  1585.              * set. It now needs to be
  1586.              * corrected as we set a real
  1587.              * BaseLine
  1588.              */
  1589.             if ((LineHeight - baseline) >
  1590.                 (LineBottom - baseline))
  1591.             {
  1592.                 LineBottom = LineHeight -
  1593.                     baseline;
  1594.             }
  1595.             else
  1596.             {
  1597.                 LineBottom = LineBottom -
  1598.                     baseline;
  1599.             }
  1600.         }
  1601.     }
  1602.     else if (baseline <= BaseLine)
  1603.     {
  1604.         if (baseline < BaseLine)
  1605.         {
  1606.             Current->y_offset = BaseLine - baseline;
  1607.         }
  1608.         else
  1609.         {
  1610.             Current->y_offset = 0;
  1611.         }
  1612.  
  1613.         if ((LineHeight - baseline) > LineBottom)
  1614.         {
  1615.             LineBottom = LineHeight - baseline;
  1616.         }
  1617.     }
  1618.     else
  1619.     {
  1620.         struct ele_rec *eptr;
  1621.         int line, incy;
  1622.  
  1623.         incy = baseline - BaseLine;
  1624.         BaseLine = baseline;
  1625.  
  1626.         /*
  1627.          * Go back over this line
  1628.          * and move everything down
  1629.          * a little.
  1630.          */
  1631.         eptr = Current;
  1632.         line = eptr->line_number;
  1633.         while ((eptr->prev != NULL)&&
  1634.             (eptr->prev->line_number == line))
  1635.         {
  1636.             eptr = eptr->prev;
  1637.             eptr->y_offset = eptr->y_offset + incy;
  1638.         }
  1639.  
  1640.         if ((LineHeight - baseline) > LineBottom)
  1641.         {
  1642.             LineBottom = LineHeight - baseline;
  1643.         }
  1644.     }
  1645. }
  1646.  
  1647.  
  1648. /*
  1649.  * Place the bullet at the beginning of an unnumbered
  1650.  * list item. Create and add the element record for it.
  1651.  */
  1652. void
  1653. BulletPlace(HTMLGadClData * HTML_Data, int *x, int *y)
  1654. {
  1655. //mjw    int width; 
  1656.     int l_height;
  1657.  
  1658.     /*
  1659.      * Save the font's line height, and set your own for this
  1660.      * element.  Restore the fonts height when done.
  1661.      * Deal with bad Lucidia descents.
  1662.      */
  1663.     l_height = LineHeight;
  1664. #ifdef _AMIGA
  1665.     LineHeight = HTML_Data->font->tf_YSize;
  1666. #else
  1667.     if (HTML_Data->font->descent > HTML_Data->font->max_bounds.descent)
  1668.     {
  1669.         LineHeight = HTML_Data->font->tf_YSize +
  1670.             HTML_Data->font->descent;
  1671.     }
  1672.     else
  1673.     {
  1674.         LineHeight = HTML_Data->font->tf_YSize +
  1675.             HTML_Data->font->max_bounds.descent;
  1676.     }
  1677. #endif /* _AMIGA */
  1678.  
  1679.     NeedSpace = 0;
  1680. #ifdef _AMIGA
  1681.     SetFont(HTML_Data->rp, HTML_Data->font);
  1682. //mjw    width = TextLength(HTML_Data->rp, "n", 1) + 1; /* average character? */
  1683. #else /* _AMIGA */
  1684.     width = HTML_Data->font->max_bounds.width;
  1685. #endif /* _AMIGA */
  1686.     SetElement(HTML_Data, E_BULLET, HTML_Data->font, *x - 1, *y, (char *)NULL);
  1687.     LineHeight = l_height;
  1688. /*
  1689.  * This should reall be here, but it is a hack for headers on list
  1690.  * elements to work if we leave it out
  1691.     PF_LF_State = 0;
  1692.  */
  1693. }
  1694.  
  1695.  
  1696. /*
  1697.  * Place a horizontal rule across the page.
  1698.  * Create and add the element record for it.
  1699.  */
  1700. void
  1701. HRulePlace(HTMLGadClData * HTML_Data, int *x, int *y, unsigned int width)
  1702. {
  1703.     NeedSpace = 0;
  1704.     *x = HTML_Data->margin_width;
  1705.     SetElement(HTML_Data, E_HRULE, currentFont, *x, *y, (char *)NULL);
  1706.     *x = *x + width - (2 * HTML_Data->margin_width);
  1707.     NeedSpace = 1;
  1708.     PF_LF_State = 0;
  1709. }
  1710.  
  1711.  
  1712. /*
  1713.  * Place the number at the beginning of an numbered
  1714.  * list item. Create and add the element record for it.
  1715.  */
  1716. void
  1717. ListNumberPlace(HTMLGadClData * HTML_Data, int *x, int *y, int val)
  1718. {
  1719.     int width, my_x;
  1720. //    int dir, ascent, descent;
  1721.     XCharStruct all;
  1722.     char buf[20];
  1723.  
  1724.     sprintf(buf, "%d.", val);
  1725.  
  1726.     SetFont(HTML_Data->rp, HTML_Data->font);
  1727.     width = TextLength(HTML_Data->rp, "n", 1);
  1728.  
  1729.     XTextExtents(currentFont, buf, strlen(buf), &dir,
  1730.         &ascent, &descent, &all);
  1731.     my_x = *x - (width / 2) - all.te_Width;
  1732.     /*
  1733.      * Add a space after thenumber here so it will look right when
  1734.      * cut and pasted from a selection.
  1735.      */
  1736.     width = strlen(buf);
  1737.     buf[width] = ' ';
  1738.     buf[width + 1] = '\0';
  1739.  
  1740.     SetElement(HTML_Data, E_TEXT, currentFont, my_x, *y, buf);
  1741.     AdjustBaseLine();
  1742.     CharsInLine = CharsInLine + strlen(buf);
  1743.  
  1744.     NeedSpace = 0;
  1745. /*
  1746.  * This should reall be here, but it is a hack for headers on list
  1747.  * elements to work if we leave it out
  1748.     PF_LF_State = 0;
  1749.  */
  1750. }
  1751.  
  1752.  
  1753. /*
  1754.  * Place a piece of pre-formatted text. Add an element record for it.
  1755.  */
  1756. void
  1757. PreformatPlace(HTMLGadClData * HTML_Data, struct mark_up *mptr, int *x, int *y,
  1758.            unsigned int width)
  1759. {
  1760.     char *text;
  1761.     char *start;
  1762.     char *end;
  1763.     char *ptr;
  1764.     char tchar;
  1765.     int tab_count, char_cnt;
  1766. //    int len;
  1767. //    int dir, ascent, descent;
  1768.         XCharStruct all;
  1769.     char *line;
  1770.     int line_x;
  1771.  
  1772.     text = mptr->text;
  1773.  
  1774.     line_x = *x;
  1775.     line = CompLine;
  1776.     if (line != NULL)
  1777.     {
  1778.         line[0] = '\0';
  1779.     }
  1780.     end = text;
  1781.     while (*end != '\0')
  1782.     {
  1783.         tab_count = 0;
  1784.         char_cnt = CharsInLine;
  1785.         /*
  1786.          * make start and end point to one word.  A word is either
  1787.          * a lone linefeed, or all whitespace before a word, plus
  1788.          * the text of the word itself.
  1789.          */
  1790.         start = end;
  1791.         /*
  1792.          * Throw out carriage returns and form-feeds
  1793.          */
  1794.         if ((*end == '\r')||(*end == '\f'))
  1795.         {
  1796.             start++;
  1797.             end++;
  1798.         }
  1799.         else if (*end == '\n')
  1800.         {
  1801.             end++;
  1802.             char_cnt++;
  1803.         }
  1804.         else
  1805.         {
  1806.             /*
  1807.              * Should be only spaces and tabs here, so if it
  1808.              * is not a tab, make it a space.
  1809.              * Break on linefeeds, they must be done separately
  1810.              */
  1811.             while (((int)((unsigned char)*end) < 128)&&
  1812.                 (isspace(*end)))
  1813.             {
  1814.                 if (*end == '\n')
  1815.                 {
  1816.                     break;
  1817.                 }
  1818.                 else if (*end == '\t')
  1819.                 {
  1820.                     tab_count++;
  1821.                     char_cnt = ((char_cnt / 8) + 1) * 8;
  1822.                 }
  1823.                 else
  1824.                 {
  1825.                     *end = ' ';
  1826.                     char_cnt++;
  1827.                 }
  1828.                 end++;
  1829.             }
  1830.             while (((int)((unsigned char)*end) > 127)||
  1831.                 ((!isspace(*end))&&(*end != '\0')))
  1832.             {
  1833.                 end++;
  1834.                 char_cnt++;
  1835.             }
  1836.         }
  1837.  
  1838.         /*
  1839.          * Add the word to the end of this line, or insert
  1840.          * a linefeed if the word is a lone linefeed.
  1841.          * tabs expand to 8 spaces.
  1842.          */
  1843.         if (start != end)
  1844.         {
  1845.             int tlen;
  1846.  
  1847.             tchar = *end;
  1848.             *end = '\0';
  1849.  
  1850.             tlen = char_cnt + 1;
  1851.             if (tlen > CompWordLen)
  1852.             {
  1853.                 CompWordLen += COMP_LINE_BUF_LEN;
  1854.                 if (tlen > CompWordLen)
  1855.                 {
  1856.                     CompWordLen = tlen;
  1857.                 }
  1858.                 if (CompWord != NULL)
  1859.                 {
  1860.                     free(CompWord);
  1861.                 }
  1862.                 CompWord = (char *)malloc(CompWordLen);
  1863.             }
  1864.             ptr = CompWord;
  1865.  
  1866.             /*
  1867.              * If we have any tabs, expand them into spaces.
  1868.              */
  1869.             if (tab_count)
  1870.             {
  1871.                 char *p1, *p2;
  1872.                 int i, new;
  1873.  
  1874.                 char_cnt = CharsInLine;
  1875.                 p1 = ptr;
  1876.                 p2 = start;
  1877.                 while (*p2 != '\0')
  1878.                 {
  1879.                     if (*p2 == '\t')
  1880.                     {
  1881.                         new = ((char_cnt / 8) + 1) * 8;
  1882.                         for (i=0; i<(new-char_cnt); i++)
  1883.                         {
  1884.                             *p1++ = ' ';
  1885.                         }
  1886.                         p2++;
  1887.                         char_cnt = new;
  1888.                     }
  1889.                     else
  1890.                     {
  1891.                         *p1++ = *p2++;
  1892.                         char_cnt++;
  1893.                     }
  1894.                 }
  1895.                 *p1 = '\0';
  1896.             }
  1897.             else
  1898.             {
  1899.                 strcpy(ptr, start);
  1900.             }
  1901.  
  1902. #ifdef ASSUME_FIXED_WIDTH_PRE
  1903.             all.te_Width = currentFont->max_bounds.width * strlen(ptr);
  1904. #else
  1905.             XTextExtents(currentFont, ptr, strlen(ptr), &dir,
  1906.                 &ascent, &descent, &all);
  1907. #endif /* ASSUME_FIXED_WIDTH_PRE */
  1908.  
  1909.             if (*start == '\n')
  1910.             {
  1911.                 if ((line != NULL)&&(line[0] != '\0'))
  1912.                 {
  1913.                     SetElement(HTML_Data, E_TEXT, currentFont,
  1914.                             line_x, *y, line);
  1915.                     /*
  1916.                      * Save width here to avoid an 
  1917.                      * XTextExtents call later.
  1918.                      */
  1919.                     Current->width = *x - line_x + 1;
  1920.  
  1921.                     AdjustBaseLine();
  1922.                     PF_LF_State = 0;
  1923.  
  1924.                     line[0] = '\0';
  1925.                 }
  1926.  
  1927.                 HardLineFeed(HTML_Data, x, y);
  1928.                 line_x = *x;
  1929.                 NeedSpace = 0;
  1930.             }
  1931.             else
  1932.             {
  1933.                 char *tptr;
  1934.                 int tlen;
  1935.  
  1936.                 if (line == NULL)
  1937.                 {
  1938.                     tlen = strlen(ptr) + 1;
  1939.                 }
  1940.                 else
  1941.                 {
  1942.                     tlen = strlen(line) +
  1943.                         strlen(ptr) + 1;
  1944.                 }
  1945.                 if (tlen > CompLineLen)
  1946.                 {
  1947.                     CompLineLen += COMP_LINE_BUF_LEN;
  1948.                     if (tlen > CompLineLen)
  1949.                     {
  1950.                         CompLineLen = tlen;
  1951.                     }
  1952.                     tptr = (char *)malloc(CompLineLen);
  1953.                     if (CompLine != NULL)
  1954.                     {
  1955.                         strcpy(tptr, CompLine);
  1956.                         free(CompLine);
  1957.                     }
  1958.                     else
  1959.                     {
  1960.                         tptr[0] = '\0';
  1961.                     }
  1962.                     CompLine = tptr;
  1963.                 }
  1964.                 line = CompLine;
  1965.  
  1966.                 strcat(line, ptr);
  1967.  
  1968.                 *x = *x + all.te_Width;
  1969.                 CharsInLine = CharsInLine + strlen(ptr);
  1970.                 NeedSpace = 1;
  1971.             }
  1972.             *end = tchar;
  1973.         }
  1974.     }
  1975.     if ((line != NULL)&&(line[0] != '\0'))
  1976.     {
  1977.         SetElement(HTML_Data, E_TEXT, currentFont,
  1978.                 line_x, *y, line);
  1979.         /*
  1980.          * Save width here to avoid an 
  1981.          * XTextExtents call later.
  1982.          */
  1983.         Current->width = *x - line_x + 1;
  1984.  
  1985.         AdjustBaseLine();
  1986.         PF_LF_State = 0;
  1987.         line[0] = '\0';
  1988.     }
  1989. }
  1990.  
  1991.  
  1992. /*
  1993.  * Format and place a piece of text. Add an element record for it.
  1994.  */
  1995. void
  1996. FormatPlace(HTMLGadClData * HTML_Data, struct mark_up *mptr, int *x, int *y,
  1997.         unsigned int width)
  1998. {
  1999.     char *text;
  2000.     char *start = NULL;
  2001.     char *end;
  2002.     char *ptr;
  2003.     char tchar;
  2004. //    char tchar2;
  2005.     int stripped_space;
  2006.     int added_space;
  2007.     int double_space;
  2008. //    int len;
  2009. //    int dir, ascent, descent;
  2010.         XCharStruct all;
  2011.     char *line;
  2012.     int line_x;
  2013.  
  2014.     text = mptr->text;
  2015.  
  2016.     line_x = *x;
  2017.     line = CompLine;
  2018.     if (line != NULL)
  2019.     {
  2020.         line[0] = '\0';
  2021.     }
  2022.     end = text;
  2023.     while (*end != '\0')
  2024.     {
  2025.         /*
  2026.          * make start and end point to one word.
  2027.          * set flag if we removed any leading white space.
  2028.          * set flag if we add any leading white space.
  2029.          */
  2030.         stripped_space = 0;
  2031.         added_space = 0;
  2032.  
  2033.         if (start == end) {
  2034.           end++;
  2035.         } else {
  2036.           start = end;
  2037.         }
  2038.         while (((int)((unsigned char)*start) < 128)&&(isspace(*start)))
  2039.         {
  2040.             stripped_space = 1;
  2041.             start++;
  2042.         }
  2043.  
  2044.         end = start;
  2045.         while (((int)((unsigned char)*end) > 127)||(*end < 0)||
  2046.             ((!isspace(*end))&&(*end != '\0')))
  2047.         {
  2048.             end++;
  2049.         }
  2050.  
  2051.         /*
  2052.          * Add the word to the end of this line, or insert
  2053.          * a linefeed an put the word at the start of the next line.
  2054.          */
  2055.         if (start != end)
  2056.         {
  2057.             int nobreak;
  2058.             int tlen;
  2059.  
  2060.             /*
  2061.              * nobreak is a horrible hack that specifies special
  2062.              * conditions where line breaks are just not allowed
  2063.              */
  2064.             nobreak = 0;
  2065.  
  2066.             tchar = *end;
  2067.             *end = '\0';
  2068.  
  2069.             /*
  2070.              * Malloc temp space if needed, leave room for
  2071.              * 2 spaces and a end of string char
  2072.              */
  2073.             tlen = strlen(start) + 3;
  2074.             if (tlen > CompWordLen)
  2075.             {
  2076.                 CompWordLen += COMP_LINE_BUF_LEN;
  2077.                 if (tlen > CompWordLen)
  2078.                 {
  2079.                     CompWordLen = tlen;
  2080.                 }
  2081.                 if (CompWord != NULL)
  2082.                 {
  2083.                     free(CompWord);
  2084.                 }
  2085.                 CompWord = (char *)malloc(CompWordLen);
  2086.             }
  2087.             ptr = CompWord;
  2088.  
  2089.             if ((NeedSpace > 0)&&(stripped_space))
  2090.             {
  2091.                 if (NeedSpace == 2)
  2092.                 {
  2093.                     strcpy(ptr, "  ");
  2094.                     added_space = 2;
  2095.                 }
  2096.                 else
  2097.                 {
  2098.                     strcpy(ptr, " ");
  2099.                     added_space = 1;
  2100.                 }
  2101.             }
  2102.             else
  2103.             {
  2104.                 strcpy(ptr, "");
  2105.             }
  2106.             strcat(ptr, start);
  2107.  
  2108. #ifdef DOUBLE_SPACE_AFTER_PUNCT
  2109.             /*
  2110.              * If this text ends in '.', '!', or '?' we need
  2111.              * to set up the addition of two spaces after it.
  2112.              */
  2113.             tchar2 = ptr[strlen(ptr) - 1];
  2114.             if ((tchar2 == '.')||(tchar2 == '!')||(tchar2 == '?'))
  2115.             {
  2116.                 double_space = 1;
  2117.             }
  2118.             else
  2119.             {
  2120.                 double_space = 0;
  2121.             }
  2122. #else
  2123.             double_space = 0;
  2124. #endif /* DOUBLE_SPACE_AFTER_PUNCT */
  2125.  
  2126.             XTextExtents(currentFont, ptr, strlen(ptr), &dir,
  2127.                 &ascent, &descent, &all);
  2128.  
  2129.             /*
  2130.              * Horrible hack for punctuation following
  2131.              * font changes to not go on the next line.
  2132.              */
  2133.             if ((MY_ISPUNCT(*ptr))&&(added_space == 0))
  2134.             {
  2135.                 char *tptr;
  2136.  
  2137.                 /*
  2138.                  * Take into account whole streams of
  2139.                  * punctuation.
  2140.                  */
  2141.                 nobreak = 1;
  2142.                 tptr = ptr;
  2143.                 while ((*tptr != '\0')&&(MY_ISPUNCT(*tptr)))
  2144.                 {
  2145.                     tptr++;
  2146.                 }
  2147.                 if (*tptr != '\0')
  2148.                 {
  2149.                     nobreak = 0;
  2150.                 }
  2151.             }
  2152.  
  2153.             /*
  2154.              * No linebreaks if this whole line is just too
  2155.              * long.
  2156.              */
  2157.             if (*x == TextIndent)
  2158.             {
  2159.                 nobreak = 1;
  2160.             }
  2161.  
  2162.             if (((*x + all.te_Width + MarginW) <= width)||(nobreak))
  2163.             {
  2164.                 char *tptr;
  2165.                 int tlen;
  2166.  
  2167.                 if (line == NULL)
  2168.                 {
  2169.                     tlen = strlen(ptr) + 1;
  2170.                 }
  2171.                 else
  2172.                 {
  2173.                     tlen = strlen(line) +
  2174.                         strlen(ptr) + 1;
  2175.                 }
  2176.                 if (tlen > CompLineLen)
  2177.                 {
  2178.                     CompLineLen += COMP_LINE_BUF_LEN;
  2179.                     if (tlen > CompLineLen)
  2180.                     {
  2181.                         CompLineLen = tlen;
  2182.                     }
  2183.                     tptr = (char *)malloc(CompLineLen);
  2184.                     if (CompLine != NULL)
  2185.                     {
  2186.                         strcpy(tptr, CompLine);
  2187.                         free(CompLine);
  2188.                     }
  2189.                     else
  2190.                     {
  2191.                         tptr[0] = '\0';
  2192.                     }
  2193.                     CompLine = tptr;
  2194.                 }
  2195.                 line = CompLine;
  2196.  
  2197.                 strcat(line, ptr);
  2198.             }
  2199.             else
  2200.             {
  2201.                 char *tptr, *tptr2;
  2202.                 int tlen;
  2203.  
  2204.                 if ((line != NULL)&&(line[0] != '\0'))
  2205.                 {
  2206.                     SetElement(HTML_Data, E_TEXT, currentFont,
  2207.                             line_x, *y, line);
  2208.                     /*
  2209.                      * Save width here to avoid an 
  2210.                      * XTextExtents call later.
  2211.                      */
  2212.                     Current->width = *x - line_x + 1;
  2213.  
  2214.                     AdjustBaseLine();
  2215.                     PF_LF_State = 0;
  2216.  
  2217.                     line[0] = '\0';
  2218.                 }
  2219.  
  2220.                 LineFeed(HTML_Data, x, y);
  2221.                 line_x = *x;
  2222.  
  2223.                 /*
  2224.                  * If we added a space before, remove it now
  2225.                  * since we are at the beginning of a new line
  2226.                  */
  2227.                 if (added_space)
  2228.                 {
  2229.                     tptr2 = (char *)(ptr + added_space);
  2230.                 }
  2231.                 else
  2232.                 {
  2233.                     tptr2 = ptr;
  2234.                 }
  2235.                 XTextExtents(currentFont, tptr2,
  2236.                     strlen(tptr2), &dir,
  2237.                     &ascent, &descent, &all);
  2238.  
  2239.                 if (line == NULL)
  2240.                 {
  2241.                     tlen = strlen(tptr2) + 1;
  2242.                 }
  2243.                 else
  2244.                 {
  2245.                     tlen = strlen(line) +
  2246.                         strlen(tptr2) + 1;
  2247.                 }
  2248.                 if (tlen > CompLineLen)
  2249.                 {
  2250.                     CompLineLen += COMP_LINE_BUF_LEN;
  2251.                     if (tlen > CompLineLen)
  2252.                     {
  2253.                         CompLineLen = tlen;
  2254.                     }
  2255.                     tptr = (char *)malloc(CompLineLen);
  2256.                     if (CompLine != NULL)
  2257.                     {
  2258.                         strcpy(tptr, CompLine);
  2259.                         free(CompLine);
  2260.                     }
  2261.                     else
  2262.                     {
  2263.                         tptr[0] = '\0';
  2264.                     }
  2265.                     CompLine = tptr;
  2266.                 }
  2267.                 line = CompLine;
  2268.  
  2269.                 strcat(line, tptr2);
  2270.             }
  2271.  
  2272.             /*
  2273.              * Set NeedSpace for one or 2 spaces based on
  2274.              * whether we are after a '.', '!', or '?'
  2275.              * or not.
  2276.              */
  2277.             if (double_space)
  2278.             {
  2279.                 NeedSpace = 2;
  2280.             }
  2281.             else
  2282.             {
  2283.                 NeedSpace = 1;
  2284.             }
  2285.  
  2286.             *x = *x + all.te_Width;
  2287.             *end = tchar;
  2288.         }
  2289.         /*
  2290.          * Else if there is trailing whitespace, add it now
  2291.          */
  2292.         else if ((NeedSpace > 0)&&(stripped_space))
  2293.         {
  2294.             char *tptr;
  2295.             char *spc;
  2296.             int tlen;
  2297.  
  2298.             if (NeedSpace == 2)
  2299.             {
  2300.                 spc = (char *)malloc(strlen("  ") + 1);
  2301.                 strcpy(spc, "  ");
  2302.             }
  2303.             else
  2304.             {
  2305.                 spc = (char *)malloc(strlen(" ") + 1);
  2306.                 strcpy(spc, " ");
  2307.             }
  2308.  
  2309.             XTextExtents(currentFont, spc, strlen(spc), &dir,
  2310.                 &ascent, &descent, &all);
  2311.  
  2312.             /*
  2313.              * Sigh, adding this one little space might force a
  2314.              * line break.
  2315.              */
  2316.             if ((*x + all.te_Width + MarginW) <= width)
  2317.             {
  2318.                 if (line == NULL)
  2319.                 {
  2320.                     tlen = strlen(spc) + 1;
  2321.                 }
  2322.                 else
  2323.                 {
  2324.                     tlen = strlen(line) +
  2325.                         strlen(spc) + 1;
  2326.                 }
  2327.                 if (tlen > CompLineLen)
  2328.                 {
  2329.                     CompLineLen += COMP_LINE_BUF_LEN;
  2330.                     if (tlen > CompLineLen)
  2331.                     {
  2332.                         CompLineLen = tlen;
  2333.                     }
  2334.                     tptr = (char *)malloc(CompLineLen);
  2335.                     if (CompLine != NULL)
  2336.                     {
  2337.                         strcpy(tptr, CompLine);
  2338.                         free(CompLine);
  2339.                     }
  2340.                     else
  2341.                     {
  2342.                         tptr[0] = '\0';
  2343.                     }
  2344.                     CompLine = tptr;
  2345.                 }
  2346.                 line = CompLine;
  2347.  
  2348.                 strcat(line, spc);
  2349.             }
  2350.             /*
  2351.              * Ok, the space forced a linefeed, but now we must
  2352.              * also drop the space since we don't want it if we
  2353.              * have a linefeed here.
  2354.              */
  2355.             else
  2356.             {
  2357.                 if ((line != NULL)&&(line[0] != '\0'))
  2358.                 {
  2359.                     SetElement(HTML_Data, E_TEXT, currentFont,
  2360.                             line_x, *y, line);
  2361.                     /*
  2362.                      * Save width here to avoid an 
  2363.                      * XTextExtents call later.
  2364.                      */
  2365.                     Current->width = *x - line_x + 1;
  2366.  
  2367.                     AdjustBaseLine();
  2368.                     PF_LF_State = 0;
  2369.  
  2370.                     line[0] = '\0';
  2371.                 }
  2372.  
  2373.                 LineFeed(HTML_Data, x, y);
  2374.                 line_x = *x;
  2375.  
  2376.                 all.te_Width = 0;
  2377.             }
  2378.  
  2379.             *x = *x + all.te_Width;
  2380.             if (spc)
  2381.                 free(spc);
  2382.             NeedSpace = 0;
  2383.         }
  2384.     }
  2385.     if ((line != NULL)&&(line[0] != '\0'))
  2386.     {
  2387.         SetElement(HTML_Data, E_TEXT, currentFont,
  2388.                 line_x, *y, line);
  2389.         /*
  2390.          * Save width here to avoid an 
  2391.          * XTextExtents call later.
  2392.          */
  2393.         Current->width = *x - line_x + 1;
  2394.  
  2395.         AdjustBaseLine();
  2396.         PF_LF_State = 0;
  2397.         line[0] = '\0';
  2398.     }
  2399. }
  2400.  
  2401.  
  2402. /*
  2403.  * Place an image. Add an element record for it.
  2404.  */
  2405. void
  2406. ImagePlace(HTMLGadClData * HTML_Data, struct mark_up *mptr, int *x, int *y, unsigned int width)
  2407. {
  2408.     char *tptr;
  2409.  
  2410. #ifdef SPACE_HACK
  2411.     /*
  2412.      * If we are starting an image in formatted
  2413.      * text, and it needs a preceeding space, add
  2414.      * that space now.
  2415.      */
  2416.     if ((!Preformat)&&(NeedSpace > 0))
  2417.     {
  2418.         int dir, ascent, descent;
  2419.         XCharStruct all;
  2420.  
  2421.         if (NeedSpace == 2)
  2422.         {
  2423.             tptr = (char *)malloc(strlen("  ") + 1);
  2424.             strcpy(tptr, "  ");
  2425.         }
  2426.         else
  2427.         {
  2428.             tptr = (char *)malloc(strlen(" ") + 1);
  2429.             strcpy(tptr, " ");
  2430.         }
  2431.  
  2432.         XTextExtents(currentFont, tptr,
  2433.             strlen(tptr), &dir, &ascent,
  2434.             &descent, &all);
  2435.         SetElement(HTML_Data, E_TEXT, currentFont,
  2436.             *x, *y, tptr);
  2437.         /*
  2438.          * Save width here to avoid an 
  2439.          * XTextExtents call later.
  2440.          */
  2441.         Current->width = all.te_Width;
  2442.  
  2443.         AdjustBaseLine();
  2444.         *x = *x + all.te_Width;
  2445.         CharsInLine = CharsInLine + strlen(tptr);
  2446.                 if (tptr)
  2447.                   free(tptr);
  2448.         PF_LF_State = 0;
  2449.         NeedSpace = 0;
  2450.     }
  2451. #endif /* SPACE_HACK */
  2452.  
  2453.     tptr = ParseMarkTag(mptr->start, MT_IMAGE, "SRC");
  2454.     SetElement(HTML_Data, E_IMAGE, currentFont, *x, *y + 1, tptr);
  2455.  
  2456.     /*
  2457.      * Only after we have placed the image do we know its dimensions.
  2458.      * So now look and see if the image is too wide, and if so go
  2459.      * back and insert a linebreak.
  2460.      */
  2461.     if ((Current->pic_data != NULL)&&(!Preformat))
  2462.     {
  2463.         int extra;
  2464.  
  2465.         if ((HTML_Data->border_images == True)||
  2466.             ((Current->anchorHRef != NULL)&&
  2467.             (!Current->pic_data->internal)))
  2468.         {
  2469.             extra = 2 * IMAGE_BORDER;
  2470.         }
  2471.         else
  2472.         {
  2473.             extra = 0;
  2474.         }
  2475.  
  2476.         if (((*x + Current->pic_data->width + extra + MarginW) >width)&&
  2477.             (Current->prev != NULL)&&
  2478.             (Current->prev->line_number == LineNumber))
  2479.         {
  2480.             Current = Current->prev;
  2481.             LineFeed(HTML_Data, x, y);
  2482.             SetElement(HTML_Data, E_IMAGE, currentFont, *x, *y + 1, tptr);
  2483.         }
  2484.     }
  2485.     /*
  2486.      * Clean up parsed SRC string
  2487.      */
  2488.     if (tptr != NULL)
  2489.     {
  2490.         free(tptr);
  2491.     }
  2492.  
  2493.     /*
  2494.      * Yank out the name field, and stick it in text.
  2495.      * We may use this for ALT to at some later date.
  2496.      */
  2497.     if (Current->pic_data != NULL) 
  2498.     {
  2499.         tptr = ParseMarkTag(mptr->start, MT_IMAGE, "NAME");
  2500.         Current->pic_data->text = tptr;
  2501.     }
  2502.  
  2503.     /*
  2504.      * Check if this image has the ISMAP attribute, so we know the
  2505.      * x,y coordinates of the image click are important.
  2506.      * Due to a special case (see below), this code can acutally
  2507.      * change the size, or anchor status of the image, thus we MUST
  2508.      * doit before we muck with the Baseline and stuff.
  2509.      */
  2510.     if (Current->pic_data != NULL) 
  2511.     {
  2512.         Current->pic_data->fptr = NULL;
  2513.         tptr = ParseMarkTag(mptr->start, MT_IMAGE, "ISMAP");
  2514.         if (tptr != NULL)
  2515.         {
  2516.             free(tptr);
  2517.             Current->pic_data->ismap = 1;
  2518.             /*
  2519.              * SUPER SPECIAL CASE!  (Thanks Marc)
  2520.              * If you have an ISMAP image inside a form,
  2521.              * And that form doesn't already have an HREF
  2522.              * by being inside an anchor,
  2523.              * (Being a DelayedHRef is considered no href)
  2524.              * clicking in that image will submit the form,
  2525.              * adding the x,y coordinates of the click as part
  2526.              * of the list of name/value pairs.
  2527.              */
  2528.             if ((CurrentForm != NULL)&&
  2529.                 ((Current->anchorHRef == NULL)||
  2530.                 (IsDelayedHRef(HTML_Data, Current->anchorHRef))))
  2531.             {
  2532.                 Current->pic_data->fptr = CurrentForm;
  2533.                 Current->anchorHRef = IsMapForm(HTML_Data);
  2534.                 Current->fg = HTML_Data->anchor_fg;
  2535.             }
  2536.         }
  2537.         else
  2538.         {
  2539.             Current->pic_data->ismap = 0;
  2540.         }
  2541.     }
  2542.  
  2543.     /*
  2544.      * Check if this image will be top aligned
  2545.      */
  2546.     tptr = ParseMarkTag(mptr->start, MT_IMAGE, "ALIGN");
  2547.     if (caseless_equal(tptr, "TOP"))
  2548.     {
  2549.         Current->alignment = ALIGN_TOP;
  2550.     }
  2551.     else if (caseless_equal(tptr, "MIDDLE"))
  2552.     {
  2553.         Current->alignment = ALIGN_MIDDLE;
  2554.     }
  2555.     else
  2556.     {
  2557.         Current->alignment = ALIGN_BOTTOM;
  2558.     }
  2559.     /*
  2560.      * Clean up parsed ALIGN string
  2561.      */
  2562.     if (tptr != NULL)
  2563.     {
  2564.         free(tptr);
  2565.     }
  2566.  
  2567.     /*
  2568.      * Advance x position, and check the max
  2569.      * line height.  We need to follow this
  2570.      * image with a space.
  2571.      */
  2572.     if (Current->pic_data != NULL)
  2573.     {
  2574.         int extra;
  2575.  
  2576.         if ((HTML_Data->border_images == True)||
  2577.             ((Current->anchorHRef != NULL)&&
  2578.             (!Current->pic_data->internal)))
  2579.         {
  2580.             extra = 2 * IMAGE_BORDER;
  2581.         }
  2582.         else
  2583.         {
  2584.             extra = 0;
  2585.         }
  2586.  
  2587.         if (BaseLine == -100)
  2588.         {
  2589.             BaseLine = 0;
  2590.         }
  2591.  
  2592.         *x = *x + Current->pic_data->width + extra;
  2593.  
  2594.         if (Current->alignment == ALIGN_TOP)
  2595.         {
  2596.             Current->y_offset = 0;
  2597.  
  2598.             if ((Current->pic_data->height + extra - BaseLine) >
  2599.                 LineBottom)
  2600.             {
  2601.                 LineBottom = Current->pic_data->height + extra -
  2602.                     BaseLine;
  2603.             }
  2604.         }
  2605.         else if (Current->alignment == ALIGN_MIDDLE)
  2606.         {
  2607.             int baseline;
  2608.  
  2609.             baseline = (Current->pic_data->height + extra) / 2;
  2610.  
  2611.             if (baseline <= BaseLine)
  2612.             {
  2613.                 Current->y_offset = BaseLine - baseline;
  2614.             }
  2615.             else
  2616.             {
  2617.                 struct ele_rec *eptr;
  2618.                 int line, incy;
  2619.  
  2620.                 Current->y_offset = 0;
  2621.  
  2622.                 incy = baseline - BaseLine;
  2623.                 BaseLine = baseline;
  2624.  
  2625.                 /*
  2626.                  * Go back over this line
  2627.                  * and move everything down
  2628.                  * a little.
  2629.                  */
  2630.                 eptr = Current;
  2631.                 line = eptr->line_number;
  2632.                 while ((eptr->prev != NULL)&&
  2633.                     (eptr->prev->line_number == line))
  2634.                 {
  2635.                     eptr = eptr->prev;
  2636.                     eptr->y_offset = eptr->y_offset + incy;
  2637.                 }
  2638.             }
  2639.  
  2640.             if ((Current->pic_data->height + extra - BaseLine) >
  2641.                 LineBottom)
  2642.             {
  2643.                 LineBottom = Current->pic_data->height + extra -
  2644.                     BaseLine;
  2645.             }
  2646.         }
  2647.         else if ((Current->pic_data->height + extra) <= BaseLine)
  2648.         {
  2649.             Current->y_offset = BaseLine -
  2650.                 (Current->pic_data->height + extra);
  2651.         }
  2652.         else if ((Current->pic_data->height + extra) > BaseLine)
  2653.         {
  2654.             struct ele_rec *eptr;
  2655.             int line, incy;
  2656.  
  2657.             incy = Current->pic_data->height + extra - BaseLine;
  2658.             BaseLine = Current->pic_data->height + extra;
  2659.  
  2660.             /*
  2661.              * Go back over this line
  2662.              * and move everything down
  2663.              * a little.
  2664.              */
  2665.             eptr = Current;
  2666.             line = eptr->line_number;
  2667.             while ((eptr->prev != NULL)&&
  2668.                 (eptr->prev->line_number == line))
  2669.             {
  2670.                 eptr = eptr->prev;
  2671.                 eptr->y_offset = eptr->y_offset + incy;
  2672.             }
  2673.         }
  2674.  
  2675.         if (BaseLine == 0)
  2676.         {
  2677.             BaseLine = -100;
  2678.         }
  2679.     }
  2680.     PF_LF_State = 0;
  2681.     NeedSpace = 1;
  2682. }
  2683.  
  2684. // #ifndef _AMIGA
  2685. /*
  2686.  * Place an Widget. Add an element record for it.
  2687.  */
  2688. void
  2689. WidgetPlace(HTMLGadClData * HTML_Data, struct mark_up *mptr, int *x, int *y, unsigned int width)
  2690. {
  2691.     char *tptr;
  2692.  
  2693.     SetElement(HTML_Data, E_WIDGET, currentFont, *x, *y, mptr->start);
  2694.  
  2695.     /*
  2696.      * Only after we have placed the widget do we know its dimensions.
  2697.      * So now look and see if the widget is too wide, and if so go
  2698.      * back and insert a linebreak.
  2699.      */
  2700.     if ((Current->widget_data != NULL)&&(!Preformat))
  2701.     {
  2702.         int extra;
  2703.  
  2704.         extra = 2 * IMAGE_BORDER;
  2705.  
  2706.         if (((*x + Current->widget_data->width + extra + MarginW) >
  2707.             width)&&
  2708.             (Current->prev != NULL)&&
  2709.             (Current->prev->line_number == LineNumber))
  2710.         {
  2711.             WidgetId--;
  2712.             Current = Current->prev;
  2713.             LineFeed(HTML_Data, x, y);
  2714.             SetElement(HTML_Data, E_WIDGET, currentFont, *x, *y,
  2715.                 mptr->start);
  2716.         }
  2717.     }
  2718.  
  2719.     /*
  2720.      * Advance x position, and check BaseLine and LineBottom.
  2721.      * We need to follow this widget with a space.
  2722.      */
  2723.     if (Current->widget_data != NULL)
  2724.     {
  2725.         int extra;
  2726.         int baseline;
  2727.         XFontStruct *fp;
  2728.  
  2729.         extra = 2 * IMAGE_BORDER;
  2730.  
  2731.         /*
  2732.          * Find the font used in this widget.  Then find its baseline
  2733.          */
  2734. //sb        fp = GetWidgetFont(HTML_Data, Current->widget_data);
  2735. //sb        if (fp == NULL)
  2736.         {
  2737.             baseline = Current->widget_data->height - 4; //- extra;
  2738.         }
  2739.         /*
  2740.          * If no font, the baseline is the bottum of the widget
  2741.          */
  2742. //sb        else
  2743. //sb        {
  2744. //sb            int border;
  2745. //sb
  2746. //sb            border = ((Current->widget_data->height + extra) -
  2747. //sb                (fp->tf_YSize + fp->max_bounds.descent));
  2748. //sb            baseline = (border / 2) + fp->tf_YSize;
  2749. //sb        }
  2750.  
  2751.         /*
  2752.          * Baseline == -100 is the special unset baseline value.
  2753.          */
  2754.         if (BaseLine == -100)
  2755.         {
  2756.             BaseLine = baseline;
  2757.             Current->y_offset = 0;
  2758.             /*
  2759.              * If linebottom isn't set, set it to
  2760.              * whatever of the height is below the baseline.
  2761.              */
  2762.             if (LineBottom == 0)
  2763.             {
  2764.                 LineBottom = Current->widget_data->height +
  2765.                     extra - baseline;
  2766.             }
  2767.             /*
  2768.              * Else, it is possible that a linebottom has been
  2769.              * set even when we have no baseline yet (like if
  2770.              * the first item in the line was a top aligned image)
  2771.              * It now needs to be corrected as we set a real
  2772.              * BaseLine.
  2773.              */
  2774.             else
  2775.             {
  2776.                 if ((Current->widget_data->height +
  2777.                     extra - baseline) >
  2778.                     (LineBottom - baseline))
  2779.                 {
  2780.                     LineBottom =
  2781.                         Current->widget_data->height +
  2782.                         extra - baseline;
  2783.                 }
  2784.                 else
  2785.                 {
  2786.                     LineBottom = LineBottom - baseline;
  2787.                 }
  2788.             }
  2789.         }
  2790.         /*
  2791.          * Else we already have a baseline, and it is greater that
  2792.          * the baseline for this widget.
  2793.          * Set y_offset, and check linebottom.
  2794.          */
  2795.         else if (baseline <= BaseLine)
  2796.         {
  2797.             if (baseline < BaseLine)
  2798.             {
  2799.                 Current->y_offset = BaseLine - baseline;
  2800.             }
  2801.             else
  2802.             {
  2803.                 Current->y_offset = 0;
  2804.             }
  2805.  
  2806.             /*
  2807.              * Our line bottom may be greater than the
  2808.              * old one.
  2809.              */
  2810.             if ((Current->widget_data->height + extra - baseline) >
  2811.                 LineBottom)
  2812.             {
  2813.                 LineBottom = Current->widget_data->height +
  2814.                     extra - baseline;
  2815.             }
  2816.         }
  2817.         else
  2818.         /*
  2819.          * Else we have a new baseline greater than the old baseline.
  2820.          */
  2821.         {
  2822.             struct ele_rec *eptr;
  2823.             int line, incy;
  2824.  
  2825.             /*
  2826.              * Figure out how much to move all the old stuff
  2827.              */
  2828.             incy = baseline - BaseLine;
  2829.             BaseLine = baseline;
  2830.  
  2831.             /*
  2832.              * Go back over this line
  2833.              * and move everything down
  2834.              * a little.
  2835.              */
  2836.             eptr = Current;
  2837.             line = eptr->line_number;
  2838.             while ((eptr->prev != NULL)&&
  2839.                 (eptr->prev->line_number == line))
  2840.             {
  2841.                 eptr = eptr->prev;
  2842.                 eptr->y_offset = eptr->y_offset + incy;
  2843.             }
  2844.  
  2845.             /*
  2846.              * Our line bottom may be greater than the
  2847.              * old one.
  2848.              */
  2849.             if ((Current->widget_data->height + extra - baseline) >
  2850.                 LineBottom)
  2851.             {
  2852.                 LineBottom = Current->widget_data->height +
  2853.                     extra - baseline;
  2854.             }
  2855.         }
  2856.  
  2857.         /*
  2858.          * Advance the X position.
  2859.          */
  2860.         *x = *x + Current->widget_data->width + extra;
  2861.     }
  2862.     PF_LF_State = 0;
  2863.     NeedSpace = 1;
  2864. }
  2865. // #endif /* _AMIGA */
  2866.  
  2867. static void
  2868. PushFont(XFontStruct *font)
  2869. {
  2870.     FontRec *fptr;
  2871.  
  2872.     fptr = (FontRec *)malloc(sizeof(FontRec));
  2873.     if (fptr == NULL)
  2874.     {
  2875.         fprintf(stderr, "No memory to expand font stack!\n");
  2876.         return;
  2877.     }
  2878.  
  2879.     fptr->font = font;
  2880.     fptr->next = FontStack;
  2881.     FontStack = fptr;
  2882. }
  2883.  
  2884.  
  2885. static XFontStruct *
  2886. PopFont(void)
  2887. {
  2888.     XFontStruct *font;
  2889.     FontRec *fptr;
  2890.  
  2891.     if (FontStack->next != NULL)
  2892.     {
  2893.         fptr = FontStack;
  2894.         FontStack = FontStack->next;
  2895.         font = fptr->font;
  2896.         free((char *)fptr);
  2897.     }
  2898.     else
  2899.     {
  2900. #ifdef VERBOSE
  2901.         fprintf(stderr, "Warning, popping empty font stack!\n");
  2902. #endif
  2903.         font = FontStack->font;
  2904.     }
  2905.  
  2906.     return(font);
  2907. }
  2908.  
  2909.  
  2910. /*
  2911.  * We've just terminated the current OPTION.
  2912.  * Put it in the proper place in the SelectInfo structure.
  2913.  * Move option_bufinto options, and maybe copy into
  2914.  * value if is_value is set.
  2915.  */
  2916. static void
  2917. ProcessOption(SelectInfo *sptr)
  2918. {
  2919.     int i, cnt;
  2920.     char **tarray;
  2921.  
  2922.     clean_white_space(sptr->option_buf);
  2923.     tarray = sptr->options;
  2924.     cnt = sptr->option_cnt + 1;
  2925.     sptr->options = (char **)malloc(sizeof(char *) * cnt);
  2926.     for (i=0; i<(cnt - 1); i++)
  2927.     {
  2928.         sptr->options[i] = tarray[i];
  2929.     }
  2930.     if (tarray != NULL)
  2931.     {
  2932.         free((char *)tarray);
  2933.     }
  2934.     sptr->options[cnt - 1] = sptr->option_buf;
  2935.     sptr->option_cnt = cnt;
  2936.  
  2937.     tarray = sptr->returns;
  2938.     cnt = sptr->option_cnt;
  2939.     sptr->returns = (char **)malloc(sizeof(char *) * cnt);
  2940.     for (i=0; i<(cnt - 1); i++)
  2941.     {
  2942.         sptr->returns[i] = tarray[i];
  2943.     }
  2944.     if (tarray != NULL)
  2945.     {
  2946.         free((char *)tarray);
  2947.     }
  2948.     if(sptr->retval_buf)
  2949.         sptr->returns[cnt - 1] = sptr->retval_buf;
  2950.     else
  2951.         sptr->returns[cnt - 1] = strdup(sptr->option_buf);
  2952.  
  2953.     if (sptr->is_value)
  2954.     {
  2955.         tarray = sptr->value;
  2956.         cnt = sptr->value_cnt + 1;
  2957.         sptr->value = (char **)malloc(sizeof(char *) * cnt);
  2958.         for (i=0; i<(cnt - 1); i++)
  2959.         {
  2960.             sptr->value[i] = tarray[i];
  2961.         }
  2962.         if (tarray != NULL)
  2963.         {
  2964.             free((char *)tarray);
  2965.         }
  2966.         sptr->value[cnt - 1] = (char *)malloc(
  2967.             strlen(sptr->option_buf) + 1);
  2968.         strcpy(sptr->value[cnt - 1], sptr->option_buf);
  2969.         sptr->value_cnt = cnt;
  2970.     }
  2971. }
  2972.  
  2973. /*
  2974.  * Horrible code for the TEXTAREA element.  Escape '\' and ''' by
  2975.  * putting a '\' in front of them, then replace all '"' with '''.
  2976.  * This lets us safely put the resultant value between double quotes.
  2977.  */
  2978. char *
  2979. TextAreaAddValue(char *value, char *text)
  2980. {
  2981.     int extra;
  2982.     char *buf;
  2983.     char *bptr;
  2984.     char *tptr;
  2985.  
  2986.     if ((text == NULL)||(text[0] == '\0'))
  2987.     {
  2988.         return(value);
  2989.     }
  2990.  
  2991.     extra = 0;
  2992.     tptr = text;
  2993.     while (*tptr != '\0')
  2994.     {
  2995.         if (*tptr == '\\')
  2996.         {
  2997.             extra++;
  2998.         }
  2999.         else if (*tptr == '\'')
  3000.         {
  3001.             extra++;
  3002.         }
  3003.         tptr++;
  3004.     }
  3005.  
  3006.     buf = (char *)malloc(strlen(value) + strlen(text) + extra + 1);
  3007.     if (buf == NULL)
  3008.     {
  3009.         return(value);
  3010.     }
  3011.     strcpy(buf, value);
  3012.  
  3013.     tptr = text;
  3014.     bptr = (char *)(buf + strlen(value));
  3015.     while (*tptr != '\0')
  3016.     {
  3017.         if ((*tptr == '\\')||(*tptr == '\''))
  3018.         {
  3019.             *bptr++ = '\\';
  3020.             *bptr++ = *tptr++;
  3021.         }
  3022.         else if (*tptr == '\"')
  3023.         {
  3024.             *bptr++ = '\'';
  3025.             tptr++;
  3026.         }
  3027.         else
  3028.         {
  3029.             *bptr++ = *tptr++;
  3030.         }
  3031.     }
  3032.     *bptr = '\0';
  3033.  
  3034.     free(value);
  3035.     return(buf);
  3036. }
  3037.  
  3038.  
  3039. /*
  3040.  * Make necessary changes to formatting, based on the type of the
  3041.  * parsed HTML text we are formatting.
  3042.  * Some calls create elements that are added to the formatted element list.
  3043.  */
  3044. void
  3045. TriggerMarkChanges(HTMLGadClData * HTML_Data, struct mark_up *mptr, int *x, int *y)
  3046. {
  3047.     struct mark_up *mark;
  3048.     XFontStruct *font;
  3049.     int type, width;
  3050.  
  3051.     mark = mptr;
  3052.     type = mark->type;
  3053.     font = NULL;
  3054.  
  3055.     /*
  3056.      * If Ignore is set, we ignore all further elements until we get to the
  3057.      * end of the Ignore
  3058.      * Let text through so we can grab the title text.
  3059.      * Let title through so we can hit the end title.
  3060.      * Now also used for SELECT parseing
  3061.      * Let SELECT through so we can hit the end SELECT.
  3062.      * Let OPTION through so we can hit the OPTIONs.
  3063.      * Let TEXTAREA through so we can hit the TEXTAREAs.
  3064.      */
  3065.     if ((Ignore)&&(type != M_TITLE)&&(type != M_NONE)&&
  3066.         (type != M_SELECT)&&(type != M_OPTION)&&
  3067.         (type != M_TEXTAREA))
  3068.     {
  3069.         return;
  3070.     }
  3071.  
  3072.     switch(type)
  3073.     {
  3074.         /*
  3075.          * Place the text.  Different functions based on whether it
  3076.          * is pre-formatted or not.
  3077.          */
  3078.         case M_NONE:
  3079.             if ((Ignore)&&(CurrentSelect == NULL)&&
  3080.                 (TextAreaBuf == NULL))
  3081.             {
  3082.                 if (TitleText == NULL)
  3083.                 {
  3084.                     TitleText = (char *)
  3085.                         malloc(strlen(mptr->text) + 1);
  3086.                     strcpy(TitleText, mptr->text);
  3087.                 }
  3088.                 else
  3089.                 {
  3090.                     char *tptr;
  3091.  
  3092.                     tptr = (char *)
  3093.                         malloc(strlen(TitleText) +
  3094.                                strlen(mptr->text) + 1);
  3095.                     strcpy(tptr, TitleText);
  3096.                     strcat(tptr, mptr->text);
  3097.                     free(TitleText);
  3098.                     TitleText = tptr;
  3099.                 }
  3100.             }
  3101.             else if ((Ignore)&&(CurrentSelect != NULL))
  3102.             {
  3103.                 if (CurrentSelect->option_buf != NULL)
  3104.                 {
  3105.                     char *tptr;
  3106.  
  3107.                     tptr = (char *)malloc(strlen(
  3108.                         CurrentSelect->option_buf) +
  3109.                                strlen(mptr->text) + 1);
  3110.                     strcpy(tptr, CurrentSelect->option_buf);
  3111.                     strcat(tptr, mptr->text);
  3112.                     free(CurrentSelect->option_buf);
  3113.                     CurrentSelect->option_buf = tptr;
  3114.                 }
  3115.             }
  3116.             else if ((Ignore)&&(TextAreaBuf != NULL))
  3117.             {
  3118.                 TextAreaBuf = TextAreaAddValue(TextAreaBuf,
  3119.                     mptr->text);
  3120.             }
  3121.             else if (Preformat)
  3122.             {
  3123.                 PreformatPlace(HTML_Data, mptr, x, y, Width);
  3124.             }
  3125.             else
  3126.             {
  3127.                 FormatPlace(HTML_Data, mptr, x, y, Width);
  3128.             }
  3129.             break;
  3130.         /*
  3131.          * Titles are just set into the widget for retrieval by
  3132.          * XtGetValues().
  3133.          */
  3134.         case M_TITLE:
  3135.             if (mark->is_end)
  3136.             {
  3137.                 Ignore = 0;
  3138.                 HTML_Data->title = TitleText;
  3139.                 TitleText = NULL;
  3140.             }
  3141.             else
  3142.             {
  3143.                 Ignore = 1;
  3144.                 TitleText = NULL;
  3145.             }
  3146.             break;
  3147.         /*
  3148.          * Formatting commands just change the current font.
  3149.          */
  3150.         case M_CODE:
  3151.         case M_SAMPLE:
  3152.         case M_KEYBOARD:
  3153.         case M_FIXED:
  3154.             if (mark->is_end)
  3155.             {
  3156.                 font = PopFont();
  3157.             }
  3158.             else
  3159.             {
  3160.                 PushFont(currentFont);
  3161.                 font = HTML_Data->fixed_font;
  3162.             }
  3163.             break;
  3164.         case M_STRONG:
  3165.         case M_BOLD:
  3166.             if (mark->is_end)
  3167.             {
  3168.                 font = PopFont();
  3169.             }
  3170.             else
  3171.             {
  3172.                 PushFont(currentFont);
  3173.                 font = HTML_Data->bold_font;
  3174.             }
  3175.             break;
  3176.         case M_EMPHASIZED:
  3177.         case M_VARIABLE:
  3178.         case M_CITATION:
  3179.         case M_ITALIC:
  3180.             if (mark->is_end)
  3181.             {
  3182.                 font = PopFont();
  3183.             }
  3184.             else
  3185.             {
  3186.                 PushFont(currentFont);
  3187.                 font = HTML_Data->italic_font;
  3188.             }
  3189.             break;
  3190.         /*
  3191.          * Strikeout means draw a line through the text.
  3192.          * Right now we just set a boolean flag which gets shoved
  3193.          * in the element record for all elements in the
  3194.          * strikeout zone.
  3195.          */
  3196.         case M_STRIKEOUT:
  3197.             if (mark->is_end)
  3198.             {
  3199.                 Strikeout = False;
  3200.             }
  3201.             else
  3202.             {
  3203.                 Strikeout = True;
  3204.             }
  3205.             break;
  3206.         /*
  3207.          * Headers are preceeded and followed by a linefeed,
  3208.          * and the change the font.
  3209.          */
  3210.         case M_HEADER_1:
  3211.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3212.             if (mark->is_end)
  3213.             {
  3214.                 font = PopFont();
  3215.                 NewFont(font);
  3216.                 currentFont = font;
  3217.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3218.             }
  3219.             else
  3220.             {
  3221.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3222.                 PushFont(currentFont);
  3223.                 font = HTML_Data->header1_font;
  3224.             }
  3225.             break;
  3226.         case M_HEADER_2:
  3227.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3228.             if (mark->is_end)
  3229.             {
  3230.                 font = PopFont();
  3231.                 NewFont(font);
  3232.                 currentFont = font;
  3233.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3234.             }
  3235.             else
  3236.             {
  3237.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3238.                 PushFont(currentFont);
  3239.                 font = HTML_Data->header2_font;
  3240.             }
  3241.             break;
  3242.         case M_HEADER_3:
  3243.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3244.             if (mark->is_end)
  3245.             {
  3246.                 font = PopFont();
  3247.                 NewFont(font);
  3248.                 currentFont = font;
  3249.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3250.             }
  3251.             else
  3252.             {
  3253.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3254.                 PushFont(currentFont);
  3255.                 font = HTML_Data->header3_font;
  3256.             }
  3257.             break;
  3258.         case M_HEADER_4:
  3259.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3260.             if (mark->is_end)
  3261.             {
  3262.                 font = PopFont();
  3263.                 NewFont(font);
  3264.                 currentFont = font;
  3265.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3266.             }
  3267.             else
  3268.             {
  3269.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3270.                 PushFont(currentFont);
  3271.                 font = HTML_Data->header4_font;
  3272.             }
  3273.             break;
  3274.         case M_HEADER_5:
  3275.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3276.             if (mark->is_end)
  3277.             {
  3278.                 font = PopFont();
  3279.                 NewFont(font);
  3280.                 currentFont = font;
  3281.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3282.             }
  3283.             else
  3284.             {
  3285.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3286.                 PushFont(currentFont);
  3287.                 font = HTML_Data->header5_font;
  3288.             }
  3289.             break;
  3290.         case M_HEADER_6:
  3291.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3292.             if (mark->is_end)
  3293.             {
  3294.                 font = PopFont();
  3295.                 NewFont(font);
  3296.                 currentFont = font;
  3297.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3298.             }
  3299.             else
  3300.             {
  3301.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3302.                 PushFont(currentFont);
  3303.                 font = HTML_Data->header6_font;
  3304.             }
  3305.             break;
  3306.         /*
  3307.          * Anchors change the text color, and may set
  3308.          * underlineing attributes.
  3309.          * No linefeeds, so they can be imbedded anywhere.
  3310.          */
  3311.         case M_ANCHOR:
  3312.             if (mark->is_end)
  3313.             {
  3314. /*
  3315.  * Without motif we use our own foreground resource instead of
  3316.  * using the manager's
  3317.  */
  3318.                 Fg = HTML_Data->foreground;
  3319.                 Underlines = 0;
  3320.                 DashedUnderlines = False;
  3321.                 AnchorText = NULL;
  3322.             }
  3323.             else
  3324.             {
  3325.                 char *tptr;
  3326.  
  3327.                 /*
  3328.                  * Only change the color of anchors with
  3329.                  * HREF tags, because other anchors are
  3330.                  * not active.
  3331.                  */
  3332.                 tptr = ParseMarkTag(mark->start,
  3333.                     MT_ANCHOR, AT_HREF);
  3334.                 if (tptr != NULL)
  3335.                 {
  3336.                     /*
  3337.                      * If internal check our internal list
  3338.                      * to change color if visited before.
  3339.                      */
  3340.                     if (Internal == True)
  3341.                     {
  3342.                     struct ref_rec *hptr;
  3343.  
  3344.                     hptr = FindHRef(
  3345.                         HTML_Data->my_visited_hrefs,
  3346.                         tptr);
  3347.                     if (hptr != NULL)
  3348.                     {
  3349.                         Fg = HTML_Data->visitedAnchor_fg;
  3350.                         Underlines = HTML_Data->num_visitedAnchor_underlines;
  3351.                         DashedUnderlines = HTML_Data->dashed_visitedAnchor_lines;
  3352.                     }
  3353.                     else
  3354.                     {
  3355.                         Fg = HTML_Data->anchor_fg;
  3356.                         Underlines = HTML_Data->num_anchor_underlines;
  3357.                         DashedUnderlines = HTML_Data->dashed_anchor_lines;
  3358.                     }
  3359.                     }
  3360.                     /*
  3361.                      * Else we may want to send
  3362.                      * the href back somewhere else and
  3363.                      * find out if we've visited it before
  3364.                      */
  3365.                     else if (HTML_Data->previously_visited_test !=
  3366.                         NULL)
  3367.                     {
  3368.                     if ((*(visitTestProc)
  3369.                         (HTML_Data->previously_visited_test))
  3370.                         (HTML_Data, tptr))
  3371.                     {
  3372.                         Fg = HTML_Data->visitedAnchor_fg;
  3373.                         Underlines = HTML_Data->num_visitedAnchor_underlines;
  3374.                         DashedUnderlines = HTML_Data->dashed_visitedAnchor_lines;
  3375.                     }
  3376.                     else
  3377.                     {
  3378.                         Fg = HTML_Data->anchor_fg;
  3379.                         Underlines = HTML_Data->num_anchor_underlines;
  3380.                         DashedUnderlines = HTML_Data->dashed_anchor_lines;
  3381.                     }
  3382.                     }
  3383.                     else
  3384.                     {
  3385.                     Fg = HTML_Data->anchor_fg;
  3386.                     Underlines = HTML_Data->num_anchor_underlines;
  3387.                     DashedUnderlines = HTML_Data->dashed_anchor_lines;
  3388.                     }
  3389.                                     if (tptr)
  3390.                                       free(tptr);
  3391.                 }
  3392.                 AnchorText = mark->start;
  3393.             }
  3394.             break;
  3395.         /*
  3396.          * Just insert a linefeed, or ignore if this is prefomatted
  3397.          * text because the <P> will be followed be a linefeed.
  3398.          */
  3399.         case M_PARAGRAPH:
  3400.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3401.             ConditionalLineFeed(HTML_Data, x, y, 2);
  3402.             break;
  3403.         /*
  3404.          * Just insert the image for now
  3405.          */
  3406.         case M_IMAGE:
  3407.             ImagePlace(HTML_Data, mptr, x, y, Width);
  3408.             break;
  3409.         /*
  3410.          * Can only be inside a SELECT tag.
  3411.          */
  3412.         case M_OPTION:
  3413.             if (CurrentSelect != NULL)
  3414.             {
  3415.                 char *tptr;
  3416.  
  3417.                 if (CurrentSelect->option_buf != NULL)
  3418.                 {
  3419.                     ProcessOption(CurrentSelect);
  3420.                 }
  3421.                 CurrentSelect->option_buf = (char *)malloc(1);
  3422.                 strcpy(CurrentSelect->option_buf, "");
  3423.  
  3424.                 /*
  3425.                  * Check if this option starts selected
  3426.                  */
  3427.                 tptr = ParseMarkTag(mark->start,
  3428.                     MT_OPTION, "SELECTED");
  3429.                 if (tptr != NULL)
  3430.                 {
  3431.                     CurrentSelect->is_value = 1;
  3432.                     free(tptr);
  3433.                 }
  3434.                 else
  3435.                 {
  3436.                     CurrentSelect->is_value = 0;
  3437.                 }
  3438.  
  3439.                 /*
  3440.                  * Check if this option has an different
  3441.                  * return value field.
  3442.                  */
  3443.                 tptr = ParseMarkTag(mark->start,
  3444.                     MT_OPTION, "VALUE");
  3445.                 if (tptr != NULL)
  3446.                 {
  3447.                     if (*tptr != '\0')
  3448.                     {
  3449.                     CurrentSelect->retval_buf = tptr;
  3450.                     }
  3451.                     else
  3452.                     {
  3453.                     CurrentSelect->retval_buf = NULL;
  3454.                     free(tptr);
  3455.                     }
  3456.                 }
  3457.                 else
  3458.                 {
  3459.                     CurrentSelect->retval_buf = NULL;
  3460.                 }
  3461.             }
  3462.             break;
  3463.         /*
  3464.          * Special INPUT tag.  Allows an option menu or
  3465.          * a scrolled list.
  3466.          * Due to a restriction in SGML, this can't just be a 
  3467.          * subset of the INPUT markup.  However, I can treat it
  3468.          * that way to avoid duplicating code.
  3469.          * As a result I combine SELECT and OPTION into a faked
  3470.          * up INPUT mark.
  3471.          */
  3472.         case M_SELECT:
  3473. //#ifndef _AMIGA
  3474.             if (CurrentForm != NULL)
  3475.             {
  3476.                 if ((mark->is_end)&&(CurrentSelect != NULL))
  3477.                 {
  3478.                     int len;
  3479.                     char *buf;
  3480.                     char *start;
  3481.                     char *options, *returns, *value;
  3482.  
  3483.                     if (CurrentSelect->option_buf != NULL)
  3484.                     {
  3485.                         ProcessOption(CurrentSelect);
  3486.                     }
  3487.  
  3488.                     options = ComposeCommaList(
  3489.                         CurrentSelect->options,
  3490.                         CurrentSelect->option_cnt);
  3491.                     returns = ComposeCommaList(
  3492.                         CurrentSelect->returns,
  3493.                         CurrentSelect->option_cnt);
  3494.                     value = ComposeCommaList(
  3495.                         CurrentSelect->value,
  3496.                         CurrentSelect->value_cnt);
  3497.                     FreeCommaList(
  3498.                         CurrentSelect->options,
  3499.                         CurrentSelect->option_cnt);
  3500.                     FreeCommaList(
  3501.                         CurrentSelect->returns,
  3502.                         CurrentSelect->option_cnt);
  3503.                     FreeCommaList(
  3504.                         CurrentSelect->value,
  3505.                         CurrentSelect->value_cnt);
  3506.  
  3507.                     /*
  3508.                      * Construct a fake INPUT tag.
  3509.                      */
  3510.                     len = strlen(MT_INPUT) +
  3511.                         strlen(options) +
  3512.                         strlen(returns) +
  3513.                         strlen(value) + strlen(
  3514.             " type=select options=\"\" returns=\"\" value=\"\"");
  3515.                     buf = (char *)malloc(len +
  3516.                         strlen(CurrentSelect->mptr->start)
  3517.                         + 1);
  3518.                     strcpy(buf, MT_INPUT);
  3519.                     strcat(buf, " type=select");
  3520.                     strcat(buf, " options=\"");
  3521.                     strcat(buf, options);
  3522.                     strcat(buf, "\" returns=\"");
  3523.                     strcat(buf, returns);
  3524.                     strcat(buf, "\" value=\"");
  3525.                     strcat(buf, value);
  3526.                     strcat(buf, "\"");
  3527.                     strcat(buf, (char *)
  3528.                         (CurrentSelect->mptr->start +
  3529.                         strlen(MT_SELECT)));
  3530.                     /*
  3531.                      * stick the fake in, saving the
  3532.                      * real one.
  3533.                      */
  3534.                     start = CurrentSelect->mptr->start;
  3535.                     CurrentSelect->mptr->start = buf;
  3536.                     WidgetPlace(HTML_Data, CurrentSelect->mptr,
  3537.                         x, y, Width);
  3538.                     /*
  3539.                      * free the fake, put the original back
  3540.                      */
  3541.                     free(buf);
  3542.                     free(options);
  3543.                     free(returns);
  3544.                     free(value);
  3545.                     CurrentSelect->mptr->start = start;
  3546.  
  3547.                     free((char *)CurrentSelect);
  3548.                     CurrentSelect = NULL;
  3549.                     Ignore = 0;
  3550.                 }
  3551.                 else if ((!mark->is_end)&&(CurrentSelect == NULL))
  3552.                 {
  3553.                     CurrentSelect = (SelectInfo *)malloc(
  3554.                         sizeof(SelectInfo));
  3555.                     CurrentSelect->HTML_Data = (Widget)HTML_Data;
  3556.                     CurrentSelect->mptr = mptr;
  3557.                     CurrentSelect->option_cnt = 0;
  3558.                     CurrentSelect->returns = NULL;
  3559.                     CurrentSelect->retval_buf = NULL;
  3560.                     CurrentSelect->options = NULL;
  3561.                     CurrentSelect->option_buf = NULL;
  3562.                     CurrentSelect->value_cnt = 0;
  3563.                     CurrentSelect->value = NULL;
  3564.                     CurrentSelect->is_value = -1;
  3565.                     Ignore = 1;
  3566.                 }
  3567.             }
  3568. //#endif /* _AMIGA */
  3569.             break;
  3570.         /*
  3571.          * TEXTAREA is a replacement for INPUT type=text size=rows,cols
  3572.          * because SGML will not allow an arbitrary length value
  3573.          * field.
  3574.          */
  3575.         case M_TEXTAREA:
  3576. // #ifndef _AMIGA
  3577. //            kprintf("Parsing textarea\n");
  3578.             if (CurrentForm != NULL)
  3579.             {
  3580.                 if ((mark->is_end)&&(TextAreaBuf != NULL))
  3581.                 {
  3582.                     char *start;
  3583.                     char *buf;
  3584.  
  3585.                     /*
  3586.                      * Finish a fake INPUT tag.
  3587.                      */
  3588.                     buf = (char *)malloc(
  3589.                         strlen(TextAreaBuf) + 2);
  3590.                     strcpy(buf, TextAreaBuf);
  3591.                     strcat(buf, "\"");
  3592.  
  3593.                     /*
  3594.                      * stick the fake in, saving the
  3595.                      * real one.
  3596.                      */
  3597.                     start = mark->start;
  3598.                     mark->start = buf;
  3599.                     mark->is_end = 0;
  3600.                     WidgetPlace(HTML_Data, mark, x, y, Width);
  3601.  
  3602.                     /*
  3603.                      * free the fake, put the original back
  3604.                      */
  3605.                     free(buf);
  3606.                     free(TextAreaBuf);
  3607.                     mark->start = start;
  3608.                     mark->is_end = 1;
  3609.                     TextAreaBuf = NULL;
  3610.                     Ignore = 0;
  3611.                 }
  3612.                 else if ((!mark->is_end)&&(TextAreaBuf == NULL))
  3613.                 {
  3614.                     char *buf;
  3615.                     int len;
  3616.  
  3617.                     /*
  3618.                      * Construct  the start of
  3619.                      * a fake INPUT tag.
  3620.                      */
  3621.                     len = strlen(MT_INPUT) +
  3622.                         strlen(
  3623.                     " type=textarea value=\"\"");
  3624.                     buf = (char *)malloc(len +
  3625.                         strlen(mark->start)
  3626.                         + 1);
  3627.                     strcpy(buf, MT_INPUT);
  3628.                     strcat(buf, (char *)
  3629.                         (mark->start +
  3630.                         strlen(MT_TEXTAREA)));
  3631.                     strcat(buf, " type=textarea");
  3632.                     strcat(buf, " value=\"");
  3633.  
  3634.                     TextAreaBuf = buf;
  3635.                     Ignore = 1;
  3636.                 }
  3637.             }
  3638. //#endif /* _AMIGA */
  3639.             break;
  3640.         /*
  3641.          * Just insert the widget.
  3642.          * Can only inside a FORM tag.
  3643.          * Special case the type=image stuff to become a special
  3644.          * IMG tag.
  3645.          */
  3646.         case M_INPUT:
  3647. // #ifndef _AMIGA
  3648.             if (CurrentForm != NULL)
  3649.             {
  3650.                 char *tptr;
  3651.                 char *tptr2;
  3652.  
  3653.                 tptr = ParseMarkTag(mptr->start,
  3654.                     MT_INPUT, "TYPE");
  3655.                 if ((tptr != NULL)&&
  3656.                     (strcmp(tptr, "image") == 0))
  3657.                 {
  3658.                     free(tptr);
  3659.                     tptr = (char *)malloc(
  3660.                         strlen(mptr->start) +
  3661.                         strlen(" ISMAP") +
  3662.                         strlen(MT_IMAGE) -
  3663.                         strlen(MT_INPUT) + 1);
  3664.                     strcpy(tptr, MT_IMAGE);
  3665.                     strcat(tptr, (char *)
  3666.                         (mptr->start + strlen(MT_INPUT))
  3667.                         );
  3668.                     strcat(tptr, " ISMAP");
  3669.                     tptr2 = mptr->start;
  3670.                     mptr->start = tptr;
  3671.                     ImagePlace(HTML_Data, mptr, x, y, Width);
  3672.                     mptr->start = tptr2;
  3673.                     free(tptr);
  3674. //                    kprintf("mptr type %ld string %s\n",mptr->type,mptr->start);
  3675.                 }
  3676.                 else
  3677.                 {
  3678.                     if (tptr != NULL)
  3679.                     {
  3680.                         free(tptr);
  3681.                     }
  3682.                     WidgetPlace(HTML_Data, mptr, x, y, Width);
  3683.                 }
  3684.             }
  3685. // #endif /* _AMIGA */
  3686.             break;
  3687.         /*
  3688.          * Fillout forms.  Cannot be nested.
  3689.          */
  3690.         case M_FORM:
  3691. //#ifndef _AMIGA
  3692. //            kprintf("Parsing form at x: %ld y: %ld\n",*x,*y);
  3693.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3694.             if ((mark->is_end)&&(CurrentForm != NULL))
  3695.             {
  3696.                 CurrentForm->end = WidgetId;
  3697.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3698.                 AddNewForm(HTML_Data, CurrentForm);
  3699.                 CurrentForm = NULL;
  3700.             }
  3701.             else if ((!mark->is_end)&&(CurrentForm == NULL))
  3702.             {
  3703.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3704.                 CurrentForm = (FormInfo *)calloc(1,
  3705.                     sizeof(FormInfo));
  3706.                 CurrentForm->next = NULL;
  3707.                 CurrentForm->HTML_Data = (Widget)HTML_Data;
  3708.                 CurrentForm->action = ParseMarkTag(mark->start,
  3709.                     MT_FORM, "ACTION");
  3710.                                 CurrentForm->method = ParseMarkTag(mark->start,
  3711.                                         MT_FORM, "METHOD");
  3712.                                 CurrentForm->enctype = ParseMarkTag(mark->start,
  3713.                                         MT_FORM, "ENCTYPE");
  3714.                 CurrentForm->start = WidgetId;
  3715.                 CurrentForm->end = -1;
  3716.             }
  3717. //#endif /* _AMIGA */
  3718.             break;
  3719.         /*
  3720.          * Addresses are just like headers.  A linefeed before and
  3721.          * after, and change the font.
  3722.          */
  3723.         case M_ADDRESS:
  3724.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3725.             if (mark->is_end)
  3726.             {
  3727.                 font = PopFont();
  3728.             }
  3729.             else
  3730.             {
  3731.                 PushFont(currentFont);
  3732.                 font = HTML_Data->address_font;
  3733.             }
  3734.             break;
  3735.         /*
  3736.          * Blockquotes increase the margin width.
  3737.          * They cannot be nested.
  3738.          */
  3739.         case M_BLOCKQUOTE:
  3740.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3741.             if (mark->is_end)
  3742.             {
  3743.                 MarginW = HTML_Data->margin_width;
  3744.                 /*
  3745.                  * Only unindent if we think we indented
  3746.                  * when we started the blockquote
  3747.                  */
  3748.                 if (TextIndent <= (2 * MarginW))
  3749.                 {
  3750.                     TextIndent = MarginW;
  3751.                 }
  3752.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3753.                 /*
  3754.                  * The linefeed should have set x to TextIndent
  3755.                  * but since it is conditional, it might not
  3756.                  * have, so check it here.
  3757.                  */
  3758.                 if (*x > TextIndent)
  3759.                 {
  3760.                     *x = TextIndent;
  3761.                 }
  3762.             }
  3763.             else
  3764.             {
  3765.                 MarginW = 2 * HTML_Data->margin_width;
  3766.                 /*
  3767.                  * Only indent if the current indent
  3768.                  * is less than what we want.
  3769.                  */
  3770.                 if (TextIndent < MarginW)
  3771.                 {
  3772.                     TextIndent = MarginW;
  3773.                 }
  3774.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3775.                 /*
  3776.                  * The linefeed should have set x to TextIndent
  3777.                  * but since it is conditional, it might not
  3778.                  * have, so check it here.
  3779.                  */
  3780.                 if (*x < TextIndent)
  3781.                 {
  3782.                     *x = TextIndent;
  3783.                 }
  3784.             }
  3785.             break;
  3786.         /*
  3787.          * Plain text.  A single pre-formatted chunk of text
  3788.          * in its own font.
  3789.          */
  3790.         case M_PLAIN_TEXT:
  3791.             if (mark->is_end)
  3792.             {
  3793.                 Preformat = 0;
  3794.                 /*
  3795.                  * Properly convert the Linefeed state
  3796.                  * variable from preformat to formatted
  3797.                  * state.
  3798.                  */
  3799.                 if (PF_LF_State == 2)
  3800.                 {
  3801.                     PF_LF_State = 1;
  3802.                 }
  3803.                 else
  3804.                 {
  3805.                     PF_LF_State = 0;
  3806.                 }
  3807.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  3808.                 font = PopFont();
  3809.                 NewFont(font);
  3810.                 currentFont = font;
  3811.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3812.             }
  3813.             else
  3814.             {
  3815.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  3816.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3817.                 Preformat = 1;
  3818.                 PF_LF_State = 0;
  3819.                 PushFont(currentFont);
  3820.                 font = HTML_Data->plain_font;
  3821.             }
  3822.             break;
  3823.         /*
  3824.          * Listing text.  A different pre-formatted chunk of text
  3825.          * in its own font.
  3826.          */
  3827.                 case M_LISTING_TEXT:
  3828.             if (mark->is_end)
  3829.             {
  3830.                 Preformat = 0;
  3831.                 /*
  3832.                  * Properly convert the Linefeed state
  3833.                  * variable from preformat to formatted
  3834.                  * state.
  3835.                  */
  3836.                 if (PF_LF_State == 2)
  3837.                 {
  3838.                     PF_LF_State = 1;
  3839.                 }
  3840.                 else
  3841.                 {
  3842.                     PF_LF_State = 0;
  3843.                 }
  3844.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  3845.                 font = PopFont();
  3846.                 NewFont(font);
  3847.                 currentFont = font;
  3848.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3849.             }
  3850.             else
  3851.             {
  3852.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  3853.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3854.                 Preformat = 1;
  3855.                 PF_LF_State = 0;
  3856.                 PushFont(currentFont);
  3857.                 font = HTML_Data->listing_font;
  3858.             }
  3859.             break;
  3860.         /*
  3861.          * Plain text.  The rest of the text is pre-formatted.
  3862.          * There is not end for this mark.
  3863.          */
  3864.         case M_PLAIN_FILE:
  3865.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3866.             ConditionalLineFeed(HTML_Data, x, y, 2);
  3867.             Preformat = 1;
  3868.             PF_LF_State = 0;
  3869.             PushFont(currentFont);
  3870.             font = HTML_Data->plain_font;
  3871.             break;
  3872.         /*
  3873.          * Numbered lists, Unnumbered lists, Menus.
  3874.          * Currently also lump directory listings into this.
  3875.          * Save state for each indent level.
  3876.          * Change the value of the TxtIndent (can be nested)
  3877.          * Linefeed at the end of the list.
  3878.          */
  3879.         case M_NUM_LIST:
  3880.         case M_UNUM_LIST:
  3881.         case M_MENU:
  3882.         case M_DIRECTORY:
  3883.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3884.             SetFont(HTML_Data->rp, HTML_Data->font);
  3885.             width = TextLength(HTML_Data->rp, "n", 1);
  3886. //            width = HTML_Data->font->max_bounds.width;
  3887.             /*
  3888.              * If this is the outermost level of indentation,
  3889.              * add another linefeed for more white space.
  3890.              */
  3891.             if ((TextIndent <= MarginW)||((mark->is_end)&&
  3892.                 ((TextIndent - ((INDENT_SPACES + 1) * width)) <=
  3893.                     MarginW)))
  3894.             {
  3895.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  3896.             }
  3897.             if (mark->is_end)
  3898.             {
  3899.                 TextIndent = TextIndent -
  3900.                     ((INDENT_SPACES + 1) * width);
  3901.                 if (TextIndent < MarginW)
  3902.                 {
  3903.                     TextIndent = MarginW;
  3904.                 }
  3905.                 IndentLevel--;
  3906.                 if (IndentLevel < 0)
  3907.                 {
  3908.                     IndentLevel = 0;
  3909.                 }
  3910.  
  3911.                 /*
  3912.                  * restore the old state if there is one
  3913.                  */
  3914.                 if (ListData->next != NULL)
  3915.                 {
  3916.                     DescRec *dptr;
  3917.  
  3918.                     dptr = ListData;
  3919.                     ListData = ListData->next;
  3920.                     free((char *)dptr);
  3921.                 }
  3922.             }
  3923.             else
  3924.             {
  3925.                 DescRec *dptr;
  3926.  
  3927.                 dptr = (DescRec *)malloc(sizeof(DescRec));
  3928.                 /*
  3929.                  * Save the old state, and start a new
  3930.                  */
  3931.                 if (type == M_NUM_LIST)
  3932.                 {
  3933.                     dptr->type = D_OLIST;
  3934.                     dptr->count = 1;
  3935.                 }
  3936.                 else
  3937.                 {
  3938.                     dptr->type = D_ULIST;
  3939.                     dptr->count = 0;
  3940.                 }
  3941.                 dptr->next = ListData;
  3942.                 ListData = dptr;
  3943.  
  3944.                 TextIndent = TextIndent +
  3945.                     ((INDENT_SPACES + 1) * width);
  3946.                 IndentLevel++;
  3947.             }
  3948.             *x = TextIndent;
  3949.             break;
  3950.         /*
  3951.          * Place the bullet element at the beginning of this item.
  3952.          */
  3953.         case M_LIST_ITEM:
  3954.             if (!mark->is_end)
  3955.             {
  3956.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  3957.                 /*
  3958.                  * for ordered/numbered lists
  3959.                  * put numbers in place of bullets.
  3960.                  */
  3961.                 if (ListData->type == D_OLIST)
  3962.                 {
  3963.                     ListNumberPlace(HTML_Data, x, y,
  3964.                         ListData->count);
  3965.                     ListData->count++;
  3966.                 }    
  3967.                 else
  3968.                 {
  3969.                     BulletPlace(HTML_Data, x, y);
  3970.                 }    
  3971.             }
  3972.             break;
  3973.         /*
  3974.          * Description lists
  3975.          */
  3976.         case M_DESC_LIST:
  3977.             ConditionalLineFeed(HTML_Data, x, y, 1);
  3978.             ConditionalLineFeed(HTML_Data, x, y, 2);
  3979.             SetFont(HTML_Data->rp, HTML_Data->font);
  3980.             width = TextLength(HTML_Data->rp, "n", 1);
  3981. //            width = HTML_Data->font->max_bounds.width;
  3982.             if (mark->is_end)
  3983.             {
  3984.                 if (DescType->type == D_TEXT)
  3985.                 {
  3986.                     TextIndent = TextIndent -
  3987.                         ((INDENT_SPACES + 1) * width);
  3988.                     if (TextIndent < MarginW)
  3989.                     {
  3990.                         TextIndent = MarginW;
  3991.                     }
  3992.                 }
  3993.                 /*
  3994.                  * restore the old state if there is one
  3995.                  */
  3996.                 if (DescType->next != NULL)
  3997.                 {
  3998.                     DescRec *dptr;
  3999.  
  4000.                     dptr = DescType;
  4001.                     DescType = DescType->next;
  4002.                     free((char *)dptr);
  4003.                     /*
  4004.                      * If the old state had forced an
  4005.                      * indent, outdent it now.
  4006.                      */
  4007.                     if (DescType->type == D_TITLE)
  4008.                     {
  4009.                         TextIndent = TextIndent -
  4010.                           ((INDENT_SPACES + 1) * width);
  4011.                         if (TextIndent < MarginW)
  4012.                         {
  4013.                             TextIndent = MarginW;
  4014.                         }
  4015.                     }
  4016.                 }
  4017.             }
  4018.             else
  4019.             {
  4020.                 DescRec *dptr;
  4021.                 char *tptr;
  4022.  
  4023.                 dptr = (DescRec *)malloc(sizeof(DescRec));
  4024.                 /*
  4025.                  * Check is this is a compact list
  4026.                  */
  4027.                 tptr = ParseMarkTag(mark->start,
  4028.                     MT_DESC_LIST, "COMPACT");
  4029.                 if (tptr != NULL)
  4030.                 {
  4031.                     free(tptr);
  4032.                     dptr->compact = 1;
  4033.                 }
  4034.                 else
  4035.                 {
  4036.                     dptr->compact = 0;
  4037.                 }
  4038.                 /*
  4039.                  * Description list stared after a title needs
  4040.                  * a forced indentation here
  4041.                  */
  4042.                 if (DescType->type == D_TITLE)
  4043.                 {
  4044.                     TextIndent = TextIndent +
  4045.                         ((INDENT_SPACES + 1) * width);
  4046.                 }
  4047.                 /*
  4048.                  * Save the old state, and start a new
  4049.                  */
  4050.                 dptr->type = D_TITLE;
  4051.                 dptr->next = DescType;
  4052.                 DescType = dptr;
  4053.             }
  4054.             *x = TextIndent;
  4055.             break;
  4056.         case M_DESC_TITLE:
  4057.             ConditionalLineFeed(HTML_Data, x, y, 1);
  4058.             SetFont(HTML_Data->rp, HTML_Data->font);
  4059.             width = TextLength(HTML_Data->rp, "n", 1);
  4060. //            width = HTML_Data->font->max_bounds.width;
  4061.             /*
  4062.              * Special hack.  Don't indent again for
  4063.              * multiple <dt>'s in a row.
  4064.              */
  4065.             if (DescType->type == D_TEXT)
  4066.             {
  4067.                 TextIndent = TextIndent -
  4068.                     ((INDENT_SPACES + 1) * width);
  4069.                 if (TextIndent < MarginW)
  4070.                 {
  4071.                     TextIndent = MarginW;
  4072.                 }
  4073.             }
  4074.             DescType->type = D_TITLE;
  4075.             *x = TextIndent;
  4076.             break;
  4077.         case M_DESC_TEXT:
  4078.             SetFont(HTML_Data->rp, HTML_Data->font);
  4079.             width = TextLength(HTML_Data->rp, "n", 1);
  4080. //            width = HTML_Data->font->max_bounds.width;
  4081.  
  4082.             /*
  4083.              * For a compact list we want to stay on the same
  4084.              * line if there is room and we are the first line
  4085.              * after a title.
  4086.              */
  4087.             if ((DescType->compact)&&(DescType->type == D_TITLE)&&
  4088.                 (*x < (TextIndent + (INDENT_SPACES * width))))
  4089.             {
  4090.                 NeedSpace = 0;
  4091.             }
  4092.             else
  4093.             {
  4094.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4095.             }
  4096.  
  4097.             /*
  4098.              * Special hack.  Don't indent again for
  4099.              * multiple <dd>'s in a row.
  4100.              */
  4101.             if (DescType->type == D_TITLE)
  4102.             {
  4103.                 TextIndent = TextIndent +
  4104.                     ((INDENT_SPACES + 1) * width);
  4105.             }
  4106.             DescType->type = D_TEXT;
  4107.             *x = TextIndent;
  4108.             break;
  4109.         case M_PREFORMAT:
  4110.             if (mark->is_end)
  4111.             {
  4112.                 Preformat = 0;
  4113.                 /*
  4114.                  * Properly convert the Linefeed state
  4115.                  * variable from preformat to formatted
  4116.                  * state.
  4117.                  */
  4118.                 if (PF_LF_State == 2)
  4119.                 {
  4120.                     PF_LF_State = 1;
  4121.                 }
  4122.                 else
  4123.                 {
  4124.                     PF_LF_State = 0;
  4125.                 }
  4126.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4127.                 if (saveFont != NULL)
  4128.                 {
  4129.                     HTML_Data->font = saveFont;
  4130.                     saveFont = NULL;
  4131.                 }
  4132.                 font = PopFont();
  4133.                 NewFont(font);
  4134.                 currentFont = font;
  4135.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  4136.             }
  4137.             else
  4138.             {
  4139.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4140.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  4141.                 Preformat = 1;
  4142.                 PF_LF_State = 2;
  4143.                 if (saveFont == NULL)
  4144.                 {
  4145.                     saveFont = HTML_Data->font;
  4146.                     HTML_Data->font = HTML_Data->plain_font;
  4147.                 }
  4148.                 PushFont(currentFont);
  4149.                 font = HTML_Data->font;
  4150.             }
  4151.             break;
  4152.         /*
  4153.          * Now with forms, <INDEX> is the same as:
  4154.          * <FORM>
  4155.          * <HR>
  4156.          * This is a searchable index.  Enter search keywords:
  4157.          * <INPUT NAME="isindex">
  4158.          * <HR>
  4159.          * </FORM>
  4160.          * Also, <INDEX> will take an ACTION tag to specify a
  4161.          * different URL to submit the query to.
  4162.          */
  4163.         case M_INDEX:
  4164.             if(!Rdata.isindex_to_form)
  4165.                 HTML_Data->is_index = True;
  4166.             else
  4167.             {
  4168.             /*
  4169.              * No index inside a form
  4170.              */
  4171.             if (CurrentForm == NULL)
  4172.             {
  4173.                 struct mark_up mark_tmp;
  4174.                 char *tptr;
  4175.  
  4176.                 /*
  4177.                  * Start the form
  4178.                  */
  4179.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4180.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  4181.                 CurrentForm = (FormInfo *)malloc(
  4182.                     sizeof(FormInfo));
  4183.                 CurrentForm->next = NULL;
  4184.                 CurrentForm->HTML_Data = (Widget)HTML_Data;
  4185.                 CurrentForm->action = NULL;
  4186.                 CurrentForm->action = ParseMarkTag(mark->start,
  4187.                     MT_INDEX, "ACTION");
  4188.                                 CurrentForm->method = ParseMarkTag(mark->start,
  4189.                                         MT_INDEX, "METHOD");
  4190.                                 CurrentForm->enctype = ParseMarkTag(mark->start,
  4191.                                         MT_INDEX, "ENCTYPE");
  4192.                 CurrentForm->start = WidgetId;
  4193.                 CurrentForm->end = -1;
  4194.  
  4195.                 /*
  4196.                  * Horizontal rule
  4197.                  */
  4198.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4199.                 HRulePlace(HTML_Data, x, y, Width);
  4200.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4201.  
  4202.                 /*
  4203.                  * Text: "This is a searchable index.
  4204.                  *  Enter search keywords: "
  4205.                  */
  4206.                 tptr=ParseMarkTag(mark->start,MT_INDEX,"PROMPT");
  4207.                 if(tptr)
  4208.                     mark_tmp.text = tptr;
  4209.                 else{
  4210.                     mark_tmp.text = (char *)malloc(
  4211.                         strlen("This is a searchable index.  Enter search keywords: ") + 1);
  4212.                     strcpy(mark_tmp.text,"This is a searchable index.  Enter search keywords: ");
  4213.                     }
  4214.                 FormatPlace(HTML_Data, &mark_tmp, x, y, Width);
  4215.  
  4216.                 /*
  4217.                  * Fake up the text INPUT tag.
  4218.                  */
  4219.                 mark_tmp.start = (char *)malloc(
  4220.                     strlen("input SIZE=25 NAME=\"isindex\"") + 1);
  4221.                 strcpy(mark_tmp.start,"input SIZE=25 NAME=\"isindex\"");
  4222.                 WidgetPlace(HTML_Data, &mark_tmp, x, y, Width);
  4223.  
  4224. #ifdef ISINDEX_SUBMIT
  4225.                 /*
  4226.                  * Text: ";<CR> press this button to submit
  4227.                  * the query: "
  4228.                  */
  4229.                 mark_tmp.text = (char *)malloc(
  4230.                     strlen(";\n press this button to submit the query: ") + 1);
  4231.                 strcpy(mark_tmp.text,";\n press this button to submit the query: ");
  4232.                 FormatPlace(HTML_Data, &mark_tmp, x, y, Width);
  4233.  
  4234.                 /*
  4235.                  * Fake up the submit INPUT tag.
  4236.                  */
  4237.                 mark_tmp.start = (char *)malloc(
  4238.                     strlen("input TYPE=\"submit\"") + 1);
  4239.                 strcpy(mark_tmp.start, "input TYPE=\"submit\"");
  4240.                 WidgetPlace(HTML_Data, &mark_tmp, x, y, Width);
  4241.  
  4242.                 /*
  4243.                  * Text: ".<CR>"
  4244.                  */
  4245.                 mark_tmp.text = (char *)malloc(
  4246.                     strlen(".\n") + 1);
  4247.                 strcpy(mark_tmp.text, ".\n");
  4248.                 FormatPlace(HTML_Data, &mark_tmp, x, y, Width);
  4249. #endif /* ISINDEX_SUBMIT */
  4250.  
  4251.                 /*
  4252.                  * Horizontal rule
  4253.                  */
  4254.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4255.                 HRulePlace(HTML_Data, x, y, Width);
  4256.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4257.  
  4258.                 /*
  4259.                  * Close the form
  4260.                  */
  4261.                 ConditionalLineFeed(HTML_Data, x, y, 1);
  4262.                 CurrentForm->end = WidgetId;
  4263.                 ConditionalLineFeed(HTML_Data, x, y, 2);
  4264.                 AddNewForm(HTML_Data, CurrentForm);
  4265.                 CurrentForm = NULL;
  4266.             }
  4267.             }
  4268.             break;
  4269.         case M_HRULE:
  4270.             ConditionalLineFeed(HTML_Data, x, y, 1);
  4271.             HRulePlace(HTML_Data, x, y, Width);
  4272.             ConditionalLineFeed(HTML_Data, x, y, 1);
  4273.             break;
  4274.         case M_LINEBREAK:
  4275.             LineFeed(HTML_Data, x, y);
  4276.             break;
  4277.         default:
  4278.             break;
  4279.     }
  4280.     if ((font != NULL)&&(font != currentFont))
  4281.     {
  4282.         NewFont(font);
  4283.         currentFont = font;
  4284.     }
  4285. }
  4286.  
  4287.  
  4288. /*
  4289.  * Format all the objects in the passed Widget's
  4290.  * parsed object list to fit the locally global Width.
  4291.  * Passes in the x,y coords of where to start placing the
  4292.  * formatted text.
  4293.  * Returns the ending x,y in same variables.
  4294.  * Title objects are ignored, and not formatted.
  4295.  *
  4296.  * The locally global variables are assumed to have been initialized
  4297.  * before this function was called.
  4298.  */
  4299. void
  4300. FormatChunk(HTMLGadClData * HTML_Data, int *x, int *y)
  4301. {
  4302.     struct mark_up *mptr;
  4303.  
  4304.     /*
  4305.      * Format all objects
  4306.      */
  4307.     mptr = HTML_Data->html_objects;
  4308.     Last = NULL;
  4309.     while (mptr != NULL)
  4310.     {
  4311.         TriggerMarkChanges(HTML_Data, mptr, x, y);
  4312.         /*
  4313.          * Save last non-text mark
  4314.          */
  4315.         if (mptr->type != M_NONE)
  4316.         {
  4317.             Last = mptr;
  4318.         }
  4319.         mptr = mptr->next;
  4320.     }
  4321. }
  4322.  
  4323.  
  4324. /*
  4325.  * Called by the widget to format all the objects in the
  4326.  * parsed object list to fit its current window size.
  4327.  * Returns the max_height of the entire document.
  4328.  * Title objects are ignored, and not formatted.
  4329.  */
  4330. int
  4331. FormatAll(HTMLGadClData * HTML_Data, int *Fwidth)
  4332. {
  4333.     int x, y;
  4334.     int width;
  4335.     struct mark_up *msave;
  4336. //    struct mark_up *mptr;
  4337. #ifdef TIMING
  4338. gettimeofday(&Tv, &Tz);
  4339. fprintf(stderr, "FormatAll enter (%d.%d)\n", Tv.tv_sec, Tv.tv_usec);
  4340. #endif
  4341.  
  4342.     width = *Fwidth;
  4343.     MaxWidth = width;
  4344.  
  4345.     /*
  4346.      * Clear the is_index flag
  4347.      */
  4348.     HTML_Data->is_index = False;
  4349.  
  4350.     /*
  4351.      * Initialize local variables, some from the widget
  4352.      */
  4353.     MarginW = HTML_Data->margin_width;
  4354. /*
  4355.  * Without motif we use our own foreground resource instead of
  4356.  * using the manager's
  4357.  */
  4358.     Fg = HTML_Data->foreground;
  4359.     Bg = HTML_Data->background_pixel;
  4360.     Underlines = 0;
  4361.     DashedUnderlines = False;
  4362.     Width = width;
  4363.     TextIndent = MarginW;
  4364.     ElementId = 0;
  4365.     WidgetId = 0;
  4366.     LineNumber = 1;
  4367.     LineBottom = 0;
  4368.     BaseLine = -100;
  4369.     CharsInLine = 0;
  4370.     IndentLevel = 0;
  4371.     Ignore = 0;
  4372.     Preformat = 0;
  4373.     PF_LF_State = 0;
  4374.     NeedSpace = 0;
  4375.     Internal = False;
  4376.     Strikeout = False;
  4377.     AnchorText = NULL;
  4378.     DescType = &BaseDesc;
  4379.     ListData = &BaseDesc;
  4380.     DescType->type = D_NONE;
  4381.     DescType->count = 0;
  4382.     DescType->compact = 0;
  4383.     DescType->next = NULL;
  4384.     CurrentForm = NULL;
  4385.     CurrentSelect = NULL;
  4386.     TextAreaBuf = NULL;
  4387.  
  4388.     /*
  4389.      * Free the old title, if there is one.
  4390.      */
  4391.     if (HTML_Data->title != NULL)
  4392.     {
  4393.         free(HTML_Data->title);
  4394.         HTML_Data->title = NULL;
  4395.     }
  4396.     TitleText = NULL;
  4397.  
  4398. #ifdef THROW_AWAY_OLD_LIST
  4399.     /*
  4400.      * Free up previously formatted elements
  4401.      */
  4402.     FreeLineList(HTML_Data->formatted_elements);
  4403.     HTML_Data->formatted_elements = NULL;
  4404. #endif
  4405.  
  4406.     /*
  4407.      * Clear any previous selections
  4408.      */
  4409.     HTML_Data->select_start = NULL;
  4410.     HTML_Data->select_end = NULL;
  4411.     HTML_Data->new_start = NULL;
  4412.     HTML_Data->new_end = NULL;
  4413.  
  4414.     /*
  4415.      * Set up a starting font, and starting x, y, position
  4416.      */
  4417.     NewFont(HTML_Data->font);
  4418.     currentFont = HTML_Data->font;
  4419.     saveFont = NULL;
  4420.     FontStack = &FontBase;
  4421.     FontStack->font = HTML_Data->font;
  4422.  
  4423.     x = TextIndent;
  4424.     y = HTML_Data->margin_height;
  4425.  
  4426.     /*
  4427.      * Start a null element list, to be filled in as we go.
  4428.      */
  4429.     Current = NULL;
  4430.  
  4431.     /*
  4432.      * If we have parsed special header text, fill it in now.
  4433.      */
  4434.     if (HTML_Data->html_header_objects != NULL)
  4435.     {
  4436.         msave = HTML_Data->html_objects;
  4437.         HTML_Data->html_objects = HTML_Data->html_header_objects;
  4438.         FormatChunk(HTML_Data, &x, &y);
  4439.  
  4440.         if (saveFont != NULL)
  4441.         {
  4442.             HTML_Data->font = saveFont;
  4443.             saveFont = NULL;
  4444.         }
  4445.         NewFont(HTML_Data->font);
  4446.         currentFont = HTML_Data->font;
  4447.  
  4448.         ConditionalLineFeed(HTML_Data, &x, &y, 1);
  4449.  
  4450.         HTML_Data->html_objects = msave;
  4451.     }
  4452.  
  4453.     /*
  4454.      * Format all objects for width
  4455.      */
  4456.     FormatChunk(HTML_Data, &x, &y);
  4457.  
  4458.     /*
  4459.      * If we have parsed special footer text, fill it in now.
  4460.      */
  4461.     if (HTML_Data->html_footer_objects != NULL)
  4462.     {
  4463.         if (saveFont != NULL)
  4464.         {
  4465.             HTML_Data->font = saveFont;
  4466.             saveFont = NULL;
  4467.         }
  4468.         NewFont(HTML_Data->font);
  4469.         currentFont = HTML_Data->font;
  4470.  
  4471.         Preformat = 0;
  4472.         PF_LF_State = 0;
  4473.         NeedSpace = 0;
  4474.  
  4475.         ConditionalLineFeed(HTML_Data, &x, &y, 1);
  4476.  
  4477.         msave = HTML_Data->html_objects;
  4478.         HTML_Data->html_objects = HTML_Data->html_footer_objects;
  4479.         FormatChunk(HTML_Data, &x, &y);
  4480.  
  4481.         HTML_Data->html_objects = msave;
  4482.     }
  4483.  
  4484.     /*
  4485.      * Ensure a linefeed after the final element.
  4486.      */
  4487.     ConditionalLineFeed(HTML_Data, &x, &y, 1);
  4488.  
  4489.     /*
  4490.      * Restore the proper font from unterminated preformatted text
  4491.      * sequences.
  4492.      */
  4493.     if (saveFont != NULL)
  4494.     {
  4495.         HTML_Data->font = saveFont;
  4496.         saveFont = NULL;
  4497.     }
  4498.  
  4499.     /*
  4500.      * Free and extra of the pre-allocated list.
  4501.      * Terminate the element list.
  4502.      */
  4503.     if ((Current != NULL)&&(Current->next != NULL))
  4504.     {
  4505.         FreeLineList(Current->next);
  4506.         Current->next = NULL;
  4507.     }
  4508.     else if ((Current == NULL)&&(HTML_Data->formatted_elements != NULL))
  4509.     {
  4510.         FreeLineList(HTML_Data->formatted_elements);
  4511.         HTML_Data->formatted_elements = NULL;
  4512.     }
  4513.  
  4514.     /*
  4515.      * Add the bottom margin to the max height.
  4516.      */
  4517.     y = y + HTML_Data->margin_height;
  4518.  
  4519.     /*
  4520.      * Make the line array indexed into the element list
  4521.      * and store it into the widget
  4522.      */
  4523.     HTML_Data->line_count = LineNumber;
  4524.     if (HTML_Data->line_array != NULL)
  4525.     {
  4526.         free((char *)HTML_Data->line_array);
  4527.     }
  4528.     HTML_Data->line_array = MakeLineList(HTML_Data->formatted_elements,
  4529.                         LineNumber);
  4530.  
  4531.     /*
  4532.      * If the passed in MaxWidth was wrong, correct it.
  4533.      */
  4534.     if (MaxWidth != width)
  4535.     {
  4536.         *Fwidth = MaxWidth;
  4537.     }
  4538.  
  4539.     if(CurrentForm){ /* A bad HTML page with no </FORM> tag. */
  4540.         AddNewForm(HTML_Data, CurrentForm);
  4541.         CurrentForm = NULL;
  4542.         }
  4543.  
  4544.  
  4545. #ifdef TIMING
  4546. gettimeofday(&Tv, &Tz);
  4547. fprintf(stderr, "FormatAll exit (%d.%d)\n", Tv.tv_sec, Tv.tv_usec);
  4548. #endif
  4549.     return(y);
  4550. }
  4551.  
  4552.  
  4553. /*
  4554.  * Redraw a linefeed.
  4555.  * Basically a filled rectangle at the end of a line.
  4556.  */
  4557. void
  4558. LinefeedRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr)
  4559. {
  4560. #ifndef _AMIGA            /* This is only needed during selection */
  4561.  
  4562.     int x1, y1;
  4563.     unsigned int width, height;
  4564.  
  4565. #ifdef NO_EXTRA_FILLS
  4566.     /*
  4567.      * The actualt height of the rectangle to fill is strange, based
  4568.      * an a differente between eptr->font->(ascent/descent) and
  4569.      * eptr->font->max_bounds.(ascent/descent) which I don't quite
  4570.      * understand. But it works.
  4571.      * Deal with bad Lucidia descents.
  4572.      */
  4573.     x1 = eptr->x;
  4574.     if (x1 > (int)HTML_Data->core.width)
  4575.     {
  4576.         width = 0;
  4577.     }
  4578.     else
  4579.     {
  4580.         width = HTML_Data->core.width - x1;
  4581.     }
  4582. #ifdef SHORT_LINEFEEDS
  4583.     y1 = eptr->y + eptr->y_offset + eptr->font->tf_YSize -
  4584.         eptr->font->ascent;
  4585.     height = eptr->font->ascent + eptr->font->descent;
  4586. #else
  4587.     y1 = eptr->y + eptr->font->tf_YSize - eptr->font->ascent;
  4588.     height = eptr->line_height;
  4589. #endif /* SHORT_LINEFEEDS */
  4590. #else
  4591.     x1 = eptr->x;
  4592.     if (x1 > (int)HTML_Data->core.width)
  4593.     {
  4594.         width = 0;
  4595.     }
  4596.     else
  4597.     {
  4598.         width = HTML_Data->core.width - x1;
  4599.     }
  4600. #ifdef SHORT_LINEFEEDS
  4601.     y1 = eptr->y + eptr->y_offset;
  4602.     if (eptr->font->descent > eptr->font->max_bounds.descent)
  4603.     {
  4604.         height = eptr->font->tf_YSize +
  4605.             eptr->font->descent;
  4606.     }
  4607.     else
  4608.     {
  4609.         height = eptr->font->tf_YSize +
  4610.             eptr->font->max_bounds.descent;
  4611.     }
  4612. #else
  4613.     y1 = eptr->y;
  4614.     height = eptr->line_height;
  4615. #endif /* SHORT_LINEFEEDS */
  4616. #endif /* NO_EXTRA_FILLS */
  4617.  
  4618.     x1 = x1 - HTML_Data->scroll_x;
  4619.     y1 = y1 - HTML_Data->scroll_y;
  4620.  
  4621.     if (eptr->selected == True)
  4622.     {
  4623.         XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->fg);
  4624.     }
  4625.     else
  4626.     {
  4627.         XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->bg);
  4628.     }
  4629.     XFillRectangle(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4630.         HTML_Data->drawGC,
  4631.         x1, y1, width, height);
  4632. #endif /* _AMIGA */
  4633. }
  4634.  
  4635.  
  4636. /*
  4637.  * Redraw part of a formatted text element, in the passed fg and bg
  4638.  */
  4639. void
  4640. PartialRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr, int start_pos, int end_pos,
  4641.            unsigned long fg, unsigned long bg)
  4642. {
  4643.     int ascent;
  4644.     char *tdata;
  4645.     int tlen;
  4646.     int x, y, width;
  4647.     int partial;
  4648.     int style = 0;        /* MDF - for Amiga Font Style hack */
  4649.  
  4650.     SetFont(HTML_Data->rp, eptr->font);
  4651. //    XSetFont(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->font->fid);
  4652.     ascent = eptr->font->tf_Baseline;
  4653. //mjw    width = -1;
  4654.     partial = 0;
  4655.  
  4656.     if (start_pos != 0)
  4657.     {
  4658. //        int dir, nascent, descent;
  4659.         XCharStruct all;
  4660. //        int height;
  4661.  
  4662. #ifdef ASSUME_FIXED_WIDTH_PRE
  4663.         if (eptr->font == HTML_Data->plain_font)
  4664.         {
  4665.             all.te_Width = eptr->font->max_bounds.width * start_pos;
  4666.         }
  4667.         else
  4668.         {
  4669.             XTextExtents(eptr->font, (char *)eptr->edata,
  4670.                 start_pos, &dir, &nascent, &descent, &all);
  4671.         }
  4672. #else
  4673.         XTextExtents(eptr->font, (char *)eptr->edata,
  4674.             start_pos, &dir, &nascent, &descent, &all);
  4675. #endif /* ASSUME_FIXED_WIDTH_PRE */
  4676.         x = eptr->x + all.te_Width;
  4677.         tdata = (char *)(eptr->edata + start_pos);
  4678.         partial = 1;
  4679.     }
  4680.     else
  4681.     {
  4682.         x = eptr->x;
  4683.         tdata = (char *)eptr->edata;
  4684.     }
  4685.  
  4686.     if (end_pos != (eptr->edata_len - 2))
  4687.     {
  4688.         tlen = end_pos - start_pos + 1;
  4689.         partial = 1;
  4690.     }
  4691.     else
  4692.     {
  4693.         tlen = eptr->edata_len - start_pos - 1;
  4694.     }
  4695.  
  4696.     y = eptr->y + eptr->y_offset;
  4697.  
  4698.     x = x - HTML_Data->scroll_x;
  4699.     y = y - HTML_Data->scroll_y;
  4700.  
  4701. #ifndef NO_EXTRA_FILLS
  4702.     {
  4703. //        int dir, nascent, descent;
  4704.         XCharStruct all;
  4705. //        int height;
  4706.  
  4707.         /*
  4708.          * May be safe to used the cached full width of this
  4709.          * string, and thus avoid a call to XTextExtents
  4710.          */
  4711.         if ((!partial)&&(eptr->width != 0))
  4712.         {
  4713.             all.te_Width = eptr->width;
  4714.         }
  4715.         else
  4716.         {
  4717. #ifdef ASSUME_FIXED_WIDTH_PRE
  4718.             if (eptr->font == HTML_Data->plain_font)
  4719.             {
  4720.                 all.te_Width = eptr->font->max_bounds.width * tlen;
  4721.             }
  4722.             else
  4723.             {
  4724.                 XTextExtents(eptr->font, (char *)tdata,
  4725.                     tlen, &dir, &nascent, &descent, &all);
  4726.             }
  4727. #else
  4728.             XTextExtents(eptr->font, (char *)tdata,
  4729.                 tlen, &dir, &nascent, &descent, &all);
  4730. #endif /* ASSUME_FIXED_WIDTH_PRE */
  4731.         }
  4732.  
  4733.         XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, bg);
  4734.  
  4735. #ifndef _AMIGA            /* Our fonts don't have this problem. */
  4736.         height = (eptr->font->tf_YSize - eptr->font->ascent);
  4737.         if (height > 0)
  4738.         {
  4739.             XFillRectangle(XtDisplay(HTML_Data->view),
  4740.                 XtWindow(HTML_Data->view),
  4741.                 HTML_Data->drawGC, x, y,
  4742.                 (unsigned int)all.te_Width, (unsigned int)height);
  4743.         }
  4744.         height = (eptr->font->max_bounds.descent - eptr->font->descent);
  4745.         if (height > 0)
  4746.         {
  4747.             XFillRectangle(XtDisplay(HTML_Data->view),
  4748.                 XtWindow(HTML_Data->view),
  4749.                 HTML_Data->drawGC, x,
  4750.                 (int)(y + eptr->font->tf_YSize +
  4751.                     eptr->font->descent),
  4752.                 (unsigned int)all.te_Width, (unsigned int)height);
  4753.         }
  4754. #endif /* _AMIGA */
  4755.         width = all.te_Width;
  4756.     }
  4757. #endif /* NO_EXTRA_FILLS */
  4758.  
  4759.     XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, fg);
  4760.     XSetBackground(XtDisplay(HTML_Data), HTML_Data->drawGC, bg);
  4761.  
  4762.     /* MDF HACK!  This is my hack to make bold/italic work. */
  4763.  
  4764. #ifdef _AMIGA
  4765.     SetFont(HTML_Data->rp, eptr->font);
  4766.     if (eptr->font->tf_Style) {
  4767.       style = eptr->font->tf_Style;
  4768.       eptr->font->tf_Style = 0;
  4769.       SetSoftStyle(HTML_Data->rp, style, FSF_BOLD | FSF_ITALIC);
  4770.       eptr->font->tf_Style = style;
  4771. //mjw      style = 0;
  4772.     }
  4773. #endif /* _AMIGA */
  4774.  
  4775.     XDrawImageString(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4776.         HTML_Data->drawGC,
  4777.         x, y + ascent,
  4778.         (char *)tdata, tlen);
  4779.  
  4780.     if (eptr->underline_number)
  4781.     {
  4782.         int i, ly;
  4783.  
  4784.         if (eptr->dashed_underline)
  4785.         {
  4786.           SetDrPt(HTML_Data->rp, 0xCCCC);
  4787. //            XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4788. //                LineDoubleDash, CapButt, JoinBevel);
  4789.         }
  4790.         else
  4791.         {
  4792.           SetDrPt(HTML_Data->rp, 0xFFFF);
  4793. //            XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4794. //                LineSolid, CapButt, JoinBevel);
  4795.         }
  4796.  
  4797.         if (width == -1)
  4798.         {
  4799. //            int dir, nascent, descent;
  4800.             XCharStruct all;
  4801.  
  4802. #ifdef ASSUME_FIXED_WIDTH_PRE
  4803.             if (eptr->font == HTML_Data->plain_font)
  4804.             {
  4805.                 all.te_Width = eptr->font->max_bounds.width * tlen;
  4806.             }
  4807.             else
  4808.             {
  4809.                 XTextExtents(eptr->font, (char *)tdata,
  4810.                     tlen, &dir, &nascent, &descent,&all);
  4811.             }
  4812. #else
  4813.             XTextExtents(eptr->font, (char *)tdata,
  4814.                 tlen, &dir, &nascent, &descent,&all);
  4815. #endif /* ASSUME_FIXED_WIDTH_PRE */
  4816.             width = all.te_Width;
  4817.         }
  4818.  
  4819. //        ly = (int)(y + eptr->font->ascent +
  4820. //                eptr->font->descent - 1);
  4821.         ly = (int)(y + eptr->font->tf_YSize - 2);
  4822.  
  4823.         for (i=0; i<eptr->underline_number; i++)
  4824.         {
  4825.             XDrawLine(XtDisplay(HTML_Data->view),
  4826.                 XtWindow(HTML_Data->view), HTML_Data->drawGC,
  4827.                 x, ly, (int)(x + width), ly);
  4828.             ly -= 2;
  4829.         }
  4830.     }
  4831.  
  4832.     if (eptr->strikeout == True)
  4833.     {
  4834.         int ly; // ,i;
  4835.  
  4836.         SetDrPt(HTML_Data->rp, 0xFFFF);
  4837. //        XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4838. //            LineSolid, CapButt, JoinBevel);
  4839.  
  4840.         if (width == -1)
  4841.         {
  4842. //            int dir, nascent, descent;
  4843.             XCharStruct all;
  4844.  
  4845. #ifdef ASSUME_FIXED_WIDTH_PRE
  4846.             if (eptr->font == HTML_Data->plain_font)
  4847.             {
  4848.                 all.te_Width = eptr->font->max_bounds.width * tlen;
  4849.             }
  4850.             else
  4851.             {
  4852.                 XTextExtents(eptr->font, (char *)tdata,
  4853.                     tlen, &dir, &nascent, &descent,&all);
  4854.             }
  4855. #else
  4856.             XTextExtents(eptr->font, (char *)tdata,
  4857.                 tlen, &dir, &nascent, &descent,&all);
  4858. #endif /* ASSUME_FIXED_WIDTH_PRE */
  4859.             width = all.te_Width;
  4860.         }
  4861.  
  4862. //        ly = (int)(y + eptr->font->ascent +
  4863. //                eptr->font->descent - 1);
  4864.         ly = (int)(y + eptr->font->tf_YSize - 1);
  4865. //        ly = ly - ((HTML_Data->font->ascent +
  4866. //            HTML_Data->font->descent) / 2);
  4867.         ly = ly - ((HTML_Data->font->tf_YSize) / 2);
  4868.  
  4869.         XDrawLine(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4870.             HTML_Data->drawGC,
  4871.             x, ly, (int)(x + width), ly);
  4872.     }
  4873.     SetDrPt(HTML_Data->rp, 0xFFFF);
  4874. }
  4875.  
  4876.  
  4877. /*
  4878.  * Redraw a formatted text element
  4879.  */
  4880. void
  4881. TextRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr, int start_pos, int end_pos)
  4882. {
  4883.     if (eptr->selected == False)
  4884.     {
  4885.         PartialRefresh(HTML_Data, eptr, start_pos, end_pos,
  4886.             eptr->fg, eptr->bg);
  4887.     }
  4888.     else if ((start_pos >= eptr->start_pos)&&(end_pos <= eptr->end_pos))
  4889.     {
  4890.         PartialRefresh(HTML_Data, eptr, start_pos, end_pos,
  4891.             eptr->bg, eptr->fg);
  4892.     }
  4893.     else
  4894.     {
  4895.         if (start_pos < eptr->start_pos)
  4896.         {
  4897.             PartialRefresh(HTML_Data, eptr, start_pos, eptr->start_pos - 1,
  4898.                 eptr->fg, eptr->bg);
  4899.             start_pos = eptr->start_pos;
  4900.         }
  4901.         if (end_pos > eptr->end_pos)
  4902.         {
  4903.             PartialRefresh(HTML_Data, eptr, eptr->end_pos + 1, end_pos,
  4904.                 eptr->fg, eptr->bg);
  4905.             end_pos = eptr->end_pos;
  4906.         }
  4907.         PartialRefresh(HTML_Data, eptr, start_pos, end_pos,
  4908.             eptr->bg, eptr->fg);
  4909.     }
  4910. }
  4911.  
  4912.  
  4913. /*
  4914.  * Redraw a formatted bullet element
  4915.  */
  4916. void
  4917. BulletRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr)
  4918. {
  4919.     int width, line_height;
  4920.     int x1, y1;
  4921.  
  4922.     SetFont(HTML_Data->rp, eptr->font);
  4923.     width = TextLength(HTML_Data->rp, "n", 1);
  4924.     line_height = eptr->font->tf_YSize;
  4925. /*
  4926.     width = eptr->font->max_bounds.width;
  4927.     width = eptr->font->max_bounds.lbearing +
  4928.         eptr->font->max_bounds.rbearing;
  4929. */
  4930.     x1 = eptr->x;
  4931.     y1 = eptr->y + eptr->y_offset + (line_height / 2) - (width / 4);
  4932.     x1 = x1 - HTML_Data->scroll_x;
  4933.     y1 = y1 - HTML_Data->scroll_y;
  4934. //    XSetFont(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->font->fid);
  4935.     SetFont(HTML_Data->rp, eptr->font);
  4936.     XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->fg);
  4937.     XSetBackground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->bg);
  4938.     if (eptr->indent_level < 2)
  4939.     {
  4940.         XFillArc(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4941.             HTML_Data->drawGC,
  4942.             (x1 - width), y1,
  4943.             (width / 2), (width / 2), 0, 23040);
  4944.     }
  4945.     else if (eptr->indent_level == 2)
  4946.     {
  4947.            SetDrPt(HTML_Data->rp, 0xFFFF);
  4948. //        XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4949. //            LineSolid, CapButt, JoinBevel);
  4950.         XDrawRectangle(XtDisplay(HTML_Data->view),
  4951.             XtWindow(HTML_Data->view), HTML_Data->drawGC,
  4952.             (x1 - width), y1,
  4953.             (width / 2), (width / 2));
  4954.     }
  4955.     else if (eptr->indent_level > 2)
  4956.     {
  4957.             SetDrPt(HTML_Data->rp, 0xFFFF);
  4958. //        XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4959. //            LineSolid, CapButt, JoinBevel);
  4960.         XDrawArc(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4961.             HTML_Data->drawGC,
  4962.             (x1 - width), y1,
  4963.             (width / 2), (width / 2), 0, 23040);
  4964.     }
  4965. }
  4966.  
  4967.  
  4968. /*
  4969.  * Redraw a formatted horizontal rule element
  4970.  */
  4971. void
  4972. HRuleRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr)
  4973. {
  4974.     int width, height;
  4975.     int x1, y1;
  4976.  
  4977.     width = (int)HTML_Data->view_width - (int)(2 * HTML_Data->margin_width);
  4978.     if (width < 0)
  4979.     {
  4980.         width = 0;
  4981.     }
  4982.  
  4983.     x1 = eptr->x;
  4984.     y1 = eptr->y;
  4985.     x1 = x1 - HTML_Data->scroll_x;
  4986.     y1 = y1 - HTML_Data->scroll_y;
  4987.     height = eptr->line_height;
  4988.  
  4989.     /* blank out area */
  4990.     XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->bg);
  4991.     XFillRectangle(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  4992.         HTML_Data->drawGC, x1, y1, width, height);
  4993.     y1 = y1 + (height / 2) - 1;
  4994.  
  4995.     SetDrPt(HTML_Data->rp, 0xFFFF);
  4996. //    XSetLineAttributes(XtDisplay(HTML_Data), HTML_Data->drawGC, 1,
  4997. //        LineSolid, CapButt, JoinBevel);
  4998.     /* changing the GC back and forth is not the most efficient way.... */
  4999. //    XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->fg);
  5000.     XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, 1);
  5001.     XDrawLine(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  5002.         HTML_Data->drawGC,
  5003.         x1, y1, (int)(x1 + width), y1);
  5004.     XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, 2);
  5005.     XDrawLine(XtDisplay(HTML_Data->view), XtWindow(HTML_Data->view),
  5006.         HTML_Data->drawGC,
  5007.         x1, y1 + 1, (int)(x1 + width), y1 + 1);
  5008. }
  5009.  
  5010.  
  5011. /*
  5012.  * Redraw a formatted image element.
  5013.  * The color of the image border reflects whether it is an active anchor
  5014.  * or not.
  5015.  * Actual Pixmap creation was put off until now to make sure we
  5016.  * had a window.  If it hasn't been already created, make the Pixmap
  5017.  * now.
  5018.  */
  5019. void
  5020. ImageRefresh(HTMLGadClData * HTML_Data, struct ele_rec *eptr)
  5021. {
  5022.     if (eptr->pic_data != NULL)
  5023.     {
  5024.         int x, y, extra;
  5025.  
  5026.         x = eptr->x;
  5027.         y = eptr->y + eptr->y_offset;
  5028.  
  5029.         if ((HTML_Data->border_images == True)||
  5030.             ((eptr->anchorHRef != NULL)&&
  5031.             (!eptr->pic_data->internal)))
  5032.         {
  5033.             extra = IMAGE_BORDER;
  5034.         }
  5035.         else
  5036.         {
  5037.             extra = 0;
  5038.         }
  5039.  
  5040.         x = x - HTML_Data->scroll_x;
  5041.         y = y - HTML_Data->scroll_y;
  5042.  
  5043.         XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->fg);
  5044.         XSetBackground(XtDisplay(HTML_Data), HTML_Data->drawGC, eptr->bg);
  5045.         XFillRectangle(XtDisplay(HTML_Data->view),
  5046.             XtWindow(HTML_Data->view), HTML_Data->drawGC,
  5047.             x, y,
  5048.             (eptr->pic_data->width + (1 * extra)),
  5049.             extra-1);
  5050.         XFillRectangle(XtDisplay(HTML_Data->view),
  5051.             XtWindow(HTML_Data->view), HTML_Data->drawGC,
  5052.             x,
  5053.             (y + eptr->pic_data->height + extra),
  5054.             (eptr->pic_data->width + (1 * extra)),
  5055.             extra-1);
  5056.         XFillRectangle(XtDisplay(HTML_Data->view),
  5057.             XtWindow(HTML_Data->view), HTML_Data->drawGC,
  5058.             x, y,
  5059.             extra-1,
  5060.             (eptr->pic_data->height + (1 * extra)));
  5061.         XFillRectangle(XtDisplay(HTML_Data->view),
  5062.             XtWindow(HTML_Data->view), HTML_Data->drawGC,
  5063.             (x + eptr->pic_data->width + extra),
  5064.             y,
  5065.             extra-1,
  5066.             (eptr->pic_data->height + (1 * extra)));
  5067.  
  5068.         if (eptr->pic_data->image == (Pixmap)NULL)
  5069.         {
  5070.             if (eptr->pic_data->image_data != NULL)
  5071.             {
  5072.                 eptr->pic_data->image = InfoToImage(HTML_Data,
  5073.                     eptr->pic_data);
  5074.             }
  5075.             else
  5076.             {
  5077.                 if (eptr->pic_data->delayed)
  5078.                 {
  5079.                     if ((eptr->anchorHRef != NULL)&&
  5080.                     (!IsDelayedHRef(HTML_Data, eptr->anchorHRef))&&
  5081.                     (!IsIsMapForm(HTML_Data, eptr->anchorHRef)))
  5082.                     {
  5083.                     eptr->pic_data->image = DelayedImage(
  5084.                         HTML_Data, True);
  5085.                     }
  5086.                     else
  5087.                     {
  5088.                     eptr->pic_data->image = DelayedImage(
  5089.                         HTML_Data, False);
  5090.                     }
  5091.                 }
  5092.                 else
  5093.                 {
  5094.                     /*
  5095.                      * Could be that the user opened another
  5096.                      * window, and the Pixmap was freed, and
  5097.                      * then they overflowed the cache,
  5098.                      * and the XImage data was freed.
  5099.                      * If this image was ever successfully
  5100.                      * fetched, try again before giving up.
  5101.                      */
  5102.                     if ((eptr->pic_data->fetched)&&
  5103.                     (HTML_Data->resolveDelayedImage != NULL))
  5104.                     {
  5105.                     ImageInfo *pdata;
  5106.  
  5107.                     pdata = eptr->pic_data;
  5108.                         eptr->pic_data = (*(resolveImageProc)
  5109.                     (HTML_Data->resolveDelayedImage))(HTML_Data,
  5110.                         eptr->edata);
  5111.                     if (eptr->pic_data != NULL)
  5112.                     {
  5113.                         eptr->pic_data->delayed = 0;
  5114.                         /*
  5115.                          * Mark images we have sucessfully
  5116.                          * loaded at least once
  5117.                          */
  5118.                         if (eptr->pic_data->image_data != NULL)
  5119.                         {
  5120.                         eptr->pic_data->fetched = 1;
  5121.                         }
  5122.                         /*
  5123.                          * Copy over state information from
  5124.                          * the last time we had this image
  5125.                          */
  5126.                          eptr->pic_data->ismap =
  5127.                         pdata->ismap;
  5128.                          eptr->pic_data->fptr =
  5129.                         pdata->fptr;
  5130.                          eptr->pic_data->internal =
  5131.                         pdata->internal;
  5132.                          eptr->pic_data->text =
  5133.                         pdata->text;
  5134.                     }
  5135.                     else
  5136.                     {
  5137.                         eptr->pic_data = NoImageData(HTML_Data);
  5138.                         eptr->pic_data->delayed = 0;
  5139.                         eptr->pic_data->internal = 0;
  5140.                     }
  5141.                     }
  5142.                     else
  5143.                     {
  5144.                     eptr->pic_data->image = NoImage(HTML_Data);
  5145.                     }
  5146.                 }
  5147.             }
  5148.         }
  5149.  
  5150.         if (eptr->pic_data->image != (Pixmap)NULL)
  5151.         {
  5152. #ifdef _AMIGA
  5153.         if(!eptr->pic_data->mask_bitmap)
  5154.             BltBitMapRastPort(eptr->pic_data->image, 0, 0,
  5155.                 HTML_Data->rp, x + extra + HTML_Data->view_left,
  5156.                 y + extra + HTML_Data->view_top,
  5157.                 eptr->pic_data->width, eptr->pic_data->height,
  5158.                 0xc0);
  5159.             else
  5160.             BltMaskBitMapRastPort(eptr->pic_data->image, 0, 0,
  5161.                 HTML_Data->rp, x + extra + HTML_Data->view_left,
  5162.                 y + extra + HTML_Data->view_top,
  5163.                 eptr->pic_data->width, eptr->pic_data->height,
  5164.                 0xE0,(APTR)(eptr->pic_data->mask_bitmap->Planes[0]));
  5165. #else /* _AMIGA */
  5166.             XCopyArea(XtDisplay(HTML_Data->view),
  5167.                 eptr->pic_data->image,
  5168.                 XtWindow(HTML_Data->view), HTML_Data->drawGC, 0, 0,
  5169.                 eptr->pic_data->width, eptr->pic_data->height,
  5170.                 (x + extra),
  5171.                 (y + extra));
  5172. #endif /* _AMIGA */
  5173.         }
  5174.         if ((eptr->pic_data->delayed)&&(eptr->anchorHRef != NULL)&&
  5175.             (!IsDelayedHRef(HTML_Data, eptr->anchorHRef))&&
  5176.             (!IsIsMapForm(HTML_Data, eptr->anchorHRef)))
  5177.         {
  5178.             XSetForeground(XtDisplay(HTML_Data), HTML_Data->drawGC,
  5179.                 eptr->fg);
  5180.             XFillRectangle(XtDisplay(HTML_Data->view),
  5181.                 XtWindow(HTML_Data->view), HTML_Data->drawGC,
  5182.                 x, (y + AnchoredHeight(HTML_Data)),
  5183.                 (eptr->pic_data->width + (1 * extra)),
  5184.                 extra);
  5185.         }
  5186.     }
  5187. }
  5188.  
  5189.  
  5190. void
  5191. RefreshTextRange(HTMLGadClData * HTML_Data, struct ele_rec *start, struct ele_rec *end)
  5192. {
  5193.     struct ele_rec *eptr;
  5194.  
  5195.     eptr = start;
  5196.     while ((eptr != NULL)&&(eptr != end))
  5197.     {
  5198.         if (eptr->type == E_TEXT)
  5199.         {
  5200.             TextRefresh(HTML_Data, eptr,
  5201.                 0, (eptr->edata_len - 2));
  5202.         }
  5203.         eptr = eptr->next;
  5204.     }
  5205.     if (eptr != NULL)
  5206.     {
  5207.         if (eptr->type == E_TEXT)
  5208.         {
  5209.             TextRefresh(HTML_Data, eptr,
  5210.                 0, (eptr->edata_len - 2));
  5211.         }
  5212.     }
  5213. }
  5214.  
  5215.  
  5216. /*
  5217.  * Refresh all elements on a single line into the widget's window
  5218.  */
  5219. void
  5220. PlaceLine(HTMLGadClData * HTML_Data, int line)
  5221. {
  5222.     struct ele_rec *eptr;
  5223.  
  5224.     /*
  5225.      * Item list for this line
  5226.      */
  5227.     eptr = HTML_Data->line_array[line];
  5228.  
  5229.     while ((eptr != NULL)&&(eptr->line_number == (line + 1)))
  5230.     {
  5231.         switch(eptr->type)
  5232.         {
  5233.             case E_TEXT:
  5234.                 TextRefresh(HTML_Data, eptr,
  5235.                     0, (eptr->edata_len - 2));
  5236.                 break;
  5237.             case E_BULLET:
  5238.                 BulletRefresh(HTML_Data, eptr);
  5239.                 break;
  5240.             case E_HRULE:
  5241.                 HRuleRefresh(HTML_Data, eptr);
  5242.                 break;
  5243.             case E_LINEFEED:
  5244.                 LinefeedRefresh(HTML_Data, eptr);
  5245.                 break;
  5246.             case E_IMAGE:
  5247.                 ImageRefresh(HTML_Data, eptr);
  5248.                 break;
  5249.             case E_WIDGET:
  5250. //                kprintf("Tried to refresh a widget\n");
  5251. #ifndef _AMIGA
  5252.                 WidgetRefresh(HTML_Data, eptr);
  5253. #endif /* _AMIGA */
  5254.                 break;
  5255.         }
  5256.         eptr = eptr->next;
  5257.     }
  5258. }
  5259.  
  5260.  
  5261. /*
  5262.  * Locate the element (if any) that is at the passed location
  5263.  * in the widget.  If there is no corresponding element, return
  5264.  * NULL.  If an element is found return the position of the character
  5265.  * you are at in the pos pointer passed.
  5266.  */
  5267. struct ele_rec *
  5268. LocateElement(HTMLGadClData * HTML_Data, int x, int y, int *pos)
  5269. {
  5270.     struct ele_rec *eptr;
  5271.     struct ele_rec *rptr;
  5272.     int i, start, end, line, guess;
  5273.     int tx1, tx2, ty1, ty2;
  5274.  
  5275.     x = x + HTML_Data->scroll_x;
  5276.     y = y + HTML_Data->scroll_y;
  5277.  
  5278.     /*
  5279.      * Narrow the search down to a 2 line range
  5280.      * before beginning to search element by element
  5281.      */
  5282.     start = -1;
  5283.     end = -1;
  5284.  
  5285.     /*
  5286.      * Heuristic to speed up redraws by guessing at the starting line.
  5287.      */
  5288.     guess = y / (HTML_Data->font->tf_YSize);
  5289.     if (guess > (HTML_Data->line_count - 1))
  5290.     {
  5291.         guess = HTML_Data->line_count - 1;
  5292.     }
  5293.     while (guess > 0)
  5294.     {
  5295.         if ((HTML_Data->line_array[guess] != NULL)&&
  5296.             (HTML_Data->line_array[guess]->y <= y))
  5297.         {
  5298.             break;
  5299.         }
  5300.         guess--;
  5301.     }
  5302.     if (guess < 0)
  5303.     {
  5304.         guess = 0;
  5305.     }
  5306.  
  5307.     for (i=guess; i<HTML_Data->line_count; i++)
  5308.     {
  5309.         if (HTML_Data->line_array[i] == NULL)
  5310.         {
  5311.             continue;
  5312.         }
  5313.         else if (HTML_Data->line_array[i]->y <= y)
  5314.         {
  5315.             start = i;
  5316.             continue;
  5317.         }
  5318.         else
  5319.         {
  5320.             end = i;
  5321.             break;
  5322.         }
  5323.     }
  5324.  
  5325.     /*
  5326.      * Search may have already failed, or it may be a one line
  5327.      * range.
  5328.      */
  5329.     if ((start == -1)&&(end == -1))
  5330.     {
  5331.         return(NULL);
  5332.     }
  5333.     else if (start == -1)
  5334.     {
  5335.         start = end;
  5336.     }
  5337.     else if (end == -1)
  5338.     {
  5339.         end = start;
  5340.     }
  5341.  
  5342.     /*
  5343.      * Search element by element, for now we only search
  5344.      * text elements, images, and linefeeds.
  5345.      */
  5346.     eptr = HTML_Data->line_array[start];
  5347.     ty1 = eptr->y;
  5348.     /*
  5349.      * Deal with bad Lucidia descents.
  5350.      */
  5351. #ifndef _AMIGA
  5352.     if (eptr->font->descent > eptr->font->max_bounds.descent)
  5353.     {
  5354.         ty2 = eptr->y + eptr->font->tf_YSize +
  5355.             eptr->font->descent;
  5356.     }
  5357.     else
  5358. #endif /* _AMIGA */
  5359.     {
  5360.         ty2 = eptr->y + eptr->font->tf_YSize;
  5361.     }
  5362.     line = eptr->line_number;
  5363.     /*
  5364.      * Searches on this line should extend to the top of the
  5365.      * next line, if possible.  Which might be far away if there
  5366.      * is an image on this line.
  5367.      */
  5368.     if (((line + 1) < HTML_Data->line_count)&&
  5369.         (HTML_Data->line_array[line + 1] != NULL))
  5370.     {
  5371.         ty2 = HTML_Data->line_array[line + 1]->y - 1;
  5372.     }
  5373.     /*
  5374.      * Else we are at the last line, and need to find its height.
  5375.      * The linefeed at the end should know the max height of the line.
  5376.      */
  5377.     else
  5378.     {
  5379.         struct ele_rec *teptr;
  5380.  
  5381.         teptr = eptr;
  5382.         while (teptr != NULL)
  5383.         {
  5384.             if (teptr->type == E_LINEFEED)
  5385.             {
  5386.                 break;
  5387.             }
  5388.             teptr = teptr->next;
  5389.         }
  5390.         if (teptr != NULL)
  5391.         {
  5392.             ty2 = teptr->y + teptr->line_height - 1;
  5393.         }
  5394.     }
  5395.  
  5396.     rptr = NULL;
  5397.     while ((eptr != NULL)&&(eptr->line_number <= (end + 1)))
  5398.     {
  5399.         if (eptr->line_number != line)
  5400.         {
  5401.             ty1 = ty2;
  5402.             /*
  5403.              * Deal with bad Lucidia descents.
  5404.              */
  5405. #ifndef _AMIGA
  5406.             if(eptr->font->descent > eptr->font->max_bounds.descent)
  5407.             {
  5408.                 ty2 = eptr->y + eptr->font->tf_YSize +
  5409.                     eptr->font->descent;
  5410.             }
  5411.             else
  5412. #endif /* _AMIGA */
  5413.             {
  5414.                 ty2 = eptr->y + eptr->font->tf_YSize;
  5415.             }
  5416.             line = eptr->line_number;
  5417.             /*
  5418.              * Searches on this line should extend to the top of
  5419.              * the next line, if possible.  Which might be far
  5420.              * away if there is an image on this line.
  5421.              */
  5422.             if (((line + 1) < HTML_Data->line_count)&&
  5423.                 (HTML_Data->line_array[line + 1] != NULL))
  5424.             {
  5425.                 ty2 = HTML_Data->line_array[line + 1]->y - 1;
  5426.             }
  5427.             /*
  5428.              * Else we are at the last line, and need to find its
  5429.              * height.  The linefeed at the end should know the
  5430.              * max height of the line.
  5431.              */
  5432.             else
  5433.             {
  5434.                 struct ele_rec *teptr;
  5435.  
  5436.                 teptr = eptr;
  5437.                 while (teptr != NULL)
  5438.                 {
  5439.                     if (teptr->type == E_LINEFEED)
  5440.                     {
  5441.                         break;
  5442.                     }
  5443.                     teptr = teptr->next;
  5444.                 }
  5445.                 if (teptr != NULL)
  5446.                 {
  5447.                     ty2 = teptr->y + teptr->line_height - 1;
  5448.                 }
  5449.             }
  5450.         }
  5451.  
  5452.         if (eptr->type == E_TEXT)
  5453.         {
  5454. //            int dir, ascent, descent;
  5455.             XCharStruct all;
  5456.  
  5457.             tx1 = eptr->x;
  5458.             XTextExtents(eptr->font, (char *)eptr->edata,
  5459.                     eptr->edata_len - 1, &dir,
  5460.                     &ascent, &descent, &all);
  5461.             tx2 = eptr->x + all.te_Width;
  5462.             if ((x >= tx1)&&(x <= tx2)&&(y >= ty1)&&(y <= ty2))
  5463.             {
  5464.                 rptr = eptr;
  5465.                 break;
  5466.             }
  5467.         }
  5468.         else if ((eptr->type == E_IMAGE)&&(eptr->pic_data != NULL))
  5469.         {
  5470.             tx1 = eptr->x;
  5471.             tx2 = eptr->x + eptr->pic_data->width;
  5472.             if ((x >= tx1)&&(x <= tx2)&&(y >= ty1)&&(y <= ty2))
  5473.             {
  5474.                 rptr = eptr;
  5475.                 break;
  5476.             }
  5477.         }
  5478.         else if (eptr->type == E_LINEFEED)
  5479.         {
  5480.             tx1 = eptr->x;
  5481.             if ((x >= tx1)&&(y >= ty1)&&(y <= ty2))
  5482.             {
  5483.                 rptr = eptr;
  5484.                 break;
  5485.             }
  5486.             else if (eptr->next == NULL)
  5487.             {
  5488.                 rptr = eptr;
  5489.                 break;
  5490.             }
  5491.             else if (eptr->next != NULL)
  5492.             {
  5493.                 int tmpy;
  5494.  
  5495.                 tmpy = eptr->next->y + eptr->next->line_height;
  5496.                 tx2 = eptr->next->x;
  5497.                 if ((x < tx2)&&(y >= ty2)&&(y <= tmpy))
  5498.                 {
  5499.                     rptr = eptr;
  5500.                     break;
  5501.                 }
  5502.             }
  5503.         }
  5504.         eptr = eptr->next;
  5505.     }
  5506.  
  5507.     return rptr;
  5508.  
  5509. #ifndef _AMIGA            /* this was causing input.device hits! */
  5510.     /*
  5511.      * If we found an element, locate the exact character position within
  5512.      * that element.
  5513.      */
  5514.     if (rptr != NULL)
  5515.     {
  5516. //        int dir, ascent, descent;
  5517.         XCharStruct all;
  5518.         int epos;
  5519.  
  5520.         /*
  5521.          * Start assuming fixed width font.  The real position should
  5522.          * always be <= to this, but just in case, start at the end
  5523.          * of the string if it is not.
  5524.          */
  5525. //        epos = ((x - rptr->x) / rptr->font->max_bounds.width) + 1;
  5526. //        if (epos >= rptr->edata_len - 1)
  5527.         {
  5528.             epos = rptr->edata_len - 2;
  5529.         }
  5530.         XTextExtents(rptr->font, (char *)rptr->edata,
  5531.                 (epos + 1), &dir, &ascent, &descent, &all);
  5532.         if (x > (int)(rptr->x + all.te_Width))
  5533.         {
  5534.             epos = rptr->edata_len - 3;
  5535.         }
  5536.         else
  5537.         {
  5538.             epos--;
  5539.         }
  5540.  
  5541.         while (epos >= 0)
  5542.         {
  5543.             XTextExtents(rptr->font, (char *)rptr->edata,
  5544.                 (epos + 1), &dir, &ascent, &descent, &all);
  5545.             if ((int)(rptr->x + all.te_Width) <= x)
  5546.             {
  5547.                 break;
  5548.             }
  5549.             epos--;
  5550.         }
  5551.         epos++;
  5552.         *pos = epos;
  5553.     }
  5554.     return(rptr);
  5555. #endif /* _AMIGA */
  5556. }
  5557.  
  5558.  
  5559. /*
  5560.  * Used by ParseTextToPrettyString to let it be sloppy about its
  5561.  * string creation, and never overflow the buffer.
  5562.  * It concatonates the passed string to the current string, managing
  5563.  * both the current string length, and the total buffer length.
  5564.  */
  5565. void
  5566. strcpy_or_grow(char **str, int *slen, int *blen, char *add)
  5567. {
  5568.     int newlen;
  5569.     int addlen;
  5570.     char *buf;
  5571.  
  5572.     /*
  5573.      * If necessary, initialize this string buffer
  5574.      */
  5575.     if (*str == NULL)
  5576.     {
  5577.         *str = (char *)malloc(1024 * sizeof(char));
  5578.         if (*str == NULL)
  5579.         {
  5580.             return;
  5581.         }
  5582.         *blen = 1024;
  5583.         strcpy(*str, "");
  5584.         *slen = 0;
  5585.     }
  5586.  
  5587.     buf = *str;
  5588.     if ((buf == NULL)||(add == NULL))
  5589.     {
  5590.         return;
  5591.     }
  5592.  
  5593.     addlen = strlen(add);
  5594.  
  5595.     newlen = *slen + addlen;
  5596.     if (newlen >= *blen)
  5597.     {
  5598.         newlen = ((newlen / 1024) + 1) * 1024;
  5599.         buf = (char *)malloc(newlen * sizeof(char));
  5600.         if (buf == NULL)
  5601.         {
  5602.             return;
  5603.         }
  5604.         bcopy(*str, buf, *blen);
  5605.         free((char *)*str);
  5606.         *str = buf;
  5607.         *blen = newlen;
  5608.     }
  5609.  
  5610.     bcopy(add, (char *)(buf + *slen), addlen + 1);
  5611.  
  5612.     *slen = *slen + addlen;
  5613. }
  5614.  
  5615.  
  5616. /*
  5617.  * Parse all the formatted text elements from start to end
  5618.  * into an ascii text string, and return it.
  5619.  * space_width and lmargin tell us how many spaces
  5620.  * to indent lines.
  5621.  */
  5622. char *
  5623. ParseTextToString(struct ele_rec *elist, struct ele_rec *startp,
  5624.           struct ele_rec *endp, int start_pos, int end_pos,
  5625.           int space_width, int lmargin)
  5626. {
  5627.     int newline;
  5628.     int epos;
  5629.     char *text;
  5630.     int t_slen, t_blen;
  5631.     struct ele_rec *eptr;
  5632.     struct ele_rec *start;
  5633.     struct ele_rec *end;
  5634.  
  5635.     if (startp == NULL)
  5636.     {
  5637.         return(NULL);
  5638.     }
  5639.  
  5640.     if (SwapElements(startp, endp, start_pos, end_pos))
  5641.     {
  5642.         start = endp;
  5643.         end = startp;
  5644.         epos = start_pos;
  5645.         start_pos = end_pos;
  5646.         end_pos = epos;
  5647.     }
  5648.     else
  5649.     {
  5650.         start = startp;
  5651.         end = endp;
  5652.     }
  5653.  
  5654.     text = NULL;
  5655.     newline = 0;
  5656.     eptr = start;
  5657.     while ((eptr != NULL)&&(eptr != end))
  5658.     {
  5659.         /*
  5660.          * Skip the special internal text
  5661.          */
  5662.         if (eptr->internal == True)
  5663.         {
  5664.             eptr = eptr->next;
  5665.             continue;
  5666.         }
  5667.  
  5668.         if (eptr->type == E_TEXT)
  5669.         {
  5670.             int i, spaces;
  5671.             char *tptr;
  5672.  
  5673.             if (eptr == start)
  5674.             {
  5675.                 tptr = (char *)(eptr->edata + start_pos);
  5676.             }
  5677.             else
  5678.             {
  5679.                 tptr = (char *)eptr->edata;
  5680.             }
  5681.  
  5682.             if (newline)
  5683.             {
  5684.                 spaces = (eptr->x - lmargin) / space_width;
  5685.                 if (spaces < 0)
  5686.                 {
  5687.                     spaces = 0;
  5688.                 }
  5689.                 for (i=0; i<spaces; i++)
  5690.                 {
  5691.                     strcpy_or_grow(&text, &t_slen, &t_blen,
  5692.                         " ");
  5693.                 }
  5694.             }
  5695.             strcpy_or_grow(&text, &t_slen, &t_blen, tptr);
  5696.             newline = 0;
  5697.         }
  5698.         else if (eptr->type == E_LINEFEED)
  5699.         {
  5700.             strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  5701.             newline = 1;
  5702.         }
  5703.         eptr = eptr->next;
  5704.     }
  5705.     if ((eptr != NULL)&&(eptr->internal == False))
  5706.     {
  5707.         if (eptr->type == E_TEXT)
  5708.         {
  5709.             int i, spaces;
  5710.             char *tptr;
  5711.             char *tend, tchar;
  5712.  
  5713.             if (eptr == start)
  5714.             {
  5715.                 tptr = (char *)(eptr->edata + start_pos);
  5716.             }
  5717.             else
  5718.             {
  5719.                 tptr = (char *)eptr->edata;
  5720.             }
  5721.  
  5722.             if (eptr == end)
  5723.             {
  5724.                 tend = (char *)(eptr->edata + end_pos + 1);
  5725.                 tchar = *tend;
  5726.                 *tend = '\0';
  5727.             }
  5728.  
  5729.             if (newline)
  5730.             {
  5731.                 spaces = (eptr->x - lmargin) / space_width;
  5732.                 if (spaces < 0)
  5733.                 {
  5734.                     spaces = 0;
  5735.                 }
  5736.                 for (i=0; i<spaces; i++)
  5737.                 {
  5738.                     strcpy_or_grow(&text, &t_slen, &t_blen,
  5739.                         " ");
  5740.                 }
  5741.             }
  5742.             strcpy_or_grow(&text, &t_slen, &t_blen, tptr);
  5743.             newline = 0;
  5744.  
  5745.             if (eptr == end)
  5746.             {
  5747.                 *tend = tchar;
  5748.             }
  5749.         }
  5750.         else if (eptr->type == E_LINEFEED)
  5751.         {
  5752.             strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  5753.             newline = 1;
  5754.         }
  5755.     }
  5756.     return(text);
  5757. }
  5758.  
  5759.  
  5760. /*
  5761.  * Parse all the formatted text elements from start to end
  5762.  * into an ascii text string, and return it.
  5763.  * Very like ParseTextToString() except the text is prettied up
  5764.  * to show headers and the like.
  5765.  * space_width and lmargin tell us how many spaces
  5766.  * to indent lines.
  5767.  */
  5768. char *
  5769. ParseTextToPrettyString(HTMLGadClData * HTML_Data, struct ele_rec *elist, struct ele_rec *startp,
  5770.             struct ele_rec *endp, int start_pos, int end_pos,
  5771.             int space_width, int lmargin)
  5772. {
  5773.     int line;
  5774.     int newline;
  5775.     int lead_spaces;
  5776.     int epos;
  5777.     char *text;
  5778.     int t_slen, t_blen;
  5779.     char *line_buf;
  5780.     int l_slen, l_blen;
  5781.     char lchar;
  5782.     struct ele_rec *eptr;
  5783.     struct ele_rec *start;
  5784.     struct ele_rec *end;
  5785.     struct ele_rec *last;
  5786.  
  5787.     if (startp == NULL)
  5788.     {
  5789.         return(NULL);
  5790.     }
  5791.  
  5792.     if (SwapElements(startp, endp, start_pos, end_pos))
  5793.     {
  5794.         start = endp;
  5795.         end = startp;
  5796.         epos = start_pos;
  5797.         start_pos = end_pos;
  5798.         end_pos = epos;
  5799.     }
  5800.     else
  5801.     {
  5802.         start = startp;
  5803.         end = endp;
  5804.     }
  5805.  
  5806.     text = NULL;
  5807.     line_buf = NULL;
  5808.  
  5809.     /*
  5810.      * We need to know if we should consider the indentation or bullet
  5811.      * that might be just before the first selected element to also be
  5812.      * selected.  This current hack looks to see if they selected the
  5813.      * Whole line, and assumes if they did, they also wanted the beginning.
  5814.      *
  5815.      * If we are at the beginning of the list, or the beginning of
  5816.      * a line, or just behind a bullett, assume this is the start of
  5817.      * a line that we may want to include the indent for.
  5818.      */
  5819.     if ((start_pos == 0)&&
  5820.         ((start->prev == NULL)||(start->prev->type == E_BULLET)||
  5821.         (start->prev->line_number != start->line_number)))
  5822.     {
  5823.         eptr = start;
  5824.         while ((eptr != NULL)&&(eptr != end)&&
  5825.             (eptr->type != E_LINEFEED))
  5826.         {
  5827.             eptr = eptr->next;
  5828.         }
  5829.         if ((eptr != NULL)&&(eptr->type == E_LINEFEED))
  5830.         {
  5831.             newline = 1;
  5832.             if ((start->prev != NULL)&&
  5833.                 (start->prev->type == E_BULLET))
  5834.             {
  5835.                 start = start->prev;
  5836.             }
  5837.         }
  5838.         else
  5839.         {
  5840.             newline = 0;
  5841.         }
  5842.     }
  5843.     else
  5844.     {
  5845.         newline = 0;
  5846.     }
  5847.  
  5848.     lead_spaces = 0;
  5849.     last = start;
  5850.     eptr = start;
  5851.     line = eptr->line_number;
  5852.     while ((eptr != NULL)&&(eptr != end))
  5853.     {
  5854.         /*
  5855.          * Skip the special internal text
  5856.          */
  5857.         if (eptr->internal == True)
  5858.         {
  5859.             eptr = eptr->next;
  5860.             continue;
  5861.         }
  5862.  
  5863.         if (eptr->type == E_BULLET)
  5864.         {
  5865.             int i, spaces;
  5866.  
  5867.             if (newline)
  5868.             {
  5869.                 spaces = (eptr->x - lmargin) / space_width;
  5870.                 spaces -= 2;
  5871.                 if (spaces < 0)
  5872.                 {
  5873.                     spaces = 0;
  5874.                 }
  5875.                 lead_spaces = spaces;
  5876.                 for (i=0; i<spaces; i++)
  5877.                 {
  5878.                     strcpy_or_grow(&line_buf,
  5879.                         &l_slen, &l_blen, " ");
  5880.                 }
  5881.             }
  5882.             newline = 0;
  5883.  
  5884.             strcpy_or_grow(&line_buf, &l_slen, &l_blen, "o ");
  5885.             lead_spaces += 2;
  5886.         }
  5887.         else if (eptr->type == E_TEXT)
  5888.         {
  5889.             int i, spaces;
  5890.             char *tptr;
  5891.  
  5892.             if (eptr == start)
  5893.             {
  5894.                 tptr = (char *)(eptr->edata + start_pos);
  5895.             }
  5896.             else
  5897.             {
  5898.                 tptr = (char *)eptr->edata;
  5899.             }
  5900.  
  5901.             if (newline)
  5902.             {
  5903.                 spaces = (eptr->x - lmargin) / space_width;
  5904.                 if (spaces < 0)
  5905.                 {
  5906.                     spaces = 0;
  5907.                 }
  5908.                 lead_spaces = spaces;
  5909.                 for (i=0; i<spaces; i++)
  5910.                 {
  5911.                     strcpy_or_grow(&line_buf,
  5912.                         &l_slen, &l_blen, " ");
  5913.                 }
  5914.             }
  5915.             strcpy_or_grow(&line_buf, &l_slen, &l_blen, tptr);
  5916.             newline = 0;
  5917.         }
  5918.         else if (eptr->type == E_LINEFEED)
  5919.         {
  5920.             strcpy_or_grow(&text, &t_slen, &t_blen, line_buf);
  5921.             strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  5922.             newline = 1;
  5923.             lchar = '\0';
  5924.             if (eptr->font == HTML_Data->header1_font)
  5925.             {
  5926.                 lchar = '*';
  5927.             }
  5928.             else if (eptr->font == HTML_Data->header2_font)
  5929.             {
  5930.                 lchar = '=';
  5931.             }
  5932.             else if (eptr->font == HTML_Data->header3_font)
  5933.             {
  5934.                 lchar = '+';
  5935.             }
  5936.             else if (eptr->font == HTML_Data->header4_font)
  5937.             {
  5938.                 lchar = '-';
  5939.             }
  5940.             else if (eptr->font == HTML_Data->header5_font)
  5941.             {
  5942.                 lchar = '~';
  5943.             }
  5944.             else if (eptr->font == HTML_Data->header6_font)
  5945.             {
  5946.                 lchar = '.';
  5947.             }
  5948.             if (lchar != '\0')
  5949.             {
  5950.                 char *ptr;
  5951.                 int cnt;
  5952.  
  5953.                 cnt = 0;
  5954.                 ptr = line_buf;
  5955.                 while ((ptr != NULL)&&(*ptr != '\0'))
  5956.                 {
  5957.                     cnt++;
  5958.                     if (cnt > lead_spaces)
  5959.                     {
  5960.                         *ptr = lchar;
  5961.                     }
  5962.                     ptr++;
  5963.                 }
  5964.                 strcpy_or_grow(&text,&t_slen,&t_blen, line_buf);
  5965.                 strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  5966.             }
  5967.             if (line_buf != NULL)
  5968.             {
  5969.                 free(line_buf);
  5970.                 line_buf = NULL;
  5971.             }
  5972.         }
  5973.         last = eptr;
  5974.         eptr = eptr->next;
  5975.     }
  5976.     if ((eptr != NULL)&&(eptr->internal == False))
  5977.     {
  5978.         if (eptr->type == E_BULLET)
  5979.         {
  5980.             int i, spaces;
  5981.  
  5982.             if (newline)
  5983.             {
  5984.                 spaces = (eptr->x - lmargin) / space_width;
  5985.                 spaces -= 2;
  5986.                 if (spaces < 0)
  5987.                 {
  5988.                     spaces = 0;
  5989.                 }
  5990.                 lead_spaces = spaces;
  5991.                 for (i=0; i<spaces; i++)
  5992.                 {
  5993.                     strcpy_or_grow(&line_buf,
  5994.                         &l_slen, &l_blen, " ");
  5995.                 }
  5996.             }
  5997.             newline = 0;
  5998.  
  5999.             strcpy_or_grow(&line_buf, &l_slen, &l_blen, "o ");
  6000.             lead_spaces += 2;
  6001.         }
  6002.         else if (eptr->type == E_TEXT)
  6003.         {
  6004.             int i, spaces;
  6005.             char *tptr;
  6006.             char *tend, tchar;
  6007.  
  6008.             if (eptr == start)
  6009.             {
  6010.                 tptr = (char *)(eptr->edata + start_pos);
  6011.             }
  6012.             else
  6013.             {
  6014.                 tptr = (char *)eptr->edata;
  6015.             }
  6016.  
  6017.             if (eptr == end)
  6018.             {
  6019.                 tend = (char *)(eptr->edata + end_pos + 1);
  6020.                 tchar = *tend;
  6021.                 *tend = '\0';
  6022.             }
  6023.  
  6024.             if (newline)
  6025.             {
  6026.                 spaces = (eptr->x - lmargin) / space_width;
  6027.                 if (spaces < 0)
  6028.                 {
  6029.                     spaces = 0;
  6030.                 }
  6031.                 lead_spaces = spaces;
  6032.                 for (i=0; i<spaces; i++)
  6033.                 {
  6034.                     strcpy_or_grow(&line_buf,
  6035.                         &l_slen, &l_blen, " ");
  6036.                 }
  6037.             }
  6038.             strcpy_or_grow(&line_buf, &l_slen, &l_blen, tptr);
  6039.             newline = 0;
  6040.  
  6041.             if (eptr == end)
  6042.             {
  6043.                 *tend = tchar;
  6044.             }
  6045.         }
  6046.         else if (eptr->type == E_LINEFEED)
  6047.         {
  6048.             strcpy_or_grow(&text, &t_slen, &t_blen, line_buf);
  6049.             strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  6050.             newline = 1;
  6051.             lchar = '\0';
  6052.             if (eptr->font == HTML_Data->header1_font)
  6053.             {
  6054.                 lchar = '*';
  6055.             }
  6056.             else if (eptr->font == HTML_Data->header2_font)
  6057.             {
  6058.                 lchar = '=';
  6059.             }
  6060.             else if (eptr->font == HTML_Data->header3_font)
  6061.             {
  6062.                 lchar = '+';
  6063.             }
  6064.             else if (eptr->font == HTML_Data->header4_font)
  6065.             {
  6066.                 lchar = '-';
  6067.             }
  6068.             else if (eptr->font == HTML_Data->header5_font)
  6069.             {
  6070.                 lchar = '~';
  6071.             }
  6072.             else if (eptr->font == HTML_Data->header6_font)
  6073.             {
  6074.                 lchar = '.';
  6075.             }
  6076.             if (lchar != '\0')
  6077.             {
  6078.                 char *ptr;
  6079.                 int cnt;
  6080.  
  6081.                 cnt = 0;
  6082.                 ptr = line_buf;
  6083.                 while ((ptr != NULL)&&(*ptr != '\0'))
  6084.                 {
  6085.                     cnt++;
  6086.                     if (cnt > lead_spaces)
  6087.                     {
  6088.                         *ptr = lchar;
  6089.                     }
  6090.                     ptr++;
  6091.                 }
  6092.                 strcpy_or_grow(&text,&t_slen,&t_blen, line_buf);
  6093.                 strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  6094.             }
  6095.             if (line_buf != NULL)
  6096.             {
  6097.                 free(line_buf);
  6098.                 line_buf = NULL;
  6099.             }
  6100.         }
  6101.         last = eptr;
  6102.     }
  6103.     if (line_buf != NULL)
  6104.     {
  6105.         strcpy_or_grow(&text, &t_slen, &t_blen, line_buf);
  6106.         lchar = '\0';
  6107.         if (last->font == HTML_Data->header1_font)
  6108.         {
  6109.             lchar = '*';
  6110.         }
  6111.         else if (last->font == HTML_Data->header2_font)
  6112.         {
  6113.             lchar = '=';
  6114.         }
  6115.         else if (last->font == HTML_Data->header3_font)
  6116.         {
  6117.             lchar = '+';
  6118.         }
  6119.         else if (last->font == HTML_Data->header4_font)
  6120.         {
  6121.             lchar = '-';
  6122.         }
  6123.         else if (last->font == HTML_Data->header5_font)
  6124.         {
  6125.             lchar = '~';
  6126.         }
  6127.         else if (last->font == HTML_Data->header6_font)
  6128.         {
  6129.             lchar = '.';
  6130.         }
  6131.         if (lchar != '\0')
  6132.         {
  6133.             char *ptr;
  6134.             int cnt;
  6135.  
  6136.             cnt = 0;
  6137.             ptr = line_buf;
  6138.             while ((ptr != NULL)&&(*ptr != '\0'))
  6139.             {
  6140.                 cnt++;
  6141.                 if (cnt > lead_spaces)
  6142.                 {
  6143.                     *ptr = lchar;
  6144.                 }
  6145.                 ptr++;
  6146.             }
  6147.             strcpy_or_grow(&text, &t_slen, &t_blen, "\n");
  6148.             strcpy_or_grow(&text, &t_slen, &t_blen, line_buf);
  6149.         }
  6150.     }
  6151.     if (line_buf != NULL)
  6152.     {
  6153.         free(line_buf);
  6154.         line_buf = NULL;
  6155.     }
  6156.     return(text);
  6157. }
  6158.  
  6159.  
  6160. /*
  6161.  * Find the preferred width of a parsed HTML document
  6162.  * Currently unformatted plain text, unformatted listing text, plain files
  6163.  * and preformatted text require special width.
  6164.  * Preferred width = (width of longest plain text line in document) *
  6165.  *     (width of that text's font)
  6166.  */
  6167. int
  6168. DocumentWidth(HTMLGadClData *  HTML_Data, struct mark_up *list)
  6169. {
  6170.     struct mark_up *mptr;
  6171.     int plain_text;
  6172.     int listing_text;
  6173.     int pcnt, lcnt, pwidth, lwidth;
  6174.     int width;
  6175.     char *ptr;
  6176.  
  6177.     /*
  6178.      * Loop through object list looking at the plain, preformatted,
  6179.      * and listing text
  6180.      */
  6181.     width = 0;
  6182.     pwidth = 0;
  6183.     lwidth = 0;
  6184.     plain_text = 0;
  6185.     listing_text = 0;
  6186.     mptr = list;
  6187.     while (mptr != NULL)
  6188.     {
  6189.         /*
  6190.          * All text blocks between the starting and ending
  6191.          * plain and pre text markers are plain text blocks.
  6192.          * Manipulate flags so we recognize these blocks.
  6193.          */
  6194.         if ((mptr->type == M_PLAIN_TEXT)||
  6195.             (mptr->type == M_PLAIN_FILE)||
  6196.             (mptr->type == M_PREFORMAT))
  6197.         {
  6198.             if (mptr->is_end)
  6199.             {
  6200.                 plain_text--;
  6201.                 if (plain_text < 0)
  6202.                 {
  6203.                     plain_text = 0;
  6204.                 }
  6205.             }
  6206.             else
  6207.             {
  6208.                 plain_text++;
  6209.             }
  6210.             pcnt = 0;
  6211.             lcnt = 0;
  6212.         }
  6213.         /*
  6214.          * All text blocks between the starting and ending
  6215.          * listing markers are listing text blocks.
  6216.          */
  6217.         else if (mptr->type == M_LISTING_TEXT)
  6218.         {
  6219.             if (mptr->is_end)
  6220.             {
  6221.                 listing_text--;
  6222.                 if (listing_text < 0)
  6223.                 {
  6224.                     listing_text = 0;
  6225.                 }
  6226.             }
  6227.             else
  6228.             {
  6229.                 listing_text++;
  6230.             }
  6231.             lcnt = 0;
  6232.             pcnt = 0;
  6233.         }
  6234.         /*
  6235.          * If this is a plain text block, add to line length.
  6236.          * Find the Max of all line lengths.
  6237.          */
  6238.         else if ((plain_text)&&(mptr->type == M_NONE))
  6239.         {
  6240.             ptr = mptr->text;
  6241.             while ((ptr != NULL)&&(*ptr != '\0'))
  6242.             {
  6243.                 ptr = MaxTextWidth(ptr, &pcnt);
  6244.                 if (pcnt > pwidth)
  6245.                 {
  6246.                     pwidth = pcnt;
  6247.                 }
  6248.             }
  6249.         }
  6250.         /*
  6251.          * If this is a listing text block, add to line length.
  6252.          * Find the Max of all line lengths.
  6253.          */
  6254.         else if ((listing_text)&&(mptr->type == M_NONE))
  6255.         {
  6256.             ptr = mptr->text;
  6257.             while ((ptr != NULL)&&(*ptr != '\0'))
  6258.             {
  6259.                 ptr = MaxTextWidth(ptr, &lcnt);
  6260.                 if (lcnt > lwidth)
  6261.                 {
  6262.                     lwidth = lcnt;
  6263.                 }
  6264.             }
  6265.         }
  6266.         mptr = mptr->next;
  6267.     }
  6268.     /* MDF - We can do this XSize stuff for fixed-width fonts only */
  6269.     width = pwidth * HTML_Data->plain_font->tf_XSize;
  6270.     lwidth = lwidth * HTML_Data->listing_font->tf_XSize;
  6271.     if (lwidth > width)
  6272.     {
  6273.         width = lwidth;
  6274.     }
  6275.     return(width);
  6276. }
  6277.  
  6278.