Debian Codegraph @

src/type2str.cc

raw
1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* libticables2 - link cable library, a part of the TiLP project
5 * Copyright (C) 1999-2005 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 <string.h>
23 #include <glib.h>
24
25 #include "gettext.h"
26 #include "ticables.h"
27 #include "logging.h"
28
29 /**
30 * ticables_model_to_string:
31 * @model: a cable model.
32 *
33 * Do an integer to string conversion.
34 *
35 * Return value: a string like "BlackLink".
36 **/
37 const char *TICALL ticables_model_to_string(CableModel model)
38 {
39 switch (model)
40 {
41 case CABLE_NUL: return "null";
42 case CABLE_GRY: return "GrayLink";
43 case CABLE_BLK: return "BlackLink";
44 case CABLE_PAR: return "Parallel";
45 case CABLE_SLV: return "SilverLink";
46 case CABLE_USB: return "DirectLink";
47 case CABLE_VTI: return "VTi";
48 case CABLE_TIE: return "TiEmu";
49 case CABLE_ILP: return "linkport";
50 //case CABLE_DEV: return "UsbKernel";
51 case CABLE_TCPC: return "TCPC";
52 case CABLE_TCPS: return "TCPS";
53 default: return "unknown";
54 }
55 }
56
57 /**
58 * ticables_string_to_model:
59 * @str: a cable model as string like "BlackLink".
60 *
61 * Do a string to integer conversion.
62 *
63 * Return value: a cable model.
64 **/
65 CableModel TICALL ticables_string_to_model(const char *str)
66 {
67 if (str == NULL)
68 {
69 ticables_critical("%s(NULL)", __FUNCTION__);
70 return CABLE_NUL;
71 }
72
73 /*if (!g_ascii_strcasecmp(str, "null") || !g_ascii_strcasecmp(str, "nul"))
74 return CABLE_NUL;
75 else*/ if (!g_ascii_strcasecmp(str, "GrayLink") || !g_ascii_strcasecmp(str, "gry"))
76 return CABLE_GRY;
77 else if (!g_ascii_strcasecmp(str, "BlackLink") || !g_ascii_strcasecmp(str, "blk") || !g_ascii_strcasecmp(str, "ser"))
78 return CABLE_BLK;
79 else if (!g_ascii_strcasecmp(str, "Parallel") || !g_ascii_strcasecmp(str, "par"))
80 return CABLE_PAR;
81 else if (!g_ascii_strcasecmp(str, "SilverLink") || !g_ascii_strcasecmp(str, "slv"))
82 return CABLE_SLV;
83 else if (!g_ascii_strcasecmp(str, "DirectLink") || !g_ascii_strcasecmp(str, "usb"))
84 return CABLE_USB;
85 else if (!g_ascii_strcasecmp(str, "VTi"))
86 return CABLE_VTI;
87 else if ( !g_ascii_strcasecmp(str, "TiEmu") || !g_ascii_strcasecmp(str, "tie")
88 || !g_ascii_strcasecmp(str, "TilEm") || !g_ascii_strcasecmp(str, "TiEmu/TilEm"))
89 return CABLE_TIE;
90 else if (!g_ascii_strcasecmp(str, "linkport"))
91 return CABLE_ILP;
92 else if (!g_ascii_strcasecmp(str, "tcpc") || !g_ascii_strcasecmp(str, "tcpclient"))
93 return CABLE_TCPC;
94 else if (!g_ascii_strcasecmp(str, "tcps") || !g_ascii_strcasecmp(str, "tcpserver"))
95 return CABLE_TCPS;
96 // else fall through.
97
98 return CABLE_NUL;
99 }
100
101 /**
102 * ticables_port_to_string:
103 * @port: a link port.
104 *
105 * Do an integer to string conversion.
106 *
107 * Return value: a string like "#1".
108 **/
109 const char *TICALL ticables_port_to_string(CablePort port)
110 {
111 switch (port)
112 {
113 case PORT_0: return "null";
114 case PORT_1: return "#1";
115 case PORT_2: return "#2";
116 case PORT_3: return "#3";
117 case PORT_4: return "#4";
118 default: return "unknown";
119 }
120 }
121
122 /**
123 * ticables_string_to_port:
124 * @str: a link port as string like "#1".
125 *
126 * Do a string to integer conversion.
127 *
128 * Return value: a link port.
129 **/
130 CablePort TICALL ticables_string_to_port(const char *str)
131 {
132 if (str == NULL)
133 {
134 ticables_critical("%s(NULL)", __FUNCTION__);
135 return PORT_0;
136 }
137
138 if(!g_ascii_strcasecmp(str, "null"))
139 return PORT_0;
140 else if(!strcmp(str, "#1"))
141 return PORT_1;
142 else if(!strcmp(str, "#2"))
143 return PORT_2;
144 else if(!strcmp(str, "#3"))
145 return PORT_3;
146 else if(!strcmp(str, "#4"))
147 return PORT_4;
148
149 return PORT_0;
150 }
151
152 /**
153 * ticables_usbpid_to_string:
154 * @pid: a Usb Product Id.
155 *
156 * Do an integer to string conversion.
157 *
158 * Return value: a string like "SilverLink".
159 **/
160 const char *TICALL ticables_usbpid_to_string(UsbPid pid)
161 {
162 switch (pid)
163 {
164 case PID_TIGLUSB: return "SilverLink"; // must match ticables name
165 case PID_TI89TM: return "TI89t"; // must match tifiles name
166 case PID_TI84P: return "TI84+"; // must match tifiles name
167 case PID_TI84P_SE: return "TI84+"; // remap
168 case PID_NSPIRE: return "NSpire"; // must match tifiles name
169 default: return "unknown";
170 }
171 }
172
173 /**
174 * ticables_usbpid_to_port:
175 * @str: a Usb Product Id as string like "SilverLink".
176 *
177 * Do a string to integer conversion.
178 *
179 * Return value: a Usb Product Id.
180 **/
181 UsbPid TICALL ticables_string_to_usbpid(const char *str)
182 {
183 if (str == NULL)
184 {
185 ticables_critical("%s(NULL)", __FUNCTION__);
186 return PID_UNKNOWN;
187 }
188
189 if(!strcmp(str, "SilverLink"))
190 return PID_TIGLUSB;
191 else if(!strcmp(str, "TI89t"))
192 return PID_TI89TM;
193 else if(!strcmp(str, "TI84+"))
194 return PID_TI84P;
195 else if(!strcmp(str, "TI84+SE"))
196 return PID_TI84P_SE;
197 else if(!strcmp(str, "NSpire"))
198 return PID_NSPIRE;
199
200 return PID_UNKNOWN;
201 }