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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "paper_names.c"
28 static const gint n_infos = G_N_ELEMENTS (standard_names);
29 static const gint n_extra = G_N_ELEMENTS (extra_ppd_names);
38 static NameInfo *names = NULL;
39 static gint n_names = 0;
42 add_name (const gchar *name)
44 names[n_names].s = name;
45 names[n_names].len = strlen (name);
46 names[n_names].suffix = -1;
47 names[n_names].offset = 0;
53 find_name (const gchar *name)
60 for (i = 0; i < n_names; i++)
62 if (strcmp (names[i].s, name) == 0)
63 return names[i].offset;
66 fprintf (stderr, "BOO! %s not found\n", name);
71 #define MM_PER_INCH 25.4
72 #define POINTS_PER_INCH 72
75 parse_media_size (const gchar *size,
81 gdouble short_dim, long_dim;
85 short_dim = g_ascii_strtod (p, &e);
87 if (p == e || *e != 'x')
90 p = e + 1; /* Skip x */
92 long_dim = g_ascii_strtod (p, &e);
99 if (strcmp (p, "in") == 0)
101 short_dim = short_dim * MM_PER_INCH;
102 long_dim = long_dim * MM_PER_INCH;
104 else if (strcmp (p, "mm") != 0)
108 *width_mm = short_dim;
110 *height_mm = long_dim;
116 main (int argc, char *argv[])
119 gdouble width, height;
121 names = (NameInfo *) malloc (sizeof (NameInfo) * (4 + n_infos + 2 * n_extra));
125 for (i = 0; i < n_infos; i++)
127 add_name (standard_names[i].name);
128 add_name (standard_names[i].display_name);
129 if (standard_names[i].ppd_name)
130 add_name (standard_names[i].ppd_name);
133 for (i = 0; i < n_extra; i++)
135 add_name (extra_ppd_names[i].ppd_name);
136 add_name (extra_ppd_names[i].standard_name);
139 /* find suffixes and dupes */
140 for (i = 0; i < n_names; i++)
141 for (j = 0; j < n_names; j++)
143 if (i == j) continue;
145 if (names[i].len < names[j].len ||
146 (names[i].len == names[j].len && j < i))
148 if (strcmp (names[i].s, names[j].s + names[j].len - names[i].len) == 0)
156 /* calculate offsets for regular entries */
158 for (i = 0; i < n_names; i++)
160 if (names[i].suffix == -1)
162 names[i].offset = offset;
163 offset += names[i].len + 1;
167 /* calculate offsets for suffixes */
168 for (i = 0; i < n_names; i++)
170 if (names[i].suffix != -1)
175 } while (names[j].suffix != -1);
176 names[i].offset = names[j].offset + names[j].len - names[i].len;
180 printf ("/* Generated by gen-paper-names */\n\n");
182 /* write N_ marked names */
185 for (i = 0; i < n_infos; i++)
186 printf ("NC_(\"paper size\", \"%s\")\n", standard_names[i].display_name);
187 printf ("#endif\n\n");
190 printf ("static const char paper_names[] =");
191 for (i = 0; i < n_names; i++)
193 if (names[i].suffix == -1)
194 printf ("\n \"%s\\0\"", names[i].s);
198 /* dump PaperInfo array */
199 printf ("typedef struct {\n"
203 " int display_name;\n"
206 "static const PaperInfo standard_names_offsets[] = {\n");
208 for (i = 0; i < n_infos; i++)
210 width = height = 0.0;
211 if (!parse_media_size (standard_names[i].size, &width, &height))
212 printf ("failed to parse size %s\n", standard_names[i].size);
214 printf (" { %4d, %g, %g, %4d, %4d },\n",
215 find_name (standard_names[i].name),
217 find_name (standard_names[i].display_name),
218 find_name (standard_names[i].ppd_name));
226 printf ("static const struct {\n"
228 " int standard_name;\n"
229 "} extra_ppd_names_offsets[] = {\n");
231 for (i = 0; i < n_extra; i++)
233 printf (" { %4d, %4d },\n",
234 find_name (extra_ppd_names[i].ppd_name),
235 find_name (extra_ppd_names[i].standard_name));