home *** CD-ROM | disk | FTP | other *** search
- #include <proto/exec.h>
-
- /* SAS/C V5.10b is broken, so I can't use clib/alib_protos.h */
- void NewList(struct List *);
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
- /************************************************************************/
-
- #include "Includes.h"
- #include "Autodocs.h"
- #include "File.h"
- #include "FormatNode.h"
- #include "AdditionalDocs.h"
-
- /************************************************************************/
-
- static struct AutodocModuleNode *ExecModuleNode;
-
- /************************************************************************/
-
- struct AVLTree AutodocFileTree =
- {NULL, (int (*)(struct AVLNode *, struct AVLNode *)) nodecasecmp};
- struct AVLTree AutodocModuleTree =
- {NULL, (int (*)(struct AVLNode *, struct AVLNode *)) nodecmp};
- struct AVLTree AutodocNodeTree =
- {NULL, (int (*)(struct AVLNode *, struct AVLNode *)) nodecmp};
-
- /************************************************************************/
- /* */
- /* Create a new AutodocNodeNode */
- /* */
- /************************************************************************/
-
- struct AutodocNodeNode *
- CreateAutodocNode (char *Name, struct AutodocModuleNode *AutodocModuleNode)
-
- {
- struct AutodocNode *AutodocNode;
- struct AutodocNodeNode *AutodocNodeNode;
- struct AutodocNodeNode **Current;
-
- if (!(AutodocNode = (struct AutodocNode *) SearchNode (&AutodocNodeTree, Name)))
- {
- AutodocNode = (struct AutodocNode *) CreateNode (Name, sizeof (*AutodocNode));
- AutodocNode->Entries = NULL;
- AutodocNode->Function = TRUE;
- AVL_InsertNode (&AutodocNodeTree, &AutodocNode->AnyNode.AVLNode);
- }
- AutodocNodeNode = xmalloc (sizeof (*AutodocNodeNode));
- AutodocNodeNode->AnyNode.Name = AutodocNode->AnyNode.Name;
- AutodocNodeNode->AutodocModuleNode = AutodocModuleNode;
- AutodocNodeNode->AutodocNode = AutodocNode;
-
- Current = &AutodocNode->Entries;
- if (AutodocModuleNode != ExecModuleNode)
- {
- if (*Current && (*Current)->AutodocModuleNode == ExecModuleNode)
- {
- Current = &(*Current)->Next;
- }
- while (*Current &&
- strcasecmp ((*Current)->AutodocModuleNode->AnyNode.Name,
- AutodocNodeNode->AutodocModuleNode->AnyNode.Name) < 0)
- {
- Current = &(*Current)->Next;
- }
- }
- AutodocNodeNode->Next = *Current;
- *Current = AutodocNodeNode;
-
- return AutodocNodeNode;
- }
-
- /************************************************************************/
- /* */
- /* Find the "TABLE OF CONTENTS" line */
- /* */
- /************************************************************************/
-
- static void
- FindTOC (void)
-
- {
- struct Word *Word;
-
- Word = ReadWord (TRUE);
- if (!strcasecmp (Word->Word, "TABLE"))
- {
- FreeWord (Word);
- Word = ReadWord (TRUE);
- if (!Word->Newline && !strcasecmp (Word->Word, "OF"))
- {
- FreeWord (Word);
- Word = ReadWord (TRUE);
- if (!Word->Newline && !strcasecmp (Word->Word, "CONTENTS"))
- {
- FreeWord (Word);
- return;
- }
- }
- }
- fprintf (stderr, "%s, line %lu: expected \x22TABLE OF CONTENTS\x22\n", ReadFilename, Word->Line);
- CloseAll (RETURN_ERROR);
- }
-
- /************************************************************************/
- /* */
- /* Read and process a table of contents entry */
- /* FALSE if no entry was found */
- /* */
- /************************************************************************/
-
- static int
- ReadTOCLine (struct AutodocFileNode *AutodocFileNode)
-
- {
- struct Word *Word;
-
- Word = ReadWord (FALSE);
- if (strcmp ("\x0c", Word->Word))
- {
- char *Module;
- int Information;
- struct AutodocModuleNode *AutodocModuleNode;
-
- UnreadWord (Word);
-
- Module = ReadUntil ("/");
- FreeWord (ReadWord (FALSE)); /* kill the terminator */
-
- /* get node name */
- Information = FALSE;
- Word = ReadWord (FALSE);
- while (Word->Word[0] == '-')
- {
- Information = TRUE;
- FreeWord (Word);
- Word = ReadWord (FALSE);
- }
-
- if (!(AutodocModuleNode = (struct AutodocModuleNode *) SearchNode (&AutodocModuleTree, Module)))
- {
- struct AutodocModuleNode **CurrentNode;
-
- AutodocModuleNode = xmalloc (sizeof (*AutodocModuleNode));
- AutodocModuleNode->AnyNode.Name = Module;
- AutodocModuleNode->AutodocFileNode = AutodocFileNode;
- AutodocModuleNode->InfoNodes = NULL;
- AutodocModuleNode->Nodes.Root = NULL;
- AutodocModuleNode->Nodes.CompareNodes = AutodocNodeTree.CompareNodes;
- for (CurrentNode = &AutodocFileNode->Modules; *CurrentNode; CurrentNode = &(*CurrentNode)->Next)
- ;
- *CurrentNode = AutodocModuleNode;
- AutodocModuleNode->Next = NULL;
- AVL_InsertNode (&AutodocModuleTree, (struct AVLNode *) AutodocModuleNode);
- if (!strcmp (Module, "exec.library"))
- {
- ExecModuleNode = AutodocModuleNode;
- }
- }
- else
- {
- free (Module);
- }
-
- if (Information)
- {
- struct AutodocInfoNode *AutodocInfoNode;
- struct AutodocInfoNode **CurrentNode;
-
- AutodocInfoNode = xmalloc (sizeof (*AutodocInfoNode));
- AutodocInfoNode->Next = NULL;
- AutodocInfoNode->Name = xstrdup (Word->Word);
- AutodocInfoNode->Found = FALSE;
- for (CurrentNode = &AutodocModuleNode->InfoNodes;
- *CurrentNode;
- CurrentNode = &(*CurrentNode)->Next)
- ;
- *CurrentNode = AutodocInfoNode;
- }
- else
- {
- struct AutodocNodeNode *AutodocNodeNode;
-
- AutodocNodeNode = CreateAutodocNode (Word->Word, AutodocModuleNode);
- if (!strcmp (AutodocModuleNode->AnyNode.Name, "SAD"))
- {
- AutodocNodeNode->AutodocNode->Function = FALSE;
- }
- else
- {
- struct IncludeItemNode *IncludeItemNode;
-
- AutodocNodeNode->AutodocNode->Function =
- (!(IncludeItemNode = (struct IncludeItemNode *)
- SearchNode (&DefinesTree, AutodocNodeNode->AnyNode.Name)) ||
- IncludeItemNode->Function);
- }
-
- AutodocNodeNode->RealNode = AutodocNodeNode;
- AutodocNodeNode->Found = FALSE;
- if (AVL_InsertNode (&AutodocModuleNode->Nodes, &AutodocNodeNode->AnyNode.AVLNode))
- {
- fprintf (stderr, "%s, %lu: duplicate definition of \x22%s/%s\x22\n",
- ReadFilename, Word->Line,
- AutodocModuleNode->AnyNode.Name, AutodocNodeNode->AnyNode.Name);
- CloseAll (RETURN_ERROR);
- }
- }
- FreeWord (Word);
- Word = ReadWord (FALSE);
- while (!Word->Newline)
- {
- FreeWord (Word);
- Word = ReadWord (FALSE);
- }
- UnreadWord (Word);
- return TRUE;
- }
- FreeWord(Word);
- return FALSE;
- }
-
- /************************************************************************/
- /* */
- /* Get the next label for TOC output */
- /* Parameters: AutodocFileNode==NULL means AutodocModuleNode is valid */
- /* */
- /************************************************************************/
-
- struct FormatParameters
- {
- struct AutodocFileNode *AutodocFileNode;
- struct AutodocModuleNode *AutodocModuleNode;
-
- struct AutodocNodeNode *AutodocNodeNode;
- struct AVLStateInfo StateInfo;
- };
-
- static char *
- AutodocNextLabel (char *PrevLabel, void *Parameters)
-
- {
- struct FormatParameters *Params;
- char *Label;
- char *t;
-
- Params = (struct FormatParameters *) Parameters;
-
- if (!PrevLabel)
- {
- if (Params->AutodocFileNode)
- {
- Params->AutodocModuleNode = Params->AutodocFileNode->Modules;
- }
- AVL_InitTraversal (&Params->AutodocModuleNode->Nodes, &Params->StateInfo);
- }
- else
- {
- if (!PrevLabel[0])
- {
- AVL_InitTraversal (&Params->AutodocModuleNode->Nodes, &Params->StateInfo);
- }
- free (PrevLabel);
- }
-
- if (!(Params->AutodocNodeNode = (struct AutodocNodeNode *) AVL_InOrder (&Params->StateInfo)))
- {
- if (Params->AutodocFileNode)
- {
- if ((Params->AutodocModuleNode = Params->AutodocModuleNode->Next))
- {
- return xstrdup ("");
- }
- }
- return NULL;
- }
-
- Label = xmalloc (strlen (Params->AutodocNodeNode->AnyNode.Name) +
- (Params->AutodocNodeNode->AutodocNode->Function ? 3 : 1));
- t = stpcpy (Label, Params->AutodocNodeNode->AnyNode.Name);
- if (Params->AutodocNodeNode->AutodocNode->Function)
- strcpy (t, "()");
- return Label;
- }
-
- /************************************************************************/
- /* */
- /* Output the link information for current label */
- /* */
- /************************************************************************/
-
- static void
- AutodocPrintLink (void *Parameters)
-
- {
- WPrintf ("\x22%s%s",
- ((struct FormatParameters *) Parameters)->AutodocNodeNode->RealNode->AnyNode.Name,
- Arguments.Parentheses ? "()\x22" : "\x22");
- }
-
- /************************************************************************/
- /* */
- /* Output the table of contents */
- /* */
- /************************************************************************/
-
- static void
- OutputTOC (struct AutodocFileNode *AutodocFileNode)
-
- {
- struct FormatParameters FormatParameters;
- struct AutodocModuleNode *AutodocModuleNode;
- int *ColWidth;
-
- WPrintf ("\n@NODE MAIN \x22%s\x22\n", AutodocFileNode->AnyNode.Name);
- if (GlobalTOCFilename)
- {
- WPrintf("@TOC \x22%s/MAIN\x22\n",GlobalTOCFilename);
- }
-
- FormatParameters.AutodocFileNode = AutodocFileNode;
- ColWidth = FormatNode (AutodocNextLabel, &FormatParameters);
-
- FormatParameters.AutodocFileNode = NULL;
- AutodocModuleNode = AutodocFileNode->Modules;
- while (AutodocModuleNode)
- {
- struct AutodocInfoNode *AutodocInfoNode;
-
- WPrintf("\n");
- WHeadline (AutodocModuleNode->AnyNode.Name);
- WPrintf ("\n");
-
- for (AutodocInfoNode = AutodocModuleNode->InfoNodes;
- AutodocInfoNode;
- AutodocInfoNode = AutodocInfoNode->Next)
- {
- WPrintf ("@{\x22%s\x22 LINK \x22%s\x22}\n",
- AutodocInfoNode->Name,
- AutodocInfoNode->Name);
- }
- if (AutodocModuleNode->InfoNodes)
- WPrintf ("\n");
-
- FormatParameters.AutodocModuleNode = AutodocModuleNode;
- PrintNode (AutodocNextLabel, AutodocPrintLink, &FormatParameters, ColWidth);
-
- if ((AutodocModuleNode = AutodocModuleNode->Next))
- WPrintf ("\n\n");
- }
- free (ColWidth);
- WPrintf ("\n@ENDNODE\n");
- }
-
- /************************************************************************/
- /* */
- /* Check if the next stuff read is () (no newlines). */
- /* If yes, echo it. If no, do nothing. */
- /* This function is used to get the '()' into a button (looks better). */
- /* */
- /************************************************************************/
-
- static void
- DoParentheses (void)
-
- {
- struct Word *Word;
-
- Word = ReadWord (TRUE);
- if (Word->Word[0] == '(' && !Word->Newline)
- {
- struct Word *NextWord;
-
- NextWord = ReadWord (TRUE);
- if (NextWord->Word[0] == ')' && !NextWord->Newline)
- {
- WriteWord (Word);
- WriteWord (NextWord);
- FreeWord (Word);
- FreeWord (NextWord);
- return;
- }
- UnreadWord (NextWord);
- }
- UnreadWord (Word);
- }
-
- /************************************************************************/
- /* */
- /* Check if the word references a module. */
- /* If yes, make a link and return TRUE. If no, do nothing and return */
- /* FALSE. */
- /* Handles all cases, including module/functionname */
- /* */
- /************************************************************************/
-
- static int
- DoModule (struct Word *Word, struct AutodocNodeNode *CurrentAutodocNode)
-
- {
- struct AutodocModuleNode *AutodocModuleNode;
-
- if (Word->Length > 5 && (AutodocModuleNode = (struct AutodocModuleNode *) SearchNode (&AutodocModuleTree, Word->Word)))
- {
- struct Word *NextWord;
- struct Word *NodeName; /* is only used when initialized */
-
- WriteWhitespace (Word);
-
- NextWord = ReadWord (TRUE);
- if (NextWord->Word[0] == '/')
- {
- struct AutodocNodeNode *AutodocNodeNode;
-
- NodeName = ReadWord (TRUE);
- if ((AutodocNodeNode = (struct AutodocNodeNode *) SearchNode (&AutodocModuleNode->Nodes, NodeName->Word)))
- {
- if (AutodocNodeNode->RealNode != CurrentAutodocNode)
- {
- if (NextWord->Newline || NodeName->Newline)
- {
- WriteWord (Word);
- WriteWord (NextWord);
- WriteWhitespace (NodeName);
- WPrintf ("@{\x22");
- }
- else
- {
- WPrintf ("@{\x22");
- WriteWord (Word);
- WriteWord (NextWord);
- }
- WriteWord (NodeName);
-
- DoParentheses ();
-
- WPrintf ("\x22 LINK \x22");
- if (!(CurrentAutodocNode &&
- CurrentAutodocNode->AutodocModuleNode->AutodocFileNode == AutodocModuleNode->AutodocFileNode))
- {
- WPrintf ("%s/", AutodocModuleNode->AutodocFileNode->LinkName);
- }
- WPrintf ("%s%s\x22}",
- AutodocNodeNode->RealNode->AnyNode.Name,
- (Arguments.Parentheses && AutodocNodeNode->AutodocNode->Function) ? "()" : "");
- }
- else
- {
- WriteWord (Word);
- WriteWord (NextWord);
- WriteWord (NodeName);
- }
- FreeWord (NodeName);
- FreeWord (NextWord);
- return TRUE;
- }
- }
- else
- {
- UnreadWord (NextWord);
- NextWord = NULL;
- }
- if (!CurrentAutodocNode ||
- CurrentAutodocNode->AutodocModuleNode != AutodocModuleNode)
- {
- WriteWhitespace (Word);
- WPrintf ("@{\x22%s\x22 LINK \x22%s/MAIN\x22}",
- Word->Word,
- AutodocModuleNode->AutodocFileNode->LinkName);
- }
- else
- {
- WriteWord (Word);
- }
- if (NextWord)
- {
- WriteWord (NextWord);
- WriteWord (NodeName);
- FreeWord (NextWord);
- FreeWord (NodeName);
- }
- return TRUE;
- }
- return FALSE;
- }
-
- /************************************************************************/
- /* */
- /* Check if the word references an header file. */
- /* If yes, make a link and return TRUE. If no, do nothing and return */
- /* FALSE. */
- /* */
- /************************************************************************/
-
- static int
- DoHeader (struct Word *Word, struct IncludeFileNode *CurrentIncludeFile)
-
- {
- if (Word->Length > 1)
- {
- struct MinList WordList;
- char *Filename;
-
- NewList ((struct List *) &WordList);
- AddTail ((struct List *) &WordList, (struct Node *) &Word->Node);
- Filename = xstrdup (Word->Word);
-
- while (Word)
- {
- Word = ReadWord (TRUE);
- AddTail ((struct List *) &WordList, (struct Node *) &Word->Node);
- if (!Word->Whitespace && !Word->Newline && Word->Word[0] == '/')
- {
- Word = ReadWord (TRUE);
- AddTail ((struct List *) &WordList, (struct Node *) &Word->Node);
- if (!Word->Whitespace && !Word->Newline && Word->Length > 1)
- {
- char *NewFilename;
- struct IncludeFileNode *IncludeFileNode;
-
- NewFilename = xmalloc (strlen (Filename) + 1 + Word->Length + 1);
- stpcpy (stpcpy (stpcpy (NewFilename, Filename), "/"), Word->Word);
- free (Filename);
- Filename = NewFilename;
-
- if ((IncludeFileNode = (struct IncludeFileNode *) SearchNode (&IncludeFileTree, Filename)))
- {
- WriteWhitespace ((struct Word *) WordList.mlh_Head);
- WPrintf ("@{\x22%s\x22 LINK \x22%s/File\x22}", Filename, IncludeFileNode->LinkName);
- Word = (struct Word *) RemTail ((struct List *) &WordList);
- while (!IsListEmpty ((struct List *) &WordList))
- {
- FreeWord (Word);
- Word = (struct Word *) RemTail ((struct List *) &WordList);
- }
- free (Filename);
- return TRUE;
- }
- }
- else
- {
- Word = NULL;
- }
- }
- else
- {
- Word = NULL;
- }
- }
-
- free (Filename);
- Word = (struct Word *) RemTail ((struct List *) &WordList);
- while (!IsListEmpty ((struct List *) &WordList))
- {
- UnreadWord (Word);
- Word = (struct Word *) RemTail ((struct List *) &WordList);
- }
- }
- return FALSE;
- }
-
- /************************************************************************/
- /* */
- /* Make a link to an autodoc entry. */
- /* */
- /************************************************************************/
-
- static void
- WriteAutodocLink (struct Word *Word,
- struct AutodocNodeNode *AutodocNodeNode,
- struct AutodocNodeNode *CurrentAutodocNode)
-
- {
- AutodocNodeNode = AutodocNodeNode->RealNode;
-
- WriteWhitespace (Word);
- WPrintf ("@{\x22");
- WriteWord (Word);
- DoParentheses ();
- WPrintf ("\x22 LINK \x22");
- if (!CurrentAutodocNode ||
- CurrentAutodocNode->AutodocModuleNode->AutodocFileNode != AutodocNodeNode->AutodocModuleNode->AutodocFileNode)
- {
- WPrintf ("%s/", AutodocNodeNode->AutodocModuleNode->AutodocFileNode->LinkName);
- }
- WPrintf ("%s%s\x22}",
- AutodocNodeNode->RealNode->AnyNode.Name,
- (Arguments.Parentheses && AutodocNodeNode->AutodocNode->Function) ? "()" : "");
- }
-
- /************************************************************************/
- /* */
- /* Check if the word references an autodoc node. */
- /* If yes, make a link and return TRUE. If no, do nothing and return */
- /* FALSE. */
- /* This handles unqualified autodocs. */
- /* */
- /************************************************************************/
-
- int
- DoAutodoc (struct Word *Word, struct AutodocNodeNode *CurrentAutodocNode)
-
- {
- struct AutodocNode *AutodocNode;
-
- if ((AutodocNode = (struct AutodocNode *) SearchNode (&AutodocNodeTree, Word->Word)))
- {
- struct AutodocNodeNode *AutodocNodeNode;
-
- /* unambiguous link? */
- if (!AutodocNode->Entries->Next)
- {
- if (AutodocNode->Entries->RealNode != CurrentAutodocNode)
- {
- WriteAutodocLink (Word, AutodocNode->Entries, CurrentAutodocNode);
- return TRUE;
- }
- return FALSE;
- }
-
- /* possible link into the same module? */
- if (CurrentAutodocNode)
- {
- for (AutodocNodeNode = AutodocNode->Entries;
- AutodocNodeNode;
- AutodocNodeNode = AutodocNodeNode->Next)
- {
- if (AutodocNodeNode->AutodocModuleNode == CurrentAutodocNode->AutodocModuleNode)
- {
- if (AutodocNodeNode->RealNode != CurrentAutodocNode)
- {
- WriteAutodocLink (Word, AutodocNodeNode, CurrentAutodocNode);
- return TRUE;
- }
- else
- {
- break;
- }
- }
- }
- }
-
- /* possible link into exec.library? */
- if (AutodocNode->Entries->AutodocModuleNode == ExecModuleNode)
- {
- if (AutodocNode->Entries->RealNode != CurrentAutodocNode)
- {
- WriteAutodocLink (Word, AutodocNode->Entries, CurrentAutodocNode);
- return TRUE;
- }
- return FALSE;
- }
-
- /* if we are linking to the name we are currently working on */
- /* (i.e. CurrentAutodocNode IN AutodocNode->Entries), link to */
- /* the next entry in the list. */
- if (CurrentAutodocNode && CurrentAutodocNode->AutodocNode == AutodocNode)
- {
- if (CurrentAutodocNode->Next)
- {
- WriteAutodocLink (Word, CurrentAutodocNode->Next, CurrentAutodocNode);
- }
- else
- {
- WriteIdentifier (Word, NULL);
- }
- return TRUE;
- }
-
- /* link to the first entry of the list */
- WriteAutodocLink (Word, AutodocNode->Entries, CurrentAutodocNode);
- return TRUE;
- }
- return FALSE;
- }
-
- /************************************************************************/
- /* */
- /* Look at the "current line" to see if it is really a headline */
- /* */
- /************************************************************************/
-
- static int IsHeadline(void)
-
- {
- struct MinList WordList;
- struct Word *Word;
- int Headline;
-
- NewList((struct List *)&WordList);
- Word=ReadWord(TRUE);
-
- if ((Headline=Word->Length && Word->Newline && Word->Whitespace<=4))
- {
- /* Another bug in the MUI autodocs... */
- if (!strcmp(Word->Word,"SEE_ALSO"))
- {
- struct Word *NewWord;
-
- Word->Length=3;
- Word->Word[3]='\0';
-
- NewWord=xmalloc(sizeof(*NewWord)+4);
- NewWord->Line=Word->Line;
- NewWord->Special=Word->Special;
- NewWord->Length=4;
- NewWord->Whitespace=1;
- NewWord->Newline=0;
- strcpy(NewWord->Word,"ALSO");
-
- UnreadWord(NewWord);
- }
-
- do
- {
- size_t i;
-
- for (i=0; i<Word->Length && (Headline=isupper(Word->Word[i])); i++)
- ;
- AddTail((struct List *)&WordList,(struct Node *)&Word->Node);
- Word=ReadWord(TRUE);
- }
- while (Headline && Word->Length && !Word->Newline);
- }
- do
- {
- UnreadWord(Word);
- }
- while ((Word=(struct Word *)RemTail((struct List *)&WordList)));
- return Headline;
- }
-
- /************************************************************************/
- /* */
- /* Check if the current line should be appended to the previous line. */
- /* */
- /************************************************************************/
-
- static int AppendLine(void)
-
- {
- struct MinList WordList;
- struct Word *Word;
- size_t LineLength;
- int RC;
-
- NewList((struct List *)&WordList);
- LineLength=0;
- RC=FALSE;
- Word=ReadWord(TRUE);
- do
- {
- LineLength+=Word->Whitespace+Word->Length;
- AddTail((struct List *)&WordList,(struct Node *)&Word->Node);
- Word=ReadWord(TRUE);
- }
- while (!Word->Newline && Word->Length);
- UnreadWord(Word);
- if (Word->Whitespace>4 || IsHeadline())
- {
- if (LineLength<4)
- {
- ((struct Word *)WordList.mlh_Head)->Whitespace=1;
- ((struct Word *)WordList.mlh_Head)->Newline=0;
- RC=TRUE;
- }
- }
- while ((Word=(struct Word *)RemTail((struct List *)&WordList)))
- {
- UnreadWord(Word);
- }
- return RC;
- }
-
- /************************************************************************/
- /* */
- /* Indent all lines until the next "headline" is found. */
- /* */
- /************************************************************************/
-
- static void ReindentParagraph(void)
-
- {
- struct MinList WordList;
- struct Word *Word;
- int MinSpaces;
-
- NewList((struct List *)&WordList);
-
- /* step 1: determine the minimum indention of the paragraph ("how far left is the leftmost line?") */
- MinSpaces=8;
- while (!IsHeadline())
- {
- Word=ReadWord(TRUE);
- if (Word->Newline && Word->Length && Word->Word[0]!=0x0c && Word->Whitespace<MinSpaces)
- {
- MinSpaces=Word->Whitespace;
- }
- do
- {
- AddTail((struct List *)&WordList,(struct Node *)&Word->Node);
- Word=ReadWord(TRUE);
- }
- while (!Word->Newline && Word->Length);
- UnreadWord(Word);
- }
-
- /* now, indent the whole thing by 8-MinSpaces spaces. */
- while ((Word=(struct Word *)RemTail((struct List *)&WordList)))
- {
- if (Word->Newline)
- {
- Word->Whitespace+=(8-MinSpaces);
- }
- UnreadWord(Word);
- }
- }
-
- /************************************************************************/
- /* */
- /* Convert the node text */
- /* If Comment==TRUE, then this is really a comment in in an include */
- /* file. This implies a slightly different handling. */
- /* Node is either an AutodocNodeNode or an IncludeFileNode */
- /* */
- /************************************************************************/
-
- void
- ConvertNodeText (int Comment, void *Node)
-
- {
- enum
- {
- GENERIC = 0, SEE_ALSO = 1
- }
- Paragraph;
-
- Paragraph = GENERIC;
- while (TRUE)
- {
- struct Word *Word;
-
- Word = ReadWord (TRUE);
- if (Word->Length)
- {
- /* check for end of text */
- if (Comment)
- {
- if (Word->Word[0] == '*')
- {
- struct Word *NextWord;
-
- NextWord = ReadWord (TRUE);
- if (!NextWord->Newline && !NextWord->Whitespace && NextWord->Word[0] == '/')
- {
- WriteWord (Word);
- WriteWord (NextWord);
- FreeWord (Word);
- FreeWord (NextWord);
-
- /* now, check whether the next thing is another comment. */
- /* We treat this as one comment. */
- Word = ReadWord (TRUE);
- if (Word->Word[0] == '/')
- {
- NextWord = ReadWord (TRUE);
- if (!NextWord->Newline && !NextWord->Whitespace && NextWord->Word[0] == '*')
- {
- WriteWord (Word);
- WriteWord (NextWord);
- FreeWord (Word);
- FreeWord (NextWord);
- continue;
- }
- UnreadWord (NextWord);
- }
- UnreadWord (Word);
- break;
- }
- else
- {
- UnreadWord (NextWord);
- }
- }
- }
- else
- {
- if (Word->Word[0] == '\x0c')
- {
- FreeWord (Word);
- break;
- }
- }
-
- if (!Comment && Word->Newline && Word->Whitespace <= 4 && Node &&
- strcmp(((struct AutodocNodeNode *)Node)->AutodocModuleNode->AnyNode.Name,"SAD"))
- {
- UnreadWord(Word);
- if (IsHeadline())
- {
- Word=ReadWord(TRUE);
- if (!strcasecmp (Word->Word, "SEE"))
- {
- Paragraph = SEE_ALSO;
- }
- else
- {
- Paragraph = GENERIC;
- }
- if (*Arguments.Version >= 39)
- {
- WPrintf ("@{b}");
- }
- do
- {
- WriteWord(Word);
- FreeWord(Word);
- Word=ReadWord(TRUE);
- }
- while (Word->Length && !Word->Newline);
- UnreadWord(Word);
- if (*Arguments.Version >= 39)
- {
- WPrintf ("@{ub}");
- }
- }
- else
- {
- if (!AppendLine())
- {
- ReindentParagraph();
- }
- }
- }
- else if (!strcmp (Word->Word, "struct") ||
- !strcmp (Word->Word, "union"))
- {
- struct Word *StructUnionTag;
- struct IncludeItemNode *IncludeItemNode;
-
- StructUnionTag = ReadWord (FALSE);
- if ((IncludeItemNode = (struct IncludeItemNode *)
- SearchNode (Word->Word[0] == 'u' ? &UnionTree : &StructureTree, StructUnionTag->Word)))
- {
- WriteWhitespace (Word);
- if (!StructUnionTag->Newline)
- {
- WPrintf ("@{\x22");
- WriteWord (Word);
- }
- else
- {
- WriteWord (Word);
- WriteWhitespace (StructUnionTag);
- WPrintf ("@{\x22");
- }
- WriteWord (StructUnionTag);
- WPrintf ("\x22 LINK \x22%s/File\x22 %lu}",
- IncludeItemNode->Entries->IncludeFileNode->LinkName,
- IncludeItemNode->Entries->Line);
- }
- else
- {
- WriteWord (Word);
- WriteWord (StructUnionTag);
- }
- FreeWord (Word);
- FreeWord (StructUnionTag);
- }
-
- else if (Word->Length > 2)
- {
- if (!Word->Special && Paragraph != SEE_ALSO)
- {
- struct Word *NextWord;
-
- NextWord = ReadWord (TRUE);
- UnreadWord (NextWord);
- if (NextWord->Word[0] == '(')
- {
- if (!DoAutodoc (Word, Comment ? NULL : Node))
- {
- WriteWord (Word);
- }
- FreeWord (Word);
- continue;
- }
- if (DoHeader (Word, Comment ? Node : NULL))
- {
- FreeWord (Word);
- continue;
- }
- }
- else
- /* Word->Special == TRUE or SEE_ALSO */
- {
- if (!DoAutodoc (Word, Comment ? NULL : Node) &&
- !DoModule (Word, Comment ? NULL : Node) &&
- !DoHeader (Word, Comment ? Node : NULL))
- {
- WriteIdentifier (Word, Comment ? Node : NULL);
- }
- FreeWord (Word);
- continue;
- }
- WriteWord (Word);
- FreeWord (Word);
- }
-
- else
- {
- /* echo it normally */
- if (!DoModule (Word, Comment ? NULL : Node) &&
- !DoHeader (Word, Comment ? Node : NULL))
- {
- WriteWord (Word);
- }
- FreeWord (Word);
- }
- }
- else
- {
- /* end of file reached */
- FreeWord(Word);
- break;
- }
- }
- }
-
- /************************************************************************/
- /* */
- /* Convert an autodoc node */
- /* Return FALSE for no more nodes */
- /* */
- /************************************************************************/
-
- static int
- ConvertNode (struct AutodocFileNode *AutodocFileNode)
-
- {
- struct AutodocModuleNode *AutodocModuleNode;
- struct AutodocNodeNode *AutodocNodeNode;
- int Information;
- struct Word *Module;
- struct Word *Word;
- struct Word *NodeName;
-
- /* get module name ("exec.library") */
- Module = ReadWord (TRUE);
- if (!Module->Length)
- {
- FreeWord(Module);
- return FALSE;
- }
-
- Word=ReadWord (FALSE);
- if (Word->Word[0]!='/')
- {
- fprintf(stderr,"%s, line %lu: expected '/'.\n",ReadFilename,Word->Line);
- CloseAll(RETURN_ERROR);
- }
- FreeWord(Word);
-
- if (!(AutodocModuleNode = (struct AutodocModuleNode *) SearchNode (&AutodocModuleTree, Module->Word)))
- {
- fprintf (stderr, "%s, line %lu: module \x22%s\x22 not found in table of contents\n",
- ReadFilename, Module->Line, Module->Word);
- CloseAll (RETURN_ERROR);
- }
- FreeWord(Module);
-
- NodeName = ReadWord (FALSE);
- Word=ReadWord(FALSE);
- while (!Word->Newline && Word->Word[0] != '/')
- {
- FreeWord (Word);
- Word = ReadWord (FALSE);
- }
- if (Word->Newline)
- {
- UnreadWord(Word);
- Word = NodeName;
- }
- else
- {
- FreeWord (Word);
- FreeWord (NodeName);
- Word=ReadWord(FALSE);
- }
-
- Information = FALSE;
- while (Word->Word[0] == '-')
- {
- Information = TRUE;
- FreeWord (Word);
- Word = ReadWord (FALSE);
- }
-
- if (Information)
- {
- struct AutodocInfoNode *AutodocInfoNode;
-
- for (AutodocInfoNode = AutodocModuleNode->InfoNodes;
- AutodocInfoNode && strcmp (AutodocInfoNode->Name, Word->Word);
- AutodocInfoNode = AutodocInfoNode->Next)
- ;
- if (!AutodocInfoNode)
- {
- int RC;
-
- fprintf (stderr, "%s, line %lu: info-node \x22%s/%s\x22 not found in table of contents\n",
- ReadFilename, Word->Line, AutodocModuleNode->AnyNode.Name, Word->Word);
- SetRC (RETURN_WARN);
- while (Word->Length && Word->Word[0] != 0x0c)
- {
- FreeWord (Word);
- Word = ReadWord (TRUE);
- }
- RC = Word->Length;
- FreeWord (Word);
- return RC;
- }
- AutodocInfoNode->Found = TRUE;
- AutodocNodeNode = NULL;
- WPrintf ("@NODE \x22%s\x22 \x22%s/%s (information)\x22\n",
- AutodocInfoNode->Name,
- AutodocModuleNode->AnyNode.Name,
- AutodocInfoNode->Name);
- }
- else
- {
- /* !Information */
- NarratorBugFixed:
- if (!(AutodocNodeNode = (struct AutodocNodeNode *) SearchNode (&AutodocModuleNode->Nodes, Word->Word)))
- {
- int RC;
-
- /* hack: check for the famous narrator.doc bug */
- if (!strcasecmp (AutodocModuleNode->AnyNode.Name, "narrator.device") &&
- !strcmp (Word->Word, "CMD_Read"))
- {
- if (Pass2)
- {
- fprintf (stderr, "%s",
- "Hey! I just encountered the narrator.doc (CMD_Read) bug! It's still there!\n"
- "But I'm a very smart program, so of course I know how to deal with it.\n");
- }
- strcpy (Word->Word, "CMD_READ");
- goto NarratorBugFixed;
- }
- fprintf (stderr, "%s, line %lu: \x22%s/%s\x22 not found in table of contents\n",
- ReadFilename, Word->Line, AutodocModuleNode->AnyNode.Name, Word->Word);
- SetRC (RETURN_WARN);
- while (Word->Length && Word->Word[0] != 0x0c)
- {
- FreeWord (Word);
- Word = ReadWord (TRUE);
- }
- RC = Word->Length;
- FreeWord (Word);
- return RC;
- }
- AutodocNodeNode->Found = TRUE;
- WPrintf ("@NODE \x22%s%s\x22 \x22%s/%s%s\x22\n",
- AutodocNodeNode->AnyNode.Name,
- (AutodocNodeNode->AutodocNode->Function && Arguments.Parentheses) ? "()" : "",
- AutodocModuleNode->AnyNode.Name,
- AutodocNodeNode->AnyNode.Name,
- AutodocNodeNode->AutodocNode->Function ? "()" : "");
- }
-
- FreeWord (Word);
- Word = ReadWord (FALSE);
- while (!Word->Newline)
- {
- FreeWord (Word);
- Word = ReadWord (FALSE);
- }
- UnreadWord (Word);
-
- if (Pass2)
- {
- ConvertNodeText (FALSE, AutodocNodeNode);
- WPrintf ("\n\n@ENDNODE\n");
-
- return TRUE;
- }
- else
- {
- int SynopsisDone;
- int NodeCount;
- struct AVLStateInfo StateInfo;
-
- AVL_InitTraversal(&AutodocModuleNode->Nodes,&StateInfo);
- for (NodeCount=0; NodeCount<2 && AVL_InOrder(&StateInfo); NodeCount++)
- ;
-
- SynopsisDone = (NodeCount<2) || (AutodocNodeNode && !AutodocNodeNode->AutodocNode->Function);
- while (TRUE)
- {
- Word = ReadWord (TRUE);
- if (!Word->Length)
- {
- FreeWord (Word);
- return FALSE;
- }
- if (Word->Word[0] == 0x0c)
- {
- FreeWord (Word);
- return TRUE;
- }
- if (SynopsisDone)
- {
- FreeWord (Word);
- return ReadSkip () == 0x0c;
- }
- if (Word->Newline && Word->Whitespace < 5 && !strcmp ("SYNOPSIS", Word->Word))
- {
- while (TRUE)
- {
- FreeWord (Word);
- Word = ReadWord (TRUE);
- if (!Word->Length || Word->Word[0] == 0x0c)
- {
- break;
- }
- if (Word->Newline && Word->Whitespace < 5)
- {
- break;
- }
- if (Word->Length > 2)
- {
- struct Word *NextWord;
-
- NextWord = ReadWord (TRUE);
- if (NextWord->Word[0] == '(')
- {
- int NestCount;
-
- NestCount = 1;
- while (NestCount)
- {
- FreeWord (NextWord);
- NextWord = ReadWord (FALSE);
- if (NextWord->Word[0] == '(')
- NestCount++;
- else if (NextWord->Word[0] == ')')
- NestCount--;
- }
- FreeWord (NextWord);
- if (strcmp (Word->Word, AutodocNodeNode->AnyNode.Name) &&
- !SearchNode (&AutodocModuleNode->Nodes, Word->Word))
- {
- struct AutodocNodeNode *VarAutodocNodeNode;
-
- VarAutodocNodeNode = CreateAutodocNode (Word->Word, AutodocModuleNode);
-
- VarAutodocNodeNode->RealNode = AutodocNodeNode;
- VarAutodocNodeNode->Found = TRUE;
-
- AVL_InsertNode (&AutodocModuleNode->Nodes,
- &VarAutodocNodeNode->AnyNode.AVLNode);
- }
- }
- else
- {
- UnreadWord (NextWord);
- }
- }
- }
- UnreadWord (Word);
- SynopsisDone = TRUE;
- }
- else
- {
- FreeWord (Word);
- }
- }
- }
- /* not reached */
- }
-
- /************************************************************************/
- /* */
- /* Skip the table of contents */
- /* */
- /************************************************************************/
-
- static void
- SkipTOC (void)
-
- {
- struct Word *Word;
- int Done;
-
- do
- {
- Word=ReadWord(FALSE);
- Done=(Word->Word[0]==0x0c);
- FreeWord(Word);
- }
- while (!Done);
- }
-
- /************************************************************************/
- /* */
- /* Process a single autodoc file, first pass */
- /* */
- /************************************************************************/
-
- void
- ProcessAutodocFile1 (char *Filename)
-
- {
- struct AutodocFileNode *AutodocFileNode;
-
- ROpen (AUTODOCDIR, Filename);
- WOpen (HYPERAUTODOCDIR, Filename);
-
- AutodocFileNode = (struct AutodocFileNode *) CreateNode (Filename, sizeof (*AutodocFileNode));
- AutodocFileNode->LinkName = xstrdup (Arguments.FullPath ? WriteFilename : Filename);
- AutodocFileNode->LinkName[strlen (AutodocFileNode->LinkName) - 4] = '\0';
- AutodocFileNode->Modules = NULL;
- AVL_InsertNode (&AutodocFileTree, &AutodocFileNode->AnyNode.AVLNode);
-
- FindTOC ();
- while (ReadTOCLine (AutodocFileNode))
- ;
-
- while (ConvertNode (AutodocFileNode))
- ;
-
- WClose ();
- RClose ();
- }
-
- /************************************************************************/
- /* */
- /* Process a single autodoc file, second pass */
- /* */
- /************************************************************************/
-
- void
- ProcessAutodocFile2 (struct AutodocFileNode *AutodocFileNode)
-
- {
- printf ("Converting %s\n", AutodocFileNode->AnyNode.Name);
-
- ROpen (AUTODOCDIR, AutodocFileNode->AnyNode.Name);
- WOpen (HYPERAUTODOCDIR, AutodocFileNode->LinkName);
-
- WriteHeader (AutodocFileNode->LinkName, ReadFilename);
-
- OutputTOC (AutodocFileNode);
- SkipTOC ();
-
- while (ConvertNode (AutodocFileNode))
- ;
-
- RClose ();
- WClose ();
- }
-