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

View File

@ -10,6 +10,27 @@ error_die (void)
exit (EXIT_ERROR); 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 //! Print error message header
/** /**
* Adapted from [K&R2], p. 174 * Adapted from [K&R2], p. 174
@ -18,7 +39,7 @@ error_die (void)
void void
error_pre (void) error_pre (void)
{ {
fprintf (stderr, "error: "); printfstderr ("error: ");
} }
//! Print post-error message and die. //! Print post-error message and die.
@ -32,8 +53,8 @@ error_post (char *fmt, ...)
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
vfprintf (stderr, fmt, args); vprintfstderr (fmt, args);
fprintf (stderr, "\n"); printfstderr ("\n");
va_end (args); va_end (args);
exit (EXIT_ERROR); exit (EXIT_ERROR);
} }
@ -50,8 +71,8 @@ error (char *fmt, ...)
error_pre (); error_pre ();
va_start (args, fmt); va_start (args, fmt);
vfprintf (stderr, fmt, args); vprintfstderr (fmt, args);
fprintf (stderr, "\n"); printfstderr ("\n");
va_end (args); va_end (args);
error_die (); error_die ();
} }
@ -66,8 +87,8 @@ warning (char *fmt, ...)
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
fprintf (stderr, "warning: "); printfstderr ("warning: ");
vfprintf (stderr, fmt, args); vprintfstderr (fmt, args);
fprintf (stderr, "\n"); printfstderr ("\n");
va_end (args); va_end (args);
} }

View File

@ -5,6 +5,8 @@
enum exittypes enum exittypes
{ EXIT_NOATTACK = 0, EXIT_ERROR = 1, EXIT_NOCLAIM = 2, EXIT_ATTACK = 3 }; { 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_die (void);
void error_pre (void); void error_pre (void);
void error_post (char *fmt, ...); void error_post (char *fmt, ...);

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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