1 /****************************************************************************/
3 /* The FreeType project -- a free and portable quality TrueType renderer. */
5 /* Copyright 1996-1999 by */
6 /* D. Turner, R.Wilhelm, and W. Lemberg */
8 /* common.c: Various utility functions. */
10 /****************************************************************************/
14 * This is a cheap replacement for getopt() because that routine is not
15 * available on some platforms and behaves differently on other platforms.
16 * This code was written from scratch without looking at any other
19 * This code is hereby expressly placed in the public domain.
20 * mleisher@crl.nmsu.edu (Mark Leisher)
26 static char rcsid
[] __attribute__ ((unused
)) = "$Id$";
28 static char rcsid
[] = "$Id$";
38 #include "freetype.h" /* TT_Raster_Map */
41 * Externals visible to programs.
49 * Internal variables that are used to detect when the global values
55 static const char* cmdname
;
56 static char* const* cmdav
;
65 ft_getopt( int ac
, char* const* av
, const char* pat
)
67 ft_getopt( ac
, av
, pat
)
84 * If there is no pattern, indicate the parsing is done.
86 if ( pat
== 0 || *pat
== 0 )
90 * Always reset the option argument to NULL.
95 * If the number of arguments or argument list do not match the last
96 * values seen, reset the internal pointers and the globals.
98 if ( ac
!= cmdac
|| av
!= cmdav
)
105 * Determine the command name in case it is needed for warning
108 for ( cmdname
= 0, p
= av
[0]; *p
; p
++ )
110 if ( *p
== '/' || *p
== '\\' )
115 * Skip the path separator if the name was assigned.
124 * If the next index is greater than or equal to the number of
125 * arguments, then the command line is done.
127 if ( ft_optind
>= ac
)
131 * Test the next argument for one of three cases:
132 * 1. The next argument does not have an initial '-'.
133 * 2. The next argument is '-'.
134 * 3. The next argument is '--'.
136 * In either of these cases, command line processing is done.
138 if ( av
[ft_optind
][0] != '-' ||
139 strcmp( av
[ft_optind
], "-" ) == 0 ||
140 strcmp( av
[ft_optind
], "--" ) == 0 )
144 * Point at the next command line argument and increment the
145 * command line index.
150 * Look for the first character of the command line option.
152 for ( opt
= *(p
+ 1), pp
= pat
; *pp
&& *pp
!= opt
; pp
++ )
156 * If nothing in the pattern was recognized, then issue a warning
162 fprintf( stderr
, "%s: illegal option -- %c\n", cmdname
, opt
);
167 * If the option expects an argument, get it.
169 if ( *(pp
+ 1) == ':' && (ft_optarg
= av
[ft_optind
]) == 0 )
172 * If the option argument is NULL, issue a warning and return a '?'.
175 fprintf( stderr
, "%s: option requires an argument -- %c\n",
179 else if ( ft_optarg
)
181 * Increment the option index past the argument.
186 * Return the option character.
192 /****************************************************************************/
196 /* a stupid but useful function... */
198 /* rewritten by DavidT to get rid of GPLed programs in the FreeType engine. */
200 /****************************************************************************/
204 ft_basename( const char* name
)
227 if ( c
== '/' || c
== '\\' )
240 Panic( const char* fmt
, ... )
253 exit( EXIT_FAILURE
);
259 Show_Single_Glyph( const TT_Raster_Map
* map
)
261 Show_Single_Glyph( map
)
262 const TT_Raster_Map
* map
;
267 unsigned char* line
= map
->bitmap
;
270 for ( y
= 0; y
< map
->rows
; y
++, line
+= map
->cols
)
272 unsigned char* ptr
= line
;
274 unsigned char mask
= 0x80;
277 for ( x
= 0; x
< map
->width
; x
++ )
279 printf( "%c", (ptr
[0] & mask
) ? '*' : '.' );
294 separator_line( FILE* out
, const int length
)
296 separator_line( out
, length
)
304 for ( i
= 0; i
< length
; i
++ )
306 fprintf( out
, "\n\n" );