Annotation of Amaya/amaya/HTMLbook.c, revision 1.2

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

Webmaster