Example #1
0
RecentFiles::RecentFiles()
  : m_files(16)
  , m_paths(16)
{
  char buf[512];

  for (int c=m_files.limit()-1; c>=0; c--) {
    sprintf(buf, "Filename%02d", c);

    const char* filename = get_config_string("RecentFiles", buf, NULL);
    if (filename && *filename && base::is_file(filename)) {
      std::string fn = normalizePath(filename);
      m_files.addItem(fn, compare_path(fn));
    }
  }

  for (int c=m_paths.limit()-1; c>=0; c--) {
    sprintf(buf, "Path%02d", c);

    const char* path = get_config_string("RecentPaths", buf, NULL);
    if (path && *path) {
      std::string p = normalizePath(path);
      m_paths.addItem(p, compare_path(p));
    }
  }
}
Example #2
0
		bool File::rename(const String &sourcePath, const String &targetPath)
		{
			if(sourcePath.isEmpty() || targetPath.isEmpty())
				return false;
				
			return FileImpl::rename(normalizePath(sourcePath), normalizePath(targetPath));
		}
/**
 * This is the most important part of this class.  Here we
 * attempt to find, load, and initialize a java (or mlvm?) virtual
 * machine.
 * 
 * @return true if successful, else false    
 */ 
bool JavaBinderyImpl::loadJVM()
{
    if (jvm)
        return true;

    CreateVMFunc createVM = getCreateVMFunc();
    if (!createVM)
        {
        err("Could not find 'JNI_CreateJavaVM' in shared library");
        return false;
        }

    String javaroot;
    getJavaRoot(javaroot);
    String cp;
    populateClassPath(javaroot, cp);
    String classpath = "-Djava.class.path=";
    classpath.append(normalizePath(cp));
    msg("Class path is: '%s'", classpath.c_str());

    String libpath = "-Djava.library.path=";
    libpath.append(javaroot);
    libpath.append(DIR_SEPARATOR);
    libpath.append("libm");
    libpath = normalizePath(libpath);
    msg("Lib path is: '%s'", libpath.c_str());

    JavaVMInitArgs vm_args;
    JavaVMOption options[10];//should be enough
    int nOptions = 0;
    options[nOptions++].optionString = (char *)classpath.c_str();
    options[nOptions++].optionString = (char *)libpath.c_str();
    //options[nOptions++].optionString = (char *)"-verbose:jni";
    options[nOptions  ].optionString = (char *)"vfprintf";
    options[nOptions++].extraInfo    = (void *)vfprintfHook;
    vm_args.version                  = JNI_VERSION_1_4;
    vm_args.options                  = options;
    vm_args.nOptions                 = nOptions;
    vm_args.ignoreUnrecognized       = true;

    if (createVM(&jvm, &env, &vm_args) < 0)
        {
        err("JNI_CreateJavaVM() failed");
        return false;
        }

    //get jvm version
    jint vers = env->GetVersion();
    int versionMajor = (vers>>16) & 0xffff;
    int versionMinor = (vers    ) & 0xffff;
    msg("Loaded JVM version %d.%d", versionMajor, versionMinor);

    if (!setupGateway())
        return false;

    return true;
}
Example #4
0
int main(void) {
  {
    char path[] = "./test/casper/formelement.input.test.coffee.tested.do";
    char dir[sizeof path];
    char base[sizeof path];

    dirname(dir, base, path);

    eqStr(dir, "./test/casper");
    eqStr(base, "formelement.input.test.coffee.tested.do");
  }

  {
    const char *filename = "dir/file.tar.gz";
    char       *iter     = (char*)filename;

    eqStr(iter, "dir/file.tar.gz");
    iter = nextExtension(iter);
    eqStr(iter, ".tar.gz");
    iter = nextExtension(iter);
    eqStr(iter, ".gz");
    iter = nextExtension(iter);
    eqStr(iter, "");
  }

  {
    const char *s = "/this/is/a/file.gz";
    char        hex[strlen(s)*2+1];
    char        unhex[sizeof hex + 1];

    hexify(hex, s);
    eqStr(hex, "-_this-_is-_a-_file.gz");
    unhexify(unhex, hex);
    eqStr(unhex, "/this/is/a/file.gz");
  }

  {
    char cwd[] = "/root",
         target[] = "./a/b",
         dest[4096];

    normalizePath(dest, cwd, target);
    eqStr(dest, "/root/a/b");
  }

  {
    char cwd[] = "/root/other",
         target[] = "./a/../b/dir/e",
         dest[4096];

    normalizePath(dest, cwd, target);
    eqStr(dest, "/root/other/b/dir/e");
  }

  return 0;
}
Example #5
0
void Importer::normalizeSceneImports(Node& root, const std::string& parentPath) {
    if (Node import = root["import"]) {
        if (import.IsScalar()) {
            import = normalizePath(import.Scalar(), parentPath);
        } else if (import.IsSequence()) {
            for (Node imp : import) {
                if (imp.IsScalar()) { imp = normalizePath(imp.Scalar(), parentPath); }
            }
        }
    }
}
Example #6
0
bool PackageManager::fileExists(const Common::String &fileName) {
	// FIXME: The current Zip implementation doesn't support getting a folder entry, which is needed for detecting
	// the English voick pack
	if (fileName == "/speech/en") {
		// To get around this, change to detecting one of the files in the folder
		return getArchiveMember(normalizePath(fileName + "/APO0001.ogg", _currentDirectory));
	}

	Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory));
	return fileNode;
}
Example #7
0
/* Check that the given pathname is normal.  If not, invoke the real
   normalizer on the part of the pathname that requires normalization.
   This way we iterate through the whole pathname string only once. */
char* normalize(const char* pathname) {
    int i;
    int n = strlen(pathname);
    char prevChar = 0;
    for (i = 0; i < n; i++) {
        char c = pathname[i];
        if ((prevChar == slash) && (c == slash))
            return normalizePath(pathname, n, i - 1);
        prevChar = c;
    }
    if (prevChar == slash) return normalizePath(pathname, n, n - 1);
    return (char*)pathname;
}
Example #8
0
void Importer::setNormalizedTexture(Node& texture, const std::vector<std::string>& names,
                                    const std::string& parentPath) {

    for (size_t index = 0; index < names.size(); index++) {

        auto& name = names[index];
        if (isBase64Data(name)) {
            continue;
        }

        std::string normTexPath;

        // if texture url is a named texture then move on (this has been already resolved
        if (m_globalTextures.find(name) != m_globalTextures.end()) { continue; }

        // get normalized texture path
        if (m_textureNames.find(name) == m_textureNames.end()) {
            normTexPath = normalizePath(name, parentPath);
            m_textureNames[name] = normTexPath;
        } else {
            normTexPath = m_textureNames.at(name);
        }

        // set yaml node with normalized texture path
        if (names.size() > 1) {
            texture[index] = normTexPath;
        } else {
            texture = normTexPath;
        }
    }
}
Example #9
0
		uint64 File::size(const String &filePath)
		{
			if(filePath.isEmpty())
				return 0;
				
			return FileImpl::size(normalizePath(filePath));
		}
Example #10
0
		std::time_t File::lastWriteTime(const String &filePath)
		{
			if(filePath.isEmpty())
				return 0;
				
			return FileImpl::lastWriteTime(normalizePath(filePath));
		}
Example #11
0
		bool File::exists(const String &filePath)
		{
			if(filePath.isEmpty())
				return false;
				
			return FileImpl::exists(normalizePath(filePath));
		}
Example #12
0
/*--------------------------------------------------------------------------*/
char *get_full_path(char *_FullPath, const char *_Path, size_t _SizeInBytes)
{
#if defined(_MSC_VER)
    char *returnedFullPath = NULL;

    wchar_t *wPath = to_wide_string((char *)_Path);
    wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);

    _wfullpath(wFullPath, wPath, _SizeInBytes);
    returnedFullPath = wide_string_to_UTF8(wFullPath);
    if (returnedFullPath)
    {
        strcpy(_FullPath, returnedFullPath);
        FREE(returnedFullPath);
        returnedFullPath = NULL;
    }

    if (wPath)
    {
        FREE(wPath);
        wPath = NULL;
    }
    if (wFullPath)
    {
        FREE(wFullPath);
        wFullPath = NULL;
    }

    return _FullPath;
#else
    char *rp = NULL;
    int lenPath = (int)strlen(_Path);

    rp = realpath(_Path, _FullPath);
    int lenFullPath = 0;
    int haveFileSep = ((lenPath > 1) && isDirSeparator(_Path[lenPath - 1]));
    int addFileSep = 0;

    if (!rp)
    {
        strcpy(_FullPath, _Path);
        normalizePath(_FullPath);
    }
    lenFullPath = (int)strlen(_FullPath);
    addFileSep = ((lenFullPath > 1) && (!isDirSeparator(_FullPath[lenFullPath - 1])) && haveFileSep);
    if (addFileSep)
    {
        char *bufTmp = (char *)MALLOC(sizeof(char) * (lenFullPath + strlen(DIR_SEPARATOR) + 1));

        if (bufTmp)
        {
            sprintf(bufTmp, "%s%s", _FullPath, DIR_SEPARATOR);
            strcpy(_FullPath, bufTmp);
            FREE(bufTmp);
            bufTmp = NULL;
        }
    }
    return _FullPath;
#endif
}
Example #13
0
static int getDriverIndex(const char* aPath)
{
    char driverName[128];
    char *path, *last;
    char *firstDot;
    int i;

    // Get all chars after the last slash
    path = normalizePath(strdup(aPath ? aPath : "."));
    last = strrchr(path, PATH_SEPARATOR);
    memset(driverName, 0, sizeof(driverName));
    strncpy(driverName, last ? last + 1 : path, sizeof(driverName) - 1);
    free(path);
    
    // Remove extension    
    firstDot = strchr(driverName, '.');

    if(firstDot)
       *firstDot = 0;

    // Search list
    for (i = 0; drivers[i]; i++)
    {
       if(strcmp(driverName, drivers[i]->name) == 0)
       {
          if (log_cb)
             log_cb(RETRO_LOG_INFO, "Found game: %s [%s].\n", driverName, drivers[i]->name);
          return i;
       }
    }
    
    return -1;
}
Example #14
0
bool PackageManager::fileExists(const Common::String &fileName) {
	// FIXME: The current Zip implementation doesn't support getting a folder entry, which is needed for detecting
	// the English voice pack
	Common::String fileName2 = ensureSpeechLang(fileName);
	if (fileName2 == "/speech/en") {
		// To get around this, change to detecting one of the files in the folder
		bool exists = getArchiveMember(normalizePath(fileName2 + "/APO0001.ogg", _currentDirectory));
		if (!exists && _useEnglishSpeech) {
			_useEnglishSpeech = false;
			warning("English speech not found");
		}
		return exists;
	}

	Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName2, _currentDirectory));
	return fileNode;
}
Example #15
0
void Importer::normalizeSceneDataSources(Node &root, const std::string &parentPath) {
    if (Node sources = root["sources"]) {
        for (auto source : sources) {
            if (Node sourceUrl = source.second["url"]) {
                sourceUrl = normalizePath(sourceUrl.Scalar(), parentPath);
            }
        }
    }
}
	RecognitionResult GeometricRecognizer::recognize(Path2D points)
	{
		//--- Make sure we have some templates to compare this to
		//---  or else recognition will be impossible
        
        if (points.size() < 5){
            return RecognitionResult("Unknown", NULL);
        }
        
        if (templates.empty())
		{
			std::cout << "No templates loaded so no symbols to match." << std::endl;
			return RecognitionResult("Unknown", NULL);
		}

		points = normalizePath(points);
	
		//--- Initialize best distance to the largest possible number
		//--- That way everything will be better than that
		double bestDistance = MAX_DOUBLE;
		//--- We haven't found a good match yet
		int indexOfBestMatch = -1;

		//--- Check the shape passed in against every shape in our database
		for (int i = 0; i < (int)templates.size(); i++)
		{
			//--- Calculate the total distance of each point in the passed in
			//---  shape against the corresponding point in the template
			//--- We'll rotate the shape a few degrees in each direction to
			//---  see if that produces a better match
			double distance = distanceAtBestAngle(points, templates[i]);
			if (distance < bestDistance)
			{
				bestDistance     = distance;
				indexOfBestMatch = i;
			}
		}

		//--- Turn the distance into a percentage by dividing it by 
		//---  half the maximum possible distance (across the diagonal 
		//---  of the square we scaled everything too)
		//--- Distance = hwo different they are
		//--- Subtract that from 1 (100%) to get the similarity
		double score = 1.0 - (bestDistance / halfDiagonal);

		//--- Make sure we actually found a good match
		//--- Sometimes we don't, like when the user doesn't draw enough points
		if (-1 == indexOfBestMatch)
		{
			//cout << "Couldn't find a good match." << endl;
			return RecognitionResult("Unknown", 1);
		}

        cout<<score<<endl;
		RecognitionResult bestMatch(templates[indexOfBestMatch].name, score);
		return bestMatch;
	};
Example #17
0
 const std::string getRootDirectory(const char * relativeDirectory)
 {
     char buffer[100];
     char * cwd = getcwd(buffer, sizeof(buffer));
     if(cwd != 0)
     {
         return normalizePath(std::string(cwd) + "/", std::string(relativeDirectory) + "/", "/bin/kerberos");
     }
     return "";
 }
Example #18
0
Common::SeekableReadStream *PackageManager::getStream(const Common::String &fileName) {
	Common::SeekableReadStream *in;
	Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory));
	if (!fileNode)
		return 0;
	if (!(in = fileNode->createReadStream()))
		return 0;

	return in;
}
Example #19
0
void RecentFiles::removeRecentFile(const char* filename)
{
  std::string fn = normalizePath(filename);
  m_files.removeItem(fn, compare_path(fn));

  std::string path = base::get_file_path(filename);
  m_paths.removeItem(path, compare_path(path));

  Changed();
}
Example #20
0
/* 
 * Check that the given pathname is normal.  If not, invoke the real
 * normalizer on the part of the pathname that requires normalization.
 * This way we iterate through the whole pathname string only once. 
 */
char* normalize(char* path) {        
    int n = (int)strlen(path);
    int i;
    char c = 0;
    int prev = 0;
    for (i = 0; i < n; i++) {
	char c = path[i];
	if (c == altSlash)
	    return normalizePath(path, n, (prev == slash) ? i - 1 : i);
	if ((c == slash) && (prev == slash) && (i > 1))
	    return normalizePath(path, n, i - 1);
	if ((c == ':') && (i > 1))
	    return normalizePath(path, n, 0);
	prev = c;
    }
    if (prev == slash) 
	return normalizePath(path, n, n - 1);
    return path;
}
std::string StandardDirectory::getPath(const char* relativePath) const
	{
	/* Assemble and normalize the absolute path name: */
	std::string result=pathName;
	if(result.length()>1)
		result.push_back('/');
	result.append(relativePath);
	normalizePath(result,1);
	
	return result;
	}
Example #22
0
void splitPath(const string &path, string &dir, string &file)
{
    string normal = normalizePath(path);
    size_t offset = normal.rfind('/');
    if (offset != normal.npos) {
        dir = normal.substr(0, offset);
        file = normal.substr(offset + 1);
    } else {
        dir = "";
        file = normal;
    }
}
Example #23
0
void Alcatraz::rmdir_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch(maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break ;
    case PATH_DELETED:{
	arch->abortCall(pid, -1, ENOENT);
	break ;
    }		   
    case PATH_CREATED: 
    case PATH_MODIFIED:{
	int retval = rmdir(buf) ;
	if (0 == retval) {
	    mt.delMapping(tempname) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", normpath, "N/A", "DE", pid, ppid) ;
#endif
	} else {
	    arch->abortCall(pid, -1, errno) ;
	}
	break ;
    }
    case PATH_NEW:{
	int retval = rmdir_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} else {
	    mt.newDelete(TYPE_DIRECTORY, buf) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", buf, "N/A", "DE", pid, ppid) ;
#endif
	}
	break ;
    }
    default:
	break; 
    }

}
Example #24
0
void FileMgr::operateFile(String& fullname, OperateCB cb, InternalOperateCB cb2)
{
   normalizePath(fullname);

   // any files operate discover will be added to the list of files
   String hash(toString(fullname.cStr()));

   // hollaback!
   if (cb)
      cb(hash);
   else if (cb2)
      cb2(fullname.cStr());
}
Example #25
0
    sf::Texture* getTexture(std::string path){
        normalizePath(path);
        auto it = _textures.find(path);
        if(it!=_textures.end())
            return it->second;

        sf::Texture* tex = new sf::Texture();
        if(tex->loadFromFile("resources/" + path)){
            _textures[path] = tex;
            return tex;
        }
        delete tex;
        return nullptr;
    }
std::string StandardDirectory::getPath(const char* relativePath) const
	{
	/* Check if the given path is absolute: */
	if(relativePath[0]=='/')
		{
		/* Normalize the given absolute path name: */
		std::string result=relativePath;
		normalizePath(result,1);
		
		return result;
		}
	else
		{
		/* Assemble and normalize the absolute path name: */
		std::string result=pathName;
		if(result.length()>1)
			result.push_back('/');
		result.append(relativePath);
		normalizePath(result,1);
		
		return result;
		}
	}
	int GeometricRecognizer::addTemplate(string name, Path2D points)
	{
		points = normalizePath(points);

                allTemplates.push_back(GestureTemplate(name, points));
		//--- Let them know how many examples of this template we have now
		int numInstancesOfGesture = 0;
		// You know, i don't care so i'm just going to ignore this
		//for (var i = 0; i < templates.size(); i++)
		//{
		//	if (templates[i].Name == name)
		//		numInstancesOfGesture++;
		//}
		return numInstancesOfGesture;
	}
Example #28
0
/*--------------------------------------------------------------------------*/
wchar_t *get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t _SizeInBytes)
{
    wchar_t *wcResult = NULL;

#if defined(_MSC_VER)
    if (_wcPath)
    {
        wcResult = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);
        if (wcResult)
        {
            _wfullpath(wcResult, _wcPath, _SizeInBytes);
            wcscpy(_wcFullPath, wcResult);
        }
    }
#else
    if (_wcPath)
    {
        char *_Path = wide_string_to_UTF8(_wcPath);

        if (_Path)
        {
            char *_FullPath = (char *)MALLOC(sizeof(char) * (_SizeInBytes));

            if (_FullPath)
            {
                char *rp = NULL;

                rp = realpath(_Path, _FullPath);
                if (!rp)
                {
                    strcpy(_FullPath, _Path);
                    normalizePath(_FullPath);
                }
                wcResult = to_wide_string(_FullPath);
                if (wcResult)
                {
                    wcscpy(_wcFullPath, wcResult);
                }
                FREE(_FullPath);
                _FullPath = NULL;
            }
            FREE(_Path);
            _Path = NULL;
        }
    }
#endif
    return wcResult;
}
Example #29
0
		bool File::rename(const String &filePath)
		{
			_mutex.lock();
			
			bool opened = isOpen();
			close();
			
			bool success = rename(_filePath, filePath);
			if(success)
				_filePath = normalizePath(filePath);
				
			if(opened)
				open();
				
			return success;
		}
Example #30
0
FILE* openFile(const char* path, const char* mode)
{
	// we need to get a full path to the file for relative paths (normalizePath will always work, isFullPath is an optimization)
	std::wstring wpath = fromUtf8(isFullPath(path) ? path : normalizePath(getCurrentDirectory().c_str(), path).c_str());

	// this makes sure we can use long paths and, more importantly, allows us to open files with special names such as 'aux.c'
	wpath.insert(0, L"\\\\?\\");
	std::replace(wpath.begin(), wpath.end(), '/', '\\');

	// convert file mode, assume short ASCII literal string
	wchar_t wmode[8] = {};
	assert(strlen(mode) < ARRAYSIZE(wmode));
	std::copy(mode, mode + strlen(mode), wmode);

	return _wfopen(wpath.c_str(), wmode);
}