예제 #1
0
void
gtBaseOpts::processOption_ResourceDir ()
{
#ifdef __CYGWIN__
    m_resourceDir = getWinInstallDirectory ();
#endif /* __CYGWIN__ */

    if (m_vm.count (OPT_RESOURCE_DIR) == 1)
    {
        m_resourceDir = sanitizePath (m_vm[OPT_RESOURCE_DIR].as<std::string>());
    }
    else   // command line (or config file) option not present
    {
        char *envValue = getenv ("GT_RESOURCE_DIR");

        if (envValue != NULL)
        {
            m_resourceDir = sanitizePath (envValue) + "/";
        }
        else   // No environment variable for the resource path
        {
            return;
        }
    }

    if (statDirectory (m_resourceDir) != 0)
    {
        commandLineError ("unable to open resource directory '" + m_resourceDir + "'");
    }
}
예제 #2
0
static void expandProjectItem(const std::string& srcDir, const std::string& destDir, const StringMap& params, ProjectItem* item)
{
  // Expand paths to be absolute and pretty
  if (item) {
    expandString(item->outFile, params);
    item->outFile = joinPaths(destDir, item->outFile);
    item->outFile = platformPath(sanitizePath(item->outFile));
    item->inFile = joinPaths(srcDir, item->inFile);
    item->inFile = platformPath(sanitizePath(item->inFile));
  }
}
// FIXME: Fails on Windows if one of the paths does not specify a drive letter
// E.g. c:\foo\bar and \foo\myfile.txt
String getRelativePath(const String& fromAbsPath, const String& toAbsPath)
{
  // Tokenize the paths
  StringVec fromTokens, toTokens;
  tokenize(posixPath(fromAbsPath), fromTokens, "/", "", "", "", "\\", false, false);
  tokenize(posixPath(toAbsPath), toTokens, "/", "", "", "", "\\", false, false);

  // Find the longest common prefix
  unsigned i = 0;
  StringVec::iterator fromIt = fromTokens.begin();
  StringVec::iterator toIt = toTokens.begin();
  for (; fromIt != fromTokens.end() && toIt != toTokens.end(); fromIt++, toIt++, i++) {
    if (!comparePaths(*fromIt, *toIt))
      break;
  }

  if (i > 0) {
    // Assemble the relative path
    StringVec relPathTokens(fromTokens.size() - i, "..");
    relPathTokens.insert(relPathTokens.end(), toIt, toTokens.end());
    return joinStrings(relPathTokens, "/");
  } else {
    // Paths have nothing in common, so no relative path exists (Windows-only)
    return sanitizePath(toAbsPath);
  }
}
예제 #4
0
파일: Parser.cpp 프로젝트: ptjohns2/MIPSEM
string Parser::sanitizeFilePath(string path){
	path = sanitizePath(path);
	if(path[path.length()-1] == '/'){
		path = path.substr(0, path.length()-1);
	}
	return path;
}
예제 #5
0
파일: Parser.cpp 프로젝트: ptjohns2/MIPSEM
string Parser::sanitizeDirectoryPath(string path){
	path = sanitizePath(path);
	if(path[path.length()-1] != '/'){
		path += "/";
	}
	return path;
}
예제 #6
0
// Used by download and upload
std::string
gtBaseOpts::processOption_Path ()
{
    if (m_vm.count (OPT_PATH) < 1)
    {
        return "";    
    }

    std::string path = sanitizePath (m_vm[OPT_PATH].as<std::string>());

    if (path.size() == 0)
    {
        commandLineError ("command line or config file contains no value for '"
                          OPT_PATH "'");
    }

    relativizePath (path);

    if (statDirectory (path) != 0)
    {
        commandLineError ("unable to opening directory '" + path + "'");
    }

    return path;
}
예제 #7
0
PackReader::PackReader(const Filesystem::AbsolutePath & filename):
filename(filename){
    ifstream stream;
    Global::debug(0) << "Reading pak file " << filename.path() << endl;
    stream.open(filename.path().c_str(), std::ios::in | std::ios::binary);
    Storage::LittleEndianReader reader(stream);
    uint32_t magic = reader.readByte4();
    if (magic != MAGIC){
        ostringstream error;
        error << filename.path() << " is not a packfile! " << std::hex << magic;
        throw PackError(__FILE__, __LINE__, error.str());
    } else {
        // cout << "Ok got a packfile" << endl;
    }
    uint32_t version = reader.readByte4();
    /* just assume we can read all versions for now */

    // cout << "Version is " << version << endl;
    reader.seekEnd(-4);
    uint32_t headerPosition = reader.readByte4();
    reader.seek(headerPosition);

    // cout << "Header at 0x" << std::hex << headerPosition << std::dec << endl;

    bool done = false;
    try{
        while (!done){
            uint32_t current = reader.position();
            uint32_t length = reader.readByte4();
            uint32_t start = reader.readByte4();
            uint32_t size = reader.readByte4();
            /* will read upto 80 bytes, but potentially fewer if a null byte
             * is reached.
             */
            string name = reader.readStringX(80);
            if (name.size() != 0){
                files[sanitizePath(name)] = File(start, size);
            }
            done = name.size() == 0;
            // cout << name << " at " << start << " size " << size << " length " << length << endl;
            // cout << " seek to " << (current + length) << endl;
            // reader.seek(current + length);
            done |= stream.eof();
        }
    } catch (const Storage::Eof & eof){
    }
    stream.close();

    handle.open(filename.path().c_str(), std::ios::in | std::ios::binary);
    Util::Thread::initializeLock(&readLock);
}
String joinPaths(const String& lhs, const String& rhs, bool sanitize)
{
  String joinedPath;
  if (rhs.empty()) {
    joinedPath = lhs;
  } else if (lhs.empty() || isAbsolutePath(rhs)) {
    joinedPath = rhs;
  } else {
    joinedPath = lhs + "/" + rhs;
  }

  if (sanitize) {
    return sanitizePath(joinedPath);
  } else {
    return joinedPath;
  }
}
예제 #9
0
/*!
 * Given a module name and path adjust the name and path so that all the path
 * information is in the path, the base name is in the name
 * \param name contains the name with may include some path information. The
 *        path and extension will be removed
 * \param filepath contains the path information, which will be augmented
 *        with any path information from the name, unless the name contains
 *        absolute path information, in which case the filepath will be
 *        replaced with the name path
 */
void ProtocolFile::separateModuleNameAndPath(QString& name, QString& filepath)
{
    // Handle the case where the file includes "./" to reference the current working
    // directory. We just remove this as its not needed.
    if(name.startsWith("./"))
        name.remove("./");
    else if(name.startsWith(".\\"))
        name.remove(".\\");

    // Does the name include some path information?
    int index = name.lastIndexOf("/");
    if(index < 0)
        index = name.lastIndexOf("\\");

    if(index >= 0)
    {
        // The path information in the name (including the path separator)
        QString namepath = name.left(index+1);

        // In case the user gave path information in the name which
        // references a global location, ignore the filepath (i.e. user
        // can override the working directory)
        if(namepath.contains(":") || namepath.startsWith('\\') || namepath.startsWith('/'))
            filepath = namepath;
        else
        {
            if(filepath.isEmpty())
                filepath += ".";

            filepath += "/" + namepath;
        }

        // The name without the path data
        name = name.right(name.size() - index - 1);

    }// If name contains a path separator

    // Make sure the path uses native separators and ends with a separator (unless its empty)
    filepath = sanitizePath(filepath);

}// ProtocolFile::separateModuleNameAndPath
예제 #10
0
void
generalInit(ECString path)
{
  struct rlimit 	core_limits;
  core_limits.rlim_cur = 0;
  core_limits.rlim_max = 0;
  setrlimit( RLIMIT_CORE, &core_limits );

  struct rlimit stack_limits;
  stack_limits.rlim_cur = 0;
  stack_limits.rlim_max = 0;
  getrlimit( RLIMIT_STACK, &stack_limits );
  if (stack_limits.rlim_cur < stack_limits.rlim_max)
    {
      stack_limits.rlim_cur = stack_limits.rlim_max;
      setrlimit( RLIMIT_STACK, &stack_limits );
    }

  // load locale settings from the environment
  setlocale(LC_ALL, "");

  path = sanitizePath(path);

  Term::init( path );
  readHeadInfo(path);
  InputTree::init();
  UnitRules* ur = new UnitRules;
  ur->readData(path); 
  Bchart::unitRules = ur;
  Bchart::readTermProbs(path);
  MeChart::init(path);
  Bchart::setPosStarts();
  ChartBase::midFactor = (1.0 - (.3684 *ChartBase::endFactor))/(1.0 - .3684);
  if(Feature::isLM or Feature::useExtraConditioning) 
    ClassRule::readCRules(path);
}
예제 #11
0
파일: Utils.cpp 프로젝트: VisBlank/ipfixcol
void loadDirsTree(std::string basedir, std::string first, std::string last, stringVector &tables)
{
	struct dirent **namelist;
	int dirs_counter;

	sanitizePath(basedir);
	
	/* Find root directories */
	std::string root_first = rootDir(first);
	std::string root_last = rootDir(last);

	/* scan for subdirs */
	dirs_counter = scandir(basedir.c_str(), &namelist, NULL, versionsort);
	if (dirs_counter < 0) {
#ifdef DEBUG
		std::cerr << "Cannot stat directory " << basedir << ": " << strerror(errno) << std::endl;
#endif
		return;
	}

	/* Add all directories into vector */
	for (int i = 0; i < dirs_counter; ++i) {
		std::string entry_name = namelist[i]->d_name;

		/* Ignore . and .. */
		if (entry_name == "." || entry_name == "..") {
			continue;
		}

		/* If first dir was given, ignore entries before it */
		if (!root_first.empty() && strverscmp(entry_name.c_str(), root_first.c_str()) < 0) {
			continue;
		} else if (strverscmp(entry_name.c_str(), root_first.c_str()) == 0) {
			if (root_first == first.substr(0, first.length() - 1)) {
				/* Found first folder */
				std::string tableDir = basedir + entry_name;
				sanitizePath(tableDir);
				tables.push_back(tableDir);
			} else {
				/* Go deeper and find first folder */
				std::string new_basedir = basedir + entry_name;
				std::string new_first = first.substr(root_first.length() + 1);
				loadDirsTree(new_basedir, new_first, "", tables);
			}
		} else if (root_last.empty() || strverscmp(entry_name.c_str(), root_last.c_str()) < 0) {
			/* Entry is between first and last */
			std::string tableDir = basedir + entry_name;
			sanitizePath(tableDir);
			tables.push_back(tableDir);
		} else if (strverscmp(entry_name.c_str(), root_last.c_str()) == 0){
			/* Entry == root_last */
			if (root_last == last.substr(0, last.length() - 1)) {
				/* We're on last level, add last directory to vector */
				std::string tableDir = basedir + entry_name;
				sanitizePath(tableDir);
				tables.push_back(tableDir);
			} else {
				/* Goo deeper */
				std::string new_basedir = basedir + entry_name;
				std::string new_last = last.substr(root_last.length() + 1);
				loadDirsTree(new_basedir, "", new_last, tables);
			}
		}
	}

}
예제 #12
0
VSSolution::VSSolution(const std::string& absPath, unsigned version)
    : m_absFilePath(platformPath(sanitizePath(absPath))), m_version(version) {
    sbAssertWithTelemetry(isAbsolutePath(absPath), "Path to VS solution is not absolute");
}