NEW: Scyther input files can now specify any command-line option.
By specifying: option "--X=Y"; in the Scyther input file, command-line options can be directly integrated. For example, one can specify: option "--one-role-per-agent";
This commit is contained in:
parent
d88402998e
commit
35045adf69
20
src/parser.y
20
src/parser.y
@ -22,6 +22,8 @@
|
|||||||
#include "tac.h"
|
#include "tac.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "switches.h"
|
||||||
|
|
||||||
struct tacnode* spdltac;
|
struct tacnode* spdltac;
|
||||||
|
|
||||||
@ -65,6 +67,8 @@ List findMacroDefinition(Symbol s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
%token <symb> ID
|
%token <symb> ID
|
||||||
|
%token <str> TEXT
|
||||||
|
|
||||||
%token PROTOCOL
|
%token PROTOCOL
|
||||||
%token ROLE
|
%token ROLE
|
||||||
%token READT
|
%token READT
|
||||||
@ -85,9 +89,10 @@ List findMacroDefinition(Symbol s)
|
|||||||
%token HASHFUNCTION
|
%token HASHFUNCTION
|
||||||
%token KNOWS
|
%token KNOWS
|
||||||
%token TRUSTED
|
%token TRUSTED
|
||||||
|
%token OPTION
|
||||||
|
%token MACRO
|
||||||
%token MATCH
|
%token MATCH
|
||||||
%token NOT
|
%token NOT
|
||||||
%token MACRO
|
|
||||||
|
|
||||||
%type <tac> spdlcomplete
|
%type <tac> spdlcomplete
|
||||||
%type <tac> spdlrep
|
%type <tac> spdlrep
|
||||||
@ -109,6 +114,7 @@ List findMacroDefinition(Symbol s)
|
|||||||
%type <tac> roleref
|
%type <tac> roleref
|
||||||
%type <tac> knowsdecl
|
%type <tac> knowsdecl
|
||||||
%type <tac> macrodecl
|
%type <tac> macrodecl
|
||||||
|
%type <tac> options
|
||||||
|
|
||||||
%type <value> singular
|
%type <value> singular
|
||||||
|
|
||||||
@ -161,6 +167,18 @@ spdl : UNTRUSTED termlist ';'
|
|||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
| options
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
options : OPTION TEXT optclosing
|
||||||
|
{
|
||||||
|
// Process 'option' as command-line options.
|
||||||
|
process_switch_buffer($2);
|
||||||
|
$$ = NULL;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
roles : /* empty */
|
roles : /* empty */
|
||||||
|
@ -178,6 +178,23 @@ function { return FUNCTION; }
|
|||||||
hashfunction { return HASHFUNCTION; }
|
hashfunction { return HASHFUNCTION; }
|
||||||
knows { return KNOWS; }
|
knows { return KNOWS; }
|
||||||
trusted { return TRUSTED; }
|
trusted { return TRUSTED; }
|
||||||
|
option { return OPTION; }
|
||||||
|
{text} {
|
||||||
|
if (strlen(yytext) >= 2)
|
||||||
|
{
|
||||||
|
// Make a copy without the surrounding
|
||||||
|
// double-quotes.
|
||||||
|
// TODO: Allow to unescape quotes inside string if
|
||||||
|
// needed later.
|
||||||
|
yylval.str = strndup(yytext+1,strlen(yytext)-2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If only one character, then simply copy
|
||||||
|
yylval.str = strdup(yytext);
|
||||||
|
}
|
||||||
|
return TEXT;
|
||||||
|
}
|
||||||
{id} {
|
{id} {
|
||||||
yylval.symb = mkstring(yytext);
|
yylval.symb = mkstring(yytext);
|
||||||
return ID;
|
return ID;
|
||||||
|
@ -48,7 +48,7 @@ char *lastfoundprefix = NULL;
|
|||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
void process_environment (void);
|
void process_environment (void);
|
||||||
void process_switches (int commandline);
|
int process_switches (int commandline);
|
||||||
|
|
||||||
//! Init switches
|
//! Init switches
|
||||||
/**
|
/**
|
||||||
@ -1556,13 +1556,16 @@ switcher (const int process, int index, int commandline)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the option is not recognized, it means a file name.
|
// If the option is not recognized, it means a file name.
|
||||||
|
// But we only consider this for the command line
|
||||||
|
if (commandline)
|
||||||
|
{
|
||||||
if (!process)
|
if (!process)
|
||||||
{
|
{
|
||||||
helptext ("FILE", "input file ('-' for stdin)");
|
helptext ("FILE", "input file ('-' for stdin)");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!strcmp (this_arg, "-") && commandline)
|
if (!strcmp (this_arg, "-"))
|
||||||
{
|
{
|
||||||
// '-' input: Leave input to stdin
|
// '-' input: Leave input to stdin
|
||||||
}
|
}
|
||||||
@ -1586,12 +1589,18 @@ switcher (const int process, int index, int commandline)
|
|||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Unrecognized option.
|
||||||
|
error ("Could not parse argument \"%s\".\n", this_arg);
|
||||||
|
}
|
||||||
|
|
||||||
// Now show the environment variables
|
// Now show the environment variables
|
||||||
if (!process)
|
if (!process)
|
||||||
{
|
{
|
||||||
printf
|
printf
|
||||||
("\nThere are two environment variables that influence the behaviour of Scyther.\n");
|
("\nThere are two environment variables that influence the behaviour of the Scyther command-line tool.\n");
|
||||||
printf
|
printf
|
||||||
(" SCYTHERFLAGS Put any default command-line options here, syntax as on the command line.\n");
|
(" SCYTHERFLAGS Put any default command-line options here, syntax as on the command line.\n");
|
||||||
printf
|
printf
|
||||||
@ -1603,22 +1612,22 @@ switcher (const int process, int index, int commandline)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Process environment
|
//! Process a single buffer as a potential switch
|
||||||
|
/**
|
||||||
|
* This is a public function. It is used for the environment variables but also for the in-specification defines.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
process_environment (void)
|
process_switch_buffer (char *buf)
|
||||||
{
|
{
|
||||||
char *flags;
|
if (buf != NULL)
|
||||||
|
|
||||||
flags = getenv ("SCYTHERFLAGS");
|
|
||||||
if (flags != NULL)
|
|
||||||
{
|
{
|
||||||
int slen;
|
int slen;
|
||||||
|
|
||||||
slen = strlen (flags);
|
slen = strlen (buf);
|
||||||
if (slen > 0)
|
if (slen > 0)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* We scan the flags here, but assume a stupid upper limit of 100 pieces, otherwise this all becomes fairly vague.
|
* We scan the buf here, but assume a stupid upper limit of 100 pieces, otherwise this all becomes fairly vague.
|
||||||
*/
|
*/
|
||||||
int max = 100;
|
int max = 100;
|
||||||
char *argv[100];
|
char *argv[100];
|
||||||
@ -1629,7 +1638,7 @@ process_environment (void)
|
|||||||
|
|
||||||
/* make a safe copy */
|
/* make a safe copy */
|
||||||
args = (char *) malloc (slen + 1);
|
args = (char *) malloc (slen + 1);
|
||||||
memcpy (args, flags, slen + 1);
|
memcpy (args, buf, slen + 1);
|
||||||
|
|
||||||
/* warning */
|
/* warning */
|
||||||
/*
|
/*
|
||||||
@ -1678,8 +1687,26 @@ process_environment (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Process switches
|
//! Process environment
|
||||||
void
|
void
|
||||||
|
process_environment (void)
|
||||||
|
{
|
||||||
|
char *flags;
|
||||||
|
|
||||||
|
flags = getenv ("SCYTHERFLAGS");
|
||||||
|
process_switch_buffer (flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Process switches
|
||||||
|
/**
|
||||||
|
* The 'commandline' boolean argument is set to true if called with input from the command line.
|
||||||
|
* If true:
|
||||||
|
* - Generate help info if empty
|
||||||
|
* - Accept input file argument
|
||||||
|
*
|
||||||
|
* Returns false if an error occurred.
|
||||||
|
*/
|
||||||
|
int
|
||||||
process_switches (int commandline)
|
process_switches (int commandline)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
@ -1695,7 +1722,7 @@ process_switches (int commandline)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1704,4 +1731,10 @@ process_switches (int commandline)
|
|||||||
{
|
{
|
||||||
index = switcher (1, index, commandline);
|
index = switcher (1, index, commandline);
|
||||||
}
|
}
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
// An error occurred: return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -93,5 +93,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);
|
FILE *openFileSearch (char *filename, FILE * reopener);
|
||||||
|
void process_switch_buffer (char *buf); //!< Process buffer for switches
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user