/* SYNTAX: SET [-clear | -default] [<key> [<value>]] */ static void cmd_set(char *data) { GHashTable *optlist; char *key, *value; void *free_arg; int clear, set_default; SETTINGS_REC *rec; if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "set", &optlist, &key, &value)) return; clear = g_hash_table_lookup(optlist, "clear") != NULL; set_default = g_hash_table_lookup(optlist, "default") != NULL; if (*key == '\0') clear = set_default = FALSE; if (!(clear || set_default || *value != '\0')) set_print_pattern(key); else { rec = settings_get_record(key); if (rec != NULL) { /* change the setting */ switch (rec->type) { case SETTING_TYPE_BOOLEAN: if (clear) settings_set_bool(key, FALSE); else if (set_default) settings_set_bool(key, rec->default_value.v_bool); else set_boolean(key, value); break; case SETTING_TYPE_INT: if (clear) settings_set_int(key, 0); else if (set_default) settings_set_int(key, rec->default_value.v_int); else set_int(key, value); break; case SETTING_TYPE_CHOICE: if (clear || set_default) settings_set_choice(key, rec->choices[rec->default_value.v_int]); else set_choice(key, value); break; case SETTING_TYPE_STRING: settings_set_str(key, clear ? "" : set_default ? rec->default_value.v_string : value); break; case SETTING_TYPE_TIME: if (!settings_set_time(key, clear ? "0" : set_default ? rec->default_value.v_string : value)) printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_TIME); break; case SETTING_TYPE_LEVEL: if (!settings_set_level(key, clear ? "" : set_default ? rec->default_value.v_string : value)) printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_LEVEL); break; case SETTING_TYPE_SIZE: if (!settings_set_size(key, clear ? "0" : set_default ? rec->default_value.v_string : value)) printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_SIZE); break; case SETTING_TYPE_ANY: /* Unpossible! */ break; } signal_emit("setup changed", 0); printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_TITLE, rec->section); set_print(rec); } else printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key); } cmd_params_free(free_arg); }
static nog_instruction_t *run(nog_closure_t *c, construction current, nog_instruction_t *ip_next, tree *result_tree) { nog_instruction_t *ip; /*printf("run pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip_next - pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/ if(!ip_next) return 0; for(;;) { ip = ip_next; assert(c->pg->np_program <= ip && ip < c->pg->np_program + c->pg->np_count); assert(c->bof <= c->head && c->head <= c->eof); /*printf("pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip - c->pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/ DEBUGIF(NOG_DEBUG,"%ld %ld %d\n", (long) (ip - c->pg->np_program), (long) (c->head - c->bof), c->fail); ip_next = ip + 1; switch(ip->ni_opcode) { case NOG_BRA: jump(); break; case NOG_BEOF: if(c->head == c->eof) jump(); break; case NOG_BNEOF: if(c->head < c->eof) jump(); break; case NOG_BFC: if(!c->fail) jump(); break; case NOG_BFS: if(c->fail) jump(); break; case NOG_BMB: if(c->memo == R_BUSY) jump(); break; case NOG_BMBF: if(c->memo == R_BUSY || c->memo == R_FAIL) jump(); break; case NOG_BMK: if(c->memo != R_UNKNOWN) jump(); break; case NOG_BMUK: if(c->memo == R_UNKNOWN) jump(); break; case NOG_BMF: if(c->memo == R_FAIL) jump(); break; case NOG_BBRC: if(!boolean_pop(c)) jump(); break; case NOG_BBRS: if(boolean_pop(c)) jump(); break; case NOG_JSR: (void) run(c, current, c->pg->np_program + arg0(), result_tree); break; case NOG_SBNS: if(c->head < c->eof && *c->head == arg1()) { c->head ++; } else { jump(); } break; case NOG_BSLLT: if(c->eof - c->head < arg1()) jump(); /* XXX */ break; case NOG_BNBOF: if(c->head != c->bof) jump(); break; case NOG_SSEQ: boolean_push(c, c->head < c->eof && *c->head == arg0()); break; case NOG_TSSEQ: boolean_push(c, c->head < c->eof && c->pg->np_tables[arg0()].nt_entries[*c->head] == (letter_t) arg1()); break; case NOG_SSIR: boolean_push(c, c->head < c->eof && arg0() <= *c->head && *c->head <= arg1()); break; case NOG_BTRUE: boolean_push(c, true); break; case NOG_BFALSE: boolean_push(c, false); break; case NOG_BAND: { bool b1, b2; b1 = boolean_pop(c); b2 = boolean_pop(c); boolean_push(c, b1 && b2); } break; case NOG_BOR: { bool b1, b2; b1 = boolean_pop(c); b2 = boolean_pop(c); boolean_push(c, b1 || b2); } break; case NOG_BNOT: boolean_push(c, !boolean_pop(c)); break; case NOG_SETF: c->fail = true; break; case NOG_CLRF: c->fail = false; break; case NOG_RIGHT: c->head += arg0(); break; case NOG_PUSHP: stack_push(c, c->head - c->bof); break; case NOG_POPP: c->head = c->bof + stack_pop(c); break; case NOG_RESTP: c->head = c->bof + stack_top(c); break; case NOG_DROPP: (void) stack_pop(c); break; case NOG_LDMEM: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); c->memo = get_result(c->cx, c->head - c->bof, arg0()); break; case NOG_LDCH: assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives); c->choice = get_choice(c->cx, c->head - c->bof, arg0()); break; case NOG_POPSTMEMJ: { int position; position = stack_pop(c); assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, position, arg0(), c->head - c->bof); } break; case NOG_STMEMB: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, c->head - c->bof, arg0(), R_BUSY); break; case NOG_STMEMF: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, c->head - c->bof, arg0(), R_FAIL); break; case NOG_TOPSTCH: { int position; position = stack_top(c); assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives); set_choice(c->cx, position, arg0(), arg1()); } break; case NOG_JMEM: c->head = c->bof + c->memo; break; case NOG_RTS: return ip_next; case NOG_SWCH: assert(c->choice < ip->ni_arg[0].na_table.nt_length); jump_to(ip->ni_arg[0].na_table.nt_elements[c->choice]); break; case NOG_LABEL: break; /* Construction */ case NOG_SNODE: { int id; unsigned char *name; construction new_cons; tree new_tree; id = arg0(); name = c->pg->np_constructors[id].ns_chars; new_cons = c->bd->pb_start_construction(c->bi, id, name, c->head - c->bof); ip_next = run(c, new_cons, ip_next, &new_tree); if(!ip_next) { return 0; } /* new_tree = c->bd->pb_finish_construction(c->bi, new_cons); */ if(!c->bd->pb_add_children(c->bi, current, new_tree)) return 0; } break; case NOG_FNODE: if(result_tree) { *result_tree = c->bd->pb_finish_construction(c->bi, current, c->head - c->bof); } return ip_next; case NOG_ATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->memo)) return 0; } break; case NOG_STRATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_constant_attribute(c->bi, current, id, name, ip->ni_arg[1].na_string.ns_chars, ip->ni_arg[1].na_string.ns_length)) return 0; } break; case NOG_POSATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->head - c->bof - 1)) return 0; } break; case NOG_TOKEN: if(!c->bd->pb_add_token(c->bi, current, c->head - c->bof, c->memo)) return 0; break; } } }