Ejemplo n.º 1
0
	vector<Point> outerTrees(vector<Point>& points) {
		auto cmp = [](const Point &p1, const Point &p2) -> bool {
			return p1.x == p2.x ? (p1.y < p2.y) : (p1.x < p2.x);
		};
		sort(points.begin(), points.end(), cmp);

		vector<Point> b, t; // bottom, top
		for (auto &p : points) {
			while (b.size() >= 2 && cross_prod(b[b.size()-2], b[b.size()-1], p) < 0) {
				b.pop_back();
			}
			b.push_back(p);
		}

		for (auto &p : points) {
			while (t.size() >= 2 && cross_prod(t[t.size()-2], t[t.size()-1], p) > 0) {
				t.pop_back();
			}
			t.push_back(p);
		}

		set<Point, decltype(cmp)> uniq(cmp);
		for (auto &p : b) { uniq.insert(p); }
		for (auto &p : t) { uniq.insert(p); }
		vector<Point> ans(uniq.begin(), uniq.end());
		return ans;
	}
Ejemplo n.º 2
0
SummaryConfig::SummaryConfig( const Deck& deck,
                              const Schedule& schedule,
                              const TableManager& tables,
                              const ParseContext& parseContext,
                              const GridDims& dims) {
    SUMMARYSection section( deck );
    for( auto& x : section )
        handleKW( this->keywords, x, schedule, tables, parseContext, dims);

    if( section.hasKeyword( "ALL" ) )
        this->merge( { ALL_keywords, schedule, tables, parseContext, dims} );

    if( section.hasKeyword( "GMWSET" ) )
        this->merge( { GMWSET_keywords, schedule, tables, parseContext, dims} );

    if( section.hasKeyword( "FMWSET" ) )
        this->merge( { FMWSET_keywords, schedule, tables, parseContext, dims} );

    if (section.hasKeyword( "PERFORMA" ) )
        this->merge( { PERFORMA_keywords, schedule, tables, parseContext, dims} );

    uniq( this->keywords );
    for (const auto& kw: this->keywords) {
        this->short_keywords.insert( kw.keyword() );
        this->summary_keywords.insert( kw.gen_key() );
    }

}
Ejemplo n.º 3
0
int main (int argc, char const *const *argv)
{
  genalloc lines = GENALLOC_ZERO ; /* array of stralloc */
  char sep = '\n' ;
  int flagcheck = 0 ;
  PROG = "s6-sort" ;
  {
    subgetopt_t l = SUBGETOPT_ZERO ;
    for (;;)
    {
      register int opt = subgetopt_r(argc, argv, "bcfru0", &l) ;
      if (opt == -1) break ;
      switch (opt)
      {
        case 'b' : flagnoblanks = 1 ; break ;
        case 'c' : flagcheck = 1 ; break ;
        case 'f' : comp = &case_diffb ; break ;
        case 'r' : flagreverse = 1 ; break ;
        case 'u' : flaguniq = 1 ; break ;
        case '0' : sep = '\0' ; break ;
        default : strerr_dieusage(100, USAGE) ;
      }
    }
    argc -= l.ind ; argv += l.ind ;
  }

  if (slurplines(&lines, sep) < 0) strerr_diefu1sys(111, "read from stdin") ;
  
  if (flagcheck) return !check(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)) ;
  qsort(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines), sizeof(stralloc), (qsortcmp_t_ref)&sacmp) ;
  if (flaguniq) uniq(&lines) ;
  if (outputlines(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)) < 0)
    strerr_diefu1sys(111, "write to stdout") ;
  return 0 ;
}
int main()
{
	int x[] = {1, 2, 1, 4, 5, 2, 15, 1, 3, 4};
	int i, len = uniq(x, sizeof(x) / sizeof(x[0]));
	for (i = 0; i < len; i++) printf("%d\n", x[i]);

	return 0;
}
Ejemplo n.º 5
0
SummaryConfig& SummaryConfig::merge( const SummaryConfig& other ) {
    this->keywords.insert( this->keywords.end(),
                            other.keywords.begin(),
                            other.keywords.end() );

    uniq( this->keywords );
    return *this;
}
Ejemplo n.º 6
0
SummaryConfig& SummaryConfig::merge( SummaryConfig&& other ) {
    auto fst = std::make_move_iterator( other.keywords.begin() );
    auto lst = std::make_move_iterator( other.keywords.end() );
    this->keywords.insert( this->keywords.end(), fst, lst );
    other.keywords.clear();

    uniq( this->keywords );
    return *this;
}
Ejemplo n.º 7
0
widget::widget(const char *path, const char *options): handler()
{
	_type = "undefined-widget";
	_parent = NULL;
	// no parent defined
	_path = (path? path: (char *)uniq());
	_options = (options? options: "");
	_seq = "<Button-1>";		// mouseclick as default bindsequence
	created++;
}
Ejemplo n.º 8
0
static int process(const char *fpath_bin, const char *fpath_uniq, const char *fpath_text) {
#if INTERFACE_TYPE == 0
    FILE *fp_bin = fopen(fpath_bin, "r+b");
    if (!fp_bin) return -1;
    fseek(fp_bin, 0, SEEK_END);

//	sel_sort(ftell(fp_bin)/sizeof(rec_t), sizeof(rec_t), fp_bin, rec_stdio_getter, rec_stdio_setter, rec_stdio_cmp);
    heap_sort(ftell(fp_bin)/sizeof(rec_t), sizeof(rec_t), fp_bin, rec_stdio_getter, rec_stdio_setter, rec_stdio_cmp);

    fclose(fp_bin);
#elif INTERFACE_TYPE == 1 || INTERFACE_TYPE == 2 || INTERFACE_TYPE == 3
    int fd_bin = open(fpath_bin, O_RDWR);
    if (fd_bin == -1) return -1;

#if INTERFACE_TYPE == 2
    off_t f_len = lseek(fd_bin, 0, SEEK_END);

    lseek(fd_bin, 0, SEEK_SET);
    rec_t *rec_l = (rec_t*)mmap(NULL, f_len, PROT_WRITE, MAP_SHARED, fd_bin, 0);

    heap_sort(f_len/sizeof(rec_t), sizeof(rec_t), rec_l, rec_mem_getter, rec_mem_setter, rec_mem_cmp);

    munmap(rec_l, f_len);
#elif INTERFACE_TYPE == 3
    off_t f_len = lseek(fd_bin, 0, SEEK_END);
    rec_t *rec_l = (rec_t*)malloc(f_len);

    lseek(fd_bin, 0, SEEK_SET);
    read(fd_bin, rec_l, f_len);

    heap_sort(f_len/sizeof(rec_t), sizeof(rec_t), rec_l, rec_mem_getter, rec_mem_setter, rec_mem_cmp);

    lseek(fd_bin, 0, SEEK_SET);
    write(fd_bin, rec_l, f_len);

    free(rec_l);
#else
    heap_sort(lseek(fd_bin, 0, SEEK_END)/sizeof(rec_t), sizeof(rec_t), (void*)fd_bin, rec_posix_getter, rec_posix_setter, rec_posix_cmp);
#endif

    close(fd_bin);
#endif

    FILE *fp_uniq = uniq(fpath_bin, fpath_uniq);

    write_to_text(fpath_text, fp_uniq);

    fclose(fp_uniq);

    return 0;
}
Ejemplo n.º 9
0
void load_command_list(const char *prefix,
		struct cmdnames *main_cmds,
		struct cmdnames *other_cmds)
{
	const char *env_path = getenv("PATH");
	char *exec_path = get_argv_exec_path();

	if (exec_path) {
		list_commands_in_dir(main_cmds, exec_path, prefix);
		qsort(main_cmds->names, main_cmds->cnt,
		      sizeof(*main_cmds->names), cmdname_compare);
		uniq(main_cmds);
	}

	if (env_path) {
		char *paths, *path, *colon;
		path = paths = strdup(env_path);
		while (1) {
			if ((colon = strchr(path, ':')))
				*colon = 0;
			if (!exec_path || strcmp(path, exec_path))
				list_commands_in_dir(other_cmds, path, prefix);

			if (!colon)
				break;
			path = colon + 1;
		}
		free(paths);

		qsort(other_cmds->names, other_cmds->cnt,
		      sizeof(*other_cmds->names), cmdname_compare);
		uniq(other_cmds);
	}
	free(exec_path);
	exclude_cmds(other_cmds, main_cmds);
}
Ejemplo n.º 10
0
static void
run_search(struct token*toks)
{
  binop_init();
  binop24_init();
  result = evaluate(toks, -1, lm_any, NULL);
  progress("se: result.count == %lu\n", (unsigned long)result.count);

  if (do_uniq && (res_gran == g_word || res_gran == g_grapheme))
    do_uniq = 0;

  if (do_uniq && result.count > 1)
    {
      uniq(&result);
      progress("se: post-uniq result.count == %lu\n", (unsigned long)result.count);
    }
}
Ejemplo n.º 11
0
SummaryConfig::SummaryConfig( const Deck& deck,
                              const Schedule& schedule,
                              const Eclipse3DProperties& props,
                              const ParseContext& parseContext,
                              std::array< int, 3 > n_xyz ) {

    SUMMARYSection section( deck );
    for( auto& x : section )
        handleKW( this->keywords, x, schedule, props, parseContext, n_xyz );

    if( section.hasKeyword( "ALL" ) )
        this->merge( { ALL_keywords, schedule, props, parseContext, n_xyz } );

    uniq( this->keywords );
    for (const auto& kw: this->keywords)
        this->short_keywords.insert( kw.keyword() );
}
Ejemplo n.º 12
0
int
main(int argc, char *argv[])
{
	FILE *fp[2] = { stdin, stdout };
	int ret = 0, i;
	char *fname[2] = { "<stdin>", "<stdout>" };

	ARGBEGIN {
	case 'c':
		countfmt = "%7ld ";
		break;
	case 'd':
		dflag = 1;
		break;
	case 'u':
		uflag = 1;
		break;
	case 'f':
		fskip = estrtonum(EARGF(usage()), 0, INT_MAX);
		break;
	case 's':
		sskip = estrtonum(EARGF(usage()), 0, INT_MAX);
		break;
	default:
		usage();
	} ARGEND;

	if (argc > 2)
		usage();

	for (i = 0; i < argc; i++) {
		if (strcmp(argv[i], "-")) {
			fname[i] = argv[i];
			if (!(fp[i] = fopen(argv[i], (i == 0) ? "r" : "w")))
				eprintf("fopen %s:", argv[i]);
		}
	}

	uniq(fp[0], fp[1]);
	uniqfinish(fp[1]);

	ret |= fshut(fp[0], fname[0]) | fshut(fp[1], fname[1]);

	return ret;
}
Ejemplo n.º 13
0
// Update combo box containing TEXT
static void update_combo_box(Widget text, HistoryFilter filter)
{
    StringArray entries;

    for (int i = gdb_history.size() - 1; i >= 0; i--)
    {
	const string& entry = gdb_history[i];
	string arg = filter(entry);
	if (arg.empty())
	    continue;		// Empty arg

	if (entries.size() > 0 && entries[entries.size() - 1] == arg)
	    continue;		// Adjacent duplicate

	if (app_data.popdown_history_size > 0 &&
	    entries.size() >= int(app_data.popdown_history_size))
	    break;		// Enough entries

	bool found_duplicate = false;
	if (!app_data.sort_popdown_history)
	{
	    // We'll not be sorted.  If we already have this value,
	    // ignore new entry.
	    for (int j = 0; !found_duplicate && j < entries.size(); j++)
		found_duplicate = (entries[j] == arg);
	}
	if (!found_duplicate)
	    entries += arg;
    }

    if (app_data.sort_popdown_history)
    {
	smart_sort(entries);
	uniq(entries);
    }

    ComboBoxSetList(text, entries);
}
Ejemplo n.º 14
0
Archivo: rank.c Proyecto: speark/Study
int main(int argc, char *argv[]){
	int i, j;
	int no;

	i = 0;
	while(fgets(ngram[i], N ,stdin) != NULL){
		if(i >= ITEMNO){
			fprintf(stderr, "ngram이 최대 수에 도달했씁니다.\n");
			break;
		}
		++i;
	}

	qsort(ngram, i, N, (int (*)(const void *, const void *))strcmp);

	no = uniq(i, ngram, result);

	qsort(result, no, N+NUMF,(int (*)(const void *, const void *))rescmp);

	for(j = 0; j<i;++j)printf("%s", result[j]);

	return 0;
}
Ejemplo n.º 15
0
int main()
{
	int x[] = {1, 2, 1, 4, 5, 2, 15, 1, 3, 4};
	int i, len = uniq(x, sizeof(x) / sizeof(x[0]));
	for (i = 0; i &lt; len; i++) printf(&quot;%d\n&quot;, x[i]);
Ejemplo n.º 16
0
Archivo: help.c Proyecto: CSRedRat/git
const char *help_unknown_cmd(const char *cmd)
{
	int i, n, best_similarity = 0;
	struct cmdnames main_cmds, other_cmds;

	memset(&main_cmds, 0, sizeof(main_cmds));
	memset(&other_cmds, 0, sizeof(other_cmds));
	memset(&aliases, 0, sizeof(aliases));

	git_config(git_unknown_cmd_config, NULL);

	load_command_list("git-", &main_cmds, &other_cmds);

	add_cmd_list(&main_cmds, &aliases);
	add_cmd_list(&main_cmds, &other_cmds);
	qsort(main_cmds.names, main_cmds.cnt,
	      sizeof(*main_cmds.names), cmdname_compare);
	uniq(&main_cmds);

	/* This abuses cmdname->len for levenshtein distance */
	for (i = 0, n = 0; i < main_cmds.cnt; i++) {
		int cmp = 0; /* avoid compiler stupidity */
		const char *candidate = main_cmds.names[i]->name;

		/*
		 * An exact match means we have the command, but
		 * for some reason exec'ing it gave us ENOENT; probably
		 * it's a bad interpreter in the #! line.
		 */
		if (!strcmp(candidate, cmd))
			die(_(bad_interpreter_advice), cmd, cmd);

		/* Does the candidate appear in common_cmds list? */
		while (n < ARRAY_SIZE(common_cmds) &&
		       (cmp = strcmp(common_cmds[n].name, candidate)) < 0)
			n++;
		if ((n < ARRAY_SIZE(common_cmds)) && !cmp) {
			/* Yes, this is one of the common commands */
			n++; /* use the entry from common_cmds[] */
			if (starts_with(candidate, cmd)) {
				/* Give prefix match a very good score */
				main_cmds.names[i]->len = 0;
				continue;
			}
		}

		main_cmds.names[i]->len =
			levenshtein(cmd, candidate, 0, 2, 1, 3) + 1;
	}

	qsort(main_cmds.names, main_cmds.cnt,
	      sizeof(*main_cmds.names), levenshtein_compare);

	if (!main_cmds.cnt)
		die(_("Uh oh. Your system reports no Git commands at all."));

	/* skip and count prefix matches */
	for (n = 0; n < main_cmds.cnt && !main_cmds.names[n]->len; n++)
		; /* still counting */

	if (main_cmds.cnt <= n) {
		/* prefix matches with everything? that is too ambiguous */
		best_similarity = SIMILARITY_FLOOR + 1;
	} else {
		/* count all the most similar ones */
		for (best_similarity = main_cmds.names[n++]->len;
		     (n < main_cmds.cnt &&
		      best_similarity == main_cmds.names[n]->len);
		     n++)
			; /* still counting */
	}
	if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
		const char *assumed = main_cmds.names[0]->name;
		main_cmds.names[0] = NULL;
		clean_cmdnames(&main_cmds);
		fprintf_ln(stderr,
			   _("WARNING: You called a Git command named '%s', "
			     "which does not exist.\n"
			     "Continuing under the assumption that you meant '%s'"),
			cmd, assumed);
		if (autocorrect > 0) {
			fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
				(float)autocorrect/10.0);
			poll(NULL, 0, autocorrect * 100);
		}
		return assumed;
	}

	fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);

	if (SIMILAR_ENOUGH(best_similarity)) {
		fprintf_ln(stderr,
			   Q_("\nDid you mean this?",
			      "\nDid you mean one of these?",
			   n));

		for (i = 0; i < n; i++)
			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
	}

	exit(1);
}
Ejemplo n.º 17
0
Archivo: help.c Proyecto: 777/test-proj
const char *help_unknown_cmd(const char *cmd)
{
	int i, n, best_similarity = 0;
	struct cmdnames main_cmds, other_cmds;

	memset(&main_cmds, 0, sizeof(main_cmds));
	memset(&other_cmds, 0, sizeof(other_cmds));
	memset(&aliases, 0, sizeof(aliases));

	git_config(git_unknown_cmd_config, NULL);

	load_command_list("git-", &main_cmds, &other_cmds);

	add_cmd_list(&main_cmds, &aliases);
	add_cmd_list(&main_cmds, &other_cmds);
	qsort(main_cmds.names, main_cmds.cnt,
	      sizeof(main_cmds.names), cmdname_compare);
	uniq(&main_cmds);

	/* This reuses cmdname->len for similarity index */
	for (i = 0; i < main_cmds.cnt; ++i)
		main_cmds.names[i]->len =
			levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);

	qsort(main_cmds.names, main_cmds.cnt,
	      sizeof(*main_cmds.names), levenshtein_compare);

	if (!main_cmds.cnt)
		die ("Uh oh. Your system reports no Git commands at all.");

	best_similarity = main_cmds.names[0]->len;
	n = 1;
	while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
		++n;
	if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
		const char *assumed = main_cmds.names[0]->name;
		main_cmds.names[0] = NULL;
		clean_cmdnames(&main_cmds);
		fprintf(stderr, "WARNING: You called a Git command named '%s', "
			"which does not exist.\n"
			"Continuing under the assumption that you meant '%s'\n",
			cmd, assumed);
		if (autocorrect > 0) {
			fprintf(stderr, "in %0.1f seconds automatically...\n",
				(float)autocorrect/10.0);
			poll(NULL, 0, autocorrect * 100);
		}
		return assumed;
	}

	fprintf(stderr, "git: '%s' is not a git command. See 'git --help'.\n", cmd);

	if (SIMILAR_ENOUGH(best_similarity)) {
		fprintf(stderr, "\nDid you mean %s?\n",
			n < 2 ? "this": "one of these");

		for (i = 0; i < n; i++)
			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
	}

	exit(1);
}
Ejemplo n.º 18
0
title_set_info_t *
DVDGetFileSet(char *dvd)
{
	/*
	 * TODO  Fix close of files if
	 *	we error out
	 *	We also assume that all
	 *	DVD files are of valid
	 *	size i.e. file%2048 == 0
	 */

	/* title interation */
	int		title_sets;
	int		titles;
	int		counter;
	int		i;

	/* DVD file structures */
	dvd_reader_t *	_dvd = NULL;

	ifo_handle_t *	vmg_ifo = NULL;
	ifo_handle_t *	vts_ifo = NULL;

	dvd_file_t   *	vmg_vob_file = NULL;
	dvd_file_t   *	vmg_ifo_file = NULL;

	dvd_file_t   *	vts_ifo_file = NULL;
	dvd_file_t   *	vts_menu_file = NULL;
	dvd_file_t   * 	vts_title_file = NULL;

	/* The sizes it self of each file */
	int		ifo;
	int		bup;
	int		menu_vob;
	int		title_vob;

	/* Arrays keeping the title - filset relationship */
	int		* sector;
	int		* title;
	int		* title_sets_array;
	int		* sector_sets_array;

	/* DVD Video files */
	struct stat	fileinfo;
	char		temppoint[PATH_MAX + 1];

	/* The Title Set Info struct*/
	title_set_info_t * title_set_info;

	/* Temporary mount point - to be used later */
	char		mountpoint[PATH_MAX + 1];

	strncpy(mountpoint, dvd, sizeof (mountpoint));
	mountpoint[sizeof (mountpoint)-1] = '\0';


	_dvd = DVDOpen(dvd);
	if (!_dvd) {
#ifdef	USE_LIBSCHILY
		errmsgno(EX_BAD, "Can't open device '%s'\n", dvd);
#else
		fprintf(stderr, "Can't open device\n");
#endif
		return (0);
	}
	vmg_ifo = ifoOpen(_dvd, 0);
	if (!vmg_ifo) {
#ifdef	USE_LIBSCHILY
		errmsgno(EX_BAD, "Can't open VMG info for '%s'.\n", dvd);
#else
		fprintf(stderr, "Can't open VMG info.\n");
#endif
		return (0);
	}

	/* Check mount point */

	snprintf(temppoint, sizeof (temppoint),
				"%s/VIDEO_TS/VIDEO_TS.IFO", mountpoint);


	if (stat(temppoint, &fileinfo) < 0) {
		/* If we can't stat the file, give up */
#ifdef	USE_LIBSCHILY
		errmsg("Can't stat %s\n", temppoint);
#else
		fprintf(stderr, "Can't stat %s\n", temppoint);
		perror("");
#endif
		return (0);
	}



	title_sets = vmg_ifo->vmgi_mat->vmg_nr_of_title_sets;
	titles = vmg_ifo->tt_srpt->nr_of_srpts;

	sector = e_malloc(titles * sizeof (int));
	memset(sector, 0, titles * sizeof (int));
	title = e_malloc(titles * sizeof (int));
	title_sets_array = e_malloc(title_sets * sizeof (int));
	sector_sets_array = e_malloc(title_sets * sizeof (int));
	title_set_info = (title_set_info_t *)e_malloc(sizeof (title_set_info_t));
	title_set_info->title_set = (title_set_t *)e_malloc((title_sets + 1) *
							sizeof (title_set_t));

	title_set_info->num_titles = title_sets;


	/* Fill and sort the arrays for titles*/

	if (titles >= 1) {
		for (counter = 0; counter < titles; counter++) {
			sector[counter] = vmg_ifo->tt_srpt->title[counter].title_set_sector;
			title[counter]  = counter + 1;
		}
	}

	/* Yes, we should probably do a better sort than B - but what the heck*/
	bsort(sector, title, titles);


	/*
	 * Since title sets and titles are not the same we will need to sort
	 * out "bogus" titles
	 */

	uniq(sector, title, title_sets_array, sector_sets_array, titles);


	/* Open VIDEO_TS.VOB is present */

	vmg_vob_file = DVDOpenFile(_dvd, 0, DVD_READ_MENU_VOBS);

	/* Check VIDEO_TS title set */

	vmg_ifo_file = DVDOpenFile(_dvd, 0, DVD_READ_INFO_FILE);

	if ((vmg_vob_file == 0) && vmg_ifo->vmgi_mat->vmg_last_sector + 1
			< 2 * DVDFileSize(vmg_ifo_file)) {
#ifdef	USE_LIBSCHILY
		errmsgno(EX_BAD, "IFO is not of correct size aborting\n");
#else
		fprintf(stderr, "IFO is not of correct size aborting\n");
#endif
		DVDFreeFileSetArrays(sector, title, title_sets_array,
					sector_sets_array);
		DVDFreeFileSet(title_set_info);
		return (0);
	} else if ((vmg_vob_file != 0) && (vmg_ifo->vmgi_mat->vmg_last_sector
		    + 1  < 2 * DVDFileSize(vmg_ifo_file) +
		    DVDFileSize(vmg_vob_file))) {
#ifdef	USE_LIBSCHILY
		errmsgno(EX_BAD, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size");
#else
		fprintf(stderr, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size");
#endif
		DVDFreeFileSetArrays(sector, title, title_sets_array,
					sector_sets_array);
		DVDFreeFileSet(title_set_info);
		return (0);
	}

	/* Find the actuall right size of VIDEO_TS.IFO */
	if (vmg_vob_file == 0) {
		if (vmg_ifo->vmgi_mat->vmg_last_sector + 1 > 2
				*  DVDFileSize(vmg_ifo_file)) {
			ifo = vmg_ifo->vmgi_mat->vmg_last_sector
				- DVDFileSize(vmg_ifo_file) + 1;
		} else {
			ifo = vmg_ifo->vmgi_mat->vmgi_last_sector + 1;
		}
	} else {
		if (vmg_ifo->vmgi_mat->vmgi_last_sector + 1
				< vmg_ifo->vmgi_mat->vmgm_vobs) {
			ifo = vmg_ifo->vmgi_mat->vmgm_vobs;
		} else {
			ifo = vmg_ifo->vmgi_mat->vmgi_last_sector + 1;
		}
	}

	title_set_info->title_set[0].size_ifo = ifo * 2048;
	title_set_info->title_set[0].realsize_ifo = fileinfo.st_size;
	title_set_info->title_set[0].pad_ifo = ifo - DVDFileSize(vmg_ifo_file);

	/* Find the actuall right size of VIDEO_TS.VOB */
	if (vmg_vob_file != 0) {
		if (ifo + DVDFileSize(vmg_ifo_file) +
		    DVDFileSize(vmg_vob_file) - 1 <
		    vmg_ifo->vmgi_mat->vmg_last_sector) {
				menu_vob = vmg_ifo->vmgi_mat->vmg_last_sector -
						ifo - DVDFileSize(vmg_ifo_file) + 1;
		} else {
			menu_vob = vmg_ifo->vmgi_mat->vmg_last_sector
			- ifo - DVDFileSize(vmg_ifo_file) + 1;
		}

		snprintf(temppoint, sizeof (temppoint),
				"%s/VIDEO_TS/VIDEO_TS.VOB", mountpoint);
		if (stat(temppoint, &fileinfo) < 0) {
#ifdef	USE_LIBSCHILY
			errmsg("calc: Can't stat %s\n", temppoint);
#else
			fprintf(stderr, "calc: Can't stat %s\n", temppoint);
			perror("");
#endif
			DVDFreeFileSetArrays(sector, title, title_sets_array,
						sector_sets_array);
			DVDFreeFileSet(title_set_info);
			return (0);
		}

		title_set_info->title_set[0].realsize_menu = fileinfo.st_size;
		title_set_info->title_set[0].pad_menu = menu_vob -
						DVDFileSize(vmg_vob_file);
		title_set_info->title_set[0].size_menu = menu_vob * 2048;
		DVDCloseFile(vmg_vob_file);
	} else {
		title_set_info->title_set[0].size_menu = 0;
		title_set_info->title_set[0].realsize_menu = 0;
		title_set_info->title_set[0].pad_menu = 0;
		menu_vob = 0;
	}


	/* Finding the actuall right size of VIDEO_TS.BUP */
	if (title_sets >= 1) {
		bup = sector_sets_array[0] - menu_vob - ifo;
	} else {
		/* Just in case we burn a DVD-Video without any title_sets */
		bup = vmg_ifo->vmgi_mat->vmg_last_sector + 1 - menu_vob - ifo;
	}

	/* Never trust the BUP file - use a copy of the IFO */
	snprintf(temppoint, sizeof (temppoint),
				"%s/VIDEO_TS/VIDEO_TS.IFO", mountpoint);

	if (stat(temppoint, &fileinfo) < 0) {
#ifdef	USE_LIBSCHILY
		errmsg("calc: Can't stat %s\n", temppoint);
#else
		fprintf(stderr, "calc: Can't stat %s\n", temppoint);
		perror("");
#endif
		DVDFreeFileSetArrays(sector, title, title_sets_array,
					sector_sets_array);
		DVDFreeFileSet(title_set_info);
		return (0);
	}

	title_set_info->title_set[0].realsize_bup = fileinfo.st_size;
	title_set_info->title_set[0].size_bup = bup * 2048;
	title_set_info->title_set[0].pad_bup = bup - DVDFileSize(vmg_ifo_file);

	/* Take care of the titles which we don't have in VMG */

	title_set_info->title_set[0].number_of_vob_files = 0;
	title_set_info->title_set[0].realsize_vob[0] = 0;
	title_set_info->title_set[0].pad_title = 0;

	DVDCloseFile(vmg_ifo_file);

	if (title_sets >= 1) {
		for (counter = 0; counter < title_sets; counter++) {

			vts_ifo = ifoOpen(_dvd, counter + 1);

			if (!vts_ifo) {
#ifdef	USE_LIBSCHILY
				errmsgno(EX_BAD, "Can't open VTS info.\n");
#else
				fprintf(stderr, "Can't open VTS info.\n");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			}

			snprintf(temppoint, sizeof (temppoint),
				"%s/VIDEO_TS/VTS_%02i_0.IFO",
				mountpoint, counter + 1);

			if (stat(temppoint, &fileinfo) < 0) {
#ifdef	USE_LIBSCHILY
				errmsg("calc: Can't stat %s\n", temppoint);
#else
				fprintf(stderr, "calc: Can't stat %s\n",
					temppoint);
				perror("");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			}


			/* Test if VTS_XX_0.VOB is present */

			vts_menu_file = DVDOpenFile(_dvd, counter + 1,
					DVD_READ_MENU_VOBS);

			/* Test if VTS_XX_X.VOB are present */

			vts_title_file = DVDOpenFile(_dvd, counter + 1,
						DVD_READ_TITLE_VOBS);

			/* Check VIDEO_TS.IFO */

			vts_ifo_file = DVDOpenFile(_dvd, counter + 1,
							DVD_READ_INFO_FILE);

			/*
			 * Checking that title will fit in the
			 * space given by the ifo file
			 */


			if (vts_ifo->vtsi_mat->vts_last_sector + 1
				< 2 * DVDFileSize(vts_ifo_file)) {
#ifdef	USE_LIBSCHILY
				errmsgno(EX_BAD, "IFO is not of correct size aborting.\n");
#else
				fprintf(stderr, "IFO is not of correct size aborting\n");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			} else if ((vts_title_file != 0) &&
				    (vts_menu_file != 0) &&
				    (vts_ifo->vtsi_mat->vts_last_sector + 1
				    < 2 * DVDFileSize(vts_ifo_file) +
				    DVDFileSize(vts_title_file) +
				    DVDFileSize(vts_menu_file))) {
#ifdef	USE_LIBSCHILY
				errmsgno(EX_BAD, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size.\n");
#else
				fprintf(stderr, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			} else if ((vts_title_file != 0) &&
				    (vts_menu_file == 0) &&
				    (vts_ifo->vtsi_mat->vts_last_sector + 1
				    < 2 * DVDFileSize(vts_ifo_file) +
				    DVDFileSize(vts_title_file))) {
#ifdef	USE_LIBSCHILY
				errmsgno(EX_BAD, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size.\n");
#else
				fprintf(stderr, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			} else if ((vts_menu_file != 0) &&
				    (vts_title_file == 0) &&
				    (vts_ifo->vtsi_mat->vts_last_sector + 1
				    < 2 * DVDFileSize(vts_ifo_file) +
				    DVDFileSize(vts_menu_file))) {
#ifdef	USE_LIBSCHILY
				errmsgno(EX_BAD, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size.\n");
#else
				fprintf(stderr, "Either VIDEO_TS.IFO or VIDEO_TS.VOB is not of correct size");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			}


			/* Find the actuall right size of VTS_XX_0.IFO */
			if ((vts_title_file == 0) && (vts_menu_file == 0)) {
				if (vts_ifo->vtsi_mat->vts_last_sector + 1 >
				    2 * DVDFileSize(vts_ifo_file)) {
					ifo = vts_ifo->vtsi_mat->vts_last_sector
						- DVDFileSize(vts_ifo_file) + 1;
				} else {
					ifo = vts_ifo->vtsi_mat->vts_last_sector
						- DVDFileSize(vts_ifo_file) + 1;
				}
			} else if (vts_title_file == 0) {
				if (vts_ifo->vtsi_mat->vtsi_last_sector + 1 <
				    vts_ifo->vtsi_mat->vtstt_vobs) {
					ifo = vmg_ifo->vtsi_mat->vtstt_vobs;
				} else {
					ifo = vmg_ifo->vtsi_mat->vtstt_vobs;
				}
			} else {
				if (vts_ifo->vtsi_mat->vtsi_last_sector + 1 <
				    vts_ifo->vtsi_mat->vtsm_vobs) {
					ifo = vts_ifo->vtsi_mat->vtsm_vobs;
				} else {
					ifo = vts_ifo->vtsi_mat->vtsi_last_sector + 1;
				}
			}
			title_set_info->title_set[counter + 1].size_ifo =
						ifo * 2048;
			title_set_info->title_set[counter + 1].realsize_ifo =
						fileinfo.st_size;
			title_set_info->title_set[counter + 1].pad_ifo =
						ifo - DVDFileSize(vts_ifo_file);


			/* Find the actuall right size of VTS_XX_0.VOB */
			if (vts_menu_file != 0) {
				if (vts_ifo->vtsi_mat->vtsm_vobs == 0)  {
					/*
					 * Apparently start sector 0 means that
					 * VTS_XX_0.VOB is empty after all...
					 */
					menu_vob = 0;
					if (DVDFileSize(vts_menu_file) != 0) {
						/*
						 * Paranoia: we most likely never
						 * come here...
						 */
#ifdef	USE_LIBSCHILY
						errmsgno(EX_BAD,
							"%s/VIDEO_TS/VTS_%02i_0.IFO appears to be corrupted.\n",
							mountpoint, counter+1);
#else
						fprintf(stderr,
							"%s/VIDEO_TS/VTS_%02i_0.IFO appears to be corrupted.\n",
							mountpoint, counter+1);
#endif
						return (0);
					}
				} else if ((vts_title_file != 0) &&
					(vts_ifo->vtsi_mat->vtstt_vobs -
					vts_ifo->vtsi_mat->vtsm_vobs >
						DVDFileSize(vts_menu_file))) {
					menu_vob = vts_ifo->vtsi_mat->vtstt_vobs -
							vts_ifo->vtsi_mat->vtsm_vobs;
				} else if ((vts_title_file == 0) &&
					    (vts_ifo->vtsi_mat->vtsm_vobs +
					    DVDFileSize(vts_menu_file) +
					    DVDFileSize(vts_ifo_file) - 1 <
					    vts_ifo->vtsi_mat->vts_last_sector)) {
					menu_vob = vts_ifo->vtsi_mat->vts_last_sector
						- DVDFileSize(vts_ifo_file)
						- vts_ifo->vtsi_mat->vtsm_vobs + 1;
				} else {
					menu_vob = vts_ifo->vtsi_mat->vtstt_vobs -
							vts_ifo->vtsi_mat->vtsm_vobs;
				}

				snprintf(temppoint, sizeof (temppoint),
					"%s/VIDEO_TS/VTS_%02i_0.VOB", mountpoint, counter + 1);

				if (stat(temppoint, &fileinfo)  < 0) {
#ifdef	USE_LIBSCHILY
					errmsg("calc: Can't stat %s\n", temppoint);
#else
					fprintf(stderr, "calc: Can't stat %s\n",
						temppoint);
					perror("");
#endif
					DVDFreeFileSetArrays(sector, title,
						title_sets_array, sector_sets_array);
					DVDFreeFileSet(title_set_info);
					return (0);
				}

				title_set_info->title_set[counter + 1].realsize_menu = fileinfo.st_size;
				title_set_info->title_set[counter + 1].size_menu = menu_vob * 2048;
				title_set_info->title_set[counter + 1].pad_menu = menu_vob - DVDFileSize(vts_menu_file);

			} else {
				title_set_info->title_set[counter + 1].size_menu = 0;
				title_set_info->title_set[counter + 1].realsize_menu = 0;
				title_set_info->title_set[counter + 1].pad_menu = 0;
				menu_vob = 0;
			}


			/* Find the actuall total size of VTS_XX_[1 to 9].VOB */

			if (vts_title_file != 0) {
				if (ifo + menu_vob + DVDFileSize(vts_ifo_file) -
				    1 < vts_ifo->vtsi_mat->vts_last_sector) {
				    title_vob = vts_ifo->vtsi_mat->vts_last_sector
						+ 1 - ifo - menu_vob -
						DVDFileSize(vts_ifo_file);
				} else {
					title_vob = vts_ifo->vtsi_mat->vts_last_sector +
						1 - ifo - menu_vob -
						DVDFileSize(vts_ifo_file);
				}
				/*
				 * Find out how many vob files
				 * and the size of them
				 */
				for (i = 0; i < 9; ++i) {
					snprintf(temppoint, sizeof (temppoint),
						"%s/VIDEO_TS/VTS_%02i_%i.VOB",
						mountpoint, counter + 1, i + 1);
					if (stat(temppoint, &fileinfo) < 0) {
						break;
					}
					title_set_info->title_set[counter + 1].realsize_vob[i] = fileinfo.st_size;
				}
				title_set_info->title_set[counter + 1].number_of_vob_files = i;
				title_set_info->title_set[counter + 1].size_title = title_vob * 2048;
				title_set_info->title_set[counter + 1].pad_title = title_vob - DVDFileSize(vts_title_file);
			} else {
				title_set_info->title_set[counter + 1].number_of_vob_files = 0;
				title_set_info->title_set[counter + 1].realsize_vob[0] = 0;
				title_set_info->title_set[counter + 1].size_title = 0;
				title_set_info->title_set[counter + 1].pad_title = 0;
				title_vob = 0;

			}


			/* Find the actuall total size of VTS_XX_0.BUP */
			if (title_sets - 1 > counter) {
				bup = sector_sets_array[counter+1]
					- sector_sets_array[counter]
					- title_vob - menu_vob - ifo;
			} else {
				bup = vts_ifo->vtsi_mat->vts_last_sector + 1
					- title_vob - menu_vob - ifo;
			}

			/* Never trust the BUP use a copy of the IFO */
			snprintf(temppoint, sizeof (temppoint),
				"%s/VIDEO_TS/VTS_%02i_0.IFO",
				mountpoint, counter + 1);

			if (stat(temppoint, &fileinfo) < 0) {
#ifdef	USE_LIBSCHILY
				errmsg("calc: Can't stat %s\n", temppoint);
#else
				fprintf(stderr, "calc: Can't stat %s\n",
					temppoint);
				perror("");
#endif
				DVDFreeFileSetArrays(sector, title,
					title_sets_array, sector_sets_array);
				DVDFreeFileSet(title_set_info);
				return (0);
			}

			title_set_info->title_set[counter + 1].size_bup =
						bup * 2048;
			title_set_info->title_set[counter + 1].realsize_bup =
						fileinfo.st_size;
			title_set_info->title_set[counter + 1].pad_bup =
						bup - DVDFileSize(vts_ifo_file);


			/* Closing files */

			if (vts_menu_file != 0) {
				DVDCloseFile(vts_menu_file);
			}

			if (vts_title_file != 0) {
				DVDCloseFile(vts_title_file);
			}


			if (vts_ifo_file != 0) {
				DVDCloseFile(vts_ifo_file);
			}

			ifoClose(vts_ifo);

		}

	}

	DVDFreeFileSetArrays(sector, title, title_sets_array, sector_sets_array);

	/* Close the VMG ifo file we got all the info we need */
	ifoClose(vmg_ifo);


	/* Close the DVD */
	DVDClose(_dvd);

	/* Return the actuall info*/
	return (title_set_info);


}
Ejemplo n.º 19
0
int
main(int argc, char *argv[])
{
	DB	*db;
	int	 ch;
	const char *fname = _PATH_SERVICES;
	const char *dbname = _PATH_SERVICES_DB;
	int	 warndup = 1;
	int	 unique = 0;
	int	 otherflag = 0;
	size_t	 cnt = 0;
	StringList *sl, ***svc;
	size_t port, proto;

	setprogname(argv[0]);

	while ((ch = getopt(argc, argv, "qo:u")) != -1)
		switch (ch) {
		case 'q':
			otherflag = 1;
			warndup = 0;
			break;
		case 'o':
			otherflag = 1;
			dbname = optarg;
			break;
		case 'u':
			unique++;
			break;
		case '?':
		default:
			usage();
		}

	argc -= optind;
	argv += optind;

	if (argc > 1 || (unique && otherflag))
		usage();
	if (argc == 1)
		fname = argv[0];

	if (unique)
		uniq(fname);

	svc = parseservices(fname, sl = sl_init());

	if (atexit(cleanup))
		err(1, "Cannot install exit handler");

	(void)snprintf(tname, sizeof(tname), "%s.tmp", dbname);
	db = dbopen(tname, O_RDWR | O_CREAT | O_EXCL,
	    (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), DB_HASH, &hinfo);
	if (!db)
		err(1, "Error opening temporary database `%s'", tname);


	for (port = 0; port < PMASK + 1; port++) {
		if (svc[port] == NULL)
			continue;

		for (proto = 0; proto < PROTOMAX; proto++) {
			StringList *s;
			if ((s = svc[port][proto]) == NULL)
				continue;
			add(db, s, port, getprotostr(sl, proto), &cnt, warndup);
		}

		free(svc[port]);
	}

	free(svc);
	sl_free(sl, 1);

	if ((db->close)(db))
		err(1, "Error closing temporary database `%s'", tname);

	if (rename(tname, dbname) == -1)
		err(1, "Cannot rename `%s' to `%s'", tname, dbname);

	return 0;
}
Ejemplo n.º 20
0
int main(void)
{
	initIO();

	while (1)
    {
        if (TCNT1<2000)
        {
            
        }
        
        if ((TCNT1>=2000) && (TCNT1<=5500) && (dataOK == 1))
        {
            //reset channels from high to low
            if (TCNT1>=CH1_out && bit_is_set(PORTB, PIN0)) PORTB &= ~(1<<PIN0);
            if (TCNT1>=CH2_out && bit_is_set(PORTB, PIN1)) PORTB &= ~(1<<PIN1);
            if (TCNT1>=CH3_out && bit_is_set(PORTB, PIN2)) PORTB &= ~(1<<PIN2);
            if (TCNT1>=CH4_out && bit_is_set(PORTB, PIN3)) PORTB &= ~(1<<PIN3);
            if (TCNT1>=CH5_out && bit_is_set(PORTB, PIN4)) PORTB &= ~(1<<PIN4);
            if (TCNT1>=CH6_out && bit_is_set(PORTD, PIN0)) PORTD &= ~(1<<PIN0);
            if (TCNT1>=CH7_out && bit_is_set(PORTD, PIN1)) PORTD &= ~(1<<PIN1);
            if (TCNT1>=CH8_out && bit_is_set(PORTD, PIN2)) PORTD &= ~(1<<PIN2);
            if (TCNT1>=CH9_out && bit_is_set(PORTD, PIN3)) PORTD &= ~(1<<PIN3);
            if (TCNT1>=CH10_out && bit_is_set(PORTD, PIN4)) PORTD &= ~(1<<PIN4);
            if (TCNT1>=CH11_out && bit_is_set(PORTD, PIN5)) PORTD &= ~(1<<PIN5);
            if (TCNT1>=CH12_out && bit_is_set(PORTD, PIN6)) PORTD &= ~(1<<PIN6);
        }
        
        if ((TCNT1>5500) && (TCNT1<35000))
        {
            CH1_out = uniq(rxbuffer[1], rxbuffer[2]);
            CH2_out = uniq(rxbuffer[3], rxbuffer[4]);
            CH3_out = uniq(rxbuffer[5], rxbuffer[6]);
            CH4_out = uniq(rxbuffer[7], rxbuffer[8]);
            CH5_out = uniq(rxbuffer[9], rxbuffer[10]);
            CH6_out = uniq(rxbuffer[11], rxbuffer[12]);
            CH7_out = uniq(rxbuffer[13], rxbuffer[14]);
            CH8_out = uniq(rxbuffer[15], rxbuffer[16]);
            CH9_out = uniq(rxbuffer[17], rxbuffer[18]);
            CH10_out = uniq(rxbuffer[19], rxbuffer[20]);
            CH11_out = uniq(rxbuffer[21], rxbuffer[22]);
            CH12_out = uniq(rxbuffer[23], rxbuffer[24]);
            
            //ready for output
            dataOK = 1;
        }
        
        
	}
	return 0; // never reached
}
Ejemplo n.º 21
0
Archivo: uniq.c Proyecto: lufb/code
int
main(int argc, char *argv[])
{
    int                 c;

    static struct option const long_options[] =
    {
        {"help", 0, NULL, 'h'},
        {"count", 0, NULL, 'c'},
        {"repeated", 0, NULL, 'd'},
        {"skip-fields", 1, NULL, 'f'},
        {"ignore-case", 0, NULL, 'i'},
        {"skip-chars", 1, NULL, 's'},
        {"separater", 1, NULL, 'p'},
        {NULL, 0, NULL, 0}
    };
    init_option(&g_option);
    exit_status = EXIT_SUCESS;
    program_name = argv[0];
    while((c = getopt_long(argc, argv,
                           "hHcdf:is:p:", long_options, NULL)) != -1)
    {
        switch(c)
        {
            case 'h':
            case 'H':
                uniq_usage_exit(EXIT_SUCESS);
                break;
            case 'c':
                g_option.c = 1;
                break;
            case 'd':
                g_option.d = 1;
                break;
            case 'f':
                if(optarg)
                    fill_f(optarg);
                break;
            case 'i':
                g_option.i = 1;
                break;
            case 's':
                if(optarg)
                    fill_s(optarg);
                break;
            case 'p':
                if(optarg)
                    fill_p(optarg);
                break;
            default:
                uniq_usage_exit(EXIT_FAILURE);
                break;
        }
    }

    if(argc - optind != 1)
        uniq_usage_exit(EXIT_FAILURE);

    adjust_option();
    if(uniq(argv[optind]) != 0)
        exit_status = EXIT_FAILURE;

    exit(exit_status);
}
Ejemplo n.º 22
0
    std::string countFast() {
        MessageHandler mh;
        mh.begin("counting") << " paths of " << typenameof(spec);

        std::vector<Word> tmp(stateWords + 1);
        Word* ptmp = tmp.data();
        int const n = spec.get_root(state(ptmp));
        if (n <= 0) {
            mh << " ...";
            mh.end(0);
            return (n == 0) ? "0" : "1";
        }

        uint64_t totalStorage[n / 63 + 1];
        BigNumber total(totalStorage);
        total.store(0);
        size_t maxWidth = 0;
        //std::cerr << "\nLevel,Width\n";

        std::vector<MemoryPool> pools(n + 1);
        MyVector<MyList<Word> > vnodeTable(n + 1);

        int numberWords = 1;
        Word* p0 = vnodeTable[n].alloc_front(stateWords + 1);
        spec.get_copy(state(p0), state(ptmp));
        spec.destruct(state(ptmp));
        number(p0).store(1);

        mh.setSteps(n);
        for (int i = n; i > 0; --i) {
            MyList<Word>& vnodes = vnodeTable[i];
            size_t m = 0;

            {
                UniqTable uniq(vnodes.size(), hasher, hasher);

                for (MyList<Word>::iterator t = vnodes.begin();
                        t != vnodes.end(); ++t) {
                    Word* p = *t;
                    Word* pp = uniq.add(p);

                    if (pp == p) {
                        ++m;
                    }
                    else {
                        int w = number(pp).add(number(p));
                        if (numberWords < w) {
                            numberWords = w; //FIXME might be broken at long skip
                        }
                        number(p).store(0);
                    }
                }
            }

            //std::cerr << i << "," << m << "\n";
            maxWidth = std::max(maxWidth, m);
            MyList<Word>& nextVnodes = vnodeTable[i - 1];
            int const nextWords = stateWords + numberWords + 1;
            Word* pp = nextVnodes.alloc_front(nextWords);

            for (; !vnodes.empty(); vnodes.pop_front()) {
                Word* p = vnodes.front();
                if (number(p).equals(0)) {
                    spec.destruct(state(p));
                    continue;
                }

                for (int b = 0; b <= 1; ++b) {
                    spec.get_copy(state(pp), state(p));
                    int ii = spec.get_child(state(pp), i, b);

                    if (ii <= 0) {
                        spec.destruct(state(pp));
                        if (ii != 0) {
                            total.add(number(p));
                        }
                    }
                    else if (ii < i - 1) {
                        Word* ppp = vnodeTable[ii].alloc_front(
                                nextWords + (i - ii) / 63);
                        spec.get_copy(state(ppp), state(pp));
                        spec.destruct(state(pp));
                        number(ppp).store(number(p));
                    }
                    else {
                        assert(ii == i - 1);
                        number(pp).store(number(p));
                        pp = nextVnodes.alloc_front(nextWords);
                    }
                }

                spec.destruct(state(p));
            }

            nextVnodes.pop_front();
            pools[i].clear();
            spec.destructLevel(i);
            mh.step();
        }

        mh.end(maxWidth);
        return total;
    }
Ejemplo n.º 23
0
/*!
 @brief main program of the I2C-slave

 Initializes the timer/counters and the I2C.
 Constantly updates the duty cycles of the PPM

 @return int
*/
int main(void)
{
    int i;

    cli();  // Disable interrupts

    usiTwiSlaveInit(SLAVE_ADDR_ATTINY);	// TWI slave init

    //Initialize rxbuffer
    rxbuffer[0] = HIGH_BYTE( (dutyCycles[0] - 1*8192) );
    rxbuffer[1] = LOW_BYTE(  (dutyCycles[0] - 1*8192) );

    rxbuffer[2] = HIGH_BYTE( (dutyCycles[1] - 2*8192) );
    rxbuffer[3] = LOW_BYTE(  (dutyCycles[1] - 2*8192) );

    rxbuffer[4] = HIGH_BYTE( (dutyCycles[2] - 3*8192) );
    rxbuffer[5] = LOW_BYTE(  (dutyCycles[2] - 3*8192) );

    rxbuffer[6] = HIGH_BYTE( (dutyCycles[3] - 0*8192) );
    rxbuffer[7] = LOW_BYTE(  (dutyCycles[3] - 0*8192) );

    ppmInit();

    sei();  // Re-enable interrupts

    while(1)
    {
        /*
            receivedNewValue is updated whenever a new value is written
            to the rxbuffer with the corresponding index
            As always 2 bytes are used for one dutyCycle the interesting values are 1, 3, 5, 7
            Then the corresponding value in the dutyCycle array is updated

            The new value for a dutyCycle is calculated first in a temp-variable.
            In a previous version it was directly assigned within the atomic block which caused severs problems
            that the ucontroller stopped responding to the I2C-master.
            Therefore now only the assignment to dutyCycles[x] is done in atomic block
        */
        uint16_t temp;
        switch (receivedNewValue)
        {
        case 1:  //update dutyCycle for channel 0
            receivedNewValue = 0;
            temp = uniq(rxbuffer[1], rxbuffer[0]) + 1 * 8192;
            ATOMIC_BLOCK(ATOMIC_FORCEON)
            {
                dutyCycles[0] = temp;
            }
            txbuffer[0]   = rxbuffer[0];
            txbuffer[1]   = rxbuffer[1];
            break;

        case  3:  //update dutyCycle for channel 1
            receivedNewValue = 0;
            temp = uniq(rxbuffer[3], rxbuffer[2]) + 2 * 8192;
            ATOMIC_BLOCK(ATOMIC_FORCEON)
            {
                dutyCycles[1] = temp;
            }
            txbuffer[2]   = rxbuffer[2];
            txbuffer[3]   = rxbuffer[3];
            break;

        case 5:  //update dutyCycle for channel 2
            receivedNewValue = 0;
            temp = uniq(rxbuffer[5], rxbuffer[4]) + 3 * 8192;
            ATOMIC_BLOCK(ATOMIC_FORCEON)
            {
                dutyCycles[2] = temp;
            }
            txbuffer[4]   = rxbuffer[4];
            txbuffer[5]   = rxbuffer[5];
            break;

        case 7:   //update dutyCycle for channel 3
            receivedNewValue = 0;
            temp = uniq(rxbuffer[7], rxbuffer[6]) + 0 * 8192;
            ATOMIC_BLOCK(ATOMIC_FORCEON)
            {
                dutyCycles[3] = temp;
            }
            txbuffer[6]   = rxbuffer[6];
            txbuffer[7]   = rxbuffer[7];
            break;
        } //end.switch
    } //end.while
} //end.main
Ejemplo n.º 24
0
Archivo: se.c Proyecto: oracc/owi
int
main(int argc, char * const*argv)
{
  struct token *toks = NULL;
  int ntoks = 0;
  static struct Datum result;

  f_log = stderr;
  exit_on_error = TRUE;
  setlocale(LC_ALL,LOCALE);
  options(argc, argv, "28cdg:o:p:P:stuvx:");
  if (!out_f)
    out_f = stdout;

  if (doing_debug)
    f_log = fopen("se.dbg","w");

  /*atf2utf8_init();*/
  charsets_init();
  langtag_init();
  tokinit();

  if (pretrim_file || pretrim_args)
    pretrim_setup();

  if (xmldir)
    toks = tokenize(xmldir_toks(xmldir),&ntoks);
  else
    toks = tokenize((const char **)(argv+optind),&ntoks);
  if (show_tokens)
    {
      showtoks(toks,ntoks);
    }
  else
    {
      binop_init();
      binop24_init();
      result = evaluate(toks, -1, lm_any, NULL);
      progress("se: result.count == %lu\n", (unsigned long)result.count);

      if (do_uniq && (res_gran == g_word || res_gran == g_grapheme))
	do_uniq = 0;

      if (do_uniq && result.count > 1)
	{
	  uniq(&result);
	  progress("se: post-uniq result.count == %lu\n", (unsigned long)result.count);
	}
      if (show_count)
	printf("%lu\n",(unsigned long)result.count);
      else if (result.count)
	{
	  if (xmldir)
	    xmldir_results(xmldir,result.count);
	  if ('v' == id_prefix(result.l.l8p[0]->text_id))
	    {
	      if (!strcmp(return_index, "cat"))
		vid_display_proj = vid_proj_xmd;
	      else
		vid_display_proj = vid_proj_xtf;
	      vid_show_results(&result);
	    }
	  else
	    show_results(&result);
	}
      else if (xmldir)
	xmldir_results(xmldir,result.count);
    }
  if (pretrim_args)
    {
      list_free(pretrim_args, NULL);
      pretrim_args = NULL;
    }
  if (pretrim)
    {
      hash_free(pretrim, NULL);
      pretrim = NULL;
      free(pretrim_lines);
      free(pretrim_content);
      pretrim_content = NULL;
      pretrim_lines = NULL;
    }
  langtag_term();
  return 0;
}
Ejemplo n.º 25
0
Archivo: tog.c Proyecto: berkus/lang-e
/* convert: read the text rewrite rules on fp, generating bog rewrite rules (on
   fr) and C tables (on ft) for use with tpo */
static void convert (FILE *fp, FILE *fr, FILE *ft) {
     int phase = IN, lc = 0, id, vused[26], i;
     char c, l[LSZ], *lp, v[VSZ], *vp;
     List trul = 0, tlin = 0, brul = 0, blin = 0, patterns = 0;

     for (i = 0; i < 26; i++) vused[i] = 0;
     while (fgets(l, LSZ, fp)) {
	  ++lc;
	  if (*l == '#' || *l == '\n') continue;
	  if (!strcmp(l, "=\n")) { /* End of input pattern */
	       if (phase != IN)
		    error(stringf("Misplaced '=' at line %d", lc));
	       if (!blin)
		    warning(stringf("Empty input pattern at line %d", lc));
	       trul = l_append((void *)tlin, trul, ARENA0); tlin = 0;
	       brul = l_append((void *)blin, brul, ARENA0); blin = 0;
	       phase = OUT;
	       continue;
	  }
	  if (!strcmp(l, "+\n")) { /* End of output pattern */
	       if (phase != OUT)
		    error(stringf("Misplaced '+' at line %d", lc));
	       brul = l_append((void *)blin, brul, ARENA0); blin = 0;
	       for (i = 0; i < 26; i++) vused[i] = 0;
	       phase = IN;
	       continue;
	  }
				/* Extend text line list */
	  for (lp = l; *lp; lp++) ; if (*--lp == '\n') *lp = '\0';
	  if (phase == IN)
	       tlin = l_append((void*)string(l), tlin, ARENA0);

	  vp = v;		/* "Uniqueify" string */
	  for (lp = l; *lp; lp++)
	       if (*lp == '%')
		    if ((c = tolower(*++lp)) >= 'a' && c <= 'z') {
			 int j = c-'a';
			 *vp++ = c; *lp = ' ';
			 if (phase == IN)
			      vused[j] = 1;
			 else if (!vused[j])
			      error(stringf("Symbol '%%%c' used with no prior "
					    "definition at line %d", c, lc));
		    } else if (c != '%')
			 error(stringf("Illegal expression '%%%c' at line %d",
				       c, lc));
	  *vp++ = 0;
				/* Extend list of uniq'd patterns */
	  if (uniq(l, &lp, &id))
	       patterns = l_append((void *)lp, patterns, ARENA0);
	  PDEBUG(("convert: %s :: %d\n", lp, id));
				/* Extend binary line list (for bog) */
	  blin = l_append((void *)id, blin, ARENA0);
	  blin = l_append((void *)string(v), blin, ARENA0);
     }

     unparsebin(brul, fr);
     fprintf(ft, "#include \"tpo.h\"\n\n");
     unparsepat(patterns, ft);
     unparsetxt(trul, ft);
}
Ejemplo n.º 26
0
const char *help_unknown_cmd(const char *cmd)
{
	unsigned int i, n = 0, best_similarity = 0;
	struct cmdnames main_cmds, other_cmds;

	memset(&main_cmds, 0, sizeof(main_cmds));
	memset(&other_cmds, 0, sizeof(main_cmds));
	memset(&aliases, 0, sizeof(aliases));

	perf_config(perf_unknown_cmd_config, NULL);

	load_command_list("perf-", &main_cmds, &other_cmds);

	add_cmd_list(&main_cmds, &aliases);
	add_cmd_list(&main_cmds, &other_cmds);
	qsort(main_cmds.names, main_cmds.cnt,
	      sizeof(main_cmds.names), cmdname_compare);
	uniq(&main_cmds);

	if (main_cmds.cnt) {
		/* This reuses cmdname->len for similarity index */
		for (i = 0; i < main_cmds.cnt; ++i)
			main_cmds.names[i]->len =
				levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);

		qsort(main_cmds.names, main_cmds.cnt,
		      sizeof(*main_cmds.names), levenshtein_compare);

		best_similarity = main_cmds.names[0]->len;
		n = 1;
		while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
			++n;
	}

	if (autocorrect && n == 1) {
		const char *assumed = main_cmds.names[0]->name;

		main_cmds.names[0] = NULL;
		clean_cmdnames(&main_cmds);
		fprintf(stderr, "WARNING: You called a perf program named '%s', "
			"which does not exist.\n"
			"Continuing under the assumption that you meant '%s'\n",
			cmd, assumed);
		if (autocorrect > 0) {
			fprintf(stderr, "in %0.1f seconds automatically...\n",
				(float)autocorrect/10.0);
			poll(NULL, 0, autocorrect * 100);
		}
		return assumed;
	}

	fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);

	if (main_cmds.cnt && best_similarity < 6) {
		fprintf(stderr, "\nDid you mean %s?\n",
			n < 2 ? "this": "one of these");

		for (i = 0; i < n; i++)
			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
	}

	exit(1);
}
Ejemplo n.º 27
0
Archivo: main.cpp Proyecto: CCJY/coliru
 Object() : t(uniq())
 {
     std::cout << "(" << 0 << " " << t << ") ";
 }