ReactOS  0.4.15-dev-1386-g5cb9f87
ftrandom.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <dirent.h>
#include <signal.h>
#include <time.h>
#include <ft2build.h>
Include dependency graph for ftrandom.c:

Go to the source code of this file.

Classes

struct  fontlist
 

Macros

#define _XOPEN_SOURCE   500 /* for `kill', `strdup', `random', and `srandom' */
 
#define true   1
 
#define false   0
 
#define forever   for (;;)
 
#define GOOD_FONTS_DIR   "/usr/local/share/fonts"
 

Functions

static int FT_MoveTo (const FT_Vector *to, void *user)
 
static int FT_LineTo (const FT_Vector *to, void *user)
 
static int FT_ConicTo (const FT_Vector *_cp, const FT_Vector *to, void *user)
 
static int FT_CubicTo (const FT_Vector *cp1, const FT_Vector *cp2, const FT_Vector *to, void *user)
 
static void TestFace (FT_Face face)
 
static void ExecuteTest (char *testfont)
 
static int extmatch (char *filename, char **extensions)
 
static void figurefiletype (struct fontlist *item)
 
static void FindFonts (char **fontdirs, char **extensions)
 
static unsigned int getErrorCnt (struct fontlist *item)
 
static int getRandom (int low, int high)
 
static int copyfont (struct fontlist *item, char *newfont)
 
static void abort_test (int sig)
 
static void do_test (void)
 
static void usage (FILE *out, char *name)
 
int main (int argc, char **argv)
 

Variables

static int check_outlines = false
 
static int nohints = false
 
static int rasterize = false
 
static charresults_dir = "results"
 
static chardefault_dir_list []
 
static chardefault_ext_list []
 
static unsigned int error_count = 1
 
static double error_fraction = 0.0
 
static FT_F26Dot6 font_size = 12 * 64
 
static struct fontlistfontlist
 
static unsigned int fcnt
 
static FT_Outline_Funcs outlinefuncs
 
static int child_pid
 

Macro Definition Documentation

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   500 /* for `kill', `strdup', `random', and `srandom' */

Definition at line 32 of file ftrandom.c.

◆ false

#define false   0

Definition at line 52 of file ftrandom.c.

◆ forever

#define forever   for (;;)

Definition at line 53 of file ftrandom.c.

◆ GOOD_FONTS_DIR

#define GOOD_FONTS_DIR   "/usr/local/share/fonts"

Definition at line 61 of file ftrandom.c.

◆ true

#define true   1

Definition at line 51 of file ftrandom.c.

Function Documentation

◆ abort_test()

static void abort_test ( int  sig)
static

Definition at line 505 of file ftrandom.c.

506  {
507  FT_UNUSED( sig );
508 
509  /* If a time-out happens, then kill the child */
510  kill( child_pid, SIGFPE );
511  write( 2, "Timeout... ", 11 );
512  }
#define write
Definition: acwin.h:97
static int child_pid
Definition: ftrandom.c:502
#define SIGFPE
Definition: signal.h:30
#define FT_UNUSED(arg)
Definition: ftconfig.h:101

Referenced by do_test().

◆ copyfont()

static int copyfont ( struct fontlist item,
char newfont 
)
static

Definition at line 437 of file ftrandom.c.

439  {
440  static char buffer[8096];
441  FILE *good, *newf;
442  size_t len;
443  unsigned int i, err_cnt;
444 
445 
446  good = fopen( item->name, "r" );
447  if ( !good )
448  {
449  fprintf( stderr, "Can't open `%s'\n", item->name );
450  return false;
451  }
452 
453  newf = fopen( newfont, "w+" );
454  if ( !newf )
455  {
456  fprintf( stderr, "Can't create temporary output file `%s'\n",
457  newfont );
458  exit( 1 );
459  }
460 
461  while ( ( len = fread( buffer, 1, sizeof ( buffer ), good ) ) > 0 )
462  fwrite( buffer, 1, len, newf );
463 
464  fclose( good );
465 
466  err_cnt = getErrorCnt( item );
467  for ( i = 0; i < err_cnt; i++ )
468  {
469  fseek( newf, getRandom( 0, (int)( item->len - 1 ) ), SEEK_SET );
470 
471  if ( item->isbinary )
472  putc( getRandom( 0, 0xFF ), newf );
473  else if ( item->isascii )
474  putc( getRandom( 0x20, 0x7E ), newf );
475  else
476  {
477  int hex = getRandom( 0, 15 );
478 
479 
480  if ( hex < 10 )
481  hex += '0';
482  else
483  hex += 'A' - 10;
484 
485  putc( hex, newf );
486  }
487  }
488 
489  if ( ferror( newf ) )
490  {
491  fclose( newf );
492  unlink( newfont );
493  return false;
494  }
495 
496  fclose( newf );
497 
498  return true;
499  }
static int getRandom(int low, int high)
Definition: ftrandom.c:426
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
static unsigned int getErrorCnt(struct fontlist *item)
Definition: ftrandom.c:416
#define unlink
Definition: syshdrs.h:54
GLuint buffer
Definition: glext.h:5915
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
static const char hex[16]
Definition: profile.c:123
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static ATOM item
Definition: dde.c:856
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33

Referenced by do_test().

◆ do_test()

static void do_test ( void  )
static

Definition at line 516 of file ftrandom.c.

517  {
518  int i = getRandom( 0, (int)( fcnt - 1 ) );
519  static int test_num = 0;
520  char buffer[1024];
521 
522 
523  sprintf( buffer, "%s/test%d", results_dir, test_num++ );
524 
525  if ( copyfont ( &fontlist[i], buffer ) )
526  {
527  signal( SIGALRM, abort_test );
528  /* Anything that takes more than 20 seconds */
529  /* to parse and/or rasterize is an error. */
530  alarm( 20 );
531  if ( ( child_pid = fork() ) == 0 )
532  ExecuteTest( buffer );
533  else if ( child_pid != -1 )
534  {
535  int status;
536 
537 
538  waitpid( child_pid, &status, 0 );
539  alarm( 0 );
540  if ( WIFSIGNALED ( status ) )
541  printf( "Error found in file `%s'\n", buffer );
542  else
543  unlink( buffer );
544  }
545  else
546  {
547  fprintf( stderr, "Can't fork test case.\n" );
548  exit( 1 );
549  }
550  alarm( 0 );
551  }
552  }
static int getRandom(int low, int high)
Definition: ftrandom.c:426
static char * results_dir
Definition: ftrandom.c:59
#define unlink
Definition: syshdrs.h:54
static void ExecuteTest(char *testfont)
Definition: ftrandom.c:200
GLuint buffer
Definition: glext.h:5915
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static int child_pid
Definition: ftrandom.c:502
int signal
Definition: except.c:82
static void abort_test(int sig)
Definition: ftrandom.c:505
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
static SERVICE_STATUS status
Definition: service.c:31
static unsigned int fcnt
Definition: ftrandom.c:101
static int copyfont(struct fontlist *item, char *newfont)
Definition: ftrandom.c:437
#define printf
Definition: config.h:203
Definition: ps.c:97

Referenced by main().

◆ ExecuteTest()

static void ExecuteTest ( char testfont)
static

Definition at line 200 of file ftrandom.c.

201  {
203  FT_Face face;
204 
205 
206  if ( FT_Init_FreeType( &context ) )
207  {
208  fprintf( stderr, "Can't initialize FreeType.\n" );
209  exit( 1 );
210  }
211 
212  if ( FT_New_Face( context, testfont, 0, &face ) )
213  {
214  /* The font is erroneous, so if this fails that's ok. */
215  exit( 0 );
216  }
217 
218  if ( face->num_faces == 1 )
219  TestFace( face );
220  else
221  {
222  long i, num;
223 
224 
225  num = face->num_faces;
226  FT_Done_Face( face );
227 
228  for ( i = 0; i < num; i++ )
229  {
230  if ( !FT_New_Face( context, testfont, i, &face ) )
231  TestFace( face );
232  }
233  }
234 
236 
237  exit( 0 );
238  }
Definition: http.c:7094
static void TestFace(FT_Face face)
Definition: ftrandom.c:165
FT_Done_FreeType(FT_Library library)
Definition: ftinit.c:356
FT_Init_FreeType(FT_Library *alibrary)
Definition: ftinit.c:320
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
GLuint GLuint num
Definition: glext.h:9618
WORD face[3]
Definition: mesh.c:4747
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FT_New_Face(FT_Library library, const char *filepathname, FT_Long face_index, FT_Face *aface)
Definition: ftobjs.c:1406
FT_Done_Face(FT_Face face)
Definition: ftobjs.c:2721
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
GLenum GLuint GLint GLenum face
Definition: glext.h:7025

Referenced by do_test(), and main().

◆ extmatch()

static int extmatch ( char filename,
char **  extensions 
)
static

Definition at line 242 of file ftrandom.c.

244  {
245  int i;
246  char* pt;
247 
248 
249  if ( !extensions )
250  return true;
251 
252  pt = strrchr( filename, '.' );
253  if ( !pt )
254  return false;
255  if ( pt < strrchr( filename, '/' ) )
256  return false;
257 
258  for ( i = 0; extensions[i] != NULL; i++ )
259  if ( strcasecmp( pt + 1, extensions[i] ) == 0 ||
260  strcasecmp( pt, extensions[i] ) == 0 )
261  return true;
262 
263  return false;
264  }
#define strcasecmp
Definition: fake.h:9
#define pt(x, y)
Definition: drawing.c:79
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
const char * filename
Definition: ioapi.h:135
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112

Referenced by FindFonts().

◆ figurefiletype()

static void figurefiletype ( struct fontlist item)
static

Definition at line 268 of file ftrandom.c.

269  {
270  FILE* foo;
271 
272 
273  item->isbinary = item->isascii = item->ishex = false;
274 
275  foo = fopen( item->name, "rb" );
276  if ( foo )
277  {
278  /* Try to guess the file type from the first few characters... */
279  int ch1 = getc( foo );
280  int ch2 = getc( foo );
281  int ch3 = getc( foo );
282  int ch4 = getc( foo );
283 
284 
285  fclose( foo );
286 
287  if ( ( ch1 == 0 && ch2 == 1 && ch3 == 0 && ch4 == 0 ) ||
288  ( ch1 == 'O' && ch2 == 'T' && ch3 == 'T' && ch4 == 'O' ) ||
289  ( ch1 == 't' && ch2 == 'r' && ch3 == 'u' && ch4 == 'e' ) ||
290  ( ch1 == 't' && ch2 == 't' && ch3 == 'c' && ch4 == 'f' ) )
291  {
292  /* ttf, otf, ttc files */
293  item->isbinary = true;
294  }
295  else if ( ch1 == 0x80 && ch2 == '\01' )
296  {
297  /* PFB header */
298  item->isbinary = true;
299  }
300  else if ( ch1 == '%' && ch2 == '!' )
301  {
302  /* Random PostScript */
303  if ( strstr( item->name, ".pfa" ) ||
304  strstr( item->name, ".PFA" ) )
305  item->ishex = true;
306  else
307  item->isascii = true;
308  }
309  else if ( ch1 == 1 && ch2 == 0 && ch3 == 4 )
310  {
311  /* Bare CFF */
312  item->isbinary = true;
313  }
314  else if ( ch1 == 'S' && ch2 == 'T' && ch3 == 'A' && ch4 == 'R' )
315  {
316  /* BDF */
317  item->ishex = true;
318  }
319  else if ( ch1 == 'P' && ch2 == 'F' && ch3 == 'R' && ch4 == '0' )
320  {
321  /* PFR */
322  item->isbinary = true;
323  }
324  else if ( ( ch1 == '\1' && ch2 == 'f' && ch3 == 'c' && ch4 == 'p' ) ||
325  ( ch1 == 'M' && ch2 == 'Z' ) )
326  {
327  /* Windows FON */
328  item->isbinary = true;
329  }
330  else
331  {
332  fprintf( stderr,
333  "Can't recognize file type of `%s', assuming binary\n",
334  item->name );
335  item->isbinary = true;
336  }
337  }
338  else
339  {
340  fprintf( stderr, "Can't open `%s' for typing the file.\n",
341  item->name );
342  item->isbinary = true;
343  }
344  }
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static WCHAR foo[]
Definition: stringtable.c:56
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static ATOM item
Definition: dde.c:856
FILE * stderr

Referenced by FindFonts().

◆ FindFonts()

static void FindFonts ( char **  fontdirs,
char **  extensions 
)
static

Definition at line 348 of file ftrandom.c.

350  {
351  int i;
352  unsigned int max;
353  char buffer[1025];
354  struct stat statb;
355 
356 
357  max = 0;
358  fcnt = 0;
359 
360  for ( i = 0; fontdirs[i] != NULL; i++ )
361  {
362  DIR* examples;
363  struct dirent* ent;
364 
365 
366  examples = opendir( fontdirs[i] );
367  if ( !examples )
368  {
369  fprintf( stderr,
370  "Can't open example font directory `%s'\n",
371  fontdirs[i] );
372  exit( 1 );
373  }
374 
375  while ( ( ent = readdir( examples ) ) != NULL )
376  {
377  snprintf( buffer, sizeof ( buffer ),
378  "%s/%s", fontdirs[i], ent->d_name );
379  if ( stat( buffer, &statb ) == -1 || S_ISDIR( statb.st_mode ) )
380  continue;
381  if ( !extensions || extmatch( buffer, extensions ) )
382  {
383  if ( fcnt >= max )
384  {
385  max += 100;
386  fontlist = realloc( fontlist, max * sizeof ( struct fontlist ) );
387  if ( !fontlist )
388  {
389  fprintf( stderr, "Can't allocate memory\n" );
390  exit( 1 );
391  }
392  }
393 
395  fontlist[fcnt].len = statb.st_size;
396 
398  fcnt++;
399  }
400  }
401 
402  closedir( examples );
403  }
404 
405  if ( fcnt == 0 )
406  {
407  fprintf( stderr, "Can't find matching font files.\n" );
408  exit( 1 );
409  }
410 
411  fontlist[fcnt].name = NULL;
412  }
#define realloc
Definition: debug_ros.c:6
#define max(a, b)
Definition: svc.c:63
static int extmatch(char *filename, char **extensions)
Definition: ftrandom.c:242
union DEntry ent[1]
Definition: fatfs.h:199
#define snprintf
Definition: wintirpc.h:48
GLuint buffer
Definition: glext.h:5915
char * name
Definition: ftrandom.c:93
Definition: fatfs.h:198
DIR *__cdecl opendir(const char *)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
Definition: dirent.h:39
#define S_ISDIR(mode)
Definition: various.h:18
Definition: stat.h:55
int __cdecl closedir(DIR *)
struct dirent *__cdecl readdir(DIR *)
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
FILE * stderr
static void figurefiletype(struct fontlist *item)
Definition: ftrandom.c:268
void exit(int exitcode)
Definition: _exit.c:33
static unsigned int fcnt
Definition: ftrandom.c:101
long len
Definition: ftrandom.c:94

Referenced by main().

◆ FT_ConicTo()

static int FT_ConicTo ( const FT_Vector _cp,
const FT_Vector to,
void user 
)
static

Definition at line 127 of file ftrandom.c.

130  {
131  FT_UNUSED( _cp );
132  FT_UNUSED( to );
133  FT_UNUSED( user );
134 
135  return 0;
136  }
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ FT_CubicTo()

static int FT_CubicTo ( const FT_Vector cp1,
const FT_Vector cp2,
const FT_Vector to,
void user 
)
static

Definition at line 140 of file ftrandom.c.

144  {
145  FT_UNUSED( cp1 );
146  FT_UNUSED( cp2 );
147  FT_UNUSED( to );
148  FT_UNUSED( user );
149 
150  return 0;
151  }
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ FT_LineTo()

static int FT_LineTo ( const FT_Vector to,
void user 
)
static

Definition at line 116 of file ftrandom.c.

118  {
119  FT_UNUSED( to );
120  FT_UNUSED( user );
121 
122  return 0;
123  }
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ FT_MoveTo()

static int FT_MoveTo ( const FT_Vector to,
void user 
)
static

Definition at line 105 of file ftrandom.c.

107  {
108  FT_UNUSED( to );
109  FT_UNUSED( user );
110 
111  return 0;
112  }
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ getErrorCnt()

static unsigned int getErrorCnt ( struct fontlist item)
static

Definition at line 416 of file ftrandom.c.

417  {
418  if ( error_count == 0 && error_fraction == 0.0 )
419  return 0;
420 
421  return error_count + (unsigned int)( error_fraction * item->len );
422  }
static double error_fraction
Definition: ftrandom.c:87
static unsigned int error_count
Definition: ftrandom.c:86
static ATOM item
Definition: dde.c:856
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by copyfont().

◆ getRandom()

static int getRandom ( int  low,
int  high 
)
static

Definition at line 426 of file ftrandom.c.

428  {
429  if ( low - high < 0x10000L )
430  return low + ( ( random() >> 8 ) % ( high + 1 - low ) );
431 
432  return low + ( random() % ( high + 1 - low ) );
433  }
#define random
Definition: rosdhcp.h:81

Referenced by copyfont(), and do_test().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 599 of file ftrandom.c.

601  {
602  char **dirs, **exts;
603  int dcnt = 0, ecnt = 0, rset = false, allexts = false;
604  int i;
605  time_t now;
606  char* testfile = NULL;
607 
608 
609  dirs = calloc( (size_t)( argc + 1 ), sizeof ( char ** ) );
610  exts = calloc( (size_t)( argc + 1 ), sizeof ( char ** ) );
611 
612  for ( i = 1; i < argc; i++ )
613  {
614  char* pt = argv[i];
615  char* end;
616 
617 
618  if ( pt[0] == '-' && pt[1] == '-' )
619  pt++;
620 
621  if ( strcmp( pt, "-all" ) == 0 )
622  allexts = true;
623  else if ( strcmp( pt, "-check-outlines" ) == 0 )
624  check_outlines = true;
625  else if ( strcmp( pt, "-dir" ) == 0 )
626  dirs[dcnt++] = argv[++i];
627  else if ( strcmp( pt, "-error-count" ) == 0 )
628  {
629  if ( !rset )
630  error_fraction = 0.0;
631  rset = true;
632  error_count = (unsigned int)strtoul( argv[++i], &end, 10 );
633  if ( *end != '\0' )
634  {
635  fprintf( stderr, "Bad value for error-count: %s\n", argv[i] );
636  exit( 1 );
637  }
638  }
639  else if ( strcmp( pt, "-error-fraction" ) == 0 )
640  {
641  if ( !rset )
642  error_count = 0;
643  rset = true;
644  error_fraction = strtod( argv[++i], &end );
645  if ( *end != '\0' )
646  {
647  fprintf( stderr, "Bad value for error-fraction: %s\n", argv[i] );
648  exit( 1 );
649  }
650  if ( error_fraction < 0.0 || error_fraction > 1.0 )
651  {
652  fprintf( stderr, "error-fraction must be in the range [0;1]\n" );
653  exit( 1 );
654  }
655  }
656  else if ( strcmp( pt, "-ext" ) == 0 )
657  exts[ecnt++] = argv[++i];
658  else if ( strcmp( pt, "-help" ) == 0 )
659  {
660  usage( stdout, argv[0] );
661  exit( 0 );
662  }
663  else if ( strcmp( pt, "-nohints" ) == 0 )
664  nohints = true;
665  else if ( strcmp( pt, "-rasterize" ) == 0 )
666  rasterize = true;
667  else if ( strcmp( pt, "-results" ) == 0 )
668  results_dir = argv[++i];
669  else if ( strcmp( pt, "-size" ) == 0 )
670  {
671  font_size = (FT_F26Dot6)( strtod( argv[++i], &end ) * 64 );
672  if ( *end != '\0' || font_size < 64 )
673  {
674  fprintf( stderr, "Bad value for size: %s\n", argv[i] );
675  exit( 1 );
676  }
677  }
678  else if ( strcmp( pt, "-test" ) == 0 )
679  testfile = argv[++i];
680  else
681  {
682  usage( stderr, argv[0] );
683  exit( 1 );
684  }
685  }
686 
687  if ( allexts )
688  {
689  free( exts );
690  exts = NULL;
691  }
692  else if ( ecnt == 0 )
693  {
694  free( exts );
696  }
697 
698  if ( dcnt == 0 )
699  {
700  free( dirs );
701  dirs = default_dir_list;
702  }
703 
704  if ( testfile )
705  ExecuteTest( testfile ); /* This should never return */
706 
707  time( &now );
708  srandom( (unsigned int)now );
709 
710  FindFonts( dirs, exts );
711  mkdir( results_dir, 0755 );
712 
713  forever
714  do_test();
715 
716  return 0;
717  }
static int nohints
Definition: ftrandom.c:57
static int argc
Definition: ServiceArgs.c:12
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
_Check_return_ double __cdecl strtod(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr)
#define pt(x, y)
Definition: drawing.c:79
static char * results_dir
Definition: ftrandom.c:59
#define free
Definition: debug_ros.c:5
static void do_test(void)
Definition: ftrandom.c:516
static void ExecuteTest(char *testfont)
Definition: ftrandom.c:200
__u16 time
Definition: mkdosfs.c:366
#define srandom
Definition: rosdhcp.h:82
#define argv
Definition: mplay32.c:18
FILE * stdout
static void usage(FILE *out, char *name)
Definition: ftrandom.c:556
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
time_t now
Definition: finger.c:65
#define mkdir
Definition: acwin.h:101
static double error_fraction
Definition: ftrandom.c:87
#define forever
Definition: ftrandom.c:53
GLuint GLuint end
Definition: gl.h:1545
static int rasterize
Definition: ftrandom.c:58
static FT_F26Dot6 font_size
Definition: ftrandom.c:89
static unsigned int error_count
Definition: ftrandom.c:86
signed long FT_F26Dot6
Definition: fttypes.h:276
static char * default_ext_list[]
Definition: ftrandom.c:69
static const struct encodedExtensions exts[]
Definition: encode.c:2703
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__kernel_time_t time_t
Definition: linux.h:252
static char * default_dir_list[]
Definition: ftrandom.c:63
#define NULL
Definition: types.h:112
#define calloc
Definition: rosglue.h:14
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static int check_outlines
Definition: ftrandom.c:56
void exit(int exitcode)
Definition: _exit.c:33
static void FindFonts(char **fontdirs, char **extensions)
Definition: ftrandom.c:348
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ TestFace()

static void TestFace ( FT_Face  face)
static

Definition at line 165 of file ftrandom.c.

166  {
167  unsigned int gid;
168  int load_flags = FT_LOAD_DEFAULT;
169 
170 
171  if ( check_outlines &&
172  FT_IS_SCALABLE( face ) )
173  load_flags = FT_LOAD_NO_BITMAP;
174 
175  if ( nohints )
176  load_flags |= FT_LOAD_NO_HINTING;
177 
178  FT_Set_Char_Size( face, 0, font_size, 72, 72 );
179 
180  for ( gid = 0; gid < face->num_glyphs; gid++ )
181  {
182  if ( check_outlines &&
183  FT_IS_SCALABLE( face ) )
184  {
185  if ( !FT_Load_Glyph( face, gid, load_flags ) )
186  FT_Outline_Decompose( &face->glyph->outline, &outlinefuncs, NULL );
187  }
188  else
189  FT_Load_Glyph( face, gid, load_flags );
190 
191  if ( rasterize )
193  }
194 
195  FT_Done_Face( face );
196  }
static int nohints
Definition: ftrandom.c:57
#define FT_LOAD_NO_HINTING
Definition: freetype.h:3010
#define FT_LOAD_DEFAULT
Definition: freetype.h:3008
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ftobjs.c:760
FT_Set_Char_Size(FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution)
Definition: ftobjs.c:3267
#define ft_render_mode_normal
Definition: freetype.h:3247
FT_Render_Glyph(FT_GlyphSlot slot, FT_Render_Mode render_mode)
Definition: ftobjs.c:4650
FT_BEGIN_HEADER FT_Outline_Decompose(FT_Outline *outline, const FT_Outline_Funcs *func_interface, void *user)
Definition: ftoutln.c:51
static int rasterize
Definition: ftrandom.c:58
static FT_F26Dot6 font_size
Definition: ftrandom.c:89
#define NULL
Definition: types.h:112
FT_Done_Face(FT_Face face)
Definition: ftobjs.c:2721
static FT_Outline_Funcs outlinefuncs
Definition: ftrandom.c:154
static int check_outlines
Definition: ftrandom.c:56
#define FT_LOAD_NO_BITMAP
Definition: freetype.h:3012
#define FT_IS_SCALABLE(face)
Definition: freetype.h:1312
GLenum GLuint GLint GLenum face
Definition: glext.h:7025

Referenced by ExecuteTest().

◆ usage()

static void usage ( FILE out,
char name 
)
static

Definition at line 556 of file ftrandom.c.

558  {
559  char** d = default_dir_list;
560  char** e = default_ext_list;
561 
562 
563  fprintf( out, "%s [options] -- Generate random erroneous fonts\n"
564  " and attempt to parse them with FreeType.\n\n", name );
565 
566  fprintf( out, " --all All non-directory files are assumed to be fonts.\n" );
567  fprintf( out, " --check-outlines Make sure we can parse the outlines of each glyph.\n" );
568  fprintf( out, " --dir <path> Append <path> to list of font search directories\n"
569  " (no recursive search).\n" );
570  fprintf( out, " --error-count <cnt> Introduce <cnt> single byte errors into each font\n"
571  " (default: 1)\n" );
572  fprintf( out, " --error-fraction <frac> Introduce <frac>*filesize single byte errors\n"
573  " into each font (default: 0.0).\n" );
574  fprintf( out, " --ext <ext> Add <ext> to list of extensions indicating fonts.\n" );
575  fprintf( out, " --help Print this.\n" );
576  fprintf( out, " --nohints Turn off hinting.\n" );
577  fprintf( out, " --rasterize Attempt to rasterize each glyph.\n" );
578  fprintf( out, " --results <path> Place the created test fonts into <path>\n"
579  " (default: `results')\n" );
580  fprintf( out, " --size <float> Use the given font size for the tests.\n" );
581  fprintf( out, " --test <file> Run a single test on an already existing file.\n" );
582  fprintf( out, "\n" );
583 
584  fprintf( out, "Default font extensions:\n" );
585  fprintf( out, " " );
586  while ( *e )
587  fprintf( out, " .%s", *e++ );
588  fprintf( out, "\n" );
589 
590  fprintf( out, "Default font directories:\n" );
591  fprintf( out, " " );
592  while ( *d )
593  fprintf( out, " %s", *d++ );
594  fprintf( out, "\n" );
595  }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define e
Definition: ke_i.h:82
static FILE * out
Definition: regtests2xml.c:44
static char * default_ext_list[]
Definition: ftrandom.c:69
static char * default_dir_list[]
Definition: ftrandom.c:63
Definition: name.c:38
#define d
Definition: ke_i.h:81

Referenced by main().

Variable Documentation

◆ check_outlines

int check_outlines = false
static

Definition at line 56 of file ftrandom.c.

Referenced by main(), and TestFace().

◆ child_pid

int child_pid
static

Definition at line 502 of file ftrandom.c.

Referenced by abort_test(), and do_test().

◆ default_dir_list

char* default_dir_list[]
static
Initial value:
=
{
}
#define GOOD_FONTS_DIR
Definition: ftrandom.c:61
#define NULL
Definition: types.h:112

Definition at line 63 of file ftrandom.c.

Referenced by main(), and usage().

◆ default_ext_list

char* default_ext_list[]
static
Initial value:
=
{
"ttf",
"otf",
"ttc",
"cid",
"pfb",
"pfa",
"bdf",
"pcf",
"pfr",
"fon",
"otb",
"cff",
}
#define NULL
Definition: types.h:112

Definition at line 69 of file ftrandom.c.

Referenced by main(), and usage().

◆ error_count

unsigned int error_count = 1
static

Definition at line 86 of file ftrandom.c.

Referenced by getErrorCnt(), and main().

◆ error_fraction

double error_fraction = 0.0
static

Definition at line 87 of file ftrandom.c.

Referenced by getErrorCnt(), and main().

◆ fcnt

unsigned int fcnt
static

Definition at line 101 of file ftrandom.c.

Referenced by do_test(), and FindFonts().

◆ font_size

◆ fontlist

◆ nohints

int nohints = false
static

Definition at line 57 of file ftrandom.c.

Referenced by main(), and TestFace().

◆ outlinefuncs

FT_Outline_Funcs outlinefuncs
static
Initial value:
=
{
0, 0
}
static int FT_CubicTo(const FT_Vector *cp1, const FT_Vector *cp2, const FT_Vector *to, void *user)
Definition: ftrandom.c:140
static int FT_MoveTo(const FT_Vector *to, void *user)
Definition: ftrandom.c:105
static int FT_LineTo(const FT_Vector *to, void *user)
Definition: ftrandom.c:116
static int FT_ConicTo(const FT_Vector *_cp, const FT_Vector *to, void *user)
Definition: ftrandom.c:127

Definition at line 154 of file ftrandom.c.

Referenced by TestFace().

◆ rasterize

int rasterize = false
static

Definition at line 58 of file ftrandom.c.

Referenced by main(), and TestFace().

◆ results_dir

char* results_dir = "results"
static

Definition at line 59 of file ftrandom.c.

Referenced by do_test(), and main().