File: error.cc

package info (click to toggle)
libticalcs 1.1.10~git20221211.4646a7b%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,160 kB
  • sloc: cpp: 27,288; ansic: 1,123; makefile: 228; sh: 45; sed: 16
file content (492 lines) | stat: -rw-r--r-- 12,935 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
/* Hey EMACS -*- linux-c -*- */
/* $Id$ */

/*  libticalcs - Ti Calculator library, a part of the TiLP project
 *  Copyright (C) 1999-2005  Romain Livin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software Foundation,
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdio.h>
#include <string.h>
#include <glib.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "ticalcs.h"
#include "gettext.h"
#include "export3.h"
#include "error.h"
#include "logging.h"
#include "internal.h"

// extern helpers

extern int nsp_reset;

/**
 * ticalcs_error_get:
 * @number: error number (see error.h for list).
 * @message: a newly glib allocated string which contains corresponding error *message.
 *
 * Attempt to match the message corresponding to the error number. The returned
 * string must be freed when no longer needed.
 * The error message has the following format:
 * - 1: the error message
 * - 2: the cause(s), explanations on how to fix it
 * - 3: the error returned by the system
 *
 * Return value: 0 if error has been caught, the error number otherwise (propagation).
 **/
TIEXPORT3 int TICALL ticalcs_error_get(int number, char **message)
{
	// free memory
	//dusb_vtl_pkt_purge();
	//dusb_cpca_purge();
	//nsp_vtl_pkt_purge();

	if (message == NULL)
	{
		ticalcs_critical("ticalcs_error_get(NULL)\n");
		return number;
	}

	switch(number)
	{
	case ERR_ABORT:
		*message = g_strconcat(
		_("Msg: transfer aborted."),
		"\n",
		_("Cause: the user!"),
		NULL);
		break;

	case ERR_NOT_READY:
		*message = g_strconcat(
		_("Msg: calculator is not ready."),
		"\n",
		_("Cause: the calculator is busy (Var-Link menu, Window, ...). Press HOME..."),
		NULL);
		break;

	case ERR_CHECKSUM:
		*message = g_strconcat(
		_("Msg: checksum error."),
		"\n",
		_("Cause: a transmission error. Try again."),
		NULL);
		break;

	case ERR_INVALID_HOST:
		*message = g_strconcat(
		_("Msg: invalid host ID."),
		"\n",
		_("Cause: received an unexpected Machine ID from calculator, probably due to a transmission error."),
		NULL);
		break;

	case ERR_INVALID_TARGET:
		*message = g_strconcat(
		_("Msg: invalid target ID."),
		"\n",
		_("Cause: received an unexpected Target ID from calculator, probably due to a transmission error."),
		NULL);
		break;

	case ERR_INVALID_CMD:
		*message = g_strconcat(
		_("Msg: invalid command ID."),
		"\n",
		_("Cause: received an unexpected Command ID from calculator, probably due to a transmission error."),
		NULL);
		break;

	case ERR_EOT:
		*message = g_strconcat(
		_("Msg: not really an error, should not appear!"),
		"\n",
		_("Cause: a bug. Drop us an email!"),
		NULL);
		break;

	case ERR_VAR_VERSION:
		*message = g_strconcat(
		_("Msg: program or variable is incompatible with this OS version."),
		"\n",
		_("Cause: this variable type may not be supported by the target calculator, or you may need to upgrade your calculator OS."),
		NULL);
		break;

	case ERR_VAR_REJECTED:
		*message = g_strconcat(
		_("Msg: contents has been refused."),
		"\n",
		_("Cause: you attempted to send a variable which is locked/archived on the target calculator. The calculator may be out of memory. The certificate may be invalid or already installed."),
		NULL);
		break;

	case ERR_CTS_ERROR:
		*message = g_strconcat(
		_("Invalid CTS packet."),
		"\n",
		_("Cause: a transmission error."),
		NULL);
		break;

	case ERR_NACK:
		*message = g_strconcat(
		_("NACK received."),
		"\n",
		_("Cause: the command has been refused."),
		NULL);
		break;

	case ERR_INVALID_PACKET:
		*message = g_strconcat(
		_("Invalid packet."),
		"\n",
		_("Cause: a transmission error."),
		NULL);
		break;

	case ERR_MALLOC:
		break;

	case ERR_NO_CABLE:
		*message = g_strconcat(
		_("The cable cannot be used."),
		"\n",
		_("Cause: the cable has not been initialized due to a previous/current error."),
		NULL);
		break;

	case ERR_BUSY:
		break;

	case ERR_FILE_OPEN:
		break;

	case ERR_VOID_FUNCTION:
	case ERR_UNSUPPORTED:
		*message = g_strconcat(
		_("Msg: this function does not exist for this calculator."),
		"\n",
		_("Cause: the operation you attempted is not supported by your calculator model."),
		NULL);
		break;

	case ERR_OUT_OF_MEMORY:
		*message = g_strconcat(
		_("Msg: calculator out of memory."),
		"\n",
		_("Cause: the calculator does not have memory enough for doing the operation."),
		NULL);
		break;

	case ERR_OPEN_FILE:
		*message = g_strconcat(
		_("Msg: unable to open (reading) the file."),
		"\n",
		_("Cause: disk space or permissions."),
		NULL);
		break;

	case ERR_SAVE_FILE:
		*message = g_strconcat(
		_("Msg: unable to open (writing) the file."),
		"\n",
		_("Cause: disk space or permissions."),
		NULL);
		break;

	case ERR_PENDING_TRANSFER:
		*message = g_strconcat(
		_("A transfer is in progress. You cannot start a new one."),
		"\n",
		_("Cause: this should not happen. Probably a bug: drop us an email!"),
		NULL);
		break;

	case ERR_FATAL_ERROR:
		break;

	case ERR_MISSING_VAR:
		*message = g_strconcat(
		_("The requested var does not exist."),
		"\n",
		_("Cause: you attempted to download a variable which does not exist on the calculator any longer. Maybe you have manually deleted it ?"),
		NULL);
		break;

	case ERR_NO_VARS:
		*message = g_strconcat(
		_("There is nothing to backup."),
		"\n",
		_("Cause: 0 variables stored onto your calculator."),
		NULL);
		break;

	case ERR_INVALID_HANDLE:
		*message = g_strconcat(
		_("Invalid ticalcs handle."),
		"\n",
		_("Cause: bad cable or calc model."),
		NULL);
		break;

	case ERR_INVALID_PARAMETER:
		*message = g_strconcat(
		_("Invalid parameter."),
		"\n",
		_("Cause: if you see this in normal usage, a bug: drop us an email ! Otherwise, check the arguments you're passing to the function."),
		NULL);
		break;

	case ERR_INVALID_SCREENSHOT:
		*message = g_strconcat(
		_("Unknown screenshot format."),
		"\n",
		_("Cause: a transmission error, or unsupported calculator version."),
		NULL);
		break;

	case ERR_ROMDUMP_UNINSTALLED:
		*message = g_strconcat(
		_("ROM dumping program not found."),
		"\n",
		_("Cause: ROM dumps are not possible with this program because the tools needed to build the ROM dumpers are not included in Debian."),
		NULL);
		break;

	case ERR_CALC_ERROR1:	// must be synchronized with cmd68k.c (static uint8_t dbus_errors[])
		*message = g_strconcat(
		_("Msg: hand-held returned an error."),
		"\n",
		_("Cause: hand-held returned an uncaught error. Please report log."),
		NULL);
		break;
	case ERR_CALC_ERROR1+1:
		*message = g_strdup(
		_("Msg: cannot delete application."));
		break;
	case ERR_CALC_ERROR1+2:
		*message = g_strdup(
		_("Msg: invalid variable name."));
		break;
	case ERR_CALC_ERROR1+3:
		*message = g_strdup(
		_("Msg: cannot overwrite variable (locked/archived)."));
		break;
	case ERR_CALC_ERROR1+4:
		*message = g_strdup(
		_("Msg: cannot delete variable (locked/archived)."));
		break;
	case ERR_CALC_ERROR1+5:
		*message = g_strdup(
		_("Msg: FLASH application rejected (bad target model)."));
		break;
	case ERR_CALC_ERROR1+6:
		*message = g_strdup(
		_("Msg: malformed RTS packet (AMS version conflict)."));
		break;
	case ERR_CALC_ERROR1+7:
		*message = g_strdup(
		_("Msg: FLASH application rejected (signature does not match)."));
		break;

	case ERR_CALC_ERROR2:	// must be synchronized with dusb_cmd.c (static uint16_t usb_errors[])
		*message = g_strconcat(
		_("Msg: hand-held returned an error (not caught)."),
		"\n",
		_("Cause: hand-held returned an uncaught error. Please report log."),
		NULL);
		break;
	case ERR_CALC_ERROR2+1:
		*message = g_strdup(
		_("Msg: invalid argument or name."));
		break;
	case ERR_CALC_ERROR2+2:
		*message = g_strdup(
		_("Msg: cannot delete var/app from archive."));
		break;
	case ERR_CALC_ERROR2+3:
		*message = g_strdup(
		_("Msg: transmission error."));
		break;
	case ERR_CALC_ERROR2+4:
		*message = g_strdup(
		_("Msg: using basic mode while being in boot mode."));
		break;
	case ERR_CALC_ERROR2+5:
		*message = g_strdup(
		_("Msg: out of memory."));
		break;
	case ERR_CALC_ERROR2+6:
		*message = g_strdup(
		_("Msg: invalid name."));
		break;
	case ERR_CALC_ERROR2+7:
		*message = g_strdup(
		_("Msg: invalid name."));
		break;
	case ERR_CALC_ERROR2+8:
		*message = g_strdup(
		_("Msg: busy?"));
		break;
	case ERR_CALC_ERROR2+9:
		*message = g_strdup(
		_("Msg: can't overwrite, variable is locked."));
		break;
	case ERR_CALC_ERROR2+10:
		*message = g_strdup(
		_("Msg: mode token too small."));
		break;
	case ERR_CALC_ERROR2+11:
		*message = g_strdup(
		_("Msg: mode token too large."));
		break;
	case ERR_CALC_ERROR2+12:
		*message = g_strdup(
		_("Msg: wrong size for parameter."));
		break;
	case ERR_CALC_ERROR2+13:
		*message = g_strdup(
		_("Msg: invalid parameter ID."));
		break;
	case ERR_CALC_ERROR2+14:
		*message = g_strdup(
		_("Msg: read-only parameter."));
		break;
	case ERR_CALC_ERROR2+15:
		*message = g_strdup(
		_("Msg: wrong modify request?"));
		break;
	case ERR_CALC_ERROR2+16:
		*message = g_strdup(
		_("Msg: remote control?"));
		break;
	case ERR_CALC_ERROR2+17:
		*message = g_strdup(
		_("Msg: battery low."));
		break;
	case ERR_CALC_ERROR2+18:
		*message = g_strdup(
		_("Msg: FLASH application rejected (signature does not match)."));
		break;
	case ERR_CALC_ERROR2+19:
		*message = g_strdup(
		_("Msg: hand-held is busy (set your calculator to HOME screen)."));
		break;

	case ERR_CALC_ERROR3+0:	// must be synchronized with nsp_cmd.c (static uint8_t usb_errors[])
		*message = g_strconcat(
		_("Msg: hand-held returned an error (not caught)."),
		"\n",
		_("Cause: hand-held returned an uncaught error. Please report log."),
		NULL);
		break;
	case ERR_CALC_ERROR3+1:
		*message = g_strdup(
		_("Msg: out of memory."));
		break;
	case ERR_CALC_ERROR3+2:
		*message = g_strdup(
		_("Msg: OS installation failed. File is corrupted/wrong."));
		break;
	// The following one is returned when the filename does not fit in a 254-byte packet.
	case ERR_CALC_ERROR3+3:
		*message = g_strdup(
		_("Msg: packet too large."));
		break;
	case ERR_CALC_ERROR3+4:
		*message = g_strdup(
		_("Msg: the variable or directory does not exist."));
		break;
	case ERR_CALC_ERROR3+5:
		*message = g_strdup(
		_("Msg: the directory name is invalid."));
		break;
	case ERR_CALC_ERROR3+6:
		*message = g_strdup(
		_("Msg: not currently listing a directory."));
		break;
	case ERR_CALC_ERROR3+7:
		*message = g_strdup(
		_("Msg: no more files to list."));
		break;
	case ERR_CALC_ERROR3+8:
		*message = g_strdup(
		_("Msg: the directory name already exists."));
		break;
	// The following one is returned with folder names >= 230 bytes long
	case ERR_CALC_ERROR3+9:
		*message = g_strdup(
		_("Msg: the destination (folder or file) path is too long."));
		break;
	case ERR_CALC_ERROR3+10:
		*message = g_strdup(
		_("Msg: the file name is invalid."));
		break;
	case ERR_CALC_ERROR3+11:
		*message = g_strdup(
		_("Msg: no file extension."));
		break;
	case ERR_CALC_ERROR3+12:
		*message = g_strdup(
		_("Msg: forbidden characters in folder name."));
		break;
	// The following one (FF 20) is returned immediately by a e.g. CX CAS running 3.0.1.1753,
	// when ones tries to send it ZiDian.tcc (English-Chinese dictionary) 3.1.0.392.
	// A CX CAS running 3.1.0.392 sends FF 04 (OS refused because it's not suitable / corrupted / whatever) instead.
	//
	// 3.0.1.1753 behaves exactly the same if the magic in the header is edited from __OSEXT__1 to __OTEXT__1.
	// Therefore, it seems that FF 20 is a generic error message, rather than just "this particular OS extension is refused".
	case ERR_CALC_ERROR3+13:
		*message = g_strdup(
		_("Msg: OS upgrade type not recognized."));
		break;
	case ERR_CALC_ERROR3+14:
		*message = g_strdup(
		_("Msg: anti-downgrade protection refuses this OS version."));
		break;

	default:
		// propagate error code
		return number;
	}

	return 0;
}

/**
 * ticalcs_error_free:
 * @message: a message previously allocated by ticalcs_error_get()
 *
 * Free the given message string allocated by ticalcs_error_get();
 *
 * Return value: 0 if the argument was valid and the message was freed, nonzero otherwise.
 **/
TIEXPORT3 int TICALL ticalcs_error_free(char *message)
{
	if (message == NULL)
	{
		ticalcs_critical("ticalcs_error_free(NULL)\n");
		return ERR_INVALID_PARAMETER;
	}
	g_free(message);
	return 0;
}