int main() { int fd; ssize_t size; char buf[128]; fd = open("in", O_RDWR); // contents: hellomaomao assert(fd >= 0); PLL(lseek(fd, 0, SEEK_CUR)); // 0 size = pread(fd, buf, 6, 1); // file pos is not changed! assert(size >= 0); PL(size); print_str(buf, 6); PLL(lseek(fd, 0, SEEK_CUR)); // still 0 size = read(fd, buf, 6); assert(size >= 0); PL(size); print_str(buf, 6); PLL(lseek(fd, 0, SEEK_CUR)); // 6 close(fd); return 0; }
void plotter::plot() { std::vector<PLFLT> xs, ys, zs; unsigned int size = hist.rows * hist.cols; xs.reserve( size ); ys.reserve( size ); zs.reserve( size ); for( int y = 0; y < hist.rows; ++y ) for( int x = 0; x < hist.cols; ++x ) if( hist( y, x ) > 0.0 ) { xs.push_back( (PLFLT)x ); ys.push_back( (PLFLT)y ); zs.push_back( (PLFLT)hist( y, x ) ); } PL().col0( 15 ); // white PL().poin3( ys.size(), &xs[0], &ys[0], &zs[0], 1 ); }
void plotter::toPlot( cv::Mat_<double> h ) { hist = h; xm2d = -(hist.cols / 2); xM2d = hist.cols / 2; ym2d = -(hist.rows / 2); yM2d = hist.rows / 2; xm = 0; xM = hist.cols; ym = 0; yM = hist.rows; basex = 15; basey = 15; height = 25; PL().col0( 1 ); PL().env( xm2d, xM2d, ym2d, yM2d, just, style ); PL().w3d( basex, basey, height, xm, xM, ym, yM, zm, zM, alt, az ); PL().box3( "bnt", "X", 0, 0, "bnt", "Y", 0, 0, "bnst", "Z", 1.0, 2.0 ); }
void GEMENI_charsent() { unsigned long r = s->log[s->lc]; if (UCA0IFG & UCTXIFG) { s->nch++; switch (s->nch) { case 1: UCA0TXBUF = SL(r) << 5 |TL(r)<<4|KL(r)<<3|PL(r)<<2|WL(r)<<1|HL(r); break; case 2: UCA0TXBUF = RL(r)<<6 | AL(r)<<5 | OL(r)<<4 | STAR(r)<<3; break; case 3: UCA0TXBUF = ER(r)<<3 | UR(r)<<2 | FR(r)<<1 | RR(r); break; case 4: UCA0TXBUF = PR(r)<<6 | BR(r)<<5 | LR(r)<<4 | GR(r)<<3 | TR(r)<<2 | SR(r)<<1 | DRS(r); break; case 5: UCA0TXBUF = POUND(r)<<1 | ZRS(r); break; default: s->lc++; if (s->lc != s->nc-1) { s->nch = 0; UCA0TXBUF = 1 << 7; // first packet, no fn or '#' } else { s->flags &= ~CSEND; } } } }
int main() { //freopen("in.txt","r",stdin); n=2;ll int T;SL(T); while(T--) { // powe=powe+1; SL(powe) SL(powe2);if(powe==0 && powe2 ==0){ puts("0"); continue;} /*for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>mat.a[i][j]; if(i==j){id.a[i][j]=1;}else{id.a[i][j]=0;} } }*/ mat.a[0][0]=1; mat.a[0][1]=1; mat.a[1][0]=1; mat.a[1][1]=0; matrix ans2,ans3,ans4,ans5; ans2=power(mat,powe+2-1-1); ans3=power(mat,powe2+2-1); //ans4=power(mat,powe2-powe+1);ans4.a[0][0]+=1; //ans5=power(mat,powe2-powe); ll int ret; //CO(ans2.a[0][0]<<" "<<ans3.a[0][0]<<" "<<ans4.a[0][0]<<" "<<ans5.a[0][0]) ret=(ans3.a[0][0]-ans2.a[0][0])%M;ret=(ret+M)%M; if(powe==0 ) {--ret;} /*for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cout<<ans2.a[i][j]<<" "; } cout<<endl; } }*/ //ret=((((ans2.a[0][0]+ans2.a[1][0])*1)%M)+(ans2.a[0][1]*0)%M)%M; //CO(ret<<" till "<<powe) //ll int ret2; //ret2=((((ans3.a[0][0]+ans3.a[1][0])*2)%M)+(ans3.a[0][1]*1)%M); PL(ret); } return 0; }
Poly *prim_polys(Prim *s, Poly *p) { int i; Poly *l = plist_alloc(3, p->n); for (i = 0; i < p->n; i++) { PL(l)->v[i] = SL(l)->v[i] = prim_point(s, p->v[i].x, p->v[i].y); NL(l)->v[i] = prim_normal(s, p->v[i].x, p->v[i].y); } return l; }
Poly *prim_polys(Prim *s, Poly *p) { int i; Poly *l = plist_alloc(7, p->n); for (i = 0; i < p->n; i++) { PL(l)->v[i] = SL(l)->v[i] = prim_point(s, p->v[i].x, p->v[i].y); NL(l)->v[i] = prim_normal(s, p->v[i].x, p->v[i].y); TL(l)->v[i] = prim_texc(s, p->v[i].x, p->v[i].y); DUL(l)->v[i] = v3_unit(prim_du(s, p->v[i].x, p->v[i].y)); DVL(l)->v[i] = v3_unit(prim_dv(s, p->v[i].x, p->v[i].y)); } return l; }
void prend(t_env *env, char *message, int fd) { int rsrc; char *buff; rsrc = ft_get_rsrcs(message); buff = tell_graphic_machin(fd, rsrc); if (rsrc == -1 || !env->map[PL(y)][PL(x)].rsrc[rsrc]) { create_message(env, "ko\n", fd, env->what_time_is_it + 7); return ; } env->map[PL(y)][PL(x)].rsrc[rsrc]--; if (rsrc == 0) { srand(time(NULL)); env->map[rand() % env->world->mapy][RANX].rsrc[rsrc]++; env->pl[fd]->live += 126; } env->pl[fd]->rsrc[rsrc] += 1; create_message(env, "ok\n", fd, env->what_time_is_it + 7); tell_graphic(env, buff, 0); }
static int module_init(void) { struct pl pl = PL("pip"); (void)conf_get(conf_cur(), "video_selfview", &pl); if (0 == pl_strcasecmp(&pl, "window")) vidfilt_register(&selfview_win); else if (0 == pl_strcasecmp(&pl, "pip")) vidfilt_register(&selfview_pip); (void)conf_get_vidsz(conf_cur(), "selfview_size", &selfview_size); return 0; }
int main() { int res; int fd; ssize_t size; fd = open("in", O_RDWR); assert(fd >= 0); res = lseek(fd, 100, SEEK_END); PD(res); size = write(fd, "mao", 3); PL(size); close(fd); return 0; }
int test_md5(void) { const struct pl str = PL("a93akjshdla81mx.kjda09sdkjl12jdlksaldkjas"); const uint8_t ref[16] = { 0x9d, 0x97, 0xa5, 0xf8, 0x8d, 0x1b, 0x09, 0x7c, 0x9f, 0xf9, 0xe2, 0x9d, 0xd5, 0x43, 0xb1, 0x1d }; uint8_t digest[16]; int err; /* Test constants */ if (16 != MD5_SIZE) { DEBUG_WARNING("MD5_SIZE is %u (should be 16)\n", MD5_SIZE); return EINVAL; } if (33 != MD5_STR_SIZE) { DEBUG_WARNING("MD5_STR_SIZE is %u (should be 33)\n", MD5_STR_SIZE); return EINVAL; } /* Test md5() */ md5((const uint8_t *)str.p, str.l, digest); if (0 != memcmp(digest, ref, sizeof(digest))) { DEBUG_WARNING("md5 b0Rken: %02w\n", digest, sizeof(digest)); return EINVAL; } /* Test md5_printf() */ err = md5_printf(digest, "%r", &str); if (err) goto out; if (0 != memcmp(digest, ref, sizeof(digest))) { DEBUG_WARNING("md5_printf() is b0Rken: %02w\n", digest, sizeof(digest)); return EINVAL; } out: return err; }
static void udp_recv(const struct sa *src, struct mbuf *mbrx, void *arg) { static struct pl cmd = PL(""); static char buf[32]; bool done = false; struct mbuf *mb; (void)arg; if (!re_regex((char *)mbrx->buf, mbrx->end, "[^\n]+", &cmd)) { cmd.l = MIN(cmd.l, sizeof(buf)); memcpy(buf, cmd.p, cmd.l); cmd.p = buf; } mb = mbuf_alloc(8192); if (!mb) return; restund_cmd(&cmd, mb); mb->pos = 0; while (!done) { struct mbuf mbtx; mbtx.buf = mbuf_buf(mb); mbtx.pos = 0; mbtx.end = mb->buf - mbtx.buf + mb->end; if (mbtx.end > CHUNK_SIZE) mbtx.end = CHUNK_SIZE; else done = true; udp_send(stg.us, src, &mbtx); mb->pos += mbtx.end; } mb = mem_deref(mb); }
int Arbitre::checkDoubleThree(Vector<int> const &pos, char const * const *map, int color, bool recursive) { int nb3 = 0; if (!recursive && map[pos.y][pos.x] != color) return (0); // horizontal #define R(p, c) ((pos.x + p) < 19 && map[pos.y][pos.x + p] == c) #define NR(p) ((pos.x + p) >= 19 || map[pos.y][pos.x + p] != color) #define PR(p) Vector<int>(pos.x + p, pos.y), map, color, false #define L(p, c) ((pos.x - p) >= 0 && map[pos.y][pos.x - p] == c) #define NL(p) ((pos.x - p) < 0 || map[pos.y][pos.x - p] != color) #define PL(p) Vector<int>(pos.x - p, pos.y), map, color, false if (L(1, 0)) if (R(1, color)) { if (R(2, color) && R(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(2)) - 2 : 0); else if (R(2, 0) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(3)) - 2 : 0); } else if (R(1, 0) && R(2, color) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(2)) + checkDoubleThree(PR(3)) - 2 : 0); if (R(1, 0)) if (L(1, color)) { if (L(2, color) && L(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(2)) - 2 : 0); else if (L(2, 0) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(3)) - 2 : 0); } else if (L(1, 0) && L(2, color) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PL(3)) - 2 : 0); if (L(2, 0)) { if (R(2, 0) && L(1, color) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(1)) - 2 : 0); else if (R(3, 0) && L(1, color) && R(1, 0) && R(2, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(2)) - 2 : 0); } else if (L(3, 0) && R(2, 0) && L(2, color) && L(1, 0) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PR(1)) - 2 : 0); #undef R #undef NR #undef PR #undef L #undef NL #undef PL // vertical #define R(p, c) ((pos.y + p) < 19 && map[pos.y + p][pos.x] == c) #define NR(p) ((pos.y + p) >= 19 || map[pos.y + p][pos.x] != color) #define PR(p) Vector<int>(pos.x, pos.y + p), map, color, false #define L(p, c) ((pos.y - p) >= 0 && map[pos.y - p][pos.x] == c) #define NL(p) ((pos.y - p) < 0 || map[pos.y - p][pos.x] != color) #define PL(p) Vector<int>(pos.x, pos.y - p), map, color, false if (L(1, 0)) if (R(1, color)) { if (R(2, color) && R(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(2)) - 2 : 0); else if (R(2, 0) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(3)) - 2 : 0); } else if (R(1, 0) && R(2, color) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(2)) + checkDoubleThree(PR(3)) - 2 : 0); if (R(1, 0)) if (L(1, color)) { if (L(2, color) && L(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(2)) - 2 : 0); else if (L(2, 0) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(3)) - 2 : 0); } else if (L(1, 0) && L(2, color) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PL(3)) - 2 : 0); if (L(2, 0)) { if (R(2, 0) && L(1, color) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(1)) - 2 : 0); else if (R(3, 0) && L(1, color) && R(1, 0) && R(2, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(2)) - 2 : 0); } else if (L(3, 0) && R(2, 0) && L(2, color) && L(1, 0) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PR(1)) - 2 : 0); #undef R #undef NR #undef PR #undef L #undef NL #undef PL // Diago 1 #define R(p, c) ((pos.x + p) < 19 && (pos.y + p) < 19 && map[pos.y + p][pos.x + p] == c) #define NR(p) ((pos.x + p) >= 19 || (pos.y + p) >= 19 || map[pos.y + p][pos.x + p] != color) #define PR(p) Vector<int>(pos.x + p, pos.y + p), map, color, false #define L(p, c) ((pos.x - p) >= 0 && (pos.y - p) >= 0 && map[pos.y - p][pos.x - p] == c) #define NL(p) ((pos.x - p) < 0 || (pos.y - p) < 0 || map[pos.y - p][pos.x - p] != color) #define PL(p) Vector<int>(pos.x - p, pos.y - p), map, color, false if (L(1, 0)) if (R(1, color)) { if (R(2, color) && R(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(2)) - 2 : 0); else if (R(2, 0) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(3)) - 2 : 0); } else if (R(1, 0) && R(2, color) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(2)) + checkDoubleThree(PR(3)) - 2 : 0); if (R(1, 0)) if (L(1, color)) { if (L(2, color) && L(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(2)) - 2 : 0); else if (L(2, 0) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(3)) - 2 : 0); } else if (L(1, 0) && L(2, color) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PL(3)) - 2 : 0); if (L(2, 0)) { if (R(2, 0) && L(1, color) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(1)) - 2 : 0); else if (R(3, 0) && L(1, color) && R(1, 0) && R(2, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(2)) - 2 : 0); } else if (L(3, 0) && R(2, 0) && L(2, color) && L(1, 0) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PR(1)) - 2 : 0); #undef R #undef NR #undef PR #undef L #undef NL #undef PL // Diago 2 #define R(p, c) ((pos.x - p) >= 0 && (pos.y + p) < 19 && map[pos.y + p][pos.x - p] == c) #define NR(p) ((pos.x - p) < 0 || (pos.y + p) >= 19 || map[pos.y + p][pos.x - p] != color) #define PR(p) Vector<int>(pos.x - p, pos.y + p), map, color, false #define L(p, c) ((pos.x + p) < 19 && (pos.y - p) >= 0 && map[pos.y - p][pos.x + p] == c) #define NL(p) ((pos.x + p) >= 19 || (pos.y - p) < 0 || map[pos.y - p][pos.x + p] != color) #define PL(p) Vector<int>(pos.x + p, pos.y - p), map, color, false if (L(1, 0)) if (R(1, color)) { if (R(2, color) && R(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(2)) - 2 : 0); else if (R(2, 0) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(1)) + checkDoubleThree(PR(3)) - 2 : 0); } else if (R(1, 0) && R(2, color) && R(3, color) && R(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PR(2)) + checkDoubleThree(PR(3)) - 2 : 0); if (R(1, 0)) if (L(1, color)) { if (L(2, color) && L(3, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(2)) - 2 : 0); else if (L(2, 0) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PL(3)) - 2 : 0); } else if (L(1, 0) && L(2, color) && L(3, color) && L(4, 0)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PL(3)) - 2 : 0); if (L(2, 0)) { if (R(2, 0) && L(1, color) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(1)) - 2 : 0); else if (R(3, 0) && L(1, color) && R(1, 0) && R(2, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(1)) + checkDoubleThree(PR(2)) - 2 : 0); } else if (L(3, 0) && R(2, 0) && L(2, color) && L(1, 0) && R(1, color)) nb3 += 1 + (recursive ? checkDoubleThree(PL(2)) + checkDoubleThree(PR(1)) - 2 : 0); #undef R #undef NR #undef PR #undef L #undef NL #undef PL return (nb3); }
static void generate_powerpc_thunks(void) { // check_load_invoc() thunk uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC); uint32 base; static uint32 get_resource_template[] = { PL(0x7c0802a6), // mflr r0 PL(0x90010008), // stw r0,8(r1) PL(0x9421ffbc), // stwu r1,-68(r1) PL(0x90610038), // stw r3,56(r1) PL(0x9081003c), // stw r4,60(r1) PL(0x00000000), // lwz r0,XLM_GET_RESOURCE(r0) PL(0x80402834), // lwz r2,XLM_RES_LIB_TOC(r0) PL(0x7c0903a6), // mtctr r0 PL(0x4e800421), // bctrl PL(0x90610040), // stw r3,64(r1) PL(0x80610038), // lwz r3,56(r1) PL(0xa881003e), // lha r4,62(r1) PL(0x80a10040), // lwz r5,64(r1) PL(0x00000001), // <check_load_invoc> PL(0x80610040), // lwz r3,64(r1) PL(0x8001004c), // lwz r0,76(r1) PL(0x7c0803a6), // mtlr r0 PL(0x38210044), // addi r1,r1,68 PL(0x4e800020) // blr }; const uint32 get_resource_template_size = sizeof(get_resource_template); int xlm_index = -1, check_load_invoc_index = -1; for (int i = 0; i < get_resource_template_size/4; i++) { uint32 opcode = ntohl(get_resource_template[i]); switch (opcode) { case 0x00000000: xlm_index = i; break; case 0x00000001: check_load_invoc_index = i; break; } } assert(xlm_index != -1 && check_load_invoc_index != -1); // GetResource() get_resource_func = base = SheepMem::Reserve(get_resource_template_size); Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // Get1Resource() get_1_resource_func = base = SheepMem::Reserve(get_resource_template_size); Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // GetIndResource() get_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size); Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_IND_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // Get1IndResource() get_1_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size); Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_IND_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // RGetResource() r_get_resource_func = base = SheepMem::Reserve(get_resource_template_size); Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_R_GET_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // named_check_load_invoc() thunk check_load_invoc_opcode = NativeOpcode(NATIVE_NAMED_CHECK_LOAD_INVOC); static uint32 get_named_resource_template[] = { PL(0x7c0802a6), // mflr r0 PL(0x90010008), // stw r0,8(r1) PL(0x9421ffbc), // stwu r1,-68(r1) PL(0x90610038), // stw r3,56(r1) PL(0x9081003c), // stw r4,60(r1) PL(0x00000000), // lwz r0,XLM_GET_NAMED_RESOURCE(r0) PL(0x80402834), // lwz r2,XLM_RES_LIB_TOC(r0) PL(0x7c0903a6), // mtctr r0 PL(0x4e800421), // bctrl PL(0x90610040), // stw r3,64(r1) PL(0x80610038), // lwz r3,56(r1) PL(0x8081003c), // lwz r4,60(r1) PL(0x80a10040), // lwz r5,64(r1) PL(0x00000001), // <named_check_load_invoc> PL(0x80610040), // lwz r3,64(r1) PL(0x8001004c), // lwz r0,76(r1) PL(0x7c0803a6), // mtlr r0 PL(0x38210044), // addi r1,r1,68 PL(0x4e800020) // blr }; const uint32 get_named_resource_template_size = sizeof(get_named_resource_template); xlm_index = -1, check_load_invoc_index = -1; for (int i = 0; i < get_resource_template_size/4; i++) { uint32 opcode = ntohl(get_resource_template[i]); switch (opcode) { case 0x00000000: xlm_index = i; break; case 0x00000001: check_load_invoc_index = i; break; } } assert(xlm_index != -1 && check_load_invoc_index != -1); // GetNamedResource() get_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size); Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_NAMED_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); // Get1NamedResource() get_1_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size); Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size); WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_NAMED_RESOURCE); WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); }
PX(my::search_parser(R"(\d+)", "abc1234")); PX(my::search_parser(R"((\d+))", "abc1234")); PL(); PX(my::search_parser(R"((\d+)/(\d+))", "24/7")); PX(my::search_parser(R"((\d+)/(\d+))", "24/7")); PL(); PX(my::match_parser (R"((\d+)/(\d+))", "a24/7z")); PX(my::match_parser (R"((\d+)/(\d+))", "a24/7z")); PX(my::search_parser(R"(^(\d+)/(\d+)$)", "a24/7z")); PX(my::match_parser (R"(.*(\d+)/(\d+).*)", "a24/7z")); PL(); PX(my::match_parser (R"(([a-z]+)=(\d+/\d+))", "a=24/7")); PX(my::match_parser (R"(([a-z]+)=(\d+/\d+))", "a=")); PX(my::match_parser (R"(([a-z]+)=(\d+/\d+)?)", "a=24/7")); PX(my::match_parser (R"(([a-z]+)=(\d+/\d+)?)", "a=")); PL(); PX(my::match_parser (R"(([a-z]+)=(\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))", "a=24.5/.7")); PX(my::match_parser (R"(([a-z]+)=(\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))", "a=")); PL(); PX(my::match_parser (R"(([a-z]+)=((\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))?)", "a=24.5/.7")); PX(my::match_parser (R"(([a-z]+)=((\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))?)", "a=")); PL(); PX(my::match_parser (R"(([a-z]+)=(?:(\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))?)", "a=24.5/.7")); PX(my::match_parser (R"(([a-z]+)=(?:(\d+[.]\d*|\d*[.]\d+)/(\d+[.]\d*|\d*[.]\d+))?)", "a=")); } namespace my { std::string regex_replacer(const std::string &r, std::string t, const std::string s) { return "\"" + srx::regex_replace(s, srx::regex{r}, t) + "\""; } }
/** * @function main */ int main( int argc, char* argv[] ) { /// Read image if( argc < 3 ) { printf("You moron! I need at least two images \n"); return -1; } /// Load images as they are cv::Mat L = cv::imread( argv[1], -1 ); cv::Mat R = cv::imread( argv[2], -1 ); // Have ready my Pyramid and LK object Pyramid pyr; LK lk; // Hierarchical LK int n = 4; // Max level int k; // Get the required pyramid levels std::vector<cv::Mat> PL(n+1); std::vector<cv::Mat> PR(n+1); PL[0] = L.clone(); PR[0] = R.clone(); for( int i = 1; i <= n; i++ ) { PL[i] = pyr.Reduce( PL[i-1] ); PR[i] = pyr.Reduce( PR[i-1] ); } /// Let's start the real thing cv::Mat Lk, Rk; cv::Mat U, V; cv::Mat Dx, Dy; cv::Mat Wk; cv::Mat Wkg, Rkg, Lkg; /// 1. Initialize k = n k = n; while( k >= 0 ) { /// 2. Reduce both images to level k Lk = PL[k]; Rk = PR[k]; /// 3. If k = n initialize U and K to zeros of the size of Lk if( k == n ) { U = cv::Mat::zeros( Lk.size(), CV_32FC1 ); V = cv::Mat::zeros( Lk.size(), CV_32FC1 ); } /// Else expand the flow field and double it else { cv::Mat tempU, tempV; tempU = pyr.ExpandFloat(U); tempV = pyr.ExpandFloat(V); U = cv::Mat( tempU.size(), CV_32FC1 ); V = cv::Mat( tempV.size(), CV_32FC1 ); for( int j = 0; j < U.rows; j++ ) { for( int i = 0; i < U.cols; i++ ) { U.at<float>(j,i) = ( 2.0*tempU.at<float>(j,i) ); V.at<float>(j,i) = ( 2.0*tempV.at<float>(j,i) ); } } } /// 4. Warp Lk using U and V to form Wk Wk = lk.Remap2to1( Rk, U, V ); char buf[30]; sprintf( buf, "Wk%d.png", k); imwrite( buf, Wk ); /// 5. Perform LK on Wk and Rk cvtColor( Wk, Wkg, CV_BGR2GRAY ); cvtColor( Lk, Lkg, CV_BGR2GRAY ); cvtColor( Rk, Rkg, CV_BGR2GRAY ); //lk.OpticFlowEstimation1( Lkg, Wkg, Dx, Dy, 2.0 ); //lk.OpticFlowEstimation3( Lkg, Wkg, Dx, Dy, 2.0 ); /// 6. Add these to the original flow for( int j = 0; j < U.rows; j++ ) { for( int i = 0; i < U.cols; i++ ) { U.at<float>(j,i) = U.at<float>(j,i) + Dx.at<float>(j,i); V.at<float>(j,i) = V.at<float>(j,i) + Dy.at<float>(j,i); } } cv::Mat temp = lk.Remap2to1( Rk, U, V ); sprintf( buf, "Wk%dend.png", k); imwrite( buf, temp ); k = k - 1; } // end of while cv::Mat mU, mV; lk.DrawMotionArrows3( U, V, mU, mV ); cv::Mat remap; remap = lk.Remap2to1( R, U, V ); cv::Mat remapg; cvtColor( remap, remapg, CV_BGR2GRAY ); cv::Mat diffRemap; diffRemap = lk.GetDiff( remapg, L ); cv::Mat diff21; diff21 = lk.GetDiff( L, R ); /// Write images imwrite("proj5-3-1-U.png", mU ); imwrite("proj5-3-1-V.png", mV ); imwrite("proj5-3-1-remap.png", remap ); imwrite("proj5-3-1-diffRemap.png", diffRemap ); //imwrite("proj5-3-1-diff21.png", diff21 ); // Show results cv::namedWindow("U", CV_WINDOW_NORMAL ); cv::namedWindow("V", CV_WINDOW_NORMAL ); cv::namedWindow("Remap 2 to 1", CV_WINDOW_NORMAL ); cv::namedWindow("Diff Image", CV_WINDOW_NORMAL ); cv::namedWindow("21Diff", CV_WINDOW_NORMAL ); imshow( "U", mU ); imshow( "V", mV ); imshow( "Remap 2 to 1", remap ); imshow( "Diff Image", diffRemap ); imshow( "21Diff", diff21 ); cv::waitKey(0); return 0; }
int main(int argc, char **argv); extern char *__progname; #define P(c) 1,0x90,c,0x7f,4,0x80,c,0 #define PL(c) 1,0x90,c,0x7f,8,0x80,c,0 #define C 0x3c #define D 0x3e #define E 0x40 #define F 0x41 u_char sample[] = { 'M','T','h','d', 0,0,0,6, 0,1, 0,1, 0,8, 'M','T','r','k', 0,0,0,4+13*8, P(C), P(C), P(C), P(E), P(D), P(D), P(D), P(F), P(E), P(E), P(D), P(D), PL(C), 0, 0xff, 0x2f, 0 }; #undef P #undef PL #undef C #undef D #undef E #undef F #define MARK_HEADER "MThd" #define MARK_TRACK "MTrk" #define MARK_LEN 4 #define SIZE_LEN 4 #define HEADER_LEN 6
#define DEBUG_MODULE "test_stun" #define DEBUG_LEVEL 5 #include <re_dbg.h> #define NATTED (true) /* * Test vectors from RFC 5769 */ static const uint8_t tid[] = "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae"; static const char *username = "******"; static const struct pl password = PL("VOkJxbRl1RmTxUk/WvJxBt"); static const unsigned char req[] = "\x00\x01\x00\x58" "\x21\x12\xa4\x42" "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" "\x80\x22\x00\x10" "STUN test client" "\x00\x24\x00\x04" "\x6e\x00\x01\xff" "\x80\x29\x00\x08" "\x93\x2f\xf9\xb1\x51\x26\x3b\x36" "\x00\x06\x00\x09" "\x65\x76\x74\x6a\x3a\x68\x36\x76\x59\x20\x20\x20" "\x00\x08\x00\x14" "\x9a\xea\xa7\x0c\xbf\xd8\xcb\x56\x78\x1e\xf2\xb5"