-# Copyright © 2011-2013, 2019-2022 Nick Bowler
+# Copyright © 2011-2013, 2019-2023 Nick Bowler
#
# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
# This is free software: you are free to do what the fuck you want to.
atlocal: config.status
$(AM_V_GEN) :; { \
printf ': "$${%s=%s}"\n' \
+ AWK '$(AWK)' \
EXEEXT '$(EXEEXT)' \
check_PROGRAMS '$(check_PROGRAMS)' \
; } >$@.tmp
/* --execute supersedes --filename */
if (filename && !execute) {
if (!freopen(filename, "r", stdin)) {
- print_error("failed to open %s: %s\n", filename,
+ print_error("failed to open %s: %s", filename,
strerror(errno));
return EXIT_FAILURE;
}
/*
* Main command implementation routines for cdecl99.
- * Copyright © 2011-2012, 2020-2021 Nick Bowler
+ * Copyright © 2011-2012, 2020-2021, 2023 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
decl = cdecl_parse_decl(arg);
if (!decl) {
- err = cdecl_get_error();
- print_error("%s", err->str);
+ print_error("%s", cdecl_get_error()->str);
goto out;
}
decl = cdecl_parse_decl(arg);
if (!decl) {
- err = cdecl_get_error();
- fprintf(stderr, "%s\n", err->str);
+ print_error("%s", cdecl_get_error()->str);
goto out;
}
int run_command_declare(const char *cmd)
{
- const struct cdecl_error *err;
struct cdecl *decl;
const char *str;
int ret = -1;
/* The name of the command is significant here. */
decl = cdecl_parse_english(cmd);
if (!decl) {
- err = cdecl_get_error();
- fprintf(stderr, "%s\n", err->str);
+ print_error("%s", cdecl_get_error()->str);
goto out;
}
]])
AT_CLEANUP
+
+AT_SETUP([cdecl99 --file error message])
+
+AT_CHECK([cdecl99 --file nonexistent || exit 42], [42], [], [stderr])
+AT_CHECK([grep -v nonexistent stderr || true])
+
+AT_CLEANUP
+
+AT_SETUP([cdecl99 command error messages])
+
+# Extract progname from --help usage message
+# This will only get the start of progname if it includes spaces;
+# so we won't worry too hard about the exact format later.
+AT_CHECK([LC_ALL=C cdecl99 --help], [0], [stdout])
+progname=`$AWK 'NR == 1 { print $2; }' stdout`
+
+# every line is erroneous
+AT_DATA([input],
+[[explain int a b c
+simplify int a b c
+declare a as b c
+]])
+
+AT_DATA([check.awk],
+[[BEGIN { status=0; }
+$1 == progname || $1 == (progname ":") { next; }
+{ status=1; print "unprefixed message on line", NR ":", $0; }
+END { exit(status); }
+]])
+
+AT_CHECK([LC_ALL=C cdecl99 --file=input || exit 42], [42], [], [stderr])
+AT_CHECK([$AWK -v progname="$progname" -f check.awk stderr])
+
+AT_CLEANUP