long to_long(const boost::any & operand) { if (! is_long(operand)) { std::cerr << "##### operand is not convertible to LONG .. " << std::endl; throw gsse::invalid_datatype_conversion("long"); // exit(-1); } long val = boost::any_cast<long>(operand); return val; }
char *get_token(char *lexeme , int mode){ char *token=(char*)calloc(strlen(lexeme)+50,sizeof(char)); //printf("Getting token\n"); if(is_long(lexeme)){ sprintf(token,"%d",LONG); } else if(is_static(lexeme)){ sprintf(token,"%d",STATIC); } else if(is_union(lexeme)){ sprintf(token,"%d",UNION); } else if(is_default(lexeme)){ sprintf(token,"%d",DEFAULT); } else if(is_break(lexeme)){ sprintf(token,"%d",BREAK); } else if(is_case(lexeme)){ sprintf(token,"%d",CASE); } else if(is_continue(lexeme)){ sprintf(token,"%d",CONTINUE); } else if(is_goto(lexeme)){ sprintf(token,"%d",GOTO); } else if(is_struct(lexeme)){ sprintf(token,"%d",STRUCT); } else if(is_const(lexeme)){ sprintf(token,"%d",CONST); } else if(is_void(lexeme)){ sprintf(token,"%d",VOID); } else if(is_switch(lexeme)){ sprintf(token,"%d",SWITCH); } else if(is_for(lexeme)){ sprintf(token,"%d",FOR); } else if(is_while(lexeme)){ sprintf(token,"%d",WHILE); } else if(is_do(lexeme)){ sprintf(token,"%d",DO); } else if(is_return(lexeme)){ sprintf(token,"%d",RETURN); } else if(is_bool(lexeme)){ sprintf(token,"%d",BOOL); } else if(is_char(lexeme)){ sprintf(token,"%d",CHAR); } else if(is_signed(lexeme)){ sprintf(token,"%d",SIGNED); } else if(is_unsigned(lexeme)){ sprintf(token,"%d",UNSIGNED); } else if(is_short(lexeme)){ sprintf(token,"%d",SHORT); } else if(is_int(lexeme)){ sprintf(token,"%d",INT); } else if(is_float(lexeme)){ sprintf(token,"%d",FLOAT); } else if(is_double(lexeme)){ sprintf(token,"%d",DOUBLE); } else if(is_l_square(lexeme)){ sprintf(token,"%d",L_SQUARE); } else if(is_r_square(lexeme)){ sprintf(token,"%d",R_SQUARE); } else if(is_l_paraen(lexeme)){ sprintf(token,"%d",L_PARAEN); } else if(is_r_paraen(lexeme)){ sprintf(token,"%d",R_PARAEN); } else if(is_l_cbrace(lexeme)){ sprintf(token,"%d",L_CBRACE); } else if(is_r_cbrace(lexeme)){ sprintf(token,"%d",R_CBRACE); } else if(is_comma(lexeme)){ sprintf(token,"%d",COMMA); } else if(is_semicol(lexeme)){ sprintf(token,"%d",SEMICOL); } else if(is_eq_eq(lexeme)){ sprintf(token,"%d",EQ_EQ); } else if(is_lesser(lexeme)){ sprintf(token,"%d",LESSER); } else if(is_less_eq(lexeme)){ sprintf(token,"%d",LESS_EQ); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_greater(lexeme)){ sprintf(token,"%d",GREATER); } else if(is_great_eq(lexeme)){ sprintf(token,"%d",GREAT_EQ); } else if(is_plus_eq(lexeme)){ sprintf(token,"%d",PLUS_EQ); } else if(is_minus_eq(lexeme)){ sprintf(token,"%d",MINUS_EQ); } else if(is_div_eq(lexeme)){ sprintf(token,"%d",DIV_EQ); } else if(is_mult_eq(lexeme)){ sprintf(token,"%d",MULT_EQ); } else if(is_minus_minus(lexeme)){ sprintf(token,"%d",MINUS_MINUS); } else if(is_plus_plus(lexeme)){ sprintf(token,"%d",PLUS_PLUS); } else if(is_percent(lexeme)){ sprintf(token,"%d",PERCENT); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_mult(lexeme)){ sprintf(token,"%d",MULT); } else if(is_minus(lexeme)){ sprintf(token,"%d",MINUS); } else if(is_plus(lexeme)){ sprintf(token,"%d",PLUS); } else if(is_int_const(lexeme)){ printf("int"); sprintf(token,"%d\t%s",INT_CONST,lexeme); } else if(is_flo_const(lexeme)){ printf("float"); sprintf(token,"%d\t%s",FLO_CONST,lexeme); } else if(is_comment_start(lexeme)){ sprintf(token,"$start"); } else if(is_comment_end(lexeme)){ sprintf(token,"$end"); } else if(is_identifier(lexeme)){ printf("Identifier"); if(mode==1) ht_set( symboltable, lexeme, "1"); sprintf(token,"%d\t%s",IDNTIFIER,lexeme); } else sprintf(token,"%d",NOTOK); return token; }
tree edit_env_rep::rewrite_inactive_default ( tree t, tree var, bool block, bool flush) { int i, d= 0, n= N(t); tree op= as_string (L(t)); if ((L(t) == COMPOUND) && is_atomic (t[0]) && (src_special >= SPECIAL_NORMAL)) { d = 1; op= highlight (subvar (var, 0), t[0], TYPE_VARIABLE); } if (inactive_mode == INACTIVE_INLINE_ERROR || inactive_mode == INACTIVE_BLOCK_ERROR) op= highlight (op, "", TYPE_INVALID); if ((N(t) == d) || (src_compact == COMPACT_ALL) || ((!block) && (src_compact != COMPACT_NONE)) || ((!is_long (t)) && (src_compact != COMPACT_NONE))) { tree r (INLINE_TAG, n+1-d); r[0]= op; for (i=d; i<n; i++) r[i+1-d]= rewrite_inactive_arg (t, var, i, false, false); return tree (MARK, var, r); } else { tree doc (DOCUMENT); bool compact= (src_compact < COMPACT_INLINE); for (i=d; i<n; i++) { tree next; if ((!compact) || is_long_arg (t, i)) { if (i==d) doc << tree (OPEN_TAG, op); next= rewrite_inactive_arg (t, var, i, true, src_close >= CLOSE_LONG); next= compound ("indent*", next); i++; } int start= i; for (; i<n; i++) if ((!compact) || is_long_arg (t, i)) break; int end= i; tree_label l= MIDDLE_TAG; if (end == n) l= CLOSE_TAG; if (start == d) l= OPEN_TAG; tree u (l, end - start + 1); u[0]= op; for (i=0; i<end-start; i++) u[i+1]= rewrite_inactive_arg (t, var, start+i, false, false); i= end-1; compact= (src_compact < COMPACT_INLINE_START); if (start==d) doc << u; else { if (src_close < CLOSE_LONG) doc << tree (SURROUND, "", u, next); else doc << next << u; } } if (flush) doc= tree (SURROUND, "", compound ("right-flush"), doc); return tree (MARK, var, doc); } }
bool is_long_arg (tree t, int i) { // FIXME: should go into the DRD int n= N(t); switch (L(t)) { case DOCUMENT: case VAR_INCLUDE: case TFORMAT: case TABLE: return true; case CONCAT: return false; case SURROUND: if (i == 2) return true; break; case ROW: return is_long (t[i]); case ASSIGN: case DATOMS: case DLINES: case DPAGES: case WITH: case MARK: case MACRO: case XMACRO: case CELL: case EVAL: case QUOTE: case QUASI: case QUASIQUOTE: case UNQUOTE: case VAR_UNQUOTE: if (i == n-1) return is_long (t[i]); break; case STYLE_WITH: case VAR_STYLE_WITH: if (i == n-1) { for (i=0; i<n-1; i+=2) if (t[i] == SRC_COMPACT) { if (t[i+1] == "none") return true; if (t[i+1] == "all") return false; } return is_long (t[i]); } break; case STYLE_ONLY: case VAR_STYLE_ONLY: case ACTIVE: case VAR_ACTIVE: return is_multi_paragraph (t[i]); case LOCUS: case CANVAS: case ORNAMENT: if (i == n-1) return is_long (t[i]); break; default: break; } tree u= t[i]; switch (L(u)) { case TWITH: case CWITH: case ROW: return true; default: if (L(t) < START_EXTENSIONS) return false; return is_long (u); } }
static inline bool is_option(const char* arg) { return is_long(arg) || is_short(arg); }
UpoptStatus upopt_next(UpoptContext* context, int* constant, const char** value, char** error) { const char* arg; const char* val = NULL; const UpoptOptionInfo* info = NULL; if (context->index >= context->argc) return UPOPT_STATUS_DONE; arg = context->argv[context->index++]; if (!context->only_normal) { if (is_long(arg)) { if (!arg[2]) { context->only_normal = 1; return upopt_next(context, constant, value, error); } else { char* equal = strchr(arg, '='); if (equal) { *equal = '\0'; val = equal + 1; } info = find_long(context->options, arg+2); if (equal) { *equal = '='; } if (!info) { *error = format("Unrecognized option: %s\n", arg); return UPOPT_STATUS_ERROR; } } } else if (is_short(arg)) { if (arg[2]) { val = arg+2; } info = find_short(context->options, arg[1]); if (!info) { *error = format("Unrecognized option: %s\n", arg); return UPOPT_STATUS_ERROR; } } } if (info) { if (val && !info->argument) { if (is_long(arg)) { *error = format("Did not expect an argument after --%s\n", info->longname); } else { *error = format("Did not expect an argument after -%c\n", info->shortname); } return UPOPT_STATUS_ERROR; } else if (!val && info->argument) { if ((context->index >= context->argc || (!context->only_normal && is_option(context->argv[context->index])))) { *error = format("Expected argument after %s\n", arg); return UPOPT_STATUS_ERROR; } val = context->argv[context->index++]; } *constant = info->constant; *value = val; *error = NULL; return UPOPT_STATUS_NORMAL; } else { *constant = UPOPT_ARG_NORMAL; *value = arg; *error = NULL; return UPOPT_STATUS_NORMAL; } }