#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if ENABLE_NLS
#include <libintl.h>
#define _(String) gettext (String)
#else
#define _(String) String
#endif
#if HAVE_LC_MESSAGES
#include <locale.h>
#endif
#include "afm.h"
#include "getopt.h"
#define HANDLE_ERROR(msg) \
if (error != AFM_SUCCESS) \
{ \
char buf[256]; \
afm_error_to_string (error, buf); \
fprintf (stderr, "%s: %s: %s\n", program, msg, buf); \
exit (1); \
}
static void usage ();
static char *fname = "font.map";
static char *program;
static struct option long_options[] =
{
{"output-file", required_argument, 0, 'p'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, 0, 0, 0},
};
int
main (int argc, char *argv[])
{
AFMError error;
AFMHandle afm;
AFMFont font;
int i;
FILE *ofp;
FILE *mfp;
program = strrchr (argv[0], '/');
if (program == NULL)
program = argv[0];
else
program++;
argv[0] = program;
#if HAVE_SETLOCALE
#if HAVE_LC_MESSAGES
setlocale (LC_MESSAGES, "");
#endif
#endif
#if ENABLE_NLS
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
while (1)
{
int option_index = 0;
int c;
c = getopt_long (argc, argv, "p:h", long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 'h':
usage ();
exit (0);
case 'p':
if (strcmp (optarg, "-") == 0)
fname = NULL;
else
fname = optarg;
break;
case 'V':
printf ("%s for GNU %s %s\n", program, PACKAGE, VERSION);
exit (0);
break;
case '?':
usage ();
exit (1);
break;
}
}
printf (_("file=%s\n"), fname ? fname : _("stdout"));
if (fname)
{
ofp = fopen (fname, "w");
if (ofp == NULL)
{
char buf[256];
sprintf (buf, _("%s: couldn't open output file \"%s\""),
program, fname);
perror (buf);
exit (1);
}
mfp = stdout;
}
else
{
ofp = stdout;
mfp = stderr;
}
error = afm_create (NULL, 0, &afm);
HANDLE_ERROR (_("couldn't create AFM library"));
for (i = optind; i < argc; i++)
{
fprintf (mfp, "%s...\n", argv[i]);
error = afm_open_file (afm, AFM_I_MINIMUM, argv[i], &font);
if (error == AFM_SUCCESS)
{
char *cp;
char *sf;
int len;
cp = strrchr (argv[i], '/');
if (cp == NULL)
cp = argv[i];
else
cp++;
sf = strrchr (argv[i], '.');
if (sf)
len = sf - cp;
else
len = strlen (cp);
fprintf (ofp, "%-30s\t%.*s\n", font->global_info.FontName, len, cp);
(void) afm_close_font (font);
}
else
{
char buf[256];
afm_error_to_string (error, buf);
fprintf (mfp, "%s: %s\n", program, buf);
}
}
if (fname)
fclose (ofp);
return 0;
}
static void
usage ()
{
printf (_("\
Usage: %s [OPTION]... FILE...\n\
Mandatory arguments to long options are mandatory for short options too.\n\
-h, --help print this help and exit\n\
-p, --output-file=NAME print output to file NAME (default file is\n\
font.map). If FILE is `-', leavy output to\n\
stdout.\n\
-V, --version print version number\n"), program);
}