Пример #1
0
int main(int argc, char** argv) {

  const char hc_path[] = "tmp/terrain";
  const char *map_path;
  if ((argc<2) || !strlen(argv[1])) {
    map_path = hc_path;
  } else {
    map_path = argv[1];
  }

  TCHAR jp2_path[4096];
  _tcscpy(jp2_path, PathName(map_path));
  _tcscat(jp2_path, _T(DIR_SEPARATOR_S) _T("terrain.jp2"));

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(map_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  RasterMap map(jp2_path, j2w_path, NULL);
  do {
    map.SetViewCenter(map.GetMapCenter(), fixed(100000));
  } while (map.IsDirty());

  plan_tests(1);
  test_reach(map, fixed_zero, fixed(0.1));

  return exit_status();
}
Пример #2
0
int main(int argc, char** argv) {

  const char hc_path[] = "tmp/terrain";
  const char *map_path;
  if ((argc<2) || !strlen(argv[0])) {
    map_path = hc_path;
  } else {
    map_path = argv[0];
  }

  TCHAR jp2_path[4096];
  _tcscpy(jp2_path, PathName(map_path));
  _tcscat(jp2_path, _T(DIR_SEPARATOR_S) _T("terrain.jp2"));

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(map_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  NullOperationEnvironment operation;
  RasterMap map(jp2_path, j2w_path, NULL, operation);
  do {
    map.SetViewCenter(map.GetMapCenter(), fixed(100000));
  } while (map.IsDirty());

  plan_tests(16*3);
  test_troute(map, fixed(0), fixed(0.1), RoughAltitude(10000));
  test_troute(map, fixed(0), fixed(0), RoughAltitude(10000));
  test_troute(map, fixed(5.0), fixed(1), RoughAltitude(10000));

  return exit_status();
}
Пример #3
0
int
main(int argc, char** argv)
{
  // default arguments
  autopilot_parms.ideal();

  if (!parse_args(argc, argv)) {
    return 0;
  }

  const char hc_path[] = "tmp/terrain";

  TCHAR jp2_path[4096];
  _tcscpy(jp2_path, PathName(hc_path));
  _tcscat(jp2_path, _T(DIR_SEPARATOR_S) _T("terrain.jp2"));

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(hc_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  NullOperationEnvironment operation;
  RasterMap map(jp2_path, j2w_path, NULL, operation);
  do {
    map.SetViewCenter(map.GetMapCenter(), fixed(100000));
  } while (map.IsDirty());

  plan_tests(4 + NUM_SOL);
  ok(test_route(28, map), "route 28", 0);
  return exit_status();
}
Пример #4
0
  PathName PathName::DirectoryName(void) const {
    std::string path = this->GetNativePathName();
    std::string::size_type i;
#if defined(WIN32) // windows
    i = path.rfind('\\');
    if (i == 1 && path[0] == '\\')
      i = std::string::npos;
#else /// POSIX UNIX
    i = path.rfind('/');
#endif
    if (i == 0 || i == std::string::npos)
      return PathName(".");
    return PathName(path.substr(0, i));
  }
Пример #5
0
void
Directory::Delete (/*[in]*/ const PathName &	path,
                            /*[in]*/ bool		recursive)
{
    if (recursive)
    {
        PathNameArray vecFiles;
        vecFiles.reserve (10);

        PathNameArray vecDirectories;
        vecDirectories.reserve (10);

        auto_ptr<DirectoryLister> pLister (DirectoryLister::Open(path));
        DirectoryEntry entry;
        while (pLister->GetNext(entry))
        {
            if (entry.isDirectory)
            {
                vecDirectories.push_back (PathName(path.Get(),
                                                   entry.name.c_str(),
                                                   0));
            }
            else
            {
                vecFiles.push_back (PathName(path.Get(), entry.name.c_str(), 0));
            }
        }
        pLister->Close ();

        PathNameArray::const_iterator it;

        // remove files
        for (it = vecFiles.begin(); it != vecFiles.end(); ++ it)
        {
            File::Delete (*it, true);
        }

        // remove directories recursively
        for (it = vecDirectories.begin(); it != vecDirectories.end(); ++ it)
        {
            // <recursivecall>
            Delete (*it, true);
            // </recursivecall>
        }
    }

    // remove this directory
    Directory::Delete (path);
}
Пример #6
0
PathName PathName::join(cstring component) const {
    if (component.isNullOrEmpty())
        throw std::logic_error("Empty string for pathname component");
    if (str.isNullOrEmpty())
        return PathName(component);
    char last = str[str.size() - 1];
    for (char c : pathSeparators) {
        if (c == last) {
            auto result = str + component;
            return PathName(result);
        }
    }
    auto result = str + separator() + component;
    return PathName(result);
}
Пример #7
0
void
SessionImpl::SetRecorderPath (/*[in]*/ const PathName & path)
{
    if (! (recordingFileNames || recordingPackageNames))
    {
        return;
    }
    if (fileNameRecorderStream.IsOpen())
    {
        return;
    }
    fileNameRecorderStream.Attach(File::Open(path, FileMode::Create, FileAccess::Write));
    PathName cwd;
    cwd.SetToCurrentDirectory ();
    fileNameRecorderStream.WriteFormattedLine ("PWD %s", cwd.ToUnix().Get());
    vector<FileInfoRecord> fileInfoRecords = GetFileInfoRecords();
    for (vector<FileInfoRecord>::const_iterator it = fileInfoRecords.begin();
            it != fileInfoRecords.end();
            ++ it)
    {
        fileNameRecorderStream.WriteFormattedLine ("%s %s",
                (it->access == FileAccess::Read
                 ? "INPUT"
                 : "OUTPUT"),
                PathName(it->fileName).ToUnix().Get());
    }
    fileNameRecorderStream.Flush();

}
Пример #8
0
void BasicPathName<TChar>::internalCanonicalizePath(BasicPathName<TChar>* outPath) const
{
	wchar_t tmpPath[LN_MAX_PATH];
	wchar_t* canonPath;
#ifdef _WIN32
	canonPath = _wfullpath(tmpPath, mPath.c_str(), LN_MAX_PATH);
#else
	canonPath = realpath(mPath.c_str(), pathbuf);
#endif
	if (canonPath == NULL) {
		*outPath = PathName();
	}
	else {
		*outPath = PathName(tmpPath);
	}
}
Пример #9
0
int main(int argc, char **argv)
{
  Args args(argc, argv, "PATH");
  const char *map_path = args.ExpectNext();
  args.ExpectEnd();

  char jp2_path[4096];
  strcpy(jp2_path, map_path);
  strcat(jp2_path, DIR_SEPARATOR_S "terrain.jp2");

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(map_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  NullOperationEnvironment operation;
  RasterTileCache rtc;
  if (!rtc.LoadOverview(jp2_path, j2w_path, operation)) {
    fprintf(stderr, "LoadOverview failed\n");
    return EXIT_FAILURE;
  }

  GeoBounds bounds = rtc.GetBounds();
  printf("bounds = %f|%f - %f|%f\n",
         (double)bounds.GetWest().Degrees(),
         (double)bounds.GetNorth().Degrees(),
         (double)bounds.GetEast().Degrees(),
         (double)bounds.GetSouth().Degrees());

  do {
    rtc.UpdateTiles(jp2_path, rtc.GetWidth() / 2, rtc.GetHeight() / 2,
                    1000);
  } while (rtc.IsDirty());

  return EXIT_SUCCESS;
}
Пример #10
0
bool wxGxOpenFileGDB::Rename(const wxString &sNewName)
{
    wxGISDataset* pDSet = GetDatasetFast();

    if (NULL != pDSet)
    {
        pDSet->Close();
        wsDELETE(pDSet);
    }

    wxFileName PathName(wxString(m_sPath, wxConvUTF8));
    PathName.SetName(ClearExt(sNewName));

    wxString sNewPath = PathName.GetFullPath();

    CPLString szNewPath(sNewPath.mb_str(wxConvUTF8));
    if (RenameFile(m_sPath, szNewPath))
    {
        if (m_bIsChildrenLoaded)
            Refresh();
        return true;
    }
    else
    {
        const char* err = CPLGetLastErrorMsg();
        wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str());
        return false;
    }
    return false;
}
Пример #11
0
bool wxGxArchive::Rename(const wxString &sNewName)
{
    CPLString szType("/");
    int nCount = 0;
    for(size_t i = 1; i < m_sPath.length(); ++i)
    {
        nCount++;
        szType += m_sPath[i];
        if(m_sPath[i] == '/')
            break;
    }

    m_sPath.erase(0, nCount + 1);

	wxFileName PathName(wxString(m_sPath, wxConvUTF8));
	PathName.SetName(ClearExt(sNewName));

	wxString sNewPath = PathName.GetFullPath();

    CPLString szNewPath(sNewPath.mb_str(wxConvUTF8));
    if(RenameFile(m_sPath, szNewPath))
	{
		return true;
	}
	else
    {
        const char* err = CPLGetLastErrorMsg();
		wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str());
		return false;
    }
	return false;
}
Пример #12
0
int main(int argc, char **argv)
try {
  if (argc < 3) {
    unsigned n = 100;
    if (argc > 1) {
      n = atoi(argv[1]);
    }
    TestTrace(Path(_T("test/data/09kc3ov3.igc")), n);
  } else {
    assert(argc >= 3);
    unsigned n = atoi(argv[2]);
    plan_tests(n);
    
    for (unsigned i=2; i<2+n; i++) {
      unsigned nt = pow(2,i);
      char buf[100];
      sprintf(buf," trace size %d", nt);
      ok(TestTrace(PathName(argv[1]), nt),buf, 0);
    }
  }
  return 0;
} catch (const std::runtime_error &e) {
  PrintException(e);
  return EXIT_FAILURE;
}
Пример #13
0
  PathName PathName::Tail(void) const {
    
    std::string path = this->GetNativePathName();
    std::string::size_type i;
    if (path.length() == 0)
      return PathName("");

#if defined(WIN32) // windows
    i = path.rfind('\\', path.length() - 1);
#else /// POSIX UNIX
    i = path.rfind('/', path.length() - 1);
#endif
    if (i == std::string::npos)
      return PathName(path);
    else
      return PathName(path.substr(i+1, path.length() - i - 1));
  }
Пример #14
0
PathName PathName::getFilename() const {
    if (str.isNullOrEmpty()) return *this;

    const char* lastSeparator = findLastSeparator();
    if (lastSeparator == 0)
        return *this;

    return PathName(lastSeparator+1);
}
Пример #15
0
PathName PathName::getFolder() const {
    if (str.isNullOrEmpty()) return *this;

    const char* lastSeparator = findLastSeparator();
    if (lastSeparator == 0)
        return PathName::empty;

    return PathName(str.before(lastSeparator));
}
Пример #16
0
const PathName TempDirectoryList::getConfigString() const
{
	const char* value = Config::getTempDirectories();
	if (!value)
	{
		// Temporary directory configuration has not been defined.
		// Let's make default configuration.
		return TempFile::getTempPath();
	}
	return PathName(value);
}
Пример #17
0
int main(int argc, char **argv)
{
  if (argc != 2) {
    fprintf(stderr, "Usage: %s PATH\n", argv[0]);
    return 1;
  }

  const char *map_path = argv[1];

  TCHAR jp2_path[4096];
  _tcscpy(jp2_path, PathName(map_path));
  _tcscat(jp2_path, _T(DIR_SEPARATOR_S) _T("terrain.jp2"));

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(map_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  NullOperationEnvironment operation;
  RasterMap map(jp2_path, j2w_path, NULL, operation);
  if (!map.isMapLoaded()) {
    fprintf(stderr, "failed to load map\n");
    return EXIT_FAILURE;
  }

  do {
    map.SetViewCenter(map.GetMapCenter(), fixed(50000));
  } while (map.IsDirty());

  fixed radius = fixed(50000);
  WindowProjection projection;
  projection.SetScreenSize(640, 480);
  projection.SetScaleFromRadius(radius);
  projection.SetGeoLocation(map.GetMapCenter());
  projection.SetScreenOrigin(320, 240);
  projection.UpdateScreenBounds();

  HeightMatrix matrix;
  matrix.Fill(map, projection, 1, false);

  return EXIT_SUCCESS;
}
BOOL
InverseSearchOptionsPage::OnApply ()
{
  try
    {
      PathName pathEditorsIni
	(SessionWrapper(true)->GetSpecialPath(SpecialPath::ConfigRoot),
	 MIKTEX_PATH_EDITORS_INI);
      if (mustWrite)
	{
	  SmartPointer<Cfg> pCfg (Cfg::Create());
	  for (int idx = firstCustomIdx;
	       idx < static_cast<int>(editors.size());
	       ++ idx)
	    {
	      pCfg->PutValue (editors[idx].name.c_str(),
			      T_("program"),
			      editors[idx].program.c_str());
	      pCfg->PutValue (editors[idx].name.c_str(),
			      T_("arguments"),
			      editors[idx].arguments.c_str());
	    }
	  Directory::Create (PathName(pathEditorsIni).RemoveFileSpec());
	  pCfg->Write (pathEditorsIni);
	  mustWrite = false;
	  pCfg.Release ();
	  if (! Fndb::FileExists(pathEditorsIni))
	    {
	      Fndb::Add (pathEditorsIni);
	    }
	}
      if (commandLineIdx >= 0)
	{
	  g_pYapConfig->inverseSearchCommandLine =
	    editors[commandLineIdx].GetCommandLine().c_str();
	}
      else
	{
	  g_pYapConfig->inverseSearchCommandLine = "";
	}
      return (CPropertyPage::OnApply());
    }
  catch (const MiKTeXException & e)
    {
      ErrorDialog::DoModal (this, e);
      return (FALSE);
    }
  catch (const exception & e)
    {
      ErrorDialog::DoModal (this, e);
      return (FALSE);
    }
}
Пример #19
0
std::string Base::BackgroundFileName(Stage stage) const
{
    INFO0;
//     auto name = BackgroundName();
    auto name = Name();
    switch (stage) {
    case Stage::trainer : name = TrainerName(name);
        break;
    case Stage::reader : name = ReaderName(name);
        break;
    }
    return PathName(BackgroundName(name));
}
Пример #20
0
DviDoc::DviFileStatus
DviDoc::GetDviFileStatus ()
{
  if (fileStatus == DVIFILE_LOADED)
    {
      if (! File::Exists(PathName(GetPathName())))
	{
	  fileStatus = DVIFILE_LOST;
	}
      else
	{
	  time_t timeMod = modificationTime;
	  modificationTime = File::GetLastWriteTime(PathName(GetPathName()));
	  if (timeMod != modificationTime)
	    {
	      YapLog (T_("%s has been modified"), Q_(TU_(GetPathName())));
	      modificationTime = timeMod;
	      fileStatus = DVIFILE_MODIFIED;
	    }
	}
    }
  return (fileStatus);
}
Пример #21
0
std::string Base::SignalFileName(Stage stage) const
{
    INFO0;
//     auto name = SignalName();
    auto name = Name();
    switch (stage) {
    case Stage::trainer : name = TrainerName(name);
        break;
    case Stage::reader : name = ReaderName(name);
        break;
        DEFAULT(boca::Name(stage), "");
    }
    return PathName(SignalName(name));
}
Пример #22
0
void
PostScript::ExecuteEncapsulatedPostScript (/*[in]*/ const char * lpszFileName)
{
  FileStream epsStream;

  unsigned start = 0;
  unsigned length = 0;

#if 0
  // TODO
  if (bmeps_can_handle(PathName(lpszFileName).GetBuffer()) != 0)
  {
    tracePS->WriteFormattedLine ("libdvi", T_("Converting %s to EPS..."), Q_(lpszFileName));
    epsStream.Attach (ConvertToEPS(lpszFileName));
  }
  else
#endif
  {
    epsStream.Attach (File::Open(lpszFileName, FileMode::Open, FileAccess::Read, false));
    struct
    {
      unsigned char magic[4];
      unsigned char start[4];
      unsigned char length[4];
    } epsfheader;
    if (epsStream.Read(&epsfheader, sizeof(epsfheader)) == sizeof(epsfheader)
      && epsfheader.magic[0] == 'E' + 0x80
      && epsfheader.magic[1] == 'P' + 0x80
      && epsfheader.magic[2] == 'S' + 0x80
      && epsfheader.magic[3] == 'F' + 0x80)
    {
      start = epsfheader.start[0];
      start += epsfheader.start[1] * 256;
      start += epsfheader.start[2] * 256 * 256;
      start += epsfheader.start[3] * 256 * 256 * 256;
      length = epsfheader.length[0];
      length += epsfheader.length[1] * 256;
      length += epsfheader.length[2] * 256 * 256;
      length += epsfheader.length[3] * 256 * 256 * 256;
      tracePS->WriteFormattedLine ("libdvi", T_("EPS has a binary header"));
      tracePS->WriteFormattedLine ("libdvi", T_("start: %u"), static_cast<unsigned>(start));
      tracePS->WriteFormattedLine ("libdvi", T_("length: %u"), static_cast<unsigned>(length));
    }
  }

  epsStream.Seek (start, SeekOrigin::Begin);

  CopyFile (epsStream, length);
}
Пример #23
0
void
SessionImpl::RecordFileInfo (/*[in]*/ const char *	lpszPath,
                                      /*[in]*/ FileAccess	access)
{
    if (! (recordingFileNames
            || recordingPackageNames
            || packageHistoryFile.length() > 0))
    {
        return;
    }
    fileInfoRecords.reserve (50);
    FileInfoRecord fir;
    fir.fileName = lpszPath;
    fir.access = access;
    if (recordingPackageNames || packageHistoryFile.length() > 0)
    {
        PathName pathRelPath;
        if (IsTEXMFFile(lpszPath, pathRelPath.GetBuffer(), 0))
        {
            FileNameDatabase * pFndb = GetFileNameDatabase(GetMpmRoot());
            if (pFndb != 0)
            {
                AutoFndbRelease autoRelease (pFndb);
                PathNameArray paths;
                vector<string> packageNames;
                if (pFndb->Search(pathRelPath.Get(),
                                  MPM_ROOT_PATH,
                                  true,
                                  paths,
                                  packageNames))
                {
                    fir.packageName = packageNames[0];
                }
            }
        }
    }
    fileInfoRecords.push_back (fir);
    if (fileNameRecorderStream.IsOpen())
    {
        fileNameRecorderStream.WriteFormattedLine ("%s %s",
                (fir.access == FileAccess::Read
                 ? "INPUT"
                 : "OUTPUT"),
                PathName(fir.fileName).ToUnix().Get());
        fileNameRecorderStream.Flush ();
    }
}
Пример #24
0
bool DirectoryList::isPathInList(const PathName& path) const
{
	if (fb_utils::bootBuild())
	{
		return true;
	}

	fb_assert(mode != NotInitialized);

	// Handle special cases
	switch (mode)
	{
	case None:
		return false;
	case Full:
		return true;
	}

	// Disable any up-dir(..) references - in case our path_utils
	// and OS handle paths in slightly different ways,
	// this is "wonderful" potential hole for hacks
	// Example of IIS attack attempt:
	// "GET /scripts/..%252f../winnt/system32/cmd.exe?/c+dir HTTP/1.0"
	//								(live from apache access.log :)
	if (path.find(PathUtils::up_dir_link) != PathName::npos)
		return false;

	PathName varpath(path);
	if (PathUtils::isRelative(path)) {
		PathUtils::concatPath(varpath, PathName(Config::getRootDirectory()), path);
	}

	ParsedPath pPath(varpath);
	bool rc = false;
	for (size_t i = 0; i < getCount(); i++)
	{
		if ((*this)[i].contains(pPath))
		{
			rc = true;
			break;
		}
	}
	return rc;
}
Пример #25
0
bool wxGxFile::Rename(const wxString &sNewName)
{
	wxFileName PathName(wxString(m_sPath, wxConvUTF8));
	PathName.SetName(ClearExt(sNewName));

	wxString sNewPath = PathName.GetFullPath();
    CPLString szNewPath(sNewPath.mb_str(wxConvUTF8));
    if(RenameFile(m_sPath, szNewPath))
	{
		return true;
	}
	else
    {
        const char* err = CPLGetLastErrorMsg();
		wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str());
		return false;
    }
	return false;
}
Пример #26
0
bool
FlarmDevice::GetConfig(const char *setting, TCHAR *buffer, size_t length)
{
  NarrowString<256> request;
  request.Format("PFLAC,R,%s", setting);

  NarrowString<256> expected_answer(request);
  expected_answer[6u] = 'A';
  expected_answer += ',';

  char narrow_buffer[length];

  Send(request);
  if (!Receive(expected_answer, narrow_buffer, length, 1000))
    return false;

  _tcscpy(buffer, PathName(narrow_buffer));
  return true;
}
Пример #27
0
int main(int argc, char **argv)
{
  if (argc != 2) {
    fprintf(stderr, "Usage: %s PATH\n", argv[0]);
    return 1;
  }

  const char *map_path = argv[1];

  char jp2_path[4096];
  strcpy(jp2_path, map_path);
  strcat(jp2_path, DIR_SEPARATOR_S "terrain.jp2");

  TCHAR j2w_path[4096];
  _tcscpy(j2w_path, PathName(map_path));
  _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));

  NullOperationEnvironment operation;
  RasterTileCache rtc;
  if (!rtc.LoadOverview(jp2_path, j2w_path, operation)) {
    fprintf(stderr, "LoadOverview failed\n");
    return EXIT_FAILURE;
  }

  GeoBounds bounds = rtc.GetBounds();
  printf("bounds = %f|%f - %f|%f\n",
         (double)bounds.west.value_degrees(),
         (double)bounds.north.value_degrees(),
         (double)bounds.east.value_degrees(),
         (double)bounds.south.value_degrees());

  do {
    rtc.UpdateTiles(jp2_path, rtc.GetWidth() / 2, rtc.GetHeight() / 2,
                    fixed(50000));
  } while (rtc.IsDirty());

  return EXIT_SUCCESS;
}
Пример #28
0
  PathList PathName::SearchDirectory(void) const {
    PathList opl;
    if (!this->IsDirectory())
      return opl;
  
#if defined(WIN32)
#error This needs to be implemented
#else
    DIR *dir;
    struct dirent *dirp;
    if ((dir = opendir(this->GetNativePathName().c_str())) != NULL) {
      
      while ((dirp = readdir(dir)) != NULL) {
	opl.push_back(PathName(dirp->d_name));
      }

      closedir(dir);
    }

#endif
    return opl;
    
  }
Пример #29
0
std::string Base::WeightFileName() const
{
    INFO0;
    return PathName(WeightName(), ".xml");
}
Пример #30
0
std::string Base::ExportFileName() const
{
    INFO0;
    return PathName(ExportName());
}