Correct the suffix/duplicate optimizations.
2006-04-07 Matthias Clasen <mclasen@redhat.com> * gtk/paper_names_offsets.c: * gtk/gen-paper-names.c: Correct the suffix/duplicate optimizations.
This commit is contained in:
committed by
Matthias Clasen
parent
8be5877195
commit
664ab62ba4
@@ -1,3 +1,8 @@
|
||||
2006-04-07 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/paper_names_offsets.c:
|
||||
* gtk/gen-paper-names.c: Correct the suffix/duplicate optimizations.
|
||||
|
||||
2006-04-07 Alexander Larsson <alexl@redhat.com>
|
||||
|
||||
* gtk/gtkprintoperation-win32.c:
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
2006-04-07 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/paper_names_offsets.c:
|
||||
* gtk/gen-paper-names.c: Correct the suffix/duplicate optimizations.
|
||||
|
||||
2006-04-07 Alexander Larsson <alexl@redhat.com>
|
||||
|
||||
* gtk/gtkprintoperation-win32.c:
|
||||
|
||||
@@ -30,65 +30,27 @@ static const gint n_extra = G_N_ELEMENTS (extra_ppd_names);
|
||||
|
||||
typedef struct {
|
||||
const gchar *s;
|
||||
gboolean nify;
|
||||
gint offset;
|
||||
gboolean writeout;
|
||||
gint len;
|
||||
gint suffix;
|
||||
gint offset;
|
||||
} NameInfo;
|
||||
|
||||
/* Calculate offsets, also take care of duplicates and strings
|
||||
* which are suffixes of each other. nify indicates that a string
|
||||
* must be emitted with the N_() macro, and thus must appear on
|
||||
* its own, even if it is a suffix of another string.
|
||||
*/
|
||||
static NameInfo *names = NULL;
|
||||
static gint n_names = 0;
|
||||
|
||||
static void
|
||||
add_name (NameInfo *names,
|
||||
gint *n,
|
||||
const gchar *name,
|
||||
gboolean nify)
|
||||
add_name (const gchar *name)
|
||||
{
|
||||
gint i, nlen, ilen;
|
||||
names[n_names].s = name;
|
||||
names[n_names].len = strlen (name);
|
||||
names[n_names].suffix = -1;
|
||||
names[n_names].offset = 0;
|
||||
|
||||
names[*n].s = name;
|
||||
names[*n].nify = nify;
|
||||
names[*n].writeout = 1;
|
||||
if (*n > 0)
|
||||
names[*n].offset = names[*n - 1].offset + strlen(names[*n - 1].s) + 1;
|
||||
else
|
||||
names[*n].offset = 0;
|
||||
|
||||
nlen = strlen (name);
|
||||
for (i = 0; i < *n; i++)
|
||||
{
|
||||
ilen = strlen (names[i].s);
|
||||
|
||||
if (ilen >= nlen)
|
||||
{
|
||||
if (strcmp (name, names[i].s + ilen - nlen) == 0)
|
||||
{
|
||||
names[*n].offset = names[i].offset + ilen - nlen;
|
||||
|
||||
if (ilen == nlen)
|
||||
{
|
||||
names[i].nify = names[i].nify || nify;
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
names[*n].writeout = nify;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(*n)++;
|
||||
n_names++;
|
||||
}
|
||||
|
||||
static gint
|
||||
find_name (NameInfo *names,
|
||||
gint n_names,
|
||||
const gchar *name)
|
||||
find_name (const gchar *name)
|
||||
{
|
||||
gint i;
|
||||
|
||||
@@ -101,7 +63,7 @@ find_name (NameInfo *names,
|
||||
return names[i].offset;
|
||||
}
|
||||
|
||||
printf ("BOO! %s not found\n", name);
|
||||
fprintf (stderr, "BOO! %s not found\n", name);
|
||||
|
||||
return -2;
|
||||
}
|
||||
@@ -153,46 +115,81 @@ parse_media_size (const gchar *size,
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gint i, n_names;
|
||||
NameInfo *names;
|
||||
gint i, j, offset;
|
||||
gdouble width, height;
|
||||
|
||||
names = (NameInfo *) malloc (sizeof (NameInfo) * (n_infos + n_extra));
|
||||
names = (NameInfo *) malloc (sizeof (NameInfo) * (4 + n_infos + 2 * n_extra));
|
||||
n_names = 0;
|
||||
|
||||
/* collect names */
|
||||
|
||||
n_names = 0;
|
||||
for (i = 0; i < n_infos; i++)
|
||||
{
|
||||
add_name (names, &n_names, standard_names[i].name, FALSE);
|
||||
add_name (names, &n_names, standard_names[i].display_name, TRUE);
|
||||
add_name (standard_names[i].name);
|
||||
add_name (standard_names[i].display_name);
|
||||
if (standard_names[i].ppd_name)
|
||||
add_name (names, &n_names, standard_names[i].ppd_name, FALSE);
|
||||
add_name (standard_names[i].ppd_name);
|
||||
}
|
||||
|
||||
for (i = 0; i < n_extra; i++)
|
||||
{
|
||||
add_name (names, &n_names, extra_ppd_names[i].ppd_name, 0);
|
||||
add_name (names, &n_names, extra_ppd_names[i].standard_name, 0);
|
||||
add_name (extra_ppd_names[i].ppd_name);
|
||||
add_name (extra_ppd_names[i].standard_name);
|
||||
}
|
||||
|
||||
/* dump names */
|
||||
|
||||
printf ("/* Generated by gen-paper-names */\n\n"
|
||||
"#ifndef N_\n"
|
||||
"#define N_(s) s\n"
|
||||
"#endif\n\n"
|
||||
"const char paper_names[] =");
|
||||
/* find suffixes and dupes */
|
||||
for (i = 0; i < n_names; i++)
|
||||
for (j = 0; j < n_names; j++)
|
||||
{
|
||||
if (i == j) continue;
|
||||
|
||||
if (names[i].len < names[j].len ||
|
||||
(names[i].len == names[j].len && j < i))
|
||||
{
|
||||
if (strcmp (names[i].s, names[j].s + names[j].len - names[i].len) == 0)
|
||||
{
|
||||
names[i].suffix = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* calculate offsets for regular entries */
|
||||
offset = 0;
|
||||
for (i = 0; i < n_names; i++)
|
||||
{
|
||||
if (names[i].writeout)
|
||||
if (names[i].suffix == -1)
|
||||
{
|
||||
if (names[i].nify)
|
||||
printf ("\n N_(\"%s\") \"\\0\"", names[i].s);
|
||||
else
|
||||
printf ("\n \"%s\\0\"", names[i].s);
|
||||
names[i].offset = offset;
|
||||
offset += names[i].len + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* calculate offsets for suffixes */
|
||||
for (i = 0; i < n_names; i++)
|
||||
{
|
||||
if (names[i].suffix != -1)
|
||||
{
|
||||
j = names[i].suffix;
|
||||
names[i].offset = names[j].offset + names[j].len - names[i].len;
|
||||
}
|
||||
}
|
||||
|
||||
printf ("/* Generated by gen-paper-names */\n\n");
|
||||
|
||||
/* write N_ marked names */
|
||||
|
||||
printf ("#if 0\n");
|
||||
for (i = 0; i < n_infos; i++)
|
||||
printf ("N_(\"%s\")\n", standard_names[i].display_name);
|
||||
printf ("#endif\n\n");
|
||||
|
||||
/* write strings */
|
||||
printf ("const char paper_names[] =");
|
||||
for (i = 0; i < n_names; i++)
|
||||
{
|
||||
if (names[i].suffix == -1)
|
||||
printf ("\n \"%s\\0\"", names[i].s);
|
||||
}
|
||||
printf (";\n\n");
|
||||
|
||||
/* dump PaperInfo array */
|
||||
@@ -212,10 +209,10 @@ main (int argc, char *argv[])
|
||||
printf ("failed to parse size %s\n", standard_names[i].size);
|
||||
|
||||
printf (" { %4d, %g, %g, %4d, %4d },\n",
|
||||
find_name (names, n_names, standard_names[i].name),
|
||||
find_name (standard_names[i].name),
|
||||
width, height,
|
||||
find_name (names, n_names, standard_names[i].display_name),
|
||||
find_name (names, n_names, standard_names[i].ppd_name));
|
||||
find_name (standard_names[i].display_name),
|
||||
find_name (standard_names[i].ppd_name));
|
||||
}
|
||||
|
||||
printf ("};\n\n");
|
||||
@@ -231,8 +228,8 @@ main (int argc, char *argv[])
|
||||
for (i = 0; i < n_extra; i++)
|
||||
{
|
||||
printf (" { %4d, %4d },\n",
|
||||
find_name (names, n_names, extra_ppd_names[i].ppd_name),
|
||||
find_name (names, n_names, extra_ppd_names[i].standard_name));
|
||||
find_name (extra_ppd_names[i].ppd_name),
|
||||
find_name (extra_ppd_names[i].standard_name));
|
||||
}
|
||||
|
||||
printf ("};\n\n");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user