Export account_output from output.c
Adjust calls to pass account variable explicitly.
Call it from lens_default as well.
diff --git a/lens_default.c b/lens_default.c
index 6e87a8e..fc8b0e4 100644
--- a/lens_default.c
+++ b/lens_default.c
@@ -107,19 +107,11 @@
#undef HANDLE_WIDTH
static int
-account(int *countp, int c)
-{
- if (c >= 0)
- *countp += c;
- return c;
-}
-
-static int
acc_fprintf(int *countp, FILE *stream, const char *format, ...)
{
va_list pa;
va_start(pa, format);
- int i = account(countp, vfprintf(stream, format, pa));
+ int i = account_output(countp, vfprintf(stream, format, pa));
va_end(pa);
return i;
@@ -181,7 +173,8 @@
{
int written = 0;
if (acc_fprintf(&written, stream, "'") < 0
- || account(&written, format_char(stream, value, arguments)) < 0
+ || account_output(&written,
+ format_char(stream, value, arguments)) < 0
|| acc_fprintf(&written, stream, "'") < 0)
return -1;
diff --git a/output.c b/output.c
index 3ae8f50..6dddb4d 100644
--- a/output.c
+++ b/output.c
@@ -238,18 +238,9 @@
}
static int
-account_output(int o)
-{
- if (o < 0)
- return -1;
- current_column += o;
- return 0;
-}
-
-static int
output_error(void)
{
- return account_output(fprintf(options.output, "?"));
+ return account_output(¤t_column, fprintf(options.output, "?"));
}
static int
@@ -396,7 +387,7 @@
output_one(struct value *val, struct value_dict *arguments)
{
int o = format_argument(options.output, val, arguments);
- if (account_output(o) < 0) {
+ if (account_output(¤t_column, o) < 0) {
if (output_error() < 0)
return -1;
o = 1;
@@ -412,7 +403,8 @@
int need_delim = *need_delimp;
for (i = start; i < end; ++i) {
if (need_delim
- && account_output(fprintf(options.output, ", ")) < 0)
+ && account_output(¤t_column,
+ fprintf(options.output, ", ")) < 0)
return -1;
struct value *value = val_dict_get_num(arguments, i);
if (value == NULL)
@@ -452,7 +444,8 @@
if (options.demangle)
name = my_demangle(function_name);
#endif
- if (account_output(fprintf(options.output, "%s(", name)) < 0)
+ if (account_output(¤t_column,
+ fprintf(options.output, "%s(", name)) < 0)
return;
func = name2func(function_name);
@@ -610,6 +603,14 @@
current_column = 0;
}
+int
+account_output(int *countp, int c)
+{
+ if (c > 0)
+ *countp += c;
+ return c;
+}
+
static void
do_report(const char *filename, unsigned line_no, const char *severity,
const char *fmt, va_list args)
diff --git a/output.h b/output.h
index 314bef1..c1a323f 100644
--- a/output.h
+++ b/output.h
@@ -28,6 +28,9 @@
void output_right(enum tof type, struct Process *proc,
struct library_symbol *libsym);
+/* If C is positive, add it to *COUNTP. Returns C. */
+int account_output(int *countp, int c);
+
void report_error(char const *file, unsigned line_no, const char *fmt, ...);
void report_warning(char const *file, unsigned line_no, const char *fmt, ...);
void report_global_error(const char *fmt, ...);