Example #1
0
int Path::pathType() const
{
	if(isRelativePath())
		return Path::Relative;
	else
		return Path::Absolute;
}
Example #2
0
/* TODO !!! proper error handling */
gchar *URI::toNativeFilename() const throw(BadURIException) {
    gchar *uriString = toString();
    if (isRelativePath()) {
        return uriString;
    } else {
        gchar *filename = g_filename_from_uri(uriString, NULL, NULL);
        g_free(uriString);
        if (filename) {
            return filename;
        } else {
            throw MalformedURIException();
        }
    }
}
Example #3
0
OMRawStorage* 
OMXMLStorage::openExistingDataStream(const wchar_t* uri)
{
    TRACE("OMXMLStorage::openExistingDataStream");

    wchar_t* filepath = new wchar_t[wcslen(uri) + 1];
    wcsconvertURItoFilepath(uri, filepath);
    
    wchar_t* fullFileName;
    if (isRelativePath(filepath) && _storage->fileName() != 0)
    {
        wchar_t* base = getBaseFilePath(_storage->fileName());
        fullFileName = new wchar_t[wcslen(base) + wcslen(filepath) + 1];
        wcscpy(fullFileName, base);
        wcscat(fullFileName, filepath);
        delete [] base;
    }
    else
    {
        fullFileName = new wchar_t[wcslen(filepath) + 1];
        wcscpy(fullFileName, filepath);
    }
    
    OMDiskRawStorage* storage = 0;
    if (fileExists(fullFileName))
    {
        try
        {
            if (_mode == READ_MODE)
            {
                storage = OMDiskRawStorage::openExistingRead(fullFileName);
            }
            else
            {
                storage = OMDiskRawStorage::openExistingModify(fullFileName);
            }
        }
        catch (...)
        {
            storage = 0;
        }
    }

    delete [] filepath;
    delete [] fullFileName;
    
    return storage;
}
Example #4
0
bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& state)
{
	if(state.lineInfo.size() == 0)
		return true;

	unsigned int saddr = state.lineInfo[0].offset;
	unsigned int eaddr = state.lineInfo.back().offset;
    int segIndex = state.section;
    if (segIndex < 0)
	    segIndex = img.findSection(saddr + state.seg_offset);
	if(segIndex < 0)
	{
		// throw away invalid lines (mostly due to "set address to 0")
		state.lineInfo.resize(0);
		return true;
		//return false;
	}

//    if(saddr >= 0x4000)
//        return true;

	const DWARF_FileName* dfn;
	if(state.file == 0)
		dfn = state.file_ptr;
	else if(state.file > 0 && state.file <= state.files.size())
		dfn = &state.files[state.file - 1];
	else
		return false;
	std::string fname = dfn->file_name;
	
	if(isRelativePath(fname) && 
	   dfn->dir_index > 0 && dfn->dir_index <= state.include_dirs.size())
	{
		std::string dir = state.include_dirs[dfn->dir_index - 1];
		if(dir.length() > 0 && dir[dir.length() - 1] != '/' && dir[dir.length() - 1] != '\\')
			dir.append("\\");
		fname = dir + fname;
	}
	for(size_t i = 0; i < fname.length(); i++)
		if(fname[i] == '/')
			fname[i] = '\\';

    if (!mod)
    {
        printLines(fname.c_str(), segIndex, img.findSectionSymbolName(segIndex),
                   state.lineInfo.data(), state.lineInfo.size());
		state.lineInfo.resize(0);
		return true;
    }
#if 1
	bool dump = false; // (fname == "cvtest.d");
	//qsort(&state.lineInfo[0], state.lineInfo.size(), sizeof(state.lineInfo[0]), cmpAdr);
#if 0
	printf("%s:\n", fname.c_str());
	for(size_t ln = 0; ln < state.lineInfo.size(); ln++)
		printf("  %08x: %4d\n", state.lineInfo[ln].offset + 0x401000, state.lineInfo[ln].line);
#endif

    int rc = 1;
	unsigned int firstLine = state.lineInfo[0].line;
	unsigned int firstAddr = state.lineInfo[0].offset;
	unsigned int firstEntry = 0;
	unsigned int entry = 0;
	for(size_t ln = firstEntry; ln < state.lineInfo.size(); ln++)
	{
		if(state.lineInfo[ln].line < firstLine || state.lineInfo[ln].offset < firstAddr)
		{
			if(ln > firstEntry)
			{
				unsigned int length = state.lineInfo[entry-1].offset + 1; // firstAddr has been subtracted before
				if(dump)
					printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str());
				rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine,
									(unsigned char*) &state.lineInfo[firstEntry], 
									(ln - firstEntry) * sizeof(state.lineInfo[0]));
				firstLine = state.lineInfo[ln].line;
				firstAddr = state.lineInfo[ln].offset;
				firstEntry = entry;
			}
		}
		else if(ln > firstEntry && state.lineInfo[ln].offset == state.lineInfo[ln-1].offset)
			continue; // skip entries without offset change
		state.lineInfo[entry].line = state.lineInfo[ln].line - firstLine;
		state.lineInfo[entry].offset = state.lineInfo[ln].offset - firstAddr;
		entry++;
	}
	unsigned int length = eaddr - firstAddr;
	if(dump)
		printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str());
	rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine,
					    (unsigned char*) &state.lineInfo[firstEntry], 
					    (entry - firstEntry) * sizeof(state.lineInfo[0]));

#else
	unsigned int firstLine = 0;
	unsigned int firstAddr = 0;
	int rc = mod->AddLines(fname.c_str(), segIndex + 1, saddr, eaddr - saddr, firstAddr, firstLine,
						   (unsigned char*) &state.lineInfo[0], state.lineInfo.size() * sizeof(state.lineInfo[0]));
#endif

	state.lineInfo.resize(0);
	return rc > 0;
}
QString QFSFileEngine::fileName(FileName file) const
{
    Q_D(const QFSFileEngine);
    if (file == BaseName) {
        return d->fileEntry.fileName();
    } else if (file == PathName) {
        return d->fileEntry.path();
    } else if (file == AbsoluteName || file == AbsolutePathName) {
        QString ret;

        if (!isRelativePath()) {
#if !defined(Q_OS_WINCE)
            if (d->fileEntry.filePath().startsWith(QLatin1Char('/')) || // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt
                d->fileEntry.filePath().size() == 2 ||                  // It's a drive letter that needs to get a working dir appended
                (d->fileEntry.filePath().size() > 2 && d->fileEntry.filePath().at(2) != QLatin1Char('/')) || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt
                d->fileEntry.filePath().contains(QLatin1String("/../")) || d->fileEntry.filePath().contains(QLatin1String("/./")) ||
                d->fileEntry.filePath().endsWith(QLatin1String("/..")) || d->fileEntry.filePath().endsWith(QLatin1String("/.")))
            {
                ret = QDir::fromNativeSeparators(QFileSystemEngine::nativeAbsoluteFilePath(d->fileEntry.filePath()));
            } else
#endif
            {
                ret = d->fileEntry.filePath();
            }
        } else {
            ret = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + d->fileEntry.filePath());
        }

        // The path should be absolute at this point.
        // From the docs :
        // Absolute paths begin with the directory separator "/"
        // (optionally preceded by a drive specification under Windows).
        if (ret.at(0) != QLatin1Char('/')) {
            Q_ASSERT(ret.length() >= 2);
            Q_ASSERT(ret.at(0).isLetter());
            Q_ASSERT(ret.at(1) == QLatin1Char(':'));

            // Force uppercase drive letters.
            ret[0] = ret.at(0).toUpper();
        }

        if (file == AbsolutePathName) {
            int slash = ret.lastIndexOf(QLatin1Char('/'));
            if (slash < 0)
                return ret;
            else if (ret.at(0) != QLatin1Char('/') && slash == 2)
                return ret.left(3);      // include the slash
            else
                return ret.left(slash > 0 ? slash : 1);
        }
        return ret;
    } else if (file == CanonicalName || file == CanonicalPathName) {
        if (!(fileFlags(ExistsFlag) & ExistsFlag))
            return QString();
        QFileSystemEntry entry(QFileSystemEngine::canonicalName(QFileSystemEntry(fileName(AbsoluteName)), d->metaData));

        if (file == CanonicalPathName)
            return entry.path();
        return entry.filePath();
    } else if (file == LinkName) {
        return QFileSystemEngine::getLinkTarget(d->fileEntry, d->metaData).filePath();
    } else if (file == BundleName) {
        return QString();
    }
    return d->fileEntry.filePath();
}
Example #6
0
APIRET CDECL
kalOpenL (PSZ pszFileName,
          HFILE *phFile,
	  ULONG *pulAction,
	  LONGLONG cbFile,
	  ULONG ulAttribute,
	  ULONG fsOpenFlags,
	  ULONG fsOpenMode,
	  PEAOP2 peaop2)
{
  CORBA_Environment env = dice_default_environment;
  EAOP2 eaop2;
  APIRET  rc;

  STKIN
  LOG("pszFileName=%s", pszFileName);
  LOG("ulAction=%x", *pulAction);
  LOG("cbFile=%u", cbFile);
  LOG("ulAttribute=%x", ulAttribute);
  LOG("fsOpenFlags=%x", fsOpenFlags);
  LOG("fsOpenMode=%x", fsOpenMode);
  if (peaop2 == NULL)
    peaop2 = &eaop2;
  
    /* Support for current/working directory for filenames. 
    No support yet for devicenames, COM1 etc. That needs to be done 
    inside os2server and the added current directory in this function needs to
    be separated from the filename in pszFileName
    ( add one more argument to os2fs_dos_OpenL_call for current dir). */
  unsigned char drive = '\0';
  char *path = "";

  int BUFLEN = 99;
  char *filbuf = calloc(1,BUFLEN + 1);

  ULONG dsknum=0, plog=0, dirbuf_len=100, dirbuf_len2=100, dirbuf_len_out=100;
  PBYTE dir_buf=calloc(1,dirbuf_len), 
         dir_buf2=calloc(1,dirbuf_len2), dir_buf_out=calloc(1,dirbuf_len_out);
  BYTE /*drive=0,*/ drive2=0;

  LOG("KalQueryCurrentDisk");
  KalQueryCurrentDisk(&dsknum, &plog); /*For c:\os2 it becomes 3 (drive letter)*/
                     /*  3     "os2" */
  KalQueryCurrentDir(dsknum, (PBYTE)dir_buf, &dirbuf_len);


  /*char *pszFileName = fil12; */


  LOG("2 pszFileName %s", pszFileName);
  drive = parse_drv(pszFileName);  if(drive==0)  drive2 = disknum_to_char(dsknum);
  path = parse_path(pszFileName, filbuf, BUFLEN);

  LOG("2 drive '%c', drive2 '%c' ", drive, drive2);

  BYTE drv = 0;
  if(drive==0) {  /* Is actual device specified? */
      drv = char_to_disknum(drive2);
  }else {
      drv = char_to_disknum(drive);
  }

  /* Working directory is put into dir_buf2. */
  KalQueryCurrentDir(drv, (PBYTE)dir_buf2, &dirbuf_len2);
  char s[10] = "";  /*Create device letter with colon. */
  s[0] = disknum_to_char(drv);
  s[1] = 0;
  strncat((char*)dir_buf_out, s, 1);       

  /*  .\config.sys               ':' */
  if(isRelativePath(path) ) {/* Add working directory. */

      strncat((char*)dir_buf_out, ":\\", 2);
      strncat((char*)dir_buf_out, (char*)dir_buf2, dirbuf_len2);
      if((strcmp((char*)dir_buf2,"")!=0) && isRelativePath((char*)dir_buf2))
          strncat((char*)dir_buf_out, "\\", 1);
      strncat((char*)dir_buf_out, path, strlen(path));
      /* Complete path for filename is now inside dir_buf_out.*/
      LOG("22dir_buf_out '%s'", dir_buf_out);
  }

  LOG("3");
  /*  \config.sys               'c:' */
  if((!isRelativePath(path)) ) {/* Add working directory from specified disk*/

      strncat((char*)dir_buf_out, ":", 2);
      LOG("dir_buf2 '%s', dir_buf '%s', path '%s'", dir_buf2, dir_buf, path);
      /* Is string in working directory? dir_buf2*/
      /*Is working directory going to be added?*/
      if( (isRelativePath((char*)path))) { 
          if((strcmp((char*)dir_buf2,"")!=0) && isRelativePath((char*)dir_buf2)) {
              strncat((char*)dir_buf_out, "\\", 1);
              strncat((char*)dir_buf_out, 
                          (char*)dir_buf2, dirbuf_len2);/*No working directory!*/
              if(isRelativePath((char*)path))
                  strncat((char*)dir_buf_out, "\\", 1);
          }
      }
      strncat((char*)dir_buf_out, path, strlen(path));
      /* Complete path for filename is now inside dir_buf_out.*/
      LOG("33dir_buf_out(pszFileName) '%s'", dir_buf_out);
  }
    
  /********************************************/
                                /* pszFileName */
  rc = os2fs_dos_OpenL_call (&fs, dir_buf_out, phFile,
                      pulAction, cbFile, ulAttribute,
                      fsOpenFlags, fsOpenMode, peaop2, &env);
  LOG("hFile=%x", *phFile);
  LOG("rc=%x", rc);
  LOG("exit");
  STKOUT
  return rc;
}