// drop a elements from the beginning and b from the end of l void cropList(V p, V l, I a, I b) { L lv=L(l); if (lv->r > 1) { I nl=lv->l-a-b; T t=lv->t; I s=t_sizeof(t); P v=MALLOC(s*next_pow_2(nl)); DO(i,nl) valcpy(v+s*i, LIST_PTR_ATS(lv,i+a,s), t); del(l); setL(p, wrapArray(t, nl, v)); } else { if (a>0) { DO(j,a) del(list_at(lv,a)); } if (b>0) { DO(j,b) del(list_at(lv,lv->l-b+j)); } lv->o = (lv->o+a) % lv->c; lv->l -= a+b; mv_P(p, l); } }
static void handle_name(int sock, char* args) { colour_r = rand () % 256; colour_g = rand () % 256; colour_b = rand () % 256; names[0] = '\0'; state = STATE_REGISTER; alarm(1); clientRegister(); alarm(0); state = STATE_INTERNAL; if ('\0' == names[0]) { char tbuf[80]; sprintf(tbuf, "anon%d", rand() % 10000); valcpy(names, tbuf); } client_printf(sock, "NAME %s\r\n", names); }
void setName(const char* name) { // CLIENT ensure_state(STATE_REGISTER, "setName"); valcpy(names, name); }
bool handler__watch(globals_t * vars, char **argv, unsigned argc) { value_t o, n; unsigned id; char *end = NULL, buf[128], timestamp[64]; time_t t; match_location loc; value_t old_val; void *address; scan_data_type_t data_type = vars->options.scan_data_type; if (argc != 2) { show_error("was expecting one argument, see `help watch`.\n"); return false; } if ((data_type == BYTEARRAY) || (data_type == STRING)) { show_error("`watch` is not supported for bytearray or string.\n"); return false; } /* parse argument */ id = strtoul(argv[1], &end, 0x00); /* check that strtoul() worked */ if (argv[1][0] == '\0' || *end != '\0') { show_error("sorry, couldn't parse `%s`, try `help watch`\n", argv[1]); return false; } loc = nth_match(vars->matches, id); /* check this is a valid match-id */ if (!loc.swath) { show_error("you specified a non-existent match `%u`.\n", id); show_info("use \"list\" to list matches, or \"help\" for other commands.\n"); return false; } address = remote_address_of_nth_element(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); old_val = data_to_val(loc.swath, loc.index /* ,MATCHES_AND_VALUES */); old_val.flags = loc.swath->data[loc.index].match_info; valcpy(&o, &old_val); valcpy(&n, &o); valtostr(&o, buf, sizeof(buf)); if (INTERRUPTABLE()) { (void) detach(vars->target); ENDINTERRUPTABLE(); return true; } /* every entry is timestamped */ t = time(NULL); strftime(timestamp, sizeof(timestamp), "[%T]", localtime(&t)); show_info("%s monitoring %10p for changes until interrupted...\n", timestamp, address); while (true) { if (attach(vars->target) == false) return false; if (peekdata(vars->target, address, &n) == false) return false; truncval(&n, &old_val); /* check if the new value is different */ match_flags tmpflags; zero_match_flags(&tmpflags); scan_routine_t valuecmp_routine = (get_scanroutine(ANYNUMBER, MATCHCHANGED)); if (valuecmp_routine(&o, &n, NULL, &tmpflags, address)) { valcpy(&o, &n); truncval(&o, &old_val); valtostr(&o, buf, sizeof(buf)); /* fetch new timestamp */ t = time(NULL); strftime(timestamp, sizeof(timestamp), "[%T]", localtime(&t)); show_info("%s %10p -> %s\n", timestamp, address, buf); } /* detach after valuecmp_routine, since it may read more data (e.g. bytearray) */ detach(vars->target); (void) sleep(1); } }