예제 #1
0
static bool getYesterdayTodayAndTomorrow(JNIEnv* env, jobject localeData, const char* locale_name) {
  UErrorCode status = U_ZERO_ERROR;
  ScopedResourceBundle root(ures_open(NULL, locale_name, &status));
  if (U_FAILURE(status)) {
    return false;
  }
  ScopedResourceBundle fields(ures_getByKey(root.get(), "fields", NULL, &status));
  if (U_FAILURE(status)) {
    return false;
  }
  ScopedResourceBundle day(ures_getByKey(fields.get(), "day", NULL, &status));
  if (U_FAILURE(status)) {
    return false;
  }
  ScopedResourceBundle relative(ures_getByKey(day.get(), "relative", NULL, &status));
  if (U_FAILURE(status)) {
    return false;
  }
  // bn_BD only has a "-2" entry.
  if (relative.hasKey("-1") && relative.hasKey("0") && relative.hasKey("1")) {
    setStringField(env, localeData, "yesterday", relative.get(), "-1");
    setStringField(env, localeData, "today", relative.get(), "0");
    setStringField(env, localeData, "tomorrow", relative.get(), "1");
    return true;
  }
  return false;
}
예제 #2
0
파일: uri.hpp 프로젝트: mbits-os/libbase
	std::string scheme() const
	{
		if (relative())
			return std::string();

		return m_uri.substr(m_schema);
	}
//! updates the absolute position based on the relative and the parents position
void CAnimatedMeshSceneNode::updateAbsolutePosition()
{
    if ( 0 == Mesh || Mesh->getMeshType() != EAMT_MD3 )
    {
        IAnimatedMeshSceneNode::updateAbsolutePosition();
        return;
    }

    SMD3QuaterionTag parent;
    if ( Parent && Parent->getType () == ESNT_ANIMATED_MESH)
    {
        parent = ((IAnimatedMeshSceneNode*) Parent)->getAbsoluteTransformation ( MD3Special.Tagname );
    }

    SMD3QuaterionTag relative( RelativeTranslation, RelativeRotation );

    SMD3QuaterionTagList *taglist;
    taglist = ( (IAnimatedMeshMD3*) Mesh )->getTagList ( getFrameNr(),255,getStartFrame (),getEndFrame () );
    if ( taglist )
    {
        MD3Special.AbsoluteTagList.Container.set_used ( taglist->size () );
        for ( u32 i = 0; i!= taglist->size (); ++i )
        {
            MD3Special.AbsoluteTagList[i].position = parent.position + (*taglist)[i].position + relative.position;
            MD3Special.AbsoluteTagList[i].rotation = parent.rotation * (*taglist)[i].rotation * relative.rotation;
        }

    }

}
bool file_specification::make_relative(const std::string& root)
{
  if (relative()) return true;
  file_specification rootspec;
  rootspec.initialise_folder(root);
  return make_relative(rootspec);
}
예제 #5
0
static bool getYesterdayTodayAndTomorrow(JNIEnv* env, jobject localeData, const Locale& locale, const char* locale_name) {
  UErrorCode status = U_ZERO_ERROR;
  ScopedResourceBundle root(ures_open(NULL, locale_name, &status));
  ScopedResourceBundle fields(ures_getByKey(root.get(), "fields", NULL, &status));
  ScopedResourceBundle day(ures_getByKey(fields.get(), "day", NULL, &status));
  ScopedResourceBundle relative(ures_getByKey(day.get(), "relative", NULL, &status));
  if (U_FAILURE(status)) {
    return false;
  }

  UnicodeString yesterday(ures_getUnicodeStringByKey(relative.get(), "-1", &status));
  UnicodeString today(ures_getUnicodeStringByKey(relative.get(), "0", &status));
  UnicodeString tomorrow(ures_getUnicodeStringByKey(relative.get(), "1", &status));
  if (U_FAILURE(status)) {
    ALOGE("Error getting yesterday/today/tomorrow for %s: %s", locale_name, u_errorName(status));
    return false;
  }

  // We title-case the strings so they have consistent capitalization (http://b/14493853).
  UniquePtr<BreakIterator> brk(BreakIterator::createSentenceInstance(locale, status));
  if (U_FAILURE(status)) {
    ALOGE("Error getting yesterday/today/tomorrow break iterator for %s: %s", locale_name, u_errorName(status));
    return false;
  }
  yesterday.toTitle(brk.get(), locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
  today.toTitle(brk.get(), locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
  tomorrow.toTitle(brk.get(), locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);

  setStringField(env, localeData, "yesterday", yesterday);
  setStringField(env, localeData, "today", today);
  setStringField(env, localeData, "tomorrow", tomorrow);
  return true;
}
예제 #6
0
파일: uri.hpp 프로젝트: mbits-os/libbase
	std::string authority() const
	{
		if (relative() || opaque())
			return std::string();

		auto start = m_schema + 3;
		return m_uri.substr(start, m_path - start);
	}
예제 #7
0
 vec3 Camera::getRealCameraPosition()
 {
     updateViewProjectionMatrix();
     vec3 relative(0, 0, camDist);
     relative = glm::rotateX(relative, pitch);
     relative = glm::rotateY(relative, yaw);
     return getPosition() + relative;
 }
예제 #8
0
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fAuthorityValid(false),
	fUserInfoValid(false),
	fHasUserName(false),
	fHasPassword(false),
	fHasHost(false),
	fHasPort(false),
	fHasFragment(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		if (relative.HasAuthority())
			SetAuthority(relative.Authority());
		SetPath(relative.Path());
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path());
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				_SetPathUnsafe(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(base.Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base._MergePath(relative.Path());
					SetPath(path);
				}
				SetRequest(relative.Request());
			}

			if (base.HasAuthority())
				SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	if (relative.HasFragment())
		SetFragment(relative.Fragment());
}
예제 #9
0
파일: uri.hpp 프로젝트: mbits-os/libbase
	static Uri make_base(const Uri& document)
	{
		auto tmp = document;
		if (tmp.relative())
			tmp = "http://" + tmp.string();

		tmp.fragment(std::string());
		tmp.query(std::string());
		tmp.path(filesystem::path{ tmp.path() }.remove_filename().string());
		tmp.ensure_query();
		return tmp;
	}
예제 #10
0
파일: Url.cpp 프로젝트: naveedasmat/haiku
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fHasAuthority(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		SetAuthority(relative.Authority());
		SetPath(relative.Path()); // TODO _RemoveDotSegments()
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path()); // TODO _RemoveDotSegments()
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				SetPath(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base.Path();
					// Remove last part of path (the file, if any) so we get the
					// "current directory"
					path.Truncate(path.FindLast('/') + 1);
					path += relative.Path();
					// TODO _RemoveDotSegments()
					SetPath(path);
				}
				SetRequest(relative.Request());
			}
			SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	SetFragment(relative.Fragment());
}
예제 #11
0
파일: uri.hpp 프로젝트: mbits-os/libbase
	bool hierarchical() const
	{
		if (relative())
			return true;

		ensure_path();

		if (m_path - m_schema <= 2)
			return false;

		auto c = m_uri.data();
		return c[m_schema + 1] == '/' && c[m_schema + 2] == '/';
	}
예제 #12
0
// In which decorative object are we?
// On return, the position is the location of the cursor's hot spot
// Returns false if we aren't in any zone
bool PlayGround::zone(QPoint &position)
{
  // Scan all available decorative objects on right side because we may be adding one
  int draggedNumber;
  for (draggedNumber = 0;
       draggedNumber < decorations;
       draggedNumber++) if (objectsLayout[draggedNumber].contains(position))
  {
     position.setX(position.x() - objectsLayout[draggedNumber].x());
     position.setY(position.y() - objectsLayout[draggedNumber].y());

     draggedObject.setNumber(draggedNumber);
     draggedZOrder = -1;

     return true;
  }

  // Scan all decorative objects already layed down on editable are because we may be moving or removing one
  const ToDraw *currentObject;

  for (draggedZOrder = toDraw.count()-1; draggedZOrder >= 0; draggedZOrder--)
  {
    currentObject = toDraw.at(draggedZOrder);
    if (!currentObject->getPosition().contains(position)) continue;

    QRect toUpdate(currentObject->getPosition());
    draggedObject = *currentObject;
    draggedNumber = draggedObject.getNumber();

    QBitmap shape(objectsLayout[draggedNumber].size());
    QPoint relative(position.x() - toUpdate.x(),
                    position.y() - toUpdate.y());
    bitBlt(&shape, QPoint(0, 0), &masks, objectsLayout[draggedNumber], Qt::CopyROP);
    if (!shape.convertToImage().pixelIndex(relative.x(), relative.y())) continue;

    toDraw.remove(draggedZOrder);
    toUpdate.moveBy(XMARGIN, YMARGIN);
    repaint(toUpdate, false);

    position = relative;

    return true;
  }

  // If we are on the gameboard itself, then play "tuberling" sound
  if (editableArea.contains(position))
        topLevel->playSound(editableSound);

  return false;
}
예제 #13
0
wxFileName FileViewer::GetFilename(wxString ref) const
{
    if ( ref.length() >= 3 &&
         ref[1] == _T(':') &&
         (ref[2] == _T('\\') || ref[2] == _T('/')) )
    {
        // This is an absolute Windows path (c:\foo... or c:/foo...); fix
        // the latter case.
        ref.Replace("/", "\\");
    }

    wxPathFormat pathfmt = ref.Contains(_T('\\')) ? wxPATH_WIN : wxPATH_UNIX;
    wxFileName filename(ref.BeforeLast(_T(':')), pathfmt);

    if ( filename.IsRelative() )
    {
        wxFileName relative(filename);
        wxString basePath(m_basePath);

        // Sometimes, the path in source reference is not relative to the PO
        // file's location, but is relative to e.g. the root directory. See
        // https://code.djangoproject.com/ticket/13936 for exhaustive
        // discussion with plenty of examples.
        //
        // Deal with this by trying parent directories of m_basePath too. So if
        // a file named project/locales/cs/foo.po has a reference to src/main.c,
        // try not only project/locales/cs/src/main.c, but also
        // project/locales/src/main.c and project/src/main.c etc.
        while ( !basePath.empty() )
        {
            filename = relative;
            filename.MakeAbsolute(basePath);
            if ( filename.FileExists() )
            {
                break; // good, found the file
            }
            else
            {
                // remove the last path component
                size_t last = basePath.find_last_of("\\/");
                if ( last == wxString::npos )
                    break;
                else
                    basePath.erase(last);
            }
        }
    }

    return filename;
}
예제 #14
0
void
bridge_rewrite_rep::my_typeset (int desired_status) {
  initialize (env->rewrite (st));
  ttt->insert_marker (st, ip);
  if (is_func (st, VAR_INCLUDE)) {
    url save_name= env->cur_file_name;
    url file_name= url_unix (env->exec_string (st[0]));
    env->cur_file_name= relative (env->base_file_name, file_name);
    env->secure= is_secure (env->cur_file_name);
    body->typeset (desired_status);
    env->cur_file_name= save_name;
    env->secure= is_secure (env->cur_file_name);
  }
  else body->typeset (desired_status);
}
예제 #15
0
파일: inspect.cpp 프로젝트: ct-clmsn/hpx
    // may return an empty string [gps]
    string impute_library( const path & full_dir_path )
    {
      path relative( relative_to( full_dir_path, search_root_path() ) );
      if ( relative.empty() ) return "boost-root";
      string first( (*relative.begin()).string() );
      string second =  // borland 5.61 requires op=
        ++relative.begin() == relative.end()
          ? string() : (*++relative.begin()).string();

      if ( first == "boost" )
        return second;

      return (( first == "libs" || first == "tools" ) && !second.empty())
        ? second : first;
    }
예제 #16
0
std::string file_specification::image(void) const
{
  std::string result = m_drive;
  if (absolute())
    result += preferred_separator;
  if (!m_path.empty())
    result += vector_to_string(m_path, std::string(1,preferred_separator));
  else if (relative())
    result += '.';
  if (!m_filename.empty())
  {
    result += preferred_separator;
    result += m_filename;
  }
  return result;
}
예제 #17
0
    string impute_library( const path & full_dir_path )
    {
      path relative( relative_to( full_dir_path, fs::initial_path() ),
        fs::no_check );
      if ( relative.empty() ) return "boost-root";
      string first( *relative.begin() );
      string second =  // borland 5.61 requires op=  
        ++relative.begin() == relative.end()
          ? string() : *++relative.begin();

      if ( first == "boost" )
        return second.empty() ? string( "unknown" ) : second;

      return (( first == "libs" || first == "tools" ) && !second.empty())
        ? second : first;
    }
예제 #18
0
   void assert_macro_check::inspect(
      const string & library_name,
      const path & full_path,   // example: c:/foo/boost/filesystem/path.hpp
      const string & contents )     // contents of file to be inspected
    {
      if (contents.find( "boostinspect:" "naassert_macro" ) != string::npos)
        return;

      // Check files iff (a) they are in the boost directory, or (b) they
      // are in the src directory under libs.
      if (m_from_boost_root) {
        path relative( relative_to( full_path, fs::initial_path() ) );
        path::const_iterator pbeg = relative.begin(), pend = relative.end();
        if (pbeg != std::find(pbeg, pend, "boost") &&
          !(pbeg == std::find(pbeg, pend, "libs") && pend != std::find(pbeg, pend, "src")))
          return;
      }

      long errors = 0;
      boost::sregex_iterator cur(contents.begin(), contents.end(), assert_macro_regex), end;
      for( ; cur != end; ++cur )
      {
        if(!(*cur)[3].matched)
        {
          string::const_iterator it = contents.begin();
          string::const_iterator match_it = (*cur)[0].first;

          string::const_iterator line_start = it;

          string::size_type line_number = 1;
          for ( ; it != match_it; ++it) {
              if (string::traits_type::eq(*it, '\n')) {
                  ++line_number;
                  line_start = it + 1; // could be end()
              }
          }

          ++errors;
          error( library_name, full_path, "C-style assert macro on line "
            + boost::lexical_cast<string>( line_number ) );
        }
      }
      if(errors > 0)
        ++m_files_with_errors;
    }
예제 #19
0
void
concater_rep::typeset_sound (tree t, path ip) {
  if (N(t) != 1) { typeset_error (t, ip); return; }
  player pl= get_player (env->get_animation_ip (ip));
  tree sound_t= env->exec (t[0]);
  url sound= url_none ();
  if (is_atomic (sound_t)) {
    url sound_u= sound_t->label;
    sound= resolve (relative (env->base_file_name, sound_u));
  }
  if (!is_none (sound)) {
    int sz= script (env->fn_size, env->index_level);
    font gfn (tex_font ("cmr", sz, (int) (env->magn*env->dpi)));
    print (sound_box (ip, pl, sound, gfn->yx));
    flag ("sound", ip, brown);
  }
  else typeset_dynamic (tree (ERROR, "bad sound", t[0]), ip);
}
예제 #20
0
   void apple_macro_check::inspect(
      const string & library_name,
      const path & full_path,   // example: c:/foo/boost/filesystem/path.hpp
      const string & contents )     // contents of file to be inspected
    {
      if (contents.find( "hpxinspect:" "noapple_macros" ) != string::npos) return;

      // Only check files in the boost directory, as we can avoid including the
      // apple test headers elsewhere.
      path relative( relative_to( full_path, search_root_path() ) );
      if ( relative.empty() || *relative.begin() != "boost") return;

      boost::sregex_iterator cur(contents.begin(),
          contents.end(), apple_macro_regex), end;

      long errors = 0;

      for( ; cur != end; ++cur /*, ++m_files_with_errors*/ )
      {

        if(!(*cur)[3].matched)
        {
          string::const_iterator it = contents.begin();
          string::const_iterator match_it = (*cur)[0].first;

          string::const_iterator line_start = it;

          string::size_type line_number = 1;
          for ( ; it != match_it; ++it) {
              if (string::traits_type::eq(*it, '\n')) {
                  ++line_number;
                  line_start = it + 1; // could be end()
              }
          }
          ++errors;
          error( library_name, full_path,
            "Apple macro clash: " + std::string((*cur)[0].first, (*cur)[0].second-1),
            line_number );
        }
      }
      if(errors > 0) {
        ++m_files_with_errors;
      }
    }
예제 #21
0
void
concater_rep::typeset_video (tree t, path ip) {
  if (N(t) != 5) { typeset_error (t, ip); return; }
  player pl= get_player (env->get_animation_ip (ip));
  tree video_t= env->exec (t[0]);
  url video= url_none ();
  if (is_atomic (video_t)) {
    url video_u= video_t->label;
    video= resolve (relative (env->base_file_name, video_u));
  }
  if (!is_none (video)) {
    SI   w  = env->as_length (env->exec (t[1]));
    SI   h  = env->as_length (env->exec (t[2]));
    int  len= env->as_length (env->exec (t[3]));
    bool rep= env->exec (t[4]) != "false";
    print (video_box (ip, pl, video, w, h, env->alpha, len, rep, env->pixel));
  }
  else typeset_dynamic (tree (ERROR, "bad video", t[0]), ip);
}
예제 #22
0
파일: env.c 프로젝트: ksherlock/gno
int set_prefix(const char *cp) {

	/* union of ResultBuf255Ptr / GSString255Ptr */
	static PrefixRecGS dcb = { 2, 0, (ResultBuf255Ptr)&value.bufString };
	int pfx = -1;
	unsigned l;
	char *ptr = cp;

	if (_v) fprintf(stderr, "#env setprefix:\t%s\n", cp);

	if (isdigit(*cp)) pfx = strtol(cp, &ptr, 10);
	if (pfx < 0 || pfx > 31 || *ptr != '=' ) errx(1, "setprefix %s: invalid argument", cp);

	++ptr; /* = */
	l = strlen(ptr);
	if (l == 0 || l > 255) {
		errx(1, "setprefix %s: Invalid argument", cp);
	}

	/* in SetPrefixGS, relative paths are relative
	   to the prefix being set, not prefix 0
	   to counteract this, make it relative to prefix 0
	*/
	if (pfx && relative(ptr)) {
		if (l > 253) 
			errx(1, "setprefix %s: Invalid argument", cp);

		value.bufString.length = l + 2;
		value.bufString.text[0] = '0';
		value.bufString.text[1] = ':';
		memcpy(value.bufString.text + 2 , ptr, l);	
	} else {
		value.bufString.length = l;
		memcpy(value.bufString.text, ptr, l);	
	}

	dcb.prefixNum = pfx;
	SetPrefixGS(&dcb);
	if (_toolErr) {
		errx(1, "SetPrefixGS %s: $%04x", cp, _toolErr);
	}
	return 1;
}
예제 #23
0
bool file_specification::make_relative(const file_specification& rootspec)
{
  if (relative()) return true;
  DEBUG_ASSERT(rootspec.absolute());
  // now compare elements of the root with elements of this to find the common path
  // if the drives are different, no conversion can take place, else clear the drive
  if (!path_compare(drive(), rootspec.drive())) return true;
  set_drive("");
  // first remove leading elements that are identical to the corresponding element in root
  unsigned i = 0;
  while(subpath_size() > 0 && i < rootspec.subpath_size() && path_compare(subpath_element(0), rootspec.subpath_element(i)))
  {
    subpath_erase(0);
    i++;
  }
  // now add a .. prefix for every element in root that is different from this
  while (i < rootspec.subpath_size())
  {
    m_path.insert(m_path.begin(), "..");
    i++;
  }
  set_relative();
  return true;
}
예제 #24
0
void CFlashLight::EnableFogVolume(CWeapon* pWeapon, int slot, bool enable)
{
	if (!g_pGameCVars->i_flashlight_has_fog_volume)
	{
		return;
	}

	if (!m_sharedparams->pFlashLightParams)
	{
		return;
	}

	IEntity* pFogVolume = 0;

	if (m_fogVolume == 0)
	{
		const Vec3 size = Vec3(
		                    m_sharedparams->pFlashLightParams->fogVolumeRadius,
		                    m_sharedparams->pFlashLightParams->fogVolumeSize,
		                    m_sharedparams->pFlashLightParams->fogVolumeRadius);

		SEntitySpawnParams fogVolumeParams;
		fogVolumeParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("FogVolume");
		fogVolumeParams.nFlags = ENTITY_FLAG_NO_SAVE;
		fogVolumeParams.vPosition = Vec3(ZERO);

		pFogVolume = gEnv->pEntitySystem->SpawnEntity(fogVolumeParams);

		if (!pFogVolume)
		{
			return;
		}

		m_fogVolume = pFogVolume->GetId();

		SmartScriptTable pProperties;
		pFogVolume->GetScriptTable()->GetValue("Properties", pProperties);

		if (pProperties)
		{
			pProperties->SetValue("color_Color", m_sharedparams->pFlashLightParams->fogVolumeColor);
			pProperties->SetValue("GlobalDensity", m_sharedparams->pFlashLightParams->fogVolumeDensity);
			pProperties->SetValue("Size", size);
			pProperties->SetValue("FallOffScale", 0.0f);
		}

		EntityScripts::CallScriptFunction(pFogVolume, pFogVolume->GetScriptTable(), "OnPropertyChange");

		pFogVolume->Activate(true);
	}
	else
	{
		pFogVolume = gEnv->pEntitySystem->GetEntity(m_fogVolume);
	}

	if (!pFogVolume)
	{
		return;
	}

	const char* attachHelper = "lightFog_term";
	const float distance = m_sharedparams->pFlashLightParams->fogVolumeSize * 0.5f;
	ICharacterInstance* pCharacter = pWeapon->GetEntity()->GetCharacter(slot);

	if (enable && pCharacter)
	{
		IAttachmentManager* pAttachmentManager = pCharacter->GetIAttachmentManager();
		IAttachment* pAttachment = pAttachmentManager->GetInterfaceByName(attachHelper);

		if (pAttachment)
		{
			CEntityAttachment* pEntityAttachment = new CEntityAttachment();
			pEntityAttachment->SetEntityId(m_fogVolume);
			pAttachment->AddBinding(pEntityAttachment);
			QuatT relative(IDENTITY);
			relative.t.y = distance;
			pAttachment->SetAttRelativeDefault(relative);
		}
	}

	pFogVolume->Hide(!enable);
}
예제 #25
0
파일: folder.c 프로젝트: arcfide/Unicode-NN
static void
rewrite_folder(void)
{
    register FILE  *src, *dst;
    char           *oldfile;
    register int    c;
    register long   cnt;
    register article_header *ah, **ahp;
    register article_number n;

    if (strchr(backup_folder_path, '/'))
	oldfile = backup_folder_path;
    else
	oldfile = relative(nn_directory, backup_folder_path);

    if (move_file(group_path_name, oldfile, 1) < 0) {
	tprintf("\r\n\nCannot backup folder in %s\n", oldfile);
	goto confirm;
    }
    if ((src = open_file(oldfile, OPEN_READ)) == NULL) {
	tprintf("\rCannot open %s\n\r", oldfile);
	goto move_back;
    }
    if ((dst = open_file(group_path_name, OPEN_CREATE)) == NULL) {
	fclose(src);
	tprintf("\rCannot create %s\n\r", group_path_name);
	goto move_back;
    }
    sort_articles(-2);

    tprintf("\rCompressing folder...\n\r");
    fl;

    get_folder_type(src);

    for (ahp = articles, n = n_articles; --n >= 0; ahp++) {
	ah = *ahp;
	cnt = ah->lpos - ah->hpos;
	if (folder_rewrite_trace)
	    tprintf("%s\t%s (%ld-%ld=%ld)\n\r",
		    ah->attr == A_CANCEL ? "CANCEL" : "KEEP",
		    ah->subject, ah->hpos, (long) (ah->lpos), cnt);
	if (ah->attr == A_CANCEL)
	    continue;
	fseek(src, ah->hpos, 0);
	mailbox_format(dst, -1);
	while (--cnt >= 0) {
	    if ((c = getc(src)) == EOF)
		break;
	    putc(c, dst);
	}
	mailbox_format(dst, 0);
    }

    fclose(src);
    if (fclose(dst) == EOF)
	goto move_back;
    if (!keep_backup_folder)
	unlink(oldfile);
    if (folder_rewrite_trace)
	goto confirm;
    return;

move_back:
    if (move_file(oldfile, group_path_name, 2) == 0)
	tprintf("Cannot create new file -- Folder restored\n\r");
    else
	tprintf("Cannot create new file\n\n\rFolder saved in %s\n\r", oldfile);

confirm:
    any_key(0);
}
예제 #26
0
파일: kill.c 프로젝트: jheiss/nn
int
init_kill(void)
{
    FILE           *killf;
    comp_kill_header header;
    comp_kill_entry entry;
    register kill_list_entry *kl;
    register kill_group_regexp *tb;
    register group_header *gh;
    time_t          kill_age, comp_age;
    register long   n;
    int             first_try = 1;

    Loop_Groups_Header(gh)
    gh->kill_list = NULL;

    kill_age = file_exist(relative(nn_directory, KILL_FILE), "frw");
    if (kill_age == 0)
        return 0;

    comp_age = file_exist(relative(nn_directory, COMPILED_KILL), "fr");
again:
    if (comp_age < kill_age && !compile_kill_file())
        return 0;

    kill_tab = NULL;
    kill_patterns = NULL;
    group_regexp_table = NULL;
    regexp_table_size = 0;

    killf = open_file(relative(nn_directory, COMPILED_KILL), OPEN_READ);
    if (killf == NULL)
        return 0;

    if (fread((char *) &header, sizeof(header), 1, killf) != 1)
        goto err;
    /* MAGIC check: format changed or using different hardware */
    if (header.ckh_magic != COMP_KILL_MAGIC)
        goto err;

#ifndef NOV
    /* DB check: if database is rebuilt, group numbers may change */
    if (header.ckh_db_check != master.db_created)
        goto err;
#else
    /* ugly hack for NOV as there isn't a master to check */
    if (first_try)
        goto err;
#endif

    if (header.ckh_entries == 0) {
        fclose(killf);
        kill_file_loaded = 1;
        return 0;
    }
    if (header.ckh_pattern_size > 0) {
        kill_patterns = newstr(header.ckh_pattern_size);
        fseek(killf, header.ckh_entries * sizeof(entry), 1);
        if (fread(kill_patterns, sizeof(char), (int) header.ckh_pattern_size, killf)
                != header.ckh_pattern_size)
            goto err;
    } else
        kill_patterns = newstr(1);

    kill_tab = newobj(kill_list_entry, header.ckh_entries);
    if ((regexp_table_size = header.ckh_regexp_size))
        group_regexp_table = newobj(kill_group_regexp, header.ckh_regexp_size);

    tb = group_regexp_table;

    fseek(killf, sizeof(header), 0);
    for (n = header.ckh_entries, kl = kill_tab; --n >= 0; kl++) {
        if (fread((char *) &entry, sizeof(entry), 1, killf) != 1)
            goto err;
        if (header.ckh_pattern_size <= entry.ck_pattern_index ||
                entry.ck_pattern_index < 0)
            goto err;

        kl->kill_pattern = kill_patterns + entry.ck_pattern_index;
        kl->kill_flag = entry.ck_flag;

        if (kl->kill_flag & KILL_ON_REGEXP)
            kl->kill_regexp = regcomp(kl->kill_pattern);
        else
            kl->kill_regexp = NULL;

        if (kl->kill_flag & GROUP_REGEXP) {
            if (kl->kill_flag & GROUP_REGEXP_HDR) {
                if (header.ckh_pattern_size <= entry.ck_group ||
                        entry.ck_group < 0)
                    goto err;
                tb->group_regexp = regcomp(kill_patterns + entry.ck_group);
            } else
                tb->group_regexp = NULL;
            tb->kill_entry = kl;
            tb++;
        } else if (entry.ck_group >= 0) {
            gh = ACTIVE_GROUP(entry.ck_group);
            kl->next_kill = (kill_list_entry *) (gh->kill_list);
            gh->kill_list = (char *) kl;
        } else {
            kl->next_kill = global_kill_list;
            global_kill_list = kl;
        }
    }

    fclose(killf);

    kill_file_loaded = 1;
    return 1;

err:
    if (group_regexp_table != NULL)
        freeobj(group_regexp_table);
    if (kill_patterns != NULL)
        freeobj(kill_patterns);
    if (kill_tab != NULL)
        freeobj(kill_tab);

    fclose(killf);
    rm_kill_file();
    if (first_try) {
        first_try = 0;
        comp_age = 0;
        goto again;
    }
    strcpy(delayed_msg, "Error in compiled kill file (ignored)");

    Loop_Groups_Header(gh)
    gh->kill_list = NULL;

    global_kill_list = NULL;
    group_regexp_table = NULL;

    return 0;
}
예제 #27
0
파일: asm.cpp 프로젝트: zbc6063054/nes
///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer.
char *Disassemble(u16 addr, u8 *opcode) {
    static char str[64]={0},chr[5]={0};
    u16 tmp,tmp2;

    //these may be replaced later with passed-in values to make a lighter-weight disassembly mode that may not query the referenced values
    #define RX (nes.cpu->reg_x)
    #define RY (nes.cpu->reg_y)

    switch (opcode[0]) {
        #define relative(a) { \
            if (((a)=opcode[1])&0x80) (a) = addr-(((a)-1)^0xFF); \
            else (a)+=addr; \
        }
        #define absolute(a) { \
            (a) = opcode[1] | opcode[2]<<8; \
        }
        #define zpIndex(a,i) { \
            (a) = opcode[1]+(i); \
        }
        #define indirectX(a) { \
            (a) = (opcode[1]+RX)&0xFF; \
            (a) = nes.readByte((a)) | (nes.readByte((a)+1))<<8; \
        }
        #define indirectY(a) { \
            (a) = nes.readByte(opcode[1]) | (nes.readByte(opcode[1]+1))<<8; \
            (a) += RY; \
        }


        //odd, 1-byte opcodes
        case 0x00: strcpy(str,"BRK"); break;
        case 0x08: strcpy(str,"PHP"); break;
        case 0x0A: strcpy(str,"ASL"); break;
        case 0x18: strcpy(str,"CLC"); break;
        case 0x28: strcpy(str,"PLP"); break;
        case 0x2A: strcpy(str,"ROL"); break;
        case 0x38: strcpy(str,"SEC"); break;
        case 0x40: strcpy(str,"RTI"); break;
        case 0x48: strcpy(str,"PHA"); break;
        case 0x4A: strcpy(str,"LSR"); break;
        case 0x58: strcpy(str,"CLI"); break;
        case 0x60: strcpy(str,"RTS"); break;
        case 0x68: strcpy(str,"PLA"); break;
        case 0x6A: strcpy(str,"ROR"); break;
        case 0x78: strcpy(str,"SEI"); break;
        case 0x88: strcpy(str,"DEY"); break;
        case 0x8A: strcpy(str,"TXA"); break;
        case 0x98: strcpy(str,"TYA"); break;
        case 0x9A: strcpy(str,"TXS"); break;
        case 0xA8: strcpy(str,"TAY"); break;
        case 0xAA: strcpy(str,"TAX"); break;
        case 0xB8: strcpy(str,"CLV"); break;
        case 0xBA: strcpy(str,"TSX"); break;
        case 0xC8: strcpy(str,"INY"); break;
        case 0xCA: strcpy(str,"DEX"); break;
        case 0xD8: strcpy(str,"CLD"); break;
        case 0xE8: strcpy(str,"INX"); break;
        case 0xEA: strcpy(str,"NOP"); break;
        case 0xF8: strcpy(str,"SED"); break;

        //(Indirect,X)
        case 0x01: strcpy(chr,"ORA"); goto _indirectx;
        case 0x21: strcpy(chr,"AND"); goto _indirectx;
        case 0x41: strcpy(chr,"EOR"); goto _indirectx;
        case 0x61: strcpy(chr,"ADC"); goto _indirectx;
        case 0x81: strcpy(chr,"STA"); goto _indirectx;
        case 0xA1: strcpy(chr,"LDA"); goto _indirectx;
        case 0xC1: strcpy(chr,"CMP"); goto _indirectx;
        case 0xE1: strcpy(chr,"SBC"); goto _indirectx;
        _indirectx:
            indirectX(tmp);
            sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
            break;

        //Zero Page
        case 0x05: strcpy(chr,"ORA"); goto _zeropage;
        case 0x06: strcpy(chr,"ASL"); goto _zeropage;
        case 0x24: strcpy(chr,"BIT"); goto _zeropage;
        case 0x25: strcpy(chr,"AND"); goto _zeropage;
        case 0x26: strcpy(chr,"ROL"); goto _zeropage;
        case 0x45: strcpy(chr,"EOR"); goto _zeropage;
        case 0x46: strcpy(chr,"LSR"); goto _zeropage;
        case 0x65: strcpy(chr,"ADC"); goto _zeropage;
        case 0x66: strcpy(chr,"ROR"); goto _zeropage;
        case 0x84: strcpy(chr,"STY"); goto _zeropage;
        case 0x85: strcpy(chr,"STA"); goto _zeropage;
        case 0x86: strcpy(chr,"STX"); goto _zeropage;
        case 0xA4: strcpy(chr,"LDY"); goto _zeropage;
        case 0xA5: strcpy(chr,"LDA"); goto _zeropage;
        case 0xA6: strcpy(chr,"LDX"); goto _zeropage;
        case 0xC4: strcpy(chr,"CPY"); goto _zeropage;
        case 0xC5: strcpy(chr,"CMP"); goto _zeropage;
        case 0xC6: strcpy(chr,"DEC"); goto _zeropage;
        case 0xE4: strcpy(chr,"CPX"); goto _zeropage;
        case 0xE5: strcpy(chr,"SBC"); goto _zeropage;
        case 0xE6: strcpy(chr,"INC"); goto _zeropage;
        _zeropage:
        // ################################## Start of SP CODE ###########################
        // Change width to %04X
            sprintf(str,"%s $%04X = #$%02X", chr,opcode[1],GetMem(opcode[1]));
        // ################################## End of SP CODE ###########################
            break;

        //#Immediate
        case 0x09: strcpy(chr,"ORA"); goto _immediate;
        case 0x29: strcpy(chr,"AND"); goto _immediate;
        case 0x49: strcpy(chr,"EOR"); goto _immediate;
        case 0x69: strcpy(chr,"ADC"); goto _immediate;
        //case 0x89: strcpy(chr,"STA"); goto _immediate;  //baka, no STA #imm!!
        case 0xA0: strcpy(chr,"LDY"); goto _immediate;
        case 0xA2: strcpy(chr,"LDX"); goto _immediate;
        case 0xA9: strcpy(chr,"LDA"); goto _immediate;
        case 0xC0: strcpy(chr,"CPY"); goto _immediate;
        case 0xC9: strcpy(chr,"CMP"); goto _immediate;
        case 0xE0: strcpy(chr,"CPX"); goto _immediate;
        case 0xE9: strcpy(chr,"SBC"); goto _immediate;
        _immediate:
            sprintf(str,"%s #$%02X", chr,opcode[1]);
            break;

        //Absolute
        case 0x0D: strcpy(chr,"ORA"); goto _absolute;
        case 0x0E: strcpy(chr,"ASL"); goto _absolute;
        case 0x2C: strcpy(chr,"BIT"); goto _absolute;
        case 0x2D: strcpy(chr,"AND"); goto _absolute;
        case 0x2E: strcpy(chr,"ROL"); goto _absolute;
        case 0x4D: strcpy(chr,"EOR"); goto _absolute;
        case 0x4E: strcpy(chr,"LSR"); goto _absolute;
        case 0x6D: strcpy(chr,"ADC"); goto _absolute;
        case 0x6E: strcpy(chr,"ROR"); goto _absolute;
        case 0x8C: strcpy(chr,"STY"); goto _absolute;
        case 0x8D: strcpy(chr,"STA"); goto _absolute;
        case 0x8E: strcpy(chr,"STX"); goto _absolute;
        case 0xAC: strcpy(chr,"LDY"); goto _absolute;
        case 0xAD: strcpy(chr,"LDA"); goto _absolute;
        case 0xAE: strcpy(chr,"LDX"); goto _absolute;
        case 0xCC: strcpy(chr,"CPY"); goto _absolute;
        case 0xCD: strcpy(chr,"CMP"); goto _absolute;
        case 0xCE: strcpy(chr,"DEC"); goto _absolute;
        case 0xEC: strcpy(chr,"CPX"); goto _absolute;
        case 0xED: strcpy(chr,"SBC"); goto _absolute;
        case 0xEE: strcpy(chr,"INC"); goto _absolute;
        _absolute:
            absolute(tmp);
            sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp));
            break;

        //branches
        case 0x10: strcpy(chr,"BPL"); goto _branch;
        case 0x30: strcpy(chr,"BMI"); goto _branch;
        case 0x50: strcpy(chr,"BVC"); goto _branch;
        case 0x70: strcpy(chr,"BVS"); goto _branch;
        case 0x90: strcpy(chr,"BCC"); goto _branch;
        case 0xB0: strcpy(chr,"BCS"); goto _branch;
        case 0xD0: strcpy(chr,"BNE"); goto _branch;
        case 0xF0: strcpy(chr,"BEQ"); goto _branch;
        _branch:
            relative(tmp);
            sprintf(str,"%s $%04X", chr,tmp);
            break;

        //(Indirect),Y
        case 0x11: strcpy(chr,"ORA"); goto _indirecty;
        case 0x31: strcpy(chr,"AND"); goto _indirecty;
        case 0x51: strcpy(chr,"EOR"); goto _indirecty;
        case 0x71: strcpy(chr,"ADC"); goto _indirecty;
        case 0x91: strcpy(chr,"STA"); goto _indirecty;
        case 0xB1: strcpy(chr,"LDA"); goto _indirecty;
        case 0xD1: strcpy(chr,"CMP"); goto _indirecty;
        case 0xF1: strcpy(chr,"SBC"); goto _indirecty;
        _indirecty:
            indirectY(tmp);
            sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
            break;

        //Zero Page,X
        case 0x15: strcpy(chr,"ORA"); goto _zeropagex;
        case 0x16: strcpy(chr,"ASL"); goto _zeropagex;
        case 0x35: strcpy(chr,"AND"); goto _zeropagex;
        case 0x36: strcpy(chr,"ROL"); goto _zeropagex;
        case 0x55: strcpy(chr,"EOR"); goto _zeropagex;
        case 0x56: strcpy(chr,"LSR"); goto _zeropagex;
        case 0x75: strcpy(chr,"ADC"); goto _zeropagex;
        case 0x76: strcpy(chr,"ROR"); goto _zeropagex;
        case 0x94: strcpy(chr,"STY"); goto _zeropagex;
        case 0x95: strcpy(chr,"STA"); goto _zeropagex;
        case 0xB4: strcpy(chr,"LDY"); goto _zeropagex;
        case 0xB5: strcpy(chr,"LDA"); goto _zeropagex;
        case 0xD5: strcpy(chr,"CMP"); goto _zeropagex;
        case 0xD6: strcpy(chr,"DEC"); goto _zeropagex;
        case 0xF5: strcpy(chr,"SBC"); goto _zeropagex;
        case 0xF6: strcpy(chr,"INC"); goto _zeropagex;
        _zeropagex:
            zpIndex(tmp,RX);
        // ################################## Start of SP CODE ###########################
        // Change width to %04X
            sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
        // ################################## End of SP CODE ###########################
            break;

        //Absolute,Y
        case 0x19: strcpy(chr,"ORA"); goto _absolutey;
        case 0x39: strcpy(chr,"AND"); goto _absolutey;
        case 0x59: strcpy(chr,"EOR"); goto _absolutey;
        case 0x79: strcpy(chr,"ADC"); goto _absolutey;
        case 0x99: strcpy(chr,"STA"); goto _absolutey;
        case 0xB9: strcpy(chr,"LDA"); goto _absolutey;
        case 0xBE: strcpy(chr,"LDX"); goto _absolutey;
        case 0xD9: strcpy(chr,"CMP"); goto _absolutey;
        case 0xF9: strcpy(chr,"SBC"); goto _absolutey;
        _absolutey:
            absolute(tmp);
            tmp2=(tmp+RY);
            sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
            break;

        //Absolute,X
        case 0x1D: strcpy(chr,"ORA"); goto _absolutex;
        case 0x1E: strcpy(chr,"ASL"); goto _absolutex;
        case 0x3D: strcpy(chr,"AND"); goto _absolutex;
        case 0x3E: strcpy(chr,"ROL"); goto _absolutex;
        case 0x5D: strcpy(chr,"EOR"); goto _absolutex;
        case 0x5E: strcpy(chr,"LSR"); goto _absolutex;
        case 0x7D: strcpy(chr,"ADC"); goto _absolutex;
        case 0x7E: strcpy(chr,"ROR"); goto _absolutex;
        case 0x9D: strcpy(chr,"STA"); goto _absolutex;
        case 0xBC: strcpy(chr,"LDY"); goto _absolutex;
        case 0xBD: strcpy(chr,"LDA"); goto _absolutex;
        case 0xDD: strcpy(chr,"CMP"); goto _absolutex;
        case 0xDE: strcpy(chr,"DEC"); goto _absolutex;
        case 0xFD: strcpy(chr,"SBC"); goto _absolutex;
        case 0xFE: strcpy(chr,"INC"); goto _absolutex;
        _absolutex:
            absolute(tmp);
            tmp2=(tmp+RX);
            sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
            break;

        //jumps
        case 0x20: strcpy(chr,"JSR"); goto _jump;
        case 0x4C: strcpy(chr,"JMP"); goto _jump;
        case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break;
        _jump:
            absolute(tmp);
            sprintf(str,"%s $%04X", chr,tmp);
            break;

        //Zero Page,Y
        case 0x96: strcpy(chr,"STX"); goto _zeropagey;
        case 0xB6: strcpy(chr,"LDX"); goto _zeropagey;
        _zeropagey:
            zpIndex(tmp,RY);
        // ################################## Start of SP CODE ###########################
        // Change width to %04X
            sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
        // ################################## End of SP CODE ###########################
            break;

        //UNDEFINED
        default: strcpy(str,"ERROR"); break;

    }

    return str;
}
예제 #28
0
파일: kill.c 프로젝트: jheiss/nn
void
rm_kill_file(void)
{
    unlink(relative(nn_directory, COMPILED_KILL));
}
	LEMON_UNITTEST_CASE(FileSystemUnittest,path_test)
	{
		fs::path win32Path1(LEMON_TEXT("c:\\test.txt"));

		fs::path win32Path2(LEMON_TEXT(".\\test.txt"));

		fs::path unixPath1(LEMON_TEXT("./test.txt"));

		fs::path unixPath2(LEMON_TEXT("/test/../a/./../test.txt"));

		LEMON_CHECK(win32Path1.root() == LEMON_TEXT("c:"));

		LEMON_CHECK(win32Path2.root() == LEMON_TEXT("."));

		LEMON_CHECK(unixPath1.root() == LEMON_TEXT("."));

		LEMON_CHECK(win32Path1.begin() != win32Path1.end());

		LEMON_CHECK(*win32Path1.begin()  ==  LEMON_TEXT("test.txt"));

		LEMON_CHECK(unixPath1.leaf()  ==  LEMON_TEXT("test.txt"));

		LEMON_CHECK(win32Path2.has_leaf());

		LEMON_CHECK(win32Path2.relative_path());

		LEMON_CHECK(unixPath1.relative_path());

		LEMON_CHECK(extension(unixPath1) == LEMON_TEXT("txt"));
		
		unixPath2.compress();

		LEMON_CHECK(unixPath2.string() == LEMON_TEXT("/test.txt"));

		{
			fs::path a(LEMON_TEXT("/a/"));

			fs::path b(LEMON_TEXT("/a/b"));

			LEMON_CHECK(relative(a,b) == fs::path(LEMON_TEXT("./b")));
		}

		{
			fs::path a(LEMON_TEXT("/a/c/d"));

			fs::path b(LEMON_TEXT("/a/b"));

			LEMON_CHECK(relative(a,b) == fs::path(LEMON_TEXT("../../b")));
		}

		{
			fs::path a(LEMON_TEXT("c:/a/c/d"));

			fs::path b(LEMON_TEXT("c:/a/b"));

			LEMON_CHECK(relative(a,b) == fs::path(LEMON_TEXT("../../b")));
		}

		{
			fs::path a(LEMON_TEXT("c:/a/c/d"));

			fs::path b(LEMON_TEXT("d:/a/b"));

			LEMON_CHECK(relative(a,b) == fs::path());
		}
	}
예제 #30
0
//---------------------------------------------------------------
URI URI::getRelativeTo ( const URI& uri, bool& success,  bool ignoreCase ) const
{
    URI relative(*this);
    success = relative.makeRelativeTo ( uri, ignoreCase );
    return relative;
}