normalize example exit status

Use EXIT_SUCCESS / EXIT_FAILURE in most cases as more granularity isn't
useful. For anim_diff, use 0 (success), 1 (image difference) and 2
(error) to align it with other diff utilities (diff, etc.).

Bug: webp:637
Change-Id: I52925de8622a5a4d2141883279d69a1d95ef9b12
This commit is contained in:
James Zern 2024-04-30 18:18:23 -07:00
parent edc289092a
commit a67ff735a2
19 changed files with 139 additions and 72 deletions

View File

@ -16,7 +16,7 @@
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> // for 'strtod'. #include <stdlib.h>
#include <string.h> // for 'strcmp'. #include <string.h> // for 'strcmp'.
#include "./anim_util.h" #include "./anim_util.h"
@ -206,8 +206,9 @@ static void Help(void) {
printf(" -version ............ print version number and exit\n"); printf(" -version ............ print version number and exit\n");
} }
// Returns 0 on success, 1 if animation files differ, and 2 for any error.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int return_code = -1; int return_code = 2;
int dump_frames = 0; int dump_frames = 0;
const char* dump_folder = NULL; const char* dump_folder = NULL;
double min_psnr = 0.; double min_psnr = 0.;
@ -269,18 +270,18 @@ int main(int argc, const char* argv[]) {
} }
if (parse_error) { if (parse_error) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(return_code);
} }
} }
if (argc < 3) { if (argc < 3) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(return_code);
} }
if (!got_input2) { if (!got_input2) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(return_code);
} }
if (dump_frames) { if (dump_frames) {
@ -293,7 +294,7 @@ int main(int argc, const char* argv[]) {
if (!ReadAnimatedImage(files[i], &images[i], dump_frames, dump_folder)) { if (!ReadAnimatedImage(files[i], &images[i], dump_frames, dump_folder)) {
WFPRINTF(stderr, "Error decoding file: %s\n Aborting.\n", WFPRINTF(stderr, "Error decoding file: %s\n Aborting.\n",
(const W_CHAR*)files[i]); (const W_CHAR*)files[i]);
return_code = -2; return_code = 2;
goto End; goto End;
} else { } else {
MinimizeAnimationFrames(&images[i], max_diff); MinimizeAnimationFrames(&images[i], max_diff);
@ -304,7 +305,7 @@ int main(int argc, const char* argv[]) {
premultiply, min_psnr)) { premultiply, min_psnr)) {
WFPRINTF(stderr, "\nFiles %s and %s differ.\n", (const W_CHAR*)files[0], WFPRINTF(stderr, "\nFiles %s and %s differ.\n", (const W_CHAR*)files[0],
(const W_CHAR*)files[1]); (const W_CHAR*)files[1]);
return_code = -3; return_code = 1;
} else { } else {
WPRINTF("\nFiles %s and %s are identical.\n", (const W_CHAR*)files[0], WPRINTF("\nFiles %s and %s are identical.\n", (const W_CHAR*)files[0],
(const W_CHAR*)files[1]); (const W_CHAR*)files[1]);

View File

@ -12,6 +12,7 @@
// Author: Skal (pascal.massimino@gmail.com) // Author: Skal (pascal.massimino@gmail.com)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> // for 'strcmp'. #include <string.h> // for 'strcmp'.
#include "./anim_util.h" #include "./anim_util.h"
@ -35,6 +36,7 @@ static void Help(void) {
printf(" -version ............ print version number and exit\n"); printf(" -version ............ print version number and exit\n");
} }
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int error = 0; int error = 0;
const W_CHAR* dump_folder = TO_W_CHAR("."); const W_CHAR* dump_folder = TO_W_CHAR(".");
@ -47,7 +49,7 @@ int main(int argc, const char* argv[]) {
if (argc < 2) { if (argc < 2) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
for (c = 1; !error && c < argc; ++c) { for (c = 1; !error && c < argc; ++c) {
@ -73,7 +75,7 @@ int main(int argc, const char* argv[]) {
suffix = TO_W_CHAR("pam"); suffix = TO_W_CHAR("pam");
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-version")) { } else if (!strcmp(argv[c], "-version")) {
int dec_version, demux_version; int dec_version, demux_version;
GetAnimatedImageVersions(&dec_version, &demux_version); GetAnimatedImageVersions(&dec_version, &demux_version);
@ -82,7 +84,7 @@ int main(int argc, const char* argv[]) {
(dec_version >> 0) & 0xff, (dec_version >> 0) & 0xff,
(demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff, (demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff,
(demux_version >> 0) & 0xff); (demux_version >> 0) & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else { } else {
uint32_t i; uint32_t i;
AnimatedImage image; AnimatedImage image;
@ -121,5 +123,5 @@ int main(int argc, const char* argv[]) {
ClearAnimatedImage(&image); ClearAnimatedImage(&image);
} }
} }
FREE_WARGV_AND_RETURN(error ? 1 : 0); FREE_WARGV_AND_RETURN(error ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -651,8 +651,9 @@ static const char* const kErrorMessages[VP8_ENC_ERROR_LAST] = {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int return_value = -1; int return_value = EXIT_FAILURE;
const char* in_file = NULL, *out_file = NULL, *dump_file = NULL; const char* in_file = NULL, *out_file = NULL, *dump_file = NULL;
FILE* out = NULL; FILE* out = NULL;
int c; int c;
@ -686,22 +687,22 @@ int main(int argc, const char* argv[]) {
!WebPPictureInit(&original_picture) || !WebPPictureInit(&original_picture) ||
!WebPConfigInit(&config)) { !WebPConfigInit(&config)) {
fprintf(stderr, "Error! Version mismatch!\n"); fprintf(stderr, "Error! Version mismatch!\n");
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
if (argc == 1) { if (argc == 1) {
HelpShort(); HelpShort();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} }
for (c = 1; c < argc; ++c) { for (c = 1; c < argc; ++c) {
int parse_error = 0; int parse_error = 0;
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
HelpShort(); HelpShort();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) { } else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
HelpLong(); HelpLong();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-o") && c + 1 < argc) { } else if (!strcmp(argv[c], "-o") && c + 1 < argc) {
out_file = (const char*)GET_WARGV(argv, ++c); out_file = (const char*)GET_WARGV(argv, ++c);
} else if (!strcmp(argv[c], "-d") && c + 1 < argc) { } else if (!strcmp(argv[c], "-d") && c + 1 < argc) {
@ -842,7 +843,7 @@ int main(int argc, const char* argv[]) {
printf("libsharpyuv: %d.%d.%d\n", printf("libsharpyuv: %d.%d.%d\n",
(sharpyuv_version >> 24) & 0xff, (sharpyuv_version >> 16) & 0xffff, (sharpyuv_version >> 24) & 0xff, (sharpyuv_version >> 16) & 0xffff,
sharpyuv_version & 0xff); sharpyuv_version & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-progress")) { } else if (!strcmp(argv[c], "-progress")) {
show_progress = 1; show_progress = 1;
} else if (!strcmp(argv[c], "-quiet")) { } else if (!strcmp(argv[c], "-quiet")) {
@ -904,7 +905,7 @@ int main(int argc, const char* argv[]) {
if (i == kNumTokens) { if (i == kNumTokens) {
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n", fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
(int)(token - start), start); (int)(token - start), start);
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
start = token + 1; start = token + 1;
} }
@ -923,14 +924,14 @@ int main(int argc, const char* argv[]) {
} else if (argv[c][0] == '-') { } else if (argv[c][0] == '-') {
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]); fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
HelpLong(); HelpLong();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} else { } else {
in_file = (const char*)GET_WARGV(argv, c); in_file = (const char*)GET_WARGV(argv, c);
} }
if (parse_error) { if (parse_error) {
HelpLong(); HelpLong();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
} }
if (in_file == NULL) { if (in_file == NULL) {
@ -1231,7 +1232,7 @@ int main(int argc, const char* argv[]) {
PrintMetadataInfo(&metadata, metadata_written); PrintMetadataInfo(&metadata, metadata_written);
} }
} }
return_value = 0; return_value = EXIT_SUCCESS;
Error: Error:
WebPMemoryWriterClear(&memory_writer); WebPMemoryWriterClear(&memory_writer);

View File

@ -177,6 +177,7 @@ static uint8_t* AllocateExternalBuffer(WebPDecoderConfig* config,
return external_buffer; return external_buffer;
} }
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int ok = 0; int ok = 0;
const char* in_file = NULL; const char* in_file = NULL;
@ -197,14 +198,14 @@ int main(int argc, const char* argv[]) {
if (!WebPInitDecoderConfig(&config)) { if (!WebPInitDecoderConfig(&config)) {
fprintf(stderr, "Library version mismatch!\n"); fprintf(stderr, "Library version mismatch!\n");
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
for (c = 1; c < argc; ++c) { for (c = 1; c < argc; ++c) {
int parse_error = 0; int parse_error = 0;
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-o") && c < argc - 1) { } else if (!strcmp(argv[c], "-o") && c < argc - 1) {
out_file = (const char*)GET_WARGV(argv, ++c); out_file = (const char*)GET_WARGV(argv, ++c);
} else if (!strcmp(argv[c], "-alpha")) { } else if (!strcmp(argv[c], "-alpha")) {
@ -227,7 +228,7 @@ int main(int argc, const char* argv[]) {
const int version = WebPGetDecoderVersion(); const int version = WebPGetDecoderVersion();
printf("%d.%d.%d\n", printf("%d.%d.%d\n",
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff); (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-pgm")) { } else if (!strcmp(argv[c], "-pgm")) {
format = PGM; format = PGM;
} else if (!strcmp(argv[c], "-yuv")) { } else if (!strcmp(argv[c], "-yuv")) {
@ -293,21 +294,21 @@ int main(int argc, const char* argv[]) {
} else if (argv[c][0] == '-') { } else if (argv[c][0] == '-') {
fprintf(stderr, "Unknown option '%s'\n", argv[c]); fprintf(stderr, "Unknown option '%s'\n", argv[c]);
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} else { } else {
in_file = (const char*)GET_WARGV(argv, c); in_file = (const char*)GET_WARGV(argv, c);
} }
if (parse_error) { if (parse_error) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
} }
if (in_file == NULL) { if (in_file == NULL) {
fprintf(stderr, "missing input file!!\n"); fprintf(stderr, "missing input file!!\n");
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
if (quiet) verbose = 0; if (quiet) verbose = 0;
@ -316,7 +317,7 @@ int main(int argc, const char* argv[]) {
VP8StatusCode status = VP8_STATUS_OK; VP8StatusCode status = VP8_STATUS_OK;
size_t data_size = 0; size_t data_size = 0;
if (!LoadWebP(in_file, &data, &data_size, bitstream)) { if (!LoadWebP(in_file, &data, &data_size, bitstream)) {
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
switch (format) { switch (format) {
@ -415,7 +416,7 @@ int main(int argc, const char* argv[]) {
WebPFreeDecBuffer(output_buffer); WebPFreeDecBuffer(output_buffer);
WebPFree((void*)external_buffer); WebPFree((void*)external_buffer);
WebPFree((void*)data); WebPFree((void*)data);
FREE_WARGV_AND_RETURN(ok ? 0 : -1); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -96,6 +96,7 @@ static void Help(void) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int verbose = 0; int verbose = 0;
int gif_error = GIF_ERROR; int gif_error = GIF_ERROR;
@ -140,7 +141,7 @@ int main(int argc, const char* argv[]) {
!WebPPictureInit(&frame) || !WebPPictureInit(&curr_canvas) || !WebPPictureInit(&frame) || !WebPPictureInit(&curr_canvas) ||
!WebPPictureInit(&prev_canvas)) { !WebPPictureInit(&prev_canvas)) {
fprintf(stderr, "Error! Version mismatch!\n"); fprintf(stderr, "Error! Version mismatch!\n");
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
config.lossless = 1; // Use lossless compression by default. config.lossless = 1; // Use lossless compression by default.
@ -150,14 +151,14 @@ int main(int argc, const char* argv[]) {
if (argc == 1) { if (argc == 1) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} }
for (c = 1; c < argc; ++c) { for (c = 1; c < argc; ++c) {
int parse_error = 0; int parse_error = 0;
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-o") && c < argc - 1) { } else if (!strcmp(argv[c], "-o") && c < argc - 1) {
out_file = GET_WARGV(argv, ++c); out_file = GET_WARGV(argv, ++c);
} else if (!strcmp(argv[c], "-lossy")) { } else if (!strcmp(argv[c], "-lossy")) {
@ -216,7 +217,7 @@ int main(int argc, const char* argv[]) {
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n", fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
(int)(token - start), start); (int)(token - start), start);
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
start = token + 1; start = token + 1;
} }
@ -229,7 +230,7 @@ int main(int argc, const char* argv[]) {
(enc_version >> 16) & 0xff, (enc_version >> 8) & 0xff, (enc_version >> 16) & 0xff, (enc_version >> 8) & 0xff,
enc_version & 0xff, (mux_version >> 16) & 0xff, enc_version & 0xff, (mux_version >> 16) & 0xff,
(mux_version >> 8) & 0xff, mux_version & 0xff); (mux_version >> 8) & 0xff, mux_version & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-quiet")) { } else if (!strcmp(argv[c], "-quiet")) {
quiet = 1; quiet = 1;
enc_options.verbose = 0; enc_options.verbose = 0;
@ -242,14 +243,14 @@ int main(int argc, const char* argv[]) {
} else if (argv[c][0] == '-') { } else if (argv[c][0] == '-') {
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]); fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} else { } else {
in_file = GET_WARGV(argv, c); in_file = GET_WARGV(argv, c);
} }
if (parse_error) { if (parse_error) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
} }
@ -593,7 +594,7 @@ int main(int argc, const char* argv[]) {
#endif #endif
} }
FREE_WARGV_AND_RETURN(!ok); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }
#else // !WEBP_HAVE_GIF #else // !WEBP_HAVE_GIF
@ -601,7 +602,7 @@ int main(int argc, const char* argv[]) {
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
fprintf(stderr, "GIF support not enabled in %s.\n", argv[0]); fprintf(stderr, "GIF support not enabled in %s.\n", argv[0]);
(void)argc; (void)argc;
return 0; return EXIT_FAILURE;
} }
#endif #endif

View File

@ -130,6 +130,7 @@ static int SetLoopCount(int loop_count, WebPData* const webp_data) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
const char* output = NULL; const char* output = NULL;
WebPAnimEncoder* enc = NULL; WebPAnimEncoder* enc = NULL;
@ -151,7 +152,7 @@ int main(int argc, const char* argv[]) {
INIT_WARGV(argc, argv); INIT_WARGV(argc, argv);
ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args); ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args);
if (!ok) FREE_WARGV_AND_RETURN(1); if (!ok) FREE_WARGV_AND_RETURN(EXIT_FAILURE);
argc = cmd_args.argc_; argc = cmd_args.argc_;
argv = cmd_args.argv_; argv = cmd_args.argv_;
@ -199,7 +200,7 @@ int main(int argc, const char* argv[]) {
verbose = 1; verbose = 1;
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-version")) { } else if (!strcmp(argv[c], "-version")) {
const int enc_version = WebPGetEncoderVersion(); const int enc_version = WebPGetEncoderVersion();
const int mux_version = WebPGetMuxVersion(); const int mux_version = WebPGetMuxVersion();
@ -335,5 +336,5 @@ int main(int argc, const char* argv[]) {
} }
WebPDataClear(&webp_data); WebPDataClear(&webp_data);
ExUtilDeleteCommandLineArguments(&cmd_args); ExUtilDeleteCommandLineArguments(&cmd_args);
FREE_WARGV_AND_RETURN(ok ? 0 : 1); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }

View File

@ -506,7 +506,7 @@ int main(int argc, char* argv[]) {
if (!WebPInitDecoderConfig(config)) { if (!WebPInitDecoderConfig(config)) {
fprintf(stderr, "Library version mismatch!\n"); fprintf(stderr, "Library version mismatch!\n");
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
config->options.dithering_strength = 50; config->options.dithering_strength = 50;
config->options.alpha_dithering_strength = 100; config->options.alpha_dithering_strength = 100;
@ -518,7 +518,7 @@ int main(int argc, char* argv[]) {
int parse_error = 0; int parse_error = 0;
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-noicc")) { } else if (!strcmp(argv[c], "-noicc")) {
kParams.use_color_profile = 0; kParams.use_color_profile = 0;
} else if (!strcmp(argv[c], "-nofancy")) { } else if (!strcmp(argv[c], "-nofancy")) {
@ -541,7 +541,7 @@ int main(int argc, char* argv[]) {
(dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff, (dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
dec_version & 0xff, (dmux_version >> 16) & 0xff, dec_version & 0xff, (dmux_version >> 16) & 0xff,
(dmux_version >> 8) & 0xff, dmux_version & 0xff); (dmux_version >> 8) & 0xff, dmux_version & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-mt")) { } else if (!strcmp(argv[c], "-mt")) {
config->options.use_threads = 1; config->options.use_threads = 1;
} else if (!strcmp(argv[c], "--")) { } else if (!strcmp(argv[c], "--")) {
@ -553,7 +553,7 @@ int main(int argc, char* argv[]) {
} else if (argv[c][0] == '-') { } else if (argv[c][0] == '-') {
printf("Unknown option '%s'\n", argv[c]); printf("Unknown option '%s'\n", argv[c]);
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} else { } else {
kParams.file_name = (const char*)GET_WARGV(argv, c); kParams.file_name = (const char*)GET_WARGV(argv, c);
file_name_argv_index = c; file_name_argv_index = c;
@ -561,14 +561,14 @@ int main(int argc, char* argv[]) {
if (parse_error) { if (parse_error) {
Help(); Help();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
} }
if (kParams.file_name == NULL) { if (kParams.file_name == NULL) {
printf("missing input file!!\n"); printf("missing input file!!\n");
Help(); Help();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} }
if (!ImgIoUtilReadFile(kParams.file_name, if (!ImgIoUtilReadFile(kParams.file_name,
@ -643,11 +643,11 @@ int main(int argc, char* argv[]) {
// Should only be reached when using FREEGLUT: // Should only be reached when using FREEGLUT:
ClearParams(); ClearParams();
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
Error: Error:
ClearParams(); ClearParams();
FREE_WARGV_AND_RETURN(-1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
#else // !WEBP_HAVE_GL #else // !WEBP_HAVE_GL
@ -655,7 +655,7 @@ int main(int argc, char* argv[]) {
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
fprintf(stderr, "OpenGL support not enabled in %s.\n", argv[0]); fprintf(stderr, "OpenGL support not enabled in %s.\n", argv[0]);
(void)argc; (void)argc;
return 0; return EXIT_FAILURE;
} }
#endif #endif

View File

@ -14,6 +14,7 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "webp/config.h" #include "webp/config.h"
@ -1120,6 +1121,7 @@ static void Help(void) {
" -bitstream_info .... Parse bitstream header.\n"); " -bitstream_info .... Parse bitstream header.\n");
} }
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int c, quiet = 0, show_diag = 0, show_summary = 0; int c, quiet = 0, show_diag = 0, show_summary = 0;
int parse_bitstream = 0; int parse_bitstream = 0;
@ -1130,7 +1132,7 @@ int main(int argc, const char* argv[]) {
if (argc == 1) { if (argc == 1) {
Help(); Help();
FREE_WARGV_AND_RETURN(WEBP_INFO_OK); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} }
// Parse command-line input. // Parse command-line input.
@ -1138,7 +1140,7 @@ int main(int argc, const char* argv[]) {
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help") || if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help") ||
!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) { !strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
Help(); Help();
FREE_WARGV_AND_RETURN(WEBP_INFO_OK); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else if (!strcmp(argv[c], "-quiet")) { } else if (!strcmp(argv[c], "-quiet")) {
quiet = 1; quiet = 1;
} else if (!strcmp(argv[c], "-diag")) { } else if (!strcmp(argv[c], "-diag")) {
@ -1151,7 +1153,7 @@ int main(int argc, const char* argv[]) {
const int version = WebPGetDecoderVersion(); const int version = WebPGetDecoderVersion();
printf("WebP Decoder version: %d.%d.%d\n", printf("WebP Decoder version: %d.%d.%d\n",
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff); (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else { // Assume the remaining are all input files. } else { // Assume the remaining are all input files.
break; break;
} }
@ -1159,7 +1161,7 @@ int main(int argc, const char* argv[]) {
if (c == argc) { if (c == argc) {
Help(); Help();
FREE_WARGV_AND_RETURN(WEBP_INFO_INVALID_COMMAND); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
// Process input files one by one. // Process input files one by one.
@ -1182,5 +1184,6 @@ int main(int argc, const char* argv[]) {
webp_info_status = AnalyzeWebP(&webp_info, &webp_data); webp_info_status = AnalyzeWebP(&webp_info, &webp_data);
WebPDataClear(&webp_data); WebPDataClear(&webp_data);
} }
FREE_WARGV_AND_RETURN(webp_info_status); FREE_WARGV_AND_RETURN((webp_info_status == WEBP_INFO_OK) ? EXIT_SUCCESS
: EXIT_FAILURE);
} }

View File

@ -59,6 +59,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "webp/decode.h" #include "webp/decode.h"
#include "webp/mux.h" #include "webp/mux.h"
#include "../examples/example_util.h" #include "../examples/example_util.h"
@ -1225,6 +1226,7 @@ static int Process(const Config* config) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Main. // Main.
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
Config config; Config config;
int ok; int ok;
@ -1238,7 +1240,7 @@ int main(int argc, const char* argv[]) {
PrintHelp(); PrintHelp();
} }
DeleteConfig(&config); DeleteConfig(&config);
FREE_WARGV_AND_RETURN(!ok); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -227,10 +227,11 @@ static void Help(void) {
WebPGetEnabledInputFileFormats()); WebPGetEnabledInputFileFormats());
} }
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
WebPPicture pic1, pic2; WebPPicture pic1, pic2;
size_t size1 = 0, size2 = 0; size_t size1 = 0, size2 = 0;
int ret = 1; int ret = EXIT_FAILURE;
float disto[5]; float disto[5];
int type = 0; int type = 0;
int c; int c;
@ -246,7 +247,7 @@ int main(int argc, const char* argv[]) {
if (!WebPPictureInit(&pic1) || !WebPPictureInit(&pic2)) { if (!WebPPictureInit(&pic1) || !WebPPictureInit(&pic2)) {
fprintf(stderr, "Can't init pictures\n"); fprintf(stderr, "Can't init pictures\n");
FREE_WARGV_AND_RETURN(1); FREE_WARGV_AND_RETURN(EXIT_FAILURE);
} }
for (c = 1; c < argc; ++c) { for (c = 1; c < argc; ++c) {
@ -262,7 +263,7 @@ int main(int argc, const char* argv[]) {
use_gray = 1; use_gray = 1;
} else if (!strcmp(argv[c], "-h")) { } else if (!strcmp(argv[c], "-h")) {
help = 1; help = 1;
ret = 0; ret = EXIT_SUCCESS;
} else if (!strcmp(argv[c], "-o")) { } else if (!strcmp(argv[c], "-o")) {
if (++c == argc) { if (++c == argc) {
fprintf(stderr, "missing file name after %s option.\n", argv[c - 1]); fprintf(stderr, "missing file name after %s option.\n", argv[c - 1]);
@ -337,7 +338,8 @@ int main(int argc, const char* argv[]) {
fprintf(stderr, "Error during lossless encoding.\n"); fprintf(stderr, "Error during lossless encoding.\n");
goto End; goto End;
} }
ret = ImgIoUtilWriteFile(output, data, data_size) ? 0 : 1; ret = ImgIoUtilWriteFile(output, data, data_size) ? EXIT_SUCCESS
: EXIT_FAILURE;
WebPFree(data); WebPFree(data);
if (ret) goto End; if (ret) goto End;
#else #else
@ -345,9 +347,10 @@ int main(int argc, const char* argv[]) {
(void)data_size; (void)data_size;
fprintf(stderr, "Cannot save the difference map. Please recompile " fprintf(stderr, "Cannot save the difference map. Please recompile "
"without the WEBP_REDUCE_CSP flag.\n"); "without the WEBP_REDUCE_CSP flag.\n");
goto End;
#endif // WEBP_REDUCE_CSP #endif // WEBP_REDUCE_CSP
} }
ret = 0; ret = EXIT_SUCCESS;
End: End:
WebPPictureFree(&pic1); WebPPictureFree(&pic1);

View File

@ -15,6 +15,7 @@
// Author: James Zern (jzern@google.com) // Author: James Zern (jzern@google.com)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "webp/config.h" #include "webp/config.h"
@ -49,6 +50,7 @@ static void ProcessEvents(void) {
} }
} }
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
int c; int c;
int ok = 0; int ok = 0;
@ -61,7 +63,7 @@ int main(int argc, char* argv[]) {
size_t webp_size = 0; size_t webp_size = 0;
if (!strcmp(argv[c], "-h")) { if (!strcmp(argv[c], "-h")) {
printf("Usage: %s [-h] image.webp [more_files.webp...]\n", argv[0]); printf("Usage: %s [-h] image.webp [more_files.webp...]\n", argv[0]);
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else { } else {
file = (const char*)GET_WARGV(argv, c); file = (const char*)GET_WARGV(argv, c);
} }
@ -87,7 +89,7 @@ int main(int argc, char* argv[]) {
Error: Error:
SDL_Quit(); SDL_Quit();
FREE_WARGV_AND_RETURN(ok ? 0 : 1); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }
#else // !WEBP_HAVE_SDL #else // !WEBP_HAVE_SDL

View File

@ -15,6 +15,7 @@
#include "imageio/imageio_util.h" #include "imageio/imageio_util.h"
#include "../examples/unicode.h" #include "../examples/unicode.h"
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
int c; int c;
int quiet = 0; int quiet = 0;
@ -27,7 +28,7 @@ int main(int argc, const char* argv[]) {
quiet = 1; quiet = 1;
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) { } else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) {
printf("webp_quality [-h][-quiet] webp_files...\n"); printf("webp_quality [-h][-quiet] webp_files...\n");
FREE_WARGV_AND_RETURN(0); FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
} else { } else {
const char* const filename = (const char*)GET_WARGV(argv, c); const char* const filename = (const char*)GET_WARGV(argv, c);
const uint8_t* data = NULL; const uint8_t* data = NULL;
@ -50,5 +51,5 @@ int main(int argc, const char* argv[]) {
free((void*)data); free((void*)data);
} }
} }
FREE_WARGV_AND_RETURN(ok ? 0 : 1); FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH CWEBP 1 "March 26, 2024" .TH CWEBP 1 "April 30, 2024"
.SH NAME .SH NAME
cwebp \- compress an image file to a WebP file cwebp \- compress an image file to a WebP file
.SH SYNOPSIS .SH SYNOPSIS
@ -299,6 +299,13 @@ Note: each input format may not support all combinations.
.B \-noasm .B \-noasm
Disable all assembly optimizations. Disable all assembly optimizations.
.SH EXIT STATUS
If there were no problems during execution, \fBcwebp\fP exits with the value of
the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBcwebp\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH DWEBP 1 "November 17, 2021" .TH DWEBP 1 "April 30, 2024"
.SH NAME .SH NAME
dwebp \- decompress a WebP file to an image file dwebp \- decompress a WebP file to an image file
.SH SYNOPSIS .SH SYNOPSIS
@ -108,6 +108,13 @@ Print extra information (decoding time in particular).
.B \-noasm .B \-noasm
Disable all assembly optimizations. Disable all assembly optimizations.
.SH EXIT STATUS
If there were no problems during execution, \fBdwebp\fP exits with the value of
the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBdwebp\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH GIF2WEBP 1 "November 17, 2021" .TH GIF2WEBP 1 "April 30, 2024"
.SH NAME .SH NAME
gif2webp \- Convert a GIF image to WebP gif2webp \- Convert a GIF image to WebP
.SH SYNOPSIS .SH SYNOPSIS
@ -126,6 +126,13 @@ Print extra information.
.B \-quiet .B \-quiet
Do not print anything. Do not print anything.
.SH EXIT STATUS
If there were no problems during execution, \fBgif2webp\fP exits with the value
of the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBgif2webp\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH IMG2WEBP 1 "March 17, 2023" .TH IMG2WEBP 1 "April 30, 2024"
.SH NAME .SH NAME
img2webp \- create animated WebP file from a sequence of input images. img2webp \- create animated WebP file from a sequence of input images.
.SH SYNOPSIS .SH SYNOPSIS
@ -89,6 +89,13 @@ Specify the compression method to use. This parameter controls the
trade off between encoding speed and the compressed file size and quality. trade off between encoding speed and the compressed file size and quality.
Possible values range from 0 to 6. Default value is 4. Possible values range from 0 to 6. Default value is 4.
.SH EXIT STATUS
If there were no problems during execution, \fBimg2webp\fP exits with the value
of the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBimg2webp\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH EXAMPLE .SH EXAMPLE
img2webp -loop 2 in0.png -lossy in1.jpg -d 80 in2.tiff -o out.webp img2webp -loop 2 in0.png -lossy in1.jpg -d 80 in2.tiff -o out.webp
.br .br

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH VWEBP 1 "November 17, 2021" .TH VWEBP 1 "April 30, 2024"
.SH NAME .SH NAME
vwebp \- decompress a WebP file and display it in a window vwebp \- decompress a WebP file and display it in a window
.SH SYNOPSIS .SH SYNOPSIS
@ -72,6 +72,13 @@ Disable blending and disposal process, for debugging purposes.
.B 'q' / 'Q' / ESC .B 'q' / 'Q' / ESC
Quit. Quit.
.SH EXIT STATUS
If there were no problems during execution, \fBvwebp\fP exits with the value of
the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBvwebp\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH WEBPINFO 1 "November 17, 2021" .TH WEBPINFO 1 "April 30, 2024"
.SH NAME .SH NAME
webpinfo \- print out the chunk level structure of WebP files webpinfo \- print out the chunk level structure of WebP files
along with basic integrity checks. along with basic integrity checks.
@ -47,6 +47,13 @@ Detailed usage instructions.
Input files in WebP format. Input files must come last, following Input files in WebP format. Input files must come last, following
options (if any). There can be multiple input files. options (if any). There can be multiple input files.
.SH EXIT STATUS
If there were no problems during execution, \fBwebpinfo\fP exits with the value
of the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBwebpinfo\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH WEBPMUX 1 "November 17, 2021" .TH WEBPMUX 1 "April 30, 2024"
.SH NAME .SH NAME
webpmux \- create animated WebP files from non\-animated WebP images, extract webpmux \- create animated WebP files from non\-animated WebP images, extract
frames from animated WebP images, and manage XMP/EXIF metadata and ICC profile. frames from animated WebP images, and manage XMP/EXIF metadata and ICC profile.
@ -186,6 +186,13 @@ Output file in WebP format.
.TP .TP
The nature of EXIF, XMP and ICC data is not checked and is assumed to be valid. The nature of EXIF, XMP and ICC data is not checked and is assumed to be valid.
.SH EXIT STATUS
If there were no problems during execution, \fBwebpmux\fP exits with the value
of the C constant \fBEXIT_SUCCESS\fP. This is usually zero.
.PP
If an error occurs, \fBwebpmux\fP exits with the value of the C constant
\fBEXIT_FAILURE\fP. This is usually one.
.SH BUGS .SH BUGS
Please report all bugs to the issue tracker: Please report all bugs to the issue tracker:
https://bugs.chromium.org/p/webp https://bugs.chromium.org/p/webp