static void print_token(struct parser_tables *tables, int state, value tok) { value v; #if defined(__FreeBSD__) && defined(_KERNEL) char buf[16]; #endif if (Is_long(tok)) { __fprintf(stderr, "State %d: read token %s\n", state, token_name(tables->names_const, Int_val(tok))); } else { __fprintf(stderr, "State %d: read token %s(", state, token_name(tables->names_block, Tag_val(tok))); v = Field(tok, 0); if (Is_long(v)) __fprintf(stderr, "%" ARCH_INTNAT_PRINTF_FORMAT "d", Long_val(v)); else if (Tag_val(v) == String_tag) __fprintf(stderr, "%s", String_val(v)); else if (Tag_val(v) == Double_tag) #if defined(__FreeBSD__) && defined(_KERNEL) { fixpt_to_str(Double_val(v), buf, 7); __fprintf(stderr, "%s", buf); } #else __fprintf(stderr, "%g", Double_val(v)); #endif else __fprintf(stderr, "_"); __fprintf(stderr, ")\n"); }
std::string bad_token::what_long() const { const token* t = this->where.get(); /* TODO: location */ return std::string("Unexpected token (") + std::string(token_name(t->type)) + std::string(") expected (") + std::string(token_name(this->type)) + std::string(") instead"); }
void yyaccept(int tok) { if (symbol == tok) symbol = yylex(); else { fprintf(stderr, "line %d: Syntax Error\n", lineno); fprintf(stderr, "expected symbol: \"%s\"", token_name(tok)); fprintf(stderr, ", read \"%s\"\n",token_name(symbol)); } //printf("%s", token_name(symbol)); //if (symbol == UPPERCASE_STRING) printf(": %s", yytext); //printf("\n"); }
void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node) { if (const ListNode<std::size_t> *it = node->integrals) { it = it->toFront(); const ListNode<std::size_t> *end = it; do { std::size_t token = it->element; // FIXME m_type.push_back(token_name(m_session->token_stream->kind(token))); it = it->next; } while (it != end); } else if (node->type_of) { // ### implement me m_type.push_back("typeof<...>"); } visit(node->name); if (node->integrals) { m_realType = Type(m_type.join(" "), isConstant(), isVolatile()); if (m_realType.name() == "unsigned") { // implicit int.. m_realType.setName("unsigned int"); } m_realType.setIsIntegral(true); } else { setRealType(); } }
static void parse_condnode(void) { get_token(); switch (token.type) { case Cond: curr_node->type = Cond; curr_node->data.text = alloc_string(token.id); break; case Haslisp: case Hasreturn: case Lastwindow: case Hasup: curr_node->type = token.type; break; case Boxcond: curr_node->type = Boxcond; curr_node->data.text = alloc_string(token.id); break; case Hasreturnto: parse_hasreturnto(); break; default: { char eb[128]; token_name(token.type); sprintf(eb, "Unexpected Token %s\n", eb); htperror(eb, HTCONDNODE); } break; } }
static void dump_token(TOKEN *t) { char buf[256]; int i, j; for (i = 0, j = 0; i < 255 && j < t->length; j++) { switch (t->value[j]) { case '\n': case '\r': case '\t': if (i > 253) { goto done; } buf[i++] = '\\'; switch(t->value[j]) { case '\n': buf[i++] = 'n'; break; case '\r': buf[i++] = 'r'; break; case '\t': buf[i++] = 't'; break; } break; default: buf[i++] = t->value[j]; } } done: buf[i] = '\0'; pgr_debugf("got a token {%s(%d), '%s', %d}", token_name(t->type), t->type, buf, t->length); }
inline void print(Token_list& tl) { for (auto it : tl) { std::cout << "[\'" + *it.str() + "\'] " + token_name(it.kind()) + "\n"; } }
int ACE_Token_Collection::is_member (const ACE_Token_Proxy &token) { ACE_TRACE ("ACE_Token_Collection::is_member"); TOKEN_NAME token_name (token.name ()); return collection_.find (token_name) == 0; }
void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node) { if (const ListNode<std::size_t> *it = node->integrals) { m_integral = true; it = it->toFront(); const ListNode<std::size_t> *end = it; do { std::size_t token = it->element; // FIXME m_type.push_back(token_name(m_session->token_stream->kind(token))); it = it->next; } while (it != end); } else if (node->type_of) { qDebug("*** type of"); // ### implement me m_type.push_back("typeof<...>"); } visit(node->name); }
/* * print the contents of a token list */ static void print_token_fifo(struct token_fifo *tf) { size_t i; for (i = 0; i < tf->nt; i ++) if (ttMWS(tf->t[i].type)) fputc(' ', emit_output); else fputs(token_name(tf->t + i), emit_output); }
std::string bad_statement::what_long() const { const token* t = this->where.get(); /* TODO: location */ return std::string("Unable to determine statement from token (") + std::string(token_name(t->type)) + std::string(")"); }
void graficarDiccionario(struct ts_entry *ts) { int i; printf("\n\nTABLA DE SIMBOLOS\n"); for (i = 0; i < TAMDIC; i++) { if (ts[i].lexema[0] == '\0') break; printf("%d %32s %s\n", i, ts[i].lexema, token_name(ts[i].tok)); } }
int main(int argc, char *argv[]) { int ecode; bfcc_options bfopts = {0}; if (parse_arguments(argc, argv, &bfopts) != 0) { return -2; } FILE *f = stdin; if (bfopts.input_file != 0) { f = fopen(bfopts.input_file, "r"); if (!f) { fprintf(stderr, "Unknown file.\n"); return ERROR_FILE_NOT_FOUND; } } c99_options opts; c99_options_default(&opts); backend back = create_c99_backend(&opts); ecode = back.begin(&back, stdout); FATAL_IF_ERROR(ecode, "Backend preamble generation"); tokeniser *t = tokeniser_setup(f); CHECK_ALLOCATION(t, "Tokeniser setup"); while (1) { token tok; int error = tokeniser_next(t, &tok); if (IS_ERROR(error)) { fprintf(stderr, "Tokenisation error detected: %d.\n", error); return ERROR_TOKENISATION; } if (tok == token_eof) break; if (IS_ERROR(back.emit(&back, stdout, (token) tok))) { fprintf(stderr, "Failure encountered when translating token: %s\n", token_name((token) tok)); } } ecode = back.end(&back, stdout); FATAL_IF_ERROR(ecode, "Backend could not finish") return 0; }
/* print out a token value */ void print_token(void) { if (token.type == Word) printf("%s ", token.id); else { token_name(token.type); printf("\\%s ", ebuffer); } fflush(stdout); }
static void print_token(struct parser_tables *tables, int state, value tok) { value v; if (Is_long(tok)) { fprintf(stderr, "State %d: read token %s\n", state, token_name(tables->names_const, Int_val(tok))); } else { fprintf(stderr, "State %d: read token %s(", state, token_name(tables->names_block, Tag_val(tok))); v = Field(tok, 0); if (Is_long(v)) fprintf(stderr, "%ld", Long_val(v)); else if (Tag_val(v) == String_tag) fprintf(stderr, "%s", String_val(v)); else if (Tag_val(v) == Double_tag) fprintf(stderr, "%g", Double_val(v)); else fprintf(stderr, "_"); fprintf(stderr, ")\n"); } }
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(); } }
static void print_token(struct parser_tables *tables, int state, value tok) { CAMLparam1 (tok); CAMLlocal1 (v); if (Is_long(tok)) { fprintf(stderr, "State %d: read token %s\n", state, token_name(tables->names_const, Int_val(tok))); } else { fprintf(stderr, "State %d: read token %s(", state, token_name(tables->names_block, Tag_val(tok))); caml_read_field(tok, 0, &v); if (Is_long(v)) fprintf(stderr, "%" ARCH_INTNAT_PRINTF_FORMAT "d", Long_val(v)); else if (Tag_val(v) == String_tag) fprintf(stderr, "%s", String_val(v)); else if (Tag_val(v) == Double_tag) fprintf(stderr, "%g", Double_val(v)); else fprintf(stderr, "_"); fprintf(stderr, ")\n"); } CAMLreturn0; }
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; } }
int AdbEndpoint::on_adb_message(const AdbMessage& msg) { wxLogDebug("IN : %s %04x %04x %d bytes", token_name(msg.cmd), msg.arg0, msg.arg1, msg.payload_len); switch (msg.cmd) { case A_AUTH: if (msg.arg0 == 1) { // token // msg.payload_len is a random token that the recipient can sign // with a private key if (!_key) { if (!generate_key()) { wxLogError("GenerateKey failed."); } } // this is a key unknown to the device, let's // send the (new) public key over. token type=3 if (0 == _auth_attempt) { // sign with the key we have. unsigned char* buf1; unsigned char* buf2; int len = i2d_RSAPublicKey(_key, 0); buf1 = buf2 = (unsigned char *)malloc(len + 1); memset(buf1, 0, len+1); i2d_RSAPublicKey(_key, (unsigned char **)&buf2); send_adb_message(A_AUTH, 3, 0, buf1, len); free (buf1); _auth_attempt ++ ; } } break; } return 0; }
void verbose_indirect(t_line *tmp, t_cmd *ptr) { short label_value; short nb_ind; ft_printf("\n\t\t\t\t%s->%s %-20s -> [%s%s - %s0b11%s -", RED, C_END, ptr->data, ITLC, token_name(ptr->token), GREEN, C_END); if (ptr->token == INDIRECT) { nb_ind = (short)ft_atoi(ptr->data); verbose_binary_short(nb_ind); } else { label_value = (short)label_byte(tmp->label, (ptr->data + 1)); nb_ind = label_value - (short)tmp->size; verbose_binary_short(nb_ind); } }
void verbose_direct_int(t_line *tmp, t_cmd *ptr) { int label_value; int nb_ind; ft_printf("\n\t\t\t\t%s->%s %-20s -> [%s%s - %s0b10%s -", RED, C_END, ptr->data, ITLC, token_name(ptr->token), GREEN, C_END); if (ptr->token == DIRECT) { nb_ind = ft_atoi(ptr->data + 1); verbose_binary_int(nb_ind); } else { label_value = label_byte(tmp->label, (ptr->data + 2)); nb_ind = label_value - tmp->size; verbose_binary_int(nb_ind); } }
void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node) { if (const ListNode<std::size_t> *it = node->integrals) { it = it->toFront(); const ListNode<std::size_t> *end = it; QString current_item; do { std::size_t token = it->element; current_item += token_name(_M_token_stream->kind(token)); current_item += " "; it = it->next; } while (it != end); _M_type += current_item.trimmed(); } else if (node->type_of) { // ### implement me _M_type += QLatin1String("typeof<...>"); } visit(node->name); }
// Notify the token manager that a token is has been released. If // as a result, there is no owner of the token, the token is // deleted. void ACE_Token_Manager::release_token (ACE_Tokens *&token) { ACE_TRACE ("ACE_Token_Manager::release_token"); // again, let's perform our own locking here. ACE_GUARD (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_); if (token->dec_reference () == 0) { // No one has the token, so we can delete it and remove it from // our collection. First, let's get it from the collection. TOKEN_NAME token_name (token->name ()); ACE_Tokens *temp; if (collection_.unbind (token_name, temp) == -1) // we did not find one in the collection { errno = ENOENT; ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("Token Manager could not release %s:%d\n"), token->name (), token->type ())); // @@ bad } else // we found it { // sanity pointer comparison. The token referenced by the // proxy better be the one we found in the list. ACE_ASSERT (token == temp); delete token; // or delete temp // we set their token to zero. if the calling proxy is // still going to be used, it had better check it's token // value before calling a method on it! token = 0; } } // else // someone is still interested in the token, so keep it around. }
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; }
/* * yylex() - function that does the actual scanning. * Bison expects this function to be called yylex and for it to take no * input and return an int. * Conceptually yylex "returns" yylval as well as the actual return * value representing the token or type. */ int yylex(void) { static follby followedby = FOLLBY_TOKEN; size_t i; int instring; int yylval_was_set; int converted; int token; /* The return value */ int ch; instring = FALSE; yylval_was_set = FALSE; do { /* Ignore whitespace at the beginning */ while (EOF != (ch = lex_getch(lex_stack)) && isspace(ch) && !is_EOC(ch)) ; /* Null Statement */ if (EOF == ch) { if ( ! lex_pop_file()) return 0; token = T_EOC; goto normal_return; } else if (is_EOC(ch)) { /* end FOLLBY_STRINGS_TO_EOC effect */ followedby = FOLLBY_TOKEN; token = T_EOC; goto normal_return; } else if (is_special(ch) && FOLLBY_TOKEN == followedby) { /* special chars are their own token values */ token = ch; /* * '=' outside simulator configuration implies * a single string following as in: * setvar Owner = "The Boss" default */ if ('=' == ch && old_config_style) followedby = FOLLBY_STRING; yytext[0] = (char)ch; yytext[1] = '\0'; goto normal_return; } else lex_ungetch(ch, lex_stack); /* save the position of start of the token */ lex_stack->tokpos = lex_stack->curpos; /* Read in the lexeme */ i = 0; while (EOF != (ch = lex_getch(lex_stack))) { yytext[i] = (char)ch; /* Break on whitespace or a special character */ if (isspace(ch) || is_EOC(ch) || '"' == ch || (FOLLBY_TOKEN == followedby && is_special(ch))) break; /* Read the rest of the line on reading a start of comment character */ if ('#' == ch) { while (EOF != (ch = lex_getch(lex_stack)) && '\n' != ch) ; /* Null Statement */ break; } i++; if (i >= COUNTOF(yytext)) goto lex_too_long; } /* Pick up all of the string inside between " marks, to * end of line. If we make it to EOL without a * terminating " assume it for them. * * XXX - HMS: I'm not sure we want to assume the closing " */ if ('"' == ch) { instring = TRUE; while (EOF != (ch = lex_getch(lex_stack)) && ch != '"' && ch != '\n') { yytext[i++] = (char)ch; if (i >= COUNTOF(yytext)) goto lex_too_long; } /* * yytext[i] will be pushed back as not part of * this lexeme, but any closing quote should * not be pushed back, so we read another char. */ if ('"' == ch) ch = lex_getch(lex_stack); } /* Pushback the last character read that is not a part * of this lexeme. This fails silently if ch is EOF, * but then the EOF condition persists and is handled on * the next turn by the include stack mechanism. */ lex_ungetch(ch, lex_stack); yytext[i] = '\0'; } while (i == 0); /* Now return the desired token */ /* First make sure that the parser is *not* expecting a string * as the next token (based on the previous token that was * returned) and that we haven't read a string. */ if (followedby == FOLLBY_TOKEN && !instring) { token = is_keyword(yytext, &followedby); if (token) { /* * T_Server is exceptional as it forces the * following token to be a string in the * non-simulator parts of the configuration, * but in the simulator configuration section, * "server" is followed by "=" which must be * recognized as a token not a string. */ if (T_Server == token && !old_config_style) followedby = FOLLBY_TOKEN; goto normal_return; } else if (is_integer(yytext)) { yylval_was_set = TRUE; errno = 0; if ((yylval.Integer = strtol(yytext, NULL, 10)) == 0 && ((errno == EINVAL) || (errno == ERANGE))) { msyslog(LOG_ERR, "Integer cannot be represented: %s", yytext); if (lex_from_file()) { exit(1); } else { /* force end of parsing */ yylval.Integer = 0; return 0; } } token = T_Integer; goto normal_return; } else if (is_u_int(yytext)) { yylval_was_set = TRUE; if ('0' == yytext[0] && 'x' == tolower((unsigned long)yytext[1])) converted = sscanf(&yytext[2], "%x", &yylval.U_int); else converted = sscanf(yytext, "%u", &yylval.U_int); if (1 != converted) { msyslog(LOG_ERR, "U_int cannot be represented: %s", yytext); if (lex_from_file()) { exit(1); } else { /* force end of parsing */ yylval.Integer = 0; return 0; } } token = T_U_int; goto normal_return; } else if (is_double(yytext)) { yylval_was_set = TRUE; errno = 0; if ((yylval.Double = atof(yytext)) == 0 && errno == ERANGE) { msyslog(LOG_ERR, "Double too large to represent: %s", yytext); exit(1); } else { token = T_Double; goto normal_return; } } else { /* Default: Everything is a string */ yylval_was_set = TRUE; token = create_string_token(yytext); goto normal_return; } } /* * Either followedby is not FOLLBY_TOKEN or this lexeme is part * of a string. Hence, we need to return T_String. * * _Except_ we might have a -4 or -6 flag on a an association * configuration line (server, peer, pool, etc.). * * This is a terrible hack, but the grammar is ambiguous so we * don't have a choice. [SK] * * The ambiguity is in the keyword scanner, not ntp_parser.y. * We do not require server addresses be quoted in ntp.conf, * complicating the scanner's job. To avoid trying (and * failing) to match an IP address or DNS name to a keyword, * the association keywords use FOLLBY_STRING in the keyword * table, which tells the scanner to force the next token to be * a T_String, so it does not try to match a keyword but rather * expects a string when -4/-6 modifiers to server, peer, etc. * are encountered. * restrict -4 and restrict -6 parsing works correctly without * this hack, as restrict uses FOLLBY_TOKEN. [DH] */ if ('-' == yytext[0]) { if ('4' == yytext[1]) { token = T_Ipv4_flag; goto normal_return; } else if ('6' == yytext[1]) { token = T_Ipv6_flag; goto normal_return; } } instring = FALSE; if (FOLLBY_STRING == followedby) followedby = FOLLBY_TOKEN; yylval_was_set = TRUE; token = create_string_token(yytext); normal_return: if (T_EOC == token) DPRINTF(4,("\t<end of command>\n")); else DPRINTF(4, ("yylex: lexeme '%s' -> %s\n", yytext, token_name(token))); if (!yylval_was_set) yylval.Integer = token; return token; lex_too_long: yytext[min(sizeof(yytext) - 1, 50)] = 0; msyslog(LOG_ERR, "configuration item on line %d longer than limit of %lu, began with '%s'", lex_stack->curpos.nline, (u_long)min(sizeof(yytext) - 1, 50), yytext); /* * If we hit the length limit reading the startup configuration * file, abort. */ if (lex_from_file()) exit(sizeof(yytext) - 1); /* * If it's runtime configuration via ntpq :config treat it as * if the configuration text ended before the too-long lexeme, * hostname, or string. */ yylval.Integer = 0; return 0; }
std::ostream &operator<<( std::ostream &out, token_type t ) { out << token_name( t ); return out; }
void print_token(FILE* file, struct token* t){ fprintf(file, "%s (%d, %d) %s\n",token_name(t->type), t->line, t->column, t->text); }
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_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--; }
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; }