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(); } }
static void add_box_to_rb_list(char *name,InputBox *box) { RadioBoxes *trace = gPageBeingParsed->radio_boxes; InputBox *list; /*int found = 0;*/ while (trace != NULL && strcmp(trace->name, name)) trace = trace->next; if (!trace) { fprintf(stderr, "Tried to add a radio box to a non-existent group %s\n", name); print_page_and_filename(); jump(); } /* now add the box to the list */ list = trace->boxes; box->next = list; trace->boxes = box; if (box->picked && check_others(box->next)) { fprintf(stderr, "Only a single radio button can be picked\n"); print_page_and_filename(); box->picked = 0; } box->selected = trace->selected; box->unselected = trace->unselected; box->rbs = trace; return; }
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_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_mitem(void) { if (!gInItems) { fprintf(stderr, "\\mitem found outside an items environment\n"); print_page_and_filename(); print_next_ten_tokens(); jump(); } curr_node->type = Mitem; }
void parse_help(void) { curr_node->type = Noop; get_token(); if (token.type != Lbrace) { token_name(token.type); fprintf(stderr, "\\helppage was expecting a { and not a %s\n", ebuffer); print_page_and_filename(); jump(); } /* before we clobber this pointer we better free the contents (cf. alloc_page) */ free(gPageBeingParsed->helppage); gPageBeingParsed->helppage = alloc_string(get_input_string()); if (token.type != Rbrace) { token_name(token.type); fprintf(stderr, "\\helppage was expecting a } and not a %s\n", ebuffer); print_page_and_filename(); jump(); } }
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 htperror(char *msg, int errno) { char obuff[4096]; /* The first thing I do is create the error message */ if (errno <= Numerrors) { sprintf(obuff, "%s:%s\n", msg, errmess[errno]); } else { sprintf(obuff, "%s:\n", msg); fprintf(stderr, "Unknown error type %d\n", errno); } fprintf(stderr, "%s", obuff); print_page_and_filename(); print_next_ten_tokens(); }
void insert_cond(char *label, char *cond) { CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label); /* * This routine creates a new cond node and inserts it into the * current cond table */ if (condnode) { fprintf(stderr, "Error: \\%s is declared twice \n", label); print_page_and_filename(); jump(); } condnode = alloc_condnode(); condnode->label = halloc(strlen(label) + 1, "Condnode->label"); condnode->cond = halloc(strlen(cond) + 1, "Condnode->cond"); strcpy(condnode->label, label); strcpy(condnode->cond, cond); hash_insert(gWindow->fCondHashTable, (char *) condnode, condnode->label); }
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; }
void parse_radioboxes(void) { TextNode *return_node = curr_node; RadioBoxes *newrb; char *fname; /* I really don't need this node, it just sets up some parsing stuff */ return_node->type = openaxiom_Noop_token; newrb = alloc_rbs(); get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "\\radioboxes was expecting a name not %s\n", ebuffer); print_page_and_filename(); jump(); } newrb->name = alloc_string(get_input_string()); /* quick search for the name in the current list */ if (already_there(newrb->name)) { free(newrb->name); free(newrb); fprintf(stderr, "Tried to redefine radioboxes %s\n", newrb->name); print_page_and_filename(); jump(); } /* now I have to get the selected and unslected bitmaps */ get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "\\radioboxes was expecting a name not %s\n", ebuffer); print_page_and_filename(); jump(); } fname = get_input_string(); if (!make_input_file) newrb->selected = insert_image_struct(fname); get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "\\radioboxes was expecting a name not %s\n", ebuffer); print_page_and_filename(); jump(); } fname = get_input_string(); if (!make_input_file) { newrb->unselected = insert_image_struct(fname); newrb->height = max(newrb->selected->height, newrb->unselected->height); newrb->width = max(newrb->selected->width, newrb->unselected->width); /* now add the thing to the current list of radio boxes */ } newrb->next = gPageBeingParsed->radio_boxes; gPageBeingParsed->radio_boxes = newrb; curr_node = return_node; return; }
void parse_radiobox(void) { InputBox *box; char *name; char *group_name; short int picked = 0; TextNode *input_box = curr_node; gStringValueOk = 0; /* set the type and space fields */ input_box->type = openaxiom_Radiobox_token; input_box->space = token.id[-1]; /* IS it selected? */ get_token(); if (token.type == openaxiom_Lsquarebrace_token) { get_expected_token(openaxiom_Word_token); if (!is_number(token.id)) { fprintf(stderr, "parse_simple_box: Expected a value not %s\n", token.id); print_page_and_filename(); jump(); } else if (!strcmp(token.id, "1")) picked = 1; else if (!strcmp(token.id, "0")) picked = 0; else { fprintf(stderr, "parse_simple_box: Unexpected Value %s\n", token.id); print_page_and_filename(); jump(); } get_expected_token(openaxiom_Rsquarebrace_token); get_token(); } if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer); print_page_and_filename(); jump(); } name = get_input_string(); if (gPageBeingParsed->box_hash && hash_find(gPageBeingParsed->box_hash, name)) { fprintf(stderr, "Input box name %s is not unique \n", name); print_page_and_filename(); jump(); } box = alloc_inputbox(); box->name = alloc_string(name); input_box->data.text = alloc_string(name); box->picked = picked; /* Now what I need to do is get the group name */ get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer); print_page_and_filename(); jump(); } group_name = get_input_string(); /* * Now call a routine which searches the radio box list for the current * group name, and if found adds this box to it */ add_box_to_rb_list(group_name, box); input_box->width = box->rbs->width; input_box->height = box->rbs->height; /* Make the window and stuff */ input_box->link = make_box_window(box, openaxiom_Radiobox_token); if (!make_input_file) box->win = input_box->link->win; /* TTT */ /* Now add the box to the box_has table for this window */ if (gPageBeingParsed->box_hash == NULL) { gPageBeingParsed->box_hash = (HashTable *) halloc(sizeof(HashTable), "Box Hash"); hash_init( gPageBeingParsed->box_hash, BoxHashSize, (EqualFunction) string_equal, (HashcodeFunction) string_hash); } hash_insert(gPageBeingParsed->box_hash, (char *)box, box->name); /* reset the curr_node and then return */ curr_node = input_box; gStringValueOk = 1; return; }
void parse_simplebox(void) { InputBox *box; char *name; short int picked = 0; char *filename; TextNode *input_box = curr_node; gStringValueOk = 0; /* set the type and space fields */ input_box->type = openaxiom_SimpleBox_token; input_box->space = token.id[-1]; /* IS it selected? */ get_token(); if (token.type == openaxiom_Lsquarebrace_token) { get_expected_token(openaxiom_Word_token); if (!is_number(token.id)) { fprintf(stderr, "parse_simple_box: Expected a value not %s\n", token.id); print_page_and_filename(); jump(); } else if (!strcmp(token.id, "1")) picked = 1; else if (!strcmp(token.id, "0")) picked = 0; else { fprintf(stderr, "parse_simple_box: Unexpected Value %s\n", token.id); print_page_and_filename(); jump(); } get_expected_token(openaxiom_Rsquarebrace_token); get_token(); } if (token.type != openaxiom_Lbrace_token) { token_name(token.type); fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer); print_page_and_filename(); jump(); } name = get_input_string(); if (gPageBeingParsed->box_hash && hash_find(gPageBeingParsed->box_hash, name)) { fprintf(stderr, "Input box name %s is not unique \n", name); print_page_and_filename(); jump(); } box = alloc_inputbox(); box->name = alloc_string(name); input_box->data.text = alloc_string(name); box->picked = picked; /* Get the filename for the selected and unselected bitmaps */ get_expected_token(openaxiom_Lbrace_token); filename = get_input_string(); if (!make_input_file) box->selected = insert_image_struct(filename); get_expected_token(openaxiom_Lbrace_token); filename = get_input_string(); if (!make_input_file) { box->unselected = insert_image_struct(filename); /* set the width and height for the maximaum of the two */ input_box->height = max(box->selected->height, box->unselected->height); input_box->width = max(box->selected->width, box->unselected->width); /* Make the window and stuff */ input_box->link = make_box_window(box, openaxiom_SimpleBox_token); box->win = input_box->link->win; /* Now add the box to the box_has table for this window */ if (gPageBeingParsed->box_hash == NULL) { gPageBeingParsed->box_hash = (HashTable *) halloc(sizeof(HashTable), "Box Hash"); hash_init( gPageBeingParsed->box_hash, BoxHashSize, (EqualFunction) string_equal, (HashcodeFunction) string_hash); } hash_insert(gPageBeingParsed->box_hash, (char *)box, box->name); } /* reset the curr_node and then return */ curr_node = input_box; gStringValueOk = 1; return; }