Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #891 #892

Merged
merged 9 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file.
As of v3.0.0 this project adheres to [Semantic Versioning](http://semver.org/). It follows [some conventions](http://keepachangelog.com/).

## [Unreleased][unreleased]

### Changed
- Command line output (help message, version message, error handling) has been improved, see [#891](https://github.com/gregorio-project/gregorio/issues/891)

## [4.1.0-beta2] - 2016-02-08
### Fixed
Expand Down
5 changes: 3 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl Gregorio
dnl Copyright (C) 2006-2015 The Gregorio Project (see CONTRIBUTORS.md)
dnl
dnl This file is part of Gregorio.
dnl
dnl
dnl Gregorio is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
Expand All @@ -16,9 +16,10 @@ dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Gregorio. If not, see <http://www.gnu.org/licenses/>.

AC_INIT([gregorio],[4.1.0-beta2],[gregorio-[email protected]])
AC_INIT([gregorio],[4.1.0-beta2],[https://github.com/gregorio-project/gregorio/issues],[gregorio],[http://gregorio-project.github.io/])
FILENAME_VERSION="4_1_0-beta2"
AC_SUBST(FILENAME_VERSION)
AC_DEFINE_UNQUOTED(FILENAME_VERSION, "$FILENAME_VERSION", [version suitable for file names])
MK=""
AC_SUBST(MK)
AC_PREREQ(2.59)
Expand Down
114 changes: 76 additions & 38 deletions src/gregorio-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2006-2015 The Gregorio Project (see CONTRIBUTORS.md)
*
* This file is part of Gregorio.
*
*
* Gregorio is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -161,54 +161,65 @@ static char *get_output_filename(char *fbasename, const char *extension)
return output_filename;
}

/*
* the type definitions of the function to read a score from a file, and to
* write a score to a file. Necessary for the libtool stuff...
*/

static void print_licence(void)
{
printf("\n\
Tools for manipulation of gregorian chant files\n\
Copyright (C) 2006-2015 Gregorio project authors (see CONTRIBUTORS.md)\n\
printf("Gregorio: Gregorian chant score engraving.\n\
%s\n\
\n\
This program is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n\
\n");
\n", copyright);
printf("This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
");
}

static void print_usage(char *name)
{
printf(_("\nUsage :\n%s [OPTION] {file}\n where OPTION is :\n\
\t-o file writes output to specified file\n\
\t-S writes output to stdout\n\
\t-F format specifies output file format (default: gtex)\n\
\t-l file writes messages output to specified file (default: stderr)\n\
\t-f format specifies input file format (default: gabc)\n\
\t-s reads input from stdin\n\
\t-p generate point-and-click information\n\
\t-h displays this message\n\
\t-V displays %s version\n"), name, name);
printf(_("\t-L displays licence\n\
\t-v verbose mode\n\
\t-W displays all warnings\n\
printf(_("Usage: %s [OPTION]... [-s | INPUT_FILE]\n\
\nEngrave Gregorian chant scores, convert a gabc file to GregorioTeX.\n\n\
Options:\n\
-o, --output-file FILE write output to FILE,\n\
default is basename(INPUT_FILE).FORMAT\n\
-S, --stdout write output to stdout\n\
-s, --stdin read input from stdin\n\
-l, --messages-file FILE output messages to FILE (default: stderr)\n\
-F, --output-format FORMAT\n\
specify output format (default: gtex)\n"), name);
printf(_(" -f, --input-format FORMAT\n\
specify input format (default: gabc)\n\
-p, --point-and-click generate Lilypond point and click information\n\
-h, --help print this help message\n\
-V, --version print version and exit\n"));
printf(_("\
-L, --license print licence\n\
-v, --verbose verbose mode\n\
-W, --all-warnings output warnings\n\
-d, --debug output debug information\n\
\n\
Formats:\n\
gabc gabc\n\
gtex GregorioTeX\n\
dump plain text dump (for debugging purpose)\n\
\n\
available formats are:\n\
\t gabc gabc\n\
\t gtex GregorioTeX\n\
\t dump simple text dump (for debugging purpose)\n\
See <" PACKAGE_URL "> for general documentation,\n\
GregorioRef-" FILENAME_VERSION ".pdf and GregorioNabcRef-" FILENAME_VERSION ".pdf for full documentation.\
\n"));
}

static void print_short_usage(char *name)
{
fprintf(stderr, "Usage: %s [OPTION]... [-s | INPUT_FILE]\n\
Try '%s --help' for more information.\n", name, name);
}

static void check_input_clobber(char *input_file_name, char *output_file_name)
{
if (input_file_name && output_file_name) {
Expand Down Expand Up @@ -316,6 +327,7 @@ int main(int argc, char **argv)
bool point_and_click = false;
char *point_and_click_filename = NULL;
bool debug = false;
bool must_print_short_usage = false;
int option_index = 0;
static struct option long_options[] = {
{"output-file", 1, 0, 'o'},
Expand All @@ -337,7 +349,8 @@ int main(int argc, char **argv)
gregorio_support_init("gregorio", argv[0]);

if (argc == 1) {
print_usage(argv[0]);
fprintf(stderr, "%s: missing file operand.\n", argv[0]);
print_short_usage(argv[0]);
gregorio_exit(0);
}
setlocale(LC_CTYPE, "C");
Expand All @@ -353,11 +366,13 @@ int main(int argc, char **argv)
fprintf(stderr,
"warning: several output files declared, %s taken\n",
output_file_name);
must_print_short_usage = true;
break;
}
if (output_file) { /* means that stdout is defined */
fprintf(stderr,
"warning: can't write to file and stdout, writing on stdout\n");
must_print_short_usage = true;
break;
}
output_file_name = optarg;
Expand All @@ -367,10 +382,12 @@ int main(int argc, char **argv)
fprintf(stderr,
"warning: can't write to file and stdout, writing on %s\n",
output_file_name);
must_print_short_usage = true;
break;
}
if (output_file) { /* means that stdout is defined */
fprintf(stderr, "warning: option used two times: %c\n", c);
fprintf(stderr, "warning: option used several times: %c\n", c);
must_print_short_usage = true;
break;
}
output_file = stdout;
Expand All @@ -379,6 +396,7 @@ int main(int argc, char **argv)
if (output_format) {
fprintf(stderr,
"warning: several output formats declared, first taken\n");
must_print_short_usage = true;
break;
}
if (!strcmp(optarg, GABC_STR)) {
Expand All @@ -394,6 +412,7 @@ int main(int argc, char **argv)
break;
} else {
fprintf(stderr, "error: unknown output format: %s\n", optarg);
print_short_usage(argv[0]);
gregorio_exit(1);
}
break;
Expand All @@ -402,6 +421,7 @@ int main(int argc, char **argv)
fprintf(stderr,
"warning: several error files declared, %s taken\n",
error_file_name);
must_print_short_usage = true;
break;
}
error_file_name = optarg;
Expand All @@ -411,13 +431,15 @@ int main(int argc, char **argv)
gregorio_set_error_out(error_file);
fprintf(stderr,
"warning: several output formats declared, first taken\n");
must_print_short_usage = true;
break;
}
if (!strcmp(optarg, GABC_STR)) {
input_format = GABC;
break;
} else {
fprintf(stderr, "error: unknown input format: %s\n", optarg);
print_short_usage(argv[0]);
gregorio_exit(1);
}
break;
Expand All @@ -426,7 +448,8 @@ int main(int argc, char **argv)
* we use getopt_long */
assert(!input_file_name);
if (input_file) { /* means that stdin is defined */
fprintf(stderr, "warning: option used two times: %c\n", c);
fprintf(stderr, "warning: option used several times: %c\n", c);
must_print_short_usage = true;
break;
}
input_file = stdin;
Expand All @@ -441,15 +464,17 @@ int main(int argc, char **argv)
break;
case 'v':
if (verb_mode && verb_mode != VERBOSITY_WARNING) {
fprintf(stderr, "warning: verbose option passed two times\n");
fprintf(stderr, "warning: verbose option passed several times\n");
must_print_short_usage = true;
break;
}
verb_mode = VERBOSITY_INFO;
break;
case 'W':
if (verb_mode == VERBOSITY_WARNING) {
fprintf(stderr,
"warning: all-warnings option passed two times\n");
"warning: all-warnings option passed several times\n");
must_print_short_usage = true;
break;
}
if (verb_mode != VERBOSITY_INFO) {
Expand All @@ -463,54 +488,65 @@ int main(int argc, char **argv)
case 'p':
if (point_and_click) {
fprintf(stderr,
"warning: point-and-click option passed two times\n");
"warning: point-and-click option passed several times\n");
must_print_short_usage = true;
break;
}
point_and_click = true;
break;
case 'd':
if (debug) {
fprintf(stderr,
"warning: debug option passed two times\n");
"warning: debug option passed several times\n");
must_print_short_usage = true;
break;
}
debug = true;
break;
case '?':
must_print_short_usage = true;
break;
default:
/* not reachable unless there's a programming error */
/* LCOV_EXCL_START */
gregorio_fail2(main, "unknown option: %c", c);
print_short_usage(argv[0]);
gregorio_exit(1);
break;
/* LCOV_EXCL_STOP */
}
} /* end of while */
if (optind == argc) {
if (!input_file) { /* input not undefined (could be stdin) */
fprintf(stderr, "error: no input file specified\n");
print_usage(argv[0]);
fprintf(stderr, "%s: missing file operand.\n", argv[0]);
print_short_usage(argv[0]);
gregorio_exit(1);
}
} else {
input_file_name = argv[optind++];
output_basename = get_base_filename(input_file_name);
if (input_file) {
fprintf(stderr,
"warning: can't read from stdin and a file, reading from file %s\n",
"warning: can't read from both stdin and a file, reading from %s\n",
input_file_name);
input_file = NULL;
must_print_short_usage = true;
}
}
if (optind < argc) {
must_print_short_usage = true;
fprintf(stderr, "ignored arguments:");
for (; optind < argc; ++optind) {
fprintf(stderr, " %s", argv[optind]);
}
fprintf(stderr, "\n");
}

if (must_print_short_usage) {
print_short_usage(argv[0]);
fprintf(stderr, "Proceeding anyway...\n");
}

gregorio_set_debug_messages(debug);

if (!input_format) {
Expand Down Expand Up @@ -544,11 +580,13 @@ int main(int argc, char **argv)
/* not reachable unless there's a programming error */
/* LCOV_EXCL_START */
fprintf(stderr, "error: unsupported format");
print_short_usage(argv[0]);
gregorio_exit(1);
/* LCOV_EXCL_STOP */
}
}
}

if (output_basename) {
free(output_basename);
}
Expand Down
7 changes: 5 additions & 2 deletions src/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ void gregorio_support_init(const char *const program USED_FOR_KPSE,
void gregorio_print_version(const char *copyright)
{
#ifdef USE_KPSE
printf("Gregorio version %s (%s).\n%s\n", GREGORIO_VERSION,
printf("Gregorio %s (%s).\n%s\n", GREGORIO_VERSION,
kpathsea_version_string, copyright);
#else
printf("Gregorio version %s.\n%s\n", GREGORIO_VERSION,
printf("Gregorio %s.\n%s\n", GREGORIO_VERSION,
copyright);
#endif
printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n");
}

#ifdef USE_KPSE
Expand Down