4 * Author: Teemu Rantanen <tvr@cs.hut.fi>
5 * Copyright (c) 1992 Teemu Rantanen
8 * Created: Wed Feb 26 15:59:04 1992 tvr
9 * Last modified: Mon Apr 27 00:41:22 1992 tvr
20 * This file interacts with WWWLibrary and builds one hypertext page.
21 * For every hypertext object on this page will be set
23 * - anchor information
25 * Empty object will be generated for paragraph endings, newlines and
31 * Debug module (temporary)
34 #define HT_DEBUG(a) /*printf a*/
41 void new_htext_object ();
42 void make_paragraph_object ();
43 void HText_setStyle ();
47 * Local text (temporary)
50 struct HText *HtLocalText;
54 * When constructing data, save it first here. Then malloc needed space
58 char localdata[HTEXT_MAX_OBJECT_SIZE];
62 * Set same anchor information to all objects belonging to same
66 HTChildAnchor *local_anchor = 0;
71 extern HTStyleSheet *styleSheet;
75 * This file has functions that WWWLibrary uses to construct an hypertext
84 HTParentAnchor *anchor;
89 * Create hypertext object.
92 self = (struct HText *) malloc (sizeof (struct HText));
97 HTAnchor_setDocument (anchor, (HyperDoc *) self);
103 memset (self, 0, sizeof (struct HText));
106 * Set some WWWLibrary stuff ...
108 self->node_anchor = anchor;
127 struct HTextObject *p, *p2;
128 struct HTextAnchor *a, *a2;
136 * Set some WWWLibrary stuff ...
138 if (self->node_anchor)
139 HTAnchor_setDocument (self->node_anchor, (HyperDoc *) 0);
143 * Free all data allocated on this file.
151 * Avoid loop if something goes wrong
153 p2->next = p2->prev = NULL;
162 a = self->anchorlist;
179 ht_get_default_style ()
181 HTStyle *p = styleSheet->styles;
185 if (!strcmp (p->SGMLTag, "XMP"))
191 * Return last if xmp not found
198 /* Object Building methods
199 ** -----------------------
201 ** These are used by a parser to build the text in an object
204 HText_beginAppend (text)
208 * Set object to accept text
211 new_htext_object (text);
215 HT_DEBUG ((stderr, "htext begin append failed?\n"));
219 * Set default style. Some pages cause no setStyle.
221 HText_setStyle (text, ht_get_default_style ());
225 /* New paragraph in current style
226 ** ------------------------------
227 ** See also: setStyle.
231 HText_appendParagraph (text)
234 HT_DEBUG (("\nHText_appendParagraph\n"));
237 * Create paragraph object
240 make_paragraph_object (text, HTEXT_PARAGRAPH);
246 /* Append a character to the text object
247 ** -------------------------------------
250 HText_appendCharacter (text, ch)
254 struct HTextObject *p;
256 static char lastchar = 0;
258 HT_DEBUG (("%c", ch));
268 * Parse special characters
273 make_paragraph_object (text, HTEXT_NEWLINE);
282 make_paragraph_object (text, HTEXT_TAB);
289 * Append space(s) at the end of objects
291 if (lastchar == ' ' && ch != ' ')
294 new_htext_object (text);
297 * Don't loose this character
301 HText_appendCharacter (text, ch);
311 * If local buffer is full, make continued hypertext object.
312 * This should not happen (is extreamely rare).
315 if (p->length >= HTEXT_MAX_OBJECT_SIZE)
318 p->paragraph = HTEXT_CONTINUE;
320 new_htext_object (text);
322 HText_appendCharacter (p, ch);
330 localdata[p->length++] = ch;
340 p = (HTextAnchor_t *) malloc (sizeof (HTextAnchor_t));
344 HT_DEBUG (("cannot malloc on htext_new_anchor(). tough.\n"));
349 memset (p, 0, sizeof (HTextAnchor_t));
358 /* Start an anchor field
361 HText_beginAnchor (text, anc)
365 HT_DEBUG (("\nHText_beginAnchor [%s]\n", anc->tag));
374 if (HTAnchor_followMainLink ((HTAnchor *) anc))
377 * Anchor is to be shown on the screen
379 new_htext_object (text);
384 * Anchor is HREF anchor only
386 if (!text->anchorlist)
389 text->anchorlist = htext_new_anchor ();
391 text->anchorlist->object = text->last;
393 text->anchorlist->anchor = anc;
399 HTextAnchor_t *p = text->anchorlist;
401 for (; p->next; p = p->next) ;
403 p->next = htext_new_anchor ();
405 p->next->anchor = anc;
407 p->next->object = text->last;
414 * End anchor creation
418 HText_endAnchor (text)
421 HT_DEBUG (("\nHText_endAnchor\n"));
424 * Create this anchor an object and create new
427 new_htext_object (text);
436 HText_appendText (text, str)
442 HT_DEBUG (("HText_appendText by characters\n"));
445 * Append characters (or better, words)
448 for (p = str; *p; p++)
449 HText_appendCharacter (text, *p);
458 HText_endAppend (text)
461 HT_DEBUG (("HText_endAppend"));
463 new_htext_object (text);
468 HText_setStyle (text, style)
472 HT_DEBUG (("HText_setStyle %s\n", style->name));
476 HT_DEBUG (("HText bug on HText_setStyle ... not changing style\n"));
483 new_htext_object (text);
486 * If many headers in a row, append paragraph
488 if (text->last->style == style)
490 HText_appendParagraph (text);
493 text->last->style = style;
502 HT_DEBUG (("\nHText_select ??????\n"));
513 HText_selectAnchor (text, anchor)
515 struct HTChildAnchor *anchor;
517 HT_DEBUG (("\nHText_selectAnchor\n"));
527 * Allocate new object. Set up modes from previous. Set up data -area.
531 malloc_ht_object (prev)
532 struct HTextObject *prev;
534 struct HTextObject *p;
540 p = (struct HTextObject *) malloc (sizeof (struct HTextObject));
544 HT_DEBUG (("cannot malloc hypertextobject\n"));
551 memcpy (p, prev, sizeof (struct HTextObject));
565 memset (p, 0, sizeof (struct HTextObject));
577 * Create new hypertext object.
581 new_htext_object (text)
584 struct HTextObject *p;
589 if (text->first == 0)
591 text->first = text->last = malloc_ht_object (NULL);
597 * Temporary assignment
603 * Strip all null objects exept paragraph marks
605 if ((p->length == 0) && !(p->paragraph))
609 * Check paragraph objects
611 if (p->paragraph && (p->paragraph != HTEXT_CONTINUE) && p->length)
613 HT_DEBUG (("non null paragraph object ?\n"));
618 * If constructing object, malloc and copy local data
624 p->data = (char *) malloc (p->length + 1);
628 HT_DEBUG (("cannot malloc data on new_htext_object()\n"));
632 memcpy (p->data, localdata, p->length);
634 p->data[p->length] = 0;
638 * Set anchorinformation to object
641 p->anchor = local_anchor;
647 p = malloc_ht_object (text->last);
653 p->prev = text->last;
655 text->last->next = p;
663 * Make empty object only stating paragraph, tab or newline
667 make_paragraph_object (text, type)
671 new_htext_object (text);
673 text->last->paragraph = type;
675 new_htext_object (text);
681 * Malloc and copy data
684 ht_memdup (data, len)
690 p = (char *) malloc (len);
695 memcpy (p, data, len);
702 * Duplicate object information of this hypertext-page
710 HTextObject_t *o, *p;
711 HTextObject_t *p_old = 0;
713 newtext = (HText_t *) malloc (sizeof (*newtext));
718 memset (newtext, 0, sizeof (*newtext));
723 * Allocate new htext -page info
727 p = newtext->first = (HTextObject_t *) malloc (sizeof (*p));
740 memset (p, 0, sizeof (*p));
742 p->paragraph = o->paragraph;
744 p->length = o->length;
748 p->data = (char *) ht_memdup (o->data, o->length);
753 goto free_allocated_error;
763 p = (HTextObject_t *) malloc (sizeof (*p));
768 goto free_allocated_error;
781 free_allocated_error: