Skip to content

Commit

Permalink
New flag -fdiagnostics-absolute-path to display full paths within err…
Browse files Browse the repository at this point in the history
…or locations

This flag is useful for editors that cannot correctly locate files
with recursive build systems.
  • Loading branch information
lefessan committed Oct 2, 2023
1 parent c0d64ad commit 09cd572
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

2023-10-02 Fabrice Le Fessant <fabrice.le_fessant@ocamlpro.com>

* error.c (print_error_prefix), flag.def: add new flag
-fdiagnostics-absolute-path to print the full path of
a file in case of error. This flag can be activated if
your editor and build system do not correctly work
together to locate files after errors within your project.

2023-07-26 Simon Sobisch <simonsobisch@gnu.org>

* typeck.c (search_set_keys): improving SEARCH ALL syntax checks
Expand Down
24 changes: 24 additions & 0 deletions cobc/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/stat.h>

#include "cobc.h"
#include "tree.h"
Expand Down Expand Up @@ -57,13 +58,36 @@ static void
print_error_prefix (const char *file, int line, const char *prefix)
{
if (file) {
char *absfile = NULL ;
if (cb_diagnostics_absolute_path
&& strcmp (file, COB_DASH) != 0
&& file[0] != '/'
&& file[0] != '\\'
&& ( file[0] != 0 && file[1] != ':' )
){
int filelen = strlen (file);
int dirlen = 256;
char *cwd ;
absfile = cobc_malloc( dirlen + 1 + filelen + 1 );
cwd = getcwd (absfile, dirlen);
if (cwd != NULL ){
struct stat st;
dirlen = strlen (cwd);
absfile[dirlen] = '/';
memcpy (absfile+dirlen+1, file, filelen+1);
if (!stat(absfile,&st)){
file = absfile;
}
}
}
if (line <= 0) {
fprintf (stderr, "%s: ", file);
} else if (cb_msg_style == CB_MSG_STYLE_MSC) {
fprintf (stderr, "%s(%d): ", file, line);
} else {
fprintf (stderr, "%s:%d: ", file, line);
}
if (absfile) cobc_free (absfile);
}
if (prefix) {
fprintf (stderr, "%s", prefix);
Expand Down
3 changes: 3 additions & 0 deletions cobc/flag.def
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,6 @@ CB_FLAG_ON (cb_diagnostics_show_caret, 1, "diagnostics-show-caret",

CB_FLAG_ON (cb_diagnostics_show_line_numbers, 1, "diagnostics-show-line-numbers",
_(" -fno-diagnostics-show-line-numbers\tsuppress display of line numbers in diagnostics"))

CB_FLAG (cb_diagnostics_absolute_path, 1, "diagnostics-absolute-path",
_(" -fdiagnostics-absolute-path\tdisplay paths with absolute paths"))

0 comments on commit 09cd572

Please sign in to comment.