sfnt2fon: Avoid using getopt_long().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-10-05 11:52:53 +02:00
parent 3eb1855c7e
commit e0ef12241b
1 changed files with 39 additions and 46 deletions

View File

@ -27,9 +27,6 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#ifdef HAVE_FREETYPE
@ -438,9 +435,11 @@ static const char *output_name;
static FT_Library ft_library;
static void usage(char **argv)
static const char *argv0;
static void usage(void)
{
fprintf(stderr, "%s [options] input.ttf ppem,enc,avg_width ...\n", argv[0]);
fprintf(stderr, "%s [options] input.ttf ppem,enc,avg_width ...\n", argv0);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h Display help\n" );
fprintf(stderr, " -d char Set the font default char\n" );
@ -825,41 +824,36 @@ static void write_fontinfo( const struct fontinfo *info, FILE *fp )
fwrite( info->data, info->hdr.dfSize - info->hdr.fi.dfBitsOffset, 1, fp );
}
/* parse options from the argv array and remove all the recognized ones */
static char **parse_options( int argc, char **argv )
static void option_callback( int optc, char *optarg )
{
int optc;
while ((optc = getopt_long( argc, argv, "d:ho:qr:s", NULL, NULL )) != -1)
switch(optc)
{
switch(optc)
{
case 'd':
option_defchar = atoi( optarg );
break;
case 'o':
option_output = xstrdup( optarg );
break;
case 'q':
option_quiet = 1;
break;
case 'r':
option_dpi = atoi( optarg );
break;
case 's':
option_fnt_mode = 1;
break;
case 'h':
usage(argv);
exit(0);
case '?':
usage(argv);
exit(1);
}
case 'd':
option_defchar = atoi( optarg );
break;
case 'o':
option_output = xstrdup( optarg );
break;
case 'q':
option_quiet = 1;
break;
case 'r':
option_dpi = atoi( optarg );
break;
case 's':
option_fnt_mode = 1;
break;
case 'h':
usage();
exit(0);
case '?':
fprintf( stderr, "%s: %s\n\n", argv0, optarg );
usage();
exit(1);
}
return &argv[optind];
}
int main(int argc, char **argv)
{
int i, j;
@ -875,18 +869,19 @@ int main(int argc, char **argv)
NE_TYPEINFO rc_type;
NE_NAMEINFO rc_name;
struct fontinfo **info;
char *input_file;
char **args;
const char *input_file;
struct strarray args;
short tmp16;
args = parse_options( argc, argv );
argv0 = argv[0];
args = parse_options( argc, argv, "d:ho:qr:s", NULL, 0, option_callback );
input_file = *args++;
if (!input_file || !*args)
if (!args.count)
{
usage(argv);
usage();
exit(1);
}
input_file = args.str[0];
if(FT_Init_FreeType(&ft_library))
error("ft init failure\n");
@ -894,9 +889,7 @@ int main(int argc, char **argv)
FT_Version.major=FT_Version.minor=FT_Version.patch=-1;
FT_Library_Version(ft_library,&FT_Version.major,&FT_Version.minor,&FT_Version.patch);
num_files = 0;
while (args[num_files]) num_files++;
num_files = args.count - 1;
if (option_fnt_mode && num_files > 1)
error( "can only specify one font in .fnt mode\n" );
@ -906,9 +899,9 @@ int main(int argc, char **argv)
int ppem, enc, avg_width;
const char *name;
if (sscanf( args[i], "%d,%d,%d", &ppem, &enc, &avg_width ) != 3)
if (sscanf( args.str[i + 1], "%d,%d,%d", &ppem, &enc, &avg_width ) != 3)
{
usage(argv);
usage();
exit(1);
}
if (!(info[i] = fill_fontinfo( input_file, ppem, enc, option_dpi, option_defchar, avg_width )))