- Added `include "dinges";' command, that is aware of Scytherdirs.

This commit is contained in:
ccremers 2006-04-12 12:42:04 +00:00
parent db8e72f37e
commit 08f705234b
3 changed files with 69 additions and 8 deletions

View File

@ -7,6 +7,7 @@
#include "pheading.h" #include "pheading.h"
#include "memory.h" #include "memory.h"
#include "tac.h" #include "tac.h"
#include "switches.h"
/* tokens for language */ /* tokens for language */
#include "parser.h" #include "parser.h"
@ -47,7 +48,38 @@ integer {digit}+
text \"({ascii_char}|{escaped_char})*\" text \"({ascii_char}|{escaped_char})*\"
id @?({letter}|{digit}|[\^\-])+ id @?({letter}|{digit}|[\^\-])+
/* the "incl" state is used for picking up the name of an include file
*/
%x incl inclend
%% %%
include BEGIN(incl);
<incl>[ \t]*\" /* eat the whitespace */
<incl>[^\"]+ { /* got the include file name */
/* try to open, using scytherdirs environment variable as well. */
yyin = openFileSearch (yytext, NULL);
if (! yyin)
{
error ("Could not open include file %s.", yytext);
}
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE ));
BEGIN(INITIAL);
}
<inclend>\";? { /* eat the closing things */
BEGIN(INITIAL);
}
<INITIAL><<EOF>> {
yypop_buffer_state();
if (! YY_CURRENT_BUFFER )
{
yyterminate();
}
else
{
BEGIN(inclend);
}
}
"/*" { "/*" {
register int c; register int c;

View File

@ -92,12 +92,14 @@ switchesDone (void)
{ {
} }
//! Open a (protocol) file instead of stdin //! Open a (protocol) file.
/** /**
* Uses the environment variable SCYTHERDIR to also search for files * Uses the environment variable SCYTHERDIR to also search for files
*
* If reopener == NULL then we open a new file pointer, otherwise reopen this one.
*/ */
int FILE *
openFileStdin (char *filename) openFileSearch (char *filename, FILE * reopener)
{ {
const char *separators = ":;\n"; const char *separators = ":;\n";
char *dirs; char *dirs;
@ -139,9 +141,20 @@ openFileStdin (char *filename)
} }
// Now try to open it // Now try to open it
if (freopen (buffer, "r", stdin) != NULL) if (reopener != NULL)
{ {
result = true; if (freopen (buffer, "r", reopener) != NULL)
{
result = true;
}
}
else
{
reopener = fopen (buffer, "r");
if (reopener != NULL)
{
result = true;
}
} }
free (buffer); free (buffer);
@ -152,7 +165,7 @@ openFileStdin (char *filename)
if (try ("")) if (try (""))
{ {
return true; return reopener;
} }
// Now try the environment variable // Now try the environment variable
@ -164,7 +177,7 @@ openFileStdin (char *filename)
// try this one // try this one
if (try (dirs)) if (try (dirs))
{ {
return true; return reopener;
} }
// skip to next // skip to next
dirs = strpbrk (dirs, separators); dirs = strpbrk (dirs, separators);
@ -181,7 +194,21 @@ openFileStdin (char *filename)
} }
// Nope // Nope
return false; return NULL;
}
//! Open a (protocol) file instead of stdin
int
openFileStdin (char *filename)
{
if (openFileSearch (filename, stdin) == NULL)
{
return false;
}
else
{
return true;
}
} }
//! Process a single switch or generate help text //! Process a single switch or generate help text

View File

@ -61,4 +61,6 @@ struct switchdata
extern struct switchdata switches; //!< pointer to switchdata structure extern struct switchdata switches; //!< pointer to switchdata structure
FILE *openFileSearch (char *filename, FILE * reopener);
#endif #endif