Exemplo n.º 1
0
static void fill_directory(struct dir_struct *dir, const char **pathspec,
		int ignored_too)
{
	const char *path, *base;
	int baselen;

	/* Set up the default git porcelain excludes */
	memset(dir, 0, sizeof(*dir));
	if (!ignored_too) {
		dir->collect_ignored = 1;
		setup_standard_excludes(dir);
	}

	/*
	 * Calculate common prefix for the pathspec, and
	 * use that to optimize the directory walk
	 */
	baselen = common_prefix(pathspec);
	path = ".";
	base = "";
	if (baselen)
		path = base = xmemdupz(*pathspec, baselen);

	/* Read the directory and prune it */
	read_directory(dir, path, base, baselen, pathspec);
	if (pathspec)
		prune_directory(dir, pathspec, baselen);
}
Exemplo n.º 2
0
static int symtab_get_matches(jl_sym_t *tree, const char *str, char **answer)
{
    int x, plen, count=0;
    ios_t ans;

    plen = strlen(str);

    while (tree != NULL) {
        x = common_prefix(str, tree->name);
        if (x == plen) {
            ios_mem(&ans, 0);
            symtab_search(tree, &count, &ans, str, plen);
            size_t nb;
            *answer = ios_takebuf(&ans, &nb);
            return count;
        }
        else {
            x = strcmp(str, tree->name);
            if (x < 0)
                tree = tree->left;
            else
                tree = tree->right;
        }
    }
    return 0;
}
Exemplo n.º 3
0
/*
 * Take a union of paths in the index and the named tree (typically, "HEAD"),
 * and return the paths that match the given pattern in list.
 */
static int list_paths(struct string_list *list, const char *with_tree,
		      const char *prefix, const struct pathspec *pattern)
{
	int i;
	char *m;

	if (!pattern->nr)
		return 0;

	m = xcalloc(1, pattern->nr);

	if (with_tree) {
		char *max_prefix = common_prefix(pattern);
		overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
		free(max_prefix);
	}

	for (i = 0; i < active_nr; i++) {
		const struct cache_entry *ce = active_cache[i];
		struct string_list_item *item;

		if (ce->ce_flags & CE_UPDATE)
			continue;
		if (!ce_path_match(ce, pattern, m))
			continue;
		item = string_list_insert(list, ce->name);
		if (ce_skip_worktree(ce))
			item->util = item; /* better a valid pointer than a fake one */
	}

	return report_path_error(m, pattern, prefix);
}
Exemplo n.º 4
0
/// Postprocess settings to compute common prefix.
bool finalize_tool_settings(ToolSettings& s, const boost::program_options::variables_map&) {
	s.tools_common_prefix = common_prefix({
		s.tools_generic, s.tools_smtrat, s.tools_smtrat_opb,
		s.tools_minisatp, s.tools_z3
	});
	BENCHMAX_LOG_DEBUG("benchmax.tools", "Common tool prefix is " << s.tools_common_prefix);
	return false;
}
static void verify_log_output(const size_t buf_sz,
							  const char *const expected[],
							  const size_t expected_n)
{
	const size_t modifiable = buf_sz + 1;
	const size_t unmodifiable = ZF_LOG_BUF_SZ - modifiable;
	if (g_line > expected_n)
	{
		fprintf(stderr, "Lines produced: actual=%u, expected=<%u\n",
				(unsigned)g_line, (unsigned)expected_n);
		exit(1);
	}
	size_t complete_lines = 0;
	for (size_t i = 0; g_line > i; ++i)
	{
		const char *const line = g_lines[i];
		const size_t line_len = strlen(expected[i]);
		const size_t untouched = memchk(line + modifiable, -1, unmodifiable);
		const size_t match = common_prefix(expected[i], line_len,
										   line, g_len[i]);
		if (untouched != unmodifiable)
		{
			fprintf(stderr, "Untouched bytes: actual=%u, expected=%u\n",
					(unsigned)untouched, (unsigned)unmodifiable);
			exit(1);
		}
		if (g_null_pos[i] != g_len[i])
		{
			fprintf(stderr, "Null position: actual=%u, expected=%u\n",
					(unsigned)g_null_pos[i], (unsigned)g_len[i]);
			exit(1);
		}
		if (match < g_len[i])
		{
			fprintf(stderr, "Line partial match: actual=%u, expected=>%u\n",
					(unsigned)match, (unsigned)g_len[i]);
			exit(1);
		}
		if (line_len <= buf_sz)
		{
			++complete_lines;
			if (line_len <= buf_sz && match != g_len[i])
			{
				fprintf(stderr, "Line complete match: actual=%u, expected=%u\n",
						(unsigned)match, (unsigned)g_len[i]);
				exit(1);
			}
		}
	}
	if (expected_n == complete_lines && g_line != expected_n)
	{
		fprintf(stderr, "Complete lines produced: actual=%u, expected=<%u\n",
				(unsigned)g_line, (unsigned)expected_n);
		exit(1);
	}
}
Exemplo n.º 6
0
static int symtab_get_matches(jl_sym_t *tree, const char *str, char **answer)
{
    int x, plen, count=0;
    ios_t ans;

    // given str "X.Y.a", set module := X.Y and name := "a"
    jl_module_t *module = NULL;
    char *name = NULL, *strcopy = strdup(str);
    for (char *s=strcopy, *r=NULL;; s=NULL) {
        char *t = strtok_r(s, ".", &r);
        if (!t) {
            if (str[strlen(str)-1] == '.') {
                // this case is "Module."
                if (name) {
                    if (!module) module = jl_current_module;
                    module = find_submodule_named(module, name);
                    if (!module) goto symtab_get_matches_exit;
                }
                name = "";
            }
            break;
        }
        if (name) {
            if (!module) module = jl_current_module;
            module = find_submodule_named(module, name);
            if (!module) goto symtab_get_matches_exit;
        }
        name = t;
    }

    if (!name) goto symtab_get_matches_exit;
    plen = strlen(name);

    while (tree != NULL) {
        x = common_prefix(name, tree->name);
        if (x == plen) {
            ios_mem(&ans, 0);
            symtab_search(tree, &count, &ans, module, str, name, plen);
            size_t nb;
            *answer = ios_takebuf(&ans, &nb);
            break;
        }
        else {
            x = strcmp(name, tree->name);
            if (x < 0)
                tree = tree->left;
            else
                tree = tree->right;
        }
    }

symtab_get_matches_exit:
    free(strcopy);
    return count;
}
Exemplo n.º 7
0
// If the names of all children have the form (PREFIX)(INDEX)(SUFFIX),
// return the common PREFIX and SUFFIX.
void DispValue::get_index_surroundings(string& prefix, string& suffix) const
{
    assert (nchildren() > 0);

    prefix = child(0)->full_name();
    suffix = child(0)->full_name();

    for (int i = 1; i < nchildren(); i++)
    {
	prefix = common_prefix(prefix, child(i)->full_name());
	suffix = common_suffix(suffix, child(i)->full_name());
    }
}
Exemplo n.º 8
0
static void symtab_search(jl_sym_t *tree, int *pcount, ios_t *result,
                          const char *prefix, int plen)
{
    do {
        if (common_prefix(prefix, tree->name) == plen &&
            jl_boundp(jl_system_module, tree)) {
            ios_puts(tree->name, result);
            ios_putc('\n', result);
            (*pcount)++;
        }
        if (tree->left)
            symtab_search(tree->left, pcount, result, prefix, plen);
        tree = tree->right;
    } while (tree != NULL);
}
Exemplo n.º 9
0
static void symtab_search(jl_sym_t *tree, int *pcount, ios_t *result,
                          jl_module_t *module, const char *str,
                          const char *prefix, int plen)
{
    do {
        if (common_prefix(prefix, tree->name) == plen &&
            (module ? jl_defines_or_exports_p(module, tree) : jl_boundp(jl_current_module, tree))) {
            ios_puts(str, result);
            ios_puts(tree->name + plen, result);
            ios_putc('\n', result);
            (*pcount)++;
        }
        if (tree->left)
            symtab_search(tree->left, pcount, result, module, str, prefix, plen);
        tree = tree->right;
    } while (tree != NULL);
}
Exemplo n.º 10
0
Path::completion Path::complete(String & s) const {
	Path copy(*this);
	copy.rep += '*';
	List<Path> all;
	copy.expand_wildcards(all);

	completion ret = Path::no_completion;
	if (all.length() == 1) {
		// s = all.get()->rep;
		s = all.get().rep;
		ret = Path::unique_completion;
	}
	else if (all.length() > 1) {
		s = common_prefix(all);
		ret = Path::several_completions;
	}	
	return ret;
}
Exemplo n.º 11
0
int fill_directory(struct dir_struct *dir, const char **pathspec)
{
	const char *path;
	int len;

	/*
	 * Calculate common prefix for the pathspec, and
	 * use that to optimize the directory walk
	 */
	len = common_prefix(pathspec);
	path = "";

	if (len)
		path = xmemdupz(*pathspec, len);

	/* Read the directory and prune it */
	read_directory(dir, path, len, pathspec);
	return len;
}
Exemplo n.º 12
0
char* get_longest_prefix(char **results){
	int i;
	int prefix=0;
	int test=0;
	char *ret=NULL;

	if(results && results[0]){
		prefix=strlen(results[0]);
		for(i=1;results[i];i++){
			test=common_prefix(results[0],results[i]);
			prefix=minimum(prefix,test);
		}
		INIT_MEM(ret,(2*prefix)+1);
		memcpy(ret,results[0],prefix);
		ret[prefix]=0;
		add_slashes(ret,prefix+1);
	}

	return ret;
}
Exemplo n.º 13
0
    string longestCommonPrefix(vector<string>& strs) {
        string common_prefix("");
        int maxlength = 0;
        
        for (int i = 0; i < strs.size(); i++) {
            if (strs[i].length() > maxlength)
                maxlength = strs[i].length();
        }
        
        for (int i = 0; i < maxlength; i++) {
            for (int j = 0; j < strs.size(); j++) {
                if (common_prefix.length() == i)
                    common_prefix += strs[j][i];
                else if (common_prefix[i] != strs[j][i])
                    return common_prefix.erase(common_prefix.size() - 1);
            }
        }

        return common_prefix;
        
    }
Exemplo n.º 14
0
// precondition: players should be sorted by team by nameclean or nameclean reverse
void determine_clantags( int prefix )
{
	// if prefix is true , search for prefix, else search for postfix

	// players should be sorted by team by nameclean
	// determine clantags from teams
	// we need to extract the [dbB+ ] part
	// go for the biggest common prefix (for at least half the team)
/*	Let's hear it for the BLUE team :
    PluTo               |
    Spammage            |
    dbB+ BLADE          y1
    dbB+ CROW           |
    dbB+ DEMOMAN        |
    dbB+ DeG            | 
    dbB+ SNK            y2
    duB+ twist          |
	----x--------

	the nr of players from y1 to y2 should be >= pivot
	'x' is the length of the tag
*/
	//int MIN_TAGLENGTH  = 2; // this is the minimum size to be considered a tag
							// btw this fixes a bug too.

	int y1, y2;				// variables to indicate a playerrange : players y1..y2
	int p1, p2;				// indicate the first and last player in a team
	int t;					// variable used in for loop to walk the teams
	int tag_length;			// 
	int max_length;			// longest tag found
	int max_y1, max_y2;		// playerrange of players that have this longest tag in common
	int found_tag;
	int finished;			// tagsearch finished for this team
	int pivot;				// nr of players needed to make it a clantag
	
	// do all the teams
	p1 = 0; p2 = -1;
	for ( t = 0 ; t < team_count ; t++ ) {
		
		p1 = p2 + 1;
		p2 = p1;
		while ( p2 < player_count - 1 && ( sorted_player( p1 )->team == sorted_player( p2 )->team ) ) {
		// look for the last player in this team
			p2++;
		}

		// in case loop ended because of p2 == player_count
		if ( sorted_player( p1 )->team != sorted_player( p2 )->team ) {
			p2--;
		}
		// ok, now we got p1 and p2 being the first and last player of the same team
		pivot = calculate_pivot_point( nr_players_in_range( p1, p2 ) );

		if ( pivot > 0 ) {

			y1 = p1;
			y2 = p1 + 1;
			found_tag = FALSE;
			max_length = 0;
			finished = ( nr_players_in_range( y1, p2 ) < pivot );
			while ( !found_tag && !finished ) {
				
				y2 = y1 + 1;

				//tag_length = 0;
				while ( y2 <= p2 && common_prefix( y1, y2, &tag_length, prefix ) ){
					// we got a playerrange with a common prefix of length "tag_length"

					if ( nr_players_in_range( y1, y2 ) >= pivot ) {
						// we got the number of players needed to make it a clantag
						if ( tag_length > max_length ) {
							// cool, it's even bigger than a previously found tag
							max_length = tag_length;
							max_y1 = y1; // remember first player
							max_y2 = y2; // remember last player

							// because the tag won't get bigger when we increase y2, we
							// may as well speed up the search and break out of this while loop
							break;
						}
					}

					y2++;
				}

				y1++;

				finished = ( nr_players_in_range( y1, p2 ) < pivot );
				// this means there are not enough players in the range y1..p2 to find 
				// a possible clantag, so we might as well stop searching this range.
			}

			if ( max_length >= MIN_TAGLENGTH ) {
				// ok we found it
				found_tag = TRUE;
				if ( prefix ) {
					// normal clantag
					if ( max_length > (signed)strlen( TEAMS[ sorted_player( max_y1 )->team ].clantag ) ) {
						// only copy if it's bigger than the current clantag
						strncopy( TEAMS[ sorted_player( max_y1 )->team ].clantag , sorted_player( max_y1 )->nameclean, max_length );
						create_clantag_html( player_index[ max_y1 ], FALSE );

					}
				}
				else {
					// reverse clantag
					if ( max_length > (signed)strlen( TEAMS[ sorted_player( max_y1 )->team ].clantag ) )  {
						// only copy if it's bigger than the current clantag
						strncopy( TEAMS[ sorted_player( max_y1 )->team ].clantag , 
								  sorted_player( max_y1 )->nameclean + strlen( sorted_player( max_y1 )->nameclean ) - max_length, 
								  max_length );
						create_clantag_html( player_index[ max_y1 ], TRUE );
					}
				}
				rstrip( TEAMS[ sorted_player( max_y1 )->team ].clantag );
			}
		}
		else {
			// don't bother, teamsize is 0 or 1, no use to try to get the clantag
		}
	}
	
}
Exemplo n.º 15
0
static bool extract_theme(const std::string &path, const std::string &target,
                          const std::string &theme_name)
{
    mb::autoclose::archive in(archive_read_new(), archive_read_free);
    if (!in) {
        LOGE("%s: Out of memory when creating archive reader", __FUNCTION__);
        return false;
    }
    mb::autoclose::archive out(archive_write_disk_new(), archive_write_free);
    if (!out) {
        LOGE("%s: Out of memory when creating disk writer", __FUNCTION__);
        return false;
    }

    archive_read_support_format_zip(in.get());

    // Set up disk writer parameters. We purposely don't extract any file
    // metadata
    int flags = ARCHIVE_EXTRACT_SECURE_SYMLINKS
            | ARCHIVE_EXTRACT_SECURE_NODOTDOT;

    archive_write_disk_set_standard_lookup(out.get());
    archive_write_disk_set_options(out.get(), flags);

    if (archive_read_open_filename(in.get(), path.c_str(), 10240) != ARCHIVE_OK) {
        LOGE("%s: Failed to open file: %s",
             path.c_str(), archive_error_string(in.get()));
        return false;
    }

    archive_entry *entry;
    int ret;
    std::string target_path;

    std::string common_prefix("theme/common/");
    std::string theme_prefix("theme/");
    theme_prefix += theme_name;
    theme_prefix += '/';

    while (true) {
        ret = archive_read_next_header(in.get(), &entry);
        if (ret == ARCHIVE_EOF) {
            break;
        } else if (ret == ARCHIVE_RETRY) {
            LOGW("%s: Retrying header read", path.c_str());
            continue;
        } else if (ret != ARCHIVE_OK) {
            LOGE("%s: Failed to read header: %s",
                 path.c_str(), archive_error_string(in.get()));
            return false;
        }

        const char *path = archive_entry_pathname(entry);
        if (!path || !*path) {
            LOGE("%s: Header has null or empty filename", path);
            return false;
        }

        const char *suffix;

        if (mb::util::starts_with(path, common_prefix)) {
            suffix = path + common_prefix.size();
        } else if (mb::util::starts_with(path, theme_prefix)) {
            suffix = path + theme_prefix.size();
        } else {
            LOGV("Skipping: %s", path);
            continue;
        }

        // Build path
        target_path = target;
        if (target_path.back() != '/' && *suffix != '/') {
            target_path += '/';
        }
        target_path += suffix;

        LOGV("Extracting: %s -> %s", path, target_path.c_str());

        archive_entry_set_pathname(entry, target_path.c_str());

        // Extract file
        ret = archive_read_extract2(in.get(), entry, out.get());
        if (ret != ARCHIVE_OK) {
            LOGE("%s: %s", archive_entry_pathname(entry),
                 archive_error_string(in.get()));
            return false;
        }
    }

    if (archive_read_close(in.get()) != ARCHIVE_OK) {
        LOGE("%s: Failed to close file: %s",
             path.c_str(), archive_error_string(in.get()));
        return false;
    }

    return true;
}
Exemplo n.º 16
0
address_prefix address_prefix::common_prefix(const address_prefix & second)const
{
    return common_prefix(*this, second);
}
Exemplo n.º 17
0
int
main (int argc, char **argv)
{
  int i, pid, status, res;
  int time_out, max_decisions;
  char *name;

  pretty_print = 0;
  multiple_files = 0;
  time_out = 3600;
  max_decisions = -1;		/* no bound is default */
#ifdef SAT2002FMT
  verbose = 1;
#else
  verbose = 0;
#endif
  limmat = 0;
  sparse = 0;
  name = 0;

  for (i = 1; i < argc; i++)
    {
      if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help"))
	{
	  usage ();
	  exit (0);
	}
      else if (!strcmp (argv[i], "--clauses"))
	{
	  assignment_as_clauses = 1;
	}
      else if (!strcmp (argv[i], "--version"))
	{
	  printf ("%s\n", version_Limmat ());
	  exit (0);
	}
      else if (!strcmp (argv[i], "--options"))
	{
	  printf ("%s\n", options_Limmat ());
	  exit (0);
	}
      else if (!strcmp (argv[i], "--copyright"))
	{
	  printf ("%s\n", copyright_Limmat ());
	  exit (0);
	}
      else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--verbose"))
	{
	  verbose++;
	}
      else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--sparse"))
	{
	  sparse++;
	}
      else if (!strcmp (argv[i], "-p") || !strcmp (argv[i], "--pretty-print"))
	{
	  pretty_print = 1;
	}
      else if (argv[i][0] == '-' && argv[i][1] == 'm')
	{
	  if (argv[i][2])
	    {
	      if (isdigit ((int) argv[i][2]))
		{
		  max_decisions = atoi (argv[i] + 2);
		}
	      else
		goto EXPECTED_DIGIT_FOR_MAX_DECISIONS_ARGUMENT;
	    }
	  else if (++i < argc && isdigit ((int) argv[i][0]))
	    {
	      max_decisions = atoi (argv[i]);
	    }
	  else
	    goto EXPECTED_DIGIT_FOR_MAX_DECISIONS_ARGUMENT;
	}
      else
	if (argv[i][0] == '-' &&
	    argv[i][1] == '-' &&
	    argv[i][2] == 't' &&
	    argv[i][3] == 'i' &&
	    argv[i][4] == 'm' &&
	    argv[i][5] == 'e' &&
	    argv[i][6] == '-' &&
	    argv[i][7] == 'o' &&
	    argv[i][8] == 'u' && argv[i][9] == 't' && argv[i][10] == '=')
	{
	  if (isdigit ((int) argv[i][11]))
	    {
	      max_decisions = atoi (argv[i] + 11);
	    }
	  else
	    {
	    EXPECTED_DIGIT_FOR_MAX_DECISIONS_ARGUMENT:
	      fprintf (stderr,
		       "*** limmat: expected digit for max decisions argument\n");
	      exit (1);
	    }
	}
      else if (argv[i][0] == '-' && argv[i][1] == 't')
	{
	  if (argv[i][2])
	    {
	      if (isdigit ((int) argv[i][2]))
		{
		  time_out = atoi (argv[i] + 2);
		}
	      else
		goto EXPECTED_DIGIT_FOR_TIME_OUT_ARGUMENT;
	    }
	  else if (++i < argc && isdigit ((int) argv[i][0]))
	    {
	      time_out = atoi (argv[i]);
	    }
	  else
	    goto EXPECTED_DIGIT_FOR_TIME_OUT_ARGUMENT;
	}
      else
	if (argv[i][0] == '-' &&
	    argv[i][1] == '-' &&
	    argv[i][2] == 't' &&
	    argv[i][3] == 'i' &&
	    argv[i][4] == 'm' &&
	    argv[i][5] == 'e' &&
	    argv[i][6] == '-' &&
	    argv[i][7] == 'o' &&
	    argv[i][8] == 'u' && argv[i][9] == 't' && argv[i][10] == '=')
	{
	  if (isdigit ((int) argv[i][11]))
	    {
	      time_out = atoi (argv[i] + 11);
	    }
	  else
	    {
	    EXPECTED_DIGIT_FOR_TIME_OUT_ARGUMENT:
	      fprintf (stderr,
		       "*** limmat: expected digit for time out argument\n");
	      exit (1);
	    }
	}
      else if (argv[i][0] == '-')
	{
	  fprintf (stderr,
		   "*** limmat: unknown command line option '%s' (try '-h')\n",
		   argv[i]);
	  exit (1);
	}
      else if (name)
	{
	  multiple_files = 1;
	}
      else
	name = argv[i];
    }

  if (multiple_files)
    {
      prefix = common_prefix (argv, argc);
      suffix = common_suffix (argv, argc);
      len_prefix = strlen (prefix);
      len_suffix = strlen (suffix);
      sparse = 1;
    }

  if (verbose)
    sparse = 0;

  if (pretty_print)
    {
      if (multiple_files)
	{
	  fprintf (stderr,
		   "*** limmat: can not pretty print multiple files\n");
	  exit (1);
	}

      limmat = new_Limmat (0);
      parse (name);
      print_Limmat (limmat, stdout);
      delete_Limmat (limmat);
      res = ABNORMAL_EXIT_VALUE;
    }
  else
    {
      res = 0;

      if (multiple_files)
	{
	  for (i = 1; !res && i < argc; i++)
	    {
	      if (!skip_arg (argv, &i))
		{
		  if ((pid = fork ()))
		    {
		      wait (&status);
		      if (WIFSIGNALED (status) ||
			  WEXITSTATUS (status) == ABNORMAL_EXIT_VALUE)
			{
			  res = ABNORMAL_EXIT_VALUE;
			}
		    }
		  else
		    child (argv[i], time_out, max_decisions);
		}
	    }
	}
      else
	child (name, time_out, max_decisions);
    }

  if (prefix)
    free (prefix);

  if (suffix)
    free (suffix);

  exit (res);
  return res;
}