Module: rflat.cpp

Flat functions
 

RFindFilecstring RFindFile(cstring fname,cstring prefDir)

Find the file in a number of places
The environment var "RACER" may be used to find Racer's base directory
(mainly used for development)
Returns the filename as it SHOULD be, if not found

RFindDircstring RFindDir(cstring prefDir)

Returns the directory full path
The environment var "RACER" may be used to find Racer's base directory
(mainly used for development)



/*
 * Racer - flat functions
 * 06-12-00: Created!
 * (c) Dolphinity/RvG
 */

#include <racer/racer.h>
#include <qlib/debug.h>
#pragma hdrstop
DEBUG_ENABLE

cstring RFindFile(cstring fname,cstring prefDir)
// Find the file in a number of places
// The environment var "RACER" may be used to find Racer's base directory
// (mainly used for development)
// Returns the filename as it SHOULD be, if not found
{
  static char buf[256];
  char *env;

  // Try preferred directory
  sprintf(buf,"%s/%s",prefDir,fname);
  if(QFileExists(buf))
    goto do_ok;

  // Try preffered directory in relation to $RACER
  env=getenv("RACER");
  if(env)
  {
    sprintf(buf,"%s/%s/%s",env,prefDir,fname);
    if(QFileExists(buf))
      goto do_ok;
  }

  // Not found anywhere, return filename as it SHOULD be
  if(env)
  {
    // We have an env var; base it on that
    sprintf(buf,"%s/%s/%s",env,prefDir,fname);
    goto do_ok;
  } else
  {
    // Joe user PC probably; assume we're in Racer's home directory
    sprintf(buf,"%s/%s",prefDir,fname);
    goto do_ok;
  }
 do_ok:
//qdbg("RFindFile(%s,%s)=%s\n",fname,prefDir,buf);
  return buf;
}

cstring RFindDir(cstring prefDir)
// Returns the directory full path
// The environment var "RACER" may be used to find Racer's base directory
// (mainly used for development)
{
  static char buf[256];
  char *env;

  // Try preffered directory in relation to $RACER
  env=getenv("RACER");
  if(env)
  {
    // We have an env var; base it on that
    sprintf(buf,"%s/%s",env,prefDir);
  } else
  {
    // Joe user PC probably; assume we're in Racer's home directory
    sprintf(buf,"%s",prefDir);
  }
  return buf;
}