void parse_item(void) { if (!gInItems) { fprintf(stderr, "\\item found outside an items environment\n"); print_page_and_filename(); print_next_ten_tokens(); jump(); } curr_node->type = Item; get_token(); if (token.type == Lsquarebrace) { /* I should parse the optional argument */ curr_node->next = alloc_node(); curr_node = curr_node->next; curr_node->type = Description; curr_node->next = alloc_node(); curr_node = curr_node->next; gInOptional++; parse_HyperDoc(); gInOptional--; curr_node->type = Enddescription; if (token.type != Rsquarebrace) { fprintf(stderr, "(HyperDoc) Optional arguments must end with ].\n"); print_next_ten_tokens(); print_page_and_filename(); jump(); } } else { unget_token(); } }
void parse_begin_items(void) { TextNode *bi = curr_node; /* * This procedure parses a begin item. It sets the current * node and sees if there is an optional argument for the itemspace */ bi->type = token.type; get_token(); if (token.type == Lsquarebrace) { bi->data.node = alloc_node(); curr_node = bi->data.node; gInOptional++; parse_HyperDoc(); gInOptional--; curr_node->type = Enddescription; if (token.type != Rsquarebrace) { fprintf(stderr, "(HyperDoc) Optional arguments must end with ].\n"); print_next_ten_tokens(); print_page_and_filename(); jump(); } curr_node = bi; } else unget_token(); gInItems++; }
void parse_pastebutton(void) { PasteNode *paste; TextNode *pb; /* * this routine parse a \pastebutton expression. The syntax is * \pastebutton{name} */ pb = curr_node; pb->type = openaxiom_Pastebutton_token; /* first thing I should do is get the name */ get_token(); if (token.type != openaxiom_Lbrace_token) { fprintf(stderr, "(HyperDoc) \\pastebutton needs a name\n"); print_page_and_filename(); print_next_ten_tokens(); jump(); } pb->data.text = alloc_string(get_input_string()); /* * now I should see if the paste area has already been parsed, and if not * I should create a spot in the hash table for it */ paste = (PasteNode *) hash_find(gWindow->fPasteHashTable, pb->data.text); if (paste == 0) { paste = alloc_paste_node(pb->data.text); hash_insert(gWindow->fPasteHashTable,(char *) paste, paste->name); } else if (paste->hasbutton) { fprintf(stderr, "(HyperDoc) Tried to redefine paste area %s\n", paste->name); print_page_and_filename(); /* jump(); */ } paste->hasbutton = 1; /* Now we need to parse the HyperDoc and for the displayed text */ get_token(); if (token.type != openaxiom_Lbrace_token) { fprintf(stderr, "(HyperDoc) \\pastebutton was expecting a { \n"); print_page_and_filename(); print_next_ten_tokens(); jump(); } pb->next = alloc_node(); curr_node = pb->next; parse_HyperDoc(); curr_node->type = openaxiom_Endpastebutton_token; /* once that is done I need only make the window for this link */ pb->link = make_paste_window(paste); }
void parse_button(void) { TextNode *link_node, *save_node; gInButton++; if (gParserMode == SimpleMode) { curr_node->type = Noop; fprintf(stderr, "Parser Error token %s unexpected\n", token_table[token.type]); longjmp(jmpbuf, 1); } /* fill the node */ curr_node->type = token.type; curr_node->space = token.id[-1]; /* the save the current node for creating the link and stuff */ link_node = curr_node; /* then parse the label */ curr_node->next = alloc_node(); curr_node = curr_node->next; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endbutton; /* now try to get the argument node */ save_node = curr_node; get_expected_token(Lbrace); save_node->data.node = alloc_node(); curr_node = save_node->data.node; parse_HyperDoc(); curr_node->type = Endarg; /* * buffer[0] = '\0'; print_to_string(arg_node, buffer + 1); */ link_node->link = make_link_window(save_node->data.node, link_node->type, 0); curr_node = save_node; gInButton--; }
void parse_mbox(void) { curr_node->type = token.type; curr_node->space = token.id[-1]; curr_node->width = -1; curr_node->next = alloc_node(); curr_node = curr_node->next; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endbox; }
static void parse_hasreturnto(void) { TextNode *hrt = curr_node, *arg_node = alloc_node(); curr_node->type = Hasreturnto; curr_node = arg_node; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endarg; hrt->data.node = arg_node; curr_node = hrt; }
void parse_free(void) { TextNode *free_node = curr_node; curr_node->type = token.type; curr_node->space = token.id[-1]; curr_node->width = -1; curr_node->data.node = alloc_node(); curr_node = curr_node->data.node; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endarg; curr_node = free_node; }
void parse_command(void) { TextNode *link_node, *save_node, *arg_node; gInButton++; if (gParserMode == SimpleMode) { curr_node->type = Noop; fprintf(stderr, "Parser Error token %s unexpected\n", token_table[token.type]); longjmp(jmpbuf, 1); } gStringValueOk = 1; /* set the values for the current node */ curr_node->type = token.type; curr_node->space = token.id[-1]; /* now parse for the label */ link_node = curr_node; curr_node->next = alloc_node(); curr_node = curr_node->next; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endbutton; save_node = curr_node; arg_node = alloc_node(); curr_node = arg_node; get_expected_token(Lbrace); parse_HyperDoc(); curr_node->type = Endarg; link_node->link = make_link_window(arg_node, link_node->type, 0); gStringValueOk = 0; curr_node = save_node; gInButton--; }
void parse_table(void) { TextNode *tn = curr_node; if (gParserMode != AllMode) { curr_node->type = Noop; fprintf(stderr, "Parser Error token %s unexpected\n", token_table[token.type]); longjmp(jmpbuf, 1); } curr_node->type = Table; get_expected_token(Lbrace); curr_node->next = alloc_node(); curr_node = curr_node->next; get_token(); if (token.type == Lbrace) { while (token.type != Rbrace) { curr_node->type = Tableitem; curr_node->next = alloc_node(); curr_node = curr_node->next; parse_HyperDoc(); curr_node->type = Endtableitem; curr_node->next = alloc_node(); curr_node = curr_node->next; get_token(); } curr_node->type = Endtable; } else { /* a patch for SG for empty tables */ if (token.type != Rbrace) { token_name(token.type); fprintf(stderr, "Unexpected Token %s found while parsing a table\n", ebuffer); print_page_and_filename(); jump(); } tn->type = Noop; tn->next = NULL; free(curr_node); curr_node = tn; } }
void parse_centerline(void) { curr_node->type = token.type; curr_node->space = token.id[-1]; curr_node->width = -1; curr_node->next = alloc_node(); curr_node = curr_node->next; get_expected_token(Lbrace); parse_HyperDoc(); if (token.type != Rbrace) { curr_node->type = Noop; fprintf(stderr, "(HyperdDoc) \\centerline was expecting a }\n"); print_page_and_filename(); print_next_ten_tokens(); longjmp(jmpbuf, 1); } curr_node->type = Endcenter; }
void parse_spadcommand(TextNode *spad_node) { /*TextNode *node = NULL;*/ example_number++; gInButton++; spad_node->type = token.type; spad_node->space = token.id[-1]; get_expected_token(Lbrace); cur_spadcom = curr_node; spad_node->next = alloc_node(); curr_node = spad_node->next; parse_HyperDoc(); curr_node->type = Endspadcommand; cur_spadcom = NULL; spad_node->link = make_link_window(spad_node->next, spad_node->type, 1); gInButton--; }
void parse_ifcond(void) { TextNode *ifnode = curr_node; TextNode *endif; TextNode *condnode; /* * parse a conditional. At first I am just going to parse if * <hypertext> fi */ if (gInIf) { curr_node->type = Noop; fprintf(stderr, "\\if found within \\if \n"); longjmp(jmpbuf, 1); fprintf(stderr, "Longjump failed, Exiting\n"); exit(-1); } gInIf++; curr_node->type = Ifcond; curr_node->space = token.id[-1]; curr_node->data.ifnode = alloc_ifnode(); /* Now get the cond node I hope */ condnode = curr_node->data.ifnode->cond = alloc_node(); curr_node = condnode; parse_condnode(); endif = alloc_node(); endif->type = Endif; ifnode->data.ifnode->thennode = alloc_node(); curr_node = ifnode->data.ifnode->thennode; parse_HyperDoc(); if (token.type == Fi) { curr_node->type = Fi; curr_node->next = endif; ifnode->data.ifnode->elsenode = endif; } else if (token.type == Else) { /* first finish up the then part */ curr_node->type = Fi; curr_node->next = endif; /* the go and parse the else part */ ifnode->data.ifnode->elsenode = alloc_node(); curr_node = ifnode->data.ifnode->elsenode; parse_HyperDoc(); if (token.type != Fi) { token_name(token.type); curr_node->type = Noop; fprintf(stderr, "Expected a \\fi not a %s", ebuffer); longjmp(jmpbuf, 1); fprintf(stderr, "Longjump failed, Exiting\n"); exit(-1); } curr_node->type = Fi; curr_node->next = endif; } else { curr_node->type = Noop; token_name(token.type); fprintf(stderr, "Expected a \\fi not a %s", ebuffer); longjmp(jmpbuf, 1); fprintf(stderr, "Longjump failed, Exiting\n"); exit(-1); } ifnode->next = ifnode->data.ifnode->thennode; ifnode->width = -1; /* A flag for compute if extents */ curr_node = endif; gInIf--; }
void parse_paste(void) { TextNode *pn = curr_node; PasteNode *paste; int where; if (gParserRegion != Scrolling) { fprintf(stderr, "(HyperDoc) Paste areas are only allowed in the scrolling area:"); print_page_and_filename(); jump(); } gInPaste++; /* now I need to get the name */ get_token(); if (token.type != openaxiom_Lbrace_token) { fprintf(stderr, "(HyperDoc) A paste area needs a name:\n"); print_next_ten_tokens(); print_page_and_filename(); jump(); } pn->data.text = alloc_string(get_input_string()); pn->type = openaxiom_Paste_token; /* * now see if there is already an entry in the hash_table for this thing, * if not create it and put it there. */ paste = (PasteNode *) hash_find(gWindow->fPasteHashTable, pn->data.text); if (paste == 0) { paste = alloc_paste_node(pn->data.text); hash_insert(gWindow->fPasteHashTable, (char *)paste, paste->name); } else if (paste->haspaste) { fprintf(stderr, "(HyperDoc) Tried to redefine paste area %s\n", paste->name); print_page_and_filename(); /* jump(); */ } paste->haspaste = 1; paste->paste_item = current_item(); get_token(); if (token.type == openaxiom_Lsquarebrace_token) { /* user wishes to specify a where to send the command */ where = get_where(); if (where == -1) { paste->where = -1; fprintf(stderr, "(HyperDoc) \\begin{paste} was expecting [lisp|unix|ht]\n"); print_next_ten_tokens(); print_page_and_filename(); jump(); } else paste->where = where; get_token(); } else paste->where = openaxiom_FromFile_input; /* now try to get the command argument or page name */ if (token.type != openaxiom_Lbrace_token) { paste->where = 0; fprintf(stderr, "(HyperDoc) \\begin{paste} was expecting an argument\n"); print_next_ten_tokens(); print_page_and_filename(); jump(); } paste->arg_node = alloc_node(); curr_node = paste->arg_node; parse_HyperDoc(); curr_node->type = openaxiom_Endarg_token; gWindow->fDisplayedWindow = gWindow->fScrollWindow; /* Now try to find the displaying text */ pn->next = alloc_node(); curr_node = pn->next; parse_HyperDoc(); curr_node->type = openaxiom_Endpaste_token; paste->end_node = curr_node; paste->begin_node = pn; gInPaste--; }
HyperDocPage * parse_patch(PasteNode *paste) { TextNode *new_paste; TextNode *end_node; TextNode *begin_node; TextNode *arg_node; TextNode *old; TextNode *next_node; InputItem *paste_item = paste->paste_item; int where = paste->where; GroupItem *g = paste->group; ItemStack *is = paste->item_stack; PatchStore *patch; char *patch_name; int ret_value = 1; /* prepare to throw away the current paste node */ end_node = paste->end_node; next_node = end_node->next; begin_node = paste->begin_node; arg_node = paste->arg_node; old = begin_node->next; /* now read the new stuff and add it in between all this stuff */ switch (where) { case openaxiom_FromFile_input: patch_name = print_to_string(arg_node); patch = (PatchStore *) hash_find(gWindow->fPatchHashTable, patch_name); if (!patch) { fprintf(stderr, "(HyperDoc) Unknown patch name %s\n", patch_name); BeepAtTheUser(); return 0; } if (!patch->loaded) load_patch(patch); input_type = openaxiom_FromString_input; input_string = patch->string; break; case openaxiom_FromSpadSocket_input: input_type = openaxiom_FromSpadSocket_input; ret_value = issue_serverpaste(arg_node); if (ret_value < 0) { paste->where = where; paste->end_node = end_node; paste->arg_node = arg_node; paste->group = g; paste->item_stack = is; paste->haspaste = 1; return 0; } break; case openaxiom_FromUnixFD_input: input_type = openaxiom_FromUnixFD_input; issue_unixpaste(arg_node); break; default: fprintf(stderr, "(HyperDoc) \\parsebutton error: Unknown where\n"); exit(-1); break; } paste->where = 0; paste->end_node = paste->arg_node = paste->begin_node = 0; paste->group = 0; paste->item_stack = 0; paste->haspaste = 0; paste->paste_item = 0; /* set the jump buffer in case it is needed */ if (setjmp(jmpbuf)) { /*** OOOPS, an error occurred ****/ fprintf(stderr, "(HyperDoc) Had an error parsing a patch: Goodbye!\n"); exit(-1); } end_node->next = 0; free_node(old, 1); init_parse_patch(gWindow->page); init_paste_item(paste_item); get_token(); if (token.type != openaxiom_Patch_token) { fprintf(stderr, "(HyperDoc) Pastebutton %s was expecting a patch\n", paste->name); jump(); } if (input_type == openaxiom_FromString_input) { get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer); print_page_and_filename(); jump(); } get_token(); if (token.type != openaxiom_Word_token) { token_name(token.type); fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer); print_page_and_filename(); jump(); } get_token(); if (token.type != openaxiom_Rbrace_token) { token_name(token.type); fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer); print_page_and_filename(); jump(); } } new_paste = alloc_node(); curr_node = new_paste; parse_HyperDoc(); /* Once I am back, I need only reallign all the text structures */ curr_node->type = openaxiom_Noop_token; curr_node->next = next_node; begin_node->next = new_paste; begin_node->type = openaxiom_Noop_token; free(begin_node->data.text); begin_node->data.text = 0; gWindow->fDisplayedWindow = gWindow->fScrollWindow; repaste_item(); paste_page(begin_node); /* so now I should just be able to disappear */ return gWindow->page; }