Skip to content

Commit

Permalink
Small fixes around -fdiagnostics-absolute-paths and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Oct 19, 2023
1 parent be31cf1 commit 17dc9d6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3565,6 +3565,8 @@ process_command_line (const int argc, char **argv)
/* -fdiagnostics-plain-output */
cb_diagnostics_show_caret = 0 ;
cb_diagnostics_show_line_numbers = 0;
/* in the future, may also disable urls,
colors, text art, flow paths */
break;

case 'P':
Expand Down
16 changes: 15 additions & 1 deletion cobc/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

#include "cobc.h"
#include "tree.h"

#ifdef _WIN32
#if !defined(__BORLANDC__) && !defined(__WATCOMC__) && !defined(__ORANGEC__)
#include <direct.h> // _getcwd
#define getcwd _getcwd
#endif
#endif

enum cb_error_kind {
CB_KIND_ERROR,
CB_KIND_WARNING,
Expand Down Expand Up @@ -70,11 +79,16 @@ print_error_prefix (const char *file, int line, const char *prefix)
absfile = cobc_malloc( dirlen + 1 + filelen + 1 );
cwd = getcwd (absfile, dirlen);
if (cwd != NULL ){
#ifdef HAVE_SYS_STAT_H
struct stat st;
#endif
dirlen = strlen (cwd);
absfile[dirlen] = '/';
memcpy (absfile+dirlen+1, file, filelen+1);
if (!stat(absfile,&st)){
#ifdef HAVE_SYS_STAT_H
if (!stat (absfile,&st))
#endif
{
file = absfile;
}
}
Expand Down
29 changes: 29 additions & 0 deletions doc/gnucobol.texi
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ A complete list of options can be displayed by using the option @option{--help}.
* Build target:: Build target
* Source format:: Source format
* Warning options:: Warning options
* Diagnostics options:: Diagnostics options
* Configuration options:: Configuration options
* Listing options:: Listing options
* Debug switches:: Debug switches
Expand Down Expand Up @@ -651,6 +652,34 @@ Warn if statements are likely unreachable. This is @emph{not} set with @option{-
Enable warnings that don't have an own warning flag.
@end table

@node Diagnostics options
@subsection Diagnostics options

The compiler provides some options to tune the way errors and warnings
(diagnostics) are displayed to the user.

@table @code

@item -fdiagnostics-absolute-paths
Print absolute paths in diagnostics. This option can be useful if your editor is not able
to correctly locate relative paths in your project.

@item -fdiagnostics-plain-output
Make diagnostic output as plain as possible.

@item -fno-diagnostics-show-option
Suppress output of option that directly controls the diagnostic, on which
warnings should be displayed.

@item -fno-diagnostics-show-caret
Do not display source context on warning/error diagnostic. By default, diagnostics
contain an excerpt with two lines before and after the location.

@item -fno-diagnostics-show-line-numbers
Suppress display of line numbers in the source context in diagnostics

@end table

@node Configuration options
@subsection Configuration options

Expand Down
22 changes: 12 additions & 10 deletions tests/testsuite.src/used_binaries.at
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,9 @@ AT_CLEANUP


AT_SETUP([cobc diagnostics show caret])
#AT_KEYWORDS([cobc diagnostics])

AT_DATA([progprep.cob],[
#AT_KEYWORDS([cobc diagnostics])
AT_DATA([progprep.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
Expand All @@ -941,13 +941,15 @@ AT_DATA([progprep.cob],[
])

# Testcase includes trailing whitespace, setup by dropping '#'

AT_CHECK([cat progprep.cob | tr -d '#' > prog.cob])

AT_CHECK([$COBC -fdiagnostics-plain-output -Wall prog.cob], [1], [],
[[prog.cob:7: error: CRUD.CPY: No such file or directory
prog.cob:6: warning: numeric value is expected [-Wothers]
prog.cob:14: warning: ignoring redundant . [-Wothers]
]])

AT_CHECK([$COBC -fdiagnostics-show-caret -fdiagnostics-show-line-numbers prog.cob], [1], [],
[[prog.cob:7: error: CRUD.CPY: No such file or directory
5 | WORKING-STORAGE SECTION.
Expand Down Expand Up @@ -989,24 +991,24 @@ prog.cob:14: warning: ignoring redundant . [-Wothers]
]])

# Testcase for line too long and printing only one line
AT_DATA([longgy.cob],[ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
AT_DATA([longgy.cob], [ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
])

# note: this is actually an error in the parser line number,
# but until that is solved, it is a nice edge case of "line not available"

AT_CHECK([$COBC -fdiagnostics-plain-output -fdiagnostics-show-caret -Wno-others longgy.cob], [1], [],
[[longgy.cob:2: error: PROGRAM-ID header missing
[longgy.cob:2: error: PROGRAM-ID header missing
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd..
> <EOF>
]])

])

AT_CHECK([$COBC -fdiagnostics-plain-output -fdiagnostics-absolute-paths -Wall prog.cob 2> compiler.output], [1])
AT_CHECK([$COMPILE -fdiagnostics-absolute-paths -Wall prog.cob 2> compiler.output], [1])

AT_CHECK([sed -e "s|$PWD|HOME|" compiler.output], [0],
AT_CHECK([$SED -e "s|$PWD|HOME|" compiler.output], [0],
[HOME/prog.cob:7: error: CRUD.CPY: No such file or directory
HOME/prog.cob:6: warning: numeric value is expected @<:@-Wothers@:>@
HOME/prog.cob:14: warning: ignoring redundant . @<:@-Wothers@:>@
HOME/prog.cob:6: warning: numeric value is expected
HOME/prog.cob:14: warning: ignoring redundant .
])

AT_CLEANUP
Expand Down

0 comments on commit 17dc9d6

Please sign in to comment.