std::string terrama2::core::DataAccessorJsonCemaden::getFolderMask(DataSetPtr dataSet) const
{
  auto mask = getProperty(dataSet, dataSeries_, "dcp_data_mask");

  std::string folderMask;
  auto pos = mask.find_last_of("\\/");
  if(pos != std::string::npos)
  {
    for(size_t i = 0; i < pos; ++i)
      folderMask +=mask.at(i);
  }

  return folderMask;
}
示例#2
0
// ---------------------------------------------------------------------------------------
// FUNCTION:  CString::TrimRight
//		CString& TrimRight();
//
// DESCRIPTION:
//		This function removes any whitespace characters from the right end of the string.
//
// PARAMETERS: none
// RETURN VALUE:
//		a reference to this object (*this) -- allows chaining together of
//		these calls, eg. strTest.TrimRight().TrimLeft().ToUpper();
// ---------------------------------------------------------------------------------------
CString& CString::TrimRight()
{
	CString::reverse_iterator iter = std::find_if(rbegin(), rend(), NotSpace());
	if ( iter != rend() )
	{
		CString::size_type nNewSize = find_last_of(*iter);
		erase(nNewSize+1);
	}
	else
	{
		erase();
	}
	return *this;
}
示例#3
0
文件: Files.cpp 项目: openube/ELL
 std::string RemoveFileExtension(std::string filepath)
 {
     auto filename = filepath.substr(filepath.find_last_of("/\\") + 1);
     auto dotPos = filename.find_last_of('.');
     if (dotPos == std::string::npos)
     {
         return filename;
     }
     else
     {
         auto ext = filename.substr(0, dotPos);
         return ext;
     }
 }
示例#4
0
std::string FilePath::toPath(const std::string & path)
{
    auto copy = path;

    std::replace(copy.begin(), copy.end(), '\\', '/');

    auto i = copy.find_last_of('/');
    if (i == copy.size()-1)
    {
        copy = copy.substr(0, copy.size()-1);
    }

    return copy;
}
示例#5
0
std::string _basename_932(std::string path) {
	auto wcs = _conv_from_932(path.c_str());
	if (wcs == NULL) {
		return path.substr(path.find_last_of('\\') + 1);
	}
	auto wpath = std::basic_string<wchar_t>(wcs);
	delete wcs;
	auto dest = _conv_to_932(wpath.substr(wpath.find_last_of(L'\\') + 1).c_str());
	if (dest == NULL) {
		return path.substr(path.find_last_of('\\') + 1);
	}
	auto result = std::string(dest);
	delete dest;
	return result;
}
示例#6
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_base, const pal::string_t& app)
{
    pal::string_t deps_file;
    auto app_name = get_filename(app);
    deps_file.reserve(app_base.length() + 1 + app_name.length() + 5);
    deps_file.append(app_base);

    if (!app_base.empty() && app_base.back() != DIR_SEPARATOR)
    {
        deps_file.push_back(DIR_SEPARATOR);
    }
    deps_file.append(app_name, 0, app_name.find_last_of(_X(".")));
    deps_file.append(_X(".deps.json"));
    return deps_file;
}
示例#7
0
	void H3DString::remove_file_extension(H3DString* extension_found)
	{
		size_t length = size();
		size_t extension_start = find_last_of('.');

		if( extension_start >=0 && extension_start<length)
		{
			if(extension_found)
			{
				*extension_found = substr(extension_start+1, length-extension_start-1);
			}

			*this = substr(0, extension_start);
		}
	}
示例#8
0
void SaveUi::update(float delta)
{
    if (_isBegain)
    {
        // plist frame 为空更新状态,恢复按钮
        if (_allFrames.empty())
        {
            _stat->setString("Save All Done");
            _item->setEnabled(true);
            _isBegain = false;
        }
        else
        {
            // 获取第一个 plist
            auto p = _allFrames.begin();
            auto plist = p->first;
            auto& frame = p->second;
            // 载入内存,载入过跳过
            if (!_isLoad)
            {
                _isLoad = true;
                char buf [32];
                sprintf(buf, "save %luth plist",_count + 1 - _allFrames.size());
                _num->setString(buf);
                SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plist);
                _savePath = _rootPath + "savePic/" + plist.substr(0,plist.find_last_of('.')) + '/';
            }
            if (frame.empty())
            {
                // 图片为空,清除 SpriteFrameCache
                SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(plist);
                _allFrames.erase(p);    // 删除这个 plist
                _isLoad=false;          // 清除载入状态
            }
            else
            {
                // 取出最后 frame 名字
                //auto pic = frame.at(frame.size()-1);
                auto pic = frame.rbegin();
                saveOne(pic->c_str(), _savePath);    //保存图片
                _stat->setString(pic->insert(0, "Save pic: "));
                frame.pop_back();          //删除最后 frame
            }
        }
    }
    Node::update(delta);
}
void PlistAsyncLoader::LoadImageFinishCallBack(float)
{
    if (_itm_q.Empty())
        return;

    auto item = _itm_q.GetTop();

    auto binfo  = item->baseinfo;
    auto pImage = item->image;

    auto pngname = binfo->name;

    pngname.replace(pngname.find_last_of('.'), sizeof(".plist"), ".png");

    auto texture = CCTextureCache::sharedTextureCache()->addUIImage(pImage, pngname.c_str());

    pImage->release();

    auto info = new _TextureInfo();

    info->baseinfo = binfo;
    info->texture  = texture;

    _ttw_q.Push(info);
    
    CCLOG("### LoadImageFinishCallBack: texture = %#x", texture);

    delete item;

    --_image_load_ref;

    if (0 == _image_load_ref)
    {
        CCDirector::sharedDirector()->getScheduler()
            ->unscheduleSelector(schedule_selector(PlistAsyncLoader::LoadImageFinishCallBack), this);
    }

    if (0 == _add_to_cache_ref)
    {
        CCDirector::sharedDirector()->getScheduler()
            ->scheduleSelector(schedule_selector(PlistAsyncLoader::AddToCacheFinishCallBack), this, 0, false);
    }

    ++_add_to_cache_ref;

    _add_to_cache_sleep_cond.notify_all();
}
示例#10
0
std::string FilePath::baseName() const
{
    auto path = this->path();
    auto i = path.find_last_of('/');

    if (i != std::string::npos)
    {
        path = path.substr(++i);
    }

    auto pos = path.find_first_of('.', 1); // Make sure the filename doesn't start with '.'

    if (pos == std::string::npos)
        return path;

    return path.substr(0, pos);
}
示例#11
0
// Get number from file base name ....................................................
int FileName::getNumber() const
{
    size_t skip_directories = find_last_of("/") + 1;
    size_t point = find_first_of(".", skip_directories);
    if (point == npos)
        point = length();
    size_t root_end = find_last_not_of("0123456789", point - 1);
    if (root_end + 1 != point)
    {
        if (point - root_end > FILENAMENUMBERLENGTH)
            root_end = point - FILENAMENUMBERLENGTH - 1;
        String aux = substr(root_end + 1, point - root_end + 1);
        return atoi(aux.c_str());
    }
    else
        return -1;
}
FontWrapper::FontWrapper(SDL_Renderer* rend, const char* path, int size, SDL_Color color, char style)
{
    std::string s_path;
    if(Globals::IS_DEBUG)
    {
        std::string t_path = PROJECT_DIR;
        s_path = t_path + Globals::PATH_TO_FONTS + path;
    }
    else
    {
        auto temp = FilePath::getExecFilePath();
        temp = temp.substr(0, temp.find_last_of("/") );
        s_path = temp + Globals::PATH_TO_FONTS + path;
    }
    
    _font = FC_CreateFont();
    FC_LoadFont(_font, rend, s_path.c_str(), size, color, style);
}
示例#13
0
size_type StringPiece::find_last_of(const StringPiece& s, size_type pos) const {
    if (m_length == 0 || s.m_length == 0)
        return npos;

    // Avoid the cost of BuildLookupTable() for a single-character search.
    if (s.m_length == 1)
        return find_last_of(s.m_ptr[0], pos);

    bool lookup[UCHAR_MAX + 1] = { false };
    BuildLookupTable(s, lookup);
    for (size_type i = std::min(pos, m_length - 1); ; --i) {
        if (lookup[static_cast<unsigned char>(m_ptr[i])])
            return i;
        if (i == 0)
            break;
    }
    return npos;
}
示例#14
0
std::string _dirname_932(std::string path) {
	auto wcs = _conv_from_932(path.c_str());
	auto result = path.find('\\') != std::string::npos ? path.substr(0, path.find_last_of('\\')) : std::string("");
	if (wcs == NULL) {
		return result;
	}
	auto wpath = std::basic_string<wchar_t>(wcs);
	delete wcs;
	if (wpath.find(L'\\') == std::basic_string<wchar_t>::npos) {
		return result;
	}
	auto dest = _conv_to_932(wpath.substr(0, wpath.find_last_of(L'\\')).c_str());
	if (dest == NULL) {
		return result;
	}
	result = std::string(dest);
	delete dest;
	return result;
}
示例#15
0
	void OGLModel::loadModel(std::string modelFile)
	{
		auto dir = ModelMgr::getInstance()->getDir();
		auto fileDir = dir + modelFile;

		Assimp::Importer importer;
		const aiScene *pScene = importer.ReadFile(dir + modelFile, aiProcess_Triangulate | aiProcess_FlipUVs);

		if (!pScene || pScene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !pScene->mRootNode) {
			std::cerr << "Fail to load the model ( " << modelFile << ") : "
				<< importer.GetErrorString() << std::endl;
		}
		else {
			std::cout << "Load Model: " << fileDir << std::endl;
		}

		m_dir = fileDir.substr(0, fileDir.find_last_of('/') + 1);
		processNode(pScene->mRootNode, pScene);
	}
std::string terrama2::core::DataAccessorJsonCemaden::getDataMask(DataSetPtr dataSet) const
{
  auto mask = getProperty(dataSet, dataSeries_, "dcp_data_mask");
  
  std::string fileMask;
  auto pos = mask.find_last_of("\\/");
  if(pos != std::string::npos)
  {
    fileMask = mask.substr(pos+1);
  }
  else
  {
    fileMask = mask;
  }

  boost::replace_all(fileMask, "%UF", getUf(dataSet));
  boost::replace_all(fileMask, "%ID", getStationTypeId(dataSet));
  return fileMask;
}
示例#17
0
    void DivergentAssetBase::AssetIdentifier::OnChange()
    {
        // We need to mark the target file invalidated.
        // this is a little strange, because the target file
        // hasn't actually changed. 
        // 
        // But this is required because some dependent assets
        // don't have a dependency on the asset itself (just
        // on the underlying file). Invalidating the file ensures
        // that we invoke a update on all assets that require it.

        if (_targetFilename.empty()) return;

        auto fn = _targetFilename;
        auto paramStart = fn.find_last_of(':');
		auto end = fn.cend();
        if (paramStart != std::basic_string<ResChar>::npos)
			end = fn.cbegin() + paramStart;

        Services::GetAsyncMan().GetIntermediateStore().ShadowFile(MakeStringSection(AsPointer(fn.cbegin()), AsPointer(end)));
    }
void PlistAsyncLoader::LoadImageWorker()
{
    UniqueMutexLock lock(_image_load_sleep_mutex);
    while (true)
    {
        if (_btw_q.Empty())
        {
            if (_quit_worker)
                break;
            else
                _image_load_sleep_cond.wait(lock);

            continue;
        }

        auto item    = _btw_q.GetTop();
        auto pngname = item->name;

        pngname.replace(pngname.find_last_of('.'), sizeof(".plist"), ".png");
          
        CCImage *pImage = new CCImage();
        if (pImage && !pImage->initWithImageFileThreadSafe(pngname.c_str(), CCImage::kFmtPng))
        {
            CC_SAFE_RELEASE(pImage);
            CCLOG("FATAL: Can not load %s", pngname.c_str());
            delete item;
            return;
        }

        ImageInfoPtr info = new _ImageInfo();
        info->baseinfo    = item;
        info->image       = pImage;

        CCLOG("### LoadImageWorker: pngname = %s, pImage = %#x", pngname.c_str(), pImage);

        _itm_q.Push(info);
    }
}
示例#19
0
文件: Init.hpp 项目: caiopo/INE5408
/**
 * @brief      Gera e indexa o ManPages.dat
 */
void generateManpages() {
	auto files = ls(PATH + "*.txt");

	ArvoreAVL<ManPagePtr> mptree;

	std::ofstream output(MANPAGES, std::ios::out | std::ios::binary);

	if (!output) {
		throw std::runtime_error("Init::generateManpages: could not open file");
	}

	ManPage mp;
	ManPagePtr mpptr;

	for (auto i = files.begin(); i != files.end(); ++i) {
		auto str = readwhole(*i);

		auto comando = i->substr(i->find_first_of("/")+1);

		comando = comando.substr(0, comando.find_last_of("."));

		strcpy(mp.comando, comando.c_str());
		strcpy(mp.conteudo, str.c_str());

		strcpy(mpptr.comando, comando.c_str());

		mpptr.pos = output.tellp();

		mptree.inserir(mpptr);

		output.write((char*) &mp, sizeof(ManPage));
	}

	output.close();

	mptree.saveOnDisk(MANPAGES_TREE);
}
示例#20
0
文件: GitCode.cpp 项目: nicomda/EEDD
/*
void GitCode::eliminarFichero(string nombre){
	
	list<Fichero>::iterator ificheros;
	ificheros = ficheros.begin();
	bool encontrado = false;
	while ((ificheros!=ficheros.end()) && !encontrado){
		if ((*ificheros).GetNombre()== nombre){
			encontrado = true;
		}
		else{
			ificheros++;
		}
		
	}

	if (encontrado){
		list<Commit>::iterator icommits ;
		icommits = commits.begin();
		while (icommits!=commits.end()){
			(*icommits).borrarFichero(nombre);
			icommits++;
		}
		ficheros.erase(ificheros);
	}
	
}
*/
void GitCode::cargaDeFichero(string fileFiche)
{
	string rutaFichero(fileFiche);
	string lineaActual;

	std::ifstream inputStream;
	inputStream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
	inputStream.open(rutaFichero);
	// Extraemos la cabecera del fichero
	inputStream >> lineaActual;
	while (!inputStream.eof()) {
		inputStream >> lineaActual;
		// Parseamos la linea
		auto pos = lineaActual.find(';');
		auto ruta = lineaActual.substr(0, pos);
		auto tama = lineaActual.substr(pos + 1, lineaActual.length());
		// Separamos la ubicacion del nombre del fichero
		pos = ruta.find_last_of('/');
		auto ubicacion = ruta.substr(0, pos + 1);
		auto nombre = ruta.substr(pos + 1, ruta.length());
		// Convertimos el string a int
		auto tamaBytes = std::stoi(tama);
		Fichero f(nombre, ubicacion, tamaBytes);
		//ficheros.push_back(f);
		try {
			nuevoFichero(f);

		}
		catch (ERROR_FICHERO_REPETIDO er) {
			cout << "El fichero ya se encuentra en el sistema";
			er.what();
		}
	}
		inputStream.close();
	
}
示例#21
0
std::string normalized_class_name(const php::Class& cls) {
  auto const name = cls.name->toCppString();
  if (!PreClassEmitter::IsAnonymousClassName(name)) return name;
  return name.substr(0, name.find_last_of(';'));
}
示例#22
0
文件: rescan.c 项目: Duplex923/pzs-ng
int 
main(int argc, char *argv[])
{
	int		n, l, complete_type = 0, not_allowed = 0, argv_mode = 0;

#ifdef USING_GLFTPD
        int             gnum = 0, unum = 0;
	char		myflags[20];
#endif

	char           *ext, exec[4096], *complete_bar = 0, *inc_point[2];
	unsigned int	crc;
	struct stat	fileinfo;

	uid_t		f_uid;
	gid_t		f_gid;
	double		temp_time = 0;

	DIR		*dir, *parent;
	struct dirent	*dp;
	long		loc;
	time_t		timenow;
#if (test_for_password || extract_nfo || zip_clean)
	off_t		tempstream;
#endif

	short		rescan_quick = rescan_default_to_quick;
	char		one_name[NAME_MAX];
	char		*temp_p = NULL;
	int		chdir_allowed = 0, argnum = 0;
	GLOBAL		g;
#if (enable_rescan_script)
	char		target[PATH_MAX+NAME_MAX];
#endif

#if ( program_uid > 0 )
	setegid(program_gid);
	seteuid(program_uid);
#endif

	umask(0666 & 000);

	d_log("rescan: PZS-NG (rescan v2) %s debug log.\n", ng_version);
	d_log("rescan: Rescan executed by: (uid/gid) %d/%d\n", geteuid(), getegid());

#ifdef _ALT_MAX
	d_log("rescan: PATH_MAX not found - using predefined settings! Please report to the devs!\n");
#endif

	d_log("rescan: Allocating memory for variables\n");
	g.ui = ng_realloc2(g.ui, sizeof(*g.ui) * 30, 1, 1, 1);
	g.gi = ng_realloc2(g.gi, sizeof(*g.gi) * 30, 1, 1, 1);

	bzero(one_name, NAME_MAX);

#ifdef USING_GLFTPD
	if (getenv("FLAGS")) {
		strlcpy(myflags, getenv("FLAGS"), sizeof(myflags));
		n = strlen(myflags);
		while (n > 0) {
			--n;
			l = strlen(rescan_chdir_flags);
			while(l > 0) {
				--l;
				if (myflags[n] == rescan_chdir_flags[l])
					chdir_allowed = 1;
			}
		}
	}
	if (!geteuid())
		chdir_allowed = 1;
#endif

	/* With glftpd we can use env vars, rest of the world: commandline. */
#ifndef USING_GLFTPD
	if (argc < 7) {
		print_syntax(chdir_allowed);
		ng_free(g.ui);
		ng_free(g.gi);
		return 0;
	}
	argnum = 6;

	if (chdir(argv[5]) != 0) {
		printf("Could not chdir to <cwd = '%s'>, ftpd agnostic mode: %s\n", argv[5], strerror(errno));
		d_log("rescan: Could not chdir to <cwd = '%s'>, ftpd agnostic mode: %s\n", argv[5], strerror(errno));
		ng_free(g.ui);
		ng_free(g.gi);
		return 1;
        }
#else
	argnum = 1;
#endif

	while ((argnum < argc) && argc > 1) {
		if (!strncasecmp(argv[argnum], "--quick", 7))
			rescan_quick = TRUE;
		else if (!strncasecmp(argv[argnum], "--normal", 8))
			rescan_quick = FALSE;
		else if (!strncasecmp(argv[argnum], "--dir=", 6) && (strlen(argv[argnum]) > 7) && chdir_allowed) {
			temp_p = argv[argnum] + 6;
			if ((!matchpath(nocheck_dirs, temp_p)) && (matchpath(zip_dirs, temp_p) || matchpath(sfv_dirs, temp_p)) && !matchpath(group_dirs, temp_p)) {
				if (chdir(temp_p)) {
					d_log("rescan: Failed to chdir() to %s : %s\n", temp_p, strerror(errno));
					not_allowed = 1;
				}
			} else {
				printf("Not allowed to chdir() to %s\n", temp_p);
				ng_free(g.ui);
				ng_free(g.gi);
				return 1;
			}
			printf("PZS-NG Rescan %s: Rescanning %s\n", ng_version, temp_p);
			argv_mode = 1;

		} else if (!strncasecmp(argv[argnum], "--chroot=", 9) && (strlen(argv[argnum]) > 10) && chdir_allowed) {
			if (temp_p == NULL) {
				temp_p = argv[argnum] + 9;
				if (chroot(temp_p) == -1) {
					d_log("rescan: Failed to chroot() to %s : %s\n", temp_p, strerror(errno));
					not_allowed = 1;
				}
			} else {
				temp_p = argv[argnum] + 9;
				printf("Not allowed to chroot() to %s\n", temp_p);
				ng_free(g.ui);
				ng_free(g.gi);
				return 1;
			}
			printf("PZS-NG Rescan %s: Chroot'ing to %s\n", ng_version, temp_p);
			argv_mode = 1;

		} else if (!strncasecmp(argv[argnum], "--help", 6) || !strncasecmp(argv[argnum], "/?", 2) || !strncasecmp(argv[argnum], "--?", 3)) {
                        print_syntax(chdir_allowed);
			ng_free(g.ui);
			ng_free(g.gi);
                        return 0;
		} else {
			strlcpy(one_name, argv[argnum], sizeof(one_name));
			rescan_quick = FALSE;
			printf("PZS-NG Rescan %s: Rescanning in FILE mode\n", ng_version);
			if (one_name[strlen(one_name) - 1] == '*') {
				one_name[strlen(one_name) - 1] = '\0';
			} else if (!fileexists(one_name)) {
				d_log("PZS-NG Rescan: No file named '%s' exists.\n", one_name);
				one_name[0] = '\0';
				not_allowed = 1;
			}
			argv_mode = 1;
		}
		argnum++;
	}
	if (one_name[0] == '\0') {
		if (rescan_quick == TRUE) {
			printf("PZS-NG Rescan %s: Rescanning in QUICK mode.\n", ng_version);
		} else {
			printf("PZS-NG Rescan %s: Rescanning in NORMAL mode.\n", ng_version);
		}
	}
	printf("PZS-NG Rescan %s: Use --help for options.\n\n", ng_version);

	if (not_allowed) {
		ng_free(g.ui);
		ng_free(g.gi);
		return 1;
	}

	if (!getcwd(g.l.path, PATH_MAX)) {
		d_log("rescan: getcwd() failed: %s\n", strerror(errno));
	}
	if (subcomp(g.l.path, g.l.basepath) && (g.l.basepath[0] == '\0'))
		strlcpy(g.l.basepath, g.l.path, sizeof(g.l.basepath));
	if (strncmp(g.l.path, g.l.basepath, PATH_MAX))
		d_log("rescan: We are in subdir of %s\n", g.l.basepath);
        strlcpy(g.v.misc.current_path, g.l.path, sizeof(g.v.misc.current_path));
        strlcpy(g.v.misc.basepath, g.l.basepath, sizeof(g.v.misc.basepath));

	if ((matchpath(nocheck_dirs, g.l.path) && !rescan_nocheck_dirs_allowed) || (matchpath(group_dirs, g.l.path) && argv_mode) || (!matchpath(nocheck_dirs, g.l.path) && !matchpath(zip_dirs, g.l.path) && !matchpath(sfv_dirs, g.l.path) && !matchpath(group_dirs, g.l.path)) || insampledir(g.l.path)) {
		d_log("rescan: Dir matched with nocheck_dirs/sample_list, or is not in the zip/sfv/group-dirs.\n");
		d_log("rescan: Freeing memory, and exiting.\n");
		printf("Notice: Unable to rescan this dir - check config.\n\n");
		ng_free(g.ui);
		ng_free(g.gi);
		return 0;
	}
	g.v.misc.slowest_user[0] = ULONG_MAX;

	bzero(&g.v.total, sizeof(struct race_total));
	g.v.misc.fastest_user[0] = 0;
	g.v.misc.release_type = RTYPE_NULL;
	g.v.misc.write_log = 0;

#ifdef USING_GLFTPD
	if (getenv("SECTION") == NULL) {
		sprintf(g.v.sectionname, "DEFAULT");
	} else {
		snprintf(g.v.sectionname, sizeof(g.v.sectionname), "%s", getenv("SECTION"));
	}
#else
        snprintf(g.v.sectionname, sizeof(g.v.sectionname), argv[4]);
#endif

	g.l.length_path = (int)strlen(g.l.path);
	g.l.length_zipdatadir = sizeof(storage);
	n = g.l.length_path + g.l.length_zipdatadir + 11;
	g.l.race = ng_realloc2(g.l.race, n, 1, 1, 1);
	g.l.sfv = ng_realloc2(g.l.sfv, n - 1, 1, 1, 1);
	g.l.sfvbackup = ng_realloc2(g.l.sfvbackup, n + 1, 1, 1, 1);
	g.l.leader = ng_realloc2(g.l.leader, n - 2, 1, 1, 1);
	g.l.sfv_incomplete = 0;

	getrelname(&g);

#ifdef USING_GLFTPD
	gnum = buffer_groups(GROUPFILE, 0);
	unum = buffer_users(PASSWDFILE, 0);
#endif

	sprintf(g.l.sfv, storage "/%s/sfvdata", g.l.path);
	sprintf(g.l.sfvbackup, storage "/%s/sfvbackup", g.l.path);
	sprintf(g.l.leader, storage "/%s/leader", g.l.path);
	sprintf(g.l.race, storage "/%s/racedata", g.l.path);
	d_log("rescan: Creating directory to store racedata in\n");
 	maketempdir(g.l.path);

	d_log("rescan: Locking release\n");
	while (1) {
		if ((l = create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 3, 0))) {
			d_log("rescan: Failed to lock release.\n");
			if (l == 1) {
				d_log("rescan: version mismatch. Exiting.\n");
				printf("Error. You need to rm -fR ftp-data/pzs-ng/* before rescan will work.\n"); /* */
				ng_free(g.ui);
				ng_free(g.gi);
				ng_free(g.l.sfv);
				ng_free(g.l.sfvbackup);
				ng_free(g.l.leader);
				ng_free(g.l.race);
#ifdef USING_GLFTPD
				buffer_groups(GROUPFILE, gnum);
				buffer_users(PASSWDFILE, unum);
#endif
				exit(EXIT_FAILURE);
			}
			if (l == PROGTYPE_POSTDEL) {
				n = (signed int)g.v.data_incrementor;
				d_log("rescan: Detected postdel running - sleeping for one second.\n");
				if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue))
					break;
				usleep(1000000);
				if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue))
					break;
				if ( n == (signed int)g.v.data_incrementor) {
					d_log("rescan: Failed to get lock. Forcing unlock.\n");
					if (create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 2, g.v.data_queue)) {
						d_log("rescan: Failed to force a lock.\n");
						d_log("rescan: Exiting with error.\n");
						ng_free(g.ui);
						ng_free(g.gi);
						ng_free(g.l.sfv);
						ng_free(g.l.sfvbackup);
						ng_free(g.l.leader);
						ng_free(g.l.race);
#ifdef USING_GLFTPD
						buffer_groups(GROUPFILE, gnum);
						buffer_users(PASSWDFILE, unum);
#endif
						exit(EXIT_FAILURE);
					}
					break;
				}
			} else {
				for (l = 0; l <= max_seconds_wait_for_lock * 10; ++l) {
					d_log("rescan: sleeping for .1 second before trying to get a lock (queue: %d).\n", g.v.data_queue);
					usleep(100000);
					if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue))
						break;
				}
				if (l >= max_seconds_wait_for_lock * 10) {
					d_log("rescan: Failed to get lock. Will not force unlock.\n");
					ng_free(g.ui);
					ng_free(g.gi);
					ng_free(g.l.sfv);
					ng_free(g.l.sfvbackup);
					ng_free(g.l.leader);
					ng_free(g.l.race);
#ifdef USING_GLFTPD
					buffer_groups(GROUPFILE, gnum);
					buffer_users(PASSWDFILE, unum);
#endif
					exit(EXIT_FAILURE);
				}
			}
		}
		usleep(10000);
		if (update_lock(&g.v, 1, 0) != -1)
			break;
	}

	move_progress_bar(1, &g.v, g.ui, g.gi);
	if (g.l.incomplete)
		unlink(g.l.incomplete);
	if (del_completebar)
		removecomplete();

	dir = opendir(".");
	parent = opendir("..");

	if (!((rescan_quick && findfileext(dir, ".sfv")) || *one_name)) {
		if (g.l.sfv)
			unlink(g.l.sfv);
		if (g.l.race)
			unlink(g.l.race);
	}
	printf("Rescanning files...\n");

	if (findfileext(dir, ".zip")) {
		if (!fileexists(unzip_bin)) {
			printf("rescan: ERROR! Not able to check zip-files - %s does not exist!\n", unzip_bin);
			closedir(dir);
			closedir(parent);
			ng_free(g.ui);
			ng_free(g.gi);
			ng_free(g.l.sfv);
			ng_free(g.l.sfvbackup);
			ng_free(g.l.leader);
			ng_free(g.l.race);
#ifdef USING_GLFTPD
			buffer_groups(GROUPFILE, gnum);
			buffer_users(PASSWDFILE, unum);
#endif
			remove_lock(&g.v);
			exit(EXIT_FAILURE);
		} else {
			crc = 0;
			rewinddir(dir);
			timenow = time(NULL);
			while ((dp = readdir(dir))) {
				ext = find_last_of(dp->d_name, ".");
				if (*ext == '.')
					ext++;
				if (!strcasecmp(ext, "zip")) {
					stat(dp->d_name, &fileinfo);
					f_uid = fileinfo.st_uid;
					f_gid = fileinfo.st_gid;
					if ((timenow == fileinfo.st_ctime) && (fileinfo.st_mode & 0111)) {
						d_log("rescan.c: Seems this file (%s) is in the process of being uploaded. Ignoring for now.\n", dp->d_name);
						continue;
					}
#ifdef USING_GLFTPD
					strlcpy(g.v.user.name, get_u_name(f_uid), sizeof(g.v.user.name));
					strlcpy(g.v.user.group, get_g_name(f_gid), sizeof(g.v.user.group));
#else
					strlcpy(g.v.user.name, argv[1], sizeof(g.v.user.name));
					strlcpy(g.v.user.group, argv[2], sizeof(g.v.user.group));
#endif
					strlcpy(g.v.file.name, dp->d_name, sizeof(g.v.file.name));
					g.v.file.speed = 2005 * 1024;
					g.v.file.size = fileinfo.st_size;
					g.v.total.start_time = 0;
#if (test_for_password || extract_nfo)
					tempstream = telldir(dir);
					if ((!findfileextcount(dir, ".nfo") || findfileextcount(dir, ".zip")) && !mkdir(".unzipped", 0777))
						snprintf(exec, sizeof(exec), "%s -qqjo \"%s\" -d .unzipped 2>.delme", unzip_bin, g.v.file.name);
					else
						snprintf(exec, sizeof(exec), "%s -qqt \"%s\" 2>.delme", unzip_bin, g.v.file.name);
					seekdir(dir, tempstream);
#else
					snprintf(exec, sizeof(exec), "%s -qqt \"%s\" 2>.delme", unzip_bin, g.v.file.name);
#endif
					if (system(exec) == 0 || (allow_error2_in_unzip == TRUE && errno < 3 )) {
						writerace(g.l.race, &g.v, crc, F_CHECKED);
					} else {
						writerace(g.l.race, &g.v, crc, F_BAD);
						if (g.v.file.name)
							unlink(g.v.file.name);
						removedir(".unzipped");
						continue;
					}
#if (test_for_password || extract_nfo || zip_clean)
					tempstream = telldir(dir);
                        	        if ((!findfileextcount(dir, ".nfo") || findfileextcount(dir, ".zip")) && check_zipfile(".unzipped", g.v.file.name, findfileextcount(dir, ".nfo"))) {
                                	        d_log("rescan: File %s is password protected.\n", g.v.file.name);
						writerace(g.l.race, &g.v, crc, F_BAD);
						if (g.v.file.name)
							unlink(g.v.file.name);
						seekdir(dir, tempstream);
						continue;
	                                }
					seekdir(dir, tempstream);
#endif
					if (!fileexists("file_id.diz")) {
						snprintf(exec, sizeof(exec), "%s -qqjnCLL \"%s\" file_id.diz 2>.delme", unzip_bin, g.v.file.name);
						if (execute(exec) != 0) {
							d_log("rescan: No file_id.diz found (#%d): %s\n", errno, strerror(errno));
						} else {
							if (fileexists("file_id.diz.bad")) {
								loc = findfile(dir, "file_id.diz.bad");
								seekdir(dir, loc);
								dp = readdir(dir);
								unlink(dp->d_name);
							}
							if (chmod("file_id.diz", 0666))
								d_log("rescan: Failed to chmod %s: %s\n", "file_id.diz", strerror(errno));
						}
					}
				}
			}

			if (fileexists(".delme"))
				unlink(".delme");

			g.v.total.files = read_diz();
			if (!g.v.total.files) {
				g.v.total.files = 1;
				unlink("file_id.diz");
			}
			g.v.total.files_missing = g.v.total.files;
			readrace(g.l.race, &g.v, g.ui, g.gi);
			sortstats(&g.v, g.ui, g.gi);
			if (g.v.total.files_missing < 0) {
				g.v.total.files -= g.v.total.files_missing;
				g.v.total.files_missing = 0;
			}
			buffer_progress_bar(&g.v);
			if (g.v.total.files_missing == 0) {
				complete(&g, complete_type);
				createstatusbar(convert(&g.v, g.ui, g.gi, zip_completebar));
#if (chmod_completebar)
				if (!matchpath(group_dirs, g.l.path)) {
					if (chmod_each(convert(&g.v, g.ui, g.gi, zip_completebar), 0222))
						d_log("rescan: Failed to chmod a statusbar: %s\n", strerror(errno));
				}
#endif

			} else {
				if (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) {
					if (create_incomplete()) {
						d_log("rescan: create_incomplete() returned something\n");
					}
				}
				move_progress_bar(0, &g.v, g.ui, g.gi);
			}
			if (g.l.nfo_incomplete) {
				if (findfileext(dir, ".nfo")) {
					d_log("rescan: Removing missing-nfo indicator (if any)\n");
					remove_nfo_indicator(&g);
				} else if (matchpath(check_for_missing_nfo_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) {
					if (!g.l.in_cd_dir) {
						d_log("rescan: Creating missing-nfo indicator %s.\n", g.l.nfo_incomplete);
						if (create_incomplete_nfo()) {
							d_log("rescan: create_incomplete_nfo() returned something\n");
						}
					} else {
						if (findfileextparent(parent, ".nfo")) {
							d_log("rescan: Removing missing-nfo indicator (if any)\n");
							remove_nfo_indicator(&g);
						} else {
							d_log("rescan: Creating missing-nfo indicator (base) %s.\n", g.l.nfo_incomplete);
							if (create_incomplete_nfo()) {
								d_log("rescan: create_incomplete_nfo() returned something\n");
							}
						}
					}
				}
			}
		}
	} else if ((temp_p = findfileext(dir, ".sfv")) || (create_missing_sfv && file_count(dir))) {
		if (!temp_p && create_missing_sfv && file_count(dir)) {
			d_log("rescan: No sfv found - creating one.\n");
			make_sfv(g.l.path);
			if (!(temp_p = findfileext(dir, ".sfv"))) {
				d_log("rescan: Freeing memory, removing lock and exiting.\n");
				unlink(g.l.sfv);
				if (fileexists(g.l.sfvbackup))
				unlink(g.l.sfvbackup);
				unlink(g.l.race);
				closedir(dir);
				closedir(parent);
				ng_free(g.ui);
				ng_free(g.gi);
				ng_free(g.l.sfv);
				ng_free(g.l.sfvbackup);
				ng_free(g.l.leader);
				ng_free(g.l.race);
#ifdef USING_GLFTPD
				buffer_groups(GROUPFILE, gnum);
				buffer_users(PASSWDFILE, unum);
#endif
				remove_lock(&g.v);
				return 0;
			}
		}
#if ( create_missing_sfv_link == TRUE )
		d_log("rescan: Removing missing-sfv indicator (if any)\n");
		unlink(g.l.sfv_incomplete);
#endif
		strlcpy(g.v.file.name, temp_p, sizeof(g.v.file.name));

		maketempdir(g.l.path);
		stat(g.v.file.name, &fileinfo);

		if (copysfv(g.v.file.name, g.l.sfv, &g.v)) {
			printf("Found invalid entries in SFV - Exiting.\n");

			while ((dp = readdir(dir))) {
				ext = find_last_of(dp->d_name, "-");
				if (!strcasecmp(ext, "-missing"))
					unlink(dp->d_name);
			}

			d_log("rescan: Freeing memory, removing lock and exiting\n");
			unlink(g.l.sfv);
			if (fileexists(g.l.sfvbackup))
			unlink(g.l.sfvbackup);
			unlink(g.l.race);
			closedir(dir);
			closedir(parent);
			ng_free(g.ui);
			ng_free(g.gi);
			ng_free(g.l.sfv);
			ng_free(g.l.sfvbackup);
			ng_free(g.l.leader);
			ng_free(g.l.race);
#ifdef USING_GLFTPD
			buffer_groups(GROUPFILE, gnum);
			buffer_users(PASSWDFILE, unum);
#endif
			remove_lock(&g.v);

			return 0;
		}
		g.v.total.start_time = 0;
		rewinddir(dir);
		while ((dp = readdir(dir))) {
			if (*one_name && strncasecmp(one_name, dp->d_name, strlen(one_name)))
				continue;

			l = (int)strlen(dp->d_name);

			ext = find_last_of(dp->d_name, ".-");
			if (*ext == '.')
				ext++;

			if (!update_lock(&g.v, 1, 0)) {
				d_log("rescan: Another process wants the lock - will comply and remove lock, then exit.\n");
				closedir(dir);
				closedir(parent);
				ng_free(g.ui);
				ng_free(g.gi);
				ng_free(g.l.sfv);
				ng_free(g.l.sfvbackup);
				ng_free(g.l.leader);
				ng_free(g.l.race);
#ifdef USING_GLFTPD
				buffer_groups(GROUPFILE, gnum);
				buffer_users(PASSWDFILE, unum);
#endif
				remove_lock(&g.v);
				exit(EXIT_FAILURE);
			}

			if (
				!strcomp(ignored_types, ext) &&
				(!(strcomp(allowed_types, ext) && !matchpath(allowed_types_exemption_dirs, g.l.path))) &&
				strcasecmp("sfv", ext) &&
				strcasecmp("nfo", ext) &&
				strcasecmp("bad", ext) &&
				strcasecmp("-missing", ext) &&
				strncmp(dp->d_name, ".", 1)
				) {

				stat(dp->d_name, &fileinfo);

				if (S_ISDIR(fileinfo.st_mode))
					continue;
				if (ignore_zero_sized_on_rescan && !fileinfo.st_size)
					continue;

				f_uid = fileinfo.st_uid;
				f_gid = fileinfo.st_gid;

#ifdef USING_GLFTPD
				strlcpy(g.v.user.name, get_u_name(f_uid), sizeof(g.v.user.name));
				strlcpy(g.v.user.group, get_g_name(f_gid), sizeof(g.v.user.group));
#else
				strlcpy(g.v.user.name, argv[1], sizeof(g.v.user.name));
				strlcpy(g.v.user.group, argv[2], sizeof(g.v.user.group));
#endif

				strlcpy(g.v.file.name, dp->d_name, sizeof(g.v.file.name));
				g.v.file.speed = 2005 * 1024;
				g.v.file.size = fileinfo.st_size;

				temp_time = fileinfo.st_mtime;

				if (g.v.total.start_time == 0)
					g.v.total.start_time = temp_time;
				else
					g.v.total.start_time = (g.v.total.start_time < temp_time ? g.v.total.start_time : temp_time);

				g.v.total.stop_time = (temp_time > g.v.total.stop_time ? temp_time : g.v.total.stop_time);

				/* Hide users in group_dirs */
				if (matchpath(group_dirs, g.l.path) && (hide_group_uploaders == TRUE)) {
					d_log("rescan: Hiding user in group-dir:\n");
					if ((int)strlen(hide_gname) > 0) {
						snprintf(g.v.user.group, sizeof(g.v.user.group), "%s", hide_gname);
						d_log("rescan:    Changing groupname\n");
					}
					if ((int)strlen(hide_uname) > 0) {
						snprintf(g.v.user.name, sizeof(g.v.user.name), "%s", hide_uname);
						d_log("rescan:    Changing username\n");
					}
#if (show_users_in_group_dirs == FALSE)
					if ((int)strlen(hide_uname) == 0) {
						d_log("rescan:    Making username = groupname\n");
						snprintf(g.v.user.name, sizeof(g.v.user.name), "%s", g.v.user.group);
					}
#endif
				}

				if (!rescan_quick || (g.l.race && !match_file(g.l.race, dp->d_name)))
					crc = calc_crc32(dp->d_name);
				else
 					crc = 1;

				if (!S_ISDIR(fileinfo.st_mode)) {
					if (g.v.file.name)
						unlink_missing(g.v.file.name);
					if (l > 44) {
						if (crc == 1)
							printf("\nFile: %s CHECKED", dp->d_name + l - 44);
						else
							printf("\nFile: %s %.8x", dp->d_name + l - 44, crc);
					} else {
						if (crc == 1)
							printf("\nFile: %-44s CHECKED", dp->d_name);
						else
							printf("\nFile: %-44s %.8x", dp->d_name, crc);
					}
				}
				if(fflush(stdout))
					d_log("rescan: ERROR: %s\n", strerror(errno));
				if (!rescan_quick || (g.l.race && !match_file(g.l.race,	dp->d_name)) || !fileexists(dp->d_name))
					writerace(g.l.race, &g.v, crc, F_NOTCHECKED);
			}
		}
		printf("\n");
		testfiles(&g.l, &g.v, 1);
		printf("\n");
		readsfv(g.l.sfv, &g.v, 0);
		readrace(g.l.race, &g.v, g.ui, g.gi);
		sortstats(&g.v, g.ui, g.gi);
		buffer_progress_bar(&g.v);

		if (g.l.nfo_incomplete) {
			if (findfileext(dir, ".nfo")) {
				d_log("rescan: Removing missing-nfo indicator (if any)\n");
				remove_nfo_indicator(&g);
			} else if (matchpath(check_for_missing_nfo_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) {
				if (!g.l.in_cd_dir) {
					d_log("rescan: Creating missing-nfo indicator %s.\n", g.l.nfo_incomplete);
					if (create_incomplete_nfo()) {
						d_log("rescan: create_incomplete_nfo() returned something\n");
					}
				} else {
					if (findfileextparent(parent, ".nfo")) {
						d_log("rescan: Removing missing-nfo indicator (if any)\n");
						remove_nfo_indicator(&g);
					} else {
						d_log("rescan: Creating missing-nfo indicator (base) %s.\n", g.l.nfo_incomplete);

						/* This is not pretty, but should be functional. */
						if ((inc_point[0] = find_last_of(g.l.path, "/")) != g.l.path)
							*inc_point[0] = '\0';
						if ((inc_point[1] = find_last_of(g.v.misc.release_name, "/")) != g.v.misc.release_name)
							*inc_point[1] = '\0';
						if (create_incomplete_nfo()) {
							d_log("rescan: create_incomplete_nfo() returned something\n");
						}
						if (*inc_point[0] == '\0')
							*inc_point[0] = '/';
						if (*inc_point[1] == '\0')
							*inc_point[1] = '/';
					}
				}
			}
		}
#if (create_missing_sample_link)
		if (g.l.sample_incomplete) {
			if (findfileextsub(dir) || matchpartialdirname(missing_sample_check_ignore_list, g.v.misc.release_name, missing_sample_check_ignore_dividers)) {
				d_log("rescan: Removing missing-sample indicator (if any)\n");
				remove_sample_indicator(&g);
			} else if (matchpath(check_for_missing_sample_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) {
				if (!g.l.in_cd_dir) {
					d_log("rescan: Creating missing-sample indicator %s.\n", g.l.sample_incomplete);
					if (create_incomplete_sample()) {
						d_log("rescan: create_incomplete_sample() returned something\n");
					}
				} else {
					if (findfileextsubp(dir)) {
						d_log("rescan: Removing missing-sample indicator (if any)\n");
						remove_sample_indicator(&g);
					} else {
						d_log("rescan: Creating missing-sample indicator (base) %s.\n", g.l.sample_incomplete);

						/* This is not pretty, but should be functional. */
						if ((inc_point[0] = find_last_of(g.l.path, "/")) != g.l.path)
							*inc_point[0] = '\0';
						if ((inc_point[1] = find_last_of(g.v.misc.release_name, "/")) != g.v.misc.release_name)
							*inc_point[1] = '\0';
						if (create_incomplete_sample()) {
							d_log("rescan: create_incomplete_sample() returned something\n");
						}
						if (*inc_point[0] == '\0')
							*inc_point[0] = '/';
						if (*inc_point[1] == '\0')
							*inc_point[1] = '/';
					}
				}
			}
		}
#endif
		if (g.v.misc.release_type == RTYPE_AUDIO) {
			get_audio_info(findfileextfromlist(dir, audio_types), &g.v.audio);
			/* Sort if we're not in a group-dir/nosort-dir. */
			if (!matchpath(group_dirs, g.l.path) && !matchpath(audio_nosort_dirs, g.l.path)) {
				printf(" Resorting release.\n");
				audioSort(&g.v.audio, g.l.link_source, g.l.link_target);
			}
		}
		if ((g.v.total.files_missing == 0) && (g.v.total.files > 0)) {

			switch (g.v.misc.release_type) {
			case RTYPE_RAR:
				complete_bar = rar_completebar;
				break;
			case RTYPE_OTHER:
				complete_bar = other_completebar;
				break;
			case RTYPE_AUDIO:
				complete_bar = audio_completebar;
#if ( create_m3u == TRUE )
				n = snprintf(exec, sizeof(exec), "%s", findfileext(dir, ".sfv"));
				strcpy(exec + n - 3, "m3u");
				create_indexfile(g.l.race, &g.v, exec);
#endif
				break;
			case RTYPE_VIDEO:
				complete_bar = video_completebar;
				break;
			}
			complete(&g, complete_type);

			if (complete_bar) {
				createstatusbar(convert(&g.v, g.ui, g.gi, complete_bar));
#if (chmod_completebar)
				if (!matchpath(group_dirs, g.l.path)) {
                                        if (chmod_each(convert(&g.v, g.ui, g.gi, complete_bar), 0222))
                                                d_log("rescan: Failed to chmod a statusbar: %s\n", strerror(errno));
				}
#endif
			}
#if (enable_rescan_script)
			d_log("rescan: Executing rescan_script script\n");
			if (!fileexists(rescan_script)) {
				d_log("rescan: Warning - rescan_script (%s) - file does not exist!\n", rescan_script);
			} else {
				snprintf(target, sizeof(target), rescan_script " \"%s\"", g.v.file.name);
				if (execute(target) != 0)
					d_log("rescan: Failed to execute rescan_script: %s\n", strerror(errno));
			}
#endif
		} else {
			if (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) {
				if (create_incomplete()) {
					d_log("rescan: create_incomplete() returned something\n");
				}
			}
				move_progress_bar(0, &g.v, g.ui, g.gi);
		}
	} else {
		int empty = 1;
#if (create_missing_sfv_link == TRUE)
		if ((!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) && g.l.sfv_incomplete && !matchpath(nocheck_dirs, g.l.path) && !matchpath(allowed_types_exemption_dirs, g.l.path)) {
			rewinddir(dir);
			while ((dp = readdir(dir))) {
				stat(dp->d_name, &fileinfo);
				if (S_ISREG(fileinfo.st_mode)) {
					ext = find_last_of(dp->d_name, ".");
					if (*ext == '.')
						ext++;
					if (*ext && get_filetype(&g, ext) == 3) {
						d_log("rescan: Creating missing-sfv indicator %s.\n", g.l.sfv_incomplete);
						if (create_incomplete_sfv())
							d_log("rescan: create_incomplete_sfv() returned something.\n");
						empty = 0;
						break;
					}
				}
			}
		}
#endif
		if (empty && mark_empty_dirs_as_incomplete_on_rescan) {
			if (create_incomplete()) {
				d_log("rescan: create_incomplete() returned something\n");
			}
			printf(" Empty dir - marking as incomplete.\n");
		}
	}

	printf(" Passed : %i\n", (int)g.v.total.files - (int)g.v.total.files_missing);
	printf(" Failed : %i\n", (int)g.v.total.files_bad);
	printf(" Missing: %i\n", (int)g.v.total.files_missing);
	printf("  Total : %i\n", (int)g.v.total.files);

	if (g.v.total.files && !g.v.total.files_missing) {
		g.v.misc.data_completed = 1;
	} else {
		g.v.misc.data_completed = 0;
	}

	d_log("rescan: Freeing memory and removing lock.\n");
	closedir(dir);
	closedir(parent);
	ng_free(g.l.race);
	ng_free(g.l.sfv);
	ng_free(g.l.sfvbackup);
	ng_free(g.l.leader);

	remove_lock(&g.v);
	updatestats_free(&g);

#ifdef USING_GLFTPD
	buffer_groups(GROUPFILE, gnum);
	buffer_users(PASSWDFILE, unum);
#endif

	exit(0);
}
示例#23
0
文件: Str.cpp 项目: Jin02/YumeEngine
bool String::EndsWith(const String& str, bool caseSensitive) const
{
    unsigned pos = find_last_of(str, length() - 1, caseSensitive);
    return pos != NPOS && pos == length() - str.length();
}
示例#24
0
	//-----------------------------------------------------------------//
	inline std::string get_file_base(const std::string& src) {
		auto tmp = get_file_name(src);
		return tmp.substr(0, tmp.find_last_of('.'));
	}
示例#25
0
bool MString::endWith(const string &str) const
{
    return find_last_of(str) == (size() - str.size());
}
示例#26
0
std::vector<cleaver::AbstractScalarField*>
NRRDTools::segmentationToIndicatorFunctions(std::string filename, double sigma) {
  // read file using ITK
  if (filename.find(".nrrd") != std::string::npos) {
    itk::NrrdImageIOFactory::RegisterOneFactory();
  } else if (filename.find(".mha") != std::string::npos) {
    itk::MetaImageIOFactory::RegisterOneFactory();
  }
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(filename);
  reader->Update();
  ImageType::Pointer image = reader->GetOutput();
  //determine the number of labels in the segmentations
  ImageCalculatorFilterType::Pointer imageCalculatorFilter
    = ImageCalculatorFilterType::New();
  imageCalculatorFilter->SetImage(reader->GetOutput());
  imageCalculatorFilter->Compute();
  auto maxLabel = static_cast<size_t>(imageCalculatorFilter->GetMaximum());
  auto minLabel = static_cast<size_t>(imageCalculatorFilter->GetMinimum());
  std::vector<cleaver::AbstractScalarField*> fields;
  //extract images from each label for an indicator function
  for (size_t i = minLabel, num = 0; i <= maxLabel; i++, num++) {
    //pull out this label
    ThreshType::Pointer thresh = ThreshType::New();
    thresh->SetInput(image);
    thresh->SetOutsideValue(0);
    thresh->ThresholdOutside(static_cast<double>(i) - 0.001,
      static_cast<double>(i) + 0.001);
    thresh->Update();
    //change the values to be from 0 to 1
    MultiplyImageFilterType::Pointer multiplyImageFilter =
      MultiplyImageFilterType::New();
    multiplyImageFilter->SetInput(thresh->GetOutput());
    multiplyImageFilter->SetConstant(1. / static_cast<double>(i));
    multiplyImageFilter->Update();
    //do some blurring
    GaussianBlurType::Pointer blur = GaussianBlurType::New();
    blur->SetInput(multiplyImageFilter->GetOutput());
    blur->SetVariance(sigma * sigma);
    blur->Update();
    //find the average value between
    ImageCalculatorFilterType::Pointer calc =
      ImageCalculatorFilterType::New();
    calc->SetImage(blur->GetOutput());
    calc->Compute();
    float mx = calc->GetMaximum();
    float mn = calc->GetMinimum();
    auto md = (mx + mn) / 2.f;
    //create a distance map with that minimum value as the levelset
    DMapType::Pointer dm = DMapType::New();
    dm->SetInput(blur->GetOutput());
    dm->SetInsideValue(md + 0.1f);
    dm->SetOutsideValue(md -0.1f);
    dm->Update();
    //MultiplyImageFilterType::Pointer mult =
    //  MultiplyImageFilterType::New();
    //mult->SetInput(blur->GetOutput());
    //mult->SetConstant(-20. / (mx - mn));
    //mult->Update();
    /*SubtractImageFilterType::Pointer subtractFilter
      = SubtractImageFilterType::New();
    subtractFilter->SetInput1(mult->GetOutput());
    subtractFilter->SetConstant2(1.);
    subtractFilter->Update();*/
    //convert the image to a cleaver "abstract field"
    auto img = dm->GetOutput();
    auto region = img->GetLargestPossibleRegion();
    auto numPixel = region.GetNumberOfPixels();
    float *data = new float[numPixel];
    auto x = region.GetSize()[0], y = region.GetSize()[1], z = region.GetSize()[2];
    fields.push_back(new cleaver::FloatField(data, x, y, z));
    auto beg = filename.find_last_of("/") + 1;
    auto name = filename.substr(beg, filename.size() - beg);
    auto fin = name.find_last_of(".");
    name = name.substr(0, fin);
    std::stringstream ss;
    ss << name << i;
    fields[num]->setName(ss.str());
    itk::ImageRegionConstIterator<ImageType> imageIterator(img, region);
    size_t pixel = 0;
    while (!imageIterator.IsAtEnd()) {
      // Get the value of the current pixel
      float val = static_cast<float>(imageIterator.Get());
      ((cleaver::FloatField*)fields[num])->data()[pixel++] = -val;
      ++imageIterator;
    }
    auto spacing = img->GetSpacing();
    ((cleaver::FloatField*)fields[num])->setScale(
      cleaver::vec3(spacing[0], spacing[1], spacing[2]));
    //NRRDTools::saveNRRDFile(fields[num], "a" + std::to_string(num));
  }
  return fields;
}
示例#27
0
std::string disk_index::doc_name(doc_id d_id) const
{
    auto path = doc_path(d_id);
    return path.substr(path.find_last_of("/") + 1);
}
示例#28
0
bool MString::endWith(const char *str) const
{
    return find_last_of(str) == (size() - strlen(str));
}
示例#29
0
	void String::removeUntilReverse(char c){
		size_t ocurr = find_last_of(c);
		if(ocurr == npos)ocurr = 0;
		erase(ocurr, npos);
	};
示例#30
0
size_t DwString::find_last_of(const DwString &aStr, size_t aPos) const
{
    return find_last_of(&aStr.mRep->mBuffer[aStr.mStart], aPos, aStr.mLength);
}