1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2006 Matthias Clasen
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 #include "paper_names.c"
26 static const gint n_infos = G_N_ELEMENTS (standard_names);
27 static const gint n_extra = G_N_ELEMENTS (extra_ppd_names);
36 static NameInfo *names = NULL;
37 static gint n_names = 0;
40 add_name (const gchar *name)
42 names[n_names].s = name;
43 names[n_names].len = strlen (name);
44 names[n_names].suffix = -1;
45 names[n_names].offset = 0;
51 find_name (const gchar *name)
58 for (i = 0; i < n_names; i++)
60 if (strcmp (names[i].s, name) == 0)
61 return names[i].offset;
64 fprintf (stderr, "BOO! %s not found\n", name);
69 #define MM_PER_INCH 25.4
70 #define POINTS_PER_INCH 72
73 parse_media_size (const gchar *size,
79 gdouble short_dim, long_dim;
83 short_dim = g_ascii_strtod (p, &e);
85 if (p == e || *e != 'x')
88 p = e + 1; /* Skip x */
90 long_dim = g_ascii_strtod (p, &e);
97 if (strcmp (p, "in") == 0)
99 short_dim = short_dim * MM_PER_INCH;
100 long_dim = long_dim * MM_PER_INCH;
102 else if (strcmp (p, "mm") != 0)
106 *width_mm = short_dim;
108 *height_mm = long_dim;
114 main (int argc, char *argv[])
117 gdouble width, height;
119 names = (NameInfo *) malloc (sizeof (NameInfo) * (4 + n_infos + 2 * n_extra));
123 for (i = 0; i < n_infos; i++)
125 add_name (standard_names[i].name);
126 add_name (standard_names[i].display_name);
127 if (standard_names[i].ppd_name)
128 add_name (standard_names[i].ppd_name);
131 for (i = 0; i < n_extra; i++)
133 add_name (extra_ppd_names[i].ppd_name);
134 add_name (extra_ppd_names[i].standard_name);
137 /* find suffixes and dupes */
138 for (i = 0; i < n_names; i++)
139 for (j = 0; j < n_names; j++)
141 if (i == j) continue;
143 if (names[i].len < names[j].len ||
144 (names[i].len == names[j].len && j < i))
146 if (strcmp (names[i].s, names[j].s + names[j].len - names[i].len) == 0)
154 /* calculate offsets for regular entries */
156 for (i = 0; i < n_names; i++)
158 if (names[i].suffix == -1)
160 names[i].offset = offset;
161 offset += names[i].len + 1;
165 /* calculate offsets for suffixes */
166 for (i = 0; i < n_names; i++)
168 if (names[i].suffix != -1)
173 } while (names[j].suffix != -1);
174 names[i].offset = names[j].offset + names[j].len - names[i].len;
178 printf ("/* Generated by gen-paper-names */\n\n");
180 /* write N_ marked names */
183 for (i = 0; i < n_infos; i++)
184 printf ("NC_(\"paper size\", \"%s\")\n", standard_names[i].display_name);
185 printf ("#endif\n\n");
188 printf ("static const char paper_names[] =");
189 for (i = 0; i < n_names; i++)
191 if (names[i].suffix == -1)
192 printf ("\n \"%s\\0\"", names[i].s);
196 /* dump PaperInfo array */
197 printf ("typedef struct {\n"
201 " int display_name;\n"
204 "static const PaperInfo standard_names_offsets[] = {\n");
206 for (i = 0; i < n_infos; i++)
208 width = height = 0.0;
209 if (!parse_media_size (standard_names[i].size, &width, &height))
210 printf ("failed to parse size %s\n", standard_names[i].size);
212 printf (" { %4d, %g, %g, %4d, %4d },\n",
213 find_name (standard_names[i].name),
215 find_name (standard_names[i].display_name),
216 find_name (standard_names[i].ppd_name));
224 printf ("static const struct {\n"
226 " int standard_name;\n"
227 "} extra_ppd_names_offsets[] = {\n");
229 for (i = 0; i < n_extra; i++)
231 printf (" { %4d, %4d },\n",
232 find_name (extra_ppd_names[i].ppd_name),
233 find_name (extra_ppd_names[i].standard_name));