Annotation of Amaya/amaya/HTMLbook.c, revision 1.13
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__
1.12 cvs 499: static void MoveDocumentBody (Element *el, Document destDoc,
500: Document sourceDoc, char *target, boolean deleteTree)
1.1 cvs 501: #else
1.12 cvs 502: static void MoveDocumentBody (el, destDoc, sourceDoc, target, deleteTree)
503: Element *el;
504: Document destDoc;
505: Document sourceDoc;
506: char *target;
507: boolean deleteTree;
1.1 cvs 508: #endif
509: {
1.12 cvs 510: Element root, body, ancestor, elem, firstInserted;
511: Element lastInserted, srce, copy, old, parent, sibling;
512: ElementType elType;
513: NotifyElement event;
514: int checkingMode;
1.13 ! cvs 515: boolean isID;
1.1 cvs 516:
1.12 cvs 517: firstInserted = NULL;
1.13 ! cvs 518: if (target != NULL)
! 519: {
! 520: /* locate the target element within the source document */
! 521: root = SearchNAMEattribute (sourceDoc, target, NULL);
! 522: elType = TtaGetElementType (root);
! 523: isID = (elType.ElTypeNum != HTML_EL_Anchor
! 524: && elType.ElTypeNum != HTML_EL_MAP);
! 525: }
! 526: else
! 527: {
! 528: isID = FALSE;
! 529: /* get the BODY element of source document */
! 530: root = TtaGetMainRoot (sourceDoc);
! 531: elType = TtaGetElementType (root);
! 532: elType.ElTypeNum = HTML_EL_BODY;
! 533: root = TtaSearchTypedElement (elType, SearchForward, root);
! 534: }
! 535:
! 536: if (root != NULL)
1.12 cvs 537: {
538: /* don't check the abstract tree against the structure schema */
539: checkingMode = TtaGetStructureChecking (destDoc);
540: TtaSetStructureChecking (0, destDoc);
541: /* get elem, the ancestor of *el which is a child of a DIV or BODY
542: element in the destination document. The copied elements will be
543: inserted just before this element. */
544: elem = *el;
545: do
1.1 cvs 546: {
1.12 cvs 547: ancestor = TtaGetParent (elem);
548: if (ancestor != NULL)
549: {
550: elType = TtaGetElementType (ancestor);
551: if (elType.ElTypeNum == HTML_EL_BODY ||
552: elType.ElTypeNum == HTML_EL_Division)
553: ancestor = NULL;
554: else
555: elem = ancestor;
556: }
1.1 cvs 557: }
1.12 cvs 558: while (ancestor != NULL);
559: parent = TtaGetParent (elem);
1.1 cvs 560:
1.12 cvs 561: /* do copy */
562: lastInserted = NULL;
1.13 ! cvs 563: srce = TtaGetFirstChild (root);
1.12 cvs 564: while (srce != NULL)
1.1 cvs 565: {
1.12 cvs 566: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent);
567: if (copy != NULL)
568: {
569: if (lastInserted == NULL)
570: /* this is the first copied element. Insert it before elem */
571: {
572: TtaInsertSibling (copy, elem, TRUE, destDoc);
573: firstInserted = copy;
574: }
575: else
576: /* insert the new copied element after the element previously
577: copied */
578: TtaInsertSibling (copy, lastInserted, FALSE, destDoc);
579: lastInserted = copy;
580: /* update the NAMEs and URLs in the copied element */
581: event.document = destDoc;
582: event.position = sourceDoc;
583: UpdateURLsInSubtree(&event, copy);
584: }
585: /* get the next element in the source document */
586: old = srce;
587: TtaNextSibling (&srce);
588: if (deleteTree)
589: TtaDeleteTree (old, sourceDoc);
1.13 ! cvs 590: /* Stop here if the target points to a specific element with an ID */
! 591: if (isID)
! 592: srce = NULL;
1.1 cvs 593: }
1.12 cvs 594:
595: /* delete the element(s) containing the link to the copied document */
596: /* delete the parent element of *el and all empty ancestors */
597: elem = TtaGetParent (*el);
598: do
1.1 cvs 599: {
1.12 cvs 600: sibling = elem;
601: TtaNextSibling (&sibling);
602: if (sibling == NULL)
603: {
604: sibling = elem;
605: TtaPreviousSibling (&sibling);
606: if (sibling == NULL)
607: elem = TtaGetParent (elem);
608: }
1.1 cvs 609: }
1.12 cvs 610: while (sibling == NULL);
611: TtaDeleteTree (elem, destDoc);
612: /* restore previous chacking mode */
613: TtaSetStructureChecking (checkingMode, destDoc);
614: /* return the address of the first copied element */
615: *el = firstInserted;
616: }
1.1 cvs 617: }
618:
619: /*----------------------------------------------------------------------
620: GetIncludedDocuments
621: Look forward, starting from element el, for a link (A) with attribute
1.5 cvs 622: REL="chapter" or REL="subdocument" and replace that link by the contents
623: of the target document.
1.1 cvs 624: ----------------------------------------------------------------------*/
625: #ifdef __STDC__
626: static Element GetIncludedDocuments (Element el, Document document)
627: #else
628: static Element GetIncludedDocuments (el, document)
629: Element el;
630: Document document;
631: #endif
632: {
633: Element link, next;
634: Attribute RelAttr, HrefAttr;
635: AttributeType attrType;
636: int length;
1.12 cvs 637: char *text, *ptr, *url;
1.1 cvs 638: Document includedDocument, newdoc;
639:
640: attrType.AttrSSchema = TtaGetDocumentSSchema (document);
641: attrType.AttrTypeNum = HTML_ATTR_REL;
642: link = el;
643: RelAttr = NULL;
1.5 cvs 644: /* looks for an anchor having an attribute REL="chapter" or
645: REL="subdocument" */
1.1 cvs 646: while (link != NULL && RelAttr == NULL)
647: {
648: TtaSearchAttribute (attrType, SearchForward, link, &link, &RelAttr);
649: if (link != NULL && RelAttr != NULL)
650: {
651: length = TtaGetTextAttributeLength (RelAttr);
652: text = TtaGetMemory (length + 1);
653: TtaGiveTextAttributeValue (RelAttr, text, &length);
1.5 cvs 654: if (strcasecmp (text, "chapter") && strcasecmp (text, "subdocument"))
1.1 cvs 655: RelAttr = NULL;
656: TtaFreeMemory (text);
657: }
658: }
659:
660: if (RelAttr != NULL && link != NULL)
661: /* a link with attribute REL="Chapter" has been found */
662: {
663: next = link;
664: attrType.AttrTypeNum = HTML_ATTR_HREF_;
665: HrefAttr = TtaGetAttribute (link, attrType);
666: if (HrefAttr != NULL)
667: /* this link has an attribute HREF */
668: {
669: length = TtaGetTextAttributeLength (HrefAttr);
670: text = TtaGetMemory (length + 1);
671: TtaGiveTextAttributeValue (HrefAttr, text, &length);
672: ptr = strrchr (text, '#');
1.12 cvs 673: url = text;
674: if (ptr != NULL)
675: {
676: if (ptr == text)
677: url = NULL;
678: /* link to a particular position within a document */
679: ptr[0] = EOS;
680: ptr = &ptr[1];
681: }
682:
683: if (url != NULL)
684: /* this link designate an external document */
1.1 cvs 685: {
686: /* create a new document and loads the target document */
687: includedDocument = TtaNewDocument ("HTML", "tmp");
1.12 cvs 688: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_FETCHING), url);
689: newdoc = GetHTMLDocument (url, NULL, includedDocument,
1.1 cvs 690: document, DC_TRUE);
691: if (newdoc != 0 && newdoc != document)
1.12 cvs 692: {
1.1 cvs 693: /* it's not the document itself */
694: /* copy the target document at the position of the link */
1.12 cvs 695: MoveDocumentBody (&next, document, newdoc, ptr,
1.1 cvs 696: newdoc == includedDocument);
1.12 cvs 697: }
1.1 cvs 698: FreeDocumentResource (includedDocument);
699: TtaCloseDocument (includedDocument);
700: }
1.12 cvs 701:
1.1 cvs 702: TtaFreeMemory (text);
703: }
704: return (next);
705: }
706: return (NULL);
707: }
708:
709:
710: /*----------------------------------------------------------------------
711: MakeBook
712: Replace all links in a document which have an attribute REL="chapter"
1.5 cvs 713: or REL="subdocument" by the corresponding target document.
1.1 cvs 714: ----------------------------------------------------------------------*/
715: #ifdef __STDC__
716: void MakeBook (Document document, View view)
717: #else
718: void MakeBook (document, view)
719: Document document;
720: View view;
721: #endif
722: {
723: Element root, body, el;
724: ElementType elType;
725:
726: root = TtaGetMainRoot (document);
727: elType = TtaGetElementType (root);
728: elType.ElTypeNum = HTML_EL_BODY;
729: body = TtaSearchTypedElement (elType, SearchForward, root);
730: TtaSetDocumentModified (document);
731: el = body;
732: while (el != NULL)
733: el = GetIncludedDocuments (el, document);
1.7 cvs 734: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), "");
1.1 cvs 735: }
736:
737:
738: #ifdef R_HTML
739: /*----------------------------------------------------------------------
740: ----------------------------------------------------------------------*/
741: #ifdef __STDC__
742: static void LoadEntity (Document document, char *text)
743: #else
744: static void LoadEntity (document, text)
745: Document document;
746: char *text;
747: #endif
748: {
749: Document includedDocument;
750: Attribute attr;
751: AttributeType attrType;
752: Element el, includedEl;
753: ElementType elType;
754: int length;
755:
756: /* create the temporary document */
757: includedDocument = TtaNewDocument ("HTML", "tmp");
758: /* read the temporary document */
759: includedDocument = GetHTMLDocument (text, NULL, includedDocument, document, DC_TRUE);
760:
761: if (includedDocument != 0)
762: {
763: /* To do: Seach entity in the table */
764: /* locate the entity in the document */
765: el = TtaGetMainRoot (document);
766: elType = TtaGetElementType (el);
767: elType.ElTypeNum = HTML_EL_Entity;
768: /* TtaSearchElementByLabel (label, el); */
769: el = TtaSearchTypedElement (elType, SearchForward, el);
770: /* keep the entity name to know where to insert the sub-tree */
771: attrType.AttrSSchema = TtaGetDocumentSSchema (document);
772: attrType.AttrTypeNum = HTML_ATTR_entity_name;
773: attr = TtaGetAttribute (el, attrType);
774: if (attr != NULL)
775: {
776: length = TtaGetTextAttributeLength (attr);
777: text = TtaGetMemory (length + 1);
778: TtaGiveTextAttributeValue (attr, text, &length);
779: }
780: /* To do: translate the entity name into element type
781: and search this first element type in included document */
782: includedEl = TtaGetMainRoot (includedDocument);
783: elType = TtaGetElementType (includedEl);
784: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
785: includedEl = TtaSearchTypedElement (elType, SearchForward, includedEl);
786: /* remove Entity */
787: /* To do: insert sub-trees */
788: FreeDocumentResource (includedDocument);
789: TtaCloseDocument (includedDocument);
790: }
791: }
792: #endif /* R_HTML */
793:
794:
795: /*----------------------------------------------------------------------
796: ----------------------------------------------------------------------*/
797: #ifdef __STDC__
798: void RealTimeHTML (Document document, View view)
799: #else
800: void RealTimeHTML (document, view)
801: Document document;
802: View view;
803: #endif
804: {
805: #ifdef R_HTML
806: Element root, el;
807: ElementType elType;
808:
809: root = TtaGetMainRoot (document);
810: elType = TtaGetElementType (root);
811: elType.ElTypeNum = HTML_EL_Entity;
812: el = TtaSearchTypedElement (elType, SearchForward, root);
813: if (el != NULL)
814: {
815: /* document contains entities */
816: /* To do -> build table of entities */
817:
818: /* simulate reception of different entities */
819: LoadEntity (document, "0/0");
820: LoadEntity (document, "0/1");
821: }
822: #endif /* R_HTML */
823: }
Webmaster