Beispiel #1
0
/* 
In the event of prev naming a file, not a link (so that there is no last link),
prev[0] == '\0'.

Also searchs for the ${PROFILE_BIN_DIR}, which is the *first* directory on the
link chain containing a readable file "is-profile-bin". If this is not found,
profile_bin_dir[0] == 0.
*/
static int follow_links(char *prev, char *profile_bin_dir, size_t n) {
    int no_links = 1;
    char *cur = malloc(n), *next = malloc(n), *basename;
    profile_bin_dir[0] = '\0';
    hit_strlcpy(cur, prev, n);
    for (;;) {
        /* look for "is-profile-bin" marker */
        if (profile_bin_dir[0] == '\0') {

            splitpath(cur, &basename);
            if (basename != cur) {
                hit_strlcpy(profile_bin_dir, cur, n);
                hit_strlcat(profile_bin_dir, "/is-profile-bin", n);
                if (access(profile_bin_dir, R_OK) == 0) {
                    hit_strlcpy(profile_bin_dir, cur, n);
                } else {
                    profile_bin_dir[0] = '\0';
                }
                basename[-1] = '/'; /* reassemble the path */
            }
        }
        if (resolvelink(cur, next, n) == -1) break;
        no_links = 0;
        hit_strlcpy(prev, cur, n);
        hit_strlcpy(cur, next, n);
    }
    free(cur);
    free(next);
    if (no_links) {
        prev[0] = '\0';
    }
    return (errno == EINVAL) ? 0 : -1;
}
Beispiel #2
0
void subinvdadd(short m,short n, signed char *in,signed char *topout,
		signed char *botout)
  {long i,height;
    signed char *x2d,*x2dp1,*toprow,*botrow;
    int charac;

 //   printf("startinversedadd\n");
 //   printarray(pwrof2(m),16,in);
    if(m == 0) return;

    height = pwrof2(m-1);

    initdaddarr(m-1,n,topout); //initialize arrays
    initdaddarr(m-1,n,botout);

    for(i=0;i<height;i++)
	{x2d = in +2*i*n;
	 x2dp1 = in +(2*i+1)*n;
	 botrow = botout + n*i;
	 toprow = topout + n*i;
   //      printrows(n,i,botrow,toprow,x2d,x2dp1);
	 splitpath(n,i,botrow,toprow,x2d,x2dp1);
    //     printrows(n,i,botrow,toprow,x2d,x2dp1);
    //     charac = getchar();
   //      printarray(pwrof2(m-1),16,botout);
   //      printarray(pwrof2(m-1),16,topout);
	 }

     subinvdadd(m-1,n,botout,in+(height*n)/2,in);
     subinvdadd(m-1,n,topout,in+ (3*height*n)/2,in+height*n);
     }
Beispiel #3
0
/* Like readlink, but returns the absolute path name of the link.
   Does zero-terminate the buffer (and returns either 0 or -1). */
static int resolvelink(const char *path, char *buf, size_t n) {
    char *base;
    size_t nread;
    nread = readlink(path, buf, n - 1);
    if (nread == -1) return -1;
    buf[nread] = '\0';
    if (debug) fprintf(stderr, "%sreadlink=%s -> %s\n", debug_header, path, buf);
    if (buf[0] == '/') {
        /* symlink was absolute, we are done */
        return 0;
    } else {
        /* prepend dirname(path) and read the link again */
        hit_strlcpy(buf, path, n);
        splitpath(buf, &base);
        if (base == buf) {
            fprintf(stderr, "%sASSERTION FAILED, LINE %d\n", debug_header, __LINE__);
            return -1;
        }
        base[-1] = '/';
        nread = readlink(path, base, n - (base - buf) - 1);
        if (nread == -1) return -1;
        base[nread] = '\0';
        return 0;
    }
}
Beispiel #4
0
char *basename(const char *path, char *base)
{
  char *dir, *file;
  char *ptr, *point;
  size_t sz = 0;
  if (!path || !base)
    return 0;
  if(!strlen(path))
    return 0;
  dir = new char[strlen(path)];
  file = new char[strlen(path)];
  splitpath(path, dir, strlen(path), file, strlen(path));
  point = stristr(file, ".");
  ptr = file;
  if(point != 0) 
  {
    while (ptr++ != point)
      sz++;
  } 
  else 
  {
    sz = strlen(file);
  }
  memcpy (base, file, sz);
  base[sz] = '\0';
  delete [] dir;
  delete [] file;
  return base;
}
Beispiel #5
0
void
TLJPak::dump_filetable(std::ostream& out)
{
  std::string pathpart, filepart;
  splitpath(filename, pathpart, filepart);

  out << "filename \"" << filepart << "\"" << std::endl;
  out << "files" << std::endl;
  for(int i = 0; i < int(files.size()); ++i)
    {
      if (files[i].is_file())
        {
          out << "{" << std::endl;
          out << "    index      " << i << std::endl;
          //out << "    pathname \"" << files[i].pathname << "\"" << std::endl;
          out << "    pathnames  ";
          if (files[i].guesses.empty())
            {
              out << "\"" << files[i].pathname << "\"" << std::endl;
            }
          else
            {
              for(unsigned int j = 0; j < files[i].guesses.size(); ++j)
                out << "\"" << files[i].guesses[j] << "\" ";
              out << std::endl;
            }
          out << "    filesize   " << files[i].filesize << std::endl;
          out << "    filetype   \"" << filetype2string(files[i].filetype) << "\"" << std::endl;
          out << "}" << std::endl;
        }
    }
  out << "$" << std::endl;
}
Beispiel #6
0
static Dir*
xdirstat0(char **path, int (*namecmp)(char *, char *), char *err)
{
	char *base, *name;
	Dir *d, *t;
	int n, i;

	if(d = dirstat(*path))
		return d;
	if(!splitpath(*path, &base, &name))
		return nil;
	if((n = xdirread0(&base, namecmp, &t)) < 0)
		goto out;
	for(i=0; i<n; i++){
		if(namecmp(t[i].name, name))
			continue;
		free(*path); *path = conspath(base, t[i].name);
		d = xdirdup(&t[i], 1);
		goto out;
	}
	werrstr("%s", err);
out:
	free(base);
	free(name);
	return d;
}
Beispiel #7
0
void geninvdadd(short rowcount,short length,signed char *data)
{   short i,lowercount,uppercount;
    signed char *x2d,*x2dp1;
    if(rowcount == 1) return;
    lowercount = rowcount/2;
    uppercount = rowcount - lowercount;

    for(i=0; i<lowercount; i++) //set pointers to rows of drift 2 i and 2 i + 1
    {   x2d = data + length*getposition(i,lowercount);
        x2dp1 = data +length*(lowercount + getposition(i,uppercount));

        splitpath(length,i,x2d,x2dp1); //solve for the drift i rows in
        // the lower and upper blocks
    }

    if(lowercount != uppercount)  //if blocks are different sizes, solve for
        //top row of upper block
    {   x2dp1 = data + (rowcount-1)*length;
        topsolve(length,lowercount,x2d,x2dp1);
    }

    geninvdadd(lowercount,length,data);  //invert lower block sums
    geninvdadd(uppercount,length,data+length*lowercount);//invert upper block sums

}
Beispiel #8
0
/* reads the userfiles in the dir */
int File_Select()
{
    char *utemp[10];
    int ui = 0;
    i = 0;

    /* loop to read the files */
    printf(" reading userfiles...");

    for (x = 0; x < gl.gl_pathc; x++)
    {
        char temp_gl[80];

        strcpy(temp_gl, gl.gl_pathv[x]);
        ui = splitpath(utemp, temp_gl);
        sprintf(U_File, "%s\n", utemp[ui]);

        userfile = fopen(gl.gl_pathv[x], "rt");
        if (!userfile)
            exit(1);

        Info_Gather();
        fclose(userfile);
    }

    maxuser = i;
    /* loop end here......... */

    printf("Done!\n read total of %i user-records\nThanks for using PC-TOP gftpd remote.\n", i);

    return 0;
}
Beispiel #9
0
void construct_file_names() {
	char drive[MAX_DRIVE], dir[MAX_DIR], fname[MAX_FNAME], fext[MAX_EXT]; //, s[_MAX_FNAME];
	splitpath( inputFileName, drive, dir, fname, fext );

	int t = strlen(fname)-1;
	fname[t] = '2';
	makepath( inputFileName2, drive, dir, fname, "clb" );
	fname[t] = '3';
	makepath( inputFileName3, drive, dir, fname, "clb" );
	fname[t] = '4';
	makepath( inputFileName4, drive, dir, fname, "clb" );
	fname[t] = '5';
	makepath( inputFileName5, drive, dir, fname, "clb" );
	fname[t] = 'm';
	makepath( outputFileName, drive, dir, fname, "flt" );

	logfile->debug( "исходные файлы:" );
	logfile->debug( inputFileName );
	logfile->debug( inputFileName2 );
	logfile->debug( inputFileName3 );
	logfile->debug( inputFileName4 );
	logfile->debug( inputFileName5 );

	logfile->debug( "файл результата:" );
	logfile->debug( outputFileName );
	return;
}
Beispiel #10
0
bool WEXPORT WFileName::makeDir() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    if( strlen( _x.dir ) > 0 ) {
        return( mkdir( _x.dir, 0755 ) == 0 );
    }
    return( true );
}
Beispiel #11
0
bool WEXPORT WFileName::setCWD() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    if( strlen( _x.dir ) > 0 ) {
        return( chdir( _x.dir ) == 0 );
    }
    return( true );
}
Beispiel #12
0
int main(){
	char drive[MAX_DRIVE], dir[MAX_DIR], fname[MAX_FNAME], ext[MAX_EXT], path[MAX_PATH];
	splitpath(test,drive,dir,fname,ext);
	printf("test  : %s\n",test);
	printf("drive : %s\n",drive);
	printf("dir   : %s\n",dir);
	printf("fname : %s\n",fname);
	printf("ext   : %s\n",ext);
}
Beispiel #13
0
const char* WEXPORT WFileName::dir( bool slash ) const
{
    if( slash ) {
        _splitpath( *this, NULL, _x.dir, NULL, NULL );
    } else {
        splitpath( *this, NULL, _x.dir, NULL, NULL, PATHSEP_STR );
    }
    return( _x.dir );
}
Beispiel #14
0
int
main (int argc, const char *argv[])
{
  if (argc < 2)
    return -1;

  str parent, filename;

  parentpath (parent, filename, str (argv[1]));

    warn << parent << "\n";
    warn << filename << "\n";

  return 0;

  vec<str> out;
  splitpath (out, argv[1]);
  str foo;

  while (out.size () > 0 && (foo = out.pop_front ()))
    warn << foo << "\n";
  return 0;

  str path (argv[1]);
  
  //  vec<str> out;
  static rxx r ("^(.*)/([^/]+)$");
  //  static rxx r ("^/*([^/]+)(/.*)?$");

  //  static rxx r ("^s%/[^/]*$%%");
  //   static rxx pathsplit ("^/*([^/]+)(/.*)?$");

  warn << "path: " << path << "\n";

  // path = path/r;


  if (r.search (path))
    {

      if (r.len(1) != -1)
	warn << r[1] << " -> ";
      if (r.len(2) != -1)
	warn << r[2] << "\n";
      warn << "r[0]: " << r[0] << "\n";
    }

  warn << split (&out, "/", path) << "\n";  
  for (unsigned int i=0; i< out.size(); i++)
    warn << out[i] << "\n";

  return 0;

}
Beispiel #15
0
char *makepath (char fullpath [], char const *absolute, char const *relative) 

{
	char const *stack [FILE_DIR_MAX] = 
	{
		(char *)(0)
	};
	char buffer1 [FILENAME_MAX];
	char buffer2 [FILENAME_MAX];
	size_t limit = sizeof (stack);
	size_t level = 0;

#ifdef CMASSOC_SAFEMODE

	if (fullpath == (char *) (0)) 
	{
		return (fullpath);
	}
	if (absolute == (char *) (0)) 
	{
		return (fullpath);
	}
	if (relative == (char *) (0)) 
	{
		return (fullpath);
	}

#endif

	level = splitpath (level, limit, stack, strcpy (buffer1, absolute));
	level = splitpath (level, limit, stack, strcpy (buffer2, relative));
	limit = mergepath (level, limit, stack);
	strcpy (fullpath, stack [0]);
	for (level = 1; level < limit; level++) 
	{
		strcat (fullpath, PATH_S_EXTENDER);
		strcat (fullpath, stack [level]);
	}
	return (fullpath);
}
void findpath(char const *filename, char *fullpathname) // return full pathnames
{
    char fname[FILE_MAX_FNAME];
    char ext[FILE_MAX_EXT];
    char temp_path[FILE_MAX_PATH];

    splitpath(filename ,nullptr,nullptr,fname,ext);
    makepath(temp_path,""   ,"" ,fname,ext);

    if (checkcurdir && access(temp_path,0) == 0)   // file exists
    {
        strcpy(fullpathname,temp_path);
        return;
    }

    strcpy(temp_path,filename);   // avoid side effect changes to filename

    if (temp_path[0] == SLASHC || (temp_path[0] && temp_path[1] == ':'))
    {
        if (access(temp_path,0) == 0)   // file exists
        {
            strcpy(fullpathname,temp_path);
            return;
        }
        else
        {
            splitpath(temp_path ,nullptr,nullptr,fname,ext);
            makepath(temp_path,""   ,"" ,fname,ext);
        }
    }
    fullpathname[0] = 0;                         // indicate none found
    _searchenv(temp_path,"PATH",fullpathname);
    if (fullpathname[0] != 0)                    // found it!
    {
        if (strncmp(&fullpathname[2],SLASHSLASH,2) == 0) // stupid klooge!
        {
            strcpy(&fullpathname[3],temp_path);
        }
    }
}
static int get_system_info(void)
{
//  struct perfctr_info info;
  struct wininfo win_hwinfo;
  int tmp;
//  float mhz;
  HMODULE hModule;
  DWORD len;
  long i = 0;

  /* Path and args */
  hModule = GetModuleHandle(NULL); // current process
  len = GetModuleFileName(hModule,_papi_hwi_system_info.exe_info.fullname,PAPI_MAX_STR_LEN);
  if (len) splitpath(_papi_hwi_system_info.exe_info.fullname, _papi_hwi_system_info.exe_info.name);
  else return(PAPI_ESYS);

  DBG((stderr, "Executable is %s\n",_papi_hwi_system_info.exe_info.name));
  DBG((stderr, "Full Executable is %s\n",_papi_hwi_system_info.exe_info.fullname));

  /* Hardware info */
  if (!init_hwinfo(&win_hwinfo))
    return(PAPI_ESYS);

  _papi_hwi_system_info.hw_info.ncpu = win_hwinfo.ncpus;
  _papi_hwi_system_info.hw_info.nnodes = win_hwinfo.nnodes;
  _papi_hwi_system_info.hw_info.totalcpus = win_hwinfo.total_cpus;

  _papi_hwi_system_info.hw_info.vendor = win_hwinfo.vendor;
  _papi_hwi_system_info.hw_info.revision = (float)win_hwinfo.revision;
  strcpy(_papi_hwi_system_info.hw_info.vendor_string,win_hwinfo.vendor_string);

  _papi_hwi_system_info.hw_info.model = win_hwinfo.model;
  strcpy(_papi_hwi_system_info.hw_info.model_string,win_hwinfo.model_string);

  _papi_hwi_system_info.num_cntrs = win_hwinfo.nrctr;
  _papi_hwi_system_info.num_gp_cntrs = _papi_hwi_system_info.num_cntrs;

  _papi_hwi_system_info.hw_info.mhz = (float)win_hwinfo.mhz; 

  tmp = _papi_hwd_get_memory_info(&_papi_hwi_system_info.mem_info, (int)win_hwinfo.vendor);
  if (tmp)
    return(tmp);

  /* Setup presets */

  tmp = setup_all_presets(&win_hwinfo);
  if (tmp)
    return(tmp);

  return(PAPI_OK);
}
/*--------------------------------------------------------------------------*/
static char *getPathFilename(const char *fullfilename)
{
    char *path = NULL;
    if (fullfilename)
    {
        char* drv  = os_strdup(fullfilename);
        char* dir  = os_strdup(fullfilename);
        char* name = os_strdup(fullfilename);
        char* ext  = os_strdup(fullfilename);

        path = os_strdup(fullfilename);

        if (drv && dir && name && ext && path)
        {
            splitpath(fullfilename, FALSE, drv, dir, name, ext);

            if (strcmp(drv, "") == 0)
            {
                strcpy(path, dir);
            }
            else
            {
                strcpy(path, drv);
                strcat(path, dir);
            }
        }

        if (drv)
        {
            FREE(drv);
            drv = NULL;
        }
        if (dir)
        {
            FREE(dir);
            dir = NULL;
        }
        if (name)
        {
            FREE(name);
            name = NULL;
        }
        if (ext)
        {
            FREE(ext);
            ext = NULL;
        }
    }
    return path;
}
/*--------------------------------------------------------------------------*/
static char *getFilenameWithExtension(const char *fullfilename)
{
    char *filename = NULL;
    if (fullfilename)
    {
        char* drv  = os_strdup(fullfilename);
        char* dir  = os_strdup(fullfilename);
        char* name = os_strdup(fullfilename);
        char* ext  = os_strdup(fullfilename);

        filename = os_strdup(fullfilename);

        if (drv && dir && name && ext && filename)
        {
            splitpath(fullfilename, FALSE, drv, dir, name, ext);

            if (strcmp(ext, "") == 0)
            {
                strcpy(filename, name);
            }
            else
            {
                strcpy(filename, name);
                strcat(filename, ext);
            }
        }

        if (drv)
        {
            FREE(drv);
            drv = NULL;
        }
        if (dir)
        {
            FREE(dir);
            dir = NULL;
        }
        if (name)
        {
            FREE(name);
            name = NULL;
        }
        if (ext)
        {
            FREE(ext);
            ext = NULL;
        }
    }
    return filename;
}
Beispiel #20
0
bool WEXPORT WFileName::makeDir() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    if( strlen( _x.dir ) > 0 ) {
        unsigned olddrive;
        if( setdrive( _x.drive, &olddrive ) ) {
            int ret = mkdir( _x.dir );
            unsigned total;
            _dos_setdrive( olddrive, &total );
            return( ret == 0 );
        }
        return( false );
    }
    return( true );
}
Beispiel #21
0
bool RageMovieTexture::GetFourCC( RString fn, RString &handler, RString &type )
{
	RString ignore, ext;
	splitpath( fn, ignore, ignore, ext);
	if( !ext.CompareNoCase(".mpg") ||
		!ext.CompareNoCase(".mpeg") ||
		!ext.CompareNoCase(".mpv") ||
		!ext.CompareNoCase(".mpe") )
	{
		handler = type = "MPEG";
		return true;
	}
	if( !ext.CompareNoCase(".ogv") )
	{
		handler = type = "Ogg";
		return true;
	}

	//Not very pretty but should do all the same error checking without iostream
#define HANDLE_ERROR(x) { \
		LOG->Warn( "Error reading %s: %s", fn.c_str(), x ); \
		handler = type = ""; \
		return false; \
	}

	RageFile file;
	if( !file.Open(fn) )
		HANDLE_ERROR("Could not open file.");
	if( !file.Seek(0x70) )
		HANDLE_ERROR("Could not seek.");
	type = "    ";
	if( file.Read((char *)type.c_str(), 4) != 4 )
		HANDLE_ERROR("Could not read.");
	ForceToAscii( type );
	
	if( file.Seek(0xBC) != 0xBC )
		HANDLE_ERROR("Could not seek.");
	handler = "    ";
	if( file.Read((char *)handler.c_str(), 4) != 4 )
		HANDLE_ERROR("Could not read.");
	ForceToAscii( handler );

	return true;
#undef HANDLE_ERROR
}
Beispiel #22
0
bool WEXPORT WFileName::setCWD() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    unsigned olddrive;
    if( setdrive( _x.drive, &olddrive ) ) {
        if( strlen( _x.dir ) > 0 ) {
            int ret = chdir( _x.dir );
            if( ret == 0 ) {
                return TRUE;
            }
            unsigned total;
            _dos_setdrive( olddrive, &total );
            return FALSE;
        }
        return TRUE;
    }
    return FALSE;
}
Beispiel #23
0
char *filename(char *path, char *file)
{
  char *dir, *fname;
  size_t sz = 0;
  if (!path || !file)
    return 0;
  if(!strlen(path))
    return 0;
  dir = new char[strlen(path)];
  fname = new char[strlen(path)];
  splitpath(path, dir, strlen(path), fname, strlen(path));
  sz = strlen(fname);
  memcpy (file, fname, sz);
  file[sz] = '\0';
  delete[] dir;
  delete[] fname;
  return file;
}
CharacterManager::CharacterManager()
{
	// Register with Lua.
	{
		Lua *L = LUA->Get();
		lua_pushstring( L, "CHARMAN" );
		this->PushSelf( L );
		lua_settable( L, LUA_GLOBALSINDEX );
		LUA->Release( L );
	}

	for( unsigned i=0; i<m_pCharacters.size(); i++ )
		SAFE_DELETE( m_pCharacters[i] );
	m_pCharacters.clear();

	vector<RString> as;
	GetDirListing( CHARACTERS_DIR "*", as, true, true );
	StripCvsAndSvn( as );
	StripMacResourceForks( as );

	bool FoundDefault = false;
	for( unsigned i=0; i<as.size(); i++ )
	{
		RString sCharName, sDummy;
		splitpath(as[i], sDummy, sCharName, sDummy);
		sCharName.MakeLower();

		if( sCharName.CompareNoCase("default")==0 )
			FoundDefault = true;

		Character* pChar = new Character;
		if( pChar->Load( as[i] ) )
			m_pCharacters.push_back( pChar );
		else
			delete pChar;
	}
	
	if( !FoundDefault )
		RageException::Throw( "'Characters/default' is missing." );

	// If FoundDefault, then we're not empty. -Chris
//	if( m_pCharacters.empty() )
//		RageException::Throw( "Couldn't find any character definitions" );
}
Beispiel #25
0
static int resolve_link_in_textfile(char *filename, char *out, size_t n) {
    FILE *f;
    size_t m;
    char *s, *containing_dir;
    char buf[PATH_MAX];
    if ((f = fopen(filename, "r")) == NULL) { line = __LINE__; return -1; }
    if (fgets(out, n, f) == NULL) { 
        fclose(f);
        errno = ENAMETOOLONG; line = __LINE__;
        return -1;
    }
    fclose(f);
    m = strlen(out);
    if (out[m - 1] == '\n') out[m - 1] = '\0';
    if (out[0] != '/') {
        /* path is relative to file's realpath() location */
        splitpath(filename, &s);
        if (filename != s) {
            char oldchar = s[0];

            /* resolve the realpath containing the text file */
            s[0] = '\0';
            containing_dir = realpath(filename, NULL);
            s[0] = oldchar;
            if (containing_dir == NULL) { line = __LINE__; return -1; }


            m = hit_strlcpy(buf, out, PATH_MAX);
            if (m >= PATH_MAX) { free(containing_dir); line = __LINE__; return -1; }

            m = hit_strlcpy(out, containing_dir, n);
            free(containing_dir);
            if (m >= n) { line = __LINE__; return -1; }
            if (out[m - 1] != '/') {
                out[m] = '/';
                m++;
            }
            n -= m;
            m = hit_strlcpy(out + m, buf, n);
            if (m >= n) { line = __LINE__; return -1; }
        }
    }
    return 0;
}
Beispiel #26
0
static	void	parsefile (const char *file, dki_t **listp, int sub_before)
{
	char	path[MAX_PATHSIZE+1];
	dki_t	*dkp;

	/* file arg contains path ? ... */
	file = splitpath (path, sizeof (path), file);	/* ... then split of */

	if ( is_keyfilename (file) )	/* plain file name looks like DNS key file ? */
	{
		if ( (dkp = dki_read (path, file)) )	/* read DNS key file ... */
#if defined (USE_TREE) && USE_TREE
			dki_tadd (listp, dkp, sub_before);		/* ... and add to tree */
#else
			dki_add (listp, dkp);		/* ... and add to list */
#endif
		else
			error ("error parsing %s: (%s)\n", file, dki_geterrstr());
	}
Beispiel #27
0
/* Given a path, split it into two pieces:
   the parent directory path and the filename.

   Examples:

   path      parent   filename
   "/"       "/"      ""
   "/a"      "/"      "a"
   "/a/"     "/"      "a"
   "/a/b"    "/a"     "b"
   "/a/b/c"  "/a/b"   "c"
 */
static void
parentpath (str &parent, str &filename, str inpath)
{
  vec<str> ppv;
  parent = str ("/");
  filename = str ("");

  splitpath (ppv, inpath);

  if (ppv.size () == 0)
    return;

  filename = ppv.pop_back ();
  if (ppv.size () == 0)
    return;

  // What a non-intuitive way to do concatenation!
  parent = strbuf () << "/" << join (str("/"), ppv);
}
Beispiel #28
0
  BINLINE BFile BFile::createTempFile(const wstring& suffix, const wstring& postfix) {
    char fnameBuf[L_tmpnam] = {0};
    tmpnam(fnameBuf);
    wstring path = fromUtf8(fnameBuf);
    wstring dir, name;
    splitpath(path, dir, name);
    wstringstream wss;
    bool nameEndsWithDot = name.size() != 0 && name.find_last_of(L'.') == name.size()-1;
    bool postfixStartsWithDot = postfix.find(L'.') == 0;
    wss << dir << suffix << name;
    if (nameEndsWithDot && postfixStartsWithDot) {
      wss << postfix.substr(1);
    }
    else {
      wss << postfix;
    }

    return BFile(wss.str());
  }
Beispiel #29
0
CString Font::GetFontName( CString sFileName )
{
	CString sOrig = sFileName;

	CString sDir, sFName, sExt;
	splitpath( sFileName, sDir, sFName, sExt );
	sFileName = sFName;

	/* If it ends in an extension, remove it. */
	static Regex drop_ext( "\\....$" );
	if( drop_ext.Compare(sFileName) )
		sFileName.erase( sFileName.size()-4 );

	/* If it ends in a resolution spec, remove it. */
	CStringArray asMatch;
	static Regex ResSpec( "( \\(res [0-9]+x[0-9]+\\))$" );
	if( ResSpec.Compare(sFileName, asMatch) )
		sFileName.erase(sFileName.size()-asMatch[0].size());

	/* If it ends in a dimension spec, remove it. */
	static Regex DimSpec( "( [0-9]+x[0-9]+)$" );
	if( DimSpec.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in texture hints, remove them. */
	static Regex Hints( "( \\([^\\)]+\\))$" );
	if( Hints.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in a page name, remove it. */
	static Regex PageName("( \\[.+\\])$");
	if( PageName.Compare( sFileName, asMatch ) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	TrimRight( sFileName );

	if( sFileName.empty() )
		RageException::Throw( "Can't parse font filename \"%s\"", sOrig.c_str() );

	sFileName.MakeLower();
	return sFileName;
}
int main(int argc, char **argv)
{
    char *name, c;

    if (argc <= 0)
        exit(-1);

    name = splitpath(argv[0]);
    
    if (strcmp(name, "lower") == 0)
        while ((c = getchar()) != EOF)
            putchar(tolower(c));
    else if (strcmp(name, "upper") == 0)
        while ((c = getchar()) != EOF)
            putchar(toupper(c));
    else {
        printf("Unknown name. I'm confused.\n");
        exit(-1);
    }
    return EXIT_SUCCESS;
}