#include "enrobage.hh"
#include <stdio.h>
#include <string.h>
#include <string>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include "compatibility.hh"
#include <climits>
Go to the source code of this file.
Defines | |
#define | DIR_SEPARATOR '/' |
filebasename returns the basename of a path. | |
#define | IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) |
Functions | |
void | streamCopyUntil (istream &src, ostream &dst, const string &until) |
Copy src to dst until specific line. | |
void | streamCopy (istream &src, ostream &dst) |
Copy src to dst. | |
void | streamCopyUntilEnd (istream &src, ostream &dst) |
Copy src to dst until end. | |
ifstream * | open_arch_stream (const char *filename) |
Try to open an architecture file searching in various directories. | |
bool | check_file (const char *filename) |
Check if a file exists. | |
static FILE * | fopenat (string &fullpath, const char *dir, const char *filename) |
Try to open the file '<dir>/<filename>'. | |
static FILE * | fopenat (string &fullpath, const string &dir, const char *filename) |
Try to open the file '<dir>/<filename>'. | |
static FILE * | fopenat (string &fullpath, const string &dir, const char *path, const char *filename) |
Try to open the file '<dir>/<path>/<filename>'. | |
static bool | isAbsolutePathname (const string &filename) |
Test absolute pathname. | |
static void | buildFullPathname (string &fullpath, const char *filename) |
Build a full pathname of <filename>. | |
FILE * | fopensearch (const char *filename, string &fullpath) |
Try to open the file <filename> searching in various directories. | |
const char * | filebasename (const char *name) |
Variables | |
string | gFaustSuperSuperDirectory |
string | gFaustSuperDirectory |
string | gFaustDirectory |
string | gMasterDirectory |
#define DIR_SEPARATOR '/' |
filebasename returns the basename of a path.
(adapted by kb from basename.c)
[in] | The | path to parse. |
Definition at line 298 of file enrobage.cpp.
#define IS_DIR_SEPARATOR | ( | ch | ) | ((ch) == DIR_SEPARATOR) |
Definition at line 310 of file enrobage.cpp.
Referenced by filebasename().
static void buildFullPathname | ( | string & | fullpath, | |
const char * | filename | |||
) | [static] |
Build a full pathname of <filename>.
<fullpath> = <currentdir>/<filename>
Definition at line 216 of file enrobage.cpp.
References FAUST_PATH_MAX, and isAbsolutePathname().
Referenced by fopensearch().
00217 { 00218 char old[FAUST_PATH_MAX]; 00219 00220 if (isAbsolutePathname(filename)) { 00221 fullpath = filename; 00222 } else { 00223 fullpath = getcwd (old, FAUST_PATH_MAX); 00224 fullpath += '/'; 00225 fullpath += filename; 00226 } 00227 }
bool check_file | ( | const char * | filename | ) |
Check if a file exists.
Definition at line 124 of file enrobage.cpp.
Referenced by process_cmdline().
00125 { 00126 FILE* f = fopen(filename, "r"); 00127 00128 if (f == NULL) { 00129 fprintf(stderr, "faust: "); perror(filename); 00130 } else { 00131 fclose(f); 00132 } 00133 return f != NULL; 00134 }
const char* filebasename | ( | const char * | name | ) |
Definition at line 316 of file enrobage.cpp.
References IS_DIR_SEPARATOR.
Referenced by copyFaustSources(), and printfaustlisting().
00317 { 00318 #if defined (HAVE_DOS_BASED_FILE_SYSTEM) 00319 /* Skip over the disk name in MSDOS pathnames. */ 00320 if (isalpha(name[0]) && name[1] == ':') 00321 name += 2; 00322 #endif 00323 00324 const char* base; 00325 for (base = name; *name; name++) 00326 { 00327 if (IS_DIR_SEPARATOR (*name)) 00328 { 00329 base = name + 1; 00330 } 00331 } 00332 return base; 00333 }
static FILE* fopenat | ( | string & | fullpath, | |
const string & | dir, | |||
const char * | path, | |||
const char * | filename | |||
) | [static] |
Try to open the file '<dir>/<path>/<filename>'.
If it succeed, it stores the full pathname of the file into <fullpath>
Definition at line 174 of file enrobage.cpp.
References FAUST_PATH_MAX.
00175 { 00176 int err; 00177 char olddirbuffer[FAUST_PATH_MAX]; 00178 char newdirbuffer[FAUST_PATH_MAX]; 00179 00180 char* olddir = getcwd (olddirbuffer, FAUST_PATH_MAX); 00181 if (chdir(dir.c_str()) == 0) { 00182 if (chdir(path) == 0) { 00183 FILE* f = fopen(filename, "r"); 00184 fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX); 00185 fullpath += '/'; 00186 fullpath += filename; 00187 err = chdir(olddir); 00188 return f; 00189 } 00190 } 00191 err = chdir(olddir); 00192 return 0; 00193 }
static FILE* fopenat | ( | string & | fullpath, | |
const string & | dir, | |||
const char * | filename | |||
) | [static] |
Try to open the file '<dir>/<filename>'.
If it succeed, it stores the full pathname of the file into <fullpath>
Definition at line 165 of file enrobage.cpp.
References fopenat().
00166 { 00167 return fopenat(fullpath, dir.c_str(), filename); 00168 }
static FILE* fopenat | ( | string & | fullpath, | |
const char * | dir, | |||
const char * | filename | |||
) | [static] |
Try to open the file '<dir>/<filename>'.
If it succeed, it stores the full pathname of the file into <fullpath>
Definition at line 141 of file enrobage.cpp.
References FAUST_PATH_MAX.
Referenced by fopenat(), and fopensearch().
00142 { 00143 int err; 00144 char olddirbuffer[FAUST_PATH_MAX]; 00145 char newdirbuffer[FAUST_PATH_MAX]; 00146 00147 char* olddir = getcwd (olddirbuffer, FAUST_PATH_MAX); 00148 00149 if (chdir(dir) == 0) { 00150 FILE* f = fopen(filename, "r"); 00151 fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX); 00152 fullpath += '/'; 00153 fullpath += filename; 00154 err = chdir(olddir); 00155 return f; 00156 } 00157 err = chdir(olddir); 00158 return 0; 00159 }
FILE* fopensearch | ( | const char * | filename, | |
string & | fullpath | |||
) |
Try to open the file <filename> searching in various directories.
If succesful place its full pathname in the string <fullpath>
Definition at line 258 of file enrobage.cpp.
References buildFullPathname(), fopenat(), gFaustDirectory, gFaustSuperDirectory, gFaustSuperSuperDirectory, and gMasterDirectory.
Referenced by SourceReader::parse().
00259 { 00260 FILE* f; 00261 00262 00263 if ((f = fopen(filename, "r"))) { 00264 buildFullPathname(fullpath, filename); 00265 return f; 00266 } 00267 if ((f = fopenat(fullpath, gMasterDirectory, filename))) { 00268 return f; 00269 } 00270 if ((f = fopenat(fullpath, gFaustDirectory, "architecture", filename))) { 00271 return f; 00272 } 00273 if ((f = fopenat(fullpath, gFaustSuperDirectory, "architecture", filename))) { 00274 return f; 00275 } 00276 if ((f = fopenat(fullpath, gFaustSuperSuperDirectory, "architecture", filename))) { 00277 return f; 00278 } 00279 if ((f = fopenat(fullpath, "/usr/local/lib/faust", filename))) { 00280 return f; 00281 } 00282 if ((f = fopenat(fullpath, "/usr/lib/faust", filename))) { 00283 return f; 00284 } 00285 return 0; 00286 }
static bool isAbsolutePathname | ( | const string & | filename | ) | [static] |
Test absolute pathname.
Definition at line 200 of file enrobage.cpp.
Referenced by buildFullPathname().
00201 { 00202 //test windows absolute pathname "x:xxxxxx" 00203 if (filename.size()>1 && filename[1] == ':') return true; 00204 00205 // test unix absolute pathname "/xxxxxx" 00206 if (filename.size()>0 && filename[0] == '/') return true; 00207 00208 return false; 00209 }
ifstream* open_arch_stream | ( | const char * | filename | ) |
Try to open an architecture file searching in various directories.
Definition at line 69 of file enrobage.cpp.
References FAUST_PATH_MAX, gFaustDirectory, gFaustSuperDirectory, and gFaustSuperSuperDirectory.
Referenced by main(), and openArchFile().
00070 { 00071 char buffer[FAUST_PATH_MAX]; 00072 char* old = getcwd (buffer, FAUST_PATH_MAX); 00073 int err; 00074 00075 { 00076 ifstream* f = new ifstream(); 00077 f->open(filename, ifstream::in); if (f->is_open()) return f; else delete f; 00078 } 00079 if ( (chdir(gFaustDirectory.c_str())==0) && (chdir("architecture")==0) ) { 00080 //cout << "enrobage.cpp : 'architecture' directory found in gFaustDirectory" << endl; 00081 ifstream* f = new ifstream(); 00082 f->open(filename, ifstream::in); 00083 if (f->good()) return f; else delete f; 00084 } 00085 err = chdir(old); 00086 if ((chdir(gFaustSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) { 00087 //cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperDirectory" << endl; 00088 ifstream* f = new ifstream(); 00089 f->open(filename, ifstream::in); 00090 if (f->good()) return f; else delete f; 00091 } 00092 err = chdir(old); 00093 if ((chdir(gFaustSuperSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) { 00094 //cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperSuperDirectory" << endl; 00095 ifstream* f = new ifstream(); 00096 f->open(filename, ifstream::in); 00097 if (f->good()) return f; else delete f; 00098 } 00099 err = chdir(old); 00100 if (chdir("/usr/local/lib/faust")==0) { 00101 ifstream* f = new ifstream(); 00102 f->open(filename); 00103 if (f->good()) return f; else delete f; 00104 } 00105 err = chdir(old); 00106 if (chdir("/usr/lib/faust")==0) { 00107 ifstream* f = new ifstream(); 00108 f->open(filename); 00109 if (f->good()) return f; else delete f; 00110 } 00111 00112 return 0; 00113 }
void streamCopy | ( | istream & | src, | |
ostream & | dst | |||
) |
Copy src to dst.
Definition at line 50 of file enrobage.cpp.
Referenced by main().
void streamCopyUntil | ( | istream & | src, | |
ostream & | dst, | |||
const string & | until | |||
) |
Copy src to dst until specific line.
Definition at line 41 of file enrobage.cpp.
Referenced by main().
void streamCopyUntilEnd | ( | istream & | src, | |
ostream & | dst | |||
) |
Copy src to dst until end.
Definition at line 59 of file enrobage.cpp.
Referenced by main().
string gFaustDirectory |
string gFaustSuperDirectory |
string gFaustSuperSuperDirectory |
string gMasterDirectory |
Definition at line 101 of file main.cpp.
Referenced by fopensearch(), and initFaustDirectories().