static int v4l_suspend(vbi_capture_v4l *v) { int fd; v4l_read_stop(v); if (v->read_active) { printv("Suspending read: re-open device...\n"); /* hack: cannot suspend read to allow SVBIFMT, need to close device */ fd = device_open (v->capture.sys_log_fp, v->p_dev_name, O_RDWR, 0); if (-1 == fd) { printv ("v4l2-suspend: failed to re-open " "VBI device: %d: %s\n", errno, strerror(errno)); return -1; } /* use dup2() to keep the same fd, which may be used by our client */ device_close (v->capture.sys_log_fp, v->fd); dup2 (fd, v->fd); device_close (v->capture.sys_log_fp, fd); v->read_active = FALSE; } return 0; }
int main() try{ //input std::cout << "Input a string: "; std::string s; std::getline(std::cin, s); if (!std::cin){ throw std::runtime_error("input fail"); } std::string w; std::cout << "Input whitespace: "; std::getline(std::cin, w); if (!std::cin){ throw std::runtime_error("input fail"); } //output std::cout << "split:" << std::endl; printv(split(s)); std::cout << "split (with w):" << std::endl; printv(split(s, w)); return 0; } catch (std::runtime_error& e){ std::cerr << "Error: " << e.what() << std::endl; return 1; } catch (...){ std::cerr << "Unknown error!" << std::endl; return 2; }
void check_copied_tags(struct radix_tree_root *tree, unsigned long start, unsigned long end, unsigned long *idx, int count, int fromtag, int totag) { int i; for (i = 0; i < count; i++) { /* if (i % 1000 == 0) putchar('.'); */ if (idx[i] < start || idx[i] > end) { if (item_tag_get(tree, idx[i], totag)) { printv(2, "%lu-%lu: %lu, tags %d-%d\n", start, end, idx[i], item_tag_get(tree, idx[i], fromtag), item_tag_get(tree, idx[i], totag)); } assert(!item_tag_get(tree, idx[i], totag)); continue; } if (item_tag_get(tree, idx[i], fromtag) ^ item_tag_get(tree, idx[i], totag)) { printv(2, "%lu-%lu: %lu, tags %d-%d\n", start, end, idx[i], item_tag_get(tree, idx[i], fromtag), item_tag_get(tree, idx[i], totag)); } assert(!(item_tag_get(tree, idx[i], fromtag) ^ item_tag_get(tree, idx[i], totag))); } }
void print(int num[],int total,int s){ int c,r; int i,j,k; c = 2*s; r = 2*s+3; for(i=0;i<r;i++){ for(j=total-1;j>=0;j--){ if(i==0||i==s+1||i==2*s+2){ if(i==0) print_horizon(num[j],0,s); else if(i==s+1) print_horizon(num[j],3,s); else print_horizon(num[j],6,s); } else { if(i-s<=0.0){ printv(num[j],1,2,s); }else { printv(num[j],4,5,s); } } if(j!=0)printf(" "); } printf("\n"); } }
inline void pair_print( container *C, value v ) { printf("("); printv(((pair_container_priv*)C->priv)->A, pair(v).first); printf(":"); printv(((pair_container_priv*)C->priv)->B, pair(v).second); printf(")"); }
int main(int argc, char *argv[]) { int arr[9] = {5,17,3,10,84,19,6,22,9}; int heap[5]; printv(arr, 9); k_smallest(arr, 9, heap, 5); printv(heap, 5); getchar(); return 0; }
void cos_init(void) { cbuf_t cbs[MAX_CBUFS]; int szs[MAX_CBUFS]; char *bufs[MAX_CBUFS]; int i; printc("UNIT TEST Unit tests for cbufs...\n"); for (i = 0 ; i < MAX_CBUFS ; i++) { int sz = (rand() % MAX_CBUF_SZ) + 1; bufs[i] = cbuf_alloc(sz, &cbs[i]); printv("UNIT TEST alloc %d -> %p\n", sz, bufs[i]); assert(bufs[i]); cbuf_free(bufs[i]); printv("UNIT TEST free %p\n", bufs[i]); } printc("UNIT TEST PASSED: alloc->dealloc\n"); for (i = 0 ; i < MAX_CBUFS ; i++) { int sz = (rand() % MAX_CBUF_SZ) + 1; bufs[i] = cbuf_alloc(sz, &cbs[i]); printv("UNIT TEST alloc %d -> %p\n", sz, bufs[i]); assert(bufs[i]); } for (i = 0 ; i < MAX_CBUFS ; i++) { cbuf_free(bufs[i]); printv("UNIT TEST free %p\n", bufs[i]); } printc("UNIT TEST PASSED: N alloc -> N dealloc\n"); for (i = 0 ; i < MAX_CBUFS ; i++) { int sz = (rand() % MAX_CBUF_SZ) + 1; bufs[i] = cbuf_alloc(sz, &cbs[i]); printv("UNIT TEST alloc %d -> %p\n", sz, bufs[i]); szs[i] = sz; assert(bufs[i]); bufs[i][0] = '_'; unit_cbuf(cbs[i], sz); assert(bufs[i][0] == '*'); printv("UNIT TEST cbuf2buf %d\n", sz); } printc("UNIT TEST PASSED: N alloc + cbuf2buf\n"); for (i = 0 ; i < MAX_CBUFS ; i++) { bufs[i][0] = '_'; unit_cbuf(cbs[i], szs[i]); printv("UNIT TEST cbuf2buf %d\n", szs[i]); } printc("UNIT TEST PASSED: N cached cbuf2buf\n"); for (i = 0 ; i < MAX_CBUFS ; i++) { cbuf_free(bufs[i]); printv("UNIT TEST free %p\n", bufs[i]); } printc("UNIT TEST PASSED: N deallocs\n"); printc("UNIT TEST ALL PASSED\n"); return; }
static int learn_expand_or_one(struct solver_state *s, int w, int h) { const int sz = w * h; int i; int learn = FALSE; assert(s); for (i = 0; i < sz; ++i) { int j; int one = TRUE; if (s->board[i] != EMPTY) continue; for (j = 0; j < 4; ++j) { const int x = (i % w) + dx[j]; const int y = (i / w) + dy[j]; const int idx = w*y + x; if (x < 0 || x >= w || y < 0 || y >= h) continue; if (s->board[idx] == EMPTY) { one = FALSE; continue; } if (one && (s->board[idx] == 1 || (s->board[idx] >= expandsize(s->board, s->dsf, w, h, i, s->board[idx])))) one = FALSE; assert(s->board[i] == EMPTY); s->board[i] = -SENTINEL; if (check_capacity(s->board, w, h, idx)) continue; assert(s->board[i] == EMPTY); printv("learn: expanding in one\n"); expand(s, w, h, i, idx); learn = TRUE; break; } if (j == 4 && one) { printv("learn: one at (%d, %d)\n", i % w, i / w); assert(s->board[i] == EMPTY); s->board[i] = 1; assert(s->nempty); --s->nempty; learn = TRUE; } } return learn; }
void THIS::init(parent_t * const & p) { printv_func(DEBUG); setParent(p); auto app = get_fnd_app(); if(app->G::has_object()) if(!G::has_object()) G::make_object<THIS, int>( app->get_graphics_plugin(), neb::fnd::plug::gfx::core::shape::type::CUBOID); if(app->P::has_object()) { if(P::has_object()) { printv(DEBUG, "phx plugin not null\n"); } else { P::make_object<THIS, int>( app->get_physics_plugin(), neb::fnd::plug::phx::core::shape::type::CUBOID); } } neb::fnd::core::shape::base::init(p); //neb::gfx::core::shape::base::init(p); //neb::gfx::core::shape::box::init(p); //neb::phx::core::shape::base::init(p); //neb::phx::core::shape::box::init(p); //neb::fin::core::shape::base::init(p); }
void neb::gfx::Viewport::load() { printv_func(DEBUG); printv(DEBUG, "x %i y %i w %i h %i\n", x_, y_, w_, h_); glViewport(x_, y_, w_, h_); }
static int learn_critical_square(struct solver_state *s, int w, int h) { const int sz = w * h; int i; int learn = FALSE; assert(s); /* for each connected component */ for (i = 0; i < sz; ++i) { int j; if (s->board[i] == EMPTY) continue; if (i != dsf_canonify(s->dsf, i)) continue; if (dsf_size(s->dsf, i) == s->board[i]) continue; assert(s->board[i] != 1); /* for each empty square */ for (j = 0; j < sz; ++j) { if (s->board[j] != EMPTY) continue; s->board[j] = -SENTINEL; if (check_capacity(s->board, w, h, i)) continue; /* if not expanding s->board[i] to s->board[j] implies * that s->board[i] can't reach its full size, ... */ assert(s->nempty); printv( "learn: ds %d at (%d, %d) blocking (%d, %d)\n", s->board[i], j % w, j / w, i % w, i / w); --s->nempty; s->board[j] = s->board[i]; filled_square(s, w, h, j); learn = TRUE; } } return learn; }
static void print_board(int *board, int w, int h) { if (verbose) { char *repr = board_to_string(board, w, h); printv("%s\n", repr); free(repr); } }
/* * Test 1 * */ void provaCalcS(){ printf("halloo, probando probando!!\n"); vector pc = zerov(2); vector pcPrimes = zerov(2); matrix S = zerom(2, 3); pc.v[0] = 50; pc.v[1] = 200; //Test in matlab //S = [ 0 0.0003495 0.002; 0.0018 0.0338 0.0207]; S.m[0][0] = 0; S.m[0][1] = 0.0003495; S.m[0][2] = 0.002; S.m[1][0] = 0.0018; S.m[1][1] = 0.0338; S.m[1][2] = 0.0207; int numPrimes = (int)(pc.v[pc.x - 1] / pc.v[0]); intvector numsPrimesReason = primes(numPrimes); int i, j; for(i = 0; i < numsPrimesReason.x; ++i){ printf("i: %d\n", numsPrimesReason.v[i]); int primeNum = numsPrimesReason.v[i]; for(j = 0; j < pcPrimes.x; ++j){ pcPrimes.v[j] = pc.v[j] * primeNum; } printf("\nArray pcPrimes:\n"); printv(pcPrimes); matrix SnInterp = interp1Mat(pc, pcPrimes, S, 0); printf("\nResult S\n"); printm(SnInterp); } }
void THIS::step( gal::etc::timestep const & ts) { printv(DEBUG, "%s\n", __PRETTY_FUNCTION__); neb::fnd::core::shape::util::parent::step(ts); neb::fnd::core::light::util::parent::step(ts); }
int main(void) { int x, y; int cs, st; srand((unsigned)(time(NULL))); setlocale(LC_ALL, "zh_TW.UTF-8"); while(1) { x=1, y=1+(int)(20.*rand()/(1.+RAND_MAX)); printf("\x1b[2J"); while(x<=70) { cs=(int)(2.*rand()/(1.+RAND_MAX)); if(cs) { st=(int)(2.*rand()/(1.+RAND_MAX)); if(y==20){ st=0; } else if(y==1){ st=1; } printv(&x, &y, st); } else { printf("\x1b[%d;%dH%lc", y, x, linec[0]); pwhite(x, y+1); x+=1; } } } return 0; }
/* * Enumerate over all elements in a container. */ static void * enum_start(void *arg) { char *err; uint64_t num = 0; fdf.ctr_t *ctr = arg; zs_iter_t *iter = zs_iter_init(ctr, &err); if (!iter) die_err(err, "zs_iter_init failed"); for (;;) { char *key; char *data; uint64_t keylen; uint64_t datalen; int s = zs_iter_next(iter, &key, &keylen, &data, &datalen, &err); if (s < 0) die_err(err, "zs_iter_next failed"); if (s == 0) break; num++; } if (!zs_iter_done(iter, &err)) die_err(err, "zs_iter_done failed"); if (num != Objects) die("enumerated %ld/%ld objects", num, Objects); printv("enumerated %ld/%ld objects", num, Objects); return NULL; }
int create_buffer(int i) { /* DO NOT CALL ANY MARKS FUNCTIONS HERE */ int ret = -1; int fd = open_rdrw(); if (fd < 0) { ret = 4; goto end; } ret = ioctl(fd, CRYPTO_IOCCREATE, 0); if (ret < 0) { fprintf(stderr, "ioctl(CRYPTO_IOCCREATE) #%d", i); printe(""); ret = 5; goto end; } printv("Created buffer with id %d\n", ret); ret = 0; end: if (fd >= 0) { close(fd); } return ret; }
int main(int argc, char *argv[]) { float a[] = {12, -7.5, 6.5, -3, -8, 7.5}; aranjare(a, 6); printv(a, 6); return 0; }
print(const char *a, ...) { __builtin_va_list l; __builtin_va_start(l, a); int const t = printv(a, l); __builtin_va_end(l); return t; }
int main() { std::vector<int> vi = {1, 9, 8, 8}; std::list<int> li1 = {1, 9, 8, 9}; std::list<int> li2 = {1, 9, 8}; std::list<int> li3 = {1, 9, 8, 8}; std::string joinstr; int cmp = compare(vi, li1); if (cmp == 0) joinstr = " == "; else if (cmp > 0) joinstr = " > "; else joinstr = " < "; printv(vi); std::cout << joinstr; printl(li1); std::cout << std::endl; cmp = compare(vi, li2); if (cmp == 0) joinstr = " == "; else if (cmp > 0) joinstr = " > "; else joinstr = " < "; printv(vi); std::cout << joinstr; printl(li2); std::cout << std::endl; cmp = compare(vi, li3); if (cmp == 0) joinstr = " == "; else if (cmp > 0) joinstr = " > "; else joinstr = " < "; printv(vi); std::cout << joinstr; printl(li3); std::cout << std::endl; return 0; }
int main(int argc, char *argv[]) { int n = 10; int mask[16]; /* Guess what this is */ int i; for (i = 0; i < n; ++i) mask[i] = 0; /* Print the first set */ printv(mask, n); /* Print all the others */ while (next(mask, n)) printv(mask, n); return 0; }
void wiggleSort(std::vector<int>& V) { for (int i = 1; i < V.size(); ++i) { if (((i&1) && V[i] < V[i-1]) || (!(i&1) && V[i-1] < V[i])) std::swap(V[i], V[i-1]); printf("%d : ", i); printv(V); } }
inline void map_print( container *C, value a ) { int i=0; iterator it = map_begin(a.C); printf("("); for (; it.valid; it=map_next(it)) { if (i==0) i++; else printf(" "); printv(((map_container_priv*)C->priv)->Key, map_key(it)); printf(":"); printv(((map_container_priv*)C->priv)->Data, map_val(it)); } printf(")"); }
void FileSystem::saveDirectory(FileList *fileList, File dir, int level, char *match) { printv("Opening directory ", dir.name()); int files = 0; // count how many files are there while (true) { File entry = dir.openNextFile(); if (!entry) break; if (!entry.isDirectory()) files++; entry.close(); } printv("Files found: ", files); dir.rewindDirectory(); delay(10); if ((fileList->files = (char **) malloc(files * sizeof(char *))) == NULL) { Serial.println("Can't allocate RAM"); return; } fileList->allocated = files; for (int i = 0; i < fileList->allocated; i++) { if ((fileList->files[i] = (char *) malloc(FAT32_FILENAME_LENGTH)) == NULL) { Serial.println("Can't allocate RAM"); return; } } while (true) { File entry = dir.openNextFile(); if (!entry) break; if (!entry.isDirectory()) { if (strstr(entry.name(), match) != NULL) { strcpy(fileList->files[fileList->size++], entry.name()); } } entry.close(); } sprintf(buf, "loaded %d files from directory %s", files, dir.name()); Serial.println(buf); }
int main() { std::vector<int> V = {1, 1, 0, 3, 4, 5, 1, 0, 5, 5, 3, 1, 2, 2, 2, 2}; bubble_sort(V); printv(V); return 0; }
static void single_thread_tests(bool long_run) { int i; printv(1, "starting single_thread_tests: %d allocated, preempt %d\n", nr_allocated, preempt_count); multiorder_checks(); rcu_barrier(); printv(2, "after multiorder_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); tag_check(); rcu_barrier(); printv(2, "after tag_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); gang_check(); rcu_barrier(); printv(2, "after gang_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); add_and_check(); rcu_barrier(); printv(2, "after add_and_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); dynamic_height_check(); rcu_barrier(); printv(2, "after dynamic_height_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); idr_checks(); ida_tests(); rcu_barrier(); printv(2, "after idr_checks: %d allocated, preempt %d\n", nr_allocated, preempt_count); big_gang_check(long_run); rcu_barrier(); printv(2, "after big_gang_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); for (i = 0; i < (long_run ? 2000 : 3); i++) { copy_tag_check(); printv(2, "%d ", i); fflush(stdout); } rcu_barrier(); printv(2, "after copy_tag_check: %d allocated, preempt %d\n", nr_allocated, preempt_count); }
int main (){ int vetor[] = {3,5,2,1,4,8,1}; int k = 1; ordena(vetor, 7, k); printv(vetor,7); std::cout << k << " menor elemento é " << vetor[k-1] << std::endl; }
void HMM::print_parameters() { std::cout << "initial distribution:" << std::endl; printv(hs, nu); std::cout << "transition distribution:" << std::endl; printm(hs, hs, Q); std::cout << "emission distribution:" << std::endl; printm(hs, os, g); }
void big_gang_check(bool long_run) { int i; for (i = 0; i < (long_run ? 1000 : 3); i++) { __big_gang_check(); printv(2, "%d ", i); fflush(stdout); } }
int main() { std::vector<int> V = {1, 5, 4, 3, 2, 10, 7, 6, 8, 9}; bucket_sort(V); printv(V); return 0; }