From: curt Date: Fri, 2 Oct 1998 21:40:56 +0000 (+0000) Subject: Initial revision. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2e1f12b96e83878f3bc38e39945be69aeb1241c2;p=flightgear.git Initial revision. --- diff --git a/Makedir/Makefile.am b/Makedir/Makefile.am new file mode 100644 index 000000000..c83672258 --- /dev/null +++ b/Makedir/Makefile.am @@ -0,0 +1,7 @@ +bin_PROGRAMS = makedir + +makedir_SOURCES = makedir.cxx + +makedir_LDADD = $(top_builddir)/Lib/Bucket/libBucket.a + +INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib diff --git a/Makedir/makedir.cxx b/Makedir/makedir.cxx new file mode 100644 index 000000000..96563cf1a --- /dev/null +++ b/Makedir/makedir.cxx @@ -0,0 +1,120 @@ +#include // isspace() +#include // atoi() +#include // rint() +#include +#include +#include // stat() +#include // stat() + +#include + +#include + +#ifdef __CYGWIN32__ +# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag +(NHV) +#endif // __CYGWIN32__ + +#ifdef __CYGWIN32__ + +// return the file path name ( foo/bar/file.ext = foo/bar ) +static void extract_path (char *in, char *base) { + int len, i; + + len = strlen (in); + strcpy (base, in); + + i = len - 1; + while ( (i >= 0) && (in[i] != '/') ) { + i--; + } + + base[i] = '\0'; +} + + +// Make a subdirectory +static int my_mkdir (char *dir) { + struct stat stat_buf; + int result; + + printf ("mk_dir() "); + + result = stat (dir, &stat_buf); + + if (result != 0) { + MKDIR (dir); + result = stat (dir, &stat_buf); + if (result != 0) { + printf ("problem creating %s\n", dir); + } else { + printf ("%s created\n", dir); + } + } else { + printf ("%s already exists\n", dir); + } + + return (result); +} + +#endif // __CYGWIN32__ + + +void scenery_dir( const string& dir ) { + struct stat stat_buf; + char base_path[256], file[256], exfile[256]; +#ifdef __CYGWIN32__ + char tmp_path[256]; +#endif + string command; + FILE *fd; + fgBUCKET p; + int result; + + cout << "Dir = " + dir + "\n"; + + // stat() directory and create if needed + result = stat(dir.c_str(), &stat_buf); + if ( result != 0 ) { + cout << "Stat error need to create directory\n"; + +#ifndef __CYGWIN32__ + + command = "mkdir -p " + dir + "\n"; + system( command.c_str() ); + +#else // __CYGWIN32__ + + // Cygwin crashes when trying to output to node file + // explicitly making directory structure seems OK on Win95 + + extract_path (base_path, tmp_path); + + dir = tmp_path; + if (my_mkdir ( dir.c_str() )) { exit (-1); } + + dir = base_path; + if (my_mkdir ( dir.c_str() )) { exit (-1); } + +#endif // __CYGWIN32__ + + } else { + // assume directory exists + cout << " Allready Exists !\n"; + } +} + +int main(int argc, char **argv) +{ + string root; + + if(argc != 2) + { + cout << "Makedir failed\n"; + return(10); + } + root = argv[1]; + scenery_dir(root); + + return(0); +}