Annotation of libwww/LineMode/src/GridText.c, revision 1.35
1.13 frystyk 1: /* GridText.c
2: ** CHARACTER GRID HYPERTEXT OBJECT
3: **
1.17 frystyk 4: ** (c) COPYRIGHT MIT 1995.
1.13 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
6: **
1.30 frystyk 7: ** This is the definition of the HyperDoc object and the HText interface
8: ** which is used in the current Library HTML parser
1.1 timbl 9: */
10:
1.16 frystyk 11: #include <assert.h>
12:
13: #include "WWWLib.h"
1.33 frystyk 14: #include "WWWCache.h"
15: #include "WWWRules.h"
1.19 frystyk 16: #include "HTBrowse.h"
1.16 frystyk 17: #include "HTFont.h"
18: #include "GridStyle.h"
19: #include "GridText.h"
1.1 timbl 20:
1.23 frystyk 21: #include "HTReqMan.h"
22:
1.11 howcome 23: /* HWL 18/7/94: applied patch from agl@glas2.glas.apc.org (Anton Tropashko) */
24: #ifdef CYRILLIC
25: #include "a_stdio.h"
26: #endif
27:
1.1 timbl 28: #define MAX_LINE HTScreenWidth /* No point in accumulating more */
1.16 frystyk 29: #define LOADED_LIMIT 6 /* For now, save last five texts */
1.1 timbl 30:
31: #ifdef CURSES
32: #define DISPLAY_LINES (HTScreenHeight)
33: #define TITLE_LINES 0
34: #else
1.19 frystyk 35: #define DISPLAY_LINES (HTScreenHeight - 2) /* Exclude prompt line */
1.1 timbl 36: #define TITLE_LINES 1
37: #endif
38:
1.19 frystyk 39: struct _HTStream { /* only know it as object */
40: CONST HTStreamClass * isa;
41: /* ... */
42: };
1.1 timbl 43:
44: /* From default style sheet:
45: */
46: extern HTStyleSheet * styleSheet; /* Default or overridden */
47:
48: /* Exports
49: */
50: PUBLIC HText * HTMainText = 0; /* Equivalent of main window */
51: PUBLIC HTParentAnchor * HTMainAnchor = 0; /* Anchor for HTMainText */
52:
53: typedef struct _line {
54: struct _line *next;
55: struct _line *prev;
56: short unsigned offset; /* Implicit initial spaces */
57: short unsigned size; /* Number of characters */
58: BOOL split_after; /* Can we split after? */
59: BOOL bullet; /* Do we bullet? */
60: char data[1]; /* Space for terminator at least! */
61: } HTLine;
62:
63: #define LINE_SIZE(l) (sizeof(HTLine)+(l)) /* allow for terminator */
64:
65: typedef struct _TextAnchor {
66: struct _TextAnchor * next;
67: int number; /* For user interface */
68: int start; /* Characters */
69: int extent; /* Characters */
70: HTChildAnchor * anchor;
71: } TextAnchor;
72:
73:
74: /* Notes on struct _Htext:
75: ** next_line is valid iff state is false.
76: ** top_of_screen line means the line at the top of the screen
77: ** or just under the title if there is one.
78: */
79: struct _HText {
80: HTParentAnchor * node_anchor;
81: char * title;
82: HTLine * last_line;
83: int lines; /* Number of them */
84: int chars; /* Number of them */
85: TextAnchor * first_anchor; /* Singly linked list */
86: TextAnchor * last_anchor;
87: int last_anchor_number; /* user number */
88: /* For Internal use: */
89: HTStyle * style; /* Current style */
90: int display_on_the_fly; /* Lines left */
1.3 timbl 91: BOOL all_pages; /* Loop on the fly */
1.1 timbl 92: int top_of_screen; /* Line number */
93: HTLine * top_of_screen_line; /* Top */
94: HTLine * next_line; /* Bottom + 1 */
95: int permissible_split; /* in last line */
96: BOOL in_line_1; /* of paragraph */
97: BOOL stale; /* Must refresh */
98:
99: HTStream* target; /* Output stream */
100: HTStreamClass targetClass; /* Output routines */
101: };
102:
103:
104: #define PUTC(c) (*text->targetClass.put_character)(text->target, c)
105: #define PUTS(s) (*text->targetClass.put_string)(text->target, s)
106:
107: /* Boring static variable used for moving cursor across
108: */
109:
110: #define SPACES(n) (&space_string[HTScreenWidth - (n)])
111: /* String containing blank spaces only */
112: PRIVATE char * space_string;
113:
114: PRIVATE HTStyle default_style =
115: { 0, "(Unstyled)", "",
116: (HTFont)0, 1.0, HT_BLACK, 0, 0,
117: 0, 0, 0, HT_LEFT, 1, 0, 0,
118: NO, NO, 0, 0, 0 };
119:
120:
1.29 frystyk 121: PUBLIC void clear_screen (void); /* Forward */
1.1 timbl 122:
123: PRIVATE HTList * loaded_texts; /* A list of all those in memory */
124:
125: /* Creation Method
126: ** ---------------
1.3 timbl 127: **
128: ** Interactive version
129: **
1.1 timbl 130: */
1.31 frystyk 131: PUBLIC HText * HText_new (HTRequest * request, HTParentAnchor * anchor)
1.1 timbl 132: {
133: HTLine * line;
1.34 frystyk 134: HText * self;
135: if ((self = (HText *) HT_MALLOC(sizeof(*self))) == NULL)
136: /* HT_OUTOFMEM("HText"); */
137: return self;
1.1 timbl 138:
139: if (!loaded_texts) loaded_texts = HTList_new();
140: HTList_addObject(loaded_texts, self);
141: if (HTList_count(loaded_texts) >= LOADED_LIMIT) {
1.20 frystyk 142: if (CACHE_TRACE)
1.26 frystyk 143: TTYPrint(TDEST, "MemoryCache. Freeing off cached doc.\n");
1.1 timbl 144: HText_free((HText *)HTList_removeFirstObject(loaded_texts));
145: }
146:
1.34 frystyk 147: if ((line = self->last_line = (HTLine *) HT_MALLOC(LINE_SIZE(MAX_LINE))) == NULL)
148: HT_OUTOFMEM("HText_New");
1.1 timbl 149: line->next = line->prev = line;
150: line->offset = line->size = 0;
151: self->lines = self->chars = 0;
152: self->title = 0;
153: self->first_anchor = self->last_anchor = 0;
154: self->style = &default_style;
155: self->top_of_screen = 0;
156: self->node_anchor = anchor;
157: self->last_anchor_number = 0; /* Numbering of them for references */
158: self->stale = YES;
159:
160: self->target = NULL;
161:
1.31 frystyk 162: HTAnchor_setDocument(anchor, (void *) self);
1.1 timbl 163:
164: clear_screen();
165: HTMainText = self;
166: HTMainAnchor = anchor;
167: self->display_on_the_fly = DISPLAY_LINES;
1.3 timbl 168: self->all_pages = NO; /* One page at a time on the fly */
1.1 timbl 169:
170: if (!space_string) { /* Make a blank line */
171: char *p;
1.34 frystyk 172: if ((space_string = (char *) HT_MALLOC(HTScreenWidth+1)) == NULL)
173: HT_OUTOFMEM("HText_New");
1.1 timbl 174: for (p=space_string; p<space_string+HTScreenWidth; p++)
175: *p = ' '; /* Used for printfs later */
176: space_string[HTScreenWidth] = '\0';
177: }
178:
179: return self;
180: }
181:
182:
183: /* Creation Method 2
184: ** ---------------
185: **
1.4 timbl 186: ** Non-interative OR interactive if stream is NULL
1.1 timbl 187: ** Stream is assumed open and left open.
188: */
1.31 frystyk 189: PUBLIC HText * HText_new2 (HTRequest * request,
190: HTParentAnchor * anchor,
191: HTStream * stream)
1.1 timbl 192: {
1.31 frystyk 193: HText * me = HText_new(request, anchor);
1.1 timbl 194:
195: if (stream) {
1.3 timbl 196: me->target = stream;
197: me->targetClass = *stream->isa; /* copy action procedures */
1.4 timbl 198: me->all_pages = YES; /* Display whole file on the fly */
1.3 timbl 199: }
200: return me;
1.1 timbl 201: }
202:
1.31 frystyk 203: /* Free a data object
204: ** ------------------
205: ** Removes the data object from the anchor
1.1 timbl 206: */
1.29 frystyk 207: PUBLIC void hyperfree (HText * self)
1.1 timbl 208: {
1.35 ! frystyk 209: if (self) {
! 210: while (1) { /* Free off line array */
! 211: HTLine * last = self->last_line;
! 212: if (last) {
! 213: last->next->prev = last->prev;
! 214: last->prev->next = last->next;
! 215: self->last_line = last->prev;
! 216: if (last == self->last_line) break;
! 217: HT_FREE(last);
! 218: }
! 219: break;
! 220: }
! 221: while (self->first_anchor) { /* Free off anchor array */
! 222: TextAnchor * last = self->first_anchor;
! 223: self->first_anchor = last->next;
! 224: HT_FREE(last);
! 225: }
! 226: if (self == HTMainText) HTMainText = NULL;
! 227: HT_FREE(self);
! 228: }
1.18 frystyk 229: }
230:
231:
232: /* Free Entire Text
233: ** ----------------
234: */
1.29 frystyk 235: PUBLIC void HText_free (HText * self)
1.18 frystyk 236: {
1.35 ! frystyk 237: if (self) {
! 238: HTAnchor_setDocument(self->node_anchor, NULL);
! 239: hyperfree(self);
! 240: }
1.1 timbl 241: }
242:
243:
244: /* Display Methods
245: ** ---------------
246: */
1.22 frystyk 247:
1.1 timbl 248: /* Clear the screen (on screen-mode systems)
249: ** ----------------
250: */
1.29 frystyk 251: PUBLIC void clear_screen (void)
1.1 timbl 252: {
1.25 frystyk 253: if (WWWTRACE)
1.22 frystyk 254: return; /* in trace mode, don't clear trace away */
1.1 timbl 255: #ifdef CURSES
256: if (w_text != NULL) {
1.22 frystyk 257: wmove(w_text,0,0);
258: wclear(w_text);
1.1 timbl 259: }
1.22 frystyk 260: #endif /* Not CURSES */
1.1 timbl 261: if (HTMainText) HTMainText->stale = YES;
262: }
263:
264:
265: /* Output a line
266: ** -------------
267: */
1.29 frystyk 268: PRIVATE void display_line (HText * text, HTLine * line)
1.1 timbl 269: {
270: #ifdef CURSES
271: int y, x;
272:
273: waddstr(w_text, SPACES(line->offset));
274: waddstr(w_text, line->data);
275: getyx(w_text, y, x);
276: if (y < DISPLAY_LINES-1) {
277: wmove(w_text, ++y, 0);
278: }
279: #else
280: if (!text->target)
1.11 howcome 281: {
282: #ifdef CYRILLIC
283: /* HWL 18/7/94: applied patch from agl@glas2.glas.apc.org (Anton Tropashko) */
284: a_print(SPACES(line->offset),H,stdout);
285: a_print(line->data,H,stdout);
286: fputc('\n',stdout);
287: #else
1.26 frystyk 288: TTYPrint(STDOUT, "%s%s\n", SPACES(line->offset), line->data);
1.11 howcome 289: #endif
290: }
1.1 timbl 291: else {
292: PUTS(SPACES(line->offset));
293: PUTS(line->data);
294: PUTC('\n');
295: }
296: #endif
297:
298: }
299:
300: /* Output the title line
301: ** ---------------------
302: */
1.29 frystyk 303: PRIVATE void display_title (HText * text)
1.1 timbl 304: {
305: CONST char * title = HTAnchor_title(text->node_anchor);
306: char percent[20], format[20];
307: if (text->lines > (DISPLAY_LINES-1)) {
308: #ifdef NOPE
309: sprintf(percent, " (p%d of %d)",
310: (text->top_of_screen/(DISPLAY_LINES-1)) + 1,
311: (text->lines-1)/(DISPLAY_LINES-1) + 1);
312: sprintf(percent, " (%d%%)",
313: 100*(text->top_of_screen+DISPLAY_LINES-1)/ /* Seen */
314: (text->lines)); /* Total */
315: #else
316: sprintf(percent, " (%d/%d)",
317: text->top_of_screen+DISPLAY_LINES-1, /* Seen */
318: text->lines); /* Total */
319: #endif
320: } else {
321: percent[0] = 0; /* Null string */
322: }
323:
324: sprintf(format, "%%%d.%ds%%s\n", /* Generate format string */
325: (int)(HTScreenWidth-strlen(percent)),
326: (int)(HTScreenWidth-strlen(percent)) );
327: #ifdef CURSES
328: mvwprintw(w_top, 0, 0, format, title, percent);
329: wrefresh(w_top);
330: #else
1.26 frystyk 331: if (!text->target) TTYPrint(STDOUT, format, title, percent);
1.1 timbl 332: else {
1.34 frystyk 333: char * line;
334: if ((line = (char *) HT_MALLOC(HTScreenWidth+10)) == NULL)
335: HT_OUTOFMEM("display_titile");
1.1 timbl 336: sprintf(line, format, title, percent);
337: PUTS(line);
1.34 frystyk 338: HT_FREE(line);
1.1 timbl 339: }
340: #endif
341: }
342:
343:
344: /* Fill the screen with blank after the file
345: ** --------------------------
346: */
1.29 frystyk 347: PRIVATE void fill_screen (HText * text, int n)
1.1 timbl 348: {
349: if (n<=0 || n>1000) return; /* Large value means no pagination */
350: if (text->target) return;
351: #ifdef CURSES
352: waddstr(w_text, end_mark);
353: wclrtobot(w_text);
354: wrefresh(w_text);
355: #else
356: #ifndef VIOLA
1.26 frystyk 357: if (!text->target) TTYPrint(STDOUT, "%s\n", end_mark);
1.1 timbl 358: else { PUTS(end_mark); PUTC('\n'); }
359: n--;
360:
361: for (; n; n--) {
1.26 frystyk 362: if (!text->target) TTYPrint(STDOUT, "\n");
1.1 timbl 363: else PUTC('\n');
364: }
365: #endif
366: #endif /* Not CURSES */
367: }
368:
369:
370: /* Output a page
371: ** -------------
372: */
1.29 frystyk 373: PRIVATE void display_page (HText * text, int line_number)
1.1 timbl 374: {
375: HTLine * line = text->last_line->prev;
376: int i;
377: CONST char * title = HTAnchor_title(text->node_anchor);
378: int lines_of_text = title ? (DISPLAY_LINES-TITLE_LINES) : DISPLAY_LINES;
379: int last_screen = text->lines - lines_of_text;
380:
381: /* Constrain the line number to be within the document
382: */
383: if (text->lines <= lines_of_text) line_number = 0;
384: else if (line_number>last_screen) line_number = last_screen;
385: else if (line_number < 0) line_number = 0;
386:
387: for(i=0, line = text->last_line->next; /* Find line */
388: i<line_number && (line!=text->last_line);
389: i++, line=line->next) /* Loop */ assert(line->next != NULL);
390:
391: while((line!=text->last_line) && (line->size==0)) { /* Skip blank lines */
392: assert(line->next != NULL);
393: line = line->next;
394: line_number ++;
395: }
396:
397: /* Can we just scroll to it?
398: */
399: #ifndef VM /* No scrolling */
400: if (!text->stale && (line_number>=text->top_of_screen) &&
401: (line_number < text->top_of_screen + DISPLAY_LINES)) { /* Yes */
402: lines_of_text = line_number - text->top_of_screen;
403: line = text->next_line;
404: text->top_of_screen = line_number;
405: #ifdef CURSES
406: scrollok(w_text, TRUE);
407: for (i = 0; i < lines_of_text; i++) {
408: scroll(w_text);
409: }
410: #endif
411: } else
412: #endif
413: {
414: clear_screen(); /* No */
415: text->top_of_screen = line_number;
416: if (title) display_title(text);
417: }
418:
419: /* Bug: when we scroll to a part slightly futher down a page which previously
420: fitted all on one screen including the [End], the code below will add an
421: extra [End] to the screen, giving a total of two, one underneath the other.
422: */
423:
424: /* print it
425: */
426: if (line) {
427: for(i=0;
428: (i< lines_of_text) && (line != text->last_line); i++) {
429: assert(line != NULL);
430: display_line(text, line);
431: line = line->next;
432: }
433: fill_screen(text, lines_of_text - i);
434: }
435:
436: text->next_line = line; /* Line after screen */
437: text->stale = NO; /* Display is up-to-date */
438: }
439:
440:
441: /* Object Building methods
442: ** -----------------------
443: **
444: ** These are used by a parser to build the text in an object
445: */
1.29 frystyk 446: PUBLIC void HText_beginAppend (HText * text)
1.1 timbl 447: {
448: text->permissible_split = 0;
449: text->in_line_1 = YES;
450: }
451:
452:
453: /* Add a new line of text
454: ** ----------------------
455: **
456: ** On entry,
457: **
458: ** split is zero for newline function, else number of characters
459: ** before split.
460: ** text->display_on_the_fly
461: ** may be set to indicate direct output of the finished line.
1.3 timbl 462: ** text->all_pages
463: ** if set indicates all pages are to be done on the fly.
1.1 timbl 464: ** On exit,
465: ** A new line has been made, justified according to the
466: ** current style. Text after the split (if split nonzero)
467: ** is taken over onto the next line.
468: **
469: ** If display_on_the_fly is set, then it is decremented and
470: ** the finished line is displayed.
471: */
472: #define new_line(text) split_line(text, 0)
473:
1.29 frystyk 474: PRIVATE void split_line (HText * text, int split)
1.1 timbl 475: {
476: HTStyle * style = text->style;
477: int spare;
1.14 frystyk 478: int indent = (int) (text->in_line_1 ? text->style->indent1st
479: : text->style->leftIndent);
1.7 frystyk 480:
1.1 timbl 481: /* Make new line
482: */
483: HTLine * previous = text->last_line;
1.34 frystyk 484: HTLine * line;
485: if ((line = (HTLine *) HT_MALLOC(LINE_SIZE(MAX_LINE))) == NULL)
486: HT_OUTOFMEM("split_line");
487:
1.1 timbl 488: text->lines++;
489:
490: previous->next->prev = line;
491: line->prev = previous;
492: line->next = previous->next;
493: previous->next = line;
494: text->last_line = line;
495: line->size = 0;
496: line->offset = 0;
497:
498: /* Split at required point
499: */
500: if (split) { /* Delete space at "split" splitting line */
501: char * p;
502: previous->data[previous->size] = 0;
503: for (p = &previous->data[split]; *p; p++)
504: if (*p != ' ') break;
505: strcpy(line->data, p);
506: line->size = strlen(line->data);
507: previous->size = split;
508: }
509:
510: /* Economise on space.
511: ** Not on the RS6000 due to a chaotic bug in realloc argument passing.
512: ** Same problem with Ultrix (4.2) : realloc() is not declared properly.
513: */
1.16 frystyk 514: #ifndef AIX
515: #ifndef ultrix
1.1 timbl 516: while ((previous->size > 0) &&
517: (previous->data[previous->size-1] == ' ')) /* Strip trailers */
518: previous->size--;
1.7 frystyk 519:
1.34 frystyk 520: if ((previous = (HTLine *) HT_REALLOC(previous, LINE_SIZE(previous->size))) == NULL)
521: HT_OUTOFMEM("split_line");
1.16 frystyk 522: #endif /* ultrix */
523: #endif /* AIX */
1.1 timbl 524:
525: previous->prev->next = previous; /* Link in new line */
526: previous->next->prev = previous; /* Could be same node of course */
527:
528: /* Terminate finished line for printing
529: */
530: previous->data[previous->size] = 0;
1.7 frystyk 531:
1.1 timbl 532: /* Align left, right or center
533: */
534:
1.14 frystyk 535: spare = (int) (HTScreenWidth - style->rightIndent + style->leftIndent -
536: previous->size); /* @@ first line indent */
1.1 timbl 537:
538: switch (style->alignment) {
539: case HT_CENTER :
540: previous->offset = previous->offset + indent + spare/2;
541: break;
542: case HT_RIGHT :
543: previous->offset = previous->offset + indent + spare;
544: break;
545: case HT_LEFT :
546: case HT_JUSTIFY : /* Not implemented */
547: default:
548: previous->offset = previous->offset + indent;
549: break;
550: } /* switch */
551:
552: text->chars = text->chars + previous->size + 1; /* 1 for the line */
553: text->in_line_1 = NO; /* unless caller sets it otherwise */
554:
555: /* If displaying as we go, output it:
556: */
557: if (text->display_on_the_fly) {
558: if (text->display_on_the_fly == DISPLAY_LINES) { /* First line */
559: if (previous->size == 0) {
560: text->top_of_screen++; /* Scroll white space off top */
561: return;
562: }
563: if (HTAnchor_title(text->node_anchor)) { /* Title exists */
564: display_title(text);
565: text->display_on_the_fly--;
566: }
567: }
568: display_line(text, previous);
569: text->display_on_the_fly--;
1.3 timbl 570:
571: /* Loop to top of next page? */
572: if (!text->display_on_the_fly && text->all_pages) {
573: PUTS("\f\n"); /* Form feed on its own line a la rfc1111 */
574: text->display_on_the_fly = DISPLAY_LINES;
575: }
1.1 timbl 576: }
577: } /* split_line */
578:
579:
580: /* Allow vertical blank space
581: ** --------------------------
582: */
1.29 frystyk 583: PRIVATE void blank_lines (HText * text, int newlines)
1.1 timbl 584: {
585: if (text->last_line->size == 0) { /* No text on current line */
586: HTLine * line = text->last_line->prev;
587: while ((line!=text->last_line) && (line->size == 0)) {
588: if (newlines==0) break;
589: newlines--; /* Don't bother: already blank */
590: line = line->prev;
591: }
592: } else {
593: newlines++; /* Need also to finish this line */
594: }
595:
596: for(;newlines;newlines--) {
597: new_line(text);
598: }
599: text->in_line_1 = YES;
600: }
601:
602:
603: /* New paragraph in current style
604: ** ------------------------------
605: ** See also: setStyle.
606: */
607:
1.29 frystyk 608: PUBLIC void HText_appendParagraph (HText * text)
1.1 timbl 609: {
1.14 frystyk 610: int after = (int) text->style->spaceAfter;
611: int before = (int) text->style->spaceBefore;
1.1 timbl 612: blank_lines(text, after>before ? after : before);
613: }
614:
615:
616: /* Set Style
617: ** ---------
618: **
619: ** Does not filter unnecessary style changes.
620: */
1.29 frystyk 621: PUBLIC void HText_setStyle (HText * text, HTStyle * style)
1.1 timbl 622: {
623: int after, before;
624:
625: if (!style) return; /* Safety */
1.14 frystyk 626: after = (int) text->style->spaceAfter;
627: before = (int) style->spaceBefore;
1.20 frystyk 628: if (SGML_TRACE)
1.26 frystyk 629: TTYPrint(TDEST, "HTML: Change to style %s\n", style->name);
1.1 timbl 630: blank_lines (text, after>before ? after : before);
631: text->style = style;
632: }
633:
634:
635: /* Append a character to the text object
636: ** -------------------------------------
637: */
1.29 frystyk 638: PUBLIC void HText_appendCharacter (HText * text, char ch)
1.1 timbl 639: {
640: HTLine * line = text->last_line;
641: HTStyle * style = text->style;
1.14 frystyk 642: int indent = (int)(text->in_line_1 ? style->indent1st : style->leftIndent);
1.1 timbl 643:
644: /* New Line
645: */
646: if (ch == '\n') {
647: new_line(text);
648: text->in_line_1 = YES; /* First line of new paragraph */
649: return;
650: }
651:
652: /* Tabs
653: */
654:
655: if (ch == '\t') {
656: HTTabStop * tab;
657: int target; /* Where to tab to */
658: int here = line->size + line->offset +indent;
659: if (style->tabs) { /* Use tab table */
660: for (tab = style->tabs;
661: tab->position <= here;
662: tab++)
663: if (!tab->position) {
664: new_line(text);
665: return;
666: }
1.14 frystyk 667: target = (int) tab->position;
1.1 timbl 668: } else if (text->in_line_1) { /* Use 2nd indent */
669: if (here >= style->leftIndent) {
670: new_line(text); /* wrap */
671: return;
672: } else {
1.14 frystyk 673: target = (int) style->leftIndent;
1.1 timbl 674: }
675: } else { /* Default tabs align with left indent mod 8 */
676: #ifdef DEFAULT_TABS_8
677: target = ((line->offset + line->size + 8) & (-8))
678: + style->leftIndent;
679: #else
680: new_line(text);
681: return;
682: #endif
683: }
684: if (target > HTScreenWidth - style->rightIndent) {
685: new_line(text);
686: return;
687: } else {
688: text->permissible_split = line->size; /* Can split here */
689: if (line->size == 0) line->offset = line->offset + target - here;
690: else for(; here<target; here++) {
691: line->data[line->size++] = ' '; /* Put character into line */
692: }
693: return;
694: }
695: /*NOTREACHED*/
696: } /* if tab */
697:
698:
699: if (ch==' ') {
700: text->permissible_split = line->size; /* Can split here */
701: }
702:
703: /* Check for end of line
704: */
705: if (indent + line->offset + line->size + style->rightIndent
706: >= HTScreenWidth) {
707: if (style->wordWrap) {
1.7 frystyk 708: if(text->permissible_split > line->size) /* HENRIK 21/02-94 */
709: text->permissible_split = line->size;
1.1 timbl 710: split_line(text, text->permissible_split);
711: if (ch==' ') return; /* Ignore space causing split */
712: } else new_line(text);
713: }
714:
715: /* Insert normal characters
716: */
717: if (ch == HT_NON_BREAK_SPACE) {
718: ch = ' ';
719: }
720: {
721: HTLine * line = text->last_line; /* May have changed */
722: HTFont font = style->font;
723: line->data[line->size++] = /* Put character into line */
724: font & HT_CAPITALS ? TOUPPER(ch) : ch;
725: if (font & HT_DOUBLE) /* Do again if doubled */
726: HText_appendCharacter(text, HT_NON_BREAK_SPACE);
727: /* NOT a permissible split */
728: }
729: }
730:
731: /* Anchor handling
732: ** ---------------
733: */
734: /* Start an anchor field
735: */
1.29 frystyk 736: PUBLIC void HText_beginAnchor (HText * text, HTChildAnchor * anc)
1.1 timbl 737: {
1.2 timbl 738: char marker[100];
1.34 frystyk 739: TextAnchor * a;
740: if ((a = (TextAnchor *) HT_MALLOC(sizeof(*a))) == NULL)
741: HT_OUTOFMEM("HText_beginAnchor");
1.1 timbl 742:
743: if (a == NULL) outofmem(__FILE__, "HText_beginAnchor");
744: a->start = text->chars + text->last_line->size;
745: a->extent = 0;
746: if (text->last_anchor) {
747: text->last_anchor->next = a;
748: } else {
749: text->first_anchor = a;
750: }
751: a->next = 0;
752: a->anchor = anc;
753: text->last_anchor = a;
754:
755: if (HTAnchor_followMainLink((HTAnchor*)anc)) {
756: a->number = ++(text->last_anchor_number);
757: } else {
758: a->number = 0;
759: }
1.2 timbl 760:
761: if (start_reference && a->number && display_anchors) {
762: /* If it goes somewhere */
763: sprintf(marker, start_reference, a->number);
764: HText_appendText(text, marker);
765: }
1.1 timbl 766: }
767:
768:
1.29 frystyk 769: PUBLIC void HText_endAnchor (HText * text)
1.1 timbl 770: {
771: TextAnchor * a = text->last_anchor;
772: char marker[100];
773: if (a->number && display_anchors) { /* If it goes somewhere */
1.2 timbl 774: sprintf(marker, end_reference, a->number);
1.1 timbl 775: HText_appendText(text, marker);
776: }
777: a->extent = text->chars + text->last_line->size - a->start;
778: }
779:
780:
1.5 timbl 781: /* IMAGES
782: */
1.29 frystyk 783: PUBLIC void HText_appendImage (
784: HText * text,
785: HTChildAnchor * anc,
786: CONST char * alt,
787: CONST char * alignment,
788: BOOL isMap)
1.5 timbl 789: {
1.9 frystyk 790: HText_appendText(text, alt? alt : "[IMAGE]");
1.5 timbl 791: }
792:
1.29 frystyk 793: PUBLIC void HText_appendText (HText * text, CONST char * str)
1.1 timbl 794: {
795: CONST char * p;
796: for(p=str; *p; p++) {
797: HText_appendCharacter(text, *p);
798: }
799: }
800:
801:
1.29 frystyk 802: PUBLIC void HText_endAppend (HText * text)
1.1 timbl 803: {
804: new_line(text);
805:
806: if (text->display_on_the_fly) { /* Not finished? */
807: fill_screen(text, text->display_on_the_fly); /* Finish it */
808: text->display_on_the_fly = 0;
809: text->next_line = text->last_line; /* Bug fix after EvA 920117 */
810: text->stale = NO;
811: }
812: }
813:
814:
815:
1.20 frystyk 816: /* Dump diagnostics to TDEST
1.1 timbl 817: */
1.29 frystyk 818: PUBLIC void HText_dump (HText * text)
1.1 timbl 819: {
1.26 frystyk 820: TTYPrint(TDEST, "HText: Dump called\n");
1.1 timbl 821: }
822:
823:
824: /* Return the anchor associated with this node
825: */
1.29 frystyk 826: PUBLIC HTParentAnchor * HText_nodeAnchor (HText * text)
1.1 timbl 827: {
828: return text->node_anchor;
829: }
830:
831: /* GridText specials
832: ** =================
833: */
834: /* Return the anchor with index N
835: **
836: ** The index corresponds to the number we print in the anchor.
837: */
1.29 frystyk 838: PUBLIC HTChildAnchor * HText_childNumber (HText * text, int number)
1.1 timbl 839: {
840: TextAnchor * a;
841: for (a = text->first_anchor; a; a = a->next) {
842: if (a->number == number) return a->anchor;
843: }
844: return (HTChildAnchor *)0; /* Fail */
845: }
846:
1.29 frystyk 847: PUBLIC void HText_setStale (HText * text)
1.1 timbl 848: {
1.16 frystyk 849: if (text)
850: text->stale = YES;
1.1 timbl 851: }
852:
1.29 frystyk 853: PUBLIC void HText_refresh (HText * text)
1.1 timbl 854: {
1.16 frystyk 855: if (text && text->stale)
856: display_page(text, text->top_of_screen);
1.1 timbl 857: }
858:
1.29 frystyk 859: PUBLIC int HText_sourceAnchors (HText * text)
1.1 timbl 860: {
1.16 frystyk 861: return (text ? text->last_anchor_number : -1);
1.1 timbl 862: }
863:
1.29 frystyk 864: PUBLIC BOOL HText_canScrollUp (HText * text)
1.1 timbl 865: {
1.16 frystyk 866: return (text && text->top_of_screen != 0);
1.1 timbl 867: }
868:
1.29 frystyk 869: PUBLIC BOOL HText_canScrollDown (HText * text)
1.1 timbl 870: {
1.16 frystyk 871: return (text && (text->top_of_screen + DISPLAY_LINES -
872: (text->title ? TITLE_LINES : 0)) < text->lines);
1.1 timbl 873: }
874:
875: /* Scroll actions
876: */
1.29 frystyk 877: PUBLIC void HText_scrollTop (HText * text)
1.1 timbl 878: {
879: display_page(text, 0);
880: }
881:
1.29 frystyk 882: PUBLIC void HText_scrollDown (HText * text)
1.1 timbl 883: {
884: display_page(text, text->top_of_screen + DISPLAY_LINES -1);
885: }
886:
1.29 frystyk 887: PUBLIC void HText_scrollUp (HText * text)
1.1 timbl 888: {
889: display_page(text, text->top_of_screen - DISPLAY_LINES +1);
890: }
891:
1.29 frystyk 892: PUBLIC void HText_scrollBottom (HText * text)
1.1 timbl 893: {
894: display_page(text, text->lines - DISPLAY_LINES +1);
895: }
896:
897:
898: /* Browsing functions
899: ** ==================
900: */
901:
902: /* Bring to front and highlight it
903: */
904:
1.29 frystyk 905: PRIVATE int line_for_char (HText * text, int char_num)
1.1 timbl 906: {
907: int line_number =0;
908: int characters = 0;
909: HTLine * line = text->last_line->next;
910: for(;;) {
911: if (line == text->last_line) return 0; /* Invalid */
912: characters = characters + line->size + 1;
913: if (characters > char_num) return line_number;
914: line_number ++;
915: line = line->next;
916: }
917: }
918:
1.29 frystyk 919: PUBLIC BOOL HText_select (HText * text)
1.1 timbl 920: {
1.13 frystyk 921: if (text) {
1.1 timbl 922: HTMainText = text;
923: HTMainAnchor = text->node_anchor;
924: display_page(text, text->top_of_screen);
1.13 frystyk 925: return YES;
1.1 timbl 926: }
1.20 frystyk 927: if (SGML_TRACE)
1.26 frystyk 928: TTYPrint(TDEST, "HText: Nothing to select!\n");
1.13 frystyk 929: return NO;
1.1 timbl 930: }
931:
1.29 frystyk 932: PUBLIC BOOL HText_selectAnchor (HText * text, HTChildAnchor * anchor)
1.1 timbl 933: {
934: TextAnchor * a;
935:
936: for(a=text->first_anchor; a; a=a->next) {
937: if (a->anchor == anchor) break;
938: }
939: if (!a) {
1.20 frystyk 940: if (SGML_TRACE)
1.26 frystyk 941: TTYPrint(TDEST, "HText: No such anchor in this text!\n");
1.1 timbl 942: return NO;
943: }
944:
945: if (text != HTMainText) { /* Comment out by ??? */
946: HTMainText = text; /* Put back in by tbl 921208 */
947: HTMainAnchor = text->node_anchor;
948: }
949:
950: {
1.20 frystyk 951: int l = line_for_char(text, a->start);
952: if (SGML_TRACE)
1.26 frystyk 953: TTYPrint(TDEST,"HText: Selecting anchor [%d] at char %d, line %d\n",
1.20 frystyk 954: a->number, a->start, l);
1.1 timbl 955:
956: if ( !text->stale &&
1.20 frystyk 957: (l >= text->top_of_screen) &&
958: ( l < text->top_of_screen + DISPLAY_LINES-1))
959: return YES;
1.1 timbl 960: display_page(text, l - (DISPLAY_LINES/3)); /* Scroll to it */
961: }
962: return YES;
963: }
964:
965:
966: /* Editing functions - NOT IMPLEMENTED
967: ** =================
968: **
969: ** These are called from the application. There are many more functions
970: ** not included here from the orginal text object.
971: */
972:
973: /* Style handling:
974: */
975: /* Apply this style to the selection
976: */
1.29 frystyk 977: PUBLIC void HText_applyStyle (HText * me, HTStyle * style)
1.1 timbl 978: {
979:
980: }
981:
982:
983: /* Update all text with changed style.
984: */
1.29 frystyk 985: PUBLIC void HText_updateStyle (HText * me, HTStyle * style)
1.1 timbl 986: {
987:
988: }
989:
990:
991: /* Return style of selection
992: */
1.29 frystyk 993: PUBLIC HTStyle * HText_selectionStyle (
994: HText * me,
995: HTStyleSheet * sheet)
1.1 timbl 996: {
997: return 0;
998: }
999:
1000:
1001: /* Paste in styled text
1002: */
1.29 frystyk 1003: PUBLIC void HText_replaceSel (
1004: HText * me,
1005: CONST char * aString,
1006: HTStyle * aStyle)
1.1 timbl 1007: {
1008: }
1009:
1010:
1011: /* Apply this style to the selection and all similarly formatted text
1012: ** (style recovery only)
1013: */
1.29 frystyk 1014: PUBLIC void HTextApplyToSimilar (HText * me, HTStyle * style)
1.1 timbl 1015: {
1016:
1017: }
1018:
1019:
1020: /* Select the first unstyled run.
1021: ** (style recovery only)
1022: */
1.29 frystyk 1023: PUBLIC void HTextSelectUnstyled (HText * me, HTStyleSheet * sheet)
1.1 timbl 1024: {
1025:
1026: }
1027:
1028:
1029: /* Anchor handling:
1030: */
1.29 frystyk 1031: PUBLIC void HText_unlinkSelection (HText * me)
1.1 timbl 1032: {
1033:
1034: }
1035:
1.29 frystyk 1036: PUBLIC HTAnchor * HText_referenceSelected (HText * me)
1.1 timbl 1037: {
1038: return 0;
1039: }
1040:
1041:
1042: #ifdef CURSES
1.29 frystyk 1043: PUBLIC int HText_getTopOfScreen (HText * text)
1.1 timbl 1044: {
1045: return text->top_of_screen;
1046: }
1047:
1.29 frystyk 1048: PUBLIC int HText_getLines (HText * text)
1.1 timbl 1049: {
1050: return text->lines;
1051: }
1052: #endif
1.29 frystyk 1053: PUBLIC HTAnchor * HText_linkSelTo (HText * me, HTAnchor * anchor)
1.1 timbl 1054: {
1055: return 0;
1056: }
1057:
1.20 frystyk 1058: /*
1.24 frystyk 1059: ** Returns YES: keep header, NO: discard
1060: */
1061: PUBLIC BOOL HTHeaderParser (HTRequest *request, char *header)
1062: {
1063: if (STREAM_TRACE)
1.26 frystyk 1064: TTYPrint(TDEST, "MIMEExtra... we are now in callback\n");
1.24 frystyk 1065: return YES;
1066: }
1067:
1068: /*
1.20 frystyk 1069: ** Check if document is already loaded. As the application handles the
1070: ** memory cache, we call the application to ask. Also check if it has
1071: ** expired in which case we reload it (either from disk cache or remotely)
1072: */
1.24 frystyk 1073: PUBLIC int HTMemoryCache (HTRequest * request, HTExpiresMode mode,
1074: char * notification)
1.20 frystyk 1075: {
1.27 frystyk 1076: HTParentAnchor *anchor = HTRequest_anchor(request);
1.20 frystyk 1077: HText *text;
1078: if (!request)
1079: return HT_ERROR;
1.27 frystyk 1080: if ((text = (HText *) HTAnchor_document(anchor))) {
1081: if (HTRequest_reloadMode(request) != HT_MEM_REFRESH) {
1.20 frystyk 1082: if (CACHE_TRACE)
1.26 frystyk 1083: TTYPrint(TDEST,"HTMemCache.. Document already in memory\n");
1.20 frystyk 1084: if (mode != HT_EXPIRES_IGNORE) {
1.27 frystyk 1085: if (!HTCache_isValid(anchor)) {
1.29 frystyk 1086: if (mode == HT_EXPIRES_NOTIFY) {
1087: if (WWWTRACE) TTYPrint(TDEST, "%s\n", notification);
1088: } else {
1.20 frystyk 1089: if (CACHE_TRACE)
1.26 frystyk 1090: TTYPrint(TDEST,
1.20 frystyk 1091: "HTMemCache.. Expired - autoreload\n");
1.32 frystyk 1092: HTRequest_addRqHd(request, HT_C_IMS);
1.20 frystyk 1093: #ifndef HT_SHARED_DISK_CACHE
1.27 frystyk 1094: HTRequest_setReloadMode(request, HT_CACHE_REFRESH);
1.20 frystyk 1095: #endif
1096: return HT_ERROR; /* Must go get it */
1097: }
1098: }
1099: }
1.1 timbl 1100:
1.20 frystyk 1101: /*
1102: ** If we can use object then select it and return
1103: ** This should be a callback to the app mem cache handler
1104: */
1105: if (request->childAnchor)
1106: HText_selectAnchor(text, request->childAnchor);
1107: else
1108: HText_select(text);
1109: return HT_LOADED;
1110: } else { /* If refresh version in memory */
1.32 frystyk 1111: HTRequest_addRqHd(request, HT_C_IMS);
1.20 frystyk 1112: }
1113: } else { /* Don't reuse any old metainformation */
1.27 frystyk 1114: HTAnchor_clearHeader(anchor);
1.20 frystyk 1115: }
1116: return HT_ERROR;
1117: }
1.26 frystyk 1118:
Webmaster