FAUST compiler  0.9.9.6b8
Functions
enrobage.hh File Reference
#include <stdio.h>
#include <string.h>
#include <string>
#include <fstream>
#include <iostream>
Include dependency graph for enrobage.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void copyFirstHalf (FILE *file, FILE *dst)
void copySecondHalf (FILE *file, FILE *dst)
void copyZeroHalf (FILE *file, FILE *dst)
void copyFile (FILE *file, FILE *dst)
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 streamCopyUntilEnd (istream &src, ostream &dst)
 Copy src to dst until end.
void streamCopy (istream &src, ostream &dst)
 Copy src to dst.
ifstream * open_arch_stream (const char *filename)
 Try to open an architecture file searching in various directories.
FILE * fopensearch (const char *filename, string &fullpath)
 Try to open the file <filename> searching in various directories.
bool check_file (const char *filename)
 Check if a file exists.
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 "."

Function Documentation

bool check_file ( const char *  filename)

Check if a file exists.

Returns:
true if the file exist, false otherwise

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;
}

Here is the caller graph for this function:

void copyFile ( FILE *  file,
FILE *  dst 
)
void copyFirstHalf ( FILE *  file,
FILE *  dst 
)
void copySecondHalf ( FILE *  file,
FILE *  dst 
)
void copyZeroHalf ( FILE *  file,
FILE *  dst 
)
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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

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 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;
}

Here is the call graph for this function:

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 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;
}

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
    }
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function: