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