1 //* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* TiLP - Tilp Is a Linking Program
5 * Copyright (C) 1999-2006 Romain Lievin
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "tilibs.h"
27
28 #include "tilp_core.h"
29
30 static GList *stack = NULL;
31
32 /*
33 This function take as input parameter an error code and displays it
34 in a message box.
35
36 This function is 'buffered': if one or more error messages appear
37 during startup (console or terminal), they will be displayed in the GUI.
38 */
tilp_err(int errcode)39 int tilp_err(int errcode)
40 {
41 char *s = NULL;
42 char *utf;
43 gsize bw;
44
45 /* Push error messages (if any)*/
46 if(errcode)
47 stack = g_list_append(stack, GINT_TO_POINTER(errcode));
48
49 /* Pop error messages */
50 if (!(working_mode & MODE_INI))
51 {
52 int i;
53 for (i = 0; i < (int)g_list_length(stack); i++)
54 {
55 int err = GPOINTER_TO_INT((g_list_nth(stack, i))->data);
56
57 /* Retrieve the error message */
58 err = ticables_error_get(err, &s);
59 if (err)
60 {
61 g_free(s);
62 err = tifiles_error_get(err, &s);
63 if (err)
64 {
65 g_free(s);
66 err = ticalcs_error_get(err, &s);
67 if (err)
68 {
69 // next level: error for TiLP
70 g_free(s);
71 }
72 else
73 {
74 // ticalcs error => reset
75 tilp_device_reset();
76 }
77 }
78 }
79 else
80 {
81 // ticables error => reset
82 tilp_device_reset();
83 }
84
85 utf = g_locale_to_utf8(s, -1, NULL, &bw, NULL);
86 gif->msg_box1(_("Error"), utf);
87 }
88 g_list_free(stack);
89 stack = NULL;
90 }
91 else
92 {
93 int err = errcode;
94
95 /* Retrieve the error message */
96 err = ticables_error_get(err, &s);
97 if (err)
98 {
99 g_free(s);
100 err = tifiles_error_get(err, &s);
101 if (err)
102 {
103 g_free(s);
104 err = ticalcs_error_get(err, &s);
105 if (err)
106 {
107 // next level: error for TiLP
108 g_free(s);
109 }
110 }
111 }
112
113 if(s)
114 tilp_info("%s\n", s);
115 }
116
117 //free(s);
118 return errcode;
119 }
120
121