示例#1
0
/*Check the number of arguments of the instruction*/
int	check_argvs(op_t *mnemo, t_instruction *instruction)
{
    int	i;
    int	max;

    max = 0;
    while (instruction && instruction->arg != NULL && instruction->arg[max++]);
    i = -1;
    while (++i < MAX_ARGS_NUMBER && instruction && instruction->arg)
    {
        if (mnemo->nbr_args > i)
            if (instruction->arg[i])
                check_arg_type(instruction->arg[i], mnemo->type[i],
                               instruction, mnemo->mnemonique);
            else
                print_error_message("Asm: Warning: Bad argument",
                                    *instruction->label->name, mnemo->mnemonique
                                    , instruction->line);
        else if (i < max - 1)
        {
            print_error_message("Asm: Trailing garbage",
                                *instruction->label->name, mnemo->mnemonique
                                , instruction->line);
            return (1);
        }
    }
    return (0);
}
int
find_text( db_t hdb, const char * textid, const char * locale )
{
    int rc = EXIT_FAILURE;
    db_result_t db_rc = DB_OK;
    db_row_t row;
    db_cursor_t c;
    db_table_cursor_t p = {
        STORAGE_PKEY_INDEX_NAME,   //< No index
        DB_SCAN_FORWARD | DB_LOCK_EXCLUSIVE
    };
    char en[MAX_TEXT_LEN + 1] = {0};
    char tr[MAX_TEXT_LEN + 1] = {0};

    int target_fno = EN_FNO;
    if( 0 == strncmp( "jp", locale, 2 ) ) {
        target_fno = JP_FNO;
    }
    else if( 0 == strncmp( "fr", locale, 2 ) ) {
        target_fno = FR_FNO;
    }
    else if( 0 == strncmp( "es", locale, 2 ) ) {
        target_fno = ES_FNO;
    }
    else if( 0 == strncmp( "ru", locale, 2 ) ) {
        target_fno = RU_FNO;
    }

    c = db_open_table_cursor(hdb, STORAGE_TABLE, &p);

    row = db_alloc_row( NULL, 2 );
    if( NULL == row ) {
        print_error_message( "Couldn't pupulate 'storage' table\n" );
        return EXIT_FAILURE;
    }

    dbs_bind_addr( row, ID_FNO, DB_VARTYPE_ANSISTR, (char*)textid, strlen(textid), NULL );
    if( DB_OK == db_seek( c, DB_SEEK_FIRST_EQUAL, row, 0, 1 ) )
    {
        db_unbind_field( row, ID_FNO );
        dbs_bind_addr( row, EN_FNO, DB_VARTYPE_UTF8STR, en, MAX_TEXT_LEN, NULL );
        if( target_fno != EN_FNO ) {
            dbs_bind_addr( row, target_fno, DB_VARTYPE_UTF8STR, tr, MAX_TEXT_LEN, NULL );
        }
        if( DB_OK == db_fetch( c, row, 0 ) ) {
            fprintf( stdout, "Message. Id: %s, en: [%s], %s: [%s]\n",
                     textid, en, locale, target_fno == EN_FNO ? "" : tr
                     );
            rc = EXIT_SUCCESS;
        }
    }
    if( rc != EXIT_SUCCESS ) {
        print_error_message( "Couldn't find translated text for messageid %s\n", textid );
    }

    db_free_row( row );
    db_close_cursor( c );

    return rc;
}
int
load_data( db_t hdb )
{
    db_result_t rc = DB_OK;
    int i;

    db_row_t row;
    db_table_cursor_t p = {
        NULL,   //< No index
        DB_CAN_MODIFY | DB_LOCK_EXCLUSIVE
    };
    db_cursor_t c;

    c = db_open_table_cursor(hdb, STORAGE_TABLE, &p);

    row = db_alloc_row( binds_def, DB_ARRAY_DIM( binds_def ) );
    if( NULL == row ) {
        print_error_message( "Couldn't allocate row to pupulate 'storage' table\n" );
        return EXIT_FAILURE;
    }

    for( i = 0; i < DB_ARRAY_DIM(texts) && DB_OK == rc; ++i ) {
        rc = db_insert(c, row, &texts[i], 0);
    }

    db_free_row( row );
    rc = DB_OK == rc ? db_commit_tx( hdb, 0 ) : rc;

    if( DB_OK != rc ) {
        print_error_message( "Couldn't pupulate 'storage' table\n" );
    }
    db_close_cursor(c);

    return DB_OK == rc ? EXIT_SUCCESS : EXIT_FAILURE;
}
示例#4
0
/**
 * Set schema version of DB
 */
void
set_schema_version( db_t hdb, int version )
{
    /* Use manual binding both to seek and update. */
    db_table_cursor_t p = { NULL, DB_CAN_MODIFY | DB_LOCK_EXCLUSIVE };
    db_cursor_t c;
    uint32_t db_version = 0;
    db_bind_t row_def[] = {
        DB_BIND_VAR( SCHEMA_VERSION_VERSION, DB_VARTYPE_UINT32, db_version )
    };

    c = db_open_table_cursor(hdb, SCHEMA_VERSION_TABLE, &p);

    /* Goto 1'st row. */
    if (db_seek_first(c) == DB_FAIL) {
        print_error_message("DB_FAIL in set_schema_version()", c );
        return;
    }

    if (db_eof( c )) {
        db_version = version;
        // No versioned DB yet. Insert row with version
        if (db_qinsert( c, row_def, DB_ARRAY_DIM( row_def ), &db_version, 0 ) == DB_FAIL) {
            print_error_message( "Error in set_schema_version()", c );
        }
    } else if ( db_version != version ) {
        // Update version with a new value
        db_version = version;
        if (db_qupdate( c, row_def, DB_ARRAY_DIM( row_def ), NULL ) == DB_FAIL) {
            print_error_message("Error in set_schema_version()", c);
        }
    }
    (void)db_close_cursor(c);
}
示例#5
0
int
populate_data( db_t hdb )
{
    db_result_t rc = DB_OK;
    int i;

    /* Populate "storage" table using relative bounds fields. See
       ittiadb/manuals/users-guide/api-c-database-access.html#relative-bound-fields
     */
    typedef struct {
        db_ansi_t   f0[MAX_STRING_FIELD + 1];   /* Extra char for null termination. */
        uint64_t    f1;
        double      f2;
        char        f3[MAX_STRING_FIELD*2 + 1];
    } storage_t;

    static const db_bind_t binds_def[] = {
        { 0, DB_VARTYPE_ANSISTR,  DB_BIND_OFFSET( storage_t, f0 ),  DB_BIND_SIZE( storage_t, f0 ), -1, DB_BIND_RELATIVE },
        { 1, DB_VARTYPE_SINT64,   DB_BIND_OFFSET( storage_t, f1 ),  DB_BIND_SIZE( storage_t, f1 ), -1, DB_BIND_RELATIVE },
        { 2, DB_VARTYPE_FLOAT64,  DB_BIND_OFFSET( storage_t, f2 ),  DB_BIND_SIZE( storage_t, f2 ), -1, DB_BIND_RELATIVE },
        { 3, DB_VARTYPE_UTF8STR,  DB_BIND_OFFSET( storage_t, f3 ),  DB_BIND_SIZE( storage_t, f3 ), -1, DB_BIND_RELATIVE },
    };

    static storage_t rows2ins[] = {
        { "ansi_str1",  1,  1.231, "utf8" },
        { "ansi_str2",    2,  2.231, "utf8" },
        { "ansi_str3",    3,  3.231, "УТФ-8" },
        { "ansi_str4",    4,  4.231, "utf8" },
        { "ansi_str5",    5,  5.231, "utf8" },
    };
    db_row_t row;
    db_table_cursor_t p = {
        NULL,   //< No index
        DB_CAN_MODIFY | DB_LOCK_EXCLUSIVE
    };
    db_cursor_t c;

    row = db_alloc_row( binds_def, DB_ARRAY_DIM( binds_def ) );
    if( NULL == row ) {
        print_error_message( "Couldn't pupulate 'storage' table\n" );
        return EXIT_FAILURE;
    }

    c = db_open_table_cursor(hdb, STORAGE_TABLE, &p);

    for( i = 0; i < DB_ARRAY_DIM(rows2ins) && DB_OK == rc; ++i ) {
        rc = db_insert(c, row, &rows2ins[i], 0);
    }

    db_free_row( row );
    rc = DB_OK == rc ? db_commit_tx( hdb, 0 ) : rc;

    if( DB_OK != rc ) {
        print_error_message( "Couldn't pupulate 'storage' table\n" );
    }
    db_close_cursor(c);

    return DB_OK == rc ? EXIT_SUCCESS : EXIT_FAILURE;
}
示例#6
0
int
perform_transactions( db_t hdb, trans_stat_t *stat )
{
    int i;
    db_row_t row;
    db_table_cursor_t p = {
        NULL,   //< No index
        DB_CAN_MODIFY | DB_LOCK_EXCLUSIVE
    };
    db_cursor_t c;
    db_result_t db_rc;
    storage_t row2ins = { "ansi_str1",  1,  1.231, "utf8" };

    // Allocate row. binds_def see in db_schema.h
    row = db_alloc_row( binds_def, DB_ARRAY_DIM( binds_def ) );
    if( NULL == row ) {
        print_error_message( "Couldn't allocate db_row_t\n", NULL );
        return EXIT_FAILURE;
    }

    // Open cursor
    c = db_open_table_cursor(hdb, STORAGE_TABLE, &p);

    db_rc = DB_OK;
    for( i = 0; i < 100 && DB_OK == db_rc; ++i ) {
        int do_lazy_commit = i % 5;
        db_rc = db_begin_tx( hdb, 0 );
        row2ins.f1 = i+1;
        row2ins.f2 = do_lazy_commit ? 50 : 16;
        db_rc = db_insert(c, row, &row2ins, 0);
        db_commit_tx( hdb, do_lazy_commit ? DB_LAZY_COMPLETION : DB_DEFAULT_COMPLETION );
        if( do_lazy_commit ) {
            stat->lazy_tx++;
        }
        else {
            stat->forced_tx++;
        }

        if( i % 30 ) {
            db_flush_tx( hdb, DB_FLUSH_JOURNAL );
        }
    }

    if( DB_OK != db_rc ) {
        print_error_message( "Error inserting or commiting\n", c );
    }

    db_close_cursor( c );
    db_free_row( row );

    return DB_OK == db_rc ? EXIT_SUCCESS : EXIT_FAILURE;
}
示例#7
0
void MregularIpelet::protected_run(int fn)
{
  Regular rt;
  std::vector<Weighted_point_2> input_wpt;
  
  if (fn==10) {
    show_help(false);
    return;
  }
  
  Iso_rectangle_2 bbox=
    read_active_objects( 
      CGAL::dispatch_or_drop_output<Point_2,Circle_2>(
        wpoint_grabber(std::back_inserter(input_wpt)),
        wpoint_grabber(std::back_inserter(input_wpt))
      )
    );  
  
  if (!input_wpt.size()) {
    print_error_message("No circle selected");
    return;
  }
  
    
  int order = 0;
  if(fn==0 || fn==5) order = 1;
  if(fn==1 || fn==6) order = 2;
  if(fn==2 || fn==7) order = 3;
  if(fn==3 || fn==8) order = input_wpt.size()-1;;
  if(fn==4 || fn==9){

    int ret_val;
    boost::tie(ret_val,order)=request_value_from_user<int>("Enter order");
    if (ret_val < 0){    
      print_error_message("Incorrect value");
      return;  
    }
    if(order<1 || order>=(int) input_wpt.size()){
      print_error_message("Not a good order");
      return;
    }
  }
  k_delaunay<Kernel>(rt,input_wpt,order);
  if(fn<5)//Draw k-th regular triangulation
    draw_in_ipe(rt);
  else{//Draw kth Power diagram
    double incr_len=75;
    bbox=Iso_rectangle_2(bbox.min()+Kernel::Vector_2(-incr_len,-incr_len),
                         bbox.max()+Kernel::Vector_2(incr_len,incr_len));
    draw_dual_in_ipe(rt,bbox);        //draw Voronoi Diagram
  }
}
示例#8
0
/*Check the type of the argument*/
int	check_arg_type(char *arg, args_type_t t, t_instruction *i,
                   char *mnemo_name)
{
    if ((t & arg[0]) != T_DIR && arg[0] == T_DIR)
        print_error_message("Asm: Warning: Bad argument",
                            *(i->label->name), mnemo_name, i->line);
    if ((t & arg[0]) != T_REG && arg[0] == T_REG)
        print_error_message("Asm: Warning: Bad argument",
                            *(i->label->name), mnemo_name, i->line);
    if ((t & arg[0]) != T_IND && arg[0] == T_IND)
        print_error_message("Asm: Warning: Bad argument",
                            *(i->label->name), mnemo_name, i->line);
    return (0);
}
示例#9
0
db_t
create_database(char* database_name, dbs_versioned_schema_def_t *versioned_schema, InitDataCallback cb)
{
    db_t hdb;

    /* Create a new file storage database with default parameters. */
    hdb = db_create_file_storage(database_name, NULL);

    if (hdb == NULL) {
        return NULL;
    }

    if (dbs_create_schema(hdb, &versioned_schema->schema) < 0) {
        db_shutdown(hdb, DB_SOFT_SHUTDOWN, NULL);
        /* Remove incomplete database. */
        remove(database_name);
        return NULL;
    }

    if( cb && 0 != (*cb)( hdb, versioned_schema->version ) ) {
        print_error_message( "Couldn't initialize table data in created database", NULL);
        return NULL;
    }
    set_schema_version( hdb, versioned_schema->version );
    db_commit_tx( hdb, DB_DEFAULT_COMPLETION );

    return hdb;
}
示例#10
0
/**
   Get schema version of DB
 */
int
get_schema_version( db_t hdb )
{
    /* Use manual binding both to seek and update. */
    db_table_cursor_t p = { NULL, 0 };
    db_cursor_t c;
    uint32_t db_version = 0;
    db_bind_t row_def[] = {
        DB_BIND_VAR( SCHEMA_VERSION_VERSION, DB_VARTYPE_UINT32, db_version )
    };

    c = db_open_table_cursor(hdb, SCHEMA_VERSION_TABLE, &p);

    /* Go to first row. */
    if (db_seek_first(c) == DB_FAIL) {
        print_error_message( "DBFAIL in get_schema_version", c );
        return 0;
    }
    if( db_eof(c) ) {
        db_version = 0;
    }
    else {
        db_qfetch( c, row_def, DB_ARRAY_DIM(row_def), NULL );
    }
    (void)db_close_cursor(c);

    return (int)db_version;
}
示例#11
0
static SQLRETURN
odbc_herror(SQLSMALLINT hType, SQLHANDLE handle, SQLRETURN erc, const char func[], const char msg[])
{
	char * ercstr;

	assert(func && msg);
	
	switch(erc) {
	case SQL_SUCCESS:
		return erc;
	case SQL_SUCCESS_WITH_INFO:
		ercstr = "SQL_SUCCESS_WITH_INFO";
		break;
	case SQL_ERROR:
		ercstr = "SQL_ERROR";
		break;
	case SQL_STILL_EXECUTING:
		ercstr = "SQL_STILL_EXECUTING";
		break;
	case SQL_INVALID_HANDLE:
		fprintf(stderr, "%s: error %d: %s: invalid handle: %s\n", options.appname, (int)erc, func, msg);
		exit(EXIT_FAILURE);
	default:
		fprintf(stderr, "%s: error: %d is an unknown return code for %s\n", options.appname, (int)erc, func);
		exit(EXIT_FAILURE);
	}
	
	fprintf(stderr, "%s: error %d: %s: %s: %s\n", options.appname, (int)erc, func, ercstr, msg);

	print_error_message(hType, handle); 
	
	return erc;
}
示例#12
0
int		email_domain_is_valid(char *domain, int line_number)
{
	char	*dot;

	log_string("starting validation for email domain part: ", domain);
	if ((dot = string_has_one_char_of(domain, '.')) == NULL)
	{
		print_error_message("Invalid '.' in the domain part of the email.",
				line_number);
		log_simple("email domain part validation ended unsuccesfully");
		return (0);
	}
	if (email_subdomain_is_valid(ft_strsub(domain,
					0, dot - domain), line_number) == 0)
	{
		log_simple("email domain part validation ended unsuccesfully");
		return (0);
	}
	if (email_subdomain_is_valid(ft_strsub(domain, dot - domain + 1, domain
					+ ft_strlen(domain) - dot + 1), line_number) == 0)
	{
		log_simple("email domain part validation ended unsuccesfully");
		return (0);
	}
	log_simple("email domain part validation ended succesfully");
	return (1);
}
示例#13
0
int		email_format_is_valid(char *email, int line_number)
{
	char	*arond;

	log_string("starting email format validation: ", email);
	if ((arond = string_has_one_char_of(email, '@')) == NULL)
	{
		log_simple("email format validation ended unsuccesfully");
		print_error_message("Invalid arond in email.", line_number);
		return (0);
	}
	if (email_local_part_is_valid(ft_strsub(email, 0, arond - email),
				line_number) == 0)
	{
		log_simple("email format validation ended unsuccesfully");
		return (0);
	}
	if (email_domain_is_valid(ft_strsub(email, arond - email + 1,
					email + ft_strlen(email) - arond + 1), line_number) == 0)
	{
		log_simple("email format validation ended unsuccesfully");
		return (0);
	}
	log_simple("email format validation ended succesfully");
	return (1);
}
示例#14
0
/**
 * Prints out current state of a board.
 * @param[in] response Pointer to a message containing board information.
 */
void
get_print_board_message(response_s *response) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	print_spectator_board(response);
}
示例#15
0
/**
 * Prints out a message from an opponent (private chat).
 * @param[in] response Pointer to a message containing text from the opponent.
 */
void
get_message_from_opponent(response_s *response) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	printf("\n\nMessage from the opponent: ");
	printf("%s\n", response->payload);
}
示例#16
0
/**
 * Prints out a message showing the winner player.
 * @param[in] response Pointer to a message containing error.
 * @param[in] mode     Pointer to the current mode of a menu level.
 */
void
get_print_result_message(response_s *response, player_mode_e *mode) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	printf("\n\n%s\n", response->payload);
	*mode = PLAYER_MODE_LOGGED_IN;
}
示例#17
0
/**
 * Prints out a message showing the player that lost the game.
 * @param[in] response Pointer to a message containing error.
 * @param[in] mode     Pointer to the current mode of a menu level.
 */
void
get_print_lost_message(response_s *response, player_mode_e *mode) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	printf("\n\nYou lost the game!\n");
	*mode = PLAYER_MODE_LOGGED_IN;
}
示例#18
0
/**
 * Prints out a message showing that the game has ended with a draw.
 * @param[in] response Pointer to a message containing error.
 * @param[in] mode     Pointer to the current mode of a menu level.
 */
void
get_print_draw_message(response_s *response, player_mode_e *mode) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	printf("\n\nThere is a draw! Game has ended.\n");
	*mode = PLAYER_MODE_LOGGED_IN;
}
示例#19
0
文件: wcd.c 项目: flsafe/Webdir
int main(int argc, char **argv){
  if (argc != 2) return 1;

	if (!bucket_exists(argv[1])){
		print_error_details();
		print_error_message(argv[1]);
	}

	return 0;
}
示例#20
0
/* Application entry */
int SGX_CDECL main(int argc, char *argv[])
{
    sgx_status_t sgx_ret = SGX_SUCCESS;
    sgx_status_t enclave_ret = SGX_SUCCESS;
    uint32_t sealed_log_size = 1024;
    uint8_t sealed_log[1024] = {0};
    sgx_sealed_data_t * sealed_data = 0;

    (void)(argc);
    (void)(argv);

    /* Initialize the enclave */
    if(initialize_enclave() < 0){
        printf("Enter a character before exit ...\n");
        getchar();
        return -1;
    }

    const char* str = "This is c str passed into enclave!";
    size_t len = strlen(str);

    sgx_ret = say_something(global_eid,
	                        &enclave_ret,
							(const uint8_t *) str,
							len);

    if(sgx_ret != SGX_SUCCESS) {
        print_error_message(sgx_ret);
        return -1;
    }

    if(enclave_ret != SGX_SUCCESS) {
        print_error_message(enclave_ret);
        return -1;
    }

    printf("[+] say_something success ...\n");

    /* Destroy the enclave */
    sgx_destroy_enclave(global_eid);

    return 0;
}
示例#21
0
文件: main.c 项目: jmoren/block_file
int search_by_code(char* entidad, int code){
  FILE * block_file;
  struct record_t *record;
  struct block_t * current_block;
  struct file_header * file_header;
  int res, i = 1, j = 1, recs = 0;
  int current_pos = 0, encontrado = 1;

  block_file = open_block_file(entidad, 2);
  if(!block_file){
    return BAD_NAME_FILE;
  }

  /* Allocate buffer and record */
  record        = (struct record_t*) malloc(sizeof(struct record_t));
  current_block = (struct block_t *) malloc(sizeof(struct block_t));
  file_header   = (struct file_header*) malloc(sizeof(struct file_header));

  if(!record || !current_block || !file_header)
    return ALLOCATE_FAIL;

  initialize_record(record);
  initialize_block(current_block,1);
  read_header(block_file, file_header);

  while((i < file_header->total_blocks+1) && (encontrado == 1)){
    current_pos = 0;
    j = 1;
    res  = read_from_file(block_file, current_block, file_header, i);
    if(res == RES_OK){
      recs = current_block->total_reg;
      while((j < recs+1) && (encontrado == 1)){
        initialize_record(record);
        current_pos += read_block(current_block, record, current_pos);
        if(code == record->code){
          print_success_message(record);
          encontrado = 0;
        }
        free(record->content);
        j++;
      }
    }
    i++;
  }
  if(encontrado == 1){
    print_error_message(code);
  }
  free(record);
  free(file_header);
  free(current_block);
  fclose(block_file);
  return res;
}
示例#22
0
/**
 * Prints out a message after a game has ended or one of players has given up.
 * Then changes player mode into logged in menu.
 * @param[in] response Pointer to a message containing error.
 * @param[in] mode     Pointer to the current mode of a menu level.
 * \sa player_mode_e
 */
void
get_cleanup_message(response_s *response, player_mode_e *mode) {
	if (response->error != MSG_RSP_ERROR_NONE) {
		print_error_message(response->error);
		return;
	}
	if (*mode == PLAYER_MODE_CONNECTED) {
		printf("\n\nYour opponent has given up. Back to main menu\n");
	} else if (*mode == PLAYER_MODE_SPECTATOR) {
		printf("\n\nThe game has ended. Back to main menu\n");
	}
	*mode = PLAYER_MODE_LOGGED_IN;
}
示例#23
0
文件: App.cpp 项目: 01org/linux-sgx
/* Initialize the enclave:
 *   Call sgx_create_enclave to initialize an enclave instance
 */
int initialize_enclave(void)
{
    sgx_status_t ret = SGX_ERROR_UNEXPECTED;
    
    /* Call sgx_create_enclave to initialize an enclave instance */
    /* Debug Support: set 2nd parameter to 1 */
    ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, NULL, NULL, &global_eid, NULL);
    if (ret != SGX_SUCCESS) {
        print_error_message(ret);
        return -1;
    }

    return 0;
}
示例#24
0
db_t
open_database(char* database_name, dbs_versioned_schema_def_t *versioned_schema, UpgradeCallback cb)
{
    db_t hdb;
    int version;
    int upgrade_rc = 0;

    /* Open an existing file storage database with default parameters. */
    hdb = db_open_file_storage(database_name, NULL);

    if (hdb == NULL) {
        return NULL;
    }

    db_begin_tx( hdb, DB_DEFAULT_ISOLATION | DB_LOCK_DEFAULT );
    version = get_schema_version( hdb );
    db_commit_tx( hdb, DB_DEFAULT_COMPLETION );

    if( version != versioned_schema->version
        && ( !cb
             || 0 != ( upgrade_rc = (*cb)( hdb, version, versioned_schema->version ) )
             )
        )
    {
        if( 1 == upgrade_rc ) {
            fprintf(
                stderr, "ITTIA evaluation mode can't be used to perform full upgrade actions set,\n"
                "  in this conditions we just suppose upgrade job is successfull\n"
                );
        }
        else {
            print_error_message( "Opened DB has wrong version and it couldn't be upgraded to version requiested", NULL );
            return NULL;
        }
    }

    if ( 0 == upgrade_rc && !dbs_check_schema(hdb, &versioned_schema->schema)) {
        fprintf(stderr, "WARNING: schema conflict in %s. Version: %d\n", database_name, versioned_schema->version );
        return NULL;
    }

    db_begin_tx( hdb, DB_DEFAULT_ISOLATION | DB_LOCK_DEFAULT );
    set_schema_version( hdb, versioned_schema->version );
    db_commit_tx( hdb, DB_DEFAULT_COMPLETION );

    //open_sequences(hdb);

    return hdb;
}
示例#25
0
db_t
create_database(char* database_name, dbs_schema_def_t *schema, db_file_storage_config_t * storage_cfg)
{
    db_t hdb;

    /* Create a new file storage database with default parameters. */
    hdb = db_create_file_storage(database_name, storage_cfg);

    if (hdb == NULL) {
        print_error_message( "Couldn't create DB", NULL );
        return NULL;
    }

    if (dbs_create_schema(hdb, schema) < 0) {
        print_error_message( "Couldn't initialize DB objects", NULL );

        db_shutdown(hdb, DB_SOFT_SHUTDOWN, NULL);
        /* Remove incomplete database. */
        remove(database_name);
        return NULL;
    }

    return hdb;
}
int		simple_grade_format_is_valid(char *grade, int line_number)
{
	int		grade_int;

	log_string("starting simple grade format validation: ", grade);
	grade_int = ft_atoi(grade);
	if (grade_int < 0 || grade_int > 10)
	{
		log_simple("simple grade format validation ended unsuccesfully");
		print_error_message("Grade is not in the 0-10 range.", line_number);
		return (0);
	}
	log_simple("simple grade format validation ended succesfully");
	return (1);
}
int		grade_characters_are_valid(char *grade, int line_number)
{
	int		index;

	index = 0;
	while (grade[index] != '\0')
	{
		if (!ft_isdigit(grade[index]) && grade[index] != '.')
		{
			print_error_message("Only digits and dots accepted in grade.",
					line_number);
			return (0);
		}
		index++;
	}
	return (1);
}
示例#28
0
void hilbertsortIpelet::protected_run(int fn)
{
  if (fn==1) {
    show_help();
    return;
  }


  
  std::vector<Circle_2> cir_list;
  std::vector<Circular_arc_2> arc_list;
  std::vector<Polygon_2> poly_list;
  std::vector<Segment_2> seg_list;
  std::vector<Point_2>  pt_list;

  read_active_objects( 
      CGAL::dispatch_or_drop_output<Point_2,Circle_2,Polygon_2,Circular_arc_2,Segment_2>(
                       std::back_inserter(pt_list),std::back_inserter(cir_list),
                       std::back_inserter(poly_list),std::back_inserter(arc_list),
                       std::back_inserter(seg_list)
      ),true,true
  );

  
  if (pt_list.size()<2) {
    print_error_message("No point selected to define a bounding box");
    return;
  }
  
  CGAL::Bbox_2 bbox_2=pt_list.begin()->bbox();
  for (std::vector<Point_2>::iterator it=pt_list.begin();it!=pt_list.end();++it)
    bbox_2=bbox_2+it->bbox();
  Iso_rectangle_2 bbox(bbox_2.xmin(),bbox_2.ymin(),bbox_2.xmax(),bbox_2.ymax());
  
  
  draw_in_ipe(bbox);
  draw_in_ipe(cir_list.begin(),cir_list.end(),bbox,false);
  draw_in_ipe(seg_list.begin(),seg_list.end(),bbox,false);
  draw_in_ipe(arc_list.begin(),arc_list.end(),bbox,false);
  draw_in_ipe(poly_list.begin(),poly_list.end(),bbox,false);
  
}
示例#29
0
文件: hilbert_sort.cpp 项目: FMX/CGAL
void hilbertsortIpelet::protected_run(int fn)
{
  if (fn==1) {
    show_help();
    return;
  }


  
  std::vector<Point_2> pt_list;

  read_active_objects( CGAL::dispatch_or_drop_output<Point_2>( std::back_inserter(pt_list) ) );

  if (pt_list.empty()) {
    print_error_message("No mark selected");
    return;
  }
  
  CGAL::hilbert_sort(pt_list.begin(), pt_list.end());
  
  draw_polyline_in_ipe(pt_list.begin(), pt_list.end());
}
示例#30
0
static int
upgrade_schema_cb( db_t hdb, int old_version, int new_version )
{
    db_result_t rc = DB_OK;

    fprintf( stdout, "Upgrading schema v%d to v%d\n", old_version, new_version );

    if ( old_version < 1 || new_version > 3 ) {
        print_error_message( "Schema upgrade path not supported", NULL );
        return -1;
    }

    if ( DB_OK == rc && old_version < 2 && new_version >= 2 ) {
        rc = upgrade_to_schema_v2( hdb );
    }

    if ( DB_OK == rc && old_version < 3 && new_version >= 3 ) {
        rc = upgrade_to_schema_v3( hdb );
    }

    return DB_OK != rc ? -1 : 0;
}