enrobage.cpp File Reference

#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>
Include dependency graph for enrobage.cpp:
This graph shows which files directly or indirectly include this file:

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 Documentation

#define DIR_SEPARATOR   '/'

filebasename returns the basename of a path.

(adapted by kb from basename.c)

Parameters:
[in] The path to parse.
Returns:
The last component of the given path.

Definition at line 311 of file enrobage.cpp.

#define IS_DIR_SEPARATOR ( ch   )     ((ch) == DIR_SEPARATOR)

Definition at line 323 of file enrobage.cpp.

Referenced by filebasename().


Function Documentation

static void buildFullPathname ( string &  fullpath,
const char *  filename 
) [static]

Build a full pathname of <filename>.

<fullpath> = <currentdir>/<filename>

Definition at line 224 of file enrobage.cpp.

References FAUST_PATH_MAX, and isAbsolutePathname().

Referenced by fopensearch().

00225 {
00226     char    old[FAUST_PATH_MAX];
00227 
00228     if (isAbsolutePathname(filename)) {
00229         fullpath = filename;
00230     } else {
00231         fullpath = getcwd (old, FAUST_PATH_MAX);
00232         fullpath += '/';
00233         fullpath += filename;
00234     }
00235 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool check_file ( const char *  filename  ) 

Check if a file exists.

Returns:
true if the file exist, false otherwise

Definition at line 132 of file enrobage.cpp.

Referenced by process_cmdline().

00133 {
00134     FILE* f = fopen(filename, "r");
00135     
00136     if (f == NULL) {
00137         fprintf(stderr, "faust: "); perror(filename);
00138     } else {
00139         fclose(f);
00140     }
00141     return f != NULL;
00142 }

Here is the caller graph for this function:

const char* filebasename ( const char *  name  ) 

Definition at line 329 of file enrobage.cpp.

References IS_DIR_SEPARATOR.

Referenced by copyFaustSources(), and printfaustlisting().

00330 {
00331 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
00332     /* Skip over the disk name in MSDOS pathnames. */
00333     if (isalpha(name[0]) && name[1] == ':') 
00334         name += 2;
00335 #endif
00336 
00337     const char* base;
00338     for (base = name; *name; name++)
00339     {
00340         if (IS_DIR_SEPARATOR (*name))
00341         {
00342             base = name + 1;
00343         }
00344     }
00345     return base;
00346 }

Here is the caller graph for this function:

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 182 of file enrobage.cpp.

References FAUST_PATH_MAX.

00183 {
00184     int         err;
00185     char        olddirbuffer[FAUST_PATH_MAX];
00186     char        newdirbuffer[FAUST_PATH_MAX];
00187     
00188     char*       olddir = getcwd (olddirbuffer, FAUST_PATH_MAX);
00189     if (chdir(dir.c_str()) == 0) {
00190         if (chdir(path) == 0) {            
00191             FILE* f = fopen(filename, "r");
00192             fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX);
00193             fullpath += '/';
00194             fullpath += filename;
00195             err = chdir(olddir);
00196             return f;
00197         }
00198     }
00199     err = chdir(olddir);
00200     return 0;
00201 }

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 173 of file enrobage.cpp.

References fopenat().

00174 {
00175     return fopenat(fullpath, dir.c_str(), filename);
00176 }

Here is the call graph for this function:

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 149 of file enrobage.cpp.

References FAUST_PATH_MAX.

Referenced by fopenat(), and fopensearch().

00150 {
00151     int         err; 
00152     char        olddirbuffer[FAUST_PATH_MAX];
00153     char        newdirbuffer[FAUST_PATH_MAX];
00154     
00155     char*       olddir = getcwd (olddirbuffer, FAUST_PATH_MAX);
00156 
00157     if (chdir(dir) == 0) {           
00158         FILE* f = fopen(filename, "r");
00159         fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX);
00160         fullpath += '/';
00161         fullpath += filename;
00162         err = chdir(olddir);
00163         return f;
00164     }
00165     err = chdir(olddir);
00166     return 0;
00167 }

Here is the caller graph for this function:

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 266 of file enrobage.cpp.

References buildFullPathname(), fopenat(), gFaustDirectory, gFaustSuperDirectory, gFaustSuperSuperDirectory, and gMasterDirectory.

Referenced by SourceReader::parse().

00267 {   
00268     FILE* f;
00269 
00270 
00271     if ((f = fopen(filename, "r"))) { 
00272         buildFullPathname(fullpath, filename); 
00273         return f;
00274     }
00275     if ((f = fopenat(fullpath, gMasterDirectory, filename))) { 
00276         return f;
00277     }
00278     if ((f = fopenat(fullpath, gFaustDirectory, "architecture", filename))) { 
00279         return f;
00280     }
00281     if ((f = fopenat(fullpath, gFaustSuperDirectory, "architecture", filename))) { 
00282         return f;
00283     }
00284     if ((f = fopenat(fullpath, gFaustSuperSuperDirectory, "architecture", filename))) { 
00285         return f;
00286     }
00287 #ifdef INSTALL_PREFIX
00288     if ((f = fopenat(fullpath, INSTALL_PREFIX "/lib/faust", filename))) { 
00289         return f;
00290     }
00291 #endif
00292     if ((f = fopenat(fullpath, "/usr/local/lib/faust", filename))) { 
00293         return f;
00294     }
00295     if ((f = fopenat(fullpath, "/usr/lib/faust", filename))) { 
00296         return f;
00297     }
00298     return 0;
00299 }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isAbsolutePathname ( const string &  filename  )  [static]

Test absolute pathname.

Definition at line 208 of file enrobage.cpp.

Referenced by buildFullPathname().

00209 {
00210     //test windows absolute pathname "x:xxxxxx"
00211     if (filename.size()>1 && filename[1] == ':') return true;
00212 
00213     // test unix absolute pathname "/xxxxxx"
00214     if (filename.size()>0 && filename[0] == '/') return true;
00215 
00216     return false;
00217 }

Here is the caller graph for this function:

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 #ifdef INSTALL_PREFIX
00100     err = chdir(old);
00101     if (chdir(INSTALL_PREFIX "/lib/faust")==0) {
00102         ifstream* f = new ifstream();
00103         f->open(filename); 
00104         if (f->good()) return f; else delete f;
00105     }
00106 #endif
00107     err = chdir(old);
00108     if (chdir("/usr/local/lib/faust")==0) {
00109         ifstream* f = new ifstream();
00110         f->open(filename); 
00111         if (f->good()) return f; else delete f;
00112     }
00113     err = chdir(old);
00114     if (chdir("/usr/lib/faust")==0) {
00115         ifstream* f = new ifstream();
00116         f->open(filename); 
00117         if (f->good()) return f; else delete f;
00118     }
00119     
00120     return 0;
00121 }

Here is the caller graph for this function:

void streamCopy ( istream &  src,
ostream &  dst 
)

Copy src to dst.

Definition at line 50 of file enrobage.cpp.

Referenced by main().

00051 { 
00052     string  s;
00053     while ( getline(src,s)) dst << s << endl;
00054 }

Here is the caller graph for this function:

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().

00042 { 
00043     string  s;
00044     while ( getline(src,s) && (s != until) ) dst << s << endl;
00045 }

Here is the caller graph for this function:

void streamCopyUntilEnd ( istream &  src,
ostream &  dst 
)

Copy src to dst until end.

Definition at line 59 of file enrobage.cpp.

Referenced by main().

00060 { 
00061     string  s;
00062     while ( getline(src,s) ) dst << s << endl;
00063 }

Here is the caller graph for this function:


Variable Documentation

Definition at line 103 of file main.cpp.

Definition at line 102 of file main.cpp.

Definition at line 101 of file main.cpp.

Definition at line 105 of file main.cpp.

Referenced by fopensearch(), and initFaustDirectories().

Generated on Thu Jul 15 16:15:38 2010 for FAUST compiler by  doxygen 1.6.3