1
0
Fork 0
flightgear/Makedir/makedir.cxx

120 lines
1.7 KiB
C++
Raw Normal View History

1998-10-28 19:39:33 +00:00
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
1998-10-02 21:40:56 +00:00
#include <stdio.h>
#include <sys/stat.h> // stat()
#include <unistd.h> // stat()
#include <string>
#include <Bucket/bucketutils.h>
1998-10-28 19:39:33 +00:00
#ifdef WIN32
#ifndef TRUE
#define FALSE 0
#define TRUE 1
1998-10-02 21:40:56 +00:00
#endif
1998-10-28 19:39:33 +00:00
char* PathDivider()
{
return "\\";
} // PathDivider
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
void ReplaceDivider( char* path )
{
char div = PathDivider()[0];
int i;
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
if ( ! path )
return;
if ( div == '/' )
return;
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
for ( i = 0; path[i]; i++ )
if ( path[i] == '/' )
path[i] = div;
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
} // ReplaceDivider
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
int Exists( char* path )
{
struct stat statbuff;
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
ReplaceDivider( path );
if ( path[strlen( path ) - 1] == ':' )
return TRUE;
if ( _stat( path, &statbuff ) != 0 )
return FALSE;
return TRUE;
} // Exists
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
void CreateDir( char* path )
{
if ( ! path || ! strlen( path ) )
return;
ReplaceDivider( path );
// see if the parent exists yet
int i; // looping index
string parent; // path to parent
parent = path;
for ( i = strlen( parent.c_str() )-1; i >= 0; i-- )
if ( parent[i] == PathDivider()[0] )
{
parent[i] = '\0';
break;
}
if ( ! Exists( parent.c_str() ) )
{
CreateDir( parent.c_str() );
}
1998-10-02 21:40:56 +00:00
1998-10-28 19:39:33 +00:00
if ( ! Exists( path ) )
{
if (mkdir(path, S_IRWXU) != 0 )
{
cout << "Could not create directory " << path << endl;
}else{
cout << "CreateDir: " << path << endl;
}
}
} // CreateDir
1998-10-02 21:40:56 +00:00
int main(int argc, char **argv)
{
string root;
if(argc != 2)
{
1998-10-28 19:39:33 +00:00
cout << "Makedir failed needs one argument\n";
1998-10-02 21:40:56 +00:00
return(10);
}
root = argv[1];
1998-10-28 19:39:33 +00:00
CreateDir(root.c_str());
1998-10-02 21:40:56 +00:00
return(0);
}
#else
int main(int argc, char **argv)
{
cout << "This program is intended to work with windoze\n";
cout << "Other platforms can use mkdir\n";
}
1998-10-28 19:39:33 +00:00
#endif // WIN32