2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
2013-10-05 23:56:12 +01:00
|
|
|
* Copyright (C) 2007-2013 Cas Cremers
|
2007-06-11 13:01:04 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
/**
|
|
|
|
*@file switches.c
|
|
|
|
* \brief Handle command-line options
|
|
|
|
*
|
|
|
|
* Contains the main switch handling.
|
|
|
|
*/
|
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
2005-04-10 16:30:47 +01:00
|
|
|
#include "system.h"
|
|
|
|
#include "debug.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"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "specialterm.h"
|
2005-04-10 16:30:47 +01:00
|
|
|
|
2006-08-02 10:32:29 +01:00
|
|
|
// Program name
|
2005-04-10 16:30:47 +01:00
|
|
|
const char *progname = "scyther";
|
2006-08-02 10:32:29 +01:00
|
|
|
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
// Structures
|
|
|
|
struct switchdata switches;
|
|
|
|
extern struct tacnode *spdltac;
|
2005-04-10 16:30:47 +01:00
|
|
|
|
2006-08-02 10:32:29 +01:00
|
|
|
// Global
|
2006-06-11 16:22:20 +01:00
|
|
|
char *lastfoundprefix = NULL;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
// Forward declarations
|
2005-12-28 16:33:08 +00:00
|
|
|
void process_environment (void);
|
2012-12-14 22:53:04 +00:00
|
|
|
int 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
|
|
|
|
switches.match = 0; // default matching
|
2005-08-12 13:59:25 +01:00
|
|
|
switches.tupling = 0;
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Pruning and Bounding
|
2006-07-06 16:54:14 +01:00
|
|
|
switches.prune = 2; // default pruning method (use nice heuristic)
|
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
|
2006-08-08 13:30:29 +01:00
|
|
|
switches.filterProtocol = NULL; // default check all claims
|
|
|
|
switches.filterLabel = NULL; // default check all claims
|
2005-08-15 13:49:32 +01:00
|
|
|
switches.maxAttacks = 0; // no maximum default
|
2007-01-26 15:31:49 +00:00
|
|
|
switches.maxOfRole = 0; // no maximum default
|
2012-12-14 15:59:53 +00:00
|
|
|
switches.oneRolePerAgent = 0; // agents can perform multiple roles
|
2005-06-07 16:02:27 +01:00
|
|
|
|
|
|
|
// Arachne
|
2010-11-10 21:01:38 +00:00
|
|
|
switches.heuristic = 674; // default goal selection method (used to be 162)
|
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
|
2006-03-31 09:24:41 +01:00
|
|
|
switches.initUnique = false; // default allows initiator rho to contain duplicate terms
|
|
|
|
switches.respUnique = false; // default allows responder rho to contain duplicate terms
|
2011-04-01 14:24:14 +01:00
|
|
|
switches.roleUnique = false; // default allows agents to perform multiple roles
|
2005-12-21 19:02:41 +00:00
|
|
|
switches.intruder = true; // default allows an intruder
|
2011-01-18 16:03:20 +00:00
|
|
|
switches.chosenName = false; // default no chosen name attacks
|
2007-05-03 12:40:58 +01:00
|
|
|
switches.agentUnfold = 0; // default not to unfold agents
|
|
|
|
switches.abstractionMethod = 0; // default no abstraction used
|
|
|
|
switches.useAttackBuffer = false; // don't use by default as it does not work properly under windows vista yet
|
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)
|
2006-02-22 08:41:06 +00:00
|
|
|
switches.expert = false; // expert mode (off by default)
|
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
|
2006-08-01 08:31:40 +01:00
|
|
|
switches.xml = false; // default no xml output
|
|
|
|
switches.dot = false; // default no dot output
|
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;
|
2006-02-22 08:24:29 +00:00
|
|
|
switches.countStates = false; // default off
|
2012-04-25 08:53:07 +01:00
|
|
|
switches.extendNonRecvs = 0; // default off
|
2005-08-12 13:13:50 +01:00
|
|
|
switches.extendTrivial = 0; // default off
|
2006-05-25 21:35:01 +01:00
|
|
|
switches.plain = false; // default colors for terminal
|
|
|
|
switches.monochrome = false; // default colors for dot
|
2006-05-26 13:57:27 +01:00
|
|
|
switches.lightness = 0; // lightness correction
|
2006-05-26 10:39:10 +01:00
|
|
|
switches.clusters = false; // default is no clusters for now
|
2008-06-16 17:57:28 +01:00
|
|
|
switches.exitCodes = true; // default is to flag exit codes
|
2005-06-21 12:04:34 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2006-06-11 16:22:20 +01:00
|
|
|
if (lastfoundprefix != NULL)
|
|
|
|
free (lastfoundprefix);
|
2005-06-07 16:02:27 +01:00
|
|
|
}
|
|
|
|
|
2006-04-12 13:42:04 +01:00
|
|
|
//! Open a (protocol) file.
|
2005-12-29 09:25:42 +00:00
|
|
|
/**
|
|
|
|
* Uses the environment variable SCYTHERDIR to also search for files
|
2006-04-12 13:42:04 +01:00
|
|
|
*
|
2006-06-11 16:22:20 +01:00
|
|
|
* If a file was opened before, this is stored in the static char* (initially
|
|
|
|
* NULL) lastfoundprefix. This prefix can override any other: the point of it is that
|
|
|
|
* if you find a file in a non-standard location, which then does an include,
|
|
|
|
* you want this to refer to the directory where you found that last file.
|
|
|
|
*
|
2006-04-12 13:42:04 +01:00
|
|
|
* If reopener == NULL then we open a new file pointer, otherwise reopen this one.
|
2005-12-29 09:25:42 +00:00
|
|
|
*/
|
2006-04-12 13:42:04 +01:00
|
|
|
FILE *
|
|
|
|
openFileSearch (char *filename, FILE * reopener)
|
2005-12-29 09:25:42 +00:00
|
|
|
{
|
|
|
|
const char *separators = ":;\n";
|
|
|
|
char *dirs;
|
|
|
|
|
|
|
|
//! try a filename and a prefix.
|
2006-06-11 16:22:20 +01:00
|
|
|
/**
|
|
|
|
* Prefixes don't have to end with "/"; this will be added automatically.
|
|
|
|
*/
|
2005-12-29 09:25:42 +00:00
|
|
|
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)
|
2006-06-11 16:22:20 +01:00
|
|
|
if (prefixlen > 0 && prefix[prefixlen - 1] != '/')
|
2005-12-29 09:25:42 +00:00
|
|
|
{
|
|
|
|
addslash = true;
|
|
|
|
buflen++;
|
|
|
|
nameindex++;
|
|
|
|
}
|
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
buffer = (char *) malloc (buflen);
|
2005-12-29 09:25:42 +00:00
|
|
|
memcpy (buffer, prefix, prefixlen);
|
|
|
|
memcpy (buffer + nameindex, filename, namelen);
|
|
|
|
buffer[buflen - 1] = '\0';
|
|
|
|
|
|
|
|
// Add the slash in the center
|
|
|
|
if (addslash)
|
2006-06-11 16:22:20 +01:00
|
|
|
buffer[nameindex - 1] = '/';
|
2005-12-29 09:25:42 +00:00
|
|
|
|
|
|
|
// Now try to open it
|
2006-04-12 13:42:04 +01:00
|
|
|
if (reopener != NULL)
|
2005-12-29 09:25:42 +00:00
|
|
|
{
|
2006-04-12 13:42:04 +01:00
|
|
|
if (freopen (buffer, "r", reopener) != NULL)
|
2006-06-11 16:22:20 +01:00
|
|
|
result = true;
|
2006-04-12 13:42:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reopener = fopen (buffer, "r");
|
|
|
|
if (reopener != NULL)
|
2006-06-11 16:22:20 +01:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
// There is a result. Does it have a prefix?
|
|
|
|
char *ls;
|
|
|
|
|
|
|
|
// Non-standard location, maybe we should warn for that
|
|
|
|
if (switches.expert)
|
2006-04-12 13:42:04 +01:00
|
|
|
{
|
2006-06-11 16:22:20 +01:00
|
|
|
globalError++;
|
2012-04-25 08:53:07 +01:00
|
|
|
eprintf ("Recving file %s.\n", buffer);
|
2006-06-11 16:22:20 +01:00
|
|
|
globalError--;
|
2006-04-12 13:42:04 +01:00
|
|
|
}
|
2005-12-29 09:25:42 +00:00
|
|
|
|
2006-06-11 16:22:20 +01:00
|
|
|
// Compute the prefix (simply scan for the last slash, if any)
|
|
|
|
ls = strrchr (buffer, '/');
|
|
|
|
if (ls != NULL)
|
|
|
|
{
|
|
|
|
// Store it for any next includes or something like that
|
|
|
|
// Clear the old one
|
|
|
|
if (lastfoundprefix != NULL)
|
|
|
|
free (lastfoundprefix);
|
|
|
|
ls[0] = '\0';
|
|
|
|
lastfoundprefix = buffer;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-03-08 13:58:46 +00:00
|
|
|
free (buffer);
|
2005-12-29 09:25:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main code.
|
|
|
|
|
2006-06-11 16:22:20 +01:00
|
|
|
// Try last file prefix (if it exists!)
|
|
|
|
if (lastfoundprefix != NULL)
|
2005-12-29 09:25:42 +00:00
|
|
|
{
|
2006-06-11 16:22:20 +01:00
|
|
|
if (try (lastfoundprefix))
|
|
|
|
return reopener;
|
2005-12-29 09:25:42 +00:00
|
|
|
}
|
|
|
|
|
2006-06-11 16:22:20 +01:00
|
|
|
// Try current directory
|
|
|
|
|
|
|
|
if (try (""))
|
|
|
|
return reopener;
|
|
|
|
|
2005-12-29 09:25:42 +00:00
|
|
|
// Now try the environment variable
|
|
|
|
dirs = getenv ("SCYTHERDIR");
|
|
|
|
while (dirs != NULL)
|
|
|
|
{
|
|
|
|
if (strlen (dirs) > 0)
|
|
|
|
{
|
|
|
|
// try this one
|
|
|
|
if (try (dirs))
|
2006-06-11 16:22:20 +01:00
|
|
|
return reopener;
|
2005-12-29 09:25:42 +00:00
|
|
|
// skip to next
|
|
|
|
dirs = strpbrk (dirs, separators);
|
|
|
|
if (dirs != NULL)
|
|
|
|
{
|
|
|
|
// skip over separator
|
|
|
|
dirs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nope
|
2006-04-12 13:42:04 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Open a (protocol) file instead of stdin
|
|
|
|
int
|
|
|
|
openFileStdin (char *filename)
|
|
|
|
{
|
|
|
|
if (openFileSearch (filename, stdin) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2005-12-29 09:25:42 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
//! 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];
|
|
|
|
}
|
|
|
|
|
2006-08-08 13:30:29 +01:00
|
|
|
//! Retrieve a (string) argument
|
|
|
|
char *string_argument (void)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
if (arg_pointer == NULL)
|
|
|
|
{
|
|
|
|
error ("Argument expected.");
|
|
|
|
}
|
|
|
|
result = arg_pointer;
|
|
|
|
arg_next ();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-04-10 16:30:47 +01:00
|
|
|
//! 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];
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 22:59:57 +00:00
|
|
|
// Alright, this is the right option
|
2005-04-10 16:30:47 +01:00
|
|
|
// 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-22 12:24:27 +00:00
|
|
|
if (detect ('d', "dot-output", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2007-05-03 12:40:58 +01:00
|
|
|
helptext ("-d, --dot-output", "show patterns in dot format");
|
2005-12-22 12:24:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.output = ATTACK;
|
2006-08-01 08:31:40 +01:00
|
|
|
switches.dot = true;
|
2005-12-22 12:24:27 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-01 14:32:50 +01:00
|
|
|
if (detect ('x', "xml-output", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2007-05-03 12:40:58 +01:00
|
|
|
helptext ("-x, --xml-output", "show patterns in XML format");
|
2005-05-01 14:32:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-22 12:24:27 +00:00
|
|
|
switches.output = ATTACK;
|
2006-08-01 08:31:40 +01:00
|
|
|
switches.xml = true;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-08 14:00:16 +01:00
|
|
|
if (detect (' ', "filter", 1))
|
2006-08-08 13:30:29 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-08-08 14:00:16 +01:00
|
|
|
helptext ("--filter=<protocol>[,<label>]",
|
|
|
|
"check only certain claims");
|
2006-08-08 13:30:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *second;
|
|
|
|
|
|
|
|
switches.filterProtocol = string_argument ();
|
|
|
|
second = strchr (switches.filterProtocol, ',');
|
|
|
|
if (second != NULL)
|
|
|
|
{
|
|
|
|
// Cut off first part (turn ',' into '\0'; string is disposable) and proceed to next character.
|
|
|
|
second[0] = '\0';
|
|
|
|
second++;
|
|
|
|
switches.filterLabel = second;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-15 17:00:28 +00:00
|
|
|
if (detect ('C', "check", 0))
|
2005-12-27 12:24:12 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2007-11-15 17:00:28 +00:00
|
|
|
/* discourage: not working well currently.
|
|
|
|
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)
|
|
|
|
{
|
2006-02-22 08:47:22 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext ("-C, --class",
|
2007-05-03 12:40:58 +01:00
|
|
|
"show full class (allow uninstantiated variables in pattern output)");
|
2006-02-22 08:47:22 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-15 17:00:28 +00:00
|
|
|
if (detect ('c', "characterize", 0) || detect ('s', "state-space", 0))
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
2007-11-15 17:00:28 +00:00
|
|
|
/*
|
|
|
|
* TODO maybe this switch should also filter out the intruder.
|
|
|
|
*/
|
2005-12-28 11:50:17 +00:00
|
|
|
if (!process)
|
|
|
|
{
|
2006-02-22 08:47:22 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
2007-11-15 17:00:28 +00:00
|
|
|
helptext ("-c, --characterize",
|
|
|
|
"Ignore claims and give complete characterization of all roles");
|
2006-02-22 08:47:22 +00:00
|
|
|
}
|
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-03-20 08:47:12 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext ("-m, --match=<int>",
|
|
|
|
"type matching method [0] 0: No type-flaws allowed, 1: Allow basic type-flaws only, 2: Allow all type-flaws (not complete for this beta)");
|
|
|
|
}
|
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)
|
|
|
|
{
|
2006-03-20 08:47:12 +00:00
|
|
|
/* unadvisable, implicit m2 whilst we will need m1 */
|
|
|
|
/*
|
|
|
|
helptext ("-u, --untyped", "Consider all variables to be untyped");
|
|
|
|
*/
|
2006-01-06 12:23:11 +00:00
|
|
|
}
|
|
|
|
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>",
|
2007-05-03 12:40:58 +01:00
|
|
|
"maximum number of runs in patterns [5]");
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-06 12:46:04 +00:00
|
|
|
if (detect (' ', "unbounded", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext (" --unbounded",
|
2007-05-03 12:40:58 +01:00
|
|
|
"Do not bound the number of runs in patterns");
|
2006-01-06 12:46:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.runs = INT_MAX;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-27 09:52:44 +00:00
|
|
|
if (detect (' ', "scan-claims", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* simply reduce allowed trace length to 0, cuts off any iterations immediately.
|
|
|
|
* useful to simply retrieve all claims.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.maxtracelength = 0;
|
|
|
|
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
|
2006-11-22 15:15:12 +00:00
|
|
|
helptext (" --max-attacks=<int>", "when not 0, maximum number of attacks/states per claim [0]");
|
2005-08-15 13:49:32 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-14 16:14:18 +00:00
|
|
|
/*
|
|
|
|
* This is the maximum number of *output* attacks per claim, except
|
|
|
|
* when it is 0 (unlimited). Thus, for a choice N, the tool might
|
|
|
|
* still report 'at least X attacks' with X>N, but it will only
|
|
|
|
* output N attacks.
|
|
|
|
*/
|
2005-08-15 13:49:32 +01:00
|
|
|
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
|
2006-07-06 16:54:14 +01:00
|
|
|
helptext (" --prune=<int>", "pruning method when an attack is found [2]");
|
2006-11-23 10:40:10 +00:00
|
|
|
|
|
|
|
Semantics:
|
2006-12-14 16:14:18 +00:00
|
|
|
0 - Show all attacks (up to the maximum --max-attacks)
|
|
|
|
1 - Show first attack (only one)
|
|
|
|
2 - Show 'best' attack (use heuristics) (only one)
|
2006-11-23 10:40:10 +00:00
|
|
|
|
|
|
|
Thus, a value of '0' means multiple attacks are output, otherwise just one.
|
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)
|
|
|
|
{
|
2006-02-22 08:41:06 +00:00
|
|
|
/* disabled for now
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 12:40:58 +01:00
|
|
|
if (detect (' ', "abstraction-method", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
/* Not working yet
|
|
|
|
helptext (" --abstraction-method=<int>",
|
|
|
|
"Abstraction method used. Default: 0 (disabled)");
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.abstractionMethod = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-16 17:57:28 +01:00
|
|
|
if (detect (' ', "no-exitcodes", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext (" --no-exitcodes", "Disable verbose exitcodes.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.exitCodes = false;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:59:25 +01:00
|
|
|
|
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 (' ', "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
|
|
|
|
2006-02-22 15:48:58 +00:00
|
|
|
if (detect (' ', "heuristic", 1))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-02-22 15:48:58 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
2010-11-10 21:01:38 +00:00
|
|
|
helptext (" --heuristic=<int>", "use heuristic <int> [674]");
|
2006-02-22 15:48:58 +00:00
|
|
|
}
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-23 15:03:43 +00:00
|
|
|
switches.heuristic = integer_argument ();
|
2005-04-10 16:30:47 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 12:40:58 +01:00
|
|
|
if (detect (' ', "agent-unfold", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.agentUnfold = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
if (detect (' ', "extend-nonrecvs", 0))
|
2005-06-21 12:04:34 +01:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
switches.extendNonRecvs = 1;
|
2005-06-21 12:04:34 +01:00
|
|
|
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
|
|
|
|
{
|
2006-03-31 09:24:41 +01:00
|
|
|
switches.initUnique = true;
|
|
|
|
switches.respUnique = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect (' ', "init-unique", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*
|
|
|
|
* Finds only attacks which exclude initiator Alice talking to Alice
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.initUnique = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect (' ', "resp-unique", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*
|
|
|
|
* Finds only attacks which exclude initiator Alice talking to Alice
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.respUnique = true;
|
2005-11-29 09:15:16 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 14:24:14 +01:00
|
|
|
if (detect (' ', "role-unique", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*
|
|
|
|
* Finds only attacks in which agents perform at most one role
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.roleUnique = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 16:03:20 +00:00
|
|
|
if (detect (' ', "chosen-name", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*
|
|
|
|
* Check for chosen-name attacks. Currently buggy: see prune_theorems.c for more details.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.chosenName = 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 21:35:01 +01:00
|
|
|
if (detect (' ', "monochrome", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.monochrome = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 13:57:27 +01:00
|
|
|
if (detect (' ', "lightness", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.lightness = integer_argument ();
|
|
|
|
if ((switches.lightness < 0) || (switches.lightness > 100))
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("--lightness=x only accepts integer values between 0 and 100");
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 10:39:10 +01:00
|
|
|
if (detect (' ', "clusters", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* discourage: hide
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.clusters = true;
|
|
|
|
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
|
|
|
/* ==================
|
|
|
|
* Experimental options
|
|
|
|
*
|
2006-02-28 14:06:12 +00:00
|
|
|
* Only for experts
|
2005-10-07 14:09:07 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-28 14:06:12 +00:00
|
|
|
if (switches.expert)
|
2005-10-07 14:09:07 +01:00
|
|
|
{
|
2006-02-28 14:06:12 +00:00
|
|
|
if (detect (' ', "experimental", 1))
|
2005-10-07 14:09:07 +01:00
|
|
|
{
|
2006-02-28 14:06:12 +00:00
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
/* unpredictable behaviour, can change throughout versions */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.experimental = integer_argument ();
|
|
|
|
return index;
|
|
|
|
}
|
2005-10-07 14:09:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 15:31:49 +00:00
|
|
|
if (detect (' ', "max-of-role", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext (" --max-of-role=<int>",
|
|
|
|
"maximum number of instances of each role [inf]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int arg = integer_argument ();
|
|
|
|
if (arg == 0)
|
|
|
|
{
|
|
|
|
switches.maxOfRole = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.maxOfRole = arg;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 15:59:53 +00:00
|
|
|
if (detect (' ', "one-role-per-agent", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext (" --one-role-per-agent",
|
2012-12-14 22:59:57 +00:00
|
|
|
"agents are disallowed from performing multiple roles");
|
2012-12-14 15:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.oneRolePerAgent = 1;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 15:31:49 +00:00
|
|
|
|
2005-04-15 11:04:05 +01:00
|
|
|
/* ==================
|
2006-02-22 08:41:06 +00:00
|
|
|
* Misc switches
|
2005-04-15 11:04:05 +01:00
|
|
|
*/
|
2006-02-22 08:41:06 +00:00
|
|
|
|
|
|
|
if (!process)
|
|
|
|
printf ("Misc. switches:\n");
|
|
|
|
|
|
|
|
|
|
|
|
if (detect ('E', "expert", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext ("-E, --expert", "Expert mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.expert = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 08:24:29 +00:00
|
|
|
if (detect (' ', "count-states", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-02-22 08:41:06 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext (" --count-states", "report on states (per claim)");
|
|
|
|
}
|
2006-02-22 08:24:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switches.countStates = true;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2006-02-22 08:41:06 +00:00
|
|
|
helptext (" --echo", "echo command line");
|
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
|
|
|
/* 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-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
|
|
|
{
|
2006-02-22 08:41:06 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
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);
|
2007-06-11 14:05:49 +01:00
|
|
|
printf ("Scyther version %s.\n", TAGVERSION);
|
2006-08-11 18:15:39 +01:00
|
|
|
if (switches.expert)
|
2006-11-23 10:40:10 +00:00
|
|
|
{
|
2005-04-10 16:30:47 +01:00
|
|
|
#ifdef DEBUG
|
2007-05-20 15:08:56 +01:00
|
|
|
printf ("Compiled with debugging support.\n");
|
2005-04-10 16:30:47 +01:00
|
|
|
#endif
|
2006-11-23 10:40:10 +00:00
|
|
|
}
|
2013-10-05 23:56:12 +01:00
|
|
|
printf ("Copyright (C) 2007-2013 Cas Cremers\n\n");
|
2007-06-11 14:05:49 +01:00
|
|
|
printf ("Scyther comes with ABSOLUTELY NO WARRANTY.\n");
|
|
|
|
printf ("This is free software, and you are welcome\n");
|
|
|
|
printf ("to redistribute it under certain conditions.\n");
|
2010-11-10 22:15:52 +00:00
|
|
|
printf ("Use the `--license' option for details.\n");
|
2007-06-11 14:05:49 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect (' ', "license", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext (" --license", "show license");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf
|
|
|
|
("Scyther : An automatic verifier for security protocols.\n");
|
2013-10-05 23:56:12 +01:00
|
|
|
printf ("Copyright (C) 2007-2013 Cas Cremers\n");
|
2007-06-11 14:05:49 +01:00
|
|
|
printf ("\n");
|
|
|
|
printf
|
|
|
|
("This program is free software; you can redistribute it and/or\n");
|
|
|
|
printf
|
|
|
|
("modify it under the terms of the GNU General Public License\n");
|
|
|
|
printf
|
|
|
|
("as published by the Free Software Foundation; either version 2\n");
|
|
|
|
printf ("of the License, or (at your option) any later version.\n");
|
|
|
|
printf ("\n");
|
|
|
|
printf
|
|
|
|
("This program is distributed in the hope that it will be useful,\n");
|
|
|
|
printf
|
|
|
|
("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
|
|
|
|
printf
|
|
|
|
("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
|
|
|
|
printf ("GNU General Public License for more details.\n");
|
|
|
|
printf ("\n");
|
|
|
|
printf
|
|
|
|
("You should have received a copy of the GNU General Public License\n");
|
|
|
|
printf
|
|
|
|
("along with this program; if not, write to the Free Software\n");
|
|
|
|
printf
|
|
|
|
("Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n");
|
2005-04-10 16:30:47 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detect ('h', "help", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-02-22 08:41:06 +00:00
|
|
|
helptext ("-h, --help", "show short 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 08:41:06 +00:00
|
|
|
if (detect (' ', "long-help", 0))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext (" --long-help", "show long help");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (commandline)
|
|
|
|
{
|
|
|
|
printf ("Usage:\n");
|
|
|
|
printf (" %s [switches] [FILE]\n\nSwitches:\n", progname);
|
|
|
|
switches.expert = true;
|
|
|
|
switcher (0, 0, commandline);
|
|
|
|
}
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-28 18:40:58 +00:00
|
|
|
if (detect (' ', "plain", 0))
|
2005-12-28 15:27:22 +00:00
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
2006-02-22 08:47:22 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2006-02-22 08:41:06 +00:00
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
2006-08-02 11:29:40 +01:00
|
|
|
printfstderr ("Could not create output file '%s'.\n",
|
|
|
|
arg_pointer);
|
2005-04-15 11:04:05 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
arg_next ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-14 16:28:29 +00:00
|
|
|
if (detect (' ', "append-output", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
helptext (" --append-output=<FILE>",
|
|
|
|
"append output file [stdout]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set output file name
|
|
|
|
/* try to open */
|
|
|
|
if (!freopen (arg_pointer, "a", stdout))
|
|
|
|
{
|
|
|
|
printfstderr ("Could not create output file '%s'.\n",
|
|
|
|
arg_pointer);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
arg_next ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-11 09:18:54 +00:00
|
|
|
if (detect (' ', "errors", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
2006-12-14 16:28:29 +00:00
|
|
|
helptext (" --errors=<FILE>",
|
|
|
|
"write errors to file [stderr]");
|
2006-12-11 09:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set output file name
|
|
|
|
/* try to open */
|
2006-12-14 16:28:29 +00:00
|
|
|
if (!freopen (arg_pointer, "w", stderr))
|
2006-12-11 09:18:54 +00:00
|
|
|
{
|
|
|
|
printfstderr ("Could not create error file '%s'.\n",
|
|
|
|
arg_pointer);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
arg_next ();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-14 16:28:29 +00:00
|
|
|
if (detect (' ', "append-errors", 1))
|
|
|
|
{
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
if (switches.expert)
|
|
|
|
{
|
|
|
|
helptext (" --append-errors=<FILE>",
|
|
|
|
"append errors to file [stderr]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set output file name
|
|
|
|
/* try to open */
|
|
|
|
if (!freopen (arg_pointer, "a", stderr))
|
|
|
|
{
|
|
|
|
printfstderr ("Could not create append error 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.
|
2012-12-14 22:53:04 +00:00
|
|
|
// But we only consider this for the command line
|
|
|
|
if (commandline)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
if (!process)
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
helptext ("FILE", "input file ('-' for stdin)");
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
if (!strcmp (this_arg, "-"))
|
2005-04-10 16:30:47 +01:00
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
// '-' input: Leave input to stdin
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// not '-' input: change stdin to come from this file
|
|
|
|
if (!openFileStdin (this_arg))
|
2005-04-15 15:31:32 +01:00
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
// The file was not found. We have two options...
|
|
|
|
if (this_arg[0] == '-')
|
|
|
|
{
|
|
|
|
printfstderr ("Unknown switch '%s'.\n", this_arg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printfstderr ("Could not open input file '%s'.\n",
|
|
|
|
this_arg);
|
|
|
|
}
|
|
|
|
exit (1);
|
2005-04-15 15:31:32 +01:00
|
|
|
}
|
2012-12-14 22:53:04 +00:00
|
|
|
return index + 1;
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 22:53:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unrecognized option.
|
|
|
|
error ("Could not parse argument \"%s\".\n", this_arg);
|
|
|
|
}
|
2005-12-29 09:35:08 +00:00
|
|
|
|
|
|
|
// Now show the environment variables
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
printf
|
2012-12-14 22:53:04 +00:00
|
|
|
("\nThere are two environment variables that influence the behaviour of the Scyther command-line tool.\n");
|
2005-12-29 09:35:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:53:04 +00:00
|
|
|
//! 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.
|
|
|
|
*/
|
2005-12-28 16:33:08 +00:00
|
|
|
void
|
2014-06-10 14:32:52 +01:00
|
|
|
process_switch_buffer (char *args_source)
|
2005-12-28 16:33:08 +00:00
|
|
|
{
|
2014-06-10 14:32:52 +01:00
|
|
|
int arg_string_len;
|
|
|
|
|
|
|
|
if (args_source == NULL)
|
2005-12-28 16:33:08 +00:00
|
|
|
{
|
2014-06-10 14:32:52 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-12-28 16:33:08 +00:00
|
|
|
|
2014-06-10 14:32:52 +01:00
|
|
|
arg_string_len = strlen (args_source);
|
|
|
|
if (arg_string_len > 0)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* We scan the args_source here, but assume a stupid upper limit of 100 pieces, otherwise this all becomes fairly vague.
|
|
|
|
*/
|
|
|
|
int max_args = 100;
|
|
|
|
char **args_array;
|
|
|
|
int args_count;
|
|
|
|
char *args_copy;
|
|
|
|
char *scanflag;
|
|
|
|
char *next_arg;
|
|
|
|
int i;
|
2005-12-28 16:33:08 +00:00
|
|
|
|
2014-06-10 14:32:52 +01:00
|
|
|
/* make a safe copy */
|
|
|
|
args_array = malloc (sizeof (char *) * max_args);
|
|
|
|
args_copy = (char *) malloc (arg_string_len + 1);
|
|
|
|
memcpy (args_copy, args_source, arg_string_len + 1);
|
2005-12-28 16:33:08 +00:00
|
|
|
|
2014-06-10 14:32:52 +01:00
|
|
|
for (i = 0; i < max_args; i++)
|
|
|
|
{
|
|
|
|
args_array[i] = "";
|
|
|
|
}
|
2005-12-28 16:33:08 +00:00
|
|
|
|
2014-06-10 14:32:52 +01:00
|
|
|
scanflag = args_copy;
|
|
|
|
args_count = 0;
|
|
|
|
/* ugly use of assignment in condition */
|
|
|
|
while (args_count < (max_args - 1))
|
|
|
|
{
|
|
|
|
next_arg = strtok (scanflag, "\t ");
|
|
|
|
scanflag = NULL; // needed for strtok() to work properly
|
|
|
|
if (next_arg != NULL)
|
2005-12-28 16:33:08 +00:00
|
|
|
{
|
2014-06-10 14:32:52 +01:00
|
|
|
args_count++;
|
|
|
|
args_array[args_count] = next_arg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
2005-12-28 16:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-10 14:32:52 +01:00
|
|
|
switches.argc = args_count + 1;
|
|
|
|
switches.argv = args_array;
|
|
|
|
process_switches (false);
|
2005-12-28 16:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:53:04 +00:00
|
|
|
//! Process environment
|
2005-04-10 16:30:47 +01:00
|
|
|
void
|
2012-12-14 22:53:04 +00:00
|
|
|
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
|
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);
|
2013-12-23 13:11:48 +00:00
|
|
|
printf (" http://www.cs.ox.ac.uk/people/cas.cremers/scyther/index.html\n");
|
2005-12-28 16:33:08 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-14 22:53:04 +00:00
|
|
|
return true;
|
2005-12-28 16:33:08 +00:00
|
|
|
}
|
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
|
|
|
}
|
2012-12-14 22:53:04 +00:00
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
// An error occurred: return false.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2005-04-10 16:30:47 +01:00
|
|
|
}
|