#include "ppdc-private.h"
#include <unistd.h>
static void add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog);
static void write_cstring(const char *s);
int main(void)
{
ppdcSource *src; ppdcCatalog *catalog;
if (access("../data", 0) || access("sample.drv", 0))
{
puts("You must run genstrings from the ppdc directory.");
return (1);
}
ppdcSource::add_include("../data");
src = new ppdcSource("sample.drv");
catalog = new ppdcCatalog(NULL);
ppdcMediaSize *size;
for (size = (ppdcMediaSize *)src->sizes->first();
size;
size = (ppdcMediaSize *)src->sizes->next())
catalog->add_message(size->text->value);
ppdcDriver *d;
for (d = (ppdcDriver *)src->drivers->first();
d;
d = (ppdcDriver *)src->drivers->next())
add_ui_strings(d, catalog);
ppdcMessage *message;
for (message = (ppdcMessage *)catalog->messages->first();
message;
message = (ppdcMessage *)catalog->messages->next())
write_cstring(message->id->value);
src->release();
catalog->release();
return (0);
}
static void
add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog) {
catalog->add_message(d->manufacturer->value);
catalog->add_message(d->model_name->value);
ppdcGroup *g; ppdcOption *o; ppdcChoice *c;
for (g = (ppdcGroup *)d->groups->first();
g;
g = (ppdcGroup *)d->groups->next())
{
if (!g->options->count)
continue;
if (strcasecmp(g->name->value, "General"))
catalog->add_message(g->text->value);
for (o = (ppdcOption *)g->options->first();
o;
o = (ppdcOption *)g->options->next())
{
if (!o->choices->count)
continue;
if (o->text->value && strcmp(o->name->value, o->text->value))
catalog->add_message(o->text->value);
else
catalog->add_message(o->name->value);
for (c = (ppdcChoice *)o->choices->first();
c;
c = (ppdcChoice *)o->choices->next())
if (c->text->value && strcmp(c->name->value, c->text->value))
catalog->add_message(c->text->value);
else
catalog->add_message(c->name->value);
}
}
ppdcAttr *a; for (a = (ppdcAttr *)d->attrs->first();
a;
a = (ppdcAttr *)d->attrs->next())
{
if (a->text->value && a->text->value[0] &&
(a->localizable ||
!strncmp(a->name->value, "Custom", 6) ||
!strncmp(a->name->value, "ParamCustom", 11) ||
!strcmp(a->name->value, "APCustomColorMatchingName") ||
!strcmp(a->name->value, "APPrinterPreset") ||
!strcmp(a->name->value, "cupsICCProfile") ||
!strcmp(a->name->value, "cupsIPPReason") ||
!strcmp(a->name->value, "cupsMarkerName")))
{
catalog->add_message(a->text->value);
if ((a->localizable && a->value->value[0]) ||
!strcmp(a->name->value, "cupsIPPReason"))
catalog->add_message(a->value->value);
}
else if (!strncmp(a->name->value, "Custom", 6) ||
!strncmp(a->name->value, "ParamCustom", 11))
catalog->add_message(a->name->value);
}
}
static void
write_cstring(const char *s)
{
fputs("_(\"", stdout);
if (s)
{
while (*s)
{
if (*s == '\\')
fputs("\\\\", stdout);
else if (*s == '\"')
fputs("\\\"", stdout);
else if (*s == '\t')
fputs("\\t", stdout);
else if (*s == '\n')
fputs("\\n", stdout);
else
putchar(*s);
s ++;
}
}
puts("\");");
}