~mcf/mupdf

621078008ac3d91dcd00842b2b03a52314c86f57 — Robin Watts 10 months ago 18698d1
Fix mutool usage messages not to leak.

Mostly this is to avoid me running "mutool whatever" to get the
usage message and then having to wade through pages of Memento
leaked block information to actually find what I was looking for.
M source/tools/muconvert.c => source/tools/muconvert.c +4 -4
@@ 26,7 26,7 @@ static fz_document *doc;
static fz_document_writer *out;
static int count;

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"mutool convert version " FZ_VERSION "\n"


@@ 60,7 60,7 @@ static void usage(void)
	fputs(fz_pdf_write_options_usage, stderr);
#endif
	fputs(fz_svg_write_options_usage, stderr);
	exit(1);
	return 1;
}

static void runpage(int number)


@@ 112,7 112,7 @@ int muconvert_main(int argc, char **argv)
	{
		switch (c)
		{
		default: usage(); break;
		default: return usage();

		case 'p': password = fz_optarg; break;
		case 'A': alphabits = atoi(fz_optarg); break;


@@ 129,7 129,7 @@ int muconvert_main(int argc, char **argv)
	}

	if (fz_optind == argc || (!format && !output))
		usage();
		return usage();

	/* Create a context to hold the exception stack and various caches. */
	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);

M source/tools/mudraw.c => source/tools/mudraw.c +4 -4
@@ 383,7 383,7 @@ static struct {
	char *maxlayoutfilename;
} timing;

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"mudraw version " FZ_VERSION "\n"


@@ 467,7 467,7 @@ static void usage(void)
		"\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
	return 1;
}

static int gettime(void)


@@ 1816,7 1816,7 @@ int mudraw_main(int argc, char **argv)
	{
		switch (c)
		{
		default: usage(); break;
		default: return usage();

		case 'q': quiet = 1; break;



@@ 1908,7 1908,7 @@ int mudraw_main(int argc, char **argv)
	}

	if (fz_optind == argc)
		usage();
		return usage();

	if (num_workers > 0)
	{

M source/tools/muraster.c => source/tools/muraster.c +4 -4
@@ 481,7 481,7 @@ static struct {

#define stringify(A) #A

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"muraster version " FZ_VERSION "\n"


@@ 520,7 520,7 @@ static void usage(void)
		"\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
	return 1;
}

static int gettime(void)


@@ 1442,7 1442,7 @@ int main(int argc, char **argv)
	{
		switch (c)
		{
		default: usage(); break;
		default: return usage();

		case 'p': password = fz_optarg; break;



@@ 1506,7 1506,7 @@ int main(int argc, char **argv)
		height = y_resolution * PAPER_HEIGHT;

	if (fz_optind == argc)
		usage();
		return usage();

	if (min_band_height <= 0)
	{

M source/tools/mutrace.c => source/tools/mutrace.c +4 -4
@@ 4,7 4,7 @@
#include <stdlib.h>
#include <stdio.h>

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"Usage: mutool trace [options] file [pages]\n"


@@ 20,7 20,7 @@ static void usage(void)
		"\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
	return 1;
}

static float layout_w = FZ_DEFAULT_LAYOUT_W;


@@ 95,7 95,7 @@ int mutrace_main(int argc, char **argv)
	{
		switch (c)
		{
		default: usage(); break;
		default: return usage();
		case 'p': password = fz_optarg; break;

		case 'W': layout_w = fz_atof(fz_optarg); break;


@@ 109,7 109,7 @@ int mutrace_main(int argc, char **argv)
	}

	if (fz_optind == argc)
		usage();
		return usage();

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)

M source/tools/pdfclean.c => source/tools/pdfclean.c +4 -4
@@ 16,7 16,7 @@
#include <stdlib.h>
#include <stdio.h>

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool clean [options] input.pdf [output.pdf] [pages]\n"


@@ 42,7 42,7 @@ static void usage(void)
		"\t-AA\trecreate appearance streams for annotations\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
	return 1;
}

static int encrypt_method_from_string(const char *name)


@@ 89,7 89,7 @@ int pdfclean_main(int argc, char **argv)
		case 'O': fz_strlcpy(opts.opwd_utf8, fz_optarg, sizeof opts.opwd_utf8); break;
		case 'U': fz_strlcpy(opts.upwd_utf8, fz_optarg, sizeof opts.upwd_utf8); break;

		default: usage(); break;
		default: return usage();
		}
	}



@@ 97,7 97,7 @@ int pdfclean_main(int argc, char **argv)
		opts.do_pretty = 1;

	if (argc - fz_optind < 1)
		usage();
		return usage();

	infile = argv[fz_optind++];


M source/tools/pdfcreate.c => source/tools/pdfcreate.c +4 -4
@@ 11,7 11,7 @@
#include <stdlib.h>
#include <stdio.h>

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool create [-o output.pdf] [-O options] page.txt [page2.txt ...]\n"


@@ 26,7 26,7 @@ static void usage(void)
		"\t%%%%Image Name Filename\n\n"
		);
	fputs(fz_pdf_write_options_usage, stderr);
	exit(1);
	return 1;
}

static fz_context *ctx = NULL;


@@ 240,12 240,12 @@ int pdfcreate_main(int argc, char **argv)
		{
		case 'o': output = fz_optarg; break;
		case 'O': flags = fz_optarg; break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (fz_optind == argc)
		usage();
		return usage();

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)

M source/tools/pdfextract.c => source/tools/pdfextract.c +4 -4
@@ 13,13 13,13 @@ static fz_context *ctx = NULL;
static int dorgb = 0;
static int doicc = 1;

static void usage(void)
static int usage(void)
{
	fprintf(stderr, "usage: mutool extract [options] file.pdf [object numbers]\n");
	fprintf(stderr, "\t-p\tpassword\n");
	fprintf(stderr, "\t-r\tconvert images to rgb\n");
	fprintf(stderr, "\t-N\tdo not use ICC color conversions\n");
	exit(1);
	return 1;
}

static int isimage(pdf_obj *obj)


@@ 246,12 246,12 @@ int pdfextract_main(int argc, char **argv)
		case 'p': password = fz_optarg; break;
		case 'r': dorgb++; break;
		case 'N': doicc^=1; break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (fz_optind == argc)
		usage();
		return usage();

	infile = argv[fz_optind++];


M source/tools/pdfinfo.c => source/tools/pdfinfo.c +7 -2
@@ 173,7 173,6 @@ infousage(void)
		"\t-X\tlist form and postscript xobjects\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
}

static void


@@ 921,7 920,10 @@ showinfo(fz_context *ctx, globals *glo, char *filename, int show, const char *pa
	fz_output *out = glo->out;

	if (!glo->doc)
	{
		infousage();
		fz_throw(ctx, FZ_ERROR_GENERIC, "Cannot show info without document");
	}

	allpages = !strcmp(pagelist, "1-N");



@@ 1024,12 1026,15 @@ int pdfinfo_main(int argc, char **argv)
		case 'p': password = fz_optarg; break;
		default:
			infousage();
			break;
			return 1;
		}
	}

	if (fz_optind == argc)
	{
		infousage();
		return 1;
	}

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)

M source/tools/pdfmerge.c => source/tools/pdfmerge.c +4 -4
@@ 10,7 10,7 @@
#include <stdlib.h>
#include <stdio.h>

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool merge [-o output.pdf] [-O options] input.pdf [pages] [input2.pdf] [pages2] ...\n"


@@ 20,7 20,7 @@ static void usage(void)
		"\tpages\tcomma separated list of page numbers and ranges\n\n"
		);
	fputs(fz_pdf_write_options_usage, stderr);
	exit(1);
	return 1;
}

static fz_context *ctx = NULL;


@@ 76,12 76,12 @@ int pdfmerge_main(int argc, char **argv)
		{
		case 'o': output = fz_optarg; break;
		case 'O': flags = fz_optarg; break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (fz_optind == argc)
		usage();
		return usage();

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)

M source/tools/pdfpages.c => source/tools/pdfpages.c +5 -6
@@ 9,7 9,7 @@
#include <stdlib.h>
#include <stdio.h>

static void
static int
infousage(void)
{
	fprintf(stderr,


@@ 17,7 17,7 @@ infousage(void)
		"\t-p -\tpassword for decryption\n"
		"\tpages\tcomma separated list of page numbers and ranges\n"
		);
	exit(1);
	return 1;
}

static int


@@ 110,7 110,7 @@ showpages(fz_context *ctx, pdf_document *doc, fz_output *out, const char *pageli
	int ret = 0;

	if (!doc)
		infousage();
		return infousage();

	pagecount = pdf_count_pages(ctx, doc);
	while ((pagelist = fz_parse_page_range(ctx, pagelist, &spage, &epage, pagecount)))


@@ 184,13 184,12 @@ int pdfpages_main(int argc, char **argv)
		{
		case 'p': password = fz_optarg; break;
		default:
			infousage();
			break;
			return infousage();
		}
	}

	if (fz_optind == argc)
		infousage();
		return infousage();

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)

M source/tools/pdfposter.c => source/tools/pdfposter.c +4 -4
@@ 12,14 12,14 @@
static int x_factor = 0;
static int y_factor = 0;

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool poster [options] input.pdf [output.pdf]\n"
		"\t-p -\tpassword\n"
		"\t-x\tx decimation factor\n"
		"\t-y\ty decimation factor\n");
	exit(1);
	return 1;
}

static void


@@ 191,12 191,12 @@ int pdfposter_main(int argc, char **argv)
		case 'p': password = fz_optarg; break;
		case 'x': x_factor = atoi(fz_optarg); break;
		case 'y': y_factor = atoi(fz_optarg); break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (argc - fz_optind < 1)
		usage();
		return usage();

	infile = argv[fz_optind++];


M source/tools/pdfshow.c => source/tools/pdfshow.c +4 -4
@@ 17,7 17,7 @@ static int showdecode = 1;
static int tight = 0;
static int showcolumn;

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool show [options] file.pdf ( trailer | xref | pages | grep | outline | js | form | <path> ) *\n"


@@ 31,7 31,7 @@ static void usage(void)
		"\t\tpath elements separated by '.' or '/'. Path elements must be\n"
		"\t\tarray index numbers, dictionary property names, or '*'.\n"
	);
	exit(1);
	return 1;
}

static void showtrailer(void)


@@ 578,12 578,12 @@ int pdfshow_main(int argc, char **argv)
		case 'b': showbinary = 1; break;
		case 'e': showdecode = 0; break;
		case 'g': tight = 1; break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (fz_optind == argc)
		usage();
		return usage();

	filename = argv[fz_optind++];


M source/tools/pdfsign.c => source/tools/pdfsign.c +4 -4
@@ 19,7 19,7 @@ static int clear = 0;
static int sign = 0;
static int list = 1;

static void usage(void)
static int usage(void)
{
	fprintf(stderr,
		"usage: mutool sign [options] input.pdf [signature object numbers]\n"


@@ 30,7 30,7 @@ static void usage(void)
		"\t-P -\tcertificate password\n"
		"\t-o -\toutput file name\n"
		   );
	exit(1);
	return 1;
}

static void verify_signature(fz_context *ctx, pdf_document *doc, pdf_obj *signature)


@@ 242,12 242,12 @@ int pdfsign_main(int argc, char **argv)
		case 'P': certificatepassword = fz_optarg; break;
		case 's': list = 0; sign = 1; certificatefile = fz_optarg; break;
		case 'v': list = 0; verify = 1; break;
		default: usage(); break;
		default: return usage();
		}
	}

	if (argc - fz_optind < 1)
		usage();
		return usage();

	infile = argv[fz_optind++];