- Added `include "dinges";' command, that is aware of Scytherdirs.
This commit is contained in:
parent
db8e72f37e
commit
08f705234b
@ -7,6 +7,7 @@
|
||||
#include "pheading.h"
|
||||
#include "memory.h"
|
||||
#include "tac.h"
|
||||
#include "switches.h"
|
||||
|
||||
/* tokens for language */
|
||||
#include "parser.h"
|
||||
@ -47,7 +48,38 @@ integer {digit}+
|
||||
text \"({ascii_char}|{escaped_char})*\"
|
||||
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;
|
||||
|
@ -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
|
||||
*
|
||||
* If reopener == NULL then we open a new file pointer, otherwise reopen this one.
|
||||
*/
|
||||
int
|
||||
openFileStdin (char *filename)
|
||||
FILE *
|
||||
openFileSearch (char *filename, FILE * reopener)
|
||||
{
|
||||
const char *separators = ":;\n";
|
||||
char *dirs;
|
||||
@ -139,10 +141,21 @@ openFileStdin (char *filename)
|
||||
}
|
||||
|
||||
// Now try to open it
|
||||
if (freopen (buffer, "r", stdin) != NULL)
|
||||
if (reopener != NULL)
|
||||
{
|
||||
if (freopen (buffer, "r", reopener) != NULL)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reopener = fopen (buffer, "r");
|
||||
if (reopener != NULL)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
free (buffer);
|
||||
return result;
|
||||
@ -152,7 +165,7 @@ openFileStdin (char *filename)
|
||||
|
||||
if (try (""))
|
||||
{
|
||||
return true;
|
||||
return reopener;
|
||||
}
|
||||
|
||||
// Now try the environment variable
|
||||
@ -164,7 +177,7 @@ openFileStdin (char *filename)
|
||||
// try this one
|
||||
if (try (dirs))
|
||||
{
|
||||
return true;
|
||||
return reopener;
|
||||
}
|
||||
// skip to next
|
||||
dirs = strpbrk (dirs, separators);
|
||||
@ -181,8 +194,22 @@ openFileStdin (char *filename)
|
||||
}
|
||||
|
||||
// Nope
|
||||
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
|
||||
/**
|
||||
|
@ -61,4 +61,6 @@ struct switchdata
|
||||
|
||||
extern struct switchdata switches; //!< pointer to switchdata structure
|
||||
|
||||
FILE *openFileSearch (char *filename, FILE * reopener);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user