contrib/OWB: add correct SDL dependency, fix compilers used
[AROS-Contrib.git] / freetype1 / test / common.c
blob8c90aa59e99da455799c3b6c89e12d716a1379d7
1 /****************************************************************************/
2 /* */
3 /* The FreeType project -- a free and portable quality TrueType renderer. */
4 /* */
5 /* Copyright 1996-1999 by */
6 /* D. Turner, R.Wilhelm, and W. Lemberg */
7 /* */
8 /* common.c: Various utility functions. */
9 /* */
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
17 * implementation.
19 * This code is hereby expressly placed in the public domain.
20 * mleisher@crl.nmsu.edu (Mark Leisher)
21 * 10 October 1997
24 #ifndef lint
25 #ifdef __GNUC__
26 static char rcsid[] __attribute__ ((unused)) = "$Id$";
27 #else
28 static char rcsid[] = "$Id$";
29 #endif
30 #endif
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
37 #include "common.h"
38 #include "freetype.h" /* TT_Raster_Map */
41 * Externals visible to programs.
44 int ft_opterr = 1;
45 int ft_optind = 1;
46 char* ft_optarg;
49 * Internal variables that are used to detect when the global values
50 * need to be reset.
53 static int cmdac;
54 #ifdef __STDC__
55 static const char* cmdname;
56 static char* const* cmdav;
57 #else
58 static char* cmdname;
59 static char** cmdav;
60 #endif
63 int
64 #ifdef __STDC__
65 ft_getopt( int ac, char* const* av, const char* pat )
66 #else
67 ft_getopt( ac, av, pat )
68 int ac;
69 char** av;
70 char* pat;
71 #endif
73 int opt;
74 #ifdef __STDC__
75 const char* p;
76 const char* pp;
77 #else
78 char* p;
79 char* pp;
80 #endif
84 * If there is no pattern, indicate the parsing is done.
86 if ( pat == 0 || *pat == 0 )
87 return -1;
90 * Always reset the option argument to NULL.
92 ft_optarg = 0;
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 )
100 ft_optind = 1;
101 cmdac = ac;
102 cmdav = av;
105 * Determine the command name in case it is needed for warning
106 * messages.
108 for ( cmdname = 0, p = av[0]; *p; p++ )
110 if ( *p == '/' || *p == '\\' )
111 cmdname = p;
115 * Skip the path separator if the name was assigned.
117 if ( cmdname )
118 cmdname++;
119 else
120 cmdname = av[0];
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 )
128 return -1;
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 )
141 return -1;
144 * Point at the next command line argument and increment the
145 * command line index.
147 p = av[ft_optind++];
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
157 * and return a '?'.
159 if ( *pp == 0 )
161 if ( ft_opterr )
162 fprintf( stderr, "%s: illegal option -- %c\n", cmdname, opt );
163 return '?';
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 '?'.
174 if ( ft_opterr )
175 fprintf( stderr, "%s: option requires an argument -- %c\n",
176 cmdname, opt );
177 opt = '?';
179 else if ( ft_optarg )
181 * Increment the option index past the argument.
183 ft_optind++;
186 * Return the option character.
188 return opt;
192 /****************************************************************************/
193 /* */
194 /* ft_basename(): */
195 /* */
196 /* a stupid but useful function... */
197 /* */
198 /* rewritten by DavidT to get rid of GPLed programs in the FreeType engine. */
199 /* */
200 /****************************************************************************/
202 char*
203 #ifdef __STDC__
204 ft_basename( const char* name )
205 #else
206 ft_basename( name )
207 char* name;
208 #endif
210 #ifdef __STDC__
211 const char* base;
212 const char* current;
213 #else
214 char* base;
215 char* current;
216 #endif
217 char c;
220 base = name;
221 current = name;
223 c = *current;
225 while ( c )
227 if ( c == '/' || c == '\\' )
228 base = current + 1;
230 current++;
231 c = *current;
234 return (char*)base;
238 void
239 #ifdef __STDC__
240 Panic( const char* fmt, ... )
241 #else
242 Panic( fmt )
243 const char* fmt;
244 #endif
246 va_list ap;
249 va_start( ap, fmt );
250 vprintf( fmt, ap );
251 va_end( ap );
253 exit( EXIT_FAILURE );
257 void
258 #ifdef __STDC__
259 Show_Single_Glyph( const TT_Raster_Map* map )
260 #else
261 Show_Single_Glyph( map )
262 const TT_Raster_Map* map;
263 #endif
265 int y;
267 unsigned char* line = map->bitmap;
270 for ( y = 0; y < map->rows; y++, line += map->cols )
272 unsigned char* ptr = line;
273 int x;
274 unsigned char mask = 0x80;
277 for ( x = 0; x < map->width; x++ )
279 printf( "%c", (ptr[0] & mask) ? '*' : '.' );
280 mask >>= 1;
281 if ( mask == 0 )
283 mask = 0x80;
284 ptr++;
287 printf( "\n" );
292 void
293 #ifdef __STDC__
294 separator_line( FILE* out, const int length )
295 #else
296 separator_line( out, length )
297 FILE* out;
298 int length;
299 #endif
301 int i;
304 for ( i = 0; i < length; i++ )
305 fputc( '-', out );
306 fprintf( out, "\n\n" );
310 /* End */