/** @brief The workhorse thread of the test. * * This thread recursively spawns two copies of itself decrementing n_voidstar * so long as n_voidstar is positive. Each thread repeats this process n_throws * times, after joining on the threads it created. * * @param The level we are at (to keep us from infinitly recursively spawning. */ void *juggle(void * n_voidstar) { int sub1, sub2; int throws; int substat; int ret; int n = (int)n_voidstar; inc_count(); print_count(n); if (n > 0) { for (throws = 0; throws < n_throws; throws++) { // Toss up two balls sub1 = thr_create(juggle, (void *)(n - 1)); if (sub1 < 0) { lprintf("Lev %d failed to create first thread w/ err %d\n", n, sub1); } sub2 = thr_create(juggle, (void *)(n - 1)); if (sub2 < 0) { lprintf("Lev %d failed to create second thread w/ err %d\n", n, sub2); } // Try to catch them if ((ret = thr_join(sub1, (void*)&substat)) != 0 || substat != (n - 1)) { lprintf("Lev %d failed to join first thread correctly:\n\t", n); lprintf("join(%d), ret = %d, %d ?= %d\n", sub1, ret, (n - 1), substat); } if ((ret = thr_join(sub2, (void*)&substat)) != 0 || substat != (n - 1)) { lprintf("Lev %d failed to join second thread correctly:\n\t", n); lprintf("join(%d), ret = %d, %d ?= %d\n", sub2, ret, (n - 1), substat); } } } #ifdef PRINT // Tell that we were successfull. putchar((char)n + '0'); #endif print_count(n); // Hang in the air for some amount of time sleep(genrand() % SLEEP_MAX); return (void *)n; }
static void print_count(struct search_text *t) { if (t->left) print_count(t->left); #ifdef COUNT_TOKEN_FREQ printf("%d\t%s\n", t->count, t->token); #endif if (t->right) print_count(t->right); }
int main(int argc, char **argv) { int width, height; mpz_t index; if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: %s width height [index]\n", argv[0]); return EX_USAGE; } width = atoi(argv[1]); height = atoi(argv[2]); if (width <= 0 || height <= 0) { fprintf(stderr, "Usage: %s width height [index]\n", argv[0]); fprintf(stderr, "width and height must be positive\n"); return EX_USAGE; } if (argc == 3) { print_count(width, height); return 0; } /* Construct a maze by index */ mpz_init(index); gmp_sscanf(argv[3], "%Zd", &index); print_maze(width, height, index); mpz_clear(index); return 0; }
int main (int argc, char **argv) { program_name = basename (argv[0]); struct options opts = {false, false, false, 0, NULL}; struct counts totals = {0, 0, 0}; scan_options (argc, argv, &opts); if (opts.file_count == 0) { count_file (stdin, NULL, &opts, &totals); }else { for (int filenr = 0; filenr < opts.file_count; ++filenr) { char *filename = opts.file_names[filenr]; if (strcmp (filename, stdin_name) == 0) { count_file (stdin, filename, &opts, &totals); }else { FILE *file = fopen (filename, "r"); if (file == NULL) { error ("%s: %s", filename, strerror (errno)); }else { count_file (file, filename, &opts, &totals); fclose (file); } } } if (opts.file_count > 1) print_count (&opts, &totals, "total"); } return exit_status; }
int main ( void ) { int i; for ( i = 10; i > 0; --i) print_count(i); return 0; }
/* * tagsearch: execute tag search * * i) pattern search pattern * i) cwd current directory * i) root root of source tree * i) dbpath database directory * i) db GTAGS,GRTAGS,GSYMS */ void tagsearch(const char *pattern, const char *cwd, const char *root, const char *dbpath, int db) { int count, total = 0; char libdbpath[MAXPATHLEN]; /* * search in current source tree. */ count = search(pattern, root, cwd, dbpath, db); total += count; /* * search in library path. */ if (db == GTAGS && getenv("GTAGSLIBPATH") && (count == 0 || Tflag) && !lflag) { STRBUF *sb = strbuf_open(0); char *libdir, *nextp = NULL; strbuf_puts(sb, getenv("GTAGSLIBPATH")); /* * search for each tree in the library path. */ for (libdir = strbuf_value(sb); libdir; libdir = nextp) { if ((nextp = locatestring(libdir, PATHSEP, MATCH_FIRST)) != NULL) *nextp++ = 0; if (!gtagsexist(libdir, libdbpath, sizeof(libdbpath), 0)) continue; if (!strcmp(dbpath, libdbpath)) continue; if (!test("f", makepath(libdbpath, dbname(db), NULL))) continue; /* * search again */ count = search(pattern, libdir, cwd, libdbpath, db); total += count; if (count > 0 && !Tflag) { /* for verbose message */ dbpath = libdbpath; break; } } strbuf_close(sb); } if (vflag) { print_count(total); if (!Tflag) fprintf(stderr, " (using '%s')", makepath(dbpath, dbname(db), NULL)); fputs(".\n", stderr); } }
void print_replica_exchange_statistics(FILE *fplog, struct gmx_repl_ex *re) { int i; fprintf(fplog, "\nReplica exchange statistics\n"); if (re->nex == 0) { fprintf(fplog, "Repl %d attempts, %d odd, %d even\n", re->nattempt[0]+re->nattempt[1], re->nattempt[1], re->nattempt[0]); fprintf(fplog, "Repl average probabilities:\n"); for (i = 1; i < re->nrepl; i++) { if (re->nattempt[i%2] == 0) { re->prob[i] = 0; } else { re->prob[i] = re->prob_sum[i]/re->nattempt[i%2]; } } print_ind(fplog, "", re->nrepl, re->ind, NULL); print_prob(fplog, "", re->nrepl, re->prob); fprintf(fplog, "Repl number of exchanges:\n"); print_ind(fplog, "", re->nrepl, re->ind, NULL); print_count(fplog, "", re->nrepl, re->nexchange); fprintf(fplog, "Repl average number of exchanges:\n"); for (i = 1; i < re->nrepl; i++) { if (re->nattempt[i%2] == 0) { re->prob[i] = 0; } else { re->prob[i] = ((real)re->nexchange[i])/re->nattempt[i%2]; } } print_ind(fplog, "", re->nrepl, re->ind, NULL); print_prob(fplog, "", re->nrepl, re->prob); fprintf(fplog, "\n"); } /* print the transition matrix */ print_transition_matrix(fplog, re->nrepl, re->nmoves, re->nattempt); }
void print_replica_exchange_statistics(FILE *fplog,struct gmx_repl_ex *re) { real *prob; int i; fprintf(fplog,"\nReplica exchange statistics\n"); fprintf(fplog,"Repl %d attempts, %d odd, %d even\n", re->nattempt[0]+re->nattempt[1],re->nattempt[1],re->nattempt[0]); snew(prob,re->nrepl); fprintf(fplog,"Repl average probabilities:\n"); for(i=1; i<re->nrepl; i++) { if (re->nattempt[i%2] == 0) { prob[i] = 0; } else { prob[i] = re->prob_sum[i]/re->nattempt[i%2]; } } print_ind(fplog,"",re->nrepl,re->ind,NULL); print_prob(fplog,"",re->nrepl,prob); fprintf(fplog,"Repl number of exchanges:\n"); print_ind(fplog,"",re->nrepl,re->ind,NULL); print_count(fplog,"",re->nrepl,re->nexchange); fprintf(fplog,"Repl average number of exchanges:\n"); for(i=1; i<re->nrepl; i++) { if (re->nattempt[i%2] == 0) { prob[i] = 0; } else { prob[i] = ((real)re->nexchange[i])/re->nattempt[i%2]; } } print_ind(fplog,"",re->nrepl,re->ind,NULL); print_prob(fplog,"",re->nrepl,prob); sfree(prob); fprintf(fplog,"\n"); }
static int count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags, size_t exclude_tags_length, int output, int print_lastmod) { char *line = NULL; ssize_t line_len; size_t line_size; int ret = 0; while (! ret && (line_len = getline (&line, &line_size, input)) != -1) { chomp_newline (line); ret = print_count (notmuch, line, exclude_tags, exclude_tags_length, output, print_lastmod); } if (line) free (line); return ret; }
void count_file (FILE *file, const char *filename, struct options *opts, struct counts *totals) { if (! is_plain_file (file, filename)) return; struct counts file_counts = {0, 0, 0}; bool spaces = true; for (;;) { int byte = fgetc (file); if (byte == EOF) break; ++file_counts.chars; if (byte == '\n') ++file_counts.lines; if (isspace (byte)) { spaces = true; }else if (spaces) { ++file_counts.words; spaces = false; } } print_count (opts, &file_counts, filename); totals->lines += file_counts.lines; totals->words += file_counts.words; totals->chars += file_counts.chars; }
/** * grep: @NAME{grep} pattern * * @param[in] pattern @NAME{POSIX} regular expression * @param argv * @param dbpath */ void grep(const char *pattern, char *const *argv, const char *dbpath) { FILE *fp; CONVERT *cv; GFIND *gp = NULL; STRBUF *ib = strbuf_open(MAXBUFLEN); const char *path; char encoded_pattern[IDENTLEN]; const char *buffer; int linenum, count; int flags = 0; int target = GPATH_SOURCE; regex_t preg; int user_specified = 1; /* * convert spaces into %FF format. */ encode(encoded_pattern, sizeof(encoded_pattern), pattern); /* * literal search available? */ if (!literal) { const char *p = pattern; int normal = 1; for (; *p; p++) { if (!(isalpha(*p) || isdigit(*p) || isblank(*p) || *p == '_')) { normal = 0; break; } } if (normal) literal = 1; } if (oflag) target = GPATH_BOTH; if (Oflag) target = GPATH_OTHER; if (literal) { literal_comple(pattern); } else { if (!Gflag) flags |= REG_EXTENDED; if (iflag) flags |= REG_ICASE; if (regcomp(&preg, pattern, flags) != 0) die("invalid regular expression."); } cv = convert_open(type, format, root, cwd, dbpath, stdout, NOTAGS); cv->tag_for_display = encoded_pattern; count = 0; if (*argv && file_list) args_open_both(argv, file_list); else if (*argv) args_open(argv); else if (file_list) args_open_filelist(file_list); else { args_open_gfind(gp = gfind_open(dbpath, localprefix, target)); user_specified = 0; } while ((path = args_read()) != NULL) { if (user_specified) { static char buf[MAXPATHLEN]; if (normalize(path, get_root_with_slash(), cwd, buf, sizeof(buf)) == NULL) { warning("'%s' is out of the source project.", path); continue; } if (test("d", buf)) { warning("'%s' is a directory. Ignored.", path); continue; } if (!test("f", buf)) { warning("'%s' not found. Ignored.", path); continue; } path = buf; } if (Sflag && !locatestring(path, localprefix, MATCH_AT_FIRST)) continue; if (literal) { int n = literal_search(cv, path); if (n > 0) count += n; } else { if (!(fp = fopen(path, "r"))) die("cannot open file '%s'.", path); linenum = 0; while ((buffer = strbuf_fgets(ib, fp, STRBUF_NOCRLF)) != NULL) { int result = regexec(&preg, buffer, 0, 0, 0); linenum++; if ((!Vflag && result == 0) || (Vflag && result != 0)) { count++; if (format == FORMAT_PATH) { convert_put_path(cv, NULL, path); break; } else { convert_put_using(cv, pattern, path, linenum, buffer, (user_specified) ? NULL : gp->dbop->lastdat); } } } fclose(fp); } } args_close(); convert_close(cv); strbuf_close(ib); if (literal == 0) regfree(&preg); if (vflag) { print_count(count); fprintf(stderr, " (no index used).\n"); } }
static int pre_it(DECL_ARGS) { const struct roff_node *bln; switch (n->type) { case ROFFT_HEAD: outflags |= MMAN_PP | MMAN_nl; bln = n->parent->parent; if (0 == bln->norm->Bl.comp || (NULL == n->parent->prev && NULL == bln->parent->prev)) outflags |= MMAN_sp; outflags &= ~MMAN_br; switch (bln->norm->Bl.type) { case LIST_item: return 0; case LIST_inset: case LIST_diag: case LIST_ohang: if (bln->norm->Bl.type == LIST_diag) print_line(".B \"", 0); else print_line(".BR \\& \"", 0); outflags &= ~MMAN_spc; return 1; case LIST_bullet: case LIST_dash: case LIST_hyphen: print_width(&bln->norm->Bl, NULL); TPremain = 0; outflags |= MMAN_nl; font_push('B'); if (LIST_bullet == bln->norm->Bl.type) print_word("\\(bu"); else print_word("-"); font_pop(); outflags |= MMAN_nl; return 0; case LIST_enum: print_width(&bln->norm->Bl, NULL); TPremain = 0; outflags |= MMAN_nl; print_count(&bln->norm->Bl.count); outflags |= MMAN_nl; return 0; case LIST_hang: print_width(&bln->norm->Bl, n->child); TPremain = 0; outflags |= MMAN_nl; return 1; case LIST_tag: print_width(&bln->norm->Bl, n->child); putchar('\n'); outflags &= ~MMAN_spc; return 1; default: return 1; } default: break; } return 1; }
int main(void) { print_count(0, 2, 99999999, 1000); return 0; }
// Function to perform the monte carlo integration void monte_carlo(frame &anim, double threshold, double box_length){ // Creating random numbers with mt19937 static std::random_device rd; int seed = rd(); static std::mt19937 gen(seed); // integer to hold the max number our vectors should count to int vec_count = 1, prev_print_count = 0; // Creating vector to hold points for visualization later std::vector<pos> points(1024); std::vector<color> pt_clrs(1024), area_clrs(1024), pe_clrs(1024); color pt_clr, area_clr, pe_clr; double count_in = 0; double ratio; std::vector<double> area(1024), pe_vec(1024); //double true_area = circle_area(0.5 * box_length); double true_area = batman_area(anim.res_x * 0.03); double temp_area; //double container_area = box_length * box_length; pos oval_radius; oval_radius.x = box_length / 2.0; oval_radius.y = box_length / 4.0; double container_area = oval_area(oval_radius); // distribution for box std::uniform_real_distribution<double> box_dist(-0.5,0.5); // distribution for oval? //std::uniform_real_distribution<double> oval_dist; // defining location of dot pos loc; // pe is the percent error -- setting arbitrarily high for now... double pe = 10; std::cout << "performing monte_carlo..." << '\n'; // number of generations to wor with int iterations = 200; int final_count = 1; for (int i = 0; i < iterations; ++i){ if (final_count < 1024){ final_count *= 2; } else{ final_count += 1024; } } //while (abs(pe) > threshold){ for (int count = 1; count < final_count; ++count){ loc.x = box_dist(gen) * box_length + anim.origin.x; loc.y = box_dist(gen) * box_length + anim.origin.y; //while (!in_square(loc, box_length, anim.origin)){ while(!in_oval(loc, oval_radius, anim.origin)){ //std::cout << "regenerating point" << '\n'; loc.x = box_dist(gen) * box_length + anim.origin.x; loc.y = box_dist(gen) * box_length + anim.origin.y; } if (is_batman(loc, anim.origin, anim.res_x * 0.03)){ count_in += 1; pt_clr.b = 0.0; pt_clr.g = 0.0; pt_clr.r = 0.0; } else{ pt_clr.b = 0.0; pt_clr.g = 1.0; pt_clr.r = 1.0; } /* // Color scheme for circle if (in_circle(anim, loc, box_length/2)){ count_in += 1; pt_clr.b = 0.0; pt_clr.g = 1.0; pt_clr.r = 0.0; } else{ pt_clr.b = 0.0; pt_clr.g = 0.0; pt_clr.r = 1.0; } */ //points.push_back(loc); points[count - prev_print_count - 1] = loc; //std::cout << count - prev_print_count << '\t' // << points[count - prev_print_count - 1].x << '\t' // << points[count - prev_print_count - 1].y << '\n'; //pt_clrs.push_back(pt_clr); pt_clrs[count - prev_print_count - 1] = pt_clr; temp_area = (((double)count_in/(double)count)*container_area); ratio = ((double)count_in/(double)count); //area.push_back(temp_area); pe = (temp_area - true_area) / true_area; //pe_vec.push_back(abs(pe)); if (abs(pe) < threshold){ area_clr.r = 0; area_clr.g = 1; area_clr.b = 0; pe_clr.r = 0; pe_clr.g = 1; pe_clr.b = 0; } if (abs(pe) >= threshold){ area_clr.r = 1; area_clr.g = 0; area_clr.b = 0; pe_clr.r = 1; pe_clr.g = 0; pe_clr.b = 0; } //area_clrs.push_back(area_clr); //pe_clrs.push_back(pe_clr); /* draw_point(anim, loc, pt_clr); if (anim.curr_frame + 1 < num_frames){ anim.curr_frame++; } */ if (count - prev_print_count == vec_count){ //std::cout << "printing..." << '\n'; for (int j = 0; j < vec_count; ++j){ draw_point(anim, points[j], pt_clrs[j]); //std::cout << points[j].x << '\t' << points[j].y << '\n'; } print_area(anim, ratio, area_clr); print_pe(anim, abs(pe), pe_clr); print_count(anim, count); if (vec_count < 1024){ vec_count *= 2; } if (anim.curr_frame + 1 < num_frames){ anim.curr_frame++; } prev_print_count = count; } //std::cout << count << '\t' << vec_count << '\t' // << prev_print_count << '\t' << temp_area // << '\t' << pe << '\n'; //std::cout << count << '\n'; } //std::cout << anim.curr_frame << '\n'; }
void Pass1(int argc, char *argv[]) { register int n; InitText(argc); InitTokenArray(); /* assume all texts to be new */ NumberOfNewTexts = NumberOfTexts; /* read the files */ for (n = 0; n < NumberOfTexts; n++) { register char *fname = argv[n]; register struct text *txt = &Text[n]; fprintf(OutputFile, "File %s: ", fname); txt->tx_fname = fname; txt->tx_pos = 0; txt->tx_start = txt->tx_limit = TextLength(); if (strcmp(fname, "/") == 0) { fprintf(OutputFile, "separator\n"); NumberOfNewTexts = n; } else { if (!OpenText(First, txt)) { fprintf(OutputFile, ">>>> cannot open <<<< "); /* the file has still been opened with a null file for uniformity */ } while (NextTextTokenObtained(First)) { if (!TOKEN_EQ(lex_token, EOL)) { StoreToken(); } } CloseText(First, txt); txt->tx_limit = TextLength(); /* report */ print_count(txt->tx_limit - txt->tx_start, "token"); if (lex_non_ascii_cnt) { fprintf(DebugFile, ", "); print_count(lex_non_ascii_cnt, "non-ASCII character" ); } fprintf(OutputFile, "\n"); #ifdef DB_TEXT db_print_text(txt); #endif /* DB_TEXT */ } fflush(OutputFile); } /* report total */ fprintf(OutputFile, "Total: "); print_count(TextLength() - 1, "token"); fprintf(OutputFile, "\n\n"); fflush(OutputFile); }
/* * grep: grep pattern * * i) pattern POSIX regular expression */ void grep(const char *pattern, char *const *argv, const char *dbpath) { FILE *fp; CONVERT *cv; GFIND *gp = NULL; STRBUF *ib = strbuf_open(MAXBUFLEN); const char *path; char encoded_pattern[IDENTLEN]; const char *buffer; int linenum, count; int flags = 0; int target = GPATH_SOURCE; regex_t preg; int user_specified = 1; /* * convert spaces into %FF format. */ encode(encoded_pattern, sizeof(encoded_pattern), pattern); if (oflag) target = GPATH_BOTH; if (Oflag) target = GPATH_OTHER; if (!Gflag) flags |= REG_EXTENDED; if (iflag) flags |= REG_ICASE; if (regcomp(&preg, pattern, flags) != 0) die("invalid regular expression."); cv = convert_open(type, format, root, cwd, dbpath, stdout); count = 0; if (*argv && file_list) args_open_both(argv, file_list); else if (*argv) args_open(argv); else if (file_list) args_open_filelist(file_list); else { args_open_gfind(gp = gfind_open(dbpath, localprefix, target)); user_specified = 0; } while ((path = args_read()) != NULL) { if (user_specified) { static char buf[MAXPATHLEN]; if (normalize(path, get_root_with_slash(), cwd, buf, sizeof(buf)) == NULL) if (!qflag) fprintf(stderr, "'%s' is out of source tree.\n", path); if (!test("f", buf)) die("'%s' not found. Please remake tag files by invoking gtags(1).", path); path = buf; } if (!(fp = fopen(path, "r"))) die("cannot open file '%s'.", path); linenum = 0; while ((buffer = strbuf_fgets(ib, fp, STRBUF_NOCRLF)) != NULL) { int result = regexec(&preg, buffer, 0, 0, 0); linenum++; if ((!Vflag && result == 0) || (Vflag && result != 0)) { count++; if (format == FORMAT_PATH) { convert_put_path(cv, path); break; } else { convert_put_using(cv, encoded_pattern, path, linenum, buffer, (user_specified) ? NULL : gp->dbop->lastdat); } } } fclose(fp); } args_close(); convert_close(cv); strbuf_close(ib); regfree(&preg); if (vflag) { print_count(count); fprintf(stderr, " (no index used).\n"); } }
/* * idutils: lid(idutils) pattern * * i) pattern POSIX regular expression * i) dbpath GTAGS directory */ void idutils(const char *pattern, const char *dbpath) { FILE *ip; CONVERT *cv; STRBUF *ib = strbuf_open(0); char encoded_pattern[IDENTLEN]; char path[MAXPATHLEN]; const char *lid; int linenum, count; char *p, *q, *grep; lid = usable("lid"); if (!lid) die("lid(idutils) not found."); /* * convert spaces into %FF format. */ encode(encoded_pattern, sizeof(encoded_pattern), pattern); /* * make lid command line. * Invoke lid with the --result=grep option to generate grep format. */ strbuf_puts(ib, lid); strbuf_sprintf(ib, " --file='%s/ID'", dbpath); strbuf_puts(ib, " --separator=newline"); if (format == FORMAT_PATH) strbuf_puts(ib, " --result=filenames --key=none"); else strbuf_puts(ib, " --result=grep"); if (iflag) strbuf_puts(ib, " --ignore-case"); strbuf_putc(ib, ' '); strbuf_puts(ib, quote_string(pattern)); if (debug) fprintf(stderr, "idutils: %s\n", strbuf_value(ib)); if (!(ip = popen(strbuf_value(ib), "r"))) die("cannot execute '%s'.", strbuf_value(ib)); cv = convert_open(type, format, root, cwd, dbpath, stdout); count = 0; strcpy(path, "./"); while ((grep = strbuf_fgets(ib, ip, STRBUF_NOCRLF)) != NULL) { q = path + 2; /* extract path name */ if (*grep == '/') die("The path in the output of lid is assumed absolute. '%s'", grep); p = grep; while (*p && *p != ':') *q++ = *p++; *q = '\0'; if ((xflag || tflag) && !*p) die("invalid lid(idutils) output format(1). '%s'", grep); p++; if (lflag) { if (!locatestring(path, localprefix, MATCH_AT_FIRST)) continue; } count++; switch (format) { case FORMAT_PATH: convert_put_path(cv, path); break; default: /* extract line number */ while (*p && isspace(*p)) p++; linenum = 0; for (linenum = 0; *p && isdigit(*p); linenum = linenum * 10 + (*p++ - '0')) ; if (*p != ':') die("invalid lid(idutils) output format(2). '%s'", grep); if (linenum <= 0) die("invalid lid(idutils) output format(3). '%s'", grep); p++; /* * print out. */ convert_put_using(cv, encoded_pattern, path, linenum, p, NULL); break; } } if (pclose(ip) < 0) die("terminated abnormally."); convert_close(cv); strbuf_close(ib); if (vflag) { print_count(count); fprintf(stderr, " (using idutils index in '%s').\n", dbpath); } }
void parsefile(char *const *argv, const char *cwd, const char *root, const char *dbpath, int db) { int count = 0; int file_count = 0; STRBUF *sb = strbuf_open(0); char *langmap; const char *plugin_parser, *av; char path[MAXPATHLEN]; struct parsefile_data data; if (db == GRTAGS + GSYMS) data.target = TARGET_REF|TARGET_SYM; else data.target = 1 << db; data.extractmethod = getconfb("extractmethod"); if (getconfs("langmap", sb)) langmap = check_strdup(strbuf_value(sb)); else langmap = NULL; strbuf_reset(sb); if (getconfs("gtags_parser", sb)) plugin_parser = strbuf_value(sb); else plugin_parser = NULL; data.cv = convert_open(type, format, root, cwd, dbpath, stdout); if (gpath_open(dbpath, 0) < 0) die("GPATH not found."); if (data.target == TARGET_REF || data.target == TARGET_SYM) { data.dbop = dbop_open(makepath(dbpath, dbname(GTAGS), NULL), 0, 0, 0); if (data.dbop == NULL) die("%s not found.", dbname(GTAGS)); } else { data.dbop = NULL; } data.fid = NULL; parser_init(langmap, plugin_parser); if (langmap != NULL) free(langmap); if (*argv && file_list) args_open_both(argv, file_list); else if (*argv) args_open(argv); else if (file_list) args_open_filelist(file_list); else args_open_nop(); while ((av = args_read()) != NULL) { /* * convert the path into relative to the root directory of source tree. */ if (normalize(av, get_root_with_slash(), cwd, path, sizeof(path)) == NULL) if (!qflag) fprintf(stderr, "'%s' is out of source tree.\n", path + 2); /* * Memorize the file id of the path. This is used in put_syms(). */ { static char s_fid[MAXFIDLEN]; const char *p = gpath_path2fid(path, NULL); if (!p) { if (!qflag) fprintf(stderr, "'%s' not found in GPATH.\n", path + 2); continue; } strlimcpy(s_fid, p, sizeof(s_fid)); data.fid = s_fid; } if (!test("f", makepath(root, path, NULL))) { if (test("d", NULL)) { if (!qflag) fprintf(stderr, "'%s' is a directory.\n", av); } else { if (!qflag) fprintf(stderr, "'%s' not found.\n", av); } continue; } if (lflag && !locatestring(path, localprefix, MATCH_AT_FIRST)) continue; data.count = 0; parse_file(path, 0, put_syms, &data); count += data.count; file_count++; } args_close(); parser_exit(); /* * Settlement */ if (data.dbop != NULL) dbop_close(data.dbop); gpath_close(); convert_close(data.cv); strbuf_close(sb); if (vflag) { print_count(count); fprintf(stderr, " (no index used).\n"); } }
/** * tagsearch: execute tag search * * @param[in] pattern search pattern * @param[in] cwd current directory * @param[in] root root of source tree * @param[in] dbpath database directory * @param[in] db #GTAGS,#GRTAGS,#GSYMS */ void tagsearch(const char *pattern, const char *cwd, const char *root, const char *dbpath, int db) { int count, total = 0; char buffer[IDENTLEN], *p = buffer; char libdbpath[MAXPATHLEN]; /* * trim pattern (^<no regex>$ => <no regex>) */ if (pattern) { strlimcpy(p, pattern, sizeof(buffer)); if (*p++ == '^') { char *q = p + strlen(p); if (*--q == '$') { *q = 0; if (*p == 0 || !isregex(p)) pattern = p; } } } /* * search in current source tree. */ count = search(pattern, root, cwd, dbpath, db); total += count; /* * search in library path. */ if (abslib) type = PATH_ABSOLUTE; if (db == GTAGS && getenv("GTAGSLIBPATH") && (count == 0 || Tflag) && !Sflag) { STRBUF *sb = strbuf_open(0); char *libdir, *nextp = NULL; strbuf_puts(sb, getenv("GTAGSLIBPATH")); /* * search for each tree in the library path. */ for (libdir = strbuf_value(sb); libdir; libdir = nextp) { if ((nextp = locatestring(libdir, PATHSEP, MATCH_FIRST)) != NULL) *nextp++ = 0; if (!gtagsexist(libdir, libdbpath, sizeof(libdbpath), 0)) continue; if (!strcmp(dbpath, libdbpath)) continue; if (!test("f", makepath(libdbpath, dbname(db), NULL))) continue; /* * search again */ count = search(pattern, libdir, cwd, libdbpath, db); total += count; if (count > 0 && !Tflag) { /* for verbose message */ dbpath = libdbpath; break; } } strbuf_close(sb); } if (vflag) { print_count(total); if (!Tflag) fprintf(stderr, " (using '%s')", makepath(dbpath, dbname(db), NULL)); fputs(".\n", stderr); } }
int main() { // Initialize the encoders encoders_init(IO_D2, IO_D3, IO_A3, IO_A2); float count = 0; char forward = TRUE; int motor_speed = 100; //set_motors(100, 255); while(1) { clear(); lcd_goto_xy(0,0); //Calculate the count count = encoders_get_counts_m1() / ENCODER_COUNT_PER_REVOLUTION; // Increment and decrement speed if top or bottom buttons were pressed. unsigned char button = get_single_debounced_button_press(ANY_BUTTON); if ((button & TOP_BUTTON) && motor_speed < 250) // if top button pressed motor_speed = motor_speed + 5; if ((button & BOTTOM_BUTTON) && motor_speed > 80) // if bottom button pressed motor_speed = motor_speed - 5; //If the user is holding the middle button we want to stop the motor. if(button_is_pressed(MIDDLE_BUTTON) & MIDDLE_BUTTON) { print("Paused "); set_motors(0,0); } else { // Set motor speed dependent on direction. if(forward) { set_motors(motor_speed, 0); print("Forward "); } else { set_motors(-motor_speed, 0); print("Reverse "); } // At 0 and 2 we need to switch directions. if(count >= 2 && forward) forward = FALSE; if(count <= 0 && !forward) forward = TRUE; } // Print the motor speed and revolutions print_long(motor_speed); print_count(count); //Delay so LCD doesn't flicker too much delay_ms(50); } }
static int pre_it(DECL_ARGS) { const struct mdoc_node *bln; switch (n->type) { case MDOC_HEAD: outflags |= MMAN_PP | MMAN_nl; bln = n->parent->parent; if (0 == bln->norm->Bl.comp || (NULL == n->parent->prev && NULL == bln->parent->prev)) outflags |= MMAN_sp; outflags &= ~MMAN_br; switch (bln->norm->Bl.type) { case LIST_item: return(0); case LIST_inset: /* FALLTHROUGH */ case LIST_diag: /* FALLTHROUGH */ case LIST_ohang: if (bln->norm->Bl.type == LIST_diag) print_line(".B \"", 0); else print_line(".R \"", 0); outflags &= ~MMAN_spc; return(1); case LIST_bullet: /* FALLTHROUGH */ case LIST_dash: /* FALLTHROUGH */ case LIST_hyphen: print_width(bln->norm->Bl.width, NULL, 0); TPremain = 0; outflags |= MMAN_nl; font_push('B'); if (LIST_bullet == bln->norm->Bl.type) print_word("o"); else print_word("-"); font_pop(); outflags |= MMAN_nl; return(0); case LIST_enum: print_width(bln->norm->Bl.width, NULL, 0); TPremain = 0; outflags |= MMAN_nl; print_count(&bln->norm->Bl.count); outflags |= MMAN_nl; return(0); case LIST_hang: print_width(bln->norm->Bl.width, n->child, 6); TPremain = 0; outflags |= MMAN_nl; return(1); case LIST_tag: print_width(bln->norm->Bl.width, n->child, 0); putchar('\n'); outflags &= ~MMAN_spc; return(1); default: return(1); } default: break; } return(1); }