Exemple #1
0
char* csPathsUtilities::ExpandPath (const char* path)
{
  // Remember where we are.
  char old_path[CS_MAXPATHLEN];
  if (!getcwdcheck (old_path, sizeof (old_path)))
    // In case of an error return 0.
    return 0;

  // Normalize `path'.
  if (!chdircheck (path))
  {
    if (!chdircheck (old_path))
      return 0;
    return 0;
  }
  char normalized_path[CS_MAXPATHLEN];
  if (!getcwdcheck (normalized_path, sizeof (normalized_path)))
  {
    if (!chdircheck (old_path))
      return 0;
    return 0;
  }

  // Restore working directory.
  if (!chdircheck (old_path))
    return (csStrNew (normalized_path)); // return normalized path nevertheless

  return (csStrNew (normalized_path));
}
Exemple #2
0
void csReporter::ActualReport (const csRefArray<iReporterListener>& listeners,
                               int severity, const char* msgId, 
                               const char* buf)
{
  bool add_msg = true;
  size_t i;
  for (i = 0 ; i < listeners.GetSize () ; i++)
  {
    iReporterListener* listener = listeners[i];
    if (listener->Report (this, severity, msgId, buf))
    {
      add_msg = false;
      break;
    }
  }

  if (add_msg)
  {
    csReporterMessage* msg = new csReporterMessage ();
    msg->severity = severity;
    msg->id = csStrNew (msgId);
    msg->description = csStrNew (buf);
    CS::Threading::RecursiveMutexScopedLock lock (mutex);
    messages.Push (msg);
    if (listeners.GetSize () == 0 && (severity == CS_REPORTER_SEVERITY_ERROR
    	|| severity == CS_REPORTER_SEVERITY_BUG))
    {
      csPrintf ("%s\n", buf);
    }
  }
}
Exemple #3
0
csPtr<iReporterIterator> csReporter::GetMessageIterator ()
{
  CS::Threading::RecursiveMutexScopedLock lock (mutex);
  csReporterIterator* it = new csReporterIterator ();
  size_t i;
  for (i = 0 ; i < messages.GetSize () ; i++)
  {
    csReporterMessage* msg = new csReporterMessage ();
    msg->severity = messages[i]->severity;
    msg->id = csStrNew (messages[i]->id);
    msg->description = csStrNew (messages[i]->description);
    it->messages.Push (msg);
  }
  return csPtr<iReporterIterator> (it);
}
Exemple #4
0
char* cswinGetErrorMessage (HRESULT code)
{
  wchar_t* retW = cswinGetErrorMessageW (code);
  char* ret = csStrNew (retW);
  delete[] retW;
  return ret;
}
Exemple #5
0
void csTextureWrapper::SetTextureClass (const char* className)
{
  if (handle) 
    handle->SetTextureClass (className);
  else
  {
    delete[] texClass;
    texClass = csStrNew (className);
  }
}
Exemple #6
0
csTextureWrapper::csTextureWrapper (const csTextureWrapper &t) :
  iBase(), scfImplementationType (this), engine (t.engine),
  flags(CS_TEXTURE_3D)
{
  handle = t.handle;
  image = t.image;
  keep_image = t.keep_image;
  if (!handle)
    texClass = csStrNew (t.texClass);
  else
    texClass = 0;

  keyColorDirty = true;
}
Exemple #7
0
  CS::Debug::ProfileCounter* Profiler::GetProfileCounter (const char* countername)
  {
    ProfileCounter* counter = 0;
    size_t index = allCounters.FindKey (csArrayCmp<ProfileCounter* , csString> (countername, CounterFindFun));

    if (index == csArrayItemNotFound)
    {
      //Allocate a new one
      counter = counterAllocator.Alloc ();
      counter->counterName = csStrNew (countername);
      allCounters.Push (counter);
    }
    else
    {
      counter = allCounters[index];
    }

    return counter;
  }
Exemple #8
0
void G2DTestSystemDriver::WriteCenteredWrapped (int mode, int dy, int &h, 
						int fg, int bg, 
						const char *format, ...)
{
  if (!font) return;

  csString text;
  va_list arg;

  va_start (arg, format);
  text.FormatV (format, arg);
  va_end (arg);

  int y = 0, w = myG2D->GetWidth ();
  int fW, fH;
  font->GetMaxSize (fW, fH);

  switch (mode)
  {
    case 0: // centered by Y
      y = dy + myG2D->GetHeight () / 2;
      break;
    case 1: // from top
      y = dy;
      break;
    case 2: // from bottom
      y = dy + (myG2D->GetHeight () - 1 - fH);
      break;
  }

  h = 0;

  int sW, sH;
  font->GetDimensions (" ", sW, sH);

  // break text so that it completely fits onto the screen.
  int lw = -sW;
  int maxLH = fH;
  char* line = csStrNew (text);
  char* p = line;
  csString drawLine;

  while (p && *p)
  {
    char* space = strchr (p, ' ');
    if (space != 0)
      *space = 0;
    int tW, tH;
    font->GetDimensions (p, tW, tH);
    if (lw + tW + sW >= w)
    {
      WriteCentered (1, y + h, fg, bg, (drawLine.GetData ()) + 1);
      drawLine.Clear ();
      drawLine << ' ' << p;
      //p = space + 1;
      lw = 0;
      h += maxLH;
      maxLH = MAX(fH, tH);
    }
    else
    {
      lw += tW + sW;
      drawLine << ' ' << p;
      maxLH = MAX(maxLH, tH);
    }
    if (space != 0) p = space + 1; else p = 0;
  }
  WriteCentered (1, y + h, fg, bg, (drawLine.GetData ()) + 1);
  h += maxLH;
  delete[] line;
}