void parse_env(TextNode *node) { char *env; char buff[256]; char *buff_pntr = &buff[1]; int noEnv = 0; get_expected_token(Lbrace); get_expected_token(Word); env = getenv(token.id); if (env == NULL) { /** The environment variable was not found **/ fprintf(stderr, "(HyperDoc) Warning: environment variable \'%s\' was not found.\n", token.id); env = halloc(1, "string"); env[0] = '\0'; noEnv = 1; } buff[0] = token.id[-1]; strcpy(buff_pntr, env); if (noEnv) free(env); node->data.text = alloc_string(buff_pntr); node->type = Word; get_expected_token(Rbrace); }
/* Parse the input string statement * */ void parse_inputstring(void) { TextNode *input_node = curr_node; char *name; InputItem *item; int size; char *default_value; gStringValueOk = 0; /* first get the name */ input_node->type = token.type; get_expected_token(openaxiom_Lbrace_token); name = get_input_string(); input_node->data.text = alloc_string(name); /* now get the width */ get_expected_token(openaxiom_Lbrace_token); get_expected_token(openaxiom_Word_token); get_expected_token(openaxiom_Rbrace_token); size = atoi(token.id); if (size < 0) { fprintf(stderr, "Illegal size in Input string\n"); longjmp(jmpbuf, 1); } /* get the default value */ get_expected_token(openaxiom_Lbrace_token); default_value = get_input_string(); /** now I need to malloc space for the input stuff **/ item = (InputItem *) halloc(sizeof(InputItem), "InputItem"); /* Now store all the string info */ item->name = (char *) halloc((strlen(input_node->data.text) + 1) * (sizeof(char)),"parse_inputstring"); strcpy(item->name, input_node->data.text); item->size = size; item->entered = 0; item->next = NULL; initialize_default(item, default_value); /** Now that I have all the structures made, lets make the window, and add the item to the list ****/ input_node->link = make_input_window(item); if (!make_input_file) item->win = input_node->link->win; /* TTT */ insert_item(item); gStringValueOk = 1; curr_node = input_node; return ; }
void parse_newcond(void) { char label[256]; get_expected_token(Lbrace); get_expected_token(Unkeyword); strcpy(label, token.id); get_expected_token(Rbrace); insert_cond(label, "0"); curr_node->type = Noop; }
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; }
static void load_patch(PatchStore *patch) { long start_fpos; int size = 0; int limsize; char *trace; save_scanner_state(); cfile = find_fp(patch->fpos); init_scanner(); /** First thing I should do is make sure that the name is correct ***/ start_fpos = fpos; get_expected_token(openaxiom_Patch_token); get_expected_token(openaxiom_Lbrace_token); get_expected_token(openaxiom_Word_token); if (strcmp(token.id, patch->name)) { /** WOW, Somehow I had the location of the wrong macro **/ fprintf(stderr, "(HyperDoc) Expected patch name %s: got instead %s in load_patch\n", patch->name, token.id); jump(); } get_expected_token(openaxiom_Rbrace_token); scan_HyperDoc(); fseek(cfile, patch->fpos.pos + start_fpos, 0); limsize = fpos - start_fpos + 1; patch->string = (char *) halloc((limsize + 1) * sizeof(char), "Patch String"); for (size = 1, trace = patch->string; size < limsize; size++) *trace++ = getc(cfile); *trace = '\0'; patch->loaded = 1; restore_scanner_state(); }
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_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_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_setcond(void) { char label[256], cond[256]; get_expected_token(Lbrace); get_expected_token(Cond); strcpy(label, token.id); get_expected_token(Rbrace); get_expected_token(Lbrace); get_expected_token(Word); strcpy(cond, token.id); get_expected_token(Rbrace); change_cond(label, cond); curr_node->type = Noop; }
void parse_input_pix(void) { TextNode *pixnode; char *filename; pixnode = curr_node; pixnode->type = token.type; pixnode->space = token.id[-1]; pixnode->width = -1; get_expected_token(Lbrace); filename = get_input_string(); pixnode->data.text = alloc_string(filename); curr_node = pixnode; if (pixnode->type == Inputimage) { char f[256]; char *p; if ((gXDisplay && DisplayPlanes(gXDisplay, gXScreenNumber) == 1) || gSwitch_to_mono ==1) { pixnode->type = Inputbitmap; strcpy(f, pixnode->data.text); strcat(f, ".bm"); p=pixnode->data.text; pixnode->data.text = alloc_string(f); free(p); } else { pixnode->type = Inputpixmap; strcpy(f, pixnode->data.text); #ifdef OLD strcat(f, ".pm"); #endif strcat(f, ".xpm"); p=pixnode->data.text; pixnode->data.text = alloc_string(f); free(p); } } }
void parse_value2(void) { TextNode *value_node, *ocn = curr_node; char *s; curr_node->type = token.type; curr_node->space = token.id[-1]; value_node = alloc_node(); value_node->type = Word; curr_node->data.node = value_node; get_expected_token(Lbrace); s = get_input_string(); if (!is_number(s)) { fprintf(stderr, "Parser Error: parse for value was expecting a numeric value\n"); strcpy(value_node->data.text, "1"); } else { value_node->data.text = alloc_string(s); } curr_node = ocn; }
static char * load_macro(MacroStore *macro) { int ret_val; long start_fpos; int size = 0; char *trace; char *macro_buff; save_scanner_state(); cfile = find_fp(macro->fpos); init_scanner(); /** First thing I should do is make sure that the name is correct ***/ get_expected_token(NewCommand); get_expected_token(Lbrace); get_expected_token(Macro); if (strcmp(token.id, macro->name)) { /** WOW, Somehow I had the location of the wrong macro **/ fprintf(stderr, "Expected macro name %s got insted %s in load_macro\n", macro->name, token.id); longjmp(jmpbuf, 1); } get_expected_token(Rbrace); /** Next I should check to see if I have any parameters **/ get_token(); if (token.type == Lsquarebrace) { /** The person is telling me the number of macros he is going to use **/ get_expected_token(Word); if (!number(token.id)) { fprintf(stderr, "load_macro: Expected A Value Instead Got %s\n", token.id); longjmp(jmpbuf, 1); } /** if it is a number, then I should store it in the parameter number member of the macro structure **/ macro->number_parameters = atoi(token.id); #ifdef DEBUG fprintf(stderr, "The number of parameters is %d\n", macro->number_parameters); #endif get_expected_token(Rsquarebrace); get_token(); } else macro->number_parameters = 0; /*** Now I should be able to check the token, and insure that I have read a leftbrace, then the string will follow ****/ if (token.type != Lbrace) { /** The macro is not in a group, uh oh **/ fprintf(stderr, "load_macro:Expected a Left Brace got type %d\n", token.type); longjmp(jmpbuf, 1); } start_fpos = fpos; scan_HyperDoc(); ret_val = fseek(cfile, macro->fpos.pos + start_fpos, 0); size = fpos - start_fpos; macro_buff = (char *) halloc((size + 1) * sizeof(char), "Macro_buf"); for (size = 0, trace = macro_buff; size < fpos - (start_fpos) - 1; size++) *trace++ = getc(cfile); *trace = '\0'; macro->loaded = 1; restore_scanner_state(); return macro_buff; }
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; }
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; }