ADMB Documentation  11.1.1913
 All Classes Files Functions Variables Typedefs Friends Defines
makesub.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: makesub.cpp 1906 2014-04-17 20:52:49Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 #include <adstring.hpp>
00013 //#include <fstream.h>
00014 #include <stdlib.h>
00015 #if !defined(_MSC_VER)
00016   #include <dirent.h>
00017   #include <sys/stat.h>
00018 #endif
00019 #if defined(__BORLANDC__)
00020 #  include <dir.h>
00021 #endif
00022 #if defined(_WIN32)
00023 #  include <windows.h>
00024 #else
00025 #  include <unistd.h>
00026 #endif
00027 
00028 #if !defined(_MSC_VER)
00029 #include <iostream>
00030 using namespace std;
00031 #include <memory.h>
00032 #include <fcntl.h>
00033 #include <sys/stat.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036 #endif
00037 
00042 int ad_chdir(const char * s)
00043 {
00044 #if defined(_WIN32)
00045   return SetCurrentDirectory(s);
00046 #else
00047   return chdir(s);
00048 #endif
00049 }
00050 
00055 void ad_getcd(const adstring& _s)
00056 {
00057   adstring& s=(adstring&) (_s);
00058 #if defined(_WIN32)
00059   char tmp[101];
00060   tmp[0]='\0';
00061   GetCurrentDirectory(100,tmp);
00062   s=tmp;
00063 #else
00064   char tmp[101];
00065   tmp[0]='\0';
00066   getcwd(tmp,100);
00067   s=adstring(tmp);
00068 #endif
00069 }
00070 
00075 int ad_mkdir(const char * s)
00076 {
00077 #if defined(_WIN32)
00078   return CreateDirectory(s,NULL);
00079 #else
00080   return mkdir(s,S_IREAD | S_IWRITE);
00081 #endif
00082 }
00083 
00088 int make_sub_directory(const char * s)
00089 {
00090   adstring currdir;
00091   adstring currdir1;
00092   ad_getcd(currdir);
00093   //const int len=100;
00094   //char dirname[len+1];
00095 #if defined(_WIN32)
00096   int ierr=SetCurrentDirectory(s);
00097 #else
00098   DIR * ierr=opendir(s);
00099 #endif
00100   if (!ierr) // NULL means failed
00101   {
00102     ad_getcd(currdir);
00103     return ad_mkdir(s);
00104   }
00105   else
00106   {
00107     ad_getcd(currdir1);
00108     ad_chdir(currdir);
00109     ad_getcd(currdir1);
00110     return 1;
00111   }
00112 }
00113