Commit 28cc3692e37b9f231d58c0c24e5e90674988ef64

Authored by Jay Berkenbilt
1 parent d2e68b57

Expose exit code values to C API via Constants.h

ChangeLog
1 2022-06-18 Jay Berkenbilt <ejb@ql.org> 1 2022-06-18 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Add qpdf_exit_code_e to Constants.h so that exit codes from
  4 + QPDFJob are accessible to the C API.
  5 +
3 * When --progress or --verbose is combined with writing to 6 * When --progress or --verbose is combined with writing to
4 standard output, progress reporting and verbose messages go to 7 standard output, progress reporting and verbose messages go to
5 standard error. Previously it was disabled in this case. 8 standard error. Previously it was disabled in this case.
@@ -47,8 +47,6 @@ Output Capture + QPDFJob @@ -47,8 +47,6 @@ Output Capture + QPDFJob
47 47
48 QPDFJob: 48 QPDFJob:
49 49
50 -* Expose the meanings of the return values of qpdfjob functions to the  
51 - C API.  
52 * Allow users to supply a custom progress reporter for QPDFJob 50 * Allow users to supply a custom progress reporter for QPDFJob
53 51
54 Output Capture 52 Output Capture
include/qpdf/Constants.h
@@ -27,6 +27,18 @@ @@ -27,6 +27,18 @@
27 * interfaces. 27 * interfaces.
28 */ 28 */
29 29
  30 +/* Exit Codes from QPDFJob and the qpdf CLI */
  31 +
  32 +enum qpdf_exit_code_e {
  33 + qpdf_exit_success = 0,
  34 + /* Normal exit codes */
  35 + qpdf_exit_error = 2,
  36 + qpdf_exit_warning = 3,
  37 + /* For --is-encrypted and --requires-password */
  38 + qpdf_exit_is_not_encrypted = 2,
  39 + qpdf_exit_correct_password = 3,
  40 +};
  41 +
30 /* Error Codes */ 42 /* Error Codes */
31 43
32 enum qpdf_error_code_e { 44 enum qpdf_error_code_e {
include/qpdf/QPDFJob.hh
@@ -47,11 +47,11 @@ class QPDFJob @@ -47,11 +47,11 @@ class QPDFJob
47 { 47 {
48 public: 48 public:
49 // Exit codes -- returned by getExitCode() after calling run() 49 // Exit codes -- returned by getExitCode() after calling run()
50 - static int constexpr EXIT_ERROR = 2;  
51 - static int constexpr EXIT_WARNING = 3; 50 + static int constexpr EXIT_ERROR = qpdf_exit_error;
  51 + static int constexpr EXIT_WARNING = qpdf_exit_warning;
52 // For is-encrypted and requires-password 52 // For is-encrypted and requires-password
53 - static int constexpr EXIT_IS_NOT_ENCRYPTED = 2;  
54 - static int constexpr EXIT_CORRECT_PASSWORD = 3; 53 + static int constexpr EXIT_IS_NOT_ENCRYPTED = qpdf_exit_is_not_encrypted;
  54 + static int constexpr EXIT_CORRECT_PASSWORD = qpdf_exit_correct_password;
55 55
56 // QPDFUsage is thrown if there are any usage-like errors when 56 // QPDFUsage is thrown if there are any usage-like errors when
57 // calling Config methods. 57 // calling Config methods.
include/qpdf/qpdfjob-c.h
@@ -49,7 +49,9 @@ extern &quot;C&quot; { @@ -49,7 +49,9 @@ extern &quot;C&quot; {
49 * command-line with the given arguments and returns the exit code 49 * command-line with the given arguments and returns the exit code
50 * that qpdf would use. argv must be a null-terminated array of 50 * that qpdf would use. argv must be a null-terminated array of
51 * null-terminated UTF8-encoded strings. If calling this from 51 * null-terminated UTF8-encoded strings. If calling this from
52 - * wmain on Windows, use qpdfjob_run_from_wide_argv instead. 52 + * wmain on Windows, use qpdfjob_run_from_wide_argv instead. Exit
  53 + * code values are defined in Constants.h in the qpdf_exit_code_e
  54 + * type.
53 */ 55 */
54 QPDF_DLL 56 QPDF_DLL
55 int qpdfjob_run_from_argv(char const* const argv[]); 57 int qpdfjob_run_from_argv(char const* const argv[]);
@@ -66,7 +68,8 @@ extern &quot;C&quot; { @@ -66,7 +68,8 @@ extern &quot;C&quot; {
66 /* This function runs QPDFJob from a job JSON file. See the "QPDF 68 /* This function runs QPDFJob from a job JSON file. See the "QPDF
67 * Job" section of the manual for details. The JSON string must be 69 * Job" section of the manual for details. The JSON string must be
68 * UTF8-encoded. It returns the error code that qpdf would return 70 * UTF8-encoded. It returns the error code that qpdf would return
69 - * with the equivalent command-line invocation. 71 + * with the equivalent command-line invocation. Exit code values
  72 + * are defined in Constants.h in the qpdf_exit_code_e type.
70 */ 73 */
71 QPDF_DLL 74 QPDF_DLL
72 int qpdfjob_run_from_json(char const* json); 75 int qpdfjob_run_from_json(char const* json);
manual/release-notes.rst
@@ -1717,6 +1717,12 @@ For a detailed list of changes, please see the file @@ -1717,6 +1717,12 @@ For a detailed list of changes, please see the file
1717 and may optionally compensate for rotation or scaling of the 1717 and may optionally compensate for rotation or scaling of the
1718 destination page. 1718 destination page.
1719 1719
  1720 + - Exit codes returned by ``QPDFJob::run()`` and the C API wrappers
  1721 + are now defined in :file:`qpdf/Constants.h` in the
  1722 + ``qpdf_exit_code_e`` type so that they are accessible from the C
  1723 + API. They were previously only defined as constants in
  1724 + :file:`qpdf/QPDFJob.hh`.
  1725 +
1720 - Build Improvements 1726 - Build Improvements
1721 1727
1722 - Add new configure option 1728 - Add new configure option