- Some work towards moving stderror output for non-linux things out of

the way.
This commit is contained in:
ccremers 2006-08-02 10:29:40 +00:00
parent 180d00ff41
commit 460c087cf2
8 changed files with 1232 additions and 1169 deletions

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include "debug.h"
#include "system.h"
#include "error.h"
static int debuglevel;
@ -45,7 +46,7 @@ debug (int level, char *string)
if (debugCond (level))
{
indent ();
fprintf (stderr, "DEBUG [%i]: %s\n", level, string);
printfstderr ("DEBUG [%i]: %s\n", level, string);
}
#endif
}

View File

@ -10,6 +10,27 @@ error_die (void)
exit (EXIT_ERROR);
}
//! print to stderror (must be generic to capture linux variants)
void
vprintfstderr (char *fmt, va_list args)
{
#ifdef linux
vfprintf (stderr, fmt, args);
#else
// nothing for non-linux yet
#endif
}
void
printfstderr (char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vprintfstderr (fmt, args);
va_end (args);
}
//! Print error message header
/**
* Adapted from [K&R2], p. 174
@ -18,7 +39,7 @@ error_die (void)
void
error_pre (void)
{
fprintf (stderr, "error: ");
printfstderr ("error: ");
}
//! Print post-error message and die.
@ -32,8 +53,8 @@ error_post (char *fmt, ...)
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
fprintf (stderr, "\n");
vprintfstderr (fmt, args);
printfstderr ("\n");
va_end (args);
exit (EXIT_ERROR);
}
@ -50,8 +71,8 @@ error (char *fmt, ...)
error_pre ();
va_start (args, fmt);
vfprintf (stderr, fmt, args);
fprintf (stderr, "\n");
vprintfstderr (fmt, args);
printfstderr ("\n");
va_end (args);
error_die ();
}
@ -66,8 +87,8 @@ warning (char *fmt, ...)
va_list args;
va_start (args, fmt);
fprintf (stderr, "warning: ");
vfprintf (stderr, fmt, args);
fprintf (stderr, "\n");
printfstderr ("warning: ");
vprintfstderr (fmt, args);
printfstderr ("\n");
va_end (args);
}

View File

@ -5,6 +5,8 @@
enum exittypes
{ EXIT_NOATTACK = 0, EXIT_ERROR = 1, EXIT_NOCLAIM = 2, EXIT_ATTACK = 3 };
void vprintfstderr (char *fmt, va_list args);
void printfstderr (char *fmt, ...);
void error_die (void);
void error_pre (void);
void error_post (char *fmt, ...);

View File

@ -258,7 +258,7 @@ modelCheck (const System sys)
if (switches.reportStates > 0)
{
// States: 1.000e+06
fprintf (stderr, " \r");
printfstderr (" \r");
}
if (claimcount == 0)

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
#include "pheading.h"
#include "tac.h"
#include "switches.h"
#include "error.h"
/* tokens for language */
#include "parser.h"
@ -63,7 +64,7 @@ include BEGIN(incl);
<incl>[^\"]+ { /* got the include file name */
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
{
fprintf( stderr, "Includes nested too deeply" );
printfstderr( "Includes nested too deeply" );
exit( 1 );
}

View File

@ -1231,8 +1231,8 @@ switcher (const int process, int index, int commandline)
/* try to open */
if (!freopen (arg_pointer, "w", stdout))
{
fprintf (stderr, "Could not create output file '%s'.\n",
arg_pointer);
printfstderr ("Could not create output file '%s'.\n",
arg_pointer);
exit (1);
}
arg_next ();
@ -1259,12 +1259,12 @@ switcher (const int process, int index, int commandline)
// The file was not found. We have two options...
if (this_arg[0] == '-')
{
fprintf (stderr, "Unknown switch '%s'.\n", this_arg);
printfstderr ("Unknown switch '%s'.\n", this_arg);
}
else
{
fprintf (stderr, "Could not open input file '%s'.\n",
this_arg);
printfstderr ("Could not open input file '%s'.\n",
this_arg);
}
exit (1);
}

View File

@ -318,7 +318,12 @@ getOutputStream (void)
if (globalError == 0)
return (FILE *) globalStream;
else
#ifdef linux
return stderr;
#else
// For non-linux, we simply omit it
return NULL;
#endif
}
//! Print out according to globalError
@ -336,9 +341,14 @@ void
eprintf (char *fmt, ...)
{
va_list args;
FILE *stream;
va_start (args, fmt);
vfprintf (getOutputStream (), fmt, args);
stream = getOutputStream ();
if (stream != NULL)
{
vfprintf (stream, fmt, args);
}
va_end (args);
}
@ -346,5 +356,11 @@ eprintf (char *fmt, ...)
void
veprintf (const char *fmt, va_list args)
{
vfprintf (getOutputStream (), fmt, args);
FILE *stream;
stream = getOutputStream ();
if (stream != NULL)
{
vfprintf (stream, fmt, args);
}
}