Esempio n. 1
0
Layer::Layer(linkedlist *ll, float height) {
  candidates = ll;
  this->height = height;
  // init the datastructures
  poly = new std::vector< std::vector<point*> >;
  segments = new std::vector<line*>;
  
  create_segments();
  create_polys();
}
Esempio n. 2
0
int main(void){
	//tests();
	POLYGON temp;
	assert(get_size(&temp.size_points)==TRUE);
	alloc_points(&temp.max_of_x,&temp.points,temp.size_points);
	temp.segments=create_segments(temp.size_points);
	add_segments(temp.points,temp.segments,temp.size_points);
	draw_polygon(temp);
	triangulal_polygol(temp); 
	printf("Potrzeba %d straznikow\n",coloring_sl(temp.points,temp.segments,temp.size_points));
	print_colors(temp.points,temp.size_points);
	draw_polygon(temp);
	free_segments(temp.segments,temp.size_points);
	free_points(temp.points);
	return EXIT_SUCCESS;
}
Esempio n. 3
0
static int db_open(directory_config *dcfg, char **error_msg)
{
    char errstr[1024];
    apr_pool_t *mp = dcfg->mp;
    geo_db *geo = dcfg->geo;
    apr_status_t rc;

    #ifdef DEBUG_CONF
    fprintf(stderr, "GEO: Initializing geo DB \"%s\".\n", geo->dbfn);
    #endif

    if ((rc = apr_file_open(&geo->db, geo->dbfn, APR_READ, APR_OS_DEFAULT, mp)) != APR_SUCCESS) {
        *error_msg = apr_psprintf(mp, "Could not open geo database \"%s\": %s", geo->dbfn, apr_strerror(rc, errstr, 1024));
        return 0;
    }

    create_segments(geo);
    return 1;
}
Esempio n. 4
0
//----------------------------------------------------------------------
//
//      loads the whole file into IDA
//      this is a wrapper function, which:
//
//      - checks the header for validity and fixes broken headers
//      - creates all necessary segments
//      - saves the whole file to blobs
//      - loads prg pages/banks
//      - adds informational descriptions to the database
//
static void load_ines_file( linput_t *li )
{
    // go to file offset 0 - just to be sure
	qlseek(li, 0, SEEK_SET);

	// read the whole header
	if( qlread(li, &hdr, sizeof(ines_hdr)) != sizeof(ines_hdr) )
        vloader_failure("File read error!",0);

    // check if header is corrupt
    // show a warning msg, but load the rom nonetheless
    if( is_corrupt_ines_hdr() )
    {
        //warning("The iNES header seems to be corrupt.\nLoader might give inaccurate results!");
        int code = askyn_c(1, "The iNES header seems to be corrupt.\n"
                              "The NES loader could produce wrong results!\n"
                              "Do you want to internally fix the header ?\n\n"
                              "(this will not affect the input file)");
        if( code == 1 )
            fix_ines_hdr();
    }

    // create NES segments
    create_segments( li );

    // save NES file to blobs
    save_image_as_blobs( li );
    
    // load relevant ROM banks into database
    load_rom_banks( li );
    
    // make vectors public
    add_entry_points( li );

    // fill inf structure
    set_ida_export_data();    

    // add information about the ROM image
	describe_rom_image();
  
    // let IDA add some information about the loaded file
    create_filename_cmt();
}
Esempio n. 5
0
int main( int argc, char* argv[] )
{
    ddt_segment_t* segments;
    int *send_buffer, *recv_buffer;
    int i, seg_count, errors;
    int show_only_first_error = 1;
    ompi_datatype_t* datatype = MPI_DATATYPE_NULL;

#define NELT (300)
    send_buffer = malloc(NELT*sizeof(int));
    recv_buffer = malloc(NELT*sizeof(int));
    for (i = 0; i < NELT; ++i) {
        send_buffer[i] = i;
        recv_buffer[i] = 0xdeadbeef;
    }

    opal_init_util (NULL, NULL);
    ompi_datatype_init();

    ompi_datatype_create_vector(NELT/2, 1, 2, MPI_INT, &datatype);
    ompi_datatype_commit(&datatype);

#if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0)
    opal_unpack_debug   = false;
    opal_pack_debug     = false;
    opal_position_debug = false;
#endif  /* OPAL_ENABLE_DEBUG */

    create_segments( datatype, 1, fragment_size,
                     &segments, &seg_count );

    /* shuffle the segments */
    shuffle_segments( segments, seg_count );

    /* pack the data */
    pack_segments( datatype, 1, fragment_size, segments, seg_count,
                   send_buffer );

    /* unpack the data back in the user space (recv buffer) */
    unpack_segments( datatype, 1, fragment_size, segments, seg_count,
                     recv_buffer );

    /* And now check the data */
    for( errors = i = 0; i < NELT; i++ ) {
        int expected = ((i % 2) ? (int)0xdeadbeef : i);
        if (recv_buffer[i] != expected) {
            if( (show_only_first_error && (0 == errors)) ||
                !show_only_first_error ) {
                printf("error at index %4d: 0x%08x != 0x%08x\n", i, recv_buffer[i], expected);
            }
            errors++;
        }
    }
    printf( "Found %d errors\n", errors );
    free(send_buffer); free(recv_buffer);

    for( i = 0; i < seg_count; i++ ) {
        free( segments[i].buffer );
    }
    free(segments);

    ompi_datatype_finalize();
    opal_finalize_util ();

    return (0 == errors ? 0 : -1);
}
Esempio n. 6
0
int
main (int argc, char **argv)
{
  struct segment_context ctx;

  segment_context_default(&ctx);

  char *segment_duration_check;
  int index;
  int c;

  while ((c = getopt (argc, argv, "b:t:I:o:p:i:s:f:h")) != -1)
    switch (c)
    {
      case 'b':
      ctx.base_url = optarg;
      break;
      case 'p':
      ctx.precision = atoi(optarg);
      break;
      case 'o':
      ctx.output_prefix = optarg;
      break;
      case 'i':
      ctx.input = optarg;
      break;
      case 'I':
      ctx.index_file = optarg;
      break;
      case 's':
      ctx.separator = optarg;
      break;
      case 'f':
      ctx.start_from = atoi(optarg);
      break;
      case 'h':
      display_usage();
      break;
      case 't':
      ctx.segment_duration = strtod(optarg, &segment_duration_check);
      if (segment_duration_check == optarg || ctx.segment_duration == HUGE_VAL || ctx.segment_duration == -HUGE_VAL) {
        fprintf(stderr, "Segment duration time (%s) invalid\n", optarg);
        exit(1);
      }
      break;

      default:
      exit(1);
    }

  if(argc < 1) {
    display_usage();
  }

  if (ctx.input == NULL && ctx.index_file) {
    fprintf(stderr, "Using stdin as input.\n");
  }

  if(ctx.output_prefix == NULL && ctx.index_file != NULL) {

    char * dot = strrchr(ctx.index_file,'.');
    if (dot == NULL) {
      fprintf(stderr,"Problem with name in file: %s\n", ctx.index_file);
      exit(4);
    }

    size_t size = strlen(ctx.index_file) - strlen(dot);
    ctx.output_prefix = (char *)malloc(size);
    strncpy(ctx.output_prefix, ctx.index_file , size);
  }

  if (ctx.output_prefix == NULL) {
    fprintf(stderr,"Output prefix unspecified\n");
    exit(4);
  }

  create_segments(&ctx);

  segment_context_free(&ctx);
  return 0;
}
Esempio n. 7
0
int main( int argc, char* argv[] )
{
    ddt_segment_t* segments;
    ddt_ldi_t *send_buffer, *recv_buffer;
    int i, seg_count, errors;
    int show_only_first_error = 1;
    ompi_datatype_t* datatype = MPI_LONG_DOUBLE_INT;

    send_buffer = malloc( sizeof(ddt_ldi_t) * data_count );
    recv_buffer = malloc( sizeof(ddt_ldi_t) * data_count );

    for( i = 0; i < data_count; i++ ) {
        send_buffer[i].ld = (long double)i + (long double)i / 100000.0;
        send_buffer[i].i  = i;
    }
    memcpy(recv_buffer, send_buffer, sizeof(ddt_ldi_t) * data_count );

    opal_datatype_init();
    ompi_datatype_init();

#if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0)
    opal_unpack_debug   = false;
    opal_pack_debug     = false;
    opal_position_debug = false;
#endif  /* OPAL_ENABLE_DEBUG */

    create_segments( datatype, data_count, fragment_size,
                     &segments, &seg_count );

    /* shuffle the segments */
    shuffle_segments( segments, seg_count );

    /* pack the data */
    pack_segments( datatype, data_count, fragment_size, segments, seg_count,
                   send_buffer );

    /* unpack the data back in the user space (recv buffer) */
    unpack_segments( datatype, data_count, fragment_size, segments, seg_count,
                     recv_buffer );

    /* And now check the data */
    for( errors = i = 0; i < data_count; i++ ) {
        /*if( !bytes_equal(&send_buffer[i].ld, &recv_buffer[i].ld, sizeof(long double)) ||*/
        if( (send_buffer[i].ld != recv_buffer[i].ld) ||
            (send_buffer[i].i != recv_buffer[i].i) ) {
            if( (show_only_first_error && (0 == errors)) ||
                !show_only_first_error ) {
                printf( "error at %4d [*(%s,%d)\n"
                        "             != (%s,%d)\n", i,
                        bytes_dump( &send_buffer[i].ld, sizeof(long double)), send_buffer[i].i,
                        bytes_dump( &recv_buffer[i].ld, sizeof(long double)), recv_buffer[i].i );
            }
            errors++;
        }
    }
    printf( "Found %d errors\n", errors );
    free(send_buffer); free(recv_buffer);

    for( i = 0; i < seg_count; i++ ) {
        free( segments[i].buffer );
    }
    free(segments);

    ompi_datatype_finalize();

    return (0 == errors ? 0 : -1);
}