49 for (
size_t i=0; i<s.size(); i++) {
50 if (s[i] !=
' ' && s[i] !=
'\t')
return false;
61 string::size_type l1 = oldstr.length();
62 string::size_type l2 = newstr.length();
64 string::size_type pos = str.find(oldstr);
65 while (pos != string::npos) {
66 str.replace(pos, l1, newstr);
67 pos = str.find(oldstr, pos + l2);
93 while (getline(src,s) &&
isBlank(s)) dst << s << endl;
96 if (s.find(
"/*")==string::npos) { dst << s << endl;
return; }
102 while (getline(src,s) && s.find(
"*/") == string::npos) {
104 if (s.find(exceptiontag) != string::npos)
remove=
true;
110 for (
unsigned int i=0; i<H.size(); i++) {
128 bool skip() {
while (
p<
N && isspace(
str[
p]) ) p++;
return true; }
129 bool parse(
const string& s) {
bool f;
if ((f = (
p ==
str.find(s,
p))))
p += s.length();
return f; }
134 if (c==
'<' | c==
'"') {
136 while (
p<
N && (
str[
p] !=
'>') && (
str[
p] !=
'"')) fname +=
str[
p++];
154 return Q.
parse(
"faust/");
167 void inject(ostream& dst,
const string fname)
175 cerr <<
"NOT FOUND " << fname << endl;
187 while ( getline(src,s) && (s != until) ) {
201 streamCopyUntil(src, dst,
"<<<FOBIDDEN LINE IN A FAUST ARCHITECTURE FILE>>>");
209 streamCopyUntil(src, dst,
"<<<FOBIDDEN LINE IN A FAUST ARCHITECTURE FILE>>>");
212 #define TRY_OPEN(filename) \
213 ifstream* f = new ifstream(); \
214 f->open(filename, ifstream::in); \
215 if (f->is_open()) return f; else delete f; \
228 char *envpath = getenv(
"FAUST_LIB_PATH");
230 if (chdir(envpath)==0) {
235 if ( (chdir(
gFaustDirectory.c_str())==0) && (chdir(
"architecture")==0) ) {
249 #ifdef INSTALL_PREFIX
251 if (chdir(INSTALL_PREFIX
"/lib64/faust")==0) {
255 if (chdir(INSTALL_PREFIX
"/include")==0) {
260 if (chdir(
"/usr/local/lib64/faust")==0) {
264 if (chdir(
"/usr/lib64/faust")==0) {
268 if (chdir(
"/usr/local/include")==0) {
272 if (chdir(
"/usr/include")==0) {
283 const char* start =
"file://";
284 if (strstr(filename, start) != NULL) {
285 return &filename[strlen(start)];
301 if (strstr(filename,
"file://") != 0) {
303 FILE* f = fopen(&filename[7],
"r");
308 cerr <<
"ERROR : cannot open file '" << filename <<
"' : " << strerror(errno) <<
"; for help type \"faust --help\"" << endl;
313 }
else if (strstr(filename,
"http://") != 0) {
317 cerr <<
"ERROR : unable to access URL '" << filename <<
"' : " <<
http_strerror() <<
"; for help type \"faust --help\"" << endl;
322 FILE* f = fopen(filename,
"r");
327 cerr <<
"ERROR : cannot open file '" << filename <<
"' : " << strerror(errno) <<
"; for help type \"faust --help\"" << endl;
337 static FILE*
fopenat(
string& fullpath,
const char* dir,
const char* filename)
345 if (chdir(dir) == 0) {
346 FILE* f = fopen(filename,
"r");
349 fullpath += filename;
362 static FILE*
fopenat(
string& fullpath,
const string& dir,
const char* filename)
364 return fopenat(fullpath, dir.c_str(), filename);
371 static FILE*
fopenat(
string& fullpath,
const string& dir,
const char* path,
const char* filename)
379 if (chdir(dir.c_str()) == 0) {
380 if (chdir(path) == 0) {
381 FILE* f = fopen(filename,
"r");
384 fullpath += filename;
399 if (filename.size()>1 && filename[1] ==
':')
return true;
402 if (filename.size()>0 && filename[0] ==
'/')
return true;
421 fullpath += filename;
431 FILE*
fopensearch(
const char* filename,
string& fullpath)
436 if ((f = fopen(filename,
"r"))) {
443 if ((envpath = getenv(
"FAUST_LIB_PATH")) && (f =
fopenat(fullpath, envpath, filename))) {
466 if ((f = fopen(filename,
"r"))) {
474 if ((f =
fopenat(fullpath, *i, filename))) {
486 if ((envpath = getenv(
"FAUST_LIB_PATH")) && (f =
fopenat(fullpath, envpath, filename))) {
498 #ifdef INSTALL_PREFIX
499 if ((f =
fopenat(fullpath, INSTALL_PREFIX
"/lib64/faust", filename))) {
503 if ((f =
fopenat(fullpath,
"/usr/local/lib64/faust", filename))) {
506 if ((f =
fopenat(fullpath,
"/usr/lib64/faust", filename))) {
521 #ifndef DIR_SEPARATOR
522 #define DIR_SEPARATOR '/'
526 #define HAVE_DOS_BASED_FILE_SYSTEM
527 #ifndef DIR_SEPARATOR_2
528 #define DIR_SEPARATOR_2 '\\'
533 #ifndef DIR_SEPARATOR_2
534 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
536 # define IS_DIR_SEPARATOR(ch) \
537 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
546 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
548 if (isalpha(name[0]) && name[1] ==
':')
553 for (base = name; *
name; name++)
571 const unsigned int size = (
const unsigned int)(base-name.c_str());
577 }
else if (size==1) {
581 for (
unsigned int i=0; i<size-1; i++) {
string gFaustSuperSuperDirectory
set< string > alreadyIncluded
Inject file fname into dst ostream if not already done.
bool isFaustInclude(const string &s, string &fname)
True if string s match '#include '.
void inject(ostream &dst, const string fname)
A minimalistic parser used to recognize '#include ' patterns when copying architecture fil...
const char * http_strerror()
void streamCopyUntil(istream &src, ostream &dst, const string &until)
Copy src to dst until specific line.
#define IS_DIR_SEPARATOR(ch)
ifstream * open_arch_stream(const char *filename)
Try to open an architecture file searching in various directories.
static string & replaceOccurences(string &str, const string &oldstr, const string &newstr)
Replace every occurrence of oldstr by newstr inside str.
void streamCopyLicense(istream &src, ostream &dst, const string &exceptiontag)
Copy or remove license header.
#define TRY_OPEN(filename)
bool filename(string &fname)
static bool isAbsolutePathname(const string &filename)
Test absolute pathname.
void streamCopyUntilEnd(istream &src, ostream &dst)
Copy src to dst until end.
static void buildFullPathname(string &fullpath, const char *filename)
Build a full pathname of .
static bool isBlank(const string &s)
Returns true is a line is blank (contains only white caracters)
const char * filebasename(const char *name)
returns a pointer on the basename part of name
bool check_url(const char *filename)
Check if an URL exists.
FILE * fopensearch(const char *filename, string &fullpath)
Try to open the file searching in various directories.
int http_fetch(const char *url_tmp, char **fileBuf)
void streamCopy(istream &src, ostream &dst)
Copy src to dst.
const char * name(Symbol *sym)
Returns the name of a symbol.
myparser(const string &s)
string filedirname(const string &name)
returns a string containing the dirname of name If no dirname, returns "."
static FILE * fopenat(string &fullpath, const char *dir, const char *filename)
Try to open the file '
/'.
const char * strip_start(const char *filename)
list< string > gImportDirList
bool parse(const string &s)
string gFaustSuperDirectory
static string & replaceClassName(string &str)
Used when copying architecture files to replace default mydsp class name with the user specified one...