From: Robert Pengelly Date: Sun, 31 May 2026 11:44:08 +0000 (+0100) Subject: Added -fmax-errors X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=a41673c16c237c5106db8791d4a8e6c7e1bc700e;p=scc.git Added -fmax-errors --- diff --git a/cc.h b/cc.h index 791689c..d971fae 100755 --- a/cc.h +++ b/cc.h @@ -28,6 +28,7 @@ struct cc_state { int long64; int syntax; + unsigned long max_errors; long version; }; diff --git a/lib.c b/lib.c index c7051ac..bfa7a40 100755 --- a/lib.c +++ b/lib.c @@ -38,13 +38,14 @@ struct cc_option { #define CC_OPTION_NO_LEADING_UNDERSCORE 5 #define CC_OPTION_NO_LINEMARKERS 6 #define CC_OPTION_MASM 7 -#define CC_OPTION_MLONG64 8 -#define CC_OPTION_OUTFILE 9 -#define CC_OPTION_PEDANTIC 10 -#define CC_OPTION_PREPOCESS 11 -#define CC_OPTION_STD 12 -#define CC_OPTION_TRANDITIONAL_LINEMARKERS 13 -#define CC_OPTION_UNDEF 14 +#define CC_OPTION_MAX_ERRORS 8 +#define CC_OPTION_MLONG64 9 +#define CC_OPTION_OUTFILE 10 +#define CC_OPTION_PEDANTIC 11 +#define CC_OPTION_PREPOCESS 12 +#define CC_OPTION_STD 13 +#define CC_OPTION_TRANDITIONAL_LINEMARKERS 14 +#define CC_OPTION_UNDEF 15 static struct cc_option opts[] = { @@ -62,6 +63,7 @@ static struct cc_option opts[] = { { "-S", CC_OPTION_COMPILE, CC_OPTION_NO_ARG }, { "-fno-leading-underscore", CC_OPTION_NO_LEADING_UNDERSCORE, CC_OPTION_NO_ARG }, + { "-fmax-errors", CC_OPTION_MAX_ERRORS, CC_OPTION_EQUALS_ARG }, { "-mlong64", CC_OPTION_MLONG64, CC_OPTION_NO_ARG }, { "-masm", CC_OPTION_MASM, CC_OPTION_EQUALS_ARG }, @@ -114,9 +116,10 @@ static void print_usage (void) { fprintf (stderr, " .\n"); fprintf (stderr, " Currently only C89 and C90 are\n"); fprintf (stderr, " supported.\n"); - fprintf (stderr, " -masm= Output compatible syntax.\n"); + fprintf (stderr, " -masm= Output compatible syntax.\n"); fprintf (stderr, " Defaults to MASM but also supports\n"); fprintf (stderr, " GNU AT&T, GNU INTEL and NASM.\n"); + fprintf (stderr, " -fmax-errors= Stop execution after errros.\n"); fprintf (stderr, "\n"); fprintf (stderr, " -fno-leading-underscore Don't prefix symbols with an underscore.\n"); fprintf (stderr, " -mlong64 Convert long to 64-bit.\n"); @@ -409,6 +412,19 @@ void parse_args (int argc, char **argv, int optind) { } + case CC_OPTION_MAX_ERRORS: { + + if (!(state->max_errors = atol (optarg))) { + + report_at (program_name, 0, REPORT_ERROR, "invalid number for -fmax-errors="); + exit (EXIT_FAILURE); + + } + + break; + + } + case CC_OPTION_MLONG64: { state->long64 = 1; diff --git a/report.c b/report.c index caea66a..2206a2b 100755 --- a/report.c +++ b/report.c @@ -6,6 +6,7 @@ #include #include +#include "cc.h" #include "ll.h" #include "report.h" @@ -156,6 +157,10 @@ void report_at (const char *filename, unsigned long lineno, int type, const char va_start (ap, fmt); output_message (filename, lineno, 0, type, fmt, ap); va_end (ap); + + if (errors >= state->max_errors) { + exit (EXIT_FAILURE); + } } @@ -210,14 +215,9 @@ void report_line_at (const char *filename, unsigned long lineno, int type, const char *actual_line = get_actual_line (filename, lineno); - /*if (!(actual_line = get_actual_line (filename, lineno))) { - - filename = get_real_filename (); - lineno += (get_real_line_number () - lineno); - - }*/ - - if (str && caret) { idx = (caret - str) + 1; } + if (str && caret) { + idx = (caret - str) + 1; + } va_start (ap, fmt); output_message (filename, lineno, idx, type, fmt, ap); @@ -252,34 +252,12 @@ void report_line_at (const char *filename, unsigned long lineno, int type, const fprintf (stderr, "^\n"); free (actual_line); - }/* else { - - if (lineno > 0) { - ident = fprintf (stderr, " %8lu | ", lineno); - } else { - ident = fprintf (stderr, "%*s", 12, ""); - } - - fprintf (stderr, "%s", str); - - if (str[strlen (str) - 1] != '\n') { - fprintf (stderr, "\n"); - } - - len = (idx + ident) - 1; - - for (i = 0; i < ident; i++) { - putc (' ', stderr); - } - - for (; i < len; i++) { - putc ('-', stderr); - } - - fprintf (stderr, "^\n"); - - }*/ + } + + } + if (errors >= state->max_errors) { + exit (EXIT_FAILURE); } }