1 
2 
3 #ifdef _MSC_VER
4 #pragma warning(disable : 4996)
5 #endif
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <assert.h>
10 
11 #include "ttwain_state.h"
12 #include "ttwain_error.h"
13 #include "ttwain_util.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 static char Msg_out[1024];
20 
21 #define HUMAN_MESSAGES
22 #ifdef HUMAN_MESSAGES
23 const char *RC_msg[] = {"SUCCESS",
24                         "FAILURE",
25                         "CHECK STATUS ('tried hard')",
26                         "CANCEL",
27                         "DS EVENT",
28                         "NOT DSEVENT",
29                         "TRANSFER DONE",
30                         "END OF LIST",
31                         "INFO NOT SUPPORTED",
32                         "DATA NOT AVAILABLE"};
33 
34 const char *CC_msg[] = {
35     "SUCCESS",
36     "FAILURE DUE TO UNKNOWN CAUSES",
37     "LOW MEMORY",
38     "NO DATA SOURCE",
39     "DS IS CONNECTED TO MAX POSSIBLE APPS",
40     "OPERATION ERROR, DS/DSM REPORTED ERROR",
41     "UNKNOWN CAPABILITY",
42     "undefined",
43     "undefined",
44     "UNRECOGNIZED TRIPLET",
45     "DATA PARAMETER OUT OF RANGE",
46     "TRIPLET OUT OF SEQUENCE",
47     "UNKNOWN DESTINATION APP/SRC IN DSM_ESNTRY",
48     "CAP NOT SUPPORTED BY SOURCE",
49     "OPERATION NOT SUPPORTED BY CAP",
50     "CAP HAS DEPENDANCY ON OTHER CAP",
51     "FILE SYSTEM OPERATION IS DENIED (FILE IS PROTECTED)",
52     "OPERATION FAILED BECAUSE FILE ALREADY EXISTS",
53     "FILE NOT FOUND",
54     "OPERATION FAILED BECAUSE DIRECTORY IS NOT EMPTY",
55     "THE FEEDER IS JAMMED",
56     "THE FEEDER DETECTED MULTIPLE PAGES",
57     "ERROR WRITING THE FILE (MEANT FOR THINGS LIKE DISK FULL CONDITIONS)",
58     "THE DEVICE WENT OFFLINE PRIOR TO OR DURING THIS OPERATION"};
59 #else
60 const char *RC_msg[] = {
61     "TWRC_SUCCESS",         "TWRC_FAILURE",   "TWRC_CHECKSTATUS ('tried hard')",
62     "TWRC_CANCEL",          "TWRC_DSEVENT",   "TWRC_NOTDSEVENT",
63     "TWRC_XFERDONE",        "TWRC_ENDOFLIST", "TWRC_INFONOTSUPPORTED",
64     "TWRC_DATANOTAVAILABLE"};
65 
66 const char *CC_msg[] = {
67     "TWCC_SUCCESS", "TWCC_BUMMER (Failure due to unknown causes)",
68     "TWCC_LOWMEMORY", "TWCC_NODS (No Data Source)",
69     "TWCC_MAXCONNECTIONS (DS is connected to max possible apps)",
70     "TWCC_OPERATIONERROR (DS/DSM reported error, app shouldn't)",
71     "TWCC_BADCAP (Unknown capability)", "7 (undefined)", "8 (undefined)",
72     "TWCC_BADPROTOCOL (Unrecognized triplet)",
73     "TWCC_BADVALUE (Data parameter out of range)",
74     "TWCC_SEQERROR (Triplet out of sequence)",
75     "TWCC_BADDEST (Unknown dest. App/Src in DSM_Esntry)",
76     "TWCC_CAPUNSUPPORTED (Cap not supported by source)",
77     "TWCC_CAPBADOPERATION (Operation not supported by cap)",
78     "TWCC_CAPSEQERROR (Cap has dependancy on other cap)",
79     "TWCC_DENIED      (File System operation is denied (file is protected))",
80     "TWCC_FILEEXISTS (Operation failed because file already exists)",
81     "TWCC_FILENOTFOUND (File not found)",
82     "TWCC_NOTEMPTY (Operation failed because directory is not empty)",
83     "TWCC_PAPERJAM (The feeder is jammed)",
84     "TWCC_PAPERDOUBLEFEED (The feeder detected multiple pages)",
85     "TWCC_FILEWRITEERROR (Error writing the file (meant for things like disk "
86     "full conditions))",
87     "TWCC_CHECKDEVICEONLINE (The device went offline prior to or during this "
88     "operation)"};
89 
90 #endif
91 /*---------------------------------------------------------------------------*/
TTWAIN_RecordError(void)92 void TTWAIN_RecordError(void) {
93   char tmp[1024];
94   TTwainData.ErrRC = TTWAIN_GetResultCode();
95   if ((TTwainData.ErrRC == TWRC_FAILURE) ||
96       (TTwainData.ErrRC == TWRC_CHECKSTATUS))
97     TTwainData.ErrCC = TTWAIN_GetConditionCode();
98   else
99     TTwainData.ErrCC = -1;
100 
101   if (TTwainData.ErrRC < (sizeof(RC_msg) / sizeof(RC_msg[0]))) {
102     snprintf(Msg_out, sizeof(Msg_out), "RC: %s(%d)",
103              RC_msg[TTwainData.ErrRC], (int)TTwainData.ErrRC);
104   } else {
105     snprintf(Msg_out, sizeof(Msg_out), "RC: %s(%d)", "unknown",
106              (int)TTwainData.ErrRC);
107   }
108 
109   if (TTwainData.ErrCC < (sizeof(CC_msg) / sizeof(CC_msg[0]))) {
110     snprintf(tmp, sizeof(tmp), "CC: %s(%d)", CC_msg[TTwainData.ErrCC],
111              (int)TTwainData.ErrCC);
112     strcat(Msg_out, tmp);
113   } else {
114     snprintf(tmp, sizeof(tmp), "CC: %s(%d)", "unknown",
115              (int)TTwainData.ErrCC);
116     strcat(Msg_out, tmp);
117   }
118 
119   if (TTwainData.ErrRC == TWRC_FAILURE &&
120       TTwainData.ErrCC == TWCC_OPERATIONERROR) {
121 #ifdef _WIN32
122     OutputDebugString(Msg_out);
123 #else
124 #ifdef TOONZDEBUG
125     printf("%s\n", Msg_out);
126 #endif
127 #endif
128   }
129   return;
130 }
131 /*---------------------------------------------------------------------------*/
TTWAIN_GetLastError(TUINT32 * rc,TUINT32 * cc)132 char *TTWAIN_GetLastError(TUINT32 *rc, TUINT32 *cc) {
133   assert(rc && cc);
134   *rc = TTwainData.ErrRC;
135   *cc = TTwainData.ErrCC;
136   return Msg_out;
137 }
138 /*---------------------------------------------------------------------------*/
139 
140 #ifdef __cplusplus
141 }
142 #endif
143