home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / text / hyper / GuideTool1_0.lha / GuideTool / src / GuideTool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  29.2 KB  |  1,105 lines

  1. /*
  2. ** GuideTool V1.0 (C) 1995 by Reinhard Katzmann. All Rights Reserved       
  3. ** The source code may not be altered or changed! No other similar programs
  4. ** like GuideTool may be published with the help of the source code. For
  5. ** other purposes parts of it may be used if _CLEARLY_ stated that your
  6. ** program uses them. Commercial programs need _written_ permission!
  7. **
  8. ** The information contained herein is subject to change without notice,
  9. **
  10. ** The source is provided "as is" without warranty of any kind, either ex-
  11. ** pressed or implied. The entire risk as to the use of this information is
  12. ** assumed by the user.
  13. */
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <workbench/startup.h>
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <dos/var.h>
  24. #include <dos/dos.h>
  25.  
  26. #include <clib/alib_protos.h>
  27.  
  28. #include <proto/exec.h>
  29. #include <proto/dos.h>
  30.  
  31. #include "GuideTool_rev.h"
  32.  
  33. UBYTE versiontag[] = VERSTAG;
  34. UBYTE Copyright[] = VERS " Copyright (C) 1995 by Reinhard Katzmann. All Rights Reserved";
  35.  
  36. #define TEMPLATE "FROM/A,TO/A,C=CONTENTFILE/K,X=XREFFILE/K,CONTENTS/S,INDEX/S,XREF/S,MAKECONT/S,MAKEXREF/S,L=LABELSIZE/K/N,R=XREFSIZE/K/N,ILN=INNERLINKS/S"
  37. #define OPT_FROM            0
  38. #define OPT_TO              1
  39. #define OPT_CONTFILE    2
  40. #define OPT_XREFFILE    3
  41. #define OPT_CONTENTS        4
  42. #define OPT_INDEX           5
  43. #define OPT_XREF            6
  44. #define OPT_MAKECONT        7
  45. #define OPT_MAKEXREF        8
  46. #define OPT_LABELSIZE   9
  47. #define OPT_XREFSIZE   10
  48. #define OPT_INNERLINKS 11
  49. #define OPT_COUNT         12
  50. #define DATABASE        "@database" /* AmigaGuide keywords */
  51. #define NODE            "@node"
  52. #define ENDNODE        "@endnode"
  53. #define TOC                "@toc"
  54. #define REM                "@rem"
  55. #define REMARK            "@remark"
  56. #define IGNORENODE   "@rem ignorenode"
  57. #define STARTLINK        "@{"
  58. #define LINK            " link "
  59. #define LINK2            "link "
  60. #define ENDLINK        "0}"        /* Only used for writing Content links */
  61. #define STOPLINK     "}"
  62. #define INDEX            "@index "
  63. #define INDEXNAME    "Index"
  64.  
  65. #define DBUG 0
  66.  
  67. struct RDArgs *myrda=NULL;
  68.  
  69. char   *nodep[256]={0},*linksp[2048]={0},*linkdp[2048]={0},*endnodep[256]={0};
  70. char     *infile=NULL,*outfile=NULL,*xreffile=NULL,*contfile=NULL,*linkline[2048];
  71. LONG      result[OPT_COUNT]={NULL,NULL};
  72. BOOL   ilnk=FALSE;
  73. ULONG  n=0,l=1;
  74. UBYTE  min=255,lsize,rsize,smax=0,dmax=0,lsmax=0,ldmax=0;
  75.  
  76. void CheckStop(void);
  77.  
  78. void CloseAll(BOOL ec)
  79. /* Gibt Speicher wieder frei */
  80. {
  81.     ULONG co;
  82.     for (co=0;co<n;co++) {
  83.         if (nodep[co]) FreeVec(nodep[co]);
  84.        if (endnodep[co]) FreeVec(endnodep[co]);
  85.     }
  86.     for (co=1;co<l;co++) {
  87.         if (linksp[co]) FreeVec(linksp[co]);
  88.         if (linkdp[co]) FreeVec(linkdp[co]);
  89.         if (linkline[co]) FreeVec(linkline[co]);
  90.     }
  91.     if (myrda) FreeArgs(myrda);
  92.     if (!result[OPT_CONTFILE] && contfile) FreeVec(contfile);
  93.     if (!result[OPT_XREFFILE] && xreffile) FreeVec(xreffile);
  94.     if (ec) exit(0);
  95.     else exit(EXIT_FAILURE);
  96. }
  97.  
  98. void CheckStop(void)
  99. /* CTRL-C Checking */
  100. {
  101.   puts("Break charakter received. Aborting...");
  102.   CloseAll(TRUE);
  103. }
  104.  
  105. /*
  106. ** Read the nodes from an Amigaguide file
  107. ** Does not write anything but closes all files if not an AG Database
  108. */
  109. void AGLoopNodes(FILE *rp,FILE *wp)
  110. {
  111.     BOOL adb=FALSE;
  112.     char    zeile[256],hilfzeile[256];
  113.     ULONG keyword,hp=0,zz=0;
  114.  
  115.     while ( (fgets(zeile,256,rp)) || !(feof(rp)) ) { /* Read all nodes */
  116.         if (!strcmp(zeile,"\n")) continue;
  117.         strcpy(hilfzeile,zeile);
  118.  
  119.         if (!adb) { /* Make sure we have an Amigaguide file */
  120.             keyword=(ULONG)strstr(strlwr(hilfzeile),DATABASE);
  121.             if (keyword) {
  122.                 adb=TRUE;
  123.                 continue;
  124.             } else {
  125.                 if (wp) fclose(wp);
  126.                 if (rp) fclose(rp);
  127.                 printf("Not an Amigaguide Database file.\n");
  128.                 CloseAll(FALSE);
  129.             }
  130.         }
  131.  
  132.         keyword=(ULONG)strstr(strlwr(hilfzeile),NODE);
  133.         if (keyword) { /* Add node to node array */
  134.             if (n>255) {
  135.                 zz++;
  136.                 continue;
  137.             }
  138.             nodep[n]=AllocVec(rsize,MEMF_PUBLIC|MEMF_CLEAR);
  139.             if (nodep[n]) { /* Read node name */
  140.                 hp=(ULONG)stptok(zeile,nodep[n],rsize," ");
  141.                 hp=(ULONG)stpblk((char *)++hp);
  142.                 if (stricmp(nodep[n],NODE)) { /* @node not at beginning of line */
  143.                     FreeVec(nodep[n]);
  144.                     nodep[n]=NULL;
  145.                     continue;
  146.                 }
  147.                 if (*(char *)hp=='\"') {
  148.                     hp=(ULONG)stptok((char *)(hp+1),hilfzeile,rsize-2,"\""); /* Get node */
  149.                     strcpy(nodep[n],"\"");
  150.                     strcat(nodep[n],hilfzeile);
  151.                     strcat(nodep[n],"\"");
  152.                 }
  153.                 else hp=(ULONG)stptok((char *)hp,nodep[n],rsize," ");
  154.                 strcpy(hilfzeile,nodep[n]);
  155.                 strlwr(hilfzeile);
  156.                 if (!(stricmp(hilfzeile,"main")) || !(stricmp(hilfzeile,"main\n")) || !(stricmp(hilfzeile,"\"main\"")) ) { /* Ignore main node */
  157.                     FreeVec(nodep[n]);
  158.                     nodep[n]=NULL;
  159.                     continue;
  160.                 }
  161.                 if (strlen(nodep[n])>smax) smax=strlen(nodep[n]);
  162.                 if (DBUG) printf("nodep[%d]=%s,hp=%s\n",n,nodep[n],hp);
  163.             }
  164.             endnodep[n]=AllocVec(lsize,MEMF_PUBLIC|MEMF_CLEAR);
  165.             if (endnodep[n]) { /* Read node label */
  166.                 strcat(endnodep[n]," ");
  167.                 hp=(ULONG)stpblk((char *)++hp);
  168.                 if (*(char *)hp=='\"') {
  169.                     hp=(ULONG)stptok((char *)(hp+1),hilfzeile,lsize-2,"\""); /* Get node */
  170.                     strcat(endnodep[n],"\"");
  171.                     strcat(endnodep[n],hilfzeile);
  172.                     strcat(endnodep[n],"\"");
  173.                 } else {
  174.                     hp=(ULONG)stptok((char *)hp,hilfzeile,lsize," ");
  175.                     strcat(endnodep[n],hilfzeile);
  176.                 }
  177.                 if (strlen(endnodep[n])>dmax) dmax=strlen(endnodep[n]);
  178.             }
  179.             n++;
  180.             continue;
  181.         }
  182.  
  183.         keyword=(ULONG)strstr(strlwr(hilfzeile),IGNORENODE);
  184.         if (keyword) { /* Ignore last node */
  185.             hp=(ULONG)stptok(zeile,hilfzeile,256," ");
  186.             hp=(ULONG)stpblk((char *)++hp);
  187.             if (stricmp(hilfzeile,IGNORENODE)) continue; /* IGNORENODE not at beginning of line */
  188.             if (nodep[n]) {
  189.                 FreeVec(nodep[n]);
  190.                 nodep[n]=NULL;
  191.             }
  192.             if (endnodep[n]) {
  193.                 FreeVec(endnodep[n]);
  194.                 endnodep[n]=NULL;
  195.             }
  196.             n--;
  197.         }
  198.         
  199.     }
  200.     if (zz) printf("Link number overflow: %d more links than program supports.\n",zz);
  201. }
  202.  
  203. /*
  204. ** Read all links (Currently only LINK command supported)
  205. ** Does not write anything but closes all files if not an AG Database
  206. */
  207. void AGLoopLinks(FILE *rp, FILE *wp)
  208. {
  209.     BOOL adb=FALSE,del=FALSE;
  210.     char    zeile[256],hilfzeile[256];
  211.     ULONG keyword,hp=0,hp03=0,co,zz=0;
  212.  
  213.     while ( (fgets(zeile,256,rp)) || !(feof(rp)) ) { /* Read all links */
  214.         if (!strcmp(zeile,"\n")) continue;
  215.         strcpy(hilfzeile,zeile);
  216.  
  217.         if (!adb) { /* Make sure we have an Amigaguide file */
  218.             keyword=(ULONG)strstr(strlwr(hilfzeile),DATABASE);
  219.             if (keyword) {
  220.                 adb=TRUE;
  221.                 continue;
  222.             } else {
  223.                 if (wp) fclose(wp);
  224.                 if (rp) fclose(rp);
  225.                 printf("Not an Amigaguide Database file.\n");
  226.                 CloseAll(FALSE);
  227.             }
  228.         }
  229.  
  230.         keyword=(ULONG)zeile;
  231.         while (keyword=(ULONG)strstr((char *)keyword,STARTLINK)) { /* Add Label to label array */
  232.             if (l>2047) {
  233.                 zz++;
  234.                 keyword+=2;
  235.                 continue;
  236.             }
  237.             if ((*(char *)(keyword-1))=='\\') {
  238.               keyword+=2;
  239.            continue;
  240.          }
  241.             linksp[l]=AllocVec(lsize,MEMF_PUBLIC|MEMF_CLEAR);
  242.             if (linksp[l]) { /* Read link label name */
  243.                 hp=keyword+sizeof(STARTLINK)-1;
  244.                 if (*(char *)hp=='\"') {
  245.                     hp=(ULONG)stptok((char *)(hp+1),hilfzeile,lsize-2,"\""); /* Get node */
  246.                     strcpy(linksp[l],"\"");
  247.                     hp03=(ULONG)stpblk(hilfzeile);
  248.                     hp03=(ULONG)strrev((char *)hp03);
  249.                     hp03=(ULONG)stpblk((char *)hp03);
  250.                     hp03=(ULONG)strrev((char *)hp03);
  251.                     strcat(linksp[l],(char *)hp03);
  252.                     strcat(linksp[l],"\"");
  253.                 } else { /* Original AmigaGuide has problems here, too, so I simply skip it */
  254.                     keyword+=2;
  255.                     continue; 
  256.                 }
  257.                 /* hp=(ULONG)stptok((char *)hp,linksp[l],lsize," "); */
  258.             } else CloseAll(FALSE);
  259.             strcpy(hilfzeile,(char *)hp);
  260.             strlwr(hilfzeile);
  261.             if (!((ULONG)strstr(hilfzeile,LINK)) && !((ULONG)strstr(hilfzeile,LINK2))) { /* not LINK command */
  262.                 FreeVec(linksp[l]);
  263.                 linksp[l]=NULL;
  264.                 keyword+=2;
  265.                 continue;
  266.             }
  267.             linkdp[l]=AllocVec(rsize,MEMF_PUBLIC|MEMF_CLEAR);
  268.             if (linkdp[l]) { /* Read link (path) name */
  269.                 hp+=sizeof(LINK);
  270.                 if (*(char *)(hp-1)!=' ') hp--;
  271.                 if (*(char *)hp=='\"') {
  272.                     hp=(ULONG)stptok((char *)(hp+1),hilfzeile,rsize-2,"\""); /* Get node */
  273.                     strcpy(linkdp[l],"\"");
  274.                     strcat(linkdp[l],hilfzeile);
  275.                     strcat(linkdp[l],"\"");
  276.                 } else {
  277.                     hp=(ULONG)stptok((char *)hp,linkdp[l],rsize,STOPLINK);
  278.                     hp03=(ULONG)linkdp[l];
  279.                     hp03=(ULONG)stptok((char *)hp03,hilfzeile,rsize," ");
  280.                     if ((*(char *)hp03)==' ') hp-=sizeof(hp03); else hp--;
  281.                     strcpy(linkdp[l],"\"");
  282.                     strcat(linkdp[l],hilfzeile);
  283.                     strcat(linkdp[l],"\"");
  284.                 }
  285.             } else CloseAll(FALSE);
  286.             /* Check if label is already in the array (Slow, but must be) */
  287.             for (co=0;co<l;co++) {
  288.                 if ( (!stricmp(linksp[co],linksp[l])) && (!stricmp(linkdp[co],linkdp[l]))) {
  289.                    if (ilnk) {
  290.                        del=TRUE;
  291.                         break; 
  292.                     }
  293.                else {
  294.                         if (linksp[l]) FreeVec(linksp[l]);
  295.                         linksp[l]=NULL;
  296.                         if (linkdp[l]) FreeVec(linkdp[l]);
  297.                         linkdp[l]=NULL;
  298.                         break;
  299.                     }
  300.                 }
  301.             }
  302.             if (co!=l && !ilnk) {
  303.                 keyword+=2;
  304.                 continue;
  305.             }
  306.             if (linksp[l] && (strlen(linksp[l])>lsmax)) lsmax=strlen(linksp[l]);
  307.             if (linkdp[l] && (strlen(linkdp[l])>ldmax)) ldmax=strlen(linkdp[l]);
  308.             linkline[l]=AllocVec(10,MEMF_PUBLIC|MEMF_CLEAR);
  309.             if (linkline[l]) {
  310.                 hp=(ULONG)stpblk((char *)++hp);
  311.                 hp=(ULONG)stptok((char *)hp,linkline[l],10,STOPLINK); /* Get line number */
  312.             } else CloseAll(FALSE);
  313.             if (del)
  314.                 if (!stricmp(linkline[l],linkline[co])) {
  315.                     if (linksp[l]) FreeVec(linksp[l]);
  316.                     linksp[l]=NULL;
  317.                     if (linkdp[l]) FreeVec(linkdp[l]);
  318.                     linkdp[l]=NULL;
  319.                     if (linkline[l]) FreeVec(linkline[l]);
  320.                     linkline[l]=NULL;
  321.                     keyword+=2;
  322.                     continue;
  323.                 }
  324.             l++;
  325.             keyword+=2;
  326.         }
  327.     }
  328.     if (zz) printf("Link number overflow: %d more links than program supports.\n",zz);
  329. }
  330.  
  331. /*
  332. ** Read Xref File
  333. */
  334. void ParseXref(FILE *rp)
  335. {
  336.     ULONG hp=0,zz=0;
  337.     char zeile[256],hzeile[256];
  338.  
  339.     while ( (fgets(zeile,256,rp)) || !(feof(rp)) ) {
  340.         if (!strcmp(zeile,"\n")) continue;
  341.         if (l>2047) {
  342.             zz++;
  343.             continue;
  344.         }
  345.         linksp[l]=AllocVec(lsize,MEMF_PUBLIC|MEMF_CLEAR);
  346.         if (linksp[l]) { /* Read link label name */
  347.             hp=(ULONG)zeile;
  348.             hp=(ULONG)stpblk((char *)hp);
  349.             if (*(char *)hp==';') continue;  /* ; = comment */
  350.             if (*(char *)hp=='\"') {
  351.                 hp=(ULONG)stptok((char *)(hp+1),hzeile,lsize-2,"\""); /* Get node */
  352.                 strcpy(linksp[l],"\"");
  353.                 strcat(linksp[l],hzeile);
  354.                 strcat(linksp[l],"\"");
  355.             } else hp=(ULONG)stptok((char *)hp,linksp[l],lsize," ");
  356.             if (strlen(linksp[l])<min) min=strlen(linksp[l])-2;
  357.         }
  358.         linkdp[l]=AllocVec(rsize,MEMF_PUBLIC|MEMF_CLEAR);
  359.         if (linkdp[l]) { /* Read link (path) name */
  360.             hp=(ULONG)stpblk((char *)++hp);
  361.             if (*(char *)hp=='\"') {
  362.                 hp=(ULONG)stptok((char *)(hp+1),hzeile,rsize-2,"\""); /* Get node */
  363.                 strcpy(linkdp[l],"\"");
  364.                 strcat(linkdp[l],hzeile);
  365.                 strcat(linkdp[l],"\"");
  366.             }
  367.         }        
  368.         linkline[l]=AllocVec(10,MEMF_PUBLIC|MEMF_CLEAR);
  369.         if (linkline[l]) { /* Read link (path) name */
  370.             hp=(ULONG)stpblk((char *)++hp);
  371.             hp=(ULONG)stptok((char *)hp,linkline[l],10,"\n");
  372.         }
  373.         l++;
  374.     }
  375.     if (zz) printf("Link number overflow: %d more links than program supports.\n",zz);
  376. }
  377.  
  378. /*
  379. ** Create Contents from Amigaguide file and add it
  380. */
  381. void ParseWriteContents(void)
  382. {
  383.     ULONG co;
  384.     FILE *fp,*gp,*cp;
  385.     char zeile[256],hilfzeile[256],hzeile[256];
  386.     ULONG hp;
  387.  
  388.     fp=fopen(infile,"r");
  389.     if (!fp) {
  390.         printf("Could not open Amigaguide file for reading.\n");
  391.         CloseAll(FALSE);
  392.     }
  393.  
  394.     gp=fopen(outfile,"w");
  395.     if (!gp) {
  396.         printf("Could not open Contents AG file for writing.\n");
  397.         if (fp) fclose(fp);
  398.         CloseAll(FALSE);
  399.     }
  400.     fputs("@node \"main\" \"main\"\n",gp);
  401.     fputs("@toc \"main\"\n",gp);
  402.  
  403.     cp=fopen(contfile,"r");
  404.     if (!cp) {
  405.         printf("Could not open Contents file for reading.\n");
  406.         if (gp) fclose(gp);
  407.         if (fp) fclose(fp);
  408.         CloseAll(FALSE);
  409.     }
  410.  
  411.     while ( (fgets(zeile,256,cp)) || !(feof(cp)) ) {
  412.         if (!strcmp(zeile,"###\n")) break;
  413.       fputs(zeile,gp);
  414.     }
  415.     fputs("\n\n               Table of Contents\n\n",gp);
  416.  
  417.     AGLoopNodes(fp,gp);
  418.  
  419.     if (fp) fclose(fp);
  420.  
  421.     while ( (fgets(zeile,256,cp)) || !(feof(cp)) ) {
  422.         if (!strcmp(zeile,"\n")) {
  423.             fputs(zeile,gp);
  424.             continue;
  425.         }
  426.         hp=(ULONG)stpblk(zeile); /* Skip leading blanks */
  427.         if (*(char *)hp==';') continue;  /* ; = comment */
  428.         if (*(char *)hp=='\"') {
  429.             hp=(ULONG)stptok((char *)(hp+1),hilfzeile,rsize-2,"\""); /* Get node */
  430.             strcpy(hzeile,"\"");
  431.             strcat(hzeile,hilfzeile);
  432.             strcat(hzeile,"\"");
  433.         }
  434.         else hp=(ULONG)stptok(zeile,hzeile,rsize," "); /* Get node */
  435.         hp=(ULONG)stpblk((char *)++hp);
  436.         
  437.         if (DBUG) printf("hilfzeile=%s,hzeile=%s,hp=%s\n",hilfzeile,hzeile,hp);
  438.       for (co=0;co<n;co++) {
  439.           if (!(stricmp(hzeile,nodep[co]))) {
  440.                 if (*(char *)hp=='\"') {
  441.                     hp=(ULONG)stptok((char *)(hp+1),hilfzeile,lsize-2,"\""); /* Get endnode */
  442.                     strcpy(hzeile,"\"");
  443.                     strcat(hzeile,hilfzeile);
  444.                     strcat(hzeile,"\"");
  445.                 }
  446.                 else hp=(ULONG)stptok((char *)hp,hzeile,lsize," ");
  447.                 hp=(ULONG)stpblk((char *)++hp);
  448.                 strcpy(hilfzeile,"  ");
  449.               strcat(hilfzeile,STARTLINK);
  450.               strcat(hilfzeile,hzeile);
  451.               strcat(hilfzeile,LINK);
  452.               strcat(hilfzeile,nodep[co]);
  453.               strcat(hilfzeile," ");
  454.               strcat(hilfzeile,ENDLINK);
  455.               strcat(hilfzeile," ");
  456.               strcat(hilfzeile,(char *)hp);
  457.               strcat(hilfzeile,"\n");
  458.               fputs(hilfzeile,gp);
  459.               break;
  460.           }
  461.       }
  462.     }
  463.     
  464.     if(cp) fclose(cp);
  465.     
  466.     fputs("\n\n\n",gp);
  467.     fputs(ENDNODE,gp);
  468.     fputs("\n",gp);
  469.     if (gp) fclose(gp);
  470.     CloseAll(TRUE);
  471. }
  472.  
  473. /*
  474. ** Convert Charakter to string
  475. */
  476. char *c2str(char c,char *ch)
  477. {
  478.   ch[0]=c;
  479.   ch[1]='\0';
  480.   return ch;
  481. }
  482.  
  483. /*
  484. ** Sort all links
  485. */
  486. void SortXref(void)
  487. {
  488.     ULONG co,cu,elem,hp,hp03;
  489.  
  490.     for (co=2;co<l;co++) { /* Sort all links (Insertion Sort) */
  491.         elem=(ULONG)linksp[co];
  492.         hp=(ULONG)linkdp[co];
  493.         hp03=(ULONG)linkline[co];
  494.         cu=co;
  495.         while (cu>=2 && stricmp(linksp[cu-1],(char *)elem)>0) {
  496.             linksp[cu]=linksp[cu-1];
  497.             linkdp[cu]=linkdp[cu-1];
  498.             linkline[cu]=linkline[cu-1];
  499.             cu--;
  500.         }
  501.         linksp[cu]=(char *)elem;
  502.         linkdp[cu]=(char *)hp;
  503.         linkline[cu]=(char *)hp03;
  504.     }
  505. }
  506.  
  507. /* 
  508. ** Create Index from Amigaguide file and add it
  509. */
  510. void ParseWriteIndex(void)
  511. {
  512.     FILE *fp,*gp;
  513.     ULONG co,elem;
  514.     char    hzeile[256],old[256];
  515.  
  516.     fp=fopen(infile,"r");
  517.     if (!fp) {
  518.         printf("Could not open Xref file for reading.\n");
  519.         CloseAll(FALSE);
  520.     }
  521.  
  522.     gp=fopen(outfile,"w");
  523.     if (!gp) {
  524.         printf("Could not open Index file for writing.\n");
  525.         if (fp) fclose(fp);
  526.         CloseAll(FALSE);
  527.     }
  528.  
  529.    ParseXref(fp);
  530.  
  531.     if (fp) fclose(fp);
  532.  
  533.     SortXref();
  534.  
  535.     strcpy(hzeile,INDEX);
  536.     strcat(hzeile,INDEXNAME);
  537.     strcat(hzeile,"\n\n");
  538.     fputs(hzeile,gp);
  539.     strcpy(hzeile,NODE);
  540.     strcat(hzeile," \"Index\" \"");
  541.     strcat(hzeile,INDEXNAME);
  542.     strcat(hzeile,"\"\n\n   Index\n");
  543.     fputs(hzeile,gp);
  544.     for(co=1;co<l;co++) {
  545.         elem=(ULONG)linksp[co];
  546.         if (*(char *)elem=='\"') stptok((char *)(elem+1),hzeile,lsize-2,"\"");
  547.         else strcpy(hzeile,linksp[co]);
  548.         if (!co || ((UBYTE)tolower(hzeile[0])!=(UBYTE)tolower(old[0]))) {
  549.             strcpy(old,hzeile);
  550.             strcpy(hzeile,"\n   ");
  551.             strcat(hzeile,strupr(c2str(old[0],old)));
  552.             strcat(hzeile,"\n\n");
  553.             fputs(hzeile,gp);
  554.         }
  555.         strcpy(hzeile,"   ");
  556.         strcat(hzeile,STARTLINK);
  557.         strcat(hzeile,linksp[co]);
  558.         strcat(hzeile,LINK);
  559.         strcat(hzeile,linkdp[co]);
  560.         strcat(hzeile," ");
  561.         strcat(hzeile,linkline[co]);
  562.         strcat(hzeile,STOPLINK);
  563.         strcat(hzeile,"\n");
  564.         fputs(hzeile,gp);
  565.     }
  566.     fputs("\n\n\n",gp);
  567.     fputs(ENDNODE,gp);
  568.     fputs("\n",gp);
  569.     if (gp) fclose(gp);
  570.     CloseAll(TRUE);
  571. }
  572.  
  573.  
  574. /*
  575. ** Converts pnode to AG Command if it is in link array
  576. ** but not if it current node equal to link
  577. */
  578. char *AddAGIfNode(char *pnode,char *hzeile,char *curnode)
  579. {
  580.     ULONG right=l-1,left=1,x;
  581.  
  582.     strcpy(hzeile,"\""); /* Convert it to a node with quutation marks */
  583.     strcat(hzeile,pnode);
  584.     strcat(hzeile,"\"");
  585.     while(right>=left) {
  586.         x=(left+right)/2;
  587.         if (stricmp(hzeile,linksp[x])<0) right=x-1; else left=x+1;
  588.         if (!(stricmp(hzeile,linksp[x]))) {
  589.             if ( ! stricmp(curnode,linkdp[x]))
  590.                 if (!ilnk || linkline[x]==0) return pnode;
  591.             strrev(hzeile);
  592.             strcat(hzeile,"{@\0");
  593.             strrev(hzeile);
  594.             strcat(hzeile,LINK);
  595.             strcat(hzeile,linkdp[x]);
  596.             strcat(hzeile," ");
  597.             strcat(hzeile,linkline[x]);
  598.             strcat(hzeile,STOPLINK);
  599.             return hzeile;
  600.         }
  601.     }
  602.     strcpy(hzeile,pnode);
  603.     return hzeile;
  604. }
  605.  
  606. /*
  607. ** Check if token contains a valid AG command of type STARTLINK
  608. */
  609. UBYTE GetAGCommand(char *tok,char **newl)
  610. {
  611.     char *newline, *nl;
  612.    ULONG num;
  613.     
  614.     nl=*newl;
  615.     if ( (*nl)=='@' && (*(nl+1))=='{' ) { /* Ignore command, set newline corresponding */
  616.         if ( (*(nl+2))!='\"' ) {
  617.            stptok(nl,tok,256,STOPLINK); /* Get command */
  618.            strcat(tok,STOPLINK);
  619.             nl=strstr(nl,STOPLINK);
  620.             *newl=nl;
  621.             return 1;
  622.         } else { /* @{<label> <command>} link command */
  623.             newline=nl; /* Save pointer for later use */
  624.             nl=strstr(nl+1,"\""); /* Skip Label */
  625.             nl=strstr(nl+1,"\"");
  626.             nl=strstr(nl+1," "); /* Skip command */
  627.             nl=strstr(nl+1," ");
  628.             if ( *(nl+1)!='\"') nl=strstr(nl+1,STOPLINK);
  629.             else { /* Seek end of link path name */
  630.                 nl=strstr(nl+1,"\"");
  631.                 nl=strstr(nl+1,"\"");
  632.                 nl=strstr(nl,STOPLINK);
  633.             }
  634.             num=strlen(newline)-strlen(nl);
  635.             strncpy(tok,newline,num);
  636.             tok[num]='\0';
  637.             strcat(tok,STOPLINK);
  638.         }
  639.         *newl=nl;
  640.         return 1;
  641.     }
  642.     return 0;
  643. }
  644.  
  645. /*
  646. ** Checks if the character is in the symbol quantity
  647. */
  648. BOOL Chk4Sym(char c)
  649. {
  650.     char  sm[]="\t\n !\"#$&\',-./:;=?@`"; /* symbol quantity */
  651.     UBYTE right=strlen(sm),left=0,x;
  652.  
  653.     if (c<9) if (c=='ยง') return TRUE; else return FALSE;
  654.     while(right>=left) {
  655.         if (right>strlen(sm)) right=strlen(sm);
  656.         x=(left+right)/2;
  657.         if (c<sm[x]) right=x-1; else left=x+1;
  658.         if (c==sm[x]) return TRUE;
  659.     }
  660.     return FALSE;
  661. }
  662.  
  663. /*
  664. ** Checks string until quantity symbol for match with link labels
  665. ** Deletes charakters from behind
  666. */
  667. BOOL MatchAGLabel(unsigned char *str, unsigned char *curnode)
  668. {
  669.     unsigned char cp[256],hp[256],co,cu,cl,hp01[2],*hp02,hp03[2],slen;
  670.  
  671.     strcpy(cp,str); /* Make a copy of string (str will be changed!) */
  672.     cl=strlen(cp)-1;
  673.     cu=cl;
  674.     c2str(cp[cu],hp01); /* Backup Endsymbol */
  675.     /* slen=cu */
  676.     strcpy(hp,str); /* Make a copy of the original string */
  677.  
  678.     cp[cu]='\0'; /* Remove the end symbol */
  679.     AddAGIfNode(cp,str,curnode);
  680.     if (str[0]=='@') { /* It matches */
  681.         strcat(str,hp01); /* Add the end symbol again */
  682.        return TRUE;
  683.     }
  684.  
  685.     /* *str='\0'; * No need to strcpy(str,cp), because cp=="\0" */
  686.  
  687.     for (co=0;co<=cu; co++) {
  688.  
  689.         slen=co+cl-cu;
  690.         if (Chk4Sym(cp[slen]) || !(cp[slen])) {  /* Found symbol or end */
  691.             if (cp[slen]) { /* Not needed when we reached the end */
  692.                 c2str(cp[slen],hp03);
  693.                 hp02=strstr(cp,hp03)+1;
  694.                 strcpy(cp,hp02); /* Delete first word */
  695.                 cl=strlen(cp);
  696.             } 
  697.             if (cp[0]) {
  698.                 AddAGIfNode(cp,str,curnode);
  699.                 if (str[0]=='@') { /* It matches */
  700.                     hp[co+1]='\0'; /* Make a part string out of backup string */
  701.                     strcat(hp,str); /* Add the converted string */
  702.                     strcpy(str,hp); /* Combine both strings */
  703.                     if(hp01[0]) strcat(str,hp01); /* Add the end symbol again */
  704.                    return TRUE;
  705.                }
  706.             }
  707.       }
  708.     }
  709.     strcpy(str,hp);
  710.     return FALSE;
  711. }
  712.  
  713. /*
  714. ** Adds the nodes of a Contents file to the XRef list(s)
  715. */
  716. void AddNode2XRef(FILE *fp)
  717. {
  718.    char hzeile[256],zeile[256];
  719.    ULONG hp,co;
  720.  
  721.     while ( (fgets(zeile,256,fp)) || !(feof(fp)) ) {
  722.         if (!strcmp(zeile,"###\n")) break;
  723.     }
  724.  
  725.     while ( (fgets(zeile,256,fp)) || !(feof(fp)) ) {
  726.         if (!strcmp(zeile,"\n")) continue;
  727.         hp=(ULONG)stpblk(zeile); /* Skip leading blanks */
  728.         if (*(char *)hp==';') continue;  /* ; = comment */
  729.       linksp[l]=AllocVec(lsize,MEMF_PUBLIC|MEMF_CLEAR);
  730.       linkdp[l]=AllocVec(rsize,MEMF_PUBLIC|MEMF_CLEAR);
  731.       if (!linksp[l] || !linkdp[l]) return;
  732.         if (*(char *)hp=='\"') {
  733.             hp=(ULONG)stptok((char *)(hp+1),hzeile,rsize-2,"\""); /* Get node */
  734.             strcpy(linkdp[l],"\"");
  735.             strcat(linkdp[l],hzeile);
  736.             strcat(linkdp[l],"\"");
  737.         }
  738.         else hp=(ULONG)stptok(zeile,linkdp[l],rsize," "); /* Get node */
  739.         hp=(ULONG)stpblk((char *)++hp);
  740.         
  741.         if (DBUG) printf("hzeile=%s,hp=%s\n",hzeile,hp);
  742.  
  743.         if (*(char *)hp=='\"') {
  744.             hp=(ULONG)stptok((char *)(hp+1),hzeile,lsize-2,"\""); /* Get endnode */
  745.             strcpy(linksp[l],"\"");
  746.             strcat(linksp[l],hzeile);
  747.             strcat(linksp[l],"\"");
  748.         }
  749.         else hp=(ULONG)stptok((char *)hp,linksp[l],lsize," ");
  750.         hp=(ULONG)stpblk((char *)++hp);
  751.       
  752.         for (co=0;co<l;co++) { /* Check for double links */
  753.             if ( (!stricmp(linksp[co],linksp[l])) && (!stricmp(linkdp[co],linkdp[l]))) {
  754.                 if (linksp[l]) FreeVec(linksp[l]);
  755.                 linksp[l]=NULL;
  756.                 if (linkdp[l]) FreeVec(linkdp[l]);
  757.                 linkdp[l]=NULL;
  758.                 break;
  759.             }
  760.         }
  761.         if (co!=l) continue;
  762.         if (linksp[l] && (strlen(linksp[l])>lsmax)) lsmax=strlen(linksp[l]);
  763.         if (linkdp[l] && (strlen(linkdp[l])>ldmax)) ldmax=strlen(linkdp[l]);
  764.         linkline[l]=AllocVec(10,MEMF_PUBLIC|MEMF_CLEAR);
  765.         if (linkline[l]) strcpy(linkline[l],"0"); else return;
  766.         l++;
  767.     }
  768.  
  769. }
  770.  
  771. /*
  772. ** Create Xrefs from Xreffile into Amigaguide file
  773. */
  774. void ParseWriteXrefs(void)
  775. {
  776.     FILE *fp,*gp,*xp,*cp;
  777.     BOOL noag=FALSE,adb=FALSE;
  778.     ULONG keyword,hp;
  779.     char    cc,zeile[256],node[256],hzeile[256],final[512],tmp[256],old[256];
  780.  
  781.     fp=fopen(infile,"r");
  782.     if (!fp) {
  783.         printf("Could not open Amigaguide file for reading.\n");
  784.         CloseAll(FALSE);
  785.     }
  786.  
  787.     gp=fopen(outfile,"w");
  788.     if (!gp) {
  789.         printf("Could not open Amigaguide file for writing.\n");
  790.         if (fp) fclose(fp);
  791.         CloseAll(FALSE);
  792.     }
  793.  
  794.     xp=fopen(xreffile,"r");
  795.     if (!xp) {
  796.         printf("Could not open Xref file for reading.\n");
  797.         if (gp) fclose(gp);
  798.         if (fp) fclose(fp);
  799.         CloseAll(FALSE);
  800.     }
  801.  
  802.     ParseXref(xp); /* Read XRef file */
  803.     if (xp) fclose(xp);
  804.  
  805.    if (contfile) { /* Optional Contents file for nodes */
  806.      cp=fopen(contfile,"r");
  807.      if (!cp) {
  808.         printf("Could not open optional Contents file for reading.\n");
  809.            if (gp) fclose(gp);
  810.            if (fp) fclose(fp);
  811.            CloseAll(FALSE);
  812.        }
  813.        AddNode2XRef(cp); /* Adds the nodes to the Xrefs list(s) */
  814.        if (cp) fclose(cp);
  815.    }
  816.  
  817.     SortXref(); /* sort links for binary search */
  818.  
  819.     while ( (fgets(zeile,256,fp)) || !(feof(fp)) ) { /* Read all links */
  820.         if (!strcmp(zeile,"\n")) {
  821.             fputs(zeile,gp);
  822.             continue;
  823.         }
  824.         if (strlen(zeile)>256) { zeile[254]='\n'; zeile[255]=0; }
  825.         strcpy(hzeile,zeile);
  826.  
  827.         if (!adb) { /* Make sure we have an Amigaguide file */
  828.             keyword=(ULONG)strstr(strlwr(hzeile),DATABASE);
  829.             if (keyword) {
  830.                 adb=TRUE;
  831.                 fputs(zeile,gp);
  832.                 continue;
  833.             } else {
  834.                 if (gp) fclose(gp);
  835.                 if (fp) fclose(fp);
  836.                 printf("Not an Amigaguide Database file.\n");
  837.                 CloseAll(FALSE);
  838.             }
  839.         }
  840.  
  841.         if (keyword=(ULONG)strstr(strlwr(hzeile),REM)) {
  842.             fputs(zeile,gp);
  843.             continue;
  844.         }
  845.         if (keyword=(ULONG)strstr(strlwr(hzeile),REMARK)) {
  846.             fputs(zeile,gp);
  847.             continue;
  848.         }
  849.  
  850.         keyword=(ULONG)strstr(strlwr(hzeile),NODE);
  851.         if (keyword) { /* note node */
  852.             hp=(ULONG)stptok(zeile,hzeile,256," ");
  853.             hp=(ULONG)stpblk((char *)++hp);
  854.             if (!stricmp(hzeile,NODE)) { /* Assure @node at beginning of line */
  855.                 strcpy(node,hzeile);
  856.                 if (*(char *)hp=='\"') {
  857.                     hp=(ULONG)stptok((char *)(hp+1),hzeile,rsize-2,"\""); /* Get node */
  858.                     strcpy(node,"\"");
  859.                     strcat(node,hzeile);
  860.                     strcat(node,"\"");
  861.                 }
  862.                 else hp=(ULONG)stptok((char *)hp,node,rsize," ");
  863.                 strcpy(hzeile,node);
  864.                 strlwr(hzeile);
  865.                 if (!(stricmp(hzeile,"main")) || !(stricmp(hzeile,"\"main\"")) ) { /* Ignore main node */
  866.                     strcpy(node,"\0");
  867.                     fputs(zeile,gp);
  868.                     while ( (fgets(zeile,256,fp)) || !(feof(fp)) ) { /* Seek ENDNODE */
  869.                         fputs(zeile,gp);
  870.                         if (!strcmp(zeile,"\n")) continue;
  871.                         strcpy(hzeile,zeile);
  872.                         keyword=(ULONG)strstr(strlwr(hzeile),ENDNODE);
  873.                         if (keyword) break;
  874.                     }
  875.                     if (feof(fp)) break; /* Amigaguide contains only main node (can this happen ?!?) */
  876.                 }
  877.                 else fputs(zeile,gp);
  878.                 continue;
  879.             }
  880.         }
  881.  
  882.         if (zeile[0]=='@' && zeile[1]!='{') {            /*  }  */
  883.             fputs(zeile,gp);
  884.             continue; /* Ignore Amigaguide commands */
  885.         }
  886.  
  887.         keyword=(ULONG)zeile; /* Read Pointer: shows at which point in the line we are */
  888.         strcpy(final,"\0"); 
  889.         strcpy(old,"\0");
  890.         cc=0;
  891.         while ((*(char *)keyword)!='\n') { /* Check Line for match of AG Command, Label Match */
  892.             strcat(old,c2str((*(char *)keyword),tmp)); /* Save old string */
  893.             if (Chk4Sym((*(char *)keyword))) { /* Found Symbol */
  894.                 noag=FALSE;
  895.                 if (cc && ((*(char *)(keyword-1))=='\\')) noag=TRUE; /* fake command ? */
  896.                 if (!noag && GetAGCommand(tmp,(char **)&keyword)) { /* This is a command */
  897.                     if (strlen(old)>min) MatchAGLabel(old,node); /* Check if old string matches label links */
  898.                     old[strlen(old)-1]='\0';
  899.                     strcat(final,old); /* print AG string (old is changed now!) */
  900.                     strcpy(old,"\0"); /* Delete old strings */
  901.                     strcat(final,tmp);
  902.                     cc+=strlen(tmp);
  903.                 } else { /* test if string has min size and matches link label */
  904.                     if (strlen(old)>=min) {
  905.                         if(MatchAGLabel(old,node)) { /* Check if old string matches label links */
  906.                             strcat(final,old); /* print link label (old is changed now!) */
  907.                             strcpy(old,"\0"); /* Delete old strings */
  908.                         }
  909.                     }
  910.                 }
  911.             }
  912.             keyword++; /* Increase Read Pointer by 1 */
  913.             cc++;
  914.         }
  915.         strcat(old,"\n");
  916.         if (strlen(old)>=min) MatchAGLabel(old,node); /* Check if old string matches label links */
  917.         strcat(final,old); /* print (old) string */
  918.         fputs(final,gp);
  919.         if (DBUG) printf("final=%s",final);
  920.  
  921.     }
  922.  
  923.     if (fp) fclose(fp);
  924.     if (gp) fclose(gp);
  925.     CloseAll(TRUE);
  926. }
  927.  
  928. /*
  929. ** Create .cont File from Amigaguide for Cont
  930. */
  931. void ParseWriteMyCont(void)
  932. {
  933.     FILE *fp,*gp;
  934.     int co,cu,len;
  935.     char    hzeile[256];
  936.  
  937.     fp=fopen(infile,"r");
  938.     if (!fp) {
  939.         printf("Could not open Amigaguide file for reading.\n");
  940.         CloseAll(FALSE);
  941.     }
  942.  
  943.     gp=fopen(outfile,"w");
  944.     if (!gp) {
  945.         printf("Could not open contents file for writing.\n");
  946.         if (fp) fclose(fp);
  947.         CloseAll(FALSE);
  948.     }
  949.  
  950.     AGLoopNodes(fp,gp);
  951.  
  952.     if (fp) fclose(fp);
  953.  
  954.     fputs("###\n",gp); /* Important: Else the program asumes we have only a title */
  955.  
  956.     for (co=0;co<n;co++) { /* Write all nodes into outfile */
  957.         strcpy(hzeile,nodep[co]);
  958.        len=smax-strlen(nodep[co]);
  959.        for (cu=0;cu<len;cu++) strcat(hzeile," ");
  960.         strcat(hzeile,endnodep[co]);
  961.         hzeile[strlen(hzeile)-1]='\0';
  962.        len=dmax-strlen(endnodep[co]);
  963.        for (cu=0;cu<len;cu++) strcat(hzeile," ");
  964.         strcat(hzeile,"\"\n");
  965.         fputs(hzeile,gp);
  966.     }
  967.     fputs("\n",gp);
  968.     if (gp) fclose(gp);
  969.     CloseAll(TRUE);
  970. }
  971.  
  972. /*
  973. ** Create .xref File from Amigaguide for Xrefs
  974. */
  975. void ParseWriteMakeXrefs(void)
  976. {
  977.     FILE *fp,*gp,*cp;
  978.     int co,len,cu;
  979.     char    hzeile[256];
  980.  
  981.     fp=fopen(infile,"r");
  982.     if (!fp) {
  983.         printf("Could not open Amigaguide file for reading.\n");
  984.         CloseAll(FALSE);
  985.     }
  986.  
  987.     gp=fopen(outfile,"w");
  988.     if (!gp) {
  989.         printf("Could not open Xref file for writing.\n");
  990.         if (fp) fclose(fp);
  991.         CloseAll(FALSE);
  992.     }
  993.  
  994.     AGLoopLinks(fp,gp);
  995.  
  996.     if (fp) fclose(fp);
  997.  
  998.    if (contfile) { /* Optional Contents file for nodes */
  999.      cp=fopen(contfile,"r");
  1000.      if (!cp) {
  1001.         printf("Could not open optional Contents file for reading.\n");
  1002.            if (gp) fclose(gp);
  1003.            if (fp) fclose(fp);
  1004.            CloseAll(FALSE);
  1005.        }
  1006.        AddNode2XRef(cp); /* Adds the nodes to the Xrefs list(s) */
  1007.        if (cp) fclose(cp);
  1008.    }
  1009.  
  1010.     for (co=1;co<l;co++) { /* Write all links into outfile */
  1011.         strcpy(hzeile,linksp[co]);
  1012.         strcat(hzeile," ");
  1013.        len=lsmax-strlen(linksp[co]);
  1014.        for (cu=0;cu<len;cu++) strcat(hzeile," ");
  1015.         strcat(hzeile,linkdp[co]);
  1016.         strcat(hzeile," ");
  1017.        len=ldmax-strlen(linkdp[co]);
  1018.        for (cu=0;cu<len;cu++) strcat(hzeile," ");
  1019.         strcat(hzeile,linkline[co]);
  1020.         strcat(hzeile,"\n");
  1021.         fputs(hzeile,gp);
  1022.     }
  1023.     fputs("\n",gp);
  1024.     if (gp) fclose(gp);
  1025.     CloseAll(TRUE);
  1026. }
  1027.  
  1028. void main(int argc, char **argv)
  1029. {
  1030.     BOOL cont=FALSE,ind=FALSE,xr=FALSE,myxr=FALSE,mycont=FALSE;
  1031.     struct          WBStartup *startup=NULL;
  1032.  
  1033.    if (argc==0) startup = (struct WBStartup *)argv;
  1034.     if (!startup) printf("%s\n",Copyright);
  1035.    if (argc==2 && !strcmp(argv[1],"?")) {
  1036.       printf("Usage: %s %s\n",argv[0],TEMPLATE);
  1037.       exit(TRUE);
  1038.    }
  1039.     
  1040.    if (!(myrda=ReadArgs(TEMPLATE, result, NULL))) {
  1041.       if (!startup) puts("Could not parse arguments.");
  1042.       CloseAll(FALSE);
  1043.    }
  1044.  
  1045.     if (!result[OPT_FROM]) {
  1046.         printf("Required argument missing.\n");
  1047.         CloseAll(FALSE);
  1048.     } else infile=(char *)result[OPT_FROM];
  1049.  
  1050.     if (!result[OPT_TO]) {
  1051.         printf("Required argument missing.\n");
  1052.         CloseAll(FALSE);
  1053.     } else outfile=(char *)result[OPT_TO];
  1054.  
  1055.     if (!stricmp(infile,outfile)) {
  1056.         printf("infile and outfile must differ!\n");
  1057.         CloseAll(FALSE);
  1058.     }
  1059.  
  1060.     if (result[OPT_CONTENTS]) cont=TRUE;
  1061.     if (result[OPT_INDEX]) ind=TRUE;
  1062.     if (result[OPT_XREF]) xr=TRUE;
  1063.     if (result[OPT_MAKEXREF]) myxr=TRUE;
  1064.     if (result[OPT_MAKECONT]) mycont=TRUE;    
  1065.    if (result[OPT_INNERLINKS]) ilnk=TRUE;
  1066.  
  1067.    if (result[OPT_LABELSIZE]) lsize=(UBYTE)result[OPT_LABELSIZE];
  1068.    else lsize=60;
  1069.    
  1070.    if (result[OPT_XREFSIZE]) rsize=(UBYTE)result[OPT_LABELSIZE];
  1071.    else rsize=40;
  1072.    
  1073.     if (!cont && !ind && !xr && !mycont && !myxr) cont=TRUE;  /* Contents creating is default */
  1074.    else if ( (cont&&ind) || (cont&&xr) || (cont&&myxr) || (cont&&mycont) || (ind&&xr) || (ind&&myxr) || (ind&&mycont) || (xr&&myxr) || (xr&&mycont) || (mycont&&myxr) ) {
  1075.        printf("Specify only one of CONTENTS/S,INDEX/S,XREF/S,MAKECONT/S,MAKEXREF/S Options.\n");
  1076.        CloseAll(FALSE);
  1077.    }
  1078.  
  1079.    if (cont) {
  1080.         contfile=(char *)result[OPT_CONTFILE];
  1081.        if (!contfile) {
  1082.            contfile=AllocVec(30,MEMF_PUBLIC|MEMF_CLEAR);
  1083.             if (contfile) strcpy(contfile,"s:GT.cont");
  1084.         }
  1085.     }
  1086.  
  1087.     if (xr || ind) {
  1088.         xreffile=(char *)result[OPT_XREFFILE];
  1089.         if (!xreffile) {
  1090.             xreffile=AllocVec(30,MEMF_PUBLIC|MEMF_CLEAR);
  1091.             if (xreffile) strcpy(xreffile,"s:GT.xref"); /* Default XRef File */
  1092.         }
  1093.         contfile=(char *)result[OPT_CONTFILE]; /* Optional contfile */
  1094.     }
  1095.  
  1096.    if (cont) ParseWriteContents();  /* Create Contents from Amigaguide file and add it */
  1097.    if (ind) ParseWriteIndex();      /* Create Index from Amigaguide file and add it    */
  1098.    if (xr) ParseWriteXrefs();       /* Create Xrefs from Xreffile into Amigaguide file */
  1099.    if (mycont) ParseWriteMyCont();  /* Create .cont File from Amigaguide for Cont      */
  1100.    if (myxr) {
  1101.       contfile=(char *)result[OPT_CONTFILE]; /* Optional contfile */
  1102.       ParseWriteMakeXrefs(); /* Create .xref File from Amigaguide for Xrefs     */
  1103.    }
  1104. }
  1105.