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. More...
 
void streamCopyUntil (istream &src, ostream &dst, const string &until)
 Copy src to dst until specific line. More...
 
void streamCopyUntilEnd (istream &src, ostream &dst)
 Copy src to dst until end. More...
 
void streamCopy (istream &src, ostream &dst)
 Copy src to dst. More...
 
ifstream * open_arch_stream (const char *filename)
 Try to open an architecture file searching in various directories. More...
 
FILE * fopensearch (const char *filename, string &fullpath)
 Try to open the file <filename> searching in various directories. More...
 
const char * strip_start (const char *filename)
 
bool check_url (const char *filename)
 Check if an URL exists. More...
 
const char * filebasename (const char *name)
 returns a pointer on the basename part of name More...
 
string filedirname (const string &name)
 returns a string containing the dirname of name If no dirname, returns "." More...
 

Function Documentation

bool check_url ( const char *  filename)

Check if an URL exists.

Returns
true if the URL exist, false otherwise

Definition at line 296 of file enrobage.cpp.

References http_fetch(), and http_strerror().

Referenced by process_cmdline().

297 {
298  char* fileBuf = 0;
299 
300  // Tries to open as an URL for a local file
301  if (strstr(filename, "file://") != 0) {
302  // Tries to open as a regular file after removing 'file://'
303  FILE* f = fopen(&filename[7], "r");
304  if (f) {
305  fclose(f);
306  return true;
307  } else {
308  cerr << "ERROR : cannot open file '" << filename << "' : " << strerror(errno) << "; for help type \"faust --help\"" << endl;
309  return false;
310  }
311 
312  // Tries to open as a http URL
313  } else if (strstr(filename, "http://") != 0) {
314  if (http_fetch(filename, &fileBuf) != -1) {
315  return true;
316  } else {
317  cerr << "ERROR : unable to access URL '" << filename << "' : " << http_strerror() << "; for help type \"faust --help\"" << endl;
318  return false;
319  }
320  } else {
321  // Otherwise tries to open as a regular file
322  FILE* f = fopen(filename, "r");
323  if (f) {
324  fclose(f);
325  return true;
326  } else {
327  cerr << "ERROR : cannot open file '" << filename << "' : " << strerror(errno) << "; for help type \"faust --help\"" << endl;
328  return false;
329  }
330  }
331 }
const char * http_strerror()
int http_fetch(const char *url_tmp, char **fileBuf)

Here is the call graph for this function:

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

References IS_DIR_SEPARATOR, and name().

Referenced by copyFaustSources(), filedirname(), and printfaustlisting().

545 {
546 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
547  /* Skip over the disk name in MSDOS pathnames. */
548  if (isalpha(name[0]) && name[1] == ':')
549  name += 2;
550 #endif
551 
552  const char* base;
553  for (base = name; *name; name++)
554  {
555  if (IS_DIR_SEPARATOR (*name))
556  {
557  base = name + 1;
558  }
559  }
560  return base;
561 }
#define IS_DIR_SEPARATOR(ch)
Definition: enrobage.cpp:534
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98

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

References filebasename().

Referenced by initFaustDirectories().

569 {
570  const char* base = filebasename(name.c_str());
571  const unsigned int size = (const unsigned int)(base-name.c_str());
572  string dirname;
573 
574  if (size==0) {
575  dirname += '.';
576 
577  } else if (size==1) {
578  dirname += name[0];
579 
580  } else {
581  for (unsigned int i=0; i<size-1; i++) {
582  dirname += name[i];
583  }
584  }
585  return dirname;
586 }
const char * filebasename(const char *name)
returns a pointer on the basename part of name
Definition: enrobage.cpp:544
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98

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

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

Referenced by SourceReader::parse().

459 {
460  FILE* f;
461  char* envpath;
462 
463 
464  // search in current directory
465 
466  if ((f = fopen(filename, "r"))) {
467  buildFullPathname(fullpath, filename);
468  return f;
469  }
470 
471  // search file in user supplied directory path
472 
473  for (list< string >::iterator i = gImportDirList.begin(); i != gImportDirList.end(); i++) {
474  if ((f = fopenat(fullpath, *i, filename))) {
475  //std::cerr << "found file : " << fullpath << std::endl;
476  return f;
477  }
478  }
479 
480 
481  // search in default directories
482 
483  if ((f = fopenat(fullpath, gMasterDirectory, filename))) {
484  return f;
485  }
486  if ((envpath = getenv("FAUST_LIB_PATH")) && (f = fopenat(fullpath, envpath, filename))) {
487  return f;
488  }
489  if ((f = fopenat(fullpath, gFaustDirectory, "architecture", filename))) {
490  return f;
491  }
492  if ((f = fopenat(fullpath, gFaustSuperDirectory, "architecture", filename))) {
493  return f;
494  }
495  if ((f = fopenat(fullpath, gFaustSuperSuperDirectory, "architecture", filename))) {
496  return f;
497  }
498 #ifdef INSTALL_PREFIX
499  if ((f = fopenat(fullpath, INSTALL_PREFIX "/lib64/faust", filename))) {
500  return f;
501  }
502 #endif
503  if ((f = fopenat(fullpath, "/usr/local/lib64/faust", filename))) {
504  return f;
505  }
506  if ((f = fopenat(fullpath, "/usr/lib64/faust", filename))) {
507  return f;
508  }
509  return 0;
510 }
string gMasterDirectory
Definition: main.cpp:105
string gFaustSuperSuperDirectory
Definition: main.cpp:101
string gFaustDirectory
Definition: main.cpp:103
static void buildFullPathname(string &fullpath, const char *filename)
Build a full pathname of .
Definition: enrobage.cpp:412
static FILE * fopenat(string &fullpath, const char *dir, const char *filename)
Try to open the file '/'.
Definition: enrobage.cpp:337
list< string > gImportDirList
Definition: main.cpp:161
string gFaustSuperDirectory
Definition: main.cpp:102

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

References FAUST_PATH_MAX, gFaustDirectory, gFaustSuperDirectory, gFaustSuperSuperDirectory, and TRY_OPEN.

Referenced by inject(), main(), and openArchFile().

221 {
222  char buffer[FAUST_PATH_MAX];
223  char* old = getcwd (buffer, FAUST_PATH_MAX);
224  int err;
225 
226  TRY_OPEN(filename);
227 
228  char *envpath = getenv("FAUST_LIB_PATH");
229  if (envpath!=NULL) {
230  if (chdir(envpath)==0) {
231  TRY_OPEN(filename);
232  }
233  }
234  err = chdir(old);
235  if ( (chdir(gFaustDirectory.c_str())==0) && (chdir("architecture")==0) ) {
236  //cout << "enrobage.cpp : 'architecture' directory found in gFaustDirectory" << endl;
237  TRY_OPEN(filename);
238  }
239  err = chdir(old);
240  if ((chdir(gFaustSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) {
241  //cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperDirectory" << endl;
242  TRY_OPEN(filename);
243  }
244  err = chdir(old);
245  if ((chdir(gFaustSuperSuperDirectory.c_str())==0) && (chdir("architecture")==0) ) {
246  //cout << "enrobage.cpp : 'architecture' directory found in gFaustSuperSuperDirectory" << endl;
247  TRY_OPEN(filename);
248  }
249 #ifdef INSTALL_PREFIX
250  err = chdir(old);
251  if (chdir(INSTALL_PREFIX "/lib64/faust")==0) {
252  TRY_OPEN(filename);
253  }
254  err = chdir(old);
255  if (chdir(INSTALL_PREFIX "/include")==0) {
256  TRY_OPEN(filename);
257  }
258 #endif
259  err = chdir(old);
260  if (chdir("/usr/local/lib64/faust")==0) {
261  TRY_OPEN(filename);
262  }
263  err = chdir(old);
264  if (chdir("/usr/lib64/faust")==0) {
265  TRY_OPEN(filename);
266  }
267  err = chdir(old);
268  if (chdir("/usr/local/include")==0) {
269  TRY_OPEN(filename);
270  }
271  err = chdir(old);
272  if (chdir("/usr/include")==0) {
273  TRY_OPEN(filename);
274  }
275 
276  return 0;
277 }
string gFaustSuperSuperDirectory
Definition: main.cpp:101
string gFaustDirectory
Definition: main.cpp:103
#define TRY_OPEN(filename)
Definition: enrobage.cpp:212
string gFaustSuperDirectory
Definition: main.cpp:102
#define FAUST_PATH_MAX

Here is the caller graph for this function:

void streamCopy ( istream &  src,
ostream &  dst 
)

Copy src to dst.

Definition at line 199 of file enrobage.cpp.

References streamCopyUntil().

Referenced by inject(), and main().

200 {
201  streamCopyUntil(src, dst, "<<<FOBIDDEN LINE IN A FAUST ARCHITECTURE FILE>>>");
202 }
void streamCopyUntil(istream &src, ostream &dst, const string &until)
Copy src to dst until specific line.
Definition: enrobage.cpp:183

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

References isBlank().

88 {
89  string s;
90  vector<string> H;
91 
92  // skip blank lines
93  while (getline(src,s) && isBlank(s)) dst << s << endl;
94 
95  // first non blank should start a comment
96  if (s.find("/*")==string::npos) { dst << s << endl; return; }
97 
98  // copy the header into H
99  bool remove = false;
100  H.push_back(s);
101 
102  while (getline(src,s) && s.find("*/") == string::npos) {
103  H.push_back(s);
104  if (s.find(exceptiontag) != string::npos) remove=true;
105  }
106 
107  // copy the header unless explicitely granted to remove it
108  if (!remove) {
109  // copy the header
110  for (unsigned int i=0; i<H.size(); i++) {
111  dst << H[i] << endl;
112  }
113  dst << s << endl;
114  }
115 }
static bool isBlank(const string &s)
Returns true is a line is blank (contains only white caracters)
Definition: enrobage.cpp:48

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

References gInlineArchSwitch, inject(), isFaustInclude(), and replaceClassName().

Referenced by main(), streamCopy(), and streamCopyUntilEnd().

184 {
185  string s;
186  string fname;
187  while ( getline(src,s) && (s != until) ) {
188  if (gInlineArchSwitch && isFaustInclude(s, fname)) {
189  inject(dst, fname);
190  } else {
191  dst << replaceClassName(s) << endl;
192  }
193  }
194 }
bool gInlineArchSwitch
Definition: main.cpp:156
bool isFaustInclude(const string &s, string &fname)
True if string s match '#include '.
Definition: enrobage.cpp:149
void inject(ostream &dst, const string fname)
Definition: enrobage.cpp:167
static string & replaceClassName(string &str)
Used when copying architecture files to replace default mydsp class name with the user specified one...
Definition: enrobage.cpp:76

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

References streamCopyUntil().

Referenced by main().

208 {
209  streamCopyUntil(src, dst, "<<<FOBIDDEN LINE IN A FAUST ARCHITECTURE FILE>>>");
210 }
void streamCopyUntil(istream &src, ostream &dst, const string &until)
Copy src to dst until specific line.
Definition: enrobage.cpp:183

Here is the call graph for this function:

Here is the caller graph for this function:

const char* strip_start ( const char *  filename)

Definition at line 281 of file enrobage.cpp.

282 {
283  const char* start = "file://";
284  if (strstr(filename, start) != NULL) {
285  return &filename[strlen(start)];
286  } else {
287  return filename;
288  }
289 }