summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-12-08 23:10:18 +0100
committerTor Andersson <tor.andersson@artifex.com>2011-12-08 23:10:18 +0100
commit62ff8552500694c96b998d2aac6fbc47ab2d9395 (patch)
tree570f959104e1dafe49edf553120f0ed9a0b60709
parent6796e89abefe67ea1e35e5f40f6a77620b6de9d8 (diff)
downloadmupdf-62ff8552500694c96b998d2aac6fbc47ab2d9395.tar.xz
Remove deprecated error handling code.
-rw-r--r--apps/pdfapp.c20
-rw-r--r--apps/pdfapp.h2
-rw-r--r--apps/pdfclean.c71
-rw-r--r--apps/pdfextract.c61
-rw-r--r--apps/pdfinfo.c30
-rw-r--r--apps/pdfshow.c76
-rw-r--r--apps/win_main.c51
-rw-r--r--apps/x11_main.c18
-rw-r--r--apps/xpsdraw.c24
-rw-r--r--fitz/base_error.c109
-rw-r--r--fitz/fitz.h40
-rw-r--r--pdf/pdf_cmap_load.c1
12 files changed, 86 insertions, 417 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 7dabd93e..9893af39 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -27,9 +27,9 @@ static void pdfapp_warn(pdfapp_t *app, const char *fmt, ...)
winwarn(app, buf);
}
-static void pdfapp_error(pdfapp_t *app, fz_error error)
+static void pdfapp_error(pdfapp_t *app, char *msg)
{
- winerror(app, error);
+ winerror(app, msg);
}
char *pdfapp_version(pdfapp_t *app)
@@ -110,16 +110,16 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
* Open PDF and load xref table
*/
- file = fz_open_fd(ctx, fd);
fz_try(ctx)
{
+ file = fz_open_fd(ctx, fd);
app->xref = pdf_open_xref_with_stream(file, NULL);
+ fz_close(file);
}
fz_catch(ctx)
{
- pdfapp_error(app, fz_error_note(1, "cannot open document '%s'", filename));
+ pdfapp_error(app, "cannot open document");
}
- fz_close(file);
/*
* Handle encrypted PDF files
@@ -172,7 +172,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
}
fz_catch(ctx)
{
- pdfapp_error(app, fz_error_note(1, "cannot load page tree"));
+ pdfapp_error(app, "cannot load page tree");
}
app->pagecount = pdf_count_pages(app->xref);
@@ -189,7 +189,7 @@ static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd)
}
fz_catch(app->ctx)
{
- pdfapp_error(app, fz_error_note(-1, "cannot open document '%s'", filename));
+ pdfapp_error(app, "cannot open document");
}
fz_close(file);
@@ -324,7 +324,7 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app)
}
fz_catch(app->ctx)
{
- pdfapp_error(app, 1);
+ pdfapp_error(app, "cannot load page");
}
app->page_bbox = page->mediabox;
@@ -341,7 +341,7 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app)
}
fz_catch(app->ctx)
{
- pdfapp_error(app, fz_error_note(-1, "cannot draw page %d in '%s'", app->pageno, app->doctitle));
+ pdfapp_error(app, "cannot draw page");
}
fz_free_device(mdev);
@@ -361,7 +361,7 @@ static void pdfapp_loadpage_xps(pdfapp_t *app)
}
fz_catch(app->ctx)
{
- pdfapp_error(app, fz_error_note(1, "cannot load page %d in file '%s'", app->pageno, app->doctitle));
+ pdfapp_error(app, "cannot load page");
}
app->page_bbox.x0 = 0;
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index e617333d..c9fe1d4f 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -12,7 +12,7 @@ typedef struct pdfapp_s pdfapp_t;
enum { ARROW, HAND, WAIT };
extern void winwarn(pdfapp_t*, char *s);
-extern void winerror(pdfapp_t*, fz_error error);
+extern void winerror(pdfapp_t*, char *s);
extern void wintitle(pdfapp_t*, char *title);
extern void winresize(pdfapp_t*, int w, int h);
extern void winrepaint(pdfapp_t*);
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 2c492951..58453cfb 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -26,14 +26,6 @@ static int doascii = 0;
static pdf_xref *xref = NULL;
static fz_context *ctx = NULL;
-void die(fz_error error)
-{
- fz_error_handle(error, "aborting");
- if (xref)
- pdf_free_xref(xref);
- exit(1);
-}
-
static void usage(void)
{
fprintf(stderr,
@@ -290,14 +282,7 @@ static void retainpages(int argc, char **argv)
fz_obj *oldroot, *root, *pages, *kids, *countobj, *parent, *olddests;
/* Load the old page tree */
- fz_try(xref->ctx)
- {
- pdf_load_page_tree(xref);
- }
- fz_catch(xref->ctx)
- {
- die(fz_error_note(1, "cannot load page tree"));
- }
+ pdf_load_page_tree(xref);
/* Keep only pages/type and (reduced) dest entries to avoid
* references to unretained pages */
@@ -425,14 +410,7 @@ static void preloadobjstms(void)
{
if (xref->table[num].type == 'o')
{
- fz_try(ctx)
- {
- obj = pdf_load_object(xref, num, 0);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ obj = pdf_load_object(xref, num, 0);
fz_drop_obj(obj);
}
}
@@ -536,14 +514,7 @@ static void copystream(fz_obj *obj, int num, int gen)
fz_buffer *buf, *tmp;
fz_obj *newlen;
- fz_try(ctx)
- {
- buf = pdf_load_raw_stream(xref, num, gen);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ buf = pdf_load_raw_stream(xref, num, gen);
if (doascii && isbinarystream(buf))
{
@@ -572,14 +543,7 @@ static void expandstream(fz_obj *obj, int num, int gen)
fz_buffer *buf, *tmp;
fz_obj *newlen;
- fz_try(ctx)
- {
- buf = pdf_load_stream(xref, num, gen);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ buf = pdf_load_stream(xref, num, gen);
fz_dict_dels(obj, "Filter");
fz_dict_dels(obj, "DecodeParms");
@@ -611,14 +575,7 @@ static void writeobject(int num, int gen)
fz_obj *obj;
fz_obj *type;
- fz_try(ctx)
- {
- obj = pdf_load_object(xref, num, gen);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ obj = pdf_load_object(xref, num, gen);
/* skip ObjStm and XRef objects */
if (fz_is_dict(obj))
@@ -777,21 +734,17 @@ int main(int argc, char **argv)
subset = 1;
ctx = fz_new_context(&fz_alloc_default);
- if (ctx == NULL)
- die(fz_error_note(1, "failed to initialise context"));
-
- fz_try(ctx)
+ if (!ctx)
{
- xref = pdf_open_xref(ctx, infile, password);
- }
- fz_catch(ctx)
- {
- die(fz_error_note(1, "cannot open input file '%s'", infile));
+ fprintf(stderr, "cannot initialise context\n");
+ exit(1);
}
+ xref = pdf_open_xref(ctx, infile, password);
+
out = fopen(outfile, "wb");
if (!out)
- die(fz_error_make("cannot open output file '%s'", outfile));
+ fz_throw(ctx, "cannot open output file '%s'", outfile);
fprintf(out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10);
fprintf(out, "%%\316\274\341\277\246\n\n");
@@ -838,7 +791,7 @@ int main(int argc, char **argv)
writepdf();
if (fclose(out))
- die(fz_error_make("cannot close output file '%s'", outfile));
+ fz_throw(ctx, "cannot close output file '%s'", outfile);
fz_free(xref->ctx, uselist);
fz_free(xref->ctx, ofslist);
diff --git a/apps/pdfextract.c b/apps/pdfextract.c
index bf0a74ed..cb03d745 100644
--- a/apps/pdfextract.c
+++ b/apps/pdfextract.c
@@ -9,14 +9,6 @@ static pdf_xref *xref = NULL;
static fz_context *ctx = NULL;
static int dorgb = 0;
-void die(fz_error error)
-{
- fz_error_handle(error, "aborting");
- if (xref)
- pdf_free_xref(xref);
- exit(1);
-}
-
static void usage(void)
{
fprintf(stderr, "usage: pdfextract [options] file.pdf [object numbers]\n");
@@ -47,14 +39,7 @@ static void saveimage(int num)
/* TODO: detect DCTD and save as jpeg */
- fz_try(ctx)
- {
- img = pdf_load_image(xref, ref);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ img = pdf_load_image(xref, ref);
if (dorgb && img->colorspace && img->colorspace != fz_device_rgb)
{
@@ -119,7 +104,7 @@ static void savefont(fz_obj *dict, int num)
obj = fz_dict_gets(obj, "Subtype");
if (obj && !fz_is_name(obj))
- die(fz_error_make("Invalid font descriptor subtype"));
+ fz_throw(ctx, "Invalid font descriptor subtype");
subtype = fz_to_name(obj);
if (!strcmp(subtype, "Type1C"))
@@ -127,7 +112,7 @@ static void savefont(fz_obj *dict, int num)
else if (!strcmp(subtype, "CIDFontType0C"))
ext = "cid";
else
- die(fz_error_make("Unhandled font type '%s'", subtype));
+ fz_throw(ctx, "Unhandled font type '%s'", subtype);
}
if (!stream)
@@ -136,28 +121,21 @@ static void savefont(fz_obj *dict, int num)
return;
}
- fz_try(ctx)
- {
- buf = pdf_load_stream(xref, fz_to_num(stream), fz_to_gen(stream));
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ buf = pdf_load_stream(xref, fz_to_num(stream), fz_to_gen(stream));
sprintf(name, "%s-%04d.%s", fontname, num, ext);
printf("extracting font %s\n", name);
f = fopen(name, "wb");
if (f == NULL)
- die(fz_error_make("Error creating font file"));
+ fz_throw(ctx, "Error creating font file");
n = fwrite(buf->data, 1, buf->len, f);
if (n < buf->len)
- die(fz_error_make("Error writing font file"));
+ fz_throw(ctx, "Error writing font file");
if (fclose(f) < 0)
- die(fz_error_make("Error closing font file"));
+ fz_throw(ctx, "Error closing font file");
fz_drop_buffer(ctx, buf);
}
@@ -167,16 +145,9 @@ static void showobject(int num)
fz_obj *obj;
if (!xref)
- die(fz_error_make("no file specified"));
+ fz_throw(ctx, "no file specified");
- fz_try(ctx)
- {
- obj = pdf_load_object(xref, num, 0);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ obj = pdf_load_object(xref, num, 0);
if (isimage(obj))
saveimage(num);
@@ -208,18 +179,14 @@ int main(int argc, char **argv)
infile = argv[fz_optind++];
ctx = fz_new_context(&fz_alloc_default);
- if (ctx == NULL)
- die(fz_error_note(1, "failed to initialise context"));
-
- fz_try(ctx)
+ if (!ctx)
{
- xref = pdf_open_xref(ctx, infile, password);
- }
- fz_catch(ctx)
- {
- die(fz_error_note(1, "cannot open input file '%s'", infile));
+ fprintf(stderr, "cannot initialise context\n");
+ exit(1);
}
+ xref = pdf_open_xref(ctx, infile, password);
+
if (fz_optind == argc)
{
for (o = 0; o < xref->len; o++)
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index d2aa0bb4..171317c9 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -12,13 +12,6 @@ int pagecount;
void closexref(void);
-void die(fz_error error)
-{
- fz_error_handle(error, "aborting");
- closexref();
- exit(1);
-}
-
void openxref(char *filename, char *password, int dieonbadpass, int loadpages);
enum
@@ -580,7 +573,7 @@ gatherresourceinfo(int page, fz_obj *rsrc)
pageref = xref->page_refs[page-1];
if (!pageobj)
- die(fz_error_make("cannot retrieve info from page %d", page));
+ fz_throw(ctx, "cannot retrieve info from page %d", page);
font = fz_dict_gets(rsrc, "Font");
if (font)
@@ -648,7 +641,7 @@ gatherpageinfo(int page)
pageref = xref->page_refs[page-1];
if (!pageobj)
- die(fz_error_make("cannot retrieve info from page %d", page));
+ fz_throw(ctx, "cannot retrieve info from page %d", page);
gatherdimensions(page, pageref, pageobj);
@@ -955,7 +948,6 @@ showinfo(char *filename, int show, char *pagelist)
int main(int argc, char **argv)
{
enum { NO_FILE_OPENED, NO_INFO_GATHERED, INFO_SHOWN } state;
- fz_error error;
char *filename = "";
char *password = "";
int show = ALL;
@@ -981,9 +973,12 @@ int main(int argc, char **argv)
if (fz_optind == argc)
infousage();
- ctx = fz_new_context();
- if (ctx == NULL)
- die(fz_error_make("failed to initialise context"));
+ ctx = fz_new_context(&fz_alloc_default);
+ if (!ctx)
+ {
+ fprintf(stderr, "cannot initialise context");
+ exit(1);
+ }
state = NO_FILE_OPENED;
while (fz_optind < argc)
@@ -1000,13 +995,8 @@ int main(int argc, char **argv)
filename = argv[fz_optind];
printf("%s:\n", filename);
- error = pdf_open_xref(ctx, &xref, filename, password);
- if (error)
- die(fz_error_note(error, "cannot open input file '%s'", filename));
-
- error = pdf_load_page_tree(xref);
- if (error)
- die(fz_error_note(error, "cannot load page tree: %s", filename));
+ xref = pdf_open_xref(ctx, filename, password);
+ pdf_load_page_tree(xref);
pagecount = pdf_count_pages(xref);
showglobalinfo();
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index fee20d2f..c437f262 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -11,14 +11,6 @@ static int showbinary = 0;
static int showdecode = 1;
static int showcolumn;
-void die(fz_error error)
-{
- fz_error_handle(error, "aborting");
- if (xref)
- pdf_free_xref(xref);
- exit(1);
-}
-
static void usage(void)
{
fprintf(stderr, "usage: pdfshow [options] file.pdf [grepable] [xref] [trailer] [pagetree] [object numbers]\n");
@@ -31,7 +23,7 @@ static void usage(void)
static void showtrailer(void)
{
if (!xref)
- die(fz_error_make("no file specified"));
+ fz_throw(ctx, "no file specified");
printf("trailer\n");
fz_debug_obj(xref->trailer);
printf("\n");
@@ -40,7 +32,7 @@ static void showtrailer(void)
static void showxref(void)
{
if (!xref)
- die(fz_error_make("no file specified"));
+ fz_throw(ctx, "no file specified");
pdf_debug_xref(xref);
printf("\n");
}
@@ -52,19 +44,10 @@ static void showpagetree(void)
int i;
if (!xref)
- die(fz_error_make("no file specified"));
+ fz_throw(ctx, "no file specified");
if (!xref->page_len)
- {
- fz_try(xref->ctx)
- {
- pdf_load_page_tree(xref);
- }
- fz_catch(xref->ctx)
- {
- die(fz_error_note(1, "cannot load page tree"));
- }
- }
+ pdf_load_page_tree(xref);
count = pdf_count_pages(xref);
for (i = 0; i < count; i++)
@@ -106,23 +89,14 @@ static void showstream(int num, int gen)
showcolumn = 0;
- fz_try(xref->ctx)
- {
- if (showdecode)
- stm = pdf_open_stream(xref, num, gen);
- else
- stm = pdf_open_raw_stream(xref, num, gen);
- }
- fz_catch(xref->ctx)
- {
- die(1);
- }
+ if (showdecode)
+ stm = pdf_open_stream(xref, num, gen);
+ else
+ stm = pdf_open_raw_stream(xref, num, gen);
while (1)
{
n = fz_read(stm, buf, sizeof buf);
- if (n < 0)
- die(n);
if (n == 0)
break;
if (showbinary)
@@ -139,16 +113,9 @@ static void showobject(int num, int gen)
fz_obj *obj;
if (!xref)
- die(fz_error_make("no file specified"));
+ fz_throw(ctx, "no file specified");
- fz_try(ctx)
- {
- obj = pdf_load_object(xref, num, gen);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ obj = pdf_load_object(xref, num, gen);
if (pdf_is_stream(xref, num, gen))
{
@@ -185,14 +152,7 @@ static void showgrep(char *filename)
{
if (xref->table[i].type == 'n' || xref->table[i].type == 'o')
{
- fz_try(ctx)
- {
- obj = pdf_load_object(xref, i, 0);
- }
- fz_catch(ctx)
- {
- die(1);
- }
+ obj = pdf_load_object(xref, i, 0);
fz_sort_dict(obj);
@@ -230,18 +190,14 @@ int main(int argc, char **argv)
filename = argv[fz_optind++];
ctx = fz_new_context(&fz_alloc_default);
- if (ctx == NULL)
- die(fz_error_note(1, "failed to initialise context"));
-
- fz_try(ctx)
+ if (!ctx)
{
- xref = pdf_open_xref(ctx, filename, password);
- }
- fz_catch(ctx)
- {
- die(fz_error_note(1, "cannot open document: %s", filename));
+ fprintf(stderr, "cannot initialise context\n");
+ exit(1);
}
+ xref = pdf_open_xref(ctx, filename, password);
+
if (fz_optind == argc)
showtrailer();
diff --git a/apps/win_main.c b/apps/win_main.c
index 45880e12..a64d1b08 100644
--- a/apps/win_main.c
+++ b/apps/win_main.c
@@ -93,39 +93,12 @@ void winwarn(pdfapp_t *app, char *msg)
MessageBoxA(hwndframe, msg, "MuPDF: Warning", MB_ICONWARNING);
}
-void winerror(pdfapp_t *app, fz_error error)
+void winerror(pdfapp_t *app, char *msg)
{
- char msgbuf[160 * 30];
- int i;
-
- /* TODO: redirect stderr to a log file and display here */
- fz_error_handle(error, "displaying error message to user");
-
- fz_strlcpy(msgbuf, "An error has occurred.\n\n", sizeof msgbuf);
- for (i = 0; i < fz_get_error_count(); i++)
- {
- fz_strlcat(msgbuf, fz_get_error_line(i), sizeof msgbuf);
- fz_strlcat(msgbuf, "\n", sizeof msgbuf);
- }
-
- MessageBoxA(hwndframe, msgbuf, "MuPDF: Error", MB_ICONERROR);
+ MessageBoxA(hwndframe, msg, "MuPDF: Error", MB_ICONERROR);
exit(1);
}
-void win32error(char *msg)
-{
- LPSTR buf;
- int code = GetLastError();
- FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- code,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR)&buf, 0, NULL);
- winerror(&gapp, fz_error_make("%s:\n%s", msg, buf));
-}
-
int winfilename(wchar_t *buf, int len)
{
OPENFILENAME ofn;
@@ -185,7 +158,7 @@ char *winpassword(pdfapp_t *app, char *filename)
sprintf(pd_filename, "The file \"%s\" is encrypted.", s);
code = DialogBoxW(NULL, L"IDD_DLOGPASS", hwndframe, dlogpassproc);
if (code <= 0)
- win32error("cannot create password dialog");
+ winerror(app, "cannot create password dialog");
if (pd_okay)
return pd_password;
return NULL;
@@ -282,7 +255,7 @@ void info()
{
int code = DialogBoxW(NULL, L"IDD_DLOGINFO", hwndframe, dloginfoproc);
if (code <= 0)
- win32error("cannot create info dialog");
+ winerror(&gapp, "cannot create info dialog");
}
INT CALLBACK
@@ -305,7 +278,7 @@ void winhelp(pdfapp_t*app)
{
int code = DialogBoxW(NULL, L"IDD_DLOGABOUT", hwndframe, dlogaboutproc);
if (code <= 0)
- win32error("cannot create help dialog");
+ winerror(&gapp, "cannot create help dialog");
}
/*
@@ -333,7 +306,7 @@ void winopen()
wc.lpszClassName = L"FrameWindow";
a = RegisterClassW(&wc);
if (!a)
- win32error("cannot register frame window class");
+ winerror(&gapp, "cannot register frame window class");
/* Create and register window view class */
memset(&wc, 0, sizeof(wc));
@@ -349,7 +322,7 @@ void winopen()
wc.lpszClassName = L"ViewWindow";
a = RegisterClassW(&wc);
if (!a)
- win32error("cannot register view window class");
+ winerror(&gapp, "cannot register view window class");
/* Get screen size */
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
@@ -390,7 +363,7 @@ void winopen()
0, // program instance handle
0); // creation parameters
if (!hwndframe)
- win32error("cannot create frame: %s");
+ winerror(&gapp, "cannot create frame);
hwndview = CreateWindowW(L"ViewWindow", // window class name
NULL,
@@ -399,7 +372,7 @@ void winopen()
CW_USEDEFAULT, CW_USEDEFAULT,
hwndframe, 0, 0, 0);
if (!hwndview)
- win32error("cannot create view: %s");
+ winerror(&gapp, "cannot create view");
hdc = NULL;
@@ -618,7 +591,7 @@ void winreloadfile(pdfapp_t *app)
fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666);
if (fd < 0)
- winerror(&gapp, fz_error_make("cannot reload file '%s'", filename));
+ winerror(&gapp, "cannot reload file");
pdfapp_open(app, filename, fd, 1);
}
@@ -883,11 +856,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666);
if (fd < 0)
- winerror(&gapp, fz_error_make("cannot open file '%s'", filename));
+ winerror(&gapp, "cannot open file");
code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL);
if (code == 0)
- win32error("cannot convert filename to utf-8");
+ winerror(&gapp, "cannot convert filename to utf-8");
pdfapp_open(&gapp, filename, fd, 0);
diff --git a/apps/x11_main.c b/apps/x11_main.c
index 9b4dd0a2..b875bc6a 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -98,15 +98,15 @@ static int showingpage = 0;
* Dialog boxes
*/
-void winwarn(pdfapp_t *app, char *msg)
+void winerror(pdfapp_t *app, char *msg)
{
- fprintf(stderr, "mupdf: %s\n", msg);
+ fprintf(stderr, "mupdf: error: %s\n", msg);
+ exit(1);
}
-void winerror(pdfapp_t *app, fz_error error)
+void winwarn(pdfapp_t *app, char *msg)
{
- fz_error_handle(error, "aborting");
- exit(1);
+ fprintf(stderr, "mupdf: warning: %s\n", msg);
}
char *winpassword(pdfapp_t *app, char *filename)
@@ -127,7 +127,7 @@ static void winopen(void)
xdpy = XOpenDisplay(NULL);
if (!xdpy)
- winerror(&gapp, fz_error_make("cannot open display"));
+ fz_throw(gapp.ctx, "cannot open display");
XA_TARGETS = XInternAtom(xdpy, "TARGETS", False);
XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False);
@@ -161,7 +161,7 @@ static void winopen(void)
0,
NULL);
if (xwin == None)
- winerror(&gapp, fz_error_make("cannot create window"));
+ fz_throw(gapp.ctx, "cannot create window");
XSetWindowColormap(xdpy, xwin, ximage_get_colormap());
XSelectInput(xdpy, xwin,
@@ -501,7 +501,7 @@ void winreloadfile(pdfapp_t *app)
fd = open(filename, O_BINARY | O_RDONLY, 0666);
if (fd < 0)
- winerror(app, fz_error_make("cannot reload file '%s'", filename));
+ fz_throw(gapp.ctx, "cannot reload file '%s'", filename);
pdfapp_open(app, filename, fd, 1);
}
@@ -634,7 +634,7 @@ int main(int argc, char **argv)
fd = open(filename, O_BINARY | O_RDONLY, 0666);
if (fd < 0)
- winerror(&gapp, fz_error_make("cannot open file '%s'", filename));
+ fz_throw(gapp.ctx, "cannot open file '%s'", filename);
pdfapp_open(&gapp, filename, fd, 0);
diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c
index 4ac40b72..8b15ef3e 100644
--- a/apps/xpsdraw.c
+++ b/apps/xpsdraw.c
@@ -29,12 +29,6 @@ struct {
int minpage, maxpage;
} timing;
-static void die(fz_error error)
-{
- fz_error_handle(error, "aborting");
- exit(1);
-}
-
static void usage(void)
{
fprintf(stderr,
@@ -99,14 +93,7 @@ static void drawpage(xps_document *doc, int pagenum)
start = gettime();
}
- fz_try(doc->ctx)
- {
- page = xps_load_page(doc, pagenum - 1);
- }
- fz_catch(doc->ctx)
- {
- die(fz_error_note(1, "cannot load page %d in file '%s'", pagenum, filename));
- }
+ page = xps_load_page(doc, pagenum - 1);
list = NULL;
@@ -358,14 +345,7 @@ int main(int argc, char **argv)
{
filename = argv[fz_optind++];
- fz_try(ctx)
- {
- doc = xps_open_file(ctx, filename);
- }
- fz_catch(ctx)
- {
- die(fz_error_note(-1, "cannot open document: %s", filename));
- }
+ doc = xps_open_file(ctx, filename);
if (showxml)
printf("<document name=\"%s\">\n", filename);
diff --git a/fitz/base_error.c b/fitz/base_error.c
index bd6801eb..3373016f 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -83,112 +83,3 @@ void fz_rethrow(fz_context *ctx)
{
throw(ctx->error);
}
-
-/* Deprecated error bubbling */
-
-static void
-fz_emit_error(char what, char *location, char *message)
-{
- fprintf(stderr, "%c %s%s\n", what, location, message);
-}
-
-int
-fz_get_error_count(void)
-{
- return 0;
-}
-
-char *
-fz_get_error_line(int n)
-{
- return "";
-}
-
-fz_error
-fz_error_make_imp(const char *file, int line, const char *func, char *fmt, ...)
-{
- va_list ap;
- char one[256], two[256];
-
- snprintf(one, sizeof one, "%s:%d: %s(): ", file, line, func);
- va_start(ap, fmt);
- vsnprintf(two, sizeof two, fmt, ap);
- va_end(ap);
-
- fz_emit_error('+', one, two);
-
- return -1;
-}
-
-fz_error
-fz_error_note_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
-{
- va_list ap;
- char one[256], two[256];
-
- snprintf(one, sizeof one, "%s:%d: %s(): ", file, line, func);
- va_start(ap, fmt);
- vsnprintf(two, sizeof two, fmt, ap);
- va_end(ap);
-
- fz_emit_error('|', one, two);
-
- return cause;
-}
-
-void
-fz_error_handle_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
-{
- va_list ap;
- char one[256], two[256];
-
- snprintf(one, sizeof one, "%s:%d: %s(): ", file, line, func);
- va_start(ap, fmt);
- vsnprintf(two, sizeof two, fmt, ap);
- va_end(ap);
-
- fz_emit_error('\\', one, two);
-}
-
-fz_error
-fz_error_make_impx(char *fmt, ...)
-{
- va_list ap;
- char buf[256];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof buf, fmt, ap);
- va_end(ap);
-
- fz_emit_error('+', "", buf);
-
- return -1;
-}
-
-fz_error
-fz_error_note_impx(fz_error cause, char *fmt, ...)
-{
- va_list ap;
- char buf[256];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof buf, fmt, ap);
- va_end(ap);
-
- fz_emit_error('|', "", buf);
-
- return cause;
-}
-
-void
-fz_error_handle_impx(fz_error cause, char *fmt, ...)
-{
- va_list ap;
- char buf[256];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof buf, fmt, ap);
- va_end(ap);
-
- fz_emit_error('\\', "", buf);
-}
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 09c12c14..8d523e3f 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -69,35 +69,15 @@ int gettimeofday(struct timeval *tv, struct timezone *tz);
*/
#if __STDC_VERSION__ == 199901L /* C99 */
-
-#define fz_error_make(...) fz_error_make_imp(__FILE__, __LINE__, __func__, __VA_ARGS__)
-#define fz_error_note(cause, ...) fz_error_note_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
-#define fz_error_handle(cause, ...) fz_error_handle_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
-
#elif _MSC_VER >= 1500 /* MSVC 9 or newer */
-
#define inline __inline
#define restrict __restrict
-#define fz_error_make(...) fz_error_make_imp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
-#define fz_error_note(cause, ...) fz_error_note_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
-#define fz_error_handle(cause, ...) fz_error_handle_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
-
#elif __GNUC__ >= 3 /* GCC 3 or newer */
-
#define inline __inline
#define restrict __restrict
-#define fz_error_make(fmt...) fz_error_make_imp(__FILE__, __LINE__, __FUNCTION__, fmt)
-#define fz_error_note(cause, fmt...) fz_error_note_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
-#define fz_error_handle(cause, fmt...) fz_error_handle_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
-
#else /* Unknown or ancient */
-
#define inline
#define restrict
-#define fz_error_make fz_error_make_impx
-#define fz_error_note fz_error_note_impx
-#define fz_error_handle fz_error_handle_impx
-
#endif
/*
@@ -113,26 +93,6 @@ int gettimeofday(struct timeval *tv, struct timezone *tz);
#endif
#endif
-/*
- * Deprecated error handling.
- */
-
-typedef int fz_error;
-
-#define fz_okay ((fz_error)0)
-
-fz_error fz_error_make_imp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
-fz_error fz_error_note_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-void fz_error_handle_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-
-fz_error fz_error_make_impx(char *fmt, ...) __printflike(1, 2);
-fz_error fz_error_note_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
-void fz_error_handle_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
-
-/* extract the last error stack trace */
-int fz_get_error_count(void);
-char *fz_get_error_line(int n);
-
/* Contexts */
typedef struct fz_alloc_context_s fz_alloc_context;
diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c
index 15bd8406..5bcf578f 100644
--- a/pdf/pdf_cmap_load.c
+++ b/pdf/pdf_cmap_load.c
@@ -7,7 +7,6 @@
pdf_cmap *
pdf_load_embedded_cmap(pdf_xref *xref, fz_obj *stmobj)
{
- fz_error error = fz_okay;
fz_stream *file = NULL;
pdf_cmap *cmap = NULL;
pdf_cmap *usecmap;