Annotation of Amaya/amaya/HTMLbook.c, revision 1.11
1.1 cvs 1: /*
2: *
3: * (c) COPYRIGHT MIT and INRIA, 1996.
4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: * Initialization functions and button functions of Amaya application.
10: *
11: * Authors: V. Quint, I. Vatton
12: */
13:
14:
15: /* Included headerfiles */
16: #define THOT_EXPORT
17: #include "amaya.h"
18: #include "print.h"
19:
20: #define NumFormPrint 1
21: #define NumMenuOptions 2
22: #define NumMenuPaperFormat 3
23: #define NumMenuSupport 4
24: #define NumZonePrinterName 5
25: #define PRINT_MAX_REF 6
26:
27: /* Thot printer variables */
1.2 cvs 28: static int PaperPrint;
29: static int ManualFeed;
30: static int PageSize;
31: static char PSdir[MAX_PATH];
32: static char pPrinter[MAX_PATH];
1.1 cvs 33: static Document docPrint;
34: static boolean numberLinks;
35: static boolean withToC;
36: static int basePrint;
37:
38: #include "init_f.h"
39: #include "HTMLactions_f.h"
40: #include "HTMLbook_f.h"
41: #include "HTMLedit_f.h"
42:
43:
44: /*----------------------------------------------------------------------
45: SetInternalLinks
1.8 cvs 46: Associate an InternalLink attribute with all anchor (A) elements of the
47: document which designate an element in the same document.
1.1 cvs 48: InternalLink is a Thot reference attribute that links a source and a
49: target anchor and that allows P schemas to display and print cross-references
1.8 cvs 50: Associate an ExternalLink attribute with all anchor (A) elements of the
51: document which designate an element in another document.
1.1 cvs 52: ----------------------------------------------------------------------*/
53: #ifdef __STDC__
1.4 cvs 54: void SetInternalLinks (Document document)
1.1 cvs 55: #else
1.4 cvs 56: void SetInternalLinks (document)
1.1 cvs 57: Document document;
58: #endif
59: {
60: Element root, el;
61: Element link, target;
62: ElementType elType;
1.8 cvs 63: Attribute HrefAttr, IntLinkAttr, ExtLinkAttr;
1.1 cvs 64: AttributeType attrType;
65: int length;
1.3 cvs 66: int status;
67: char *text;
1.1 cvs 68:
1.8 cvs 69: /* Remember the current status of the document */
1.3 cvs 70: status = TtaIsDocumentModified (document);
1.1 cvs 71: root = TtaGetMainRoot (document);
72: elType = TtaGetElementType (root);
73: elType.ElTypeNum = HTML_EL_BODY;
74: el = TtaSearchTypedElement (elType, SearchForward, root);
75:
76: elType.ElTypeNum = HTML_EL_Anchor;
77: attrType.AttrSSchema = elType.ElSSchema;
78: /* looks for all anchors in the document */
79: link = el;
80: while (link != NULL)
81: {
82: link = TtaSearchTypedElement (elType, SearchForward, link);
83: if (link != NULL)
84: /* an anchor has been found */
85: {
86: attrType.AttrTypeNum = HTML_ATTR_HREF_;
87: HrefAttr = TtaGetAttribute (link, attrType);
1.8 cvs 88: attrType.AttrTypeNum = HTML_ATTR_InternalLink;
89: IntLinkAttr = TtaGetAttribute (link, attrType);
90: attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
91: ExtLinkAttr = TtaGetAttribute (link, attrType);
92: if (HrefAttr == NULL)
93: /* this anchor is not a link (no href attribute) */
94: /* remove attributes InternalLink and ExternalLink if they
95: are present */
96: {
97: if (IntLinkAttr != NULL)
98: TtaRemoveAttribute (link, IntLinkAttr, document);
99: if (ExtLinkAttr != NULL)
100: TtaRemoveAttribute (link, ExtLinkAttr, document);
101: }
102: else
1.1 cvs 103: /* this anchor has an HREF attribute */
104: {
105: length = TtaGetTextAttributeLength (HrefAttr);
106: text = TtaGetMemory (length + 1);
107: TtaGiveTextAttributeValue (HrefAttr, text, &length);
108: if (text[0] == '#')
1.8 cvs 109: /* it's an internal link. Attach an attribute InternalLink to */
1.1 cvs 110: /* the link, if this attribute does not exist yet */
111: {
112: if (IntLinkAttr == NULL)
113: {
1.8 cvs 114: attrType.AttrTypeNum = HTML_ATTR_InternalLink;
1.1 cvs 115: IntLinkAttr = TtaNewAttribute (attrType);
116: TtaAttachAttribute (link, IntLinkAttr, document);
117: }
118: /* looks for the target element */
119: target = SearchNAMEattribute (document, &text[1], NULL);
120: if (target != NULL)
121: /* set the Thot link */
122: TtaSetAttributeReference (IntLinkAttr, link, document,
123: target, document);
124: }
1.8 cvs 125: else
126: /* it's an external link */
127: {
128: /* Remove the InternalLink attribute if it is present */
129: if (IntLinkAttr != NULL)
130: TtaRemoveAttribute (link, IntLinkAttr, document);
131: /* create an ExternalLink attribute if there is none */
132: if (ExtLinkAttr == NULL)
133: {
134: attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
135: ExtLinkAttr = TtaNewAttribute (attrType);
136: TtaAttachAttribute (link, ExtLinkAttr, document);
137: }
138: }
1.1 cvs 139: TtaFreeMemory (text);
140: }
141: }
142: }
1.3 cvs 143: /* Reset document status */
144: if (!status)
145: TtaSetDocumentUnmodified (document);
146: }
147:
148: /*----------------------------------------------------------------------
149: CheckPrintingDocument reinitialize printing parameters as soon as
150: the printing document changes.
151: ----------------------------------------------------------------------*/
152: #ifdef __STDC__
153: static void CheckPrintingDocument (Document document)
154: #else
155: static void CheckPrintingDocument (document)
156: Document document;
157: #endif
158: {
159: char docName[MAX_LENGTH];
160: char *ptr, suffix[MAX_LENGTH];
161: int lg;
162:
163: if (docPrint != document)
164: {
165: /* initialize print parameters */
166: docPrint = document;
167:
168: /* define the new default PS file */
169: ptr = TtaGetEnvString ("TMPDIR");
170: if (ptr != NULL && TtaCheckDirectory (ptr))
171: {
172: strcpy(PSdir,ptr);
173: lg = strlen(PSdir);
174: if (PSdir[lg - 1] == DIR_SEP)
175: PSdir[--lg] = '\0';
176: }
177: else
178: {
1.6 cvs 179: # ifdef _WINDOWS
1.3 cvs 180: strcpy (PSdir,"C:\\TEMP");
1.6 cvs 181: # else /* !_WINDOWS */
1.3 cvs 182: strcpy (PSdir,"/tmp");
1.6 cvs 183: # endif /* !_WINDOWS */
1.3 cvs 184: lg = strlen (PSdir);
185: }
186: strcpy (docName, TtaGetDocumentName (document));
187: ExtractSuffix (docName, suffix);
188: sprintf (&PSdir[lg], "/%s.ps", docName);
189: TtaSetPsFile (PSdir);
190: /* define the new default PrintSchema */
191: numberLinks = FALSE;
192: withToC = FALSE;
193: TtaSetPrintSchema ("");
194: /* no manual feed */
195: ManualFeed = PP_OFF;
196: TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
197: }
198: }
199:
200:
201: /*----------------------------------------------------------------------
202: PrintAs prints the document using predefined parameters.
203: ----------------------------------------------------------------------*/
204: #ifdef __STDC__
205: void PrintAs (Document document, View view)
206: #else /* __STDC__ */
207: void PrintAs (document, view)
208: Document document;
209: #endif /* __STDC__ */
210: {
1.9 cvs 211: char viewsToPrint[MAX_PATH];
1.3 cvs 212:
213: CheckPrintingDocument (document);
214: strcpy (viewsToPrint, "Formatted_view ");
215: if (withToC)
216: strcat (viewsToPrint, "Table_of_contents ");
217: if (numberLinks)
1.8 cvs 218: /* display numbered links */
1.3 cvs 219: {
1.8 cvs 220: /* associate an attribute InternalLink with all anchors refering
221: a target in the same document. This allows P schemas to work
222: properly */
223: SetInternalLinks (docPrint);
1.3 cvs 224: if (PageSize == PP_A4)
225: TtaSetPrintSchema ("HTMLPLP");
226: else
227: TtaSetPrintSchema ("HTMLPLPUS");
228: strcat (viewsToPrint, "Links_view ");
229: }
230: TtaPrint (docPrint, viewsToPrint);
1.1 cvs 231: }
232:
233:
234: /*----------------------------------------------------------------------
235: CallbackImage manage returns of Picture form.
236: ----------------------------------------------------------------------*/
237: #ifdef __STDC__
238: void CallbackPrint (int ref, int typedata, char *data)
239: #else /* __STDC__ */
240: void CallbackPrint (ref, typedata, data)
241: int ref;
242: int typedata;
243: char *data;
244: #endif /* __STDC__ */
245: {
246: int val;
247:
248: val = (int) data;
249: switch (ref - basePrint)
250: {
251: case NumFormPrint:
252: TtaDestroyDialogue (basePrint+NumFormPrint);
253: switch (val)
254: {
255: case 1:
256: /* confirms the paper print option */
257: /* the other options are not taken into account without this
258: confirmation */
1.2 cvs 259: TtaSetPrintParameter (PP_Destination, PaperPrint);
260: TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
261: TtaSetPrintParameter (PP_PaperSize, PageSize);
262: TtaSetPrintCommand (pPrinter);
263: TtaSetPsFile (PSdir);
1.3 cvs 264: PrintAs (docPrint, 1);
1.1 cvs 265: break;
1.2 cvs 266: case 0:
267: PaperPrint = TtaGetPrintParameter (PP_Destination);
268: ManualFeed = TtaGetPrintParameter (PP_ManualFeed);
269: PageSize = TtaGetPrintParameter (PP_PaperSize);
270: TtaGetPrintCommand (pPrinter);
271: TtaGetPsFile (PSdir);
272: break;
1.1 cvs 273: default:
274: break;
275: }
276: break;
277: case NumMenuOptions:
278: switch (val)
279: {
280: case 0:
281: /* Manual feed option */
1.2 cvs 282: if (ManualFeed == PP_ON)
283: ManualFeed = PP_OFF;
284: else
285: ManualFeed = PP_ON;
1.1 cvs 286: break;
287: case 1:
288: /* Toc option */
289: withToC = !withToC;
290: break;
291: case 2:
1.3 cvs 292: /* numberLinks option */
1.1 cvs 293: numberLinks = !numberLinks;
294: break;
295: }
296: break;
297: case NumMenuPaperFormat:
298: /* page size submenu */
299: switch (val)
300: {
301: case 0:
1.2 cvs 302: PageSize = PP_A4;
1.1 cvs 303: break;
304: case 1:
1.2 cvs 305: PageSize = PP_US;
1.1 cvs 306: break;
307: }
308: break;
309: case NumMenuSupport:
310: /* paper print/save PostScript submenu */
311: switch (val)
312: {
313: case 0:
1.2 cvs 314: if (PaperPrint == PP_PS)
1.1 cvs 315: {
1.2 cvs 316: PaperPrint = PP_PRINTER;
1.1 cvs 317: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter);
318: }
319: break;
320: case 1:
1.2 cvs 321: if (PaperPrint == PP_PRINTER)
1.1 cvs 322: {
1.2 cvs 323: PaperPrint = PP_PS;
1.1 cvs 324: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir);
325: }
326: break;
327: }
328: break;
329: case NumZonePrinterName:
330: if (data[0] != '\0')
1.2 cvs 331: if (PaperPrint == PP_PRINTER)
1.1 cvs 332: /* text capture zone for the printer name */
333: strncpy (pPrinter, data, MAX_PATH);
334: else
335: /* text capture zone for the name of the PostScript file */
336: strncpy (PSdir, data, MAX_PATH);
337: break;
338: }
339: }
340:
341: /*----------------------------------------------------------------------
342: ----------------------------------------------------------------------*/
343: #ifdef __STDC__
344: void InitPrint (void)
345: #else /* __STDC__ */
346: void InitPrint ()
347: #endif /* __STDC__ */
348: {
349: char *ptr;
350:
351: basePrint = TtaSetCallback (CallbackPrint, PRINT_MAX_REF);
352: docPrint = 0;
353:
354: /* init printer variables */
355: /* read default printer variable */
356: ptr = TtaGetEnvString ("THOTPRINT");
357: if (ptr == NULL)
358: strcpy (pPrinter, "");
359: else
360: strcpy (pPrinter, ptr);
361:
1.2 cvs 362: PageSize = PP_A4;
363: PaperPrint = PP_PRINTER;
364: TtaSetPrintParameter (PP_Destination, PaperPrint);
365: TtaSetPrintParameter (PP_PaperSize, PageSize);
366: TtaSetPrintCommand (pPrinter);
1.1 cvs 367: }
368:
369: /*----------------------------------------------------------------------
1.3 cvs 370: SetupAndPrint sets printing parameters and starts the printing process
1.1 cvs 371: ----------------------------------------------------------------------*/
372: #ifdef __STDC__
373: void SetupAndPrint (Document document, View view)
374: #else
375: void SetupAndPrint (document, view)
376: Document document;
377: View view;
378: #endif
379: {
1.10 cvs 380: # ifndef _WINDOWS
1.2 cvs 381: char bufMenu[MAX_LENGTH];
1.3 cvs 382: int i;
1.1 cvs 383:
384: /* Print form */
1.3 cvs 385: CheckPrintingDocument (document);
1.1 cvs 386: TtaNewSheet (basePrint+NumFormPrint, TtaGetViewFrame (document, view),
387: TtaGetMessage (LIB, TMSG_LIB_PRINT),
1.3 cvs 388: 1, TtaGetMessage (AMAYA, AM_BUTTON_PRINT), FALSE, 2, 'L', D_CANCEL);
1.1 cvs 389: i = 0;
390: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (LIB, TMSG_MANUAL_FEED));
391: i += strlen (&bufMenu[i]) + 1;
392: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_TOC));
393: i += strlen (&bufMenu[i]) + 1;
394: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_NUMBERED_LINKS));
395: TtaNewToggleMenu (basePrint+NumMenuOptions, basePrint+NumFormPrint,
396: TtaGetMessage (LIB, TMSG_OPTIONS), 3, bufMenu, NULL, FALSE);
1.2 cvs 397: if (ManualFeed == PP_ON)
1.1 cvs 398: TtaSetToggleMenu (basePrint+NumMenuOptions, 0, TRUE);
399: if (withToC)
400: TtaSetToggleMenu (basePrint+NumMenuOptions, 1, TRUE);
401: if (numberLinks)
402: TtaSetToggleMenu (basePrint+NumMenuOptions, 2, TRUE);
403:
404: /* Paper format submenu */
405: i = 0;
406: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_A4));
407: i += strlen (&bufMenu[i]) + 1;
408: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_US));
409: TtaNewSubmenu (basePrint+NumMenuPaperFormat, basePrint+NumFormPrint, 0,
410: TtaGetMessage (LIB, TMSG_PAPER_SIZE), 2, bufMenu, NULL, FALSE);
1.2 cvs 411: if (PageSize == PP_US)
1.1 cvs 412: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 1);
413: else
414: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 0);
415:
416: /* Print to paper/ Print to file submenu */
417: i = 0;
418: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PRINTER));
419: i += strlen (&bufMenu[i]) + 1;
420: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PS_FILE));
421: TtaNewSubmenu (basePrint+NumMenuSupport, basePrint+NumFormPrint, 0,
422: TtaGetMessage (LIB, TMSG_OUTPUT), 2, bufMenu, NULL, TRUE);
423: /* text capture zone for the printer name */
424: TtaNewTextForm (basePrint+NumZonePrinterName, basePrint+NumFormPrint, NULL, 30, 1, FALSE);
425:
426: /* initialization of the PaperPrint selector */
1.2 cvs 427: if (PaperPrint == PP_PRINTER)
1.1 cvs 428: {
429: TtaSetMenuForm (basePrint+NumMenuSupport, 0);
430: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter);
431: }
432: else
433: {
434: TtaSetMenuForm (basePrint+NumMenuSupport, 1);
435: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir);
436: }
437:
438: /* activates the Print form */
1.10 cvs 439: TtaShowDialogue (basePrint+NumFormPrint, FALSE);
440: # else /* _WINDOWS */
1.11 ! cvs 441: CreatePrintDlgWindow (TtaGetViewFrame (document, view));
1.10 cvs 442: # endif /* _WINDOWS */
1.1 cvs 443: }
444:
445: /*----------------------------------------------------------------------
446: SectionNumbering
447: Execute the "Section Numbering" command
448: ----------------------------------------------------------------------*/
449: #ifdef __STDC__
450: void SectionNumbering (Document document, View view)
451: #else
452: void SectionNumbering (document, view)
453: Document document;
454: View view;
455: #endif
456: {
457: ChangeAttrOnRoot (document, HTML_ATTR_SectionNumbering);
458: }
459:
460: /*----------------------------------------------------------------------
461: UpdateURLsInSubtree
462: Update NAMEs and URLs in subtree of el element, to take into account
463: the move from one document to another.
464: If a NAME attribute already exists in the new document, it is changed
465: to avoid duplicate names.
466: Transform the HREF and SRC attribute to make them independent from their
467: former base.
468: ----------------------------------------------------------------------*/
469: #ifdef __STDC__
470: static void UpdateURLsInSubtree (NotifyElement *event, Element el)
471: #else
472: static void UpdateURLsInSubtree (event, el)
473: NotifyElement *event;
474: Element el;
475: #endif
476: {
477: Element nextEl;
478:
479: event->element = el;
480: ElementPasted (event);
481: nextEl = TtaGetFirstChild (el);
482: while (nextEl != NULL)
483: {
484: UpdateURLsInSubtree (event, nextEl);
485: TtaNextSibling (&nextEl);
486: }
487: }
488:
489:
490: /*----------------------------------------------------------------------
491: MoveDocumentBody
492: Copy the elements contained in the BODY of document sourceDoc to the
493: position of element *el in document destDoc.
494: Delete the element containing *el and all its empty ancestors.
495: If deleteTree is TRUE, copied elements are deleted from the source
496: document.
497: ----------------------------------------------------------------------*/
498: #ifdef __STDC__
499: static void MoveDocumentBody (Element *el, Document destDoc,
500: Document sourceDoc, boolean deleteTree)
501: #else
502: static void MoveDocumentBody (el, destDoc, sourceDoc, deleteTree)
503: Element *el;
504: Document destDoc;
505: Document sourceDoc;
506: boolean deleteTree;
507: #endif
508: {
509: Element root, body, ancestor, elem, firstInserted,
510: lastInserted, srce, copy, old, parent, sibling;
511: ElementType elType;
512: NotifyElement event;
1.5 cvs 513: int checkingMode;
1.1 cvs 514:
515: firstInserted = NULL;
516: /* get the BODY element of source document */
517: root = TtaGetMainRoot (sourceDoc);
518: elType = TtaGetElementType (root);
519: elType.ElTypeNum = HTML_EL_BODY;
520: body = TtaSearchTypedElement (elType, SearchForward, root);
521: if (body != NULL)
522: {
1.5 cvs 523: /* don't check the abstract tree against the structure schema */
524: checkingMode = TtaGetStructureChecking (destDoc);
525: TtaSetStructureChecking (0, destDoc);
1.1 cvs 526: /* get elem, the ancestor of *el which is a child of a DIV or BODY
527: element in the destination document. The copied elements will be
528: inserted just before this element. */
529: elem = *el;
530: do
531: {
532: ancestor = TtaGetParent (elem);
533: if (ancestor != NULL);
534: {
535: elType = TtaGetElementType (ancestor);
536: if (elType.ElTypeNum == HTML_EL_BODY ||
537: elType.ElTypeNum == HTML_EL_Division)
538: ancestor = NULL;
539: else
540: elem = ancestor;
541: }
542: }
543: while (ancestor != NULL);
544: parent = TtaGetParent (elem);
545:
546: /* do copy */
547: lastInserted = NULL;
548: srce = TtaGetFirstChild (body);
549: while (srce != NULL)
550: {
551: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent);
552: if (copy != NULL)
553: {
554: if (lastInserted == NULL)
555: /* this is the first copied element. Insert it before elem */
556: {
557: TtaInsertSibling (copy, elem, TRUE, destDoc);
558: firstInserted = copy;
559: }
560: else
561: /* insert the new copied element after the element previously
562: copied */
563: TtaInsertSibling (copy, lastInserted, FALSE, destDoc);
564: lastInserted = copy;
565: /* update the NAMEs and URLs in the copied element */
566: event.document = destDoc;
567: event.position = sourceDoc;
568: UpdateURLsInSubtree(&event, copy);
569: }
570: /* get the next element in the source document */
571: old = srce;
572: TtaNextSibling (&srce);
573: if (deleteTree)
574: TtaDeleteTree (old, sourceDoc);
575: }
576:
577: /* delete the element(s) containing the link to the copied document */
578: /* delete the parent element of *el and all empty ancestors */
579: elem = TtaGetParent (*el);
580: do
581: {
582: sibling = elem;
583: TtaNextSibling (&sibling);
584: if (sibling == NULL)
585: {
586: sibling = elem;
587: TtaPreviousSibling (&sibling);
588: if (sibling == NULL)
589: elem = TtaGetParent (elem);
590: }
591: }
592: while (sibling == NULL);
593: TtaDeleteTree (elem, destDoc);
1.5 cvs 594: /* restore previous chacking mode */
595: TtaSetStructureChecking (checkingMode, destDoc);
1.1 cvs 596: /* return the address of the first copied element */
597: *el = firstInserted;
598: }
599: }
600:
601: /*----------------------------------------------------------------------
602: GetIncludedDocuments
603: Look forward, starting from element el, for a link (A) with attribute
1.5 cvs 604: REL="chapter" or REL="subdocument" and replace that link by the contents
605: of the target document.
1.1 cvs 606: ----------------------------------------------------------------------*/
607: #ifdef __STDC__
608: static Element GetIncludedDocuments (Element el, Document document)
609: #else
610: static Element GetIncludedDocuments (el, document)
611: Element el;
612: Document document;
613: #endif
614: {
615: Element link, next;
616: Attribute RelAttr, HrefAttr;
617: AttributeType attrType;
618: int length;
619: char *text, *ptr;
620: Document includedDocument, newdoc;
621:
622: attrType.AttrSSchema = TtaGetDocumentSSchema (document);
623: attrType.AttrTypeNum = HTML_ATTR_REL;
624: link = el;
625: RelAttr = NULL;
1.5 cvs 626: /* looks for an anchor having an attribute REL="chapter" or
627: REL="subdocument" */
1.1 cvs 628: while (link != NULL && RelAttr == NULL)
629: {
630: TtaSearchAttribute (attrType, SearchForward, link, &link, &RelAttr);
631: if (link != NULL && RelAttr != NULL)
632: {
633: length = TtaGetTextAttributeLength (RelAttr);
634: text = TtaGetMemory (length + 1);
635: TtaGiveTextAttributeValue (RelAttr, text, &length);
1.5 cvs 636: if (strcasecmp (text, "chapter") && strcasecmp (text, "subdocument"))
1.1 cvs 637: RelAttr = NULL;
638: TtaFreeMemory (text);
639: }
640: }
641:
642: if (RelAttr != NULL && link != NULL)
643: /* a link with attribute REL="Chapter" has been found */
644: {
645: next = link;
646: attrType.AttrTypeNum = HTML_ATTR_HREF_;
647: HrefAttr = TtaGetAttribute (link, attrType);
648: if (HrefAttr != NULL)
649: /* this link has an attribute HREF */
650: {
651: length = TtaGetTextAttributeLength (HrefAttr);
652: text = TtaGetMemory (length + 1);
653: TtaGiveTextAttributeValue (HrefAttr, text, &length);
654: /* ignore links to a particular position within a document */
655: ptr = strrchr (text, '#');
656: if (ptr == NULL)
657: /* this link designate the whole document */
658: {
659: /* create a new document and loads the target document */
660: includedDocument = TtaNewDocument ("HTML", "tmp");
1.7 cvs 661: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_FETCHING), text);
1.1 cvs 662: newdoc = GetHTMLDocument (text, NULL, includedDocument,
663: document, DC_TRUE);
664: if (newdoc != 0 && newdoc != document)
665: /* it's not the document itself */
666: /* copy the target document at the position of the link */
667: MoveDocumentBody (&next, document, newdoc,
668: newdoc == includedDocument);
669: FreeDocumentResource (includedDocument);
670: TtaCloseDocument (includedDocument);
671: }
672: TtaFreeMemory (text);
673: }
674: return (next);
675: }
676: return (NULL);
677: }
678:
679:
680: /*----------------------------------------------------------------------
681: MakeBook
682: Replace all links in a document which have an attribute REL="chapter"
1.5 cvs 683: or REL="subdocument" by the corresponding target document.
1.1 cvs 684: ----------------------------------------------------------------------*/
685: #ifdef __STDC__
686: void MakeBook (Document document, View view)
687: #else
688: void MakeBook (document, view)
689: Document document;
690: View view;
691: #endif
692: {
693: Element root, body, el;
694: ElementType elType;
695:
696: root = TtaGetMainRoot (document);
697: elType = TtaGetElementType (root);
698: elType.ElTypeNum = HTML_EL_BODY;
699: body = TtaSearchTypedElement (elType, SearchForward, root);
700: TtaSetDocumentModified (document);
701: el = body;
702: while (el != NULL)
703: el = GetIncludedDocuments (el, document);
1.7 cvs 704: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), "");
1.1 cvs 705: }
706:
707:
708: #ifdef R_HTML
709: /*----------------------------------------------------------------------
710: ----------------------------------------------------------------------*/
711: #ifdef __STDC__
712: static void LoadEntity (Document document, char *text)
713: #else
714: static void LoadEntity (document, text)
715: Document document;
716: char *text;
717: #endif
718: {
719: Document includedDocument;
720: Attribute attr;
721: AttributeType attrType;
722: Element el, includedEl;
723: ElementType elType;
724: int length;
725:
726: /* create the temporary document */
727: includedDocument = TtaNewDocument ("HTML", "tmp");
728: /* read the temporary document */
729: includedDocument = GetHTMLDocument (text, NULL, includedDocument, document, DC_TRUE);
730:
731: if (includedDocument != 0)
732: {
733: /* To do: Seach entity in the table */
734: /* locate the entity in the document */
735: el = TtaGetMainRoot (document);
736: elType = TtaGetElementType (el);
737: elType.ElTypeNum = HTML_EL_Entity;
738: /* TtaSearchElementByLabel (label, el); */
739: el = TtaSearchTypedElement (elType, SearchForward, el);
740: /* keep the entity name to know where to insert the sub-tree */
741: attrType.AttrSSchema = TtaGetDocumentSSchema (document);
742: attrType.AttrTypeNum = HTML_ATTR_entity_name;
743: attr = TtaGetAttribute (el, attrType);
744: if (attr != NULL)
745: {
746: length = TtaGetTextAttributeLength (attr);
747: text = TtaGetMemory (length + 1);
748: TtaGiveTextAttributeValue (attr, text, &length);
749: }
750: /* To do: translate the entity name into element type
751: and search this first element type in included document */
752: includedEl = TtaGetMainRoot (includedDocument);
753: elType = TtaGetElementType (includedEl);
754: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
755: includedEl = TtaSearchTypedElement (elType, SearchForward, includedEl);
756: /* remove Entity */
757: /* To do: insert sub-trees */
758: FreeDocumentResource (includedDocument);
759: TtaCloseDocument (includedDocument);
760: }
761: }
762: #endif /* R_HTML */
763:
764:
765: /*----------------------------------------------------------------------
766: ----------------------------------------------------------------------*/
767: #ifdef __STDC__
768: void RealTimeHTML (Document document, View view)
769: #else
770: void RealTimeHTML (document, view)
771: Document document;
772: View view;
773: #endif
774: {
775: #ifdef R_HTML
776: Element root, el;
777: ElementType elType;
778:
779: root = TtaGetMainRoot (document);
780: elType = TtaGetElementType (root);
781: elType.ElTypeNum = HTML_EL_Entity;
782: el = TtaSearchTypedElement (elType, SearchForward, root);
783: if (el != NULL)
784: {
785: /* document contains entities */
786: /* To do -> build table of entities */
787:
788: /* simulate reception of different entities */
789: LoadEntity (document, "0/0");
790: LoadEntity (document, "0/1");
791: }
792: #endif /* R_HTML */
793: }
Webmaster