Пример #1
0
int
main( int argc, char *argv[] )
{
     int            i;
     DirectResult   ret;
     DirectLogType  log_type  = DLT_STDERR;
     const char    *log_param = NULL;
     DirectLog     *log;


     for (i=1; i<argc; i++) {
          if (!strcmp( argv[i], "-f" )) {
               if (++i < argc) {
                    log_type  = DLT_FILE;
                    log_param = argv[i];
               }
               else
                    return show_usage(argv[0]);
          }
          else if (!strcmp( argv[i], "-u" )) {
               if (++i < argc) {
                    log_type  = DLT_UDP;
                    log_param = argv[i];
               }
               else
                    return show_usage(argv[0]);
          }
          else
               return show_usage(argv[0]);
     }

     /* Initialize logging. */
     ret = direct_log_create( log_type, log_param, &log );
     if (ret)
          return -1;

     /* Set default log to use. */
     direct_log_set_default( log );


     /* Test memory leak detector by not freeing this one. */
     D_MALLOC( 1351 );

     D_INFO( "Direct/Test: Application starting...\n" );


     /* Initialize libdirect. */
     direct_initialize();


     D_INFO( "Direct/Test: Application stopping...\n" );

     /* Shutdown libdirect. */
     direct_shutdown();


     D_INFO( "Direct/Test: You should see a leak message with debug-mem turned on...\n" );

     /* Shutdown logging. */
     direct_log_destroy( log );

     direct_config->debug = true;
     direct_print_memleaks();

     return 0;
}
Пример #2
0
int
main( int argc, char *argv[] )
{
     int             ret;
     int             fd;
     struct stat     stat;
     void           *ptr  = MAP_FAILED;
     Entity::vector  faces;
     DGIFFHeader     header = {
          magic: { 'D', 'G', 'I', 'F', 'F' },
          major: 0,
          minor: 0,
          flags: DGIFF_FLAG_LITTLE_ENDIAN,
          num_faces: 0
     };

     direct_initialize();

     direct_debug_config_domain( "mkdgiff", true );

     direct_config->debug    = true;
     direct_config->debugmem = true;

     /* Parse the command line. */
     if (!parse_command_line( argc, argv ))
          return -1;


     /* Open the file. */
     fd = open( filename, O_RDONLY );
     if (fd < 0) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during open() of '%s'!\n", filename );
          return ret;
     }

     /* Query file size etc. */
     if (fstat( fd, &stat ) < 0) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during fstat() of '%s'!\n", filename );
          goto out;
     }

     /* Memory map the file. */
     ptr = mmap( NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
     if (ptr == MAP_FAILED) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during mmap() of '%s'!\n", filename );
          goto out;
     }


     get_entities( (const char*) ptr, stat.st_size, faces );

     header.num_faces = faces.size();



     fwrite( &header, sizeof(header), 1, stdout );

     for (Entity::vector::const_iterator iter = faces.begin(); iter != faces.end(); iter++) {
          const Face *face = dynamic_cast<const Face*>( *iter );

          face->Dump();

          ret = do_face( face );
          if (ret)
               goto out;
     }


out:
     if (ptr != MAP_FAILED)
          munmap( ptr, stat.st_size );

     close( fd );

     direct_print_memleaks();

     direct_shutdown();

     return ret;
}