示例#1
0
文件: dag.c 项目: bjarneh/organice
static int all_c_code(const char * f){

    if(is_dir(f) && !starts_with(f,".")){ return 1; }
    
    if(starts_with(f, "_")){ return 0; } //TODO fixme

    if(ends_with(f, ".h") || ends_with(f, ".c")){
        return 1;
    }

    return 0;
};
示例#2
0
TokenMap* TokenMap::from_partitioner(StringRef partitioner) {
  if (ends_with(partitioner, Murmur3Partitioner::name())) {
    return new TokenMapImpl<Murmur3Partitioner>();
  } else if (ends_with(partitioner, RandomPartitioner::name())) {
    return new TokenMapImpl<RandomPartitioner>();
  } else if (ends_with(partitioner, ByteOrderedPartitioner::name())) {
    return new TokenMapImpl<ByteOrderedPartitioner>();
  } else {
    LOG_WARN("Unsupported partitioner class '%s'", partitioner.to_string().c_str());
    return NULL;
  }
}
示例#3
0
static const char *
fqd_http_mime_type(const char *url) {
  if(ends_with(url, ".js")) return "text/javascript";
  if(ends_with(url, ".json")) return "application/json";
  if(ends_with(url, ".css")) return "text/css";
  if(ends_with(url, ".jpg") || ends_with(url, ".jpeg")) return "image/jpeg";
  if(ends_with(url, ".gif")) return "image/gif";
  if(ends_with(url, ".png")) return "image/png";
  if(ends_with(url, "/") || ends_with(url, ".html") || ends_with(url, ".htm"))
    return "text/html";
  return "application/octet-stream";
}
示例#4
0
// This callback function will be called when the decoder produces trace output
void trace_callback(const char* zone, const char* data, void* context)
{
    (void) context;
    // The zone string starts with our custom prefix, so it is easier to
    // check if the zone ends with a given suffix
    if (ends_with(zone, "decoder_state") ||
        ends_with(zone, "symbol_coefficients_before_read_symbol") ||
        ends_with(zone, "symbol_index_before_read_uncoded_symbol"))
    {
        printf("%s:\n", zone);
        printf("%s\n", data);
    }
}
bool MeshModel::saveToFile(const std::string filename) const
{
    std::ofstream outfile(filename);

    if (outfile.bad())
    	return false;

    if (ends_with(filename, "off") || ends_with(filename, "OFF"))
		return saveOFF(outfile);
    else if (ends_with(filename, "obj") || ends_with(filename, "OBJ"))
		return saveOBJ(outfile);

    return false;
}
示例#6
0
文件: stem.c 项目: munnellg/ir_system
static void
step1a(wchar_t *word) {
	int len;
	
	len = wcslen(word);

	if(ends_with(word, L"SSES")) {
		word[len-2] = '\0';
	} else if(ends_with(word, L"IES")) {
		word[len-2] = '\0';
	} else if(!ends_with(word, L"SS") && ends_with(word, L"S")) {
		word[len-1] = '\0';
	}
}
SharedRefPtr<ReplicationStrategy> ReplicationStrategy::from_keyspace_meta(const KeyspaceMetadata& ks_meta) {
  std::string strategy_class = ks_meta.strategy_class();

  SharedRefPtr<ReplicationStrategy> strategy;
  if (ends_with(strategy_class, NetworkTopologyStrategy::STRATEGY_CLASS)) {
    return SharedRefPtr<ReplicationStrategy>(
          new NetworkTopologyStrategy(strategy_class, ks_meta.strategy_options()));
  } else if (ends_with(strategy_class, SimpleStrategy::STRATEGY_CLASS)) {
    return SharedRefPtr<ReplicationStrategy>(
          new SimpleStrategy(strategy_class, ks_meta.strategy_options()));
  } else {
    return SharedRefPtr<ReplicationStrategy>(new NonReplicatedStrategy(strategy_class));
  }
}
示例#8
0
int64_t
GetImageMetadata(const char *path, char *name)
{
	if (ends_with (path, ".jpg") || ends_with (path, ".jpeg"))
	{
		return _get_jpeg_metadata (path, name);
	}
	else if (ends_with (path, ".png"))
	{
		return _get_png_metadata (path, name);
	}
	else
		return 0;
}
示例#9
0
 size_t Environment<T>::print(std::string prefix)
 {
   size_t indent = 0;
   if (parent_) indent = parent_->print(prefix) + 1;
   std::cerr << prefix << std::string(indent, ' ') << "== " << this << std::endl;
   for (typename std::map<std::string, T>::iterator i = local_frame_.begin(); i != local_frame_.end(); ++i) {
     if (!ends_with(i->first, "[f]") && !ends_with(i->first, "[f]4") && !ends_with(i->first, "[f]2")) {
       std::cerr << prefix << std::string(indent, ' ') << i->first << " "  << i->second;
       if (Value* val = dynamic_cast<Value*>(i->second))
       { std::cerr << " : " << val->to_string(); }
       std::cerr << std::endl;
     }
   }
   return indent ;
 }
示例#10
0
inline std::string get_j4a_loader_file(const std::string& value)
{
    if (ends_with(value, ".c")) {
        std::string result(value, 0, value.length() - 2);
        return result + ".loader.j4a";
    } else if (ends_with(value, ".cpp")) {
        std::string result(value, 0, value.length() - 4);
        return result + ".loader.j4a";
    } else if (ends_with(value, ".java")) {
        std::string result(value, 0, value.length() - 5);
        return result + ".loader.j4a";
    }

    return value + ".loader.j4a";
}
示例#11
0
文件: stem.c 项目: munnellg/ir_system
static void
step5(wchar_t *word) {
	int len;
	len = wcslen(word);
	
	if(ends_with(word, L"E") && compute_measure(word, len-1) > 1) {
		word[len-1] = '\0';
	} else if(ends_with(word, L"E") && compute_measure(word, len-1) == 1 && !ends_consonant_vowel_consonant(word, len-1)) {
		word[len-1] = '\0';
	}

	if(ends_with(word, L"L") && compute_measure(word, len) > 1 && ends_double_consonant(word, len)) {
		word[len-1] = '\0';
	}
}
示例#12
0
void DirectoryTree::import_from_files()
{
    QModelIndexList ids = selectionModel()->selectedIndexes();
    if (ids.size() == 0)
        return;
    QModelIndex index = ids.at(0);
    if (!index.isValid())
        return;

    // 弹出对话框
    QStringList files = QFileDialog::getOpenFileNames(this,
        tr("打开文件"),
        QString::fromLocal8Bit(_last_visited_dir.data(), _last_visited_dir.length()),
        "Text file (*.txt)");
    const size_t size = files.size();
    if (size == 0)
        return;

    DirectoryTreeModel *m = dynamic_cast<DirectoryTreeModel*>(model());
    assert(NULL != m);
    for (size_t i = 0; i < size; ++i)
    {
        const QString& file = files.at(i);

        // get title
        string dir, name;
        Path::split(file.toLocal8Bit(), &dir, &name);
        if (!ends_with(name.c_str(), ".txt") && !ends_with(name.c_str(), ".TXT"))
            continue;
        string title;
        Path::split_ext(name.c_str(), &title, NULL);
        _last_visited_dir = dir;

        // get content
        QString all = read_text_file(file);
        all = convert_txt_to_html(all);

        // insert to db
        m->insert_article(index, QString::fromLocal8Bit(title.data(), title.length()),
                          MIME_PKM_RICHTEXT, all);
    }

    // 发送通知
    DirectoryItem *p = static_cast<DirectoryItem*>(index.internalPointer());
    assert(NULL != p);
    PkmPlugin *plugin = dynamic_cast<PkmPlugin*>(get_plugin().pointer());
    plugin->directory_activated(p->get_id(), p->get_name());
}
示例#13
0
/*
 * the::text::string_compare_utility::ends_with
 */
bool the::text::string_compare_utility::ends_with(const char *str,
        size_t strLen, const char *end, size_t endLen, bool matchCase) {
    if ((endLen == 0) || (endLen > strLen)) return false;

    if (matchCase) {
        return ::memcmp(str + (strLen - endLen), end, endLen * sizeof(char))
            == 0;

    } else {
        if (the::text::locale_utility::is_utf8_locale()) {
            the::wstring s, e;
            the::text::string_converter::convert(s, str, strLen);
            the::text::string_converter::convert(e, end, endLen);
            return ends_with(s.c_str(), s.length(), e.c_str(), e.length(),
                false);
        }
        for (size_t i = 0; i < endLen; i++) {
            if (char_utility::to_lower_case(str[strLen - endLen + i])
                    != char_utility::to_lower_case(end[i])) {
                return false;
            }
        }
        return true;
    }
}
示例#14
0
vector<string> *Sound::get_wav_filenames()
{
    vector<string> *wav_filenames = new vector<string>;
    struct dirent *dirent;
    DIR *dir;
    if (base_sound_directory.empty())
    {
        error->log(SOUND, IMPORTANT, "No sound directory specified\n");
        return NULL;
    }
    if ((dir = opendir(base_sound_directory.c_str())) == NULL)
    {
        error->log(SOUND, CRITICAL, "Can't open " + base_sound_directory + "\n");
        return NULL;
    }
    while ((dirent = readdir(dir)))
    {
        if (ends_with(dirent->d_name, ".wav"))
        {
            wav_filenames->push_back(dirent->d_name);
        }
    }
    if (closedir(dir) != 0)
    {
        error->log(SOUND, CRITICAL, "Trouble closing " + base_sound_directory + "\n");
        return NULL;
    }

    return wav_filenames;
}
示例#15
0
文件: main.cpp 项目: eranif/codelite
bool is_source_file(const std::string& filename, std::string &fixed_file_name)
{
    StringVec_t extensions;
    extensions.push_back(".cpp");
    extensions.push_back(".cxx");
    extensions.push_back(".cc");
    extensions.push_back(".c");

    for(size_t n=0; n<extensions.size(); ++n) {
        if ( ends_with(filename, extensions.at(n)) ) {
            fixed_file_name = filename;

#ifdef _WIN32
            std::replace(fixed_file_name.begin(), fixed_file_name.end(), '/', '\\');
#endif
            char* ret = normalize_path(fixed_file_name.c_str(), fixed_file_name.length());
            fixed_file_name = ret;
            free(ret);

            // rtrim
            fixed_file_name.erase(0, fixed_file_name.find_first_not_of("\t\r\v\n\" "));

            // ltrim
            fixed_file_name.erase(fixed_file_name.find_last_not_of("\t\r\v\n\" ")+1);
            return true;
        }
    }
    fixed_file_name.clear();
    return false;
}
示例#16
0
文件: bmarks.c 项目: acklinr/vifm
/* Validates list of tags.  Returns zero if tags are well-formed and non-zero
 * otherwise. */
static int
validate_tags(const char tags[])
{
	return tags[0] == '\0'
	    || starts_with_lit(tags, ",") || strstr(tags, ",,") != NULL
	    || ends_with(tags, ",");
}
示例#17
0
文件: help.c 项目: CSRedRat/git
static int is_executable(const char *name)
{
	struct stat st;

	if (stat(name, &st) || /* stat, not lstat */
	    !S_ISREG(st.st_mode))
		return 0;

#if defined(GIT_WINDOWS_NATIVE)
	/* On Windows we cannot use the executable bit. The executable
	 * state is determined by extension only. We do this first
	 * because with virus scanners opening an executeable for
	 * reading is potentially expensive.
	 */
	if (ends_with(name, ".exe"))
		return S_IXUSR;

{	/* now that we know it does not have an executable extension,
	   peek into the file instead */
	char buf[3] = { 0 };
	int n;
	int fd = open(name, O_RDONLY);
	st.st_mode &= ~S_IXUSR;
	if (fd >= 0) {
		n = read(fd, buf, 2);
		if (n == 2)
			/* look for a she-bang */
			if (!strcmp(buf, "#!"))
				st.st_mode |= S_IXUSR;
		close(fd);
	}
}
#endif
	return st.st_mode & S_IXUSR;
}
示例#18
0
文件: main.c 项目: Lampus/icoutils
static FILE *
extract_outfile_gen(char **outname_ptr, int w, int h, int bc, int i)
{
    char *inname = *outname_ptr;

    if (output == NULL || is_directory(output)) {
	StrBuf *outname;
	char *inbase;

	outname = strbuf_new();
	if (output != NULL) {
	    strbuf_append(outname, output);
	    if (!ends_with(output, "/"))
		strbuf_append(outname, "/");
	}
	inbase = strrchr(inname, '/');
	inbase = (inbase == NULL ? inname : inbase+1);
	if (ends_with_nocase(inbase, ".ico") || ends_with_nocase(inbase, ".cur")) {
	    strbuf_append_substring(outname, inbase, 0, strlen(inbase)-4);
	} else {
	    strbuf_append(outname, inbase);
	}
	strbuf_appendf(outname, "_%d_%dx%dx%d.png", i, w, h, bc);
	*outname_ptr = strbuf_free_to_string(outname);
	return fopen(*outname_ptr, "wb");
    }
    else if (strcmp(output, "-") == 0) {
	*outname_ptr = xstrdup(_("(standard out)"));
	return stdout;
    }

    *outname_ptr = xstrdup(output);
    return fopen(output, "wb");
}
示例#19
0
/**
 * Given path to app binary, say app.dll or app.exe, retrieve the app.deps.json.
 */
pal::string_t get_deps_from_app_binary(const pal::string_t& app)
{
    assert(app.find(DIR_SEPARATOR) != pal::string_t::npos);
    assert(ends_with(app, _X(".dll"), false) || ends_with(app, _X(".exe"), false));

    // First append directory.
    pal::string_t deps_file;
    deps_file.assign(get_directory(app));
    deps_file.push_back(DIR_SEPARATOR);

    // Then the app name and the file extension
    pal::string_t app_name = get_filename(app);
    deps_file.append(app_name, 0, app_name.find_last_of(_X(".")));
    deps_file.append(_X(".deps.json"));
    return deps_file;
}
示例#20
0
 inline bool iends_with( 
     const Range1T& Input, 
     const Range2T& Test,
     const std::locale& Loc=std::locale())
 {
     return ends_with(Input, Test, is_iequal(Loc));
 }
示例#21
0
/**
 * Get the list of midi files directly in the given directory
 * return a vector of file names
 * note: we don't check if they are valid MIDI files, only if the
 * MIDI extension is here
 */
static std::vector<std::string> get_midi_files(const std::string& path) {

    const std::string MIDI_EXTENSION(".mid");

    std::vector<std::string> midiFileNames;

    tinydir_dir midiDir;
    tinydir_open_sorted(&midiDir, path.c_str());

    for (unsigned i = 0; i < midiDir.n_files; i++) {
        tinydir_file file;
        tinydir_readfile_n(&midiDir, &file, i);

        if (file.is_dir) {
            continue;
        }
        std::string tmpFileName(file.name);
        std::cout << tmpFileName << std::endl;

        if (!ends_with(tmpFileName, MIDI_EXTENSION)) {
           continue ;
        }
        std::cout << tmpFileName << std::endl;
        midiFileNames.push_back(tmpFileName);
    }
    tinydir_close(&midiDir);
    return midiFileNames;
}
示例#22
0
/**
 * Concatenate two file names into a new string.
 * If file is "." return a duplicate of file2.
 */
char *
cat_files(const char *file, const char *file2)
{
	if (strcmp(file, ".") == 0)
		return xstrdup(file2);
	return xasprintf("%s%s%s", file, (ends_with(file, "/") ? "" : "/"), file2);
}
示例#23
0
void pack_closure(llvm::Type *
#if LLVM_VERSION >= 37
                  type
#endif
                  ,
                  Value *dst,
                  const Closure& closure,
                  const Scope<Value *> &src,
                  llvm::StructType *buffer_t,
                  IRBuilder<> *builder) {
    // type, type of dst should be a pointer to a struct of the type returned by build_type
    int idx = 0;
    LLVMContext &context = builder->getContext();
    vector<string> nm = closure.names();
    vector<llvm::Type*> ty = llvm_types(closure, buffer_t, context);
    for (size_t i = 0; i < nm.size(); i++) {
#if LLVM_VERSION >= 37
        Value *ptr = builder->CreateConstInBoundsGEP2_32(type, dst, 0, idx);
#else
        Value *ptr = builder->CreateConstInBoundsGEP2_32(dst, 0, idx);
#endif
        Value *val;
        if (!ends_with(nm[i], ".buffer") || src.contains(nm[i])) {
            val = src.get(nm[i]);
            if (val->getType() != ty[i]) {
                val = builder->CreateBitCast(val, ty[i]);
            }
        } else {
            // Skip over buffers not in the symbol table. They must not be needed.
            val = ConstantPointerNull::get(buffer_t->getPointerTo());
        }
        builder->CreateStore(val, ptr);
        idx++;
    }
}
示例#24
0
void SpaceStationType::Init()
{
    assert(s_lua == 0);
    if (s_lua != 0) return;

    s_lua = luaL_newstate();
    lua_State *L = s_lua;

    LUA_DEBUG_START(L);
    pi_lua_open_standard_base(L);

    LuaVector::Register(L);

    LUA_DEBUG_CHECK(L, 0);

    lua_register(L, "define_orbital_station", define_orbital_station);
    lua_register(L, "define_surface_station", define_surface_station);

    namespace fs = FileSystem;
    for (fs::FileEnumerator files(fs::gameDataFiles, "stations", fs::FileEnumerator::Recurse);
            !files.Finished(); files.Next()) {
        const fs::FileInfo &info = files.Current();
        if (ends_with(info.GetPath(), ".lua")) {
            const std::string name = info.GetName();
            s_currentStationFile = name.substr(0, name.size()-4);
            pi_lua_dofile(L, info.GetPath());
            s_currentStationFile.clear();
        }
    }
    LUA_DEBUG_END(L, 0);
}
示例#25
0
int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
{
	const unsigned char *bases[21];
	unsigned bases_count = 0;
	int i, failed;
	unsigned char h1[20], h2[20];
	struct merge_options o;
	struct commit *result;

	init_merge_options(&o);
	if (argv[0] && ends_with(argv[0], "-subtree"))
		o.subtree_shift = "";

	if (argc < 4)
		usagef(builtin_merge_recursive_usage, argv[0]);

	for (i = 1; i < argc; ++i) {
		const char *arg = argv[i];

		if (starts_with(arg, "--")) {
			if (!arg[2])
				break;
			if (parse_merge_opt(&o, arg + 2))
				die("Unknown option %s", arg);
			continue;
		}
		if (bases_count < ARRAY_SIZE(bases)-1) {
			unsigned char *sha = xmalloc(20);
			if (get_sha1(argv[i], sha))
				die("Could not parse object '%s'", argv[i]);
			bases[bases_count++] = sha;
		}
		else
			warning("Cannot handle more than %d bases. "
				"Ignoring %s.",
				(int)ARRAY_SIZE(bases)-1, argv[i]);
	}
	if (argc - i != 3) /* "--" "<head>" "<remote>" */
		die("Not handling anything other than two heads merge.");

	o.branch1 = argv[++i];
	o.branch2 = argv[++i];

	if (get_sha1(o.branch1, h1))
		die("Could not resolve ref '%s'", o.branch1);
	if (get_sha1(o.branch2, h2))
		die("Could not resolve ref '%s'", o.branch2);

	o.branch1 = better_branch_name(o.branch1);
	o.branch2 = better_branch_name(o.branch2);

	if (o.verbosity >= 3)
		printf("Merging %s with %s\n", o.branch1, o.branch2);

	failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
	if (failed < 0)
		return 128; /* die() error code */
	return failed;
}
示例#26
0
void remove_realm_files_from_directory(const std::string &dir_path)
{
    FileSystemRequest scandir_req;
    if (uv_fs_scandir(uv_default_loop(), &scandir_req, dir_path.c_str(), 0, nullptr) < 0) {
        throw UVException(static_cast<uv_errno_t>(scandir_req.result));
    }

    uv_dirent_t entry;
    while (uv_fs_scandir_next(&scandir_req, &entry) != UV_EOF) {
        std::string path(dir_path + '/' + entry.name);

        if (entry.type == UV_DIRENT_DIR) {
            static std::string realm_management_extension(".realm.management");
            if (ends_with(path, realm_management_extension)) {
                uv_dirent_t management_entry;
                FileSystemRequest management_scandir_req;
                if (uv_fs_scandir(uv_default_loop(), &management_scandir_req, path.c_str(), 0, nullptr) < 0) {
                    throw UVException(static_cast<uv_errno_t>(scandir_req.result));
                }

                while (uv_fs_scandir_next(&management_scandir_req, &management_entry) != UV_EOF) {
                    std::string management_entry_path = path + '/' + management_entry.name;
                    FileSystemRequest delete_req;
                    if (uv_fs_unlink(uv_default_loop(), &delete_req, management_entry_path.c_str(), nullptr) != 0) {
                        throw UVException(static_cast<uv_errno_t>(delete_req.result));
                    }
                }

                FileSystemRequest management_rmdir_req;
                if (uv_fs_rmdir(uv_default_loop(), &management_rmdir_req, path.c_str(), nullptr)) {
                    throw UVException(static_cast<uv_errno_t>(management_rmdir_req.result));
                }
            }
        } else {
            static std::string realm_extension(".realm");
            static std::string realm_note_extension(".realm.note");
            static std::string realm_lock_extension(".realm.lock");
            if (ends_with(path, realm_extension) || ends_with(path, realm_note_extension) || ends_with(path, realm_lock_extension)) {
                FileSystemRequest delete_req;
                if (uv_fs_unlink(uv_default_loop(), &delete_req, path.c_str(), nullptr) != 0) {
                    throw UVException(static_cast<uv_errno_t>(delete_req.result));
                }
            }
        }
    }
}
示例#27
0
/**
 * Initialize resolved paths to known entries like coreclr, jit.
 */
void deps_resolver_t::init_known_entry_path(const deps_entry_t& entry, const pal::string_t& path)
{
    if (entry.asset_type != deps_entry_t::asset_types::native)
    {
        return;
    }
    if (m_coreclr_path.empty() && ends_with(entry.relative_path, _X("/") + pal::string_t(LIBCORECLR_NAME), false))
    {
        m_coreclr_path = path;
        return;
    }
    if (m_clrjit_path.empty() && ends_with(entry.relative_path, _X("/") + pal::string_t(LIBCLRJIT_NAME), false))
    {
        m_clrjit_path = path;
        return;
    }
}
示例#28
0
文件: pkg.c 项目: bjarneh/organice
// TODO fix this stuff
static int pkg_is_main(struct pkg * slf){

    if( ! slf->h_file ){
        return ends_with(slf->c_file, "main.c");
    }
    
    return 0;
};
示例#29
0
int is_compressed_with_index(const char *path, int *index) {
    if(ends_with(path, ".compr")) {
        *index = strlen(path) - strlen(".compr");
        return 1;
    } else
        *index = -1;

    return 0;
}
示例#30
0
文件: stem.c 项目: munnellg/ir_system
static void
step1c(wchar_t *word) {
	int len;
	len = wcslen(word);
	
	if(ends_with(word, L"Y") && contains_vowel(word, len-2) > 0) {
		word[len-1] = 'i';
	}
}