1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3 
4 /*  libtifiles - file format 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 "tifiles.h"
27 
28 /**
29  * tifiles_model_to_string:
30  * @model: a calculator model.
31  *
32  * Do an integer to string conversion.
33  *
34  * Return value: a string like "TI92+".
35  **/
tifiles_model_to_string(CalcModel model)36 TIEXPORT2 const char *TICALL tifiles_model_to_string(CalcModel model)
37 {
38 	return ticonv_model_to_string(model);
39 }
40 
41 /**
42  * tifiles_string_to_model:
43  * @str: a calculator model as string like "TI92".
44  *
45  * Do a string to integer conversion.
46  *
47  * Return value: a calculator model.
48  **/
tifiles_string_to_model(const char * str)49 TIEXPORT2 CalcModel TICALL tifiles_string_to_model(const char *str)
50 {
51 	return ticonv_string_to_model(str);
52 }
53 
54 /**
55  * tifiles_attribute_to_string:
56  * @attrb: an attribute of variable.
57  *
58  * Do an integer to string conversion.
59  *
60  * Return value: a string like "archived".
61  **/
tifiles_attribute_to_string(FileAttr attrb)62 TIEXPORT2 const char *TICALL tifiles_attribute_to_string(FileAttr attrb)
63 {
64 	switch (attrb)
65 	{
66 	case ATTRB_NONE:      return _("none     ");
67 	case ATTRB_LOCKED:    return _("locked   ");
68 	case ATTRB_ARCHIVED:  return _("archived ");
69 	case ATTRB_PROTECTED: return _("protected");
70 	default: return "unknown";
71 	}
72 }
73 
74 /**
75  * tifiles_string_to_attribute:
76  * @str: a variable attribute string like "protected".
77  *
78  * Do a string to integer conversion.
79  *
80  * Return value: a variable attribute.
81  **/
tifiles_string_to_attribute(const char * str)82 TIEXPORT2 FileAttr TICALL tifiles_string_to_attribute(const char *str)
83 {
84 	if (str != NULL)
85 	{
86 		if(!g_ascii_strcasecmp(str, _("none     ")))
87 			return ATTRB_NONE;
88 		else if(!g_ascii_strcasecmp(str, _("locked   ")))
89 			return ATTRB_LOCKED;
90 		else if(!g_ascii_strcasecmp(str, _("archived ")))
91 			return ATTRB_ARCHIVED;
92 		else if(!g_ascii_strcasecmp(str, _("protected")))
93 			return ATTRB_PROTECTED;
94 	}
95 
96 	return ATTRB_NONE;
97 }
98 
99 /**
100  * tifiles_class_to_string:
101  * @klass: a class of file.
102  *
103  * Do an integer to string conversion.
104  *
105  * Return value: a string like "backup".
106  **/
tifiles_class_to_string(FileClass klass)107 TIEXPORT2 const char *TICALL tifiles_class_to_string(FileClass klass)
108 {
109 	switch (klass)
110 	{
111 	case TIFILE_SINGLE: return _("single");
112 	case TIFILE_GROUP:  return _("group");
113 	case TIFILE_REGULAR:return _("regular");
114 	case TIFILE_BACKUP: return _("backup");
115 	case TIFILE_TIGROUP:return _("tigroup");
116 	case TIFILE_OS:		return _("os");
117 	case TIFILE_APP:	return _("application");
118 	case TIFILE_FLASH:  return _("flash");
119 	default: return _("unknown");
120 	}
121 }
122 
123 /**
124  * tifiles_string_to_class:
125  * @str: a file class string like "backup".
126  *
127  * Do a string to integer conversion.
128  *
129  * Return value: a file class.
130  **/
tifiles_string_to_class(const char * str)131 TIEXPORT2 FileClass TICALL tifiles_string_to_class(const char *str)
132 {
133 	if (str != NULL)
134 	{
135 		if(!g_ascii_strcasecmp(str, _("single")))
136 			return TIFILE_SINGLE;
137 		else if(!g_ascii_strcasecmp(str, _("group")))
138 			return TIFILE_GROUP;
139 		else if(!g_ascii_strcasecmp(str, _("regular")))
140 			return TIFILE_REGULAR;
141 		else if(!g_ascii_strcasecmp(str, _("backup")))
142 			return TIFILE_BACKUP;
143 		else if(!g_ascii_strcasecmp(str, _("os")))
144 			return TIFILE_OS;
145 		else if(!g_ascii_strcasecmp(str, _("application")))
146 			return TIFILE_APP;
147 		else if(!g_ascii_strcasecmp(str, _("flash")))
148 			return TIFILE_FLASH;
149 		else if(!g_ascii_strcasecmp(str, _("tigroup")))
150 			return TIFILE_TIGROUP;
151 	}
152 
153 	return 0;
154 }
155