int equalp(int x1, int x2){ int start1,start2,len1,len2,elt; if(nullp(x1) && nullp(x2)) return(1); if((nullp(x1) && !nullp(x2)) || (!nullp(x1) && nullp(x2))) return(0); if(numberp(x1) && numberp(x2) && numeqp(x1,x2)) return(1); if(vectorp(x1) && vectorp(x2)){ start1 = car(x1); start2 = car(x2); len1 = cdr(x1); len2 = cdr(x2); if(len1 == len2){ if(len1 == 0) return(1); else{ elt = 0; while(elt < len1){ if(!equalp(car(start1+elt),car(start2+elt))) return(0); elt++; } } return(1); } else return(0); } if(atomp(x1) && atomp(x2)) return(eqvp(x1,x2)); if(equalp(car(x1),car(x2))) return(equalp(cdr(x1),cdr(x2))); else return(0); }
sexpr on_event (sexpr arguments, struct machine_state *state) { if (eolp (state->stack)) { sexpr tstate = car (arguments); if (truep(equalp(tstate, sym_always)) || ((init_state == gs_power_on) && truep(equalp(tstate, sym_power_on))) || ((init_state == gs_power_down) && truep(equalp(tstate, sym_power_down))) || ((init_state == gs_power_reset) && truep(equalp(tstate, sym_power_reset))) || ((init_state == gs_ctrl_alt_del) && truep(equalp(tstate, sym_ctrl_alt_del)))) { state->code = cdr (state->code); return sx_nonexistent; /* makes the seteh code execute the remainder of the script */ } else { return sx_false; // wrong state } } else { return sx_true; } }
static void handle_external_mod_update (struct kyu_module *newdef, struct kyu_module *mydef) { sexpr c, a, module, rv = sx_nil, flags = newdef->schedulerflags; c = sx_set_difference (mydef->schedulerflags, newdef->schedulerflags); if (eolp (c)) { return; } while (consp (c) && nilp (rv)) { a = car (c); if (truep (equalp (a, sym_enabling))) { if (falsep (sx_set_memberp (mydef->schedulerflags, sym_enabling))) { rv = handle_enable_request (mydef); if (falsep (rv)) { flags = sx_set_add (mydef->schedulerflags, sym_blocked); } } } else if (truep (equalp (a, sym_disabling))) { if (falsep (sx_set_memberp (mydef->schedulerflags, sym_disabling))) { rv = handle_disable_request (mydef); } } else if (consp (a) && falsep (sx_set_memberp (mydef->schedulerflags, a))) { rv = handle_action (mydef, cdr (a)); } c = cdr (c); } module = kyu_make_module (mydef->name, mydef->description, mydef->provides, mydef->requires, mydef->before, mydef->after, mydef->conflicts, flags, mydef->functions); my_modules = lx_environment_unbind (my_modules, mydef->name); my_modules = lx_environment_bind (my_modules, mydef->name, module); kyu_command (cons (sym_update, cons (native_system, cons (module, sx_end_of_list)))); }
static sexpr get_acceptable_type (sexpr lq) { sexpr types = get_acceptable_types (lq), ta, mape = lx_environment_alist (mime_map), n; while (consp (types)) { ta = car (types); n = mape; while (consp (n)) { if (truep (equalp (ta, cdr (car (n))))) { return ta; } n = cdr (n); } types = cdr (types); } return default_type; }
int assoc(int obj, int lis){ while(!nullp(lis)) if(equalp(obj,caar(lis))) return(car(lis)); else lis = cdr(lis); return(BOOLF); }
int member(int obj, int lis){ while(!nullp(lis)) if(equalp(obj,car(lis))) return(lis); else lis = cdr(lis); return(BOOLF); }
static void configure_callback (sexpr sx) { sexpr a = car (sx); if (truep (equalp (a, sym_root))) { webroot = car (cdr (sx)); } else if (truep (equalp (a, sym_map_extension))) { a = cdr (sx); mime_map = lx_environment_bind (mime_map, car (a), car (cdr (a))); } else if (truep (equalp (a, sym_default_type))) { default_type = car (cdr (sx)); } }
struct graph_edge *graph_node_search_edge (struct graph_node *node, sexpr label) { int i; for(i = 0; i < node->edge_count; i++) { if(truep(equalp(node->edges[i]->label, label))) return node->edges[i]; } return (struct graph_edge *)0; }
static void mx_sx_ctl_queue_read (sexpr sx, struct sexpr_io *io, void *aux) { if (consp(sx)) { sexpr sxcar = car (sx); if (truep(equalp(sxcar, sym_disable))) { cexit (0); } } }
sexpr equalp (sexpr a, sexpr b) { if (a == b) return sx_true; if (!pointerp(a) || !pointerp(b)) return sx_false; if ((stringp(a) && stringp(b)) || (symbolp(a) && symbolp(b))) { struct sexpr_string_or_symbol *sa = (struct sexpr_string_or_symbol *)sx_pointer(a), *sb = (struct sexpr_string_or_symbol *)sx_pointer(b); unsigned long i; return (str_hash(sa->character_data, &i) == str_hash(sb->character_data, &i)) ? sx_true : sx_false; } else if (consp(a) && consp(b)) { return ((truep(equalp(car(a), car(b))) && truep(equalp(cdr(a), cdr(b))))) ? sx_true : sx_false; } else if (customp(a) && customp(b)) { int type = sx_type (a); if (type == sx_type (b)) { struct sexpr_type_descriptor *d = sx_get_descriptor (type); if ((d != (struct sexpr_type_descriptor *)0) && (d->equalp != (void *)0)) { return d->equalp (a, b); } } } return sx_false; }
struct graph_node *graph_search_node (sexpr sx, sexpr label) { struct graph *gr = (struct graph *)sx_pointer(sx); int i; for(i = 0; i < gr->node_count; i++) { if(truep(equalp(gr->nodes[i]->label, label))) return gr->nodes[i]; } return (struct graph_node *)0; }
int checkclose(long int p1) { int check,ret; check=count-1; int i,j; long int t; while(check>=0) { t=closed[check]; ret=equalp(p1,t); if(ret==1) return 1; check--; } return 0; }
bool structure_equal(lref_t sta, lref_t stb) { assert(STRUCTUREP(sta)); assert(STRUCTUREP(stb)); if (STRUCTURE_LAYOUT(sta) != STRUCTURE_LAYOUT(stb)) return false; if (STRUCTURE_DIM(sta) != STRUCTURE_DIM(stb)) return false; for (size_t ii = 0; ii < STRUCTURE_DIM(sta); ii++) if (!equalp(STRUCTURE_ELEM(sta, ii), STRUCTURE_ELEM(stb, ii))) return false; return true; }
atom_t brz_deriv( atom_t atom, int c ) { if( characterp(atom) ) return PREDICATE( equalp(atom, ULISP_CHAR(c)) ); if( re_is_seq(atom) ) return re_alt( re_seq( brz_deriv(cadr(atom), c), caddr(atom) ), re_seq( PREDICATE(brz_is_nullable(cadr(atom))), brz_deriv(caddr(atom), c) )); if( re_is_alt(atom) ) return re_alt( brz_deriv(cadr(atom), c), brz_deriv(caddr(atom), c) ); if( re_is_rep(atom) ) return re_seq( brz_deriv(cadr(atom), c), re_rep(cadr(atom)) ); return PREDICATE( re_is_any(atom) ); }
static sexpr handle_action (struct kyu_module *mod, sexpr action) { sexpr act = lx_environment_lookup (mod_functions, mod->name), c, a, e; if (nexp (act)) { kyu_command (cons (sym_warning, cons (sym_module_has_no_functions, cons (mod->name, sx_end_of_list)))); return sx_false; } for (c = act; consp (c); c = cdr (c)) { a = car (c); if (truep (equalp (car (a), action))) { e = lx_environment_unbind (global_environment, sym_source); e = lx_environment_bind (e, sym_source, (sexpr)mod); lx_eval (cons (cons (sym_action_dispatch, cons (cons (mod->name, action), cons (cdr (a), cons (cons (sym_get_configuration, cons (mod->name, sx_end_of_list)), sx_end_of_list)))), sx_end_of_list), e); return sx_true; } } kyu_command (cons (sym_warning, cons (sym_module_action_not_available, cons (mod->name, sx_end_of_list)))); return sx_false; }
sexpr lx_environment_lookup (sexpr env, sexpr key) { if (environmentp (env)) { struct environment *t = (struct environment *)env; sexpr sx = t->environment; while (consp (sx)) { sexpr sxt = car (sx); if (truep (equalp (car (sxt), key))) { return cdr (sxt); } sx = cdr (sx); } } return sx_nonexistent; }
static void include_on_read (sexpr sx, struct sexpr_io *io, void *aux) { struct transdata *td = (struct transdata *)aux; if (eofp (sx)) { td->done = 1; } else if (consp (sx)) { sexpr n = car (sx); if (truep (equalp (sym_object, n))) { (*(td->data)) = cons (lx_eval (sx, (td->environment)), (*(td->data))); } else { (*(td->data)) = cons (sx, (*(td->data))); } } }
sexpr lx_environment_unbind (sexpr env, sexpr key) { sexpr r = sx_end_of_list; if (environmentp (env)) { struct environment *t = (struct environment *)env; sexpr sx = t->environment; while (consp (sx)) { sexpr sxt = car (sx); if (falsep (equalp (car (sxt), key))) { r = cons (sxt, r); } sx = cdr (sx); } } return lx_make_environment (r); }
static sexpr action_wrap (sexpr arguments, struct machine_state *state) { if (eolp (state->stack)) { state->stack = cons(lx_foreign_mu (sym_action_wrap, action_wrap), state->stack); state->stack = cons (car (state->code), state->stack); state->code = cdr (state->code); return sx_nonexistent; } else { sexpr meta = car (arguments), v = sx_true, name = car (meta), act = cdr (meta), t, module; struct kyu_module *mod; t = lx_environment_lookup (my_modules, name); if (!kmodulep (t)) { return sx_false; } mod = (struct kyu_module *)t; t = mod->schedulerflags; arguments = cdr (arguments); while (consp (arguments)) { v = car (arguments); arguments = cdr (arguments); } if (truep (equalp (act, sym_start))) { t = sx_set_remove (t, sym_enabling); if (truep (v)) { t = sx_set_add (t, sym_enabled); } else { t = sx_set_add (t, sym_blocked); } } else if (truep (equalp (act, sym_stop))) { t = sx_set_remove (t, sym_enabled); t = sx_set_remove (t, sym_disabling); } else { t = sx_set_remove (t, cons (sym_action, act)); } module = kyu_make_module (mod->name, mod->description, mod->provides, mod->requires, mod->before, mod->after, mod->conflicts, t, mod->functions); my_modules = lx_environment_unbind (my_modules, name); my_modules = lx_environment_bind (my_modules, name, module); kyu_command (cons (sym_update, cons (native_system, cons (module, sx_end_of_list)))); return sx_true; } }
static void event_add (sexpr sx) { struct event *ev; if (consp (sx)) { sexpr a = car (sx); sexpr c = cdr (sx); int repeat = 1; int stat = 0; if (truep (equalp (a, sym_quit))) { cexit (0); } if (truep (equalp (a, sym_repeat))) { a = car (c); c = cdr (c); repeat = -1; stat |= STAT_HAD_REPEAT; if (integerp (a)) { repeat = sx_integer (a); a = car (c); c = cdr (c); } else if (truep (equalp (a, sym_indefinitely))) { repeat = -1; a = car (c); c = cdr (c); } else { stat |= STAT_SKIP_IN_POP; } } if (truep (equalp (a, sym_every))) { a = car (c); c = cdr (c); if (!(stat & STAT_HAD_REPEAT)) { repeat = -1; } stat |= STAT_PROCESS_IN; stat |= STAT_SKIP_IN_POP; } if (truep (equalp (a, sym_in)) || (stat & STAT_PROCESS_IN)) { if (!(stat & STAT_SKIP_IN_POP)) { a = car (c); c = cdr (c); } if (integerp (a)) { ev = get_event (); ev->repeat = repeat; ev->model_data.seconds = sx_integer (a); a = car (c); c = cdr (c); if (truep (equalp (a, sym_seconds)) || truep (equalp (a, sym_second)) || truep (equalp (a, sym_s))) { a = car (c); c = cdr (c); /* nothing to do*/ } if (!nexp (a) && falsep (equalp (a, sym_then))) { ev->output = a; a = car (c); c = cdr (c); } if (truep (equalp (a, sym_then))) { ev->then = c; } } } } }
static sexpr environment_equalp (sexpr a, sexpr b) { return equalp (((struct environment *)a)->environment, ((struct environment *)b)->environment); }
void main() { int fg=0; int f=0; int p1[3][3]; f++; clrscr(); printf("Enter initial state:\n"); for(int i=0;i<3;i++) for(int j=0;j<3;j++) { scanf("%d",&mat[i][j]); if(mat[i][j]==0) { a=i; b=j; } puzzle=(puzzle*10)+mat[i][j]; } printf("Enter solution:\n"); for(i=0;i<3;i++) for(j=0;j<3;j++) { scanf("%d",&p1[i][j]); solution=(solution*10)+p1[i][j]; } printf("Step %d:\n",f); printpuzzle(); printf("\n\n"); fg=equalp(puzzle,solution); if(fg==1) { printf("\n\nSolution Found:\n"); printpuzzle(); getch(); exit(0); } insertclose(puzzle); while(1) { insertopen(); returnopen(); fg=equalp(puzzle,solution); if(fg==1) { printf("\n\nSolution Found:\n"); printpuzzle(); getch(); break; } insertclose(puzzle); f++; printf("Step %d:\n",f); printpuzzle(); printf("\n\n"); getch(); } getch(); }
static void on_event (sexpr sx, void *aux) { if (consp (sx)) { sexpr a = car (sx); if (truep (equalp (a, sym_reply))) { sx = cdr (sx); a = car (sx); if (truep (equalp (a, sym_configuration))) { sx = cdr (sx); a = car (sx); if (truep (equalp (a, sym_server_seteh))) { kyu_command (cons (sym_initialising, cons (sym_server_seteh, sx_end_of_list))); sx = lx_environment_lookup (car (cdr (sx)), sym_source); while (consp (sx)) { sexpr files = read_directory_sx (car (sx)); while (consp (files)) { sexpr t = car (files); open_config_files++; multiplex_add_sexpr (sx_open_i (io_open_read (sx_string (t))), on_script_file_read, (void *)0); files = cdr (files); } sx = cdr (sx); } if (open_config_files == 0) { kyu_command (cons (sym_initialised, cons (sym_server_seteh, sx_end_of_list))); } } } } else if (truep (equalp (a, sym_update))) { /* this might be a request from the scheduler, let's have a look... */ sx = cdr (sx); a = car (sx); if (truep (equalp (a, native_system))) { sx = cdr (sx); while (consp (sx)) { a = car (sx); if (kmodulep (a)) { struct kyu_module *mod = (struct kyu_module *)a; a = lx_environment_lookup (my_modules, mod->name); if (!nexp (a)) { /* someone else updated one of our modules... */ struct kyu_module *mydef = (struct kyu_module *)a; handle_external_mod_update (mod, mydef); } } sx = cdr (sx); } } } else if (truep (equalp (a, sym_process_terminated))) { update_status_from_pid_files (); } } }
static void on_script_file_read (sexpr sx, struct sexpr_io *io, void *p) { if (consp (sx)) { sexpr a = car (sx), mt, b, c; struct kyu_module *mo; char daemon = 0; if (truep (equalp (sym_init_script, a)) || (daemon = truep (equalp (sym_daemon, a)))) { sexpr name = sx_nonexistent, description = sx_nonexistent, provides = sx_end_of_list, requires = sx_end_of_list, before = sx_end_of_list, after = sx_end_of_list, conflicts = sx_end_of_list, schedulerflags = sx_end_of_list, functions = sx_end_of_list, functiondata = sx_end_of_list, binary = sx_end_of_list, pidfile = sx_end_of_list, startcommand = sx_end_of_list, stopcommand = sx_true, parameters = sx_end_of_list, module; if (daemon) { functions = cons (sym_stop, cons (sym_start, functions)); } a = cdr (sx); name = car (a); a = cdr (a); description = car (a); a = cdr (a); while (consp (a)) { sexpr v = car (a); sexpr va = car (v); if (truep (equalp (sym_provides, va))) { provides = sx_set_merge (provides, cdr (v)); } else if (truep (equalp (sym_requires, va))) { requires = sx_set_merge (requires, cdr (v)); } else if (truep (equalp (sym_conflicts_with, va))) { conflicts = sx_set_merge (conflicts, cdr (v)); } else if (truep (equalp (sym_before, va))) { before = sx_set_merge (before, cdr (v)); } else if (truep (equalp (sym_after, va))) { after = sx_set_merge (after, cdr (v)); } else if (truep (equalp (sym_schedule_limitations, va))) { schedulerflags = sx_set_merge (schedulerflags, cdr (v)); } else if (truep (equalp (sym_functions, va))) { functiondata = sx_set_merge (functiondata, cdr (v)); } else if (truep (equalp (sym_pid_file, va))) { pidfile = sx_set_merge (pidfile, cdr (v)); } else if (truep (equalp (sym_binary, va))) { binary = sx_set_merge (binary, cdr (v)); } else if (truep (equalp (sym_parameters, va))) { parameters = sx_set_merge (parameters, cdr (c)); } a = cdr (a); } if (!eolp (binary)) { for (a = binary; consp (a); a = cdr (a)) { b = car (a); if (falsep ((c = which (b)))) { kyu_command (cons (sym_warning, cons (sym_binary_not_found, cons (native_system, cons (name, cons (b, sx_end_of_list)))))); return; } if (daemon) { startcommand = cons (cons (sym_run, cons (c, parameters)), startcommand); if (!eolp(pidfile) && truep(stopcommand)) { stopcommand = sx_list1 (sx_list2(sym_kill_via_pid_file, pidfile)); } } } } if (daemon) { functiondata = cons (cons (sym_start, startcommand), cons (cons (sym_stop, stopcommand), functiondata)); } mt = lx_environment_lookup (my_modules, name); if (!nexp (mt)) { mo = (struct kyu_module *)mt; schedulerflags = sx_set_merge (schedulerflags, mo->schedulerflags); } module = kyu_make_module (name, description, provides, requires, before, after, conflicts, schedulerflags, functions); my_modules = lx_environment_unbind (my_modules, name); my_modules = lx_environment_bind (my_modules, name, module); mod_functions = lx_environment_unbind (mod_functions, name); mod_functions = lx_environment_bind (mod_functions, name, functiondata); mod_metadata = lx_environment_unbind (mod_metadata, name); mod_metadata = lx_environment_bind (mod_metadata, name, cons (binary, pidfile)); kyu_command (cons (sym_update, cons (native_system, cons (module, sx_end_of_list)))); } } else if (eofp (sx)) { open_config_files--; if (open_config_files == 0) { update_status_from_pid_files (); kyu_command (cons (sym_initialised, cons (sym_server_seteh, sx_end_of_list))); } } }