2005-04-10 16:30:47 +01:00
|
|
|
/**
|
|
|
|
*@file switches.c
|
|
|
|
* \brief Handle command-line options
|
|
|
|
*
|
|
|
|
* Contains the main switch handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "string.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "timer.h"
|
2005-06-07 16:02:27 +01:00
|
|
|
#include "switches.h"
|
2005-12-28 16:33:08 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "string.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "specialterm.h"
|
2005-12-28 16:33:08 +00:00
|
|
|
#include "memory.h"
|
2005-06-07 16:02:27 +01:00
|
|
|
#include <limits.h>
|
2005-12-28 16:33:08 +00:00
|
|
|
#include <stdlib.h>
|
2005-04-10 16:30:47 +01:00
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
struct switchdata switches;
|
2005-04-10 16:30:47 +01:00
|
|
|
|
|
|
|
extern struct tacnode *spdltac;
|
|
|
|
|
|
|
|
const char *progname = "scyther";
|
|
|
|
const char *releasetag = SVNVERSION;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
// Forward declarations
|
2005-12-28 16:33:08 +00:00
|
|
|
void process_environment (void);
|
|
|
|
void process_switches (int commandline);
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
//! Init switches
|
|
|
|
/**
|
|
|
|
* Set them all to the default settings.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
switchesInit (int argc, char **argv)
|
|
|
|
{
|
|
|
|
// Methods
|
2005-11-04 13:23:30 +00:00
|
|
|
switches.engine = ARACHNE_ENGINE; // default is arachne engine
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.match = 0; // default matching
|
|
|
|
switches.clp = 0;
|
2005-08-12 13:59:25 +01:00
|
|
|
switches.tupling = 0;
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Pruning and Bounding
|
2005-12-27 10:49:22 +00:00
|
|
|
switches.prune = 2; // default pruning method (just output a single one)
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.maxproofdepth = INT_MAX;
|
|
|
|
switches.maxtracelength = INT_MAX;
|
2005-12-22 12:27:34 +00:00
|
|
|
switches.runs = 5; // default is 5 for usability, but -r 0 or --maxruns=0 will set it back to INT_MAX
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.filterClaim = NULL; // default check all claims
|
2005-08-15 13:49:32 +01:00
|
|
|
switches.maxAttacks = 0; // no maximum default
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Modelchecker
|
|
|
|
switches.traverse = 12; // default traversal method
|
|
|
|
switches.forceChoose = 1; // force explicit chooses by default
|
|
|
|
switches.chooseFirst = 0; // no priority to chooses by default
|
|
|
|
switches.readSymmetries = 0; // don't force read symmetries by default
|
|
|
|
switches.agentSymmetries = 1; // default enable agent symmetry
|
|
|
|
switches.orderSymmetries = 0; // don't force symmetry order reduction by default
|
|
|
|
switches.pruneNomoreClaims = 1; // default cutter when there are no more claims
|
|
|
|
switches.reduceEndgame = 1; // default cutter of last events in a trace
|
|
|
|
switches.reduceClaims = 1; // default remove claims from duplicate instance choosers
|
|
|
|
// Parallellism
|
|
|
|
switches.scenario = 0;
|
|
|
|
switches.scenarioSize = 0;
|
|
|
|
|
|
|
|
// Arachne
|
|
|
|
switches.arachneSelector = 3; // default goal selection method
|
2005-08-21 22:38:32 +01:00
|
|
|
switches.maxIntruderActions = INT_MAX; // max number of encrypt/decrypt events
|
2005-10-08 20:54:30 +01:00
|
|
|
switches.agentTypecheck = 1; // default do check agent types
|
2005-11-12 21:26:50 +00:00
|
|
|
switches.concrete = true; // default removes symbols, and makes traces concrete
|
2005-11-29 09:15:16 +00:00
|
|
|
switches.extravert = false; // default allows also initiator Alice to talk to Alice
|
2005-12-21 19:02:41 +00:00
|
|
|
switches.intruder = true; // default allows an intruder
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
switches.switchP = 0; // multi-purpose parameter
|
2005-10-07 14:09:07 +01:00
|
|
|
switches.experimental = 0; // experimental stuff defaults to 0, whatever that means.
|
2005-12-27 13:53:49 +00:00
|
|
|
switches.removeclaims = false; // default: leave claims from spdl file
|
2005-12-28 11:50:17 +00:00
|
|
|
switches.addreachableclaim = false; // add 'reachable' claims
|
|
|
|
switches.addallclaims = false; // add all sorts of claims
|
2005-12-29 12:52:51 +00:00
|
|
|
switches.check = false; // check the protocol for termination etc. (default off)
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Output
|
2005-12-22 12:24:27 +00:00
|
|
|
switches.output = SUMMARY; // default is to show a summary
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.report = 0;
|
|
|
|
switches.reportClaims = 0; // default don't report on claims
|
2005-12-22 12:24:27 +00:00
|
|
|
switches.xml = 0; // default no xml output (dot)
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.human = false; // not human friendly by default
|
2005-06-21 12:04:34 +01:00
|
|
|
switches.reportMemory = 0;
|
|
|
|
switches.reportTime = 0;
|
|
|
|
switches.reportStates = 0;
|
|
|
|
switches.extendNonReads = 0; // default off
|
2005-08-12 13:13:50 +01:00
|
|
|
switches.extendTrivial = 0; // default off
|
2005-12-28 18:40:58 +00:00
|
|
|
switches.plain = false; // default colors
|
2005-06-21 12:04:34 +01:00
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
// Obsolete
|
|
|
|
switches.latex = 0; // latex output?
|
|
|
|
|
2005-12-28 16:33:08 +00:00
|
|
|
// Process the environment variable SCYTHERFLAGS
|
|
|
|
process_environment ();
|
|
|
|
// Process the command-line switches
|
|
|
|
switches.argc = argc;
|
|
|
|
switches.argv = argv;
|
|
|
|
process_switches (true);
|
2005-06-07 16:02:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Exit
|
|
|
|
void
|
|
|
|
switchesDone (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-12-29 09:25:42 +00:00
|
|
|
//! Open a (protocol) file instead of stdin
|
|
|
|
/**
|
|
|
|
* Uses the environment variable SCYTHERDIR to also search for files
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
openFileStdin (char *filename)
|
|
|
|
{
|
|
|
|
const char *separators = ":;\n";
|
|
|
|
char *dirs;
|
|
|
|
|
|
|
|
//! try a filename and a prefix.
|
|
|
|
int try (char *prefix)
|
|
|
|
{
|
|
|
|
char *buffer = NULL;
|
|
|
|
int result = false;
|
|
|
|
int buflen = 0;
|
|
|
|
int prefixlen = 0;
|
|
|
|
int namelen = 0;
|
|
|
|
int addslash = false;
|
|
|
|
int nameindex = 0;
|
|
|
|
|
|
|
|
prefixlen = (int) strcspn (prefix, separators);
|
|
|
|
namelen = strlen (filename);
|
|
|
|
nameindex = prefixlen;
|
|
|
|
|
|
|
|
buflen = prefixlen + namelen + 1;
|
|
|
|
|
|
|
|
// Does the prefix end with a slash? (it should)
|
|
|
|
if (nameindex > 0 && prefix[nameindex - 1] != '/')
|
|
|
|
{
|
|
|
|
addslash = true;
|
|
|
|
buflen++;
|
|
|
|
nameindex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = (char *) memAlloc (buflen);
|
|
|
|
memcpy (buffer, prefix, prefixlen);
|
|
|
|
memcpy (buffer + nameindex, filename, namelen);
|
|
|
|
buffer[buflen - 1] = '\0';
|
|
|
|
|
|
|
|
// Add the slash in the center
|
|
|
|
if (addslash)
|
|
|
|
{
|
|
|
|
buffer[nameindex - 1] = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now try to open it
|
|
|
|
if (freopen (buffer, "r", stdin) != NULL)
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
memFree (buffer, buflen);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main code.
|
|
|
|
|
|
|
|
if (try (""))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now try the environment variable
|
|
|
|
dirs = getenv ("SCYTHERDIR");
|
|
|
|
while (dirs != NULL)
|
|
|
|
{
|
|
|
|
if (strlen (dirs) > 0)
|
|
|
|
{
|
|
|
|
// try this one
|
|
|
|
if (try (dirs))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// skip to next
|
|
|
|
dirs = strpbrk (dirs, separators);
|
|
|
|
if (dirs != NULL)
|
|
|
|
{
|
|
|
|
// skip over separator
|
|
|
|
dirs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nope
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
//! Process a single switch or generate help text
|
|
|
|
/**
|
|
|
|
* When process is false, we just generate the help text.
|
|
|
|
*
|
|
|
|
* Yields new index, or -1 when an error occurred.
|
|
|
|
* When the new index > argc, it should not be called anymore.
|
|
|
|
* By convention, argc = the number of arguments + 1
|
|
|
|
* The index steps through 1..argc-1.
|
|
|
|
*/
|
|
|
|
int
|
2005-12-28 16:33:08 +00:00
|
|
|
switcher (const int process, int index, int commandline)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
char *this_arg; // just a shortcut
|
2005-04-15 15:31:32 +01:00
|
|
|
int this_arg_length; // same here
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
char *arg_pointer;
|
|
|
|
int arg_index;
|
|
|
|
|
|
|
|
//! Check whether there are still n options left
|
|
|
|
int enough_arguments_left (const int n, char shortopt, char *longopt)
|
|
|
|
{
|
|
|
|
if (index + n > argc)
|
|
|
|
{
|
|
|
|
error ("Option %c [%s] needs at least %i arguments.", shortopt,
|
|
|
|
longopt, n);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip over (processed) argument
|
|
|
|
void arg_next (void)
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
arg_pointer = argv[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Parse an argument into an integer
|
|
|
|
int integer_argument (void)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (arg_pointer == NULL)
|
|
|
|
{
|
|
|
|
error ("(Integer) argument expected.");
|
|
|
|
}
|
|
|
|
result = 0;
|
|
|
|
if (sscanf (arg_pointer, "%i", &result) != 1)
|
|
|
|
{
|
|
|
|
error ("Could not parse expected integer argument.");
|
|
|
|
}
|
|
|
|
arg_next ();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Detect whether this confirms to this option.
|
|
|
|
/**
|
|
|
|
* set arg_pointer and index
|
|
|
|
*/
|
|
|
|
int detect (char shortopt, char *longopt, int args)
|
|
|
|
{
|
|
|
|
arg_pointer = NULL;
|
|
|
|
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
// If we are not processing, we always yield true.
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// Is it this option anyway?
|
2005-04-15 15:31:32 +01:00
|
|
|
if (this_arg_length < 2 || this_arg[0] != '-')
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
// No option
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Compare
|
|
|
|
if (this_arg[1] == '-')
|
|
|
|
{
|
|
|
|
int optlength;
|
|
|
|
|
2005-04-15 15:31:32 +01:00
|
|
|
// This seems to be a long switch, so we handle it accordingly
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
optlength = strlen (longopt);
|
|
|
|
if (strncmp (this_arg + 2, longopt, optlength))
|
|
|
|
return 0;
|
2005-04-15 15:31:32 +01:00
|
|
|
if (optlength + 2 < this_arg_length)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
// This has an additional thing!
|
2005-04-15 15:31:32 +01:00
|
|
|
if (args > 0 && this_arg[2 + optlength] == '=')
|
|
|
|
{
|
|
|
|
// It's the right thing
|
|
|
|
if (optlength + 3 < this_arg_length)
|
|
|
|
{
|
2005-05-01 14:32:50 +01:00
|
|
|
arg_pointer = this_arg + 2 + optlength + 1;
|
2005-04-15 15:31:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// arg = next
|
|
|
|
index++;
|
|
|
|
arg_pointer = argv[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It's not this option
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// arg = next
|
|
|
|
index++;
|
|
|
|
arg_pointer = argv[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Short variant
|
2005-04-15 15:31:32 +01:00
|
|
|
if (this_arg_length < 2 || this_arg[1] != shortopt)
|
2005-04-10 16:30:47 +01:00
|
|
|
return 0;
|
2005-04-15 15:31:32 +01:00
|
|
|
if (args > 0 && this_arg_length > 2)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
// This has an additional thing!
|
2005-04-15 15:31:32 +01:00
|
|
|
// We assume the argument follows immediately (no appended '=')
|
2005-04-10 16:30:47 +01:00
|
|
|
arg_pointer = this_arg + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// arg = next
|
|
|
|
index++;
|
|
|
|
arg_pointer = argv[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Allright, this is the right option
|
|
|
|
// Enough arguments left?
|
|
|
|
return enough_arguments_left (args, shortopt, longopt);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Align columns
|
|
|
|
void helptext (const char *left, const char *right)
|
|
|
|
{
|
|
|
|
printf (" %-25s %s\n", left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
argc = switches.argc;
|
|
|
|
argv = switches.argv;
|
2005-04-10 16:30:47 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check range for debug; we trust the non-debug version :)
|
|
|
|
if (index < 1 || index >= argc)
|
|
|
|
{
|
|
|
|
error ("Bad index number %i for argc %i", index, argc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
this_arg = argv[index];
|
2005-05-01 14:32:50 +01:00
|
|
|
this_arg_length = strlen (this_arg);
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just doing help
|
|
|
|
this_arg = NULL;
|
2005-04-15 15:31:32 +01:00
|
|
|
this_arg_length = 0;
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Process the options, one by one
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
/* ==================
|
|
|
|
* Generic options
|
|
|
|
*/
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "arachne", 0))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-11-04 13:23:30 +00:00
|
|
|
/*
|
|
|
|
* Obsolete switch, as it is now the default behaviour.
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
// Select arachne engine
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.engine = ARACHNE_ENGINE;
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "modelchecker", 0))
|
2005-11-04 13:23:30 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-22 12:24:27 +00:00
|
|
|
/*
|
|
|
|
* Discourage
|
|
|
|
*
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --modelchecker",
|
2005-12-22 12:24:27 +00:00
|
|
|
"select Model checking engine [Arachne]");
|
|
|
|
*/
|
2005-11-04 13:23:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Select arachne engine
|
|
|
|
switches.engine = POR_ENGINE;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-22 12:24:27 +00:00
|
|
|
if (detect ('d', "dot-output", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-d, --dot-output", "show attack output in dot format");
|
2005-12-22 12:24:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.output = ATTACK;
|
|
|
|
switches.xml = 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-01 14:32:50 +01:00
|
|
|
if (detect ('x', "xml-output", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-x, --xml-output", "show attack output in XML format");
|
2005-05-01 14:32:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-22 12:24:27 +00:00
|
|
|
switches.output = ATTACK;
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.xml = 1;
|
2005-05-01 14:32:50 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "proof", 0))
|
2005-12-22 12:33:35 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
/*
|
|
|
|
* discourage: not very readable for non-experts yet
|
|
|
|
helptext (" --proof", "show explicit proof");
|
|
|
|
*/
|
2005-12-22 12:33:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Proof
|
|
|
|
switches.output = PROOF;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "remove-claims", 0))
|
2005-12-27 12:24:12 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
/* discourage:
|
|
|
|
*
|
|
|
|
* Causes all existing claims in the specification to be skipped.
|
|
|
|
*/
|
2005-12-27 12:24:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
switches.removeclaims = true;
|
2005-12-27 12:24:12 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect ('c', "check", 0))
|
2005-12-27 12:24:12 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-c, --check",
|
|
|
|
"disable intruder and run statespace check. For correct protocols, end of roles should be reachable");
|
2005-12-27 12:24:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
switches.check = true; // check (influences the number of runs after scanning the spdl file, setting it to the protocol role count)
|
|
|
|
switches.intruder = false; // disable intruder
|
|
|
|
switches.removeclaims = true; // remove parsed claims
|
|
|
|
switches.addreachableclaim = true; // add reachability claims
|
2005-12-27 12:24:12 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect ('a', "auto-claims", 0))
|
2005-12-27 13:53:49 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-a, --auto-claims",
|
|
|
|
"ignore any existing claims and automatically generate claims");
|
2005-12-27 13:53:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.removeclaims = true;
|
2005-12-29 12:52:51 +00:00
|
|
|
switches.addallclaims = true;
|
2005-12-27 13:53:49 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-30 15:11:39 +00:00
|
|
|
if (detect ('C', "class", 0))
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-30 15:11:39 +00:00
|
|
|
helptext ("-C, --class",
|
|
|
|
"generate full class (show uninstantiated variables in state output)");
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-30 15:11:39 +00:00
|
|
|
switches.concrete = false;
|
2005-12-28 11:50:17 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-30 15:11:39 +00:00
|
|
|
if (detect ('s', "state-space", 0))
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-30 15:11:39 +00:00
|
|
|
helptext ("-s, --state-space",
|
|
|
|
"ignore any existing claims and add 'reachable' claims. Generate full state space classes.");
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-30 15:11:39 +00:00
|
|
|
switches.removeclaims = true; // remove parsed claims
|
|
|
|
switches.addreachableclaim = true; // add reachability claims
|
|
|
|
switches.prune = 0; // do not prune anything
|
|
|
|
switches.concrete = false; // show classes
|
2005-12-29 12:52:51 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect (' ', "concrete", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* this is now the default */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.concrete = true;
|
2005-12-28 11:50:17 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-22 12:33:35 +00:00
|
|
|
/* ==================
|
|
|
|
* Bounding options
|
|
|
|
*/
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
printf ("Switches that affect the state space:\n");
|
|
|
|
}
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('m', "match", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-01-06 12:23:11 +00:00
|
|
|
/*
|
|
|
|
* Deprecated : use --untyped instead
|
|
|
|
*
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-m, --match=<int>",
|
|
|
|
"type matching method [0] 0: No type-flaws allowed, 1: Allow basic type-flaws only, 2: Allow all type-flaws");
|
2006-01-06 12:23:11 +00:00
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.match = integer_argument ();
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-06 12:23:11 +00:00
|
|
|
if (detect ('u', "untyped", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext ("-u, --untyped",
|
|
|
|
"Consider all variables to be untyped");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.match = 2;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('T', "timer", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* Not shown in from help, as we don't want to encourage this
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-T, --timer=<int>", "maximum time in seconds [inf]");
|
2005-04-15 11:04:05 +01:00
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
set_time_limit (integer_argument ());
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('r', "max-runs", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-r, --max-runs=<int>",
|
2005-12-27 12:01:17 +00:00
|
|
|
"maximum number of runs in the system [5]. Set to 0 for unbounded search");
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-12 21:26:50 +00:00
|
|
|
int arg = integer_argument ();
|
|
|
|
if (arg == 0)
|
|
|
|
{
|
|
|
|
switches.runs = INT_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.runs = arg;
|
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('l', "max-length", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-27 12:01:17 +00:00
|
|
|
/* not really needed if you prune runs
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-l, --max-length=<int>",
|
2005-12-27 12:01:17 +00:00
|
|
|
"prune traces longer than <int> events [inf]");
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.maxtracelength = integer_argument ();
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect ('A', "all-attacks", 0))
|
2005-12-27 12:01:17 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-30 15:11:39 +00:00
|
|
|
helptext ("-A, --all-attacks",
|
2005-12-29 12:52:51 +00:00
|
|
|
"generate all attacks within the state space instead of just one");
|
2005-12-27 12:01:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.prune = 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-15 13:49:32 +01:00
|
|
|
if (detect (' ', "max-attacks", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* not very important
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --max-attacks=<int>", "when not 0, maximum number of attacks [0]");
|
2005-08-15 13:49:32 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.maxAttacks = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "prune", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* not very important
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --prune=<int>", "pruning method when an attack is found [2]");
|
2005-04-15 11:04:05 +01:00
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.prune = integer_argument ();
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-02 09:25:45 +01:00
|
|
|
if (detect ('H', "human-readable", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-22 12:24:27 +00:00
|
|
|
/*
|
|
|
|
* Why?
|
|
|
|
*
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-H, --human-readable",
|
2005-12-22 12:24:27 +00:00
|
|
|
"try to make the output human-friendly (e.g. in XML).");
|
|
|
|
*/
|
2005-06-02 09:25:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.human = true;
|
2005-11-12 21:13:00 +00:00
|
|
|
switches.concrete = true;
|
2005-06-02 09:25:45 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:59:25 +01:00
|
|
|
if (detect (' ', "ra-tupling", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* for experts only
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --ra-tupling", "compile using right-associative tupling");
|
2005-08-12 13:59:25 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.tupling = 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 08:28:44 +01:00
|
|
|
if (detect (' ', "la-tupling", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-08-12 13:59:25 +01:00
|
|
|
/* for experts only
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --la-tupling", "compile using left-associative tupling");
|
2005-08-12 08:28:44 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-12 13:59:25 +01:00
|
|
|
switches.tupling = 1;
|
2005-08-12 08:28:44 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:59:25 +01:00
|
|
|
if (detect (' ', "tupling", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* for experts only
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --tupling", "tupling type to use");
|
2005-08-12 13:59:25 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.tupling = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
/* ==================
|
|
|
|
* Modelchecker only
|
|
|
|
*/
|
2005-12-22 12:33:35 +00:00
|
|
|
/*
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
printf ("Switches for modelchecking engine:\n");
|
|
|
|
}
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
/* obsolete, worked for modelchecker
|
|
|
|
*
|
|
|
|
if (detect (' ', "latex", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext (" --latex", "output attacks in LaTeX format [ASCII]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.latex = 1;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect (' ', "state-space", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext ("--state-space",
|
|
|
|
"output state space graph (in DOT format)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.output = STATESPACE;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
/* ==================
|
|
|
|
* Arachne only
|
|
|
|
*/
|
2005-12-22 12:33:35 +00:00
|
|
|
/*
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
printf ("Switches for Arachne engine:\n");
|
|
|
|
}
|
|
|
|
*/
|
2005-04-15 11:04:05 +01:00
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "goal-select", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* discourage: hide
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --goal-select=<int>",
|
2005-04-15 11:04:05 +01:00
|
|
|
"use goal selection method <int> [3]");
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.arachneSelector = integer_argument ();
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-21 12:04:34 +01:00
|
|
|
if (detect (' ', "extend-nonreads", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.extendNonReads = 1;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "disable-intruder", 0))
|
2005-12-21 19:02:41 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* for testing purposes: hide
|
|
|
|
*
|
|
|
|
* Disables the intruder
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.intruder = false;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-29 09:15:16 +00:00
|
|
|
if (detect (' ', "extravert", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*
|
|
|
|
* Finds only attacks which exclude initiator Alice talking to Alice
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.extravert = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:13:50 +01:00
|
|
|
if (detect (' ', "extend-trivial", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.extendTrivial = 1;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-21 22:38:32 +01:00
|
|
|
if (detect (' ', "intruder-actions", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
/* fairly technical */
|
2005-08-21 22:38:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.maxIntruderActions = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-08 20:54:30 +01:00
|
|
|
if (detect (' ', "disable-agenttypecheck", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* maybe add after testing */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.agentTypecheck = 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-07 14:09:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* ==================
|
|
|
|
* Experimental options
|
|
|
|
*
|
|
|
|
* Only with debugging version
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (detect (' ', "experimental", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* unpredictable behaviour, can change throughout versions */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.experimental = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
/* ==================
|
|
|
|
* External options
|
|
|
|
*/
|
|
|
|
if (!process)
|
|
|
|
printf ("Misc. switches:\n");
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "echo", 0))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* not very important
|
|
|
|
helptext ("-E,--echo", "echo command line");
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* print command line */
|
|
|
|
fprintf (stdout, "command\t");
|
2005-06-07 16:02:27 +01:00
|
|
|
commandlinePrint (stdout);
|
2005-04-15 11:04:05 +01:00
|
|
|
fprintf (stdout, "\n");
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:52:51 +00:00
|
|
|
if (detect (' ', "progress-bar", 0))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* discourage: do not show in help text
|
|
|
|
helptext ("-b,--progress-bar", "show progress bar");
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.reportStates = 50000;
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('e', "empty", 0))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-04-15 11:04:05 +01:00
|
|
|
/* not very important
|
|
|
|
helptext ("-e,--empty", "do not generate output");
|
|
|
|
*/
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
switches.output = EMPTY;
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect ('v', "version", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
2005-04-15 11:04:05 +01:00
|
|
|
{
|
|
|
|
/* not very important: hide
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-v, --version", "version information");
|
2005-04-15 11:04:05 +01:00
|
|
|
*/
|
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("'%s' model checker for security protocols.\n", progname);
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Revision %s, compiled with debugging support.\n",
|
|
|
|
SVNVERSION);
|
|
|
|
#else
|
|
|
|
printf ("Revision %s\n", SVNVERSION);
|
|
|
|
#endif
|
2005-04-15 15:31:32 +01:00
|
|
|
printf ("Code by Cas Cremers\n");
|
2005-04-10 16:30:47 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect ('h', "help", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-h, --help", "show this help");
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-28 16:33:08 +00:00
|
|
|
if (commandline)
|
|
|
|
{
|
|
|
|
printf ("Usage:\n");
|
|
|
|
printf (" %s [switches] [FILE]\n\nSwitches:\n", progname);
|
|
|
|
switcher (0, 0, commandline);
|
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-28 18:40:58 +00:00
|
|
|
if (detect (' ', "plain", 0))
|
2005-12-28 15:27:22 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext (" --plain", "disable color terminal output");
|
2005-12-28 15:27:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-28 18:40:58 +00:00
|
|
|
switches.plain = true;
|
2005-12-28 15:27:22 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (detect ('D', "debug", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-D, --debug=<int>", "set debug (verbosity) level. [0]");
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debugSet (integer_argument ());
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
if (detect ('o', "output", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2005-12-29 12:52:51 +00:00
|
|
|
helptext ("-o, --output=<FILE>", "output file [stdout]");
|
2005-04-15 11:04:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set output file name
|
|
|
|
/* try to open */
|
|
|
|
if (!freopen (arg_pointer, "w", stdout))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Could not create output file '%s'.\n",
|
|
|
|
arg_pointer);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
arg_next ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
// If the option is not recognized, it means a file name.
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext ("FILE", "input file ('-' for stdin)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-28 16:33:08 +00:00
|
|
|
if (!strcmp (this_arg, "-") && commandline)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
// '-' input: Leave input to stdin
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// not '-' input: change stdin to come from this file
|
2005-12-29 09:25:42 +00:00
|
|
|
if (!openFileStdin (this_arg))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2005-04-15 15:31:32 +01:00
|
|
|
// The file was not found. We have two options...
|
|
|
|
if (this_arg[0] == '-')
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Unknown switch '%s'.\n", this_arg);
|
|
|
|
}
|
2005-05-01 14:32:50 +01:00
|
|
|
else
|
2005-04-15 15:31:32 +01:00
|
|
|
{
|
2005-05-01 14:32:50 +01:00
|
|
|
fprintf (stderr, "Could not open input file '%s'.\n",
|
|
|
|
this_arg);
|
2005-04-15 15:31:32 +01:00
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
return index + 1;
|
|
|
|
}
|
|
|
|
}
|
2005-12-29 09:35:08 +00:00
|
|
|
|
|
|
|
// Now show the environment variables
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
printf
|
|
|
|
("\nThere are two environment variables that influence the behaviour of Scyther.\n");
|
|
|
|
printf
|
|
|
|
(" SCYTHERFLAGS Put any default command-line options here, syntax as on the command line.\n");
|
|
|
|
printf
|
|
|
|
(" SCYTHERDIR Colon-separated path of directories to search for input files if a file\n");
|
2005-12-29 10:56:09 +00:00
|
|
|
printf
|
|
|
|
(" is not found in the current directory. Note: use '$HOME' instead of '~'.\n");
|
2005-12-29 09:35:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-28 16:33:08 +00:00
|
|
|
//! Process environment
|
|
|
|
void
|
|
|
|
process_environment (void)
|
|
|
|
{
|
|
|
|
char *flags;
|
|
|
|
|
|
|
|
flags = getenv ("SCYTHERFLAGS");
|
|
|
|
if (flags != NULL)
|
|
|
|
{
|
|
|
|
int slen;
|
|
|
|
|
|
|
|
slen = strlen (flags);
|
|
|
|
if (slen > 0)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* We scan the flags here, but assume a stupid upper limit of 100 pieces, otherwise this all becomes fairly vague.
|
|
|
|
*/
|
|
|
|
int max = 100;
|
|
|
|
char *argv[100];
|
|
|
|
int count;
|
|
|
|
char *args;
|
|
|
|
char *scanflag;
|
|
|
|
char *argn;
|
|
|
|
|
|
|
|
/* make a safe copy */
|
|
|
|
args = (char *) memAlloc (slen + 1);
|
|
|
|
memcpy (args, flags, slen + 1);
|
|
|
|
|
|
|
|
/* warning */
|
|
|
|
/*
|
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: using environment variable SVNSCYTHER ('%s')\n",
|
|
|
|
args);
|
|
|
|
globalError--;
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < max)
|
|
|
|
{
|
|
|
|
argv[i] = "";
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scanflag = args;
|
|
|
|
count = 0;
|
|
|
|
/* ugly use of assignment in condition */
|
|
|
|
while (count < max)
|
|
|
|
{
|
|
|
|
argn = strtok (scanflag, "\t ");
|
|
|
|
scanflag = NULL;
|
|
|
|
if (argn != NULL)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
argv[count] = argn;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
warning ("found %i arguments in SCYTHERFLAGS\n", count);
|
|
|
|
*/
|
|
|
|
|
|
|
|
switches.argc = count + 1;
|
|
|
|
switches.argv = argv;
|
|
|
|
process_switches (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
//! Process switches
|
|
|
|
void
|
2005-12-28 16:33:08 +00:00
|
|
|
process_switches (int commandline)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.argc == 1)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2005-12-28 16:33:08 +00:00
|
|
|
if (commandline)
|
|
|
|
{
|
|
|
|
printf ("Try '%s --help' for more information, or visit:\n",
|
|
|
|
progname);
|
|
|
|
printf (" http://www.win.tue.nl/~ccremers/scyther/index.html\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
index = 1;
|
2005-06-07 16:02:27 +01:00
|
|
|
while (index < switches.argc && index > 0)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2005-12-28 16:33:08 +00:00
|
|
|
index = switcher (1, index, commandline);
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
}
|