aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-28 20:11:01 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-28 20:11:01 +0100
commit65ebd61f1ade1724afb23c7a20a204a960b30d17 (patch)
tree9d3bc4caacfa2aa7789a4ff8870e3ec1f70c6410 /src/mds-kbdc
parentmisc (diff)
downloadmds-65ebd61f1ade1724afb23c7a20a204a960b30d17.tar.gz
mds-65ebd61f1ade1724afb23c7a20a204a960b30d17.tar.bz2
mds-65ebd61f1ade1724afb23c7a20a204a960b30d17.tar.xz
mds-kbdc: split mds_kbdc_parse_error_print so that the print and the description formation are separate procedures
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r--src/mds-kbdc/parse-error.c86
1 files changed, 51 insertions, 35 deletions
diff --git a/src/mds-kbdc/parse-error.c b/src/mds-kbdc/parse-error.c
index d08ac38..4d5ab9d 100644
--- a/src/mds-kbdc/parse-error.c
+++ b/src/mds-kbdc/parse-error.c
@@ -28,12 +28,59 @@
*
* @param this The error structure
* @param output The output file
+ * @parma desc The description of the error
*/
-void mds_kbdc_parse_error_print(const mds_kbdc_parse_error_t* restrict this, FILE* restrict output)
+static void print(const mds_kbdc_parse_error_t* restrict this, FILE* restrict output, const char* restrict desc)
{
size_t i, n, start = 0, end = 0;
- ssize_t m;
const char* restrict code = this->code;
+
+ /* Convert bytes count to character count for the code position. */
+ for (i = 0, n = this->start; i < n; i++)
+ if ((code[i] & 0xC0) != 0x80)
+ start++;
+ for (n = this->end; i < n; i++)
+ if ((code[i] & 0xC0) != 0x80)
+ end++;
+ end += start;
+
+ /* Print error information. */
+ fprintf(output, "\033[01m%s\033[21m:", this->pathname); /* TODO should be relative to the current dir */
+ if (this->error_is_in_file)
+ fprintf(output, "%zu:%zu–%zu:", this->line + 1, start, end);
+ switch (this->severity)
+ {
+ case MDS_KBDC_PARSE_ERROR_NOTE: fprintf(output, " \033[01;36mnote:\033[00m "); break;
+ case MDS_KBDC_PARSE_ERROR_WARNING: fprintf(output, " \033[01;35mwarning:\033[00m "); break;
+ case MDS_KBDC_PARSE_ERROR_ERROR: fprintf(output, " \033[01;31merror:\033[00m "); break;
+ case MDS_KBDC_PARSE_ERROR_INTERNAL_ERROR: fprintf(output, " \033[01;31minternal error:\033[00m "); break;
+ default:
+ abort();
+ break;
+ }
+ if (this->error_is_in_file)
+ {
+ fprintf(output, "%s\n %s\n \033[01;32m", desc, code);
+ i = 0;
+ for (n = start; i < n; i++) fputc(' ', output);
+ for (n = end; i < n; i++) fputc('^', output);
+ }
+ else
+ fprintf(output, "%s\n", desc);
+ fprintf(output, "\033[00m\n");
+}
+
+
+/**
+ * Print information about a parsing error
+ *
+ * @param this The error structure
+ * @param output The output file
+ */
+void mds_kbdc_parse_error_print(const mds_kbdc_parse_error_t* restrict this, FILE* restrict output)
+{
+ ssize_t m;
+ size_t n;
char* desc;
char* dend = this->description + strlen(this->description);
char* dstart;
@@ -71,39 +118,8 @@ void mds_kbdc_parse_error_print(const mds_kbdc_parse_error_t* restrict this, FIL
}
*dptr = '\0';
- /* Convert bytes count to character count for the code position. */
- for (i = 0, n = this->start; i < n; i++)
- if ((code[i] & 0xC0) != 0x80)
- start++;
- for (n = this->end; i < n; i++)
- if ((code[i] & 0xC0) != 0x80)
- end++;
- end += start;
-
- /* Print error information. */
- fprintf(output, "\033[01m%s\033[21m:", this->pathname); /* TODO should be relative to the current dir */
- if (this->error_is_in_file)
- fprintf(output, "%zu:%zu–%zu:", this->line + 1, start, end);
- switch (this->severity)
- {
- case MDS_KBDC_PARSE_ERROR_NOTE: fprintf(output, " \033[01;36mnote:\033[00m "); break;
- case MDS_KBDC_PARSE_ERROR_WARNING: fprintf(output, " \033[01;35mwarning:\033[00m "); break;
- case MDS_KBDC_PARSE_ERROR_ERROR: fprintf(output, " \033[01;31merror:\033[00m "); break;
- case MDS_KBDC_PARSE_ERROR_INTERNAL_ERROR: fprintf(output, " \033[01;31minternal error:\033[00m "); break;
- default:
- abort();
- break;
- }
- if (this->error_is_in_file)
- {
- fprintf(output, "%s\n %s\n \033[01;32m", desc, code);
- i = 0;
- for (n = start; i < n; i++) fputc(' ', output);
- for (n = end; i < n; i++) fputc('^', output);
- }
- else
- fprintf(output, "%s\n", desc);
- fprintf(output, "\033[00m\n");
+ /* Print the error. */
+ print(this, output, desc);
}