|
FAUST compiler
0.9.9.6b8
|
#include "enrobage.hh"#include <vector>#include <string>#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 | |
| static bool | isBlank (const string &s) |
| Returns true is a line is blank (contains only white caracters) | |
| static string & | replaceOccurences (string &str, const string &oldstr, const string &newstr) |
| Replace every occurrence of oldstr by newstr inside str. | |
| static string & | replaceClassName (string &str) |
| Used when copying architecture files to replace default mydsp class name with the user specified one. | |
| void | streamCopyLicense (istream &src, ostream &dst, const string &exceptiontag) |
| Copy or remove license header. | |
| 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) |
| returns a pointer on the basename part of name | |
| string | filedirname (const string &name) |
| returns a string containing the dirname of name If no dirname, returns "." | |
Variables | |
| string | gFaustSuperSuperDirectory |
| string | gFaustSuperDirectory |
| string | gFaustDirectory |
| string | gMasterDirectory |
| string | gClassName |
| #define DIR_SEPARATOR '/' |
filebasename returns the basename of a path.
(adapted by kb from basename.c)
| [in] | The | path to parse. |
Definition at line 406 of file enrobage.cpp.
| #define IS_DIR_SEPARATOR | ( | ch | ) | ((ch) == DIR_SEPARATOR) |
Definition at line 418 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 312 of file enrobage.cpp.
References FAUST_PATH_MAX, and isAbsolutePathname().
Referenced by fopensearch().
{
char old[FAUST_PATH_MAX];
if (isAbsolutePathname(filename)) {
fullpath = filename;
} else {
fullpath = getcwd (old, FAUST_PATH_MAX);
fullpath += '/';
fullpath += filename;
}
}


| bool check_file | ( | const char * | filename | ) |
Check if a file exists.
Definition at line 220 of file enrobage.cpp.
Referenced by process_cmdline().
{
FILE* f = fopen(filename, "r");
if (f == NULL) {
fprintf(stderr, "faust: "); perror(filename);
} else {
fclose(f);
}
return f != NULL;
}

| const char* filebasename | ( | const char * | name | ) |
returns a pointer on the basename part of name
Definition at line 428 of file enrobage.cpp.
References IS_DIR_SEPARATOR, and name().
Referenced by copyFaustSources(), filedirname(), and printfaustlisting().
{
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over the disk name in MSDOS pathnames. */
if (isalpha(name[0]) && name[1] == ':')
name += 2;
#endif
const char* base;
for (base = name; *name; name++)
{
if (IS_DIR_SEPARATOR (*name))
{
base = name + 1;
}
}
return base;
}


| string filedirname | ( | const string & | name | ) |
returns a string containing the dirname of name If no dirname, returns "."
Definition at line 452 of file enrobage.cpp.
References filebasename().
Referenced by initFaustDirectories().
{
const char* base = filebasename(name.c_str());
const unsigned int size = base-name.c_str();
string dirname;
if (size==0) {
dirname += '.';
} else if (size==1) {
dirname += name[0];
} else {
for (unsigned int i=0; i<size-1; i++) {
dirname += name[i];
}
}
return dirname;
}


| 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 237 of file enrobage.cpp.
References FAUST_PATH_MAX.
Referenced by fopenat(), and fopensearch().
{
int err;
char olddirbuffer[FAUST_PATH_MAX];
char newdirbuffer[FAUST_PATH_MAX];
char* olddir = getcwd (olddirbuffer, FAUST_PATH_MAX);
if (chdir(dir) == 0) {
FILE* f = fopen(filename, "r");
fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX);
fullpath += '/';
fullpath += filename;
err = chdir(olddir);
return f;
}
err = chdir(olddir);
return 0;
}

| 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 261 of file enrobage.cpp.
References fopenat().
{
return fopenat(fullpath, dir.c_str(), filename);
}

| 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 270 of file enrobage.cpp.
References FAUST_PATH_MAX.
{
int err;
char olddirbuffer[FAUST_PATH_MAX];
char newdirbuffer[FAUST_PATH_MAX];
char* olddir = getcwd (olddirbuffer, FAUST_PATH_MAX);
if (chdir(dir.c_str()) == 0) {
if (chdir(path) == 0) {
FILE* f = fopen(filename, "r");
fullpath = getcwd (newdirbuffer, FAUST_PATH_MAX);
fullpath += '/';
fullpath += filename;
err = chdir(olddir);
return f;
}
}
err = chdir(olddir);
return 0;
}
| 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 358 of file enrobage.cpp.
References buildFullPathname(), fopenat(), gFaustDirectory, gFaustSuperDirectory, gFaustSuperSuperDirectory, and gMasterDirectory.
Referenced by SourceReader::parse().
{
FILE* f;
char* envpath;
if ((f = fopen(filename, "r"))) {
buildFullPathname(fullpath, filename);
return f;
}
if ((f = fopenat(fullpath, gMasterDirectory, filename))) {
return f;
}
if ((envpath = getenv("FAUST_LIB_PATH")) && (f = fopenat(fullpath, envpath, filename))) {
return f;
}
if ((f = fopenat(fullpath, gFaustDirectory, "architecture", filename))) {
return f;
}
if ((f = fopenat(fullpath, gFaustSuperDirectory, "architecture", filename))) {
return f;
}
if ((f = fopenat(fullpath, gFaustSuperSuperDirectory, "architecture", filename))) {
return f;
}
#ifdef INSTALL_PREFIX
if ((f = fopenat(fullpath, INSTALL_PREFIX "/lib/faust", filename))) {
return f;
}
#endif
if ((f = fopenat(fullpath, "/usr/local/lib/faust", filename))) {
return f;
}
if ((f = fopenat(fullpath, "/usr/lib/faust", filename))) {
return f;
}
return 0;
}


| static bool isAbsolutePathname | ( | const string & | filename | ) | [static] |
Test absolute pathname.
Definition at line 296 of file enrobage.cpp.
Referenced by buildFullPathname().
{
//test windows absolute pathname "x:xxxxxx"
if (filename.size()>1 && filename[1] == ':') return true;
// test unix absolute pathname "/xxxxxx"
if (filename.size()>0 && filename[0] == '/') return true;
return false;
}

| static bool isBlank | ( | const string & | s | ) | [static] |
Returns true is a line is blank (contains only white caracters)
Definition at line 44 of file enrobage.cpp.
Referenced by streamCopyLicense().
{
for (size_t i=0; i<s.size(); i++) {
if (s[i] != ' ' && s[i] != '\t') return false;
}
return true;
}

| ifstream* open_arch_stream | ( | const char * | filename | ) |
Try to open an architecture file searching in various directories.
Definition at line 148 of file enrobage.cpp.
References FAUST_PATH_MAX, gFaustDirectory, gFaustSuperDirectory, and gFaustSuperSuperDirectory.
Referenced by main(), and openArchFile().
{
char buffer[FAUST_PATH_MAX];
char* old = getcwd (buffer, FAUST_PATH_MAX);
int err;
{
ifstream* f = new ifstream();
f->open(filename, ifstream::in); if (f->is_open()) return f; else delete f;
}
char *envpath = getenv("FAUST_LIB_PATH");
if (envpath!=NULL) {
if (chdir(envpath)==0) {
ifstream* f = new ifstream();
f->open(filename, ifstream::in);
if (f->is_open()) return f; else delete f;
}
}
err = chdir(old);
if ( (chdir(gFaustDirectory.c_str())==0) && (chdir("architecture")==0) ) {
//cout << "enrobage.cpp : 'architecture' directory found in gFaustDirectory" << endl;
ifstream* f = new ifstream();
f->open(filename, ifstream::in);
if (f->good()) return f; else delete f;
}
err = chdir(old);
if ((chdir(gFaustSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) {
//cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperDirectory" << endl;
ifstream* f = new ifstream();
f->open(filename, ifstream::in);
if (f->good()) return f; else delete f;
}
err = chdir(old);
if ((chdir(gFaustSuperSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) {
//cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperSuperDirectory" << endl;
ifstream* f = new ifstream();
f->open(filename, ifstream::in);
if (f->good()) return f; else delete f;
}
#ifdef INSTALL_PREFIX
err = chdir(old);
if (chdir(INSTALL_PREFIX "/lib/faust")==0) {
ifstream* f = new ifstream();
f->open(filename);
if (f->good()) return f; else delete f;
}
#endif
err = chdir(old);
if (chdir("/usr/local/lib/faust")==0) {
ifstream* f = new ifstream();
f->open(filename);
if (f->good()) return f; else delete f;
}
err = chdir(old);
if (chdir("/usr/lib/faust")==0) {
ifstream* f = new ifstream();
f->open(filename);
if (f->good()) return f; else delete f;
}
return 0;
}

| static string& replaceClassName | ( | string & | str | ) | [static] |
Used when copying architecture files to replace default mydsp class name with the user specified one.
Definition at line 74 of file enrobage.cpp.
References gClassName, and replaceOccurences().
Referenced by streamCopy(), streamCopyUntil(), and streamCopyUntilEnd().
{
return replaceOccurences(str, "mydsp", gClassName);
}


| static string& replaceOccurences | ( | string & | str, |
| const string & | oldstr, | ||
| const string & | newstr | ||
| ) | [static] |
Replace every occurrence of oldstr by newstr inside str.
str is modified and returned as reference for convenience
Definition at line 56 of file enrobage.cpp.
Referenced by replaceClassName().
{
string::size_type l1 = oldstr.length();
string::size_type l2 = newstr.length();
string::size_type pos = str.find(oldstr);
while ( pos != string::npos) {
str.replace(pos, l1, newstr);
pos = str.find(oldstr, pos + l2);
}
return str;
}

| void streamCopy | ( | istream & | src, |
| ostream & | dst | ||
| ) |
Copy src to dst.
Definition at line 129 of file enrobage.cpp.
References replaceClassName().
Referenced by main().
{
string s;
while ( getline(src,s)) dst << replaceClassName(s) << endl;
}


| void streamCopyLicense | ( | istream & | src, |
| ostream & | dst, | ||
| const string & | exceptiontag | ||
| ) |
Copy or remove license header.
Architecture files can contain a header specifying the license. If this header contains an exception tag (for example "FAUST COMPILER EXCEPTION") it is an indication for the compiler to remove the license header from the resulting code. A header is the first non blank line that begins a comment.
Definition at line 86 of file enrobage.cpp.
References isBlank().
{
string s;
vector<string> H;
// skip blank lines
while (getline(src,s) && isBlank(s)) dst << s << endl;
// first non blank should start a comment
if (s.find("/*")==string::npos) { dst << s << endl; return; }
// copy the header into H
bool remove = false;
H.push_back(s);
while (getline(src,s) && s.find("*/")==string::npos) {
H.push_back(s);
if (s.find(exceptiontag) != string::npos) remove=true;
}
// copy the header unless explicitely granted to remove it
if (!remove) {
// copy the header
for (unsigned int i=0; i<H.size(); i++) {
dst << H[i] << endl;
}
dst << s << endl;
}
}

| void streamCopyUntil | ( | istream & | src, |
| ostream & | dst, | ||
| const string & | until | ||
| ) |
Copy src to dst until specific line.
Definition at line 120 of file enrobage.cpp.
References replaceClassName().
Referenced by main().
{
string s;
while ( getline(src,s) && (s != until) ) dst << replaceClassName(s) << endl;
}


| void streamCopyUntilEnd | ( | istream & | src, |
| ostream & | dst | ||
| ) |
Copy src to dst until end.
Definition at line 138 of file enrobage.cpp.
References replaceClassName().
Referenced by main().
{
string s;
while ( getline(src,s) ) dst << replaceClassName(s) << endl;
}


| string gClassName |
| string gFaustDirectory |
| string gFaustSuperDirectory |
| string gFaustSuperSuperDirectory |
| string gMasterDirectory |
Definition at line 105 of file main.cpp.
Referenced by fopensearch(), and initFaustDirectories().
1.8.0