mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-31 02:48:31 +00:00
improve C error handling interface
git-svn-id: svn+q:///qpdf/trunk@884 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
75ea1971fa
commit
7f5d78c2d1
@ -24,7 +24,6 @@ int main(int argc, char* argv[])
|
||||
int warnings = 0;
|
||||
int errors = 0;
|
||||
char* p = 0;
|
||||
qpdf_error e = 0;
|
||||
|
||||
if ((p = strrchr(argv[0], '/')) != NULL)
|
||||
{
|
||||
@ -57,11 +56,11 @@ int main(int argc, char* argv[])
|
||||
printf("warning: %s\n",
|
||||
qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
|
||||
}
|
||||
e = qpdf_get_error(qpdf);
|
||||
if (e)
|
||||
if (qpdf_has_error(qpdf))
|
||||
{
|
||||
errors = 1;
|
||||
printf("error: %s\n", qpdf_get_error_full_text(qpdf, e));
|
||||
printf("error: %s\n",
|
||||
qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
|
||||
}
|
||||
qpdf_cleanup(&qpdf);
|
||||
if (errors)
|
||||
|
@ -17,8 +17,7 @@
|
||||
|
||||
enum qpdf_error_code_e
|
||||
{
|
||||
qpdf_e_success = 0,
|
||||
qpdf_e_internal, /* logic/programming error -- indicates bug */
|
||||
qpdf_e_internal = 1, /* logic/programming error -- indicates bug */
|
||||
qpdf_e_system, /* I/O error, memory error, etc. */
|
||||
qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */
|
||||
qpdf_e_password, /* incorrect password for encrypted file */
|
||||
|
@ -106,9 +106,18 @@ extern "C" {
|
||||
|
||||
/* ERROR REPORTING */
|
||||
|
||||
/* Returns 1 if there is an error condition. The error condition
|
||||
* can be retrieved by a single call to qpdf_get_error.
|
||||
*/
|
||||
QPDF_DLL
|
||||
QPDF_BOOL qpdf_has_error(qpdf_data qpdf);
|
||||
|
||||
/* Returns the error condition, if any. The return value is a
|
||||
* pointer to data that will become invalid the next time an error
|
||||
* occurs or after this function is called gain.
|
||||
* pointer to data that will become invalid after the next call to
|
||||
* this function, qpdf_next_warning, or qpdf_destroy. After this
|
||||
* function is called, qpdf_has_error will return QPDF_FALSE until
|
||||
* the next error condition occurs. If there is no error
|
||||
* condition, this function returns a null pointer.
|
||||
*/
|
||||
QPDF_DLL
|
||||
qpdf_error qpdf_get_error(qpdf_data qpdf);
|
||||
@ -133,7 +142,8 @@ extern "C" {
|
||||
char const* qpdf_get_error_full_text(qpdf_data q, qpdf_error e);
|
||||
|
||||
/* Use these functions to extract individual fields from the
|
||||
* error; see QPDFExc.hh for details. */
|
||||
* error; see QPDFExc.hh for details. It is invalid for e to be a
|
||||
* null pointer for any of these calls. */
|
||||
QPDF_DLL
|
||||
enum qpdf_error_code_e qpdf_get_error_code(qpdf_data q, qpdf_error e);
|
||||
QPDF_DLL
|
||||
|
@ -128,13 +128,19 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf)
|
||||
}
|
||||
}
|
||||
|
||||
QPDF_BOOL qpdf_has_error(qpdf_data qpdf)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_has_error");
|
||||
return (qpdf->error.getPointer() ? QPDF_TRUE : QPDF_FALSE);
|
||||
}
|
||||
|
||||
qpdf_error qpdf_get_error(qpdf_data qpdf)
|
||||
{
|
||||
if (qpdf->error.getPointer())
|
||||
{
|
||||
qpdf->tmp_error.exc = qpdf->error;
|
||||
qpdf->error = 0;
|
||||
QTC::TC("qpdf", "qpdf-c qpdf_next_error returned error");
|
||||
QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");
|
||||
return &qpdf->tmp_error;
|
||||
}
|
||||
else
|
||||
|
@ -18,9 +18,9 @@ static void report_errors()
|
||||
printf(" pos : %ld\n", qpdf_get_error_file_position(qpdf, e));
|
||||
printf(" text: %s\n", qpdf_get_error_message_detail(qpdf, e));
|
||||
}
|
||||
e = qpdf_get_error(qpdf);
|
||||
if (e)
|
||||
if (qpdf_has_error(qpdf))
|
||||
{
|
||||
e = qpdf_get_error(qpdf);
|
||||
printf("error: %s\n", qpdf_get_error_full_text(qpdf, e));
|
||||
printf(" code: %d\n", qpdf_get_error_code(qpdf, e));
|
||||
printf(" file: %s\n", qpdf_get_error_filename(qpdf, e));
|
||||
|
@ -121,7 +121,7 @@ QPDF_Stream ignore non-dictionary DecodeParms 0
|
||||
qpdf-c called qpdf_init 0
|
||||
qpdf-c called qpdf_cleanup 0
|
||||
qpdf-c called qpdf_more_warnings 0
|
||||
qpdf-c qpdf_next_error returned error 0
|
||||
qpdf-c qpdf_get_error returned error 0
|
||||
qpdf-c qpdf_next_warning returned warning 0
|
||||
qpdf-c called qpdf_set_suppress_warnings 0
|
||||
qpdf-c called qpdf_set_ignore_xref_streams 0
|
||||
@ -172,3 +172,4 @@ qpdf-c called qpdf_set_static_aes_IV 0
|
||||
QPDF_encryption stream crypt filter 0
|
||||
QPDF ERR object stream with wrong type 0
|
||||
QPDF object gone after xref reconstruction 0
|
||||
qpdf-c called qpdf_has_error 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user