Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
sac-group
sac2c
Commits
96c87b17
Commit
96c87b17
authored
Jul 06, 2022
by
Michiel Verloop
Browse files
Rename all occurrences of first line and multiline header formats.
parent
4e4146cf
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/libsac2c/global/ctformatting.c
View file @
96c87b17
...
...
@@ -37,7 +37,7 @@ static char *processed_multi_line_format = NULL;
static
bool
initialized
=
false
;
static
char
*
current_
multi_line
_header
=
NULL
;
static
char
*
current_
continuation
_header
=
NULL
;
/** <!--********************************************************************-->
*
...
...
@@ -58,13 +58,13 @@ ProcessHeaders (void)
if
(
global
.
cti_single_line
)
{
// We shouldn't encounter \n in any of the headers, but it's not bad to account for it.
processed_header_format
=
STRsubstTokens
(
global
.
cti_header_format
,
2
,
"@"
,
" "
,
"
\n
"
,
" "
);
processed_header_format
=
STRsubstTokens
(
global
.
cti_
primary_
header_format
,
2
,
"@"
,
" "
,
"
\n
"
,
" "
);
}
else
{
processed_header_format
=
STRsubstToken
(
global
.
cti_header_format
,
"@"
,
"
\n
"
);
processed_header_format
=
STRsubstToken
(
global
.
cti_
primary_
header_format
,
"@"
,
"
\n
"
);
}
// Newlines in the
multi-line
header format lead to stupid results, so @ characters are
// Newlines in the
continuation
header format lead to stupid results, so @ characters are
// never converted to newlines, and newlines are always converted to spaces.
processed_multi_line_format
=
STRsubstToken
(
global
.
cti_
multi_line
_format
,
"
\n
"
,
" "
);
processed_multi_line_format
=
STRsubstToken
(
global
.
cti_
continuation_header
_format
,
"
\n
"
,
" "
);
}
...
...
@@ -73,11 +73,11 @@ ProcessHeaders (void)
* @fn void CTFcheckHeaderConsistency( char *header)
*
* @brief Checks whether the provided header is valid to be used as the
* global.cti_header_format or global.cti_
multiline
_format.
* global.cti_
primary_
header_format or global.cti_
continuation_header
_format.
*
* If the header is valid, the function returns void.
* If the header is invalid, the program gracefully aborts using the
* default
global header and multiline
format.
* default
primary and continuation header
format
s
.
*
* @param header The header to check.
******************************************************************************/
...
...
@@ -134,10 +134,10 @@ CTFcheckHeaderConsistency (char *header)
// Before we can raise the error, we have to replace the format with something that
// we know will work: the default error format.
MEMfree
(
global
.
cti_header_format
);
MEMfree
(
global
.
cti_
multi_line
_format
);
global
.
cti_header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
global
.
cti_
multi_line
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
MEMfree
(
global
.
cti_
primary_
header_format
);
MEMfree
(
global
.
cti_
continuation_header
_format
);
global
.
cti_
primary_
header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
global
.
cti_
continuation_header
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
ProcessHeaders
();
initialized
=
true
;
// Avoid initializing again for no reason
...
...
@@ -149,16 +149,16 @@ void
CTFinitialize
(
void
)
{
// If the headers don't exist, which can happen during unit-tests, we apply the default formats
if
(
global
.
cti_header_format
==
NULL
)
{
global
.
cti_header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
if
(
global
.
cti_
primary_
header_format
==
NULL
)
{
global
.
cti_
primary_
header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
}
if
(
global
.
cti_
multi_line
_format
==
NULL
)
{
global
.
cti_
multi_line
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
if
(
global
.
cti_
continuation_header
_format
==
NULL
)
{
global
.
cti_
continuation_header
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
}
// Gracefully aborts if the format is not invalid.
CTFcheckHeaderConsistency
(
global
.
cti_header_format
);
CTFcheckHeaderConsistency
(
global
.
cti_
multi_line
_format
);
CTFcheckHeaderConsistency
(
global
.
cti_
primary_
header_format
);
CTFcheckHeaderConsistency
(
global
.
cti_
continuation_header
_format
);
ProcessHeaders
();
...
...
@@ -168,10 +168,10 @@ CTFinitialize (void)
if
(
global
.
cti_single_line
)
{
// If either of the headers are not the default format and contain newlines,
// then warn that the newlines are replaced with a spaces.
if
((
!
STReq
(
global
.
cti_header_format
,
CTF_DEFAULT_FIRST_LINE_HEADER
)
&&
strchr
(
global
.
cti_header_format
,
'\n'
)
!=
NULL
)
||
(
!
STReq
(
global
.
cti_
multi_line
_format
,
CTF_DEFAULT_MULTI_LINE_HEADER
)
&&
strchr
(
global
.
cti_
multi_line
_format
,
'\n'
)
!=
NULL
))
{
if
((
!
STReq
(
global
.
cti_
primary_
header_format
,
CTF_DEFAULT_FIRST_LINE_HEADER
)
&&
strchr
(
global
.
cti_
primary_
header_format
,
'\n'
)
!=
NULL
)
||
(
!
STReq
(
global
.
cti_
continuation_header
_format
,
CTF_DEFAULT_MULTI_LINE_HEADER
)
&&
strchr
(
global
.
cti_
continuation_header
_format
,
'\n'
)
!=
NULL
))
{
CTIwarn
(
EMPTY_LOC
,
"Option -cti-single-line replaces newlines with spaces in the header formats."
);
}
...
...
@@ -181,8 +181,8 @@ CTFinitialize (void)
global
.
cti_message_length
=
0
;
}
if
(
!
STReq
(
global
.
cti_
multi_line
_format
,
CTF_DEFAULT_MULTI_LINE_HEADER
))
{
CTIwarn
(
EMPTY_LOC
,
"Option -cti-single-line makes option -cti-
multi-line
-format redundant."
);
if
(
!
STReq
(
global
.
cti_
continuation_header
_format
,
CTF_DEFAULT_MULTI_LINE_HEADER
))
{
CTIwarn
(
EMPTY_LOC
,
"Option -cti-single-line makes option -cti-
continuation-header
-format redundant."
);
}
}
}
...
...
@@ -243,7 +243,7 @@ InsertWrapLocations (char *buffer, size_t header_length, bool return_at_newline)
}
else
{
// Return at a newline if the parameter demands it.
// Note that continuing after the newline leads to problems if the header for the
// first line and the header for the
second
line have different lengths.
// first line and the header for the
remaining
line have different lengths.
if
(
buffer
[
index
]
==
'\n'
)
{
if
(
return_at_newline
)
{
DBUG_RETURN
();
...
...
@@ -321,15 +321,15 @@ Loc2buf (const struct location loc)
*
* @brief Produces a GNU format header of the location and message header.
* Formats that header using the processed header formats.
* It loads the
multiline
header into the current_
multi_line
_header variable,
* and returns the
first line
header.
* It loads the
continuation
header into the current_
continuation
_header variable,
* and returns the
primary
header.
*
* @param loc The location of the message.
* If no location is available or appropriate, NULL should be supplied.
* @param message_header The header of the message. Should be of the form "[A-Z][a-z]*".
* Examples are "Error", "Warn" and "Abort"
*
* @return A str_buf containing the
first line
header constructed from loc
* @return A str_buf containing the
primary
header constructed from loc
* and message_header in the GNU format.
*
******************************************************************************/
...
...
@@ -337,15 +337,15 @@ static str_buf *
CreateAndLoadGNUformatHeader
(
const
struct
location
loc
,
const
char
*
message_header
)
{
str_buf
*
base_header
;
str_buf
*
first_line
_header
;
str_buf
*
multi_line
_header
;
str_buf
*
primary
_header
;
str_buf
*
continuation
_header
;
size_t
len
;
DBUG_ENTER
();
// If this assert triggers, a call to CTFcreateMessageEnd is missing.
DBUG_ASSERT
(
current_
multi_line
_header
==
NULL
,
"Expected a deallocated current_
multi_line
_header, but it was allocated, "
DBUG_ASSERT
(
current_
continuation
_header
==
NULL
,
"Expected a deallocated current_
continuation
_header, but it was allocated, "
"leading to memory leaks."
);
base_header
=
Loc2buf
(
loc
);
...
...
@@ -360,18 +360,18 @@ CreateAndLoadGNUformatHeader (const struct location loc, const char *message_hea
// The base header is used to construct the header for the first and subsequent
// lines using the processed format string.
first_line
_header
=
SBUFcreate
(
0
);
SBUFprintf
(
first_line
_header
,
processed_header_format
,
SBUFgetBuffer
(
base_header
));
primary
_header
=
SBUFcreate
(
0
);
SBUFprintf
(
primary
_header
,
processed_header_format
,
SBUFgetBuffer
(
base_header
));
// Load the
multiline
header into the static variable current_
multi_line
_header.
// Load the
continuation
header into the static variable current_
continuation
_header.
// This prevents having to store the location/header on the calling side when invoking
// functions like CTIerrorContinued.
multi_line
_header
=
SBUFcreate
(
0
);
SBUFprintf
(
multi_line
_header
,
processed_multi_line_format
,
SBUFgetBuffer
(
base_header
));
current_
multi_line
_header
=
SBUF2strAndFree
(
&
multi_line
_header
);
continuation
_header
=
SBUFcreate
(
0
);
SBUFprintf
(
continuation
_header
,
processed_multi_line_format
,
SBUFgetBuffer
(
base_header
));
current_
continuation
_header
=
SBUF2strAndFree
(
&
continuation
_header
);
SBUFfree
(
base_header
);
DBUG_RETURN
(
first_line
_header
);
DBUG_RETURN
(
primary
_header
);
}
/** <!--********************************************************************-->
...
...
@@ -432,7 +432,7 @@ vCreateMessageBegin (str_buf **header, const char *format, va_list arg_p)
// If we call CTFcreateMessage, we want repeating newlines "\n\n" to also be respected.
// However, if the call to this function doesn't contain any newline, but would still
// process the remanining lines, the result would be something of the following form:
// concat(
first_line
_header, message,
multi_line
_header, newline)
// concat(
primary
_header, message,
continuation
_header, newline)
// Clearly, we don't want the multi_line header there.
if
(
!
SBUFisEmpty
(
remaining_lines
))
{
remaining_lines
=
CTFcreateMessageContinued
(
remaining_lines
);
...
...
@@ -444,20 +444,20 @@ vCreateMessageBegin (str_buf **header, const char *format, va_list arg_p)
/** <!--********************************************************************-->
* @fn str_buf *CTFCreateMessageBegin( str_buf **header,
* const char *
multi_line
_header,
* const char *
continuation
_header,
* const char *format, va_list arg_p)
*
* @brief Formats the message based on the given header and format string.
*
* @param header The header for the first line.
* @param
multi_line
_header The header for subsequent lines.
* @param
continuation
_header The header for subsequent lines.
* @param format The format on which to apply arg_p to generate the message.
* @param arg_p The arguments to apply to the format to generate the message.
*
* @return Returns the formatted message.
******************************************************************************/
str_buf
*
CTFcreateMessageBegin
(
str_buf
**
header
,
const
char
*
multi_line
_header
,
const
char
*
format
,
...)
CTFcreateMessageBegin
(
str_buf
**
header
,
const
char
*
continuation
_header
,
const
char
*
format
,
...)
{
str_buf
*
message
;
va_list
arg_p
;
...
...
@@ -465,10 +465,10 @@ CTFcreateMessageBegin (str_buf **header, const char *multi_line_header, const ch
DBUG_ENTER
();
// If this assert triggers, a call to CTFcreateMessageEnd is missing.
DBUG_ASSERT
(
current_
multi_line
_header
==
NULL
,
"Expected a deallocated current_
multi_line
_header, but it was allocated, "
DBUG_ASSERT
(
current_
continuation
_header
==
NULL
,
"Expected a deallocated current_
continuation
_header, but it was allocated, "
"leading to memory leaks."
);
current_
multi_line
_header
=
STRcpy
(
multi_line
_header
);
current_
continuation
_header
=
STRcpy
(
continuation
_header
);
va_start
(
arg_p
,
format
);
message
=
vCreateMessageBegin
(
header
,
format
,
arg_p
);
// frees header
...
...
@@ -528,10 +528,10 @@ CTFcreateMessageContinued (str_buf *remaining_lines)
DBUG_ENTER
();
DBUG_ASSERT
(
current_
multi_line
_header
!=
NULL
,
DBUG_ASSERT
(
current_
continuation
_header
!=
NULL
,
"Attempted to continue a message but there was no message to continue."
);
header_len
=
STRlen
(
current_
multi_line
_header
);
header_len
=
STRlen
(
current_
continuation
_header
);
InsertWrapLocations
(
SBUFgetBuffer
(
remaining_lines
),
header_len
,
false
);
message
=
SBUFcreate
(
SBUFlen
(
remaining_lines
));
...
...
@@ -545,9 +545,9 @@ CTFcreateMessageContinued (str_buf *remaining_lines)
}
else
{
// Before we add remaining_lines, we have to manually add the first header
// because remaining_lines doesn't start with a newline
SBUFprint
(
message
,
current_
multi_line
_header
);
SBUFprint
(
message
,
current_
continuation
_header
);
SBUFinsertAfterToken
(
remaining_lines
,
"
\n
"
,
current_
multi_line
_header
);
SBUFinsertAfterToken
(
remaining_lines
,
"
\n
"
,
current_
continuation
_header
);
}
SBUFprint
(
message
,
SBUFgetBuffer
(
remaining_lines
));
...
...
@@ -564,7 +564,7 @@ CTFcreateMessageContinued (str_buf *remaining_lines)
* @fn str_buf *CTFcreateMessageEnd( void)
*
* @brief Ends the message.
* Frees the static variable current_
multi_line
_header and sets it to NULL.
* Frees the static variable current_
continuation
_header and sets it to NULL.
*
* @return A str_buf containing "\n" if cti_single_line is enabled,
* an empty str_buf otherwise.
...
...
@@ -583,20 +583,20 @@ CTFcreateMessageEnd (void)
SBUFprint
(
end
,
"
\n
"
);
}
current_
multi_line
_header
=
MEMfree
(
current_
multi_line
_header
);
current_
continuation
_header
=
MEMfree
(
current_
continuation
_header
);
DBUG_RETURN
(
end
);
}
/** <!--********************************************************************-->
*
* @fn str_buf *vCreateMessage( str_buf *
first_line
_header,
* @fn str_buf *vCreateMessage( str_buf *
primary
_header,
* const char *format, va_list arg_p)
*
* @brief Creates a message based on the
first_line
header, the static
* variable current_
multi_line
_header,
and on
the format string,
* @brief Creates a message based on the
primary
header, the static
* variable current_
continuation
_header, the format string,
* and list of arguments for the format string.
*
* @param
first_line
_header The header for the first line of the message.
* @param
primary
_header The header for the first line of the message.
* @param format The format on which to apply the arguments.
* @param arg_p The arguments to apply onto the format.
*
...
...
@@ -604,7 +604,7 @@ CTFcreateMessageEnd (void)
*
******************************************************************************/
static
str_buf
*
vCreateMessage
(
const
char
*
first_line
_header
,
const
char
*
format
,
va_list
arg_p
)
vCreateMessage
(
const
char
*
primary
_header
,
const
char
*
format
,
va_list
arg_p
)
{
str_buf
*
header
;
str_buf
*
message
;
...
...
@@ -612,11 +612,11 @@ vCreateMessage (const char *first_line_header, const char *format, va_list arg_p
DBUG_ENTER
();
DBUG_ASSERT
(
current_
multi_line
_header
!=
NULL
,
DBUG_ASSERT
(
current_
continuation
_header
!=
NULL
,
"Attempted to create a message but not all information was present."
);
header
=
SBUFcreate
(
0
);
SBUFprint
(
header
,
first_line
_header
);
SBUFprint
(
header
,
primary
_header
);
message
=
vCreateMessageBegin
(
&
header
,
format
,
arg_p
);
// frees header
...
...
@@ -629,15 +629,15 @@ vCreateMessage (const char *first_line_header, const char *format, va_list arg_p
/** <!--********************************************************************-->
*
* @fn str_buf *CTFvCreateMessage( str_buf *
first_line
_header,
* const char *
multiline
_header,
* @fn str_buf *CTFvCreateMessage( str_buf *
primary
_header,
* const char *
continuation
_header,
* const char *format, va_list arg_p)
*
* @brief Creates a message based on the given headers, format string,
* and list of arguments for the format string.
*
* @param
first_line
_header The header for the first line of the message.
* @param
multiline
_header The header for subsequent lines of the message.
* @param
primary
_header The header for the first line of the message.
* @param
continuation
_header The header for subsequent lines of the message.
* @param format The format on which to apply the arguments.
* @param arg_p The arguments to apply onto the format.
*
...
...
@@ -645,27 +645,27 @@ vCreateMessage (const char *first_line_header, const char *format, va_list arg_p
*
******************************************************************************/
str_buf
*
CTFvCreateMessage
(
const
char
*
first_line
_header
,
const
char
*
multiline
_header
,
CTFvCreateMessage
(
const
char
*
primary
_header
,
const
char
*
continuation
_header
,
const
char
*
format
,
va_list
arg_p
)
{
DBUG_ENTER
();
// current_
multi_line
_header is always NULL at this point, no need to deallocate it.
current_
multi_line
_header
=
STRcpy
(
multiline
_header
);
DBUG_RETURN
(
vCreateMessage
(
first_line
_header
,
format
,
arg_p
));
// current_
continuation
_header is always NULL at this point, no need to deallocate it.
current_
continuation
_header
=
STRcpy
(
continuation
_header
);
DBUG_RETURN
(
vCreateMessage
(
primary
_header
,
format
,
arg_p
));
}
/** <!--********************************************************************-->
*
* @fn str_buf *CTFcreateMessage( str_buf *
first_line
_header,
* const char *
multiline
_header,
* @fn str_buf *CTFcreateMessage( str_buf *
primary
_header,
* const char *
continuation
_header,
* const char *format, ...)
*
* @brief Creates a message based on the given headers, format string,
* and list of arguments for the format string.
*
* @param
first_line
_header The header for the first line of the message.
* @param
multiline
_header The header for subsequent lines of the message.
* @param
primary
_header The header for the first line of the message.
* @param
continuation
_header The header for subsequent lines of the message.
* @param format The format on which to apply extra arguments to
* generate the message.
*
...
...
@@ -673,7 +673,7 @@ CTFvCreateMessage (const char *first_line_header, const char *multiline_header,
*
******************************************************************************/
str_buf
*
CTFcreateMessage
(
const
char
*
first_line
_header
,
const
char
*
multiline
_header
,
CTFcreateMessage
(
const
char
*
primary
_header
,
const
char
*
continuation
_header
,
const
char
*
format
,
...)
{
va_list
arg_p
;
...
...
@@ -682,7 +682,7 @@ CTFcreateMessage (const char *first_line_header, const char *multiline_header,
DBUG_ENTER
();
va_start
(
arg_p
,
format
);
message
=
CTFvCreateMessage
(
first_line_header
,
multiline
_header
,
format
,
arg_p
);
message
=
CTFvCreateMessage
(
primary_header
,
continuation
_header
,
format
,
arg_p
);
va_end
(
arg_p
);
DBUG_RETURN
(
message
);
...
...
@@ -709,16 +709,16 @@ str_buf *
CTFvCreateMessageLoc
(
struct
location
loc
,
const
char
*
message_header
,
const
char
*
format
,
va_list
arg_p
)
{
str_buf
*
first_line
_header
;
str_buf
*
primary
_header
;
str_buf
*
message
;
DBUG_ENTER
();
first_line
_header
=
CreateAndLoadGNUformatHeader
(
loc
,
message_header
);
primary
_header
=
CreateAndLoadGNUformatHeader
(
loc
,
message_header
);
message
=
vCreateMessage
(
SBUFgetBuffer
(
first_line
_header
),
format
,
arg_p
);
message
=
vCreateMessage
(
SBUFgetBuffer
(
primary
_header
),
format
,
arg_p
);
SBUFfree
(
first_line
_header
);
SBUFfree
(
primary
_header
);
DBUG_RETURN
(
message
);
}
...
...
src/libsac2c/global/ctformatting.h
View file @
96c87b17
...
...
@@ -11,15 +11,15 @@
extern
void
CTFinitialize
(
void
);
extern
void
CTFcheckHeaderConsistency
(
char
*
header
);
extern
str_buf
*
CTFcreateMessageBegin
(
str_buf
**
header
,
const
char
*
multiline
_header
,
const
char
*
format
,
...)
PRINTF_FORMAT
(
3
,
4
);
extern
str_buf
*
CTFcreateMessageBegin
(
str_buf
**
header
,
const
char
*
continuation
_header
,
const
char
*
format
,
...)
PRINTF_FORMAT
(
3
,
4
);
extern
str_buf
*
CTFvCreateMessageBeginLoc
(
const
struct
location
loc
,
const
char
*
message_header
,
const
char
*
format
,
va_list
arg_p
);
extern
str_buf
*
CTFcreateMessageContinued
(
str_buf
*
remaining_lines
);
extern
str_buf
*
CTFcreateMessageEnd
(
void
);
extern
str_buf
*
CTFvCreateMessage
(
const
char
*
first_line
_header
,
const
char
*
multiline
_header
,
extern
str_buf
*
CTFvCreateMessage
(
const
char
*
primary
_header
,
const
char
*
continuation
_header
,
const
char
*
format
,
va_list
arg_p
);
extern
str_buf
*
CTFcreateMessage
(
const
char
*
first_line
_header
,
const
char
*
multiline
_header
,
extern
str_buf
*
CTFcreateMessage
(
const
char
*
primary
_header
,
const
char
*
continuation
_header
,
const
char
*
format
,
...)
PRINTF_FORMAT
(
3
,
4
);
extern
str_buf
*
CTFvCreateMessageLoc
(
struct
location
loc
,
const
char
*
message_header
,
...
...
src/libsac2c/global/globals.c
View file @
96c87b17
...
...
@@ -682,8 +682,8 @@ GLOBinitializeGlobal (int argc, char *argv[], tool_t tool, const char *toolname)
if
(
!
global
.
cwd
)
CTIabort
(
EMPTY_LOC
,
"getcwd: %s"
,
strerror
(
errno
));
global
.
cti_header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
global
.
cti_
multi_line
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
global
.
cti_
primary_
header_format
=
STRcpy
(
CTF_DEFAULT_FIRST_LINE_HEADER
);
global
.
cti_
continuation_header
_format
=
STRcpy
(
CTF_DEFAULT_MULTI_LINE_HEADER
);
DBUG_RETURN
();
}
...
...
src/libsac2c/global/globals.mac
View file @
96c87b17
...
...
@@ -193,12 +193,12 @@ GLOBAL (bool, cti_single_line, FALSE, xfree_dummy, )
* suppresses newlines in cti messages
*/
GLOBAL (char *, cti_header_format, NULL, xfree_char_ptr, )
GLOBAL (char *, cti_
primary_
header_format, NULL, xfree_char_ptr, )
/*
* header spec for messages
*/
GLOBAL (char *, cti_
multi_line
_format, NULL, xfree_char_ptr, )
GLOBAL (char *, cti_
continuation_header
_format, NULL, xfree_char_ptr, )
/*
* spec for the beginning of trailing lines of multi-line messages
*/
...
...
src/libsac2c/global/options.c
View file @
96c87b17
...
...
@@ -716,9 +716,9 @@ AnalyseCommandlineSac2c (int argc, char *argv[])
ARGS_FLAG
(
"cti-single-line"
,
global
.
cti_single_line
=
TRUE
);
ARGS_OPTION
(
"cti-header-format"
,
global
.
cti_header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
primary-
header-format"
,
global
.
cti_
primary_
header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
multi-line
-format"
,
global
.
cti_
multi_line
_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
continuation-header
-format"
,
global
.
cti_
continuation_header
_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"ccflag"
,
CTIwarn
(
EMPTY_LOC
,
"Option -ccflag has been replaced by -Xc"
);
SBUFprintf
(
cflags_buf
,
" %s"
,
ARG
));
...
...
@@ -1474,9 +1474,9 @@ AnalyseCommandlineSac4c (int argc, char *argv[])
ARGS_FLAG
(
"cti-single-line"
,
global
.
cti_single_line
=
TRUE
);
ARGS_OPTION
(
"cti-header-format"
,
global
.
cti_header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
primary-
header-format"
,
global
.
cti_
primary_
header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
multi-line
-format"
,
global
.
cti_
multi_line
_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
continuation-header
-format"
,
global
.
cti_
continuation_header
_format
=
STRcpy
(
ARG
));
/*
* Options starting with ddddddddddddddddddddddddddddddddddddddddddd
...
...
@@ -1747,9 +1747,9 @@ AnalyseCommandlineSac2tex (int argc, char *argv[])
ARGS_FLAG
(
"cti-single-line"
,
global
.
cti_single_line
=
TRUE
);
ARGS_OPTION
(
"cti-header-format"
,
global
.
cti_header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
primary-
header-format"
,
global
.
cti_
primary_
header_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
multi-line
-format"
,
global
.
cti_
multi_line
_format
=
STRcpy
(
ARG
));
ARGS_OPTION
(
"cti-
continuation-header
-format"
,
global
.
cti_
continuation_header
_format
=
STRcpy
(
ARG
));
ARGS_OPTION_BEGIN
(
"cppI"
)
{
...
...
src/libsac2c/global/usage.c
View file @
96c87b17
...
...
@@ -1060,7 +1060,7 @@ PrintCompiletimeMessagingOptions (void)
" Omits all line breaks within messages and
\n
"
" sets -cti-message-length 0.
\n
"
"
\n
"
" -cti-header-format <string>
\n
"
" -cti-
primary-
header-format <string>
\n
"
" Customize the header of the first line of all message types.
\n
"
" The string must contain exactly one '%%s` which will be
\n
"
" replaced by a possible location (GNU format), followed by
\n
"
...
...
@@ -1069,8 +1069,8 @@ PrintCompiletimeMessagingOptions (void)
" line breaks.
\n
"
" (default:
\"
%s
\"
)
\n
"
"
\n
"
" -cti-
multi-line
-format <string>
\n
"
" Customize the header of
continuation
lines in multi-line
\n
"
" -cti-
continuation-header
-format <string>
\n
"
" Customize the header of
the remaining
lines in multi-line
\n
"
" messages.
\n
"
" The string must contain exactly one '%%s` which will be
\n
"
" replaced by a possible location (GNU format), followed by
\n
"
...
...
@@ -1079,7 +1079,7 @@ PrintCompiletimeMessagingOptions (void)
" Note that
\"
%%.s
\"
or
\"
%%.0s
\"
allows the location and
\n
"
" message type to be omitted.
\n
"
" This is done with the default value:
\"
%s
\"
.
\n
"
,
global
.
cti_message_length
,
global
.
cti_header_format
,
global
.
cti_
multi_line
_format
);
global
.
cti_message_length
,
global
.
cti_
primary_
header_format
,
global
.
cti_
continuation_header
_format
);
DBUG_RETURN
();
}
...
...
src/tests/test-compile-time-formatting.cpp
View file @
96c87b17
...
...
@@ -21,13 +21,13 @@ extern "C" {
// A function to call CTFcreateMessageContinued more conveniently during the tests
// without exposing additional API.
static
str_buf
*
CTFcreateMessageContinuedRaw
(
const
char
*
multiline
_header
,
str_buf
*
remaining_lines
)
CTFcreateMessageContinuedRaw
(
const
char
*
continuation
_header
,
str_buf
*
remaining_lines
)
{
str_buf
*
primary_header
;
str_buf
*
message
;
primary_header
=
SBUFcreate
(
0
);
SBUFfree
(
CTFcreateMessageBegin
(
&
primary_header
,
multiline
_header
,
"%s"
,
""
));
SBUFfree
(
CTFcreateMessageBegin
(
&
primary_header
,
continuation
_header
,
"%s"
,
""
));
message
=
CTFcreateMessageContinued
(
remaining_lines
);
SBUFfree
(
CTFcreateMessageEnd
());
...
...
@@ -53,7 +53,7 @@ TEST (CTF, testCreateMessageBeginSingleLineNoWrapping)
fprintf
(
stderr
,
"%s
\n
"
,
SBUFgetBuffer
(
header
));
#pragma GCC diagnostic ignored "-Wformat-zero-length"
message
=
CTFcreateMessageBegin
(
&
header
,
""
,
""
);
SBUFfree
(
CTFcreateMessageEnd
());
// Free the
multiline
header that CTFcreateMessageBegin allocates
SBUFfree
(
CTFcreateMessageEnd
());
// Free the
continuation
header that CTFcreateMessageBegin allocates
#pragma GCC diagnostic warning "-Wformat-zero-length"
EXPECT_TRUE
(
SBUFisEmpty
(
message
));
EXPECT_TRUE
(
header
==
NULL
);
...
...
@@ -66,7 +66,7 @@ TEST (CTF, testCreateMessageBeginSingleLineNoWrapping)
EXPECT_STREQ
(
"A normal yet fabulous test."
,
SBUFgetBuffer
(
message
));
SBUFfree
(
message
);
// Ensure that multiline messages are still printed on one line
// Ensure that multi
-
line messages are still printed on one line
header
=
SBUFcreate
(
0
);
message
=
CTFcreateMessageBegin
(
&
header
,
""
,
"A
\n
message
\n
containing%sspaces"
,
"
\n
many
\n
"
);
SBUFfree
(
CTFcreateMessageEnd
());
...
...
@@ -107,8 +107,8 @@ TEST (CTF, testCreateMessageBeginMultiLineNoWrapping)
EXPECT_STREQ
(
"A normal test.
\n
"
,
SBUFgetBuffer
(
message
));
SBUFfree
(
message
);
// Ensure that the
first_line
_header is prepended only to the first line
// and that the
multi_line
_header is prepended to the other lines
// Ensure that the
primary
_header is prepended only to the first line
// and that the
continuation
_header is prepended to the other lines
header
=
SBUFcreate
(
0
);
SBUFprint
(
header
,
"Interesting header: "
);
message
=
CTFcreateMessageBegin
(
&
header
,
" "
,
"A
\n
Multiline
\n
Test"
);
...
...
@@ -401,9 +401,9 @@ TEST (CTF, testCreateMessageMultilineNoWrapping)
str_buf
*
message
;
// Ensure that the headers are properly printed after each newline
message
=
CTFcreateMessage
(
"First header: "
,
"
Multiline
header!"
,
"After each
\n
newline, we expect a
\n
multiline
header."
);
EXPECT_STREQ
(
"First header: After each
\n
Multiline
header!newline, we expect a
\n
Multiline header!multiline
header.
\n
"
,
message
=
CTFcreateMessage
(
"First header: "
,
"
Continuation
header!"
,
"After each
\n
newline, we expect a
\n
continuation
header."
);
EXPECT_STREQ
(
"First header: After each
\n
Continuation
header!newline, we expect a
\n
Continuation header!continuation
header.
\n
"
,
SBUFgetBuffer
(
message
));
SBUFfree
(
message
);
}
...
...
@@ -455,10 +455,10 @@ TEST (CTF, testCreateMessageLoc)
{
global
.
cti_single_line
=
true
;
global
.
cti_message_length
=
0
;
MEMfree
(
global
.
cti_header_format
);
MEMfree
(
global
.
cti_
multi_line
_format
);
global
.
cti_header_format
=
STRcpy
(
"%s: "
);
global
.
cti_
multi_line
_format
=
STRcpy
(
"%.0s "
);
MEMfree
(
global
.
cti_
primary_
header_format
);
MEMfree
(
global
.
cti_
continuation_header
_format
);
global
.
cti_
primary_
header_format
=
STRcpy
(
"%s: "
);
global
.
cti_
continuation_header
_format
=
STRcpy
(
"%.0s "
);
CTFinitialize
();
str_buf
*
message
;
...
...
@@ -488,22 +488,22 @@ TEST (CTF, testCreateMessageLoc)
// to spaces if cti_single_line is enabled.
global
.
cti_single_line
=
true
;
global
.
cti_message_length
=
0
;
MEMfree
(
global
.
cti_header_format
);
global
.
cti_header_format
=
STRcpy
(
"%s:@"
);
MEMfree
(
global
.
cti_
primary_
header_format
);
global
.
cti_
primary_
header_format
=
STRcpy
(
"%s:@"
);
CTFinitialize
();
message
=
CTFcreateMessageLoc
(
EMPTY_LOC
,
"Error"
,
"foo
\n
bar"
);
EXPECT_STREQ
(
"Error: foo bar
\n
"
,
SBUFgetBuffer
(
message
));
SBUFfree
(
message
);
// Ensure that *only* @ symbols the
first line
header are converted to newlines
// and ensure that @ symbols in the
multiline
header remain @ symbols.
// Ensure that *only* @ symbols
in
the
primary
header are converted to newlines
// and ensure that @ symbols in the
continuation
header remain @ symbols.
global
.
cti_single_line
=
false
;
global
.
cti_message_length
=
0
;
MEMfree
(
global
.
cti_header_format
);
MEMfree
(
global
.
cti_
multi_line
_format
);
global
.
cti_header_format
=
STRcpy
(
"%s:@First:"
);
global
.
cti_
multi_line
_format
=
STRcpy
(
"%.0sContinued:@"
);
MEMfree
(
global
.
cti_
primary_
header_format
);
MEMfree
(
global
.
cti_
continuation_header
_format
);
global
.
cti_
primary_
header_format
=
STRcpy
(
"%s:@First:"
);
global
.
cti_
continuation_header
_format
=
STRcpy
(
"%.0sContinued:@"
);
CTFinitialize
();
message
=
CTFcreateMessageLoc
(
EMPTY_LOC
,
"Error"
,
"foo
\n
bar"
);
...
...
tests/errors/test-error-generic.sac
View file @
96c87b17
// SAC_TEST|include common.mk
// SAC_TEST|SAC2C_FLAGS += -check tc -b 1:loc -printstart 1:loc -cti-message-length 1 -cti-header-format "%s begin----: " -cti-
multi-line
-format "%s continued: "
// SAC_TEST|SAC2C_FLAGS += -check tc -b 1:loc -printstart 1:loc -cti-message-length 1 -cti-
primary-
header-format "%s begin----: " -cti-
continuation-header
-format "%s continued: "
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
//