diff options
Diffstat (limited to 'gconf/gconf-format.c')
-rw-r--r-- | gconf/gconf-format.c | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/gconf/gconf-format.c b/gconf/gconf-format.c deleted file mode 100644 index ea8a808..0000000 --- a/gconf/gconf-format.c +++ /dev/null | |||
@@ -1,200 +0,0 @@ | |||
1 | /* gconf - General purpose configuration parser. | ||
2 | Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | #include <gconf.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <ctype.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | #if ENABLE_NLS | ||
27 | # include "gettext.h" | ||
28 | #else | ||
29 | # define gettext(s) s | ||
30 | #endif | ||
31 | |||
32 | #define _(s) gettext (s) | ||
33 | #define N_(s) s | ||
34 | |||
35 | const char * | ||
36 | gconf_data_type_string (enum gconf_data_type type) | ||
37 | { | ||
38 | switch (type) | ||
39 | { | ||
40 | case gconf_type_void: | ||
41 | return "void"; | ||
42 | |||
43 | case gconf_type_string: | ||
44 | return "string"; | ||
45 | |||
46 | case gconf_type_short: | ||
47 | case gconf_type_ushort: | ||
48 | case gconf_type_int: | ||
49 | case gconf_type_uint: | ||
50 | case gconf_type_long: | ||
51 | case gconf_type_ulong: | ||
52 | case gconf_type_size: | ||
53 | /* case gconf_type_off:*/ | ||
54 | case gconf_type_uintmax: | ||
55 | case gconf_type_intmax: | ||
56 | return "number"; | ||
57 | |||
58 | case gconf_type_time: | ||
59 | return "time"; | ||
60 | |||
61 | case gconf_type_bool: | ||
62 | return "boolean"; | ||
63 | |||
64 | case gconf_type_ipv4: | ||
65 | return "IPv4"; | ||
66 | |||
67 | case gconf_type_cidr: | ||
68 | return "CIDR"; | ||
69 | |||
70 | case gconf_type_host: | ||
71 | return "hostname"; | ||
72 | |||
73 | case gconf_type_sockaddr: | ||
74 | return "sock-addr"; | ||
75 | |||
76 | case gconf_type_section: | ||
77 | return "section"; | ||
78 | } | ||
79 | return "UNKNOWN?"; | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | format_level (FILE *stream, unsigned level) | ||
84 | { | ||
85 | while (level--) | ||
86 | fprintf (stream, " "); | ||
87 | } | ||
88 | |||
89 | void | ||
90 | gconf_format_docstring (FILE *stream, const char *docstring, unsigned level) | ||
91 | { | ||
92 | size_t len = strlen (docstring); | ||
93 | int width = 78 - level * 2; | ||
94 | |||
95 | if (width < 0) | ||
96 | { | ||
97 | width = 78; | ||
98 | level = 0; | ||
99 | } | ||
100 | |||
101 | while (len) | ||
102 | { | ||
103 | size_t seglen; | ||
104 | const char *p; | ||
105 | |||
106 | for (seglen = 0, p = docstring; p < docstring + width && *p; p++) | ||
107 | { | ||
108 | if (*p == '\n') | ||
109 | { | ||
110 | seglen = p - docstring; | ||
111 | break; | ||
112 | } | ||
113 | if (isspace (*p)) | ||
114 | seglen = p - docstring; | ||
115 | } | ||
116 | if (seglen == 0 || *p == 0) | ||
117 | seglen = p - docstring; | ||
118 | |||
119 | format_level (stream, level); | ||
120 | fprintf (stream, "# "); | ||
121 | fwrite (docstring, seglen, 1, stream); | ||
122 | fputc ('\n', stream); | ||
123 | len -= seglen; | ||
124 | docstring += seglen; | ||
125 | if (*docstring == '\n') | ||
126 | { | ||
127 | docstring++; | ||
128 | len--; | ||
129 | } | ||
130 | else | ||
131 | while (*docstring && isspace (*docstring)) | ||
132 | { | ||
133 | docstring++; | ||
134 | len--; | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | void | ||
140 | gconf_format_simple_statement (FILE *stream, struct gconf_keyword *kwp, | ||
141 | unsigned level) | ||
142 | { | ||
143 | const char *argstr; | ||
144 | |||
145 | if (kwp->docstring) | ||
146 | gconf_format_docstring (stream, kwp->docstring, level); | ||
147 | format_level (stream, level); | ||
148 | |||
149 | if (kwp->argname) | ||
150 | argstr = kwp->argname; | ||
151 | else | ||
152 | argstr = N_("arg"); | ||
153 | |||
154 | if (strchr ("<[", argstr[0])) | ||
155 | fprintf (stream, "%s %s;\n", kwp->ident, gettext (argstr)); | ||
156 | else if (strchr (argstr, ':')) | ||
157 | fprintf (stream, "%s <%s>;\n", kwp->ident, gettext (argstr)); | ||
158 | else | ||
159 | { | ||
160 | fprintf (stream, "%s <%s: ", kwp->ident, gettext (argstr)); | ||
161 | if (GCONF_IS_LIST (kwp->type)) | ||
162 | fprintf (stream, "list of %s", | ||
163 | gettext (gconf_data_type_string (GCONF_TYPE (kwp->type)))); | ||
164 | else | ||
165 | fprintf (stream, "%s", gettext (gconf_data_type_string (kwp->type))); | ||
166 | fprintf (stream, ">;\n"); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | void | ||
171 | gconf_format_block_statement (FILE *stream, struct gconf_keyword *kwp, | ||
172 | unsigned level) | ||
173 | { | ||
174 | if (kwp->docstring) | ||
175 | gconf_format_docstring (stream, kwp->docstring, level); | ||
176 | format_level (stream, level); | ||
177 | fprintf (stream, "%s", kwp->ident); | ||
178 | if (kwp->argname) | ||
179 | fprintf (stream, " <%s>", gettext (kwp->argname)); | ||
180 | fprintf (stream, " {\n"); | ||
181 | gconf_format_statement_array (stream, kwp->kwd, 0, level + 1); | ||
182 | format_level (stream, level); | ||
183 | fprintf (stream, "}\n"); | ||
184 | } | ||
185 | |||
186 | void | ||
187 | gconf_format_statement_array (FILE *stream, struct gconf_keyword *kwp, | ||
188 | unsigned n, | ||
189 | unsigned level) | ||
190 | { | ||
191 | for (; kwp->ident; kwp++, n++) | ||
192 | { | ||
193 | if (n) | ||
194 | fputc ('\n', stream); | ||
195 | if (kwp->type == gconf_type_section) | ||
196 | gconf_format_block_statement (stream, kwp, level); | ||
197 | else | ||
198 | gconf_format_simple_statement (stream, kwp, level); | ||
199 | } | ||
200 | } | ||