Exemple #1
0
void er_wbuf ( int *iret )
/************************************************************************
 * er_wbuf								*
 *									*
 * This routine writes all of the error messages in the error message	*
 * buffer to the terminal.  The buffer is then re-initialized.		*
 *									*
 * er_wbuf ( iret )							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 +1 = no msgs in buffer		*
 **									*
 * Log:									*
 * K. Tyle/GSC		12/96						*
 * K. Tyle/GSC		 1/97	Change nstr to nermsg			*
 * C. Lin/EAI		 1/97	Change msgstr to errmsg			*
 * S. Maxwell/GSC	 6/97	Documentation changes			*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 ***********************************************************************/
{
	short int	i;
	int		ier;
/*---------------------------------------------------------------------*/
	*iret = 0;
/*
 *	Return error if there are no messages.
*/
	if ( nermsg == 0 ) {
	    *iret = 1;
	}
/*
 *	Write messages to the buffer.
 */
	else {
	    for ( i = 1; i <= nermsg; i++ ) {
		printf ("%s\n",errmsg[i-1]);
	    }
/*
 *	Re-initialize message buffer.
 */
	    er_init ( &ier );
	}
}
Exemple #2
0
/*
* Initialization of buffers and EduRaster structures.
*/
static void setup(){
    /* Allocate depth buffer */
    depth_buffer = (float*)malloc(window_width*window_height*sizeof(float));
    if(depth_buffer == NULL){
        fprintf(stderr, "Unable to create depth buffer. Out of memory\n");
        quit();
    }
    /* Allocate color buffer */
    color_buffer = (unsigned int*)malloc(window_width*window_height*sizeof(unsigned int));
    if(color_buffer == NULL){
        fprintf(stderr, "Unable to create color buffer. Out of memory\n");
        quit();
    }
    /* Init EduRaster */
    if(er_init() != 0) {
        fprintf(stderr, "Unable to init eduraster: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_viewport(0, 0, window_width, window_height);
    /* Set Perspective Projection */
    er_matrix_mode(ER_PROJECTION);
    er_load_identity();
    er_perspective(60.0f, (float)window_width / (float)window_height, 2.0f, 50.0f);
    er_matrix_mode(ER_MODELVIEW);

    /* Allocate buffer for vertex data */
    points = (float *)malloc(sizeof(float) * 6 * samples_t * samples_s);
    if(points == NULL){
        fprintf(stderr, "Unable to create vertex data for surface. Out of memory\n");
        quit();
    }
    /* Allocate buffer for indices */
    index_size = (samples_s - 1) * (samples_t - 1) * 6;
    index_data = (unsigned int*)malloc( index_size * sizeof(unsigned int));
    if(index_data == NULL){
        fprintf(stderr, "Unable to create indices for surface. Out of memory\n");
        quit();
    }
    /* Calculate indices */
    int width = (samples_t-1) * 6, i ,j;
    for(i = 0; i < samples_s - 1; i++){
        for(j = 0; j < samples_t - 1; j++){
            // Up Triangle
            index_data[i*width + j*6    ] = i * samples_t + j;
            index_data[i*width + j*6 + 1] = (i+1) * samples_t + j;
            index_data[i*width + j*6 + 2] = i * samples_t + (j + 1);
            // Down Triangle
            index_data[i*width + j*6 + 3] = i * samples_t + (j+1);
            index_data[i*width + j*6 + 4] = (i+1) * samples_t + j;
            index_data[i*width + j*6 + 5] = (i+1) * samples_t + (j+1);
        }
    }
    /* Evaluate surface equations */
    calculate_surface();
    /* Create vertex array for surface */
    va = er_create_vertex_array();
    if(va == NULL){
        fprintf(stderr, "Unable to create vertex array: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_use_vertex_array(va);
    er_vertex_pointer(va, 6, 3, points );
    er_normal_pointer(va, 6, &points[3] );
    er_enable_attribute_array(va, ER_VERTEX_ARRAY, ER_TRUE);
    er_enable_attribute_array(va, ER_NORMAL_ARRAY, ER_TRUE);
    /* Create program for surface lighting */
    program_surface_light = er_create_program();
    if(program_surface_light == NULL){
        fprintf(stderr, "Unable to create eduraster program: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_use_program(program_surface_light);
    er_varying_attributes(program_surface_light, 6);
    er_load_fragment_shader(program_surface_light, fragment_shader_light);
    er_load_vertex_shader(program_surface_light, vertex_shader_light);
    er_load_homogeneous_division(program_surface_light, homogeneous_division_light);
    er_uniformf(program_surface_light, 0, 0.5773503f);
    er_uniformf(program_surface_light, 1, 0.5773503f);
    er_uniformf(program_surface_light, 2, 0.5773503f);
    /* Create program for axis */
    program_axis = er_create_program();
    if(program_axis == NULL){
        fprintf(stderr, "Unable to create eduraster program: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_use_program(program_axis);
    er_varying_attributes(program_axis, 4);
    er_load_fragment_shader(program_axis, fragment_shader_axis);
    er_load_vertex_shader(program_axis, vertex_shader_axis);
    er_load_homogeneous_division(program_axis, homogeneous_division_axis);
    /* Create program for surface color */
    program_surface_color = er_create_program();
    if(program_surface_color == NULL){
        fprintf(stderr, "Unable to create eduraster program: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_use_program(program_surface_color);
    er_varying_attributes(program_surface_color, 3);
    er_load_fragment_shader(program_surface_color, fragment_shader_color);
    er_load_vertex_shader(program_surface_color, vertex_shader_color);
    er_load_homogeneous_division(program_surface_color, homogeneous_division_color);
    /* Default program */
    current_surface_program = program_surface_light;
}
Exemple #3
0
/*
 * loaddb_internal - internal main loaddb function
 *    return: NO_ERROR if successful, error code otherwise
 *    argc(in): argc of main
 *    argv(in): argv of main
 *    dba_mode(in):
 */
static int
loaddb_internal (UTIL_FUNCTION_ARG * arg, int dba_mode)
{
  UTIL_ARG_MAP *arg_map = arg->arg_map;
  int error = NO_ERROR;
  /* set to static to avoid copiler warning (clobbered by longjump) */
  static FILE *schema_file = NULL;
  static FILE *index_file = NULL;
  static FILE *object_file = NULL;
  FILE *error_file = NULL;
  int status = 0;
  int errors, objects, defaults;
#if !defined (LDR_OLD_LOADDB)
  int lastcommit = 0;
#endif /* !LDR_OLD_LOADDB */
  char *passwd;
  /* set to static to avoid copiler warning (clobbered by longjump) */
  static int interrupted = false;
  int au_save = 0;
  extern bool obt_Enable_autoincrement;

  char log_file_name[PATH_MAX];

  LOADDB_INIT_DEBUG ();
  obt_Enable_autoincrement = false;

  Volume = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
  Input_file = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE,
						1);
  User_name = utility_get_option_string_value (arg_map, LOAD_USER_S, 0);
  Password = utility_get_option_string_value (arg_map, LOAD_PASSWORD_S, 0);
  Syntax_check = utility_get_option_bool_value (arg_map, LOAD_CHECK_ONLY_S);
  Load_only = utility_get_option_bool_value (arg_map, LOAD_LOAD_ONLY_S);
  Estimated_size = utility_get_option_int_value (arg_map,
						 LOAD_ESTIMATED_SIZE_S);
  Verbose = utility_get_option_bool_value (arg_map, LOAD_VERBOSE_S);
  Disable_statistics =
    utility_get_option_bool_value (arg_map, LOAD_NO_STATISTICS_S);
  Periodic_commit = utility_get_option_int_value (arg_map,
						  LOAD_PERIODIC_COMMIT_S);
  Verbose_commit = Periodic_commit > 0 ? true : false;
  No_oid_hint = utility_get_option_bool_value (arg_map, LOAD_NO_OID_S);
  Schema_file = utility_get_option_string_value (arg_map, LOAD_SCHEMA_FILE_S,
						 0);
  Index_file = utility_get_option_string_value (arg_map, LOAD_INDEX_FILE_S,
						0);
  Object_file = utility_get_option_string_value (arg_map, LOAD_DATA_FILE_S,
						 0);
  Error_file = utility_get_option_string_value (arg_map,
						LOAD_ERROR_CONTROL_FILE_S, 0);
  Ignore_logging = utility_get_option_bool_value (arg_map,
						  LOAD_IGNORE_LOGGING_S);
#if !defined (LDR_OLD_LOADDB)
  Ignore_class_file = utility_get_option_string_value (arg_map,
						       LOAD_IGNORE_CLASS_S,
						       0);
#endif

  Input_file = Input_file ? Input_file : "";
  Schema_file = Schema_file ? Schema_file : "";
  Index_file = Index_file ? Index_file : "";
  Object_file = Object_file ? Object_file : "";
  Error_file = Error_file ? Error_file : "";

  if (ldr_validate_object_file (stderr, arg->argv0))
    {
      goto error_return;
    }

  /* error message log file */
  sprintf (log_file_name, "%s_%s.err", Volume, arg->command_name);
  er_init (log_file_name, ER_NEVER_EXIT);

  if (Index_file[0] != '\0'
      && PRM_SR_NBUFFERS < LOAD_INDEX_MIN_SORT_BUFFER_PAGES)
    {
      sysprm_set_force (PRM_NAME_SR_NBUFFERS,
			LOAD_INDEX_MIN_SORT_BUFFER_PAGES_STRING);
    }
  sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no");

  /* login */
  if (User_name != NULL || !dba_mode)
    {
      (void) db_login (User_name, Password);
      if ((error = db_restart (arg->command_name, true, Volume)))
	{
	  if (error == ER_AU_INVALID_PASSWORD)
	    {
	      /* prompt for password and try again */
	      error = NO_ERROR;
	      passwd = getpass (msgcat_message (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_PASSWORD_PROMPT));
	      if (!strlen (passwd))
		passwd = NULL;
	      (void) db_login (User_name, passwd);
	      error = db_restart (arg->command_name, true, Volume);
	    }
	}
    }
  else
    {
      /* if we're in the protected dba mode, just login without
         authorization */
      AU_DISABLE_PASSWORDS ();
      db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY);
      (void) db_login ("dba", NULL);
      error = db_restart (arg->command_name, true, Volume);
    }

  /* open loaddb log file */
  sprintf (log_file_name, "%s_loaddb.log", Volume);
  loaddb_log_file = fopen (log_file_name, "w+");
  if (loaddb_log_file == NULL)
    {
      printf ("Cannot open log file %s\n", log_file_name);
      status = 2;
      goto error_return;
    }

#if 0
#if !defined (LDR_OLD_LOADDB)

  /* Execute old loaddb if no optimization flag is set true
   * or LOADDB_NOPT is set, we must pass the argv except
   * -no option and invoke execvp() for no optimized loaddb
   */
  if (No_optimization || envvar_get ("LOADDB_NOPT"))
    {

      char **tmp;
      char *lastslash, path[PATH_MAX];
      int i = 1, j = 1;

      tmp = (char **) malloc (sizeof (char *) * (argc + 1));
      tmp[0] = (char *) "loaddb";
      while (j < argc)
	{
	  if (!strcmp (argv[j], "-no"))
	    j++;
	  else
	    tmp[i++] = argv[j++];
	};
      tmp[i] = 0;

      strcpy (path, argv[0]);
      lastslash = strrchr (path, (int) '/');
#if defined(WINDOWS)
      {
	char *p, exec_path[1024], cmd_line[1024 * 8];
	int cp_len = 0;

	db_shutdown ();

	p = envvar_root ();
	if (p == NULL)
	  {
	    printf ("The `CUBRID' environment variable is not set.\n");
	  }
	else
	  {
	    sprintf (exec_path, "%s/migdb_o.exe", p);
	    for (i = 0; tmp[i]; i++)
	      {
		cp_len += sprintf (cmd_line + cp_len, "\"%s\" ", tmp[i]);
	      }
	    if (envvar_get ("FRONT_DEBUG") != NULL)
	      {
		printf ("Executing:%s %s\n", exec_path, cmd_line);
	      }
	    run_proc (exec_path, cmd_line);
	  }
	exit (0);
      }
#else /* !WINDOWS */
      if (lastslash != NULL)
	strcpy (lastslash + 1, "migdb_o");
      else
	strcpy (path, "migdb_o");

      if (execvp (path, tmp) == -1)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_NOPT_ERR));
	  exit (0);
	};
#endif /* WINDOWS */
    }
#endif /* !LDR_OLD_LOADDB */
#endif

  /* check if schema/index/object files exist */
  ldr_check_file_name_and_line_no ();

  if (Schema_file[0] != 0)
    {
      schema_file = fopen (Schema_file, "r");
      if (schema_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Schema_file);
	  status = 2;
	  goto error_return;
	}
    }
  if (Index_file[0] != 0)
    {
      index_file = fopen (Index_file, "r");
      if (index_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Index_file);
	  status = 2;
	  goto error_return;
	}
    }
  if (Object_file[0] != 0)
    {
      object_file = fopen_ex (Object_file, "rb");	/* keep out ^Z */

      if (object_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Object_file);
	  status = 2;
	  goto error_return;
	}
    }

#if !defined (LDR_OLD_LOADDB)
  if (Ignore_class_file)
    {
      int retval;
      retval = get_ignore_class_list (Ignore_class_file);

      if (retval < 0)
	{
	  status = 2;
	  goto error_return;
	}
    }
#endif

  /* Disallow syntax only and load only options together */
  if (Load_only && Syntax_check)
    {
      print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					MSGCAT_UTIL_SET_LOADDB,
					LOADDB_MSG_INCOMPATIBLE_ARGS),
		     "--" LOAD_LOAD_ONLY_L, "--" LOAD_CHECK_ONLY_L);
      status = 1;		/* parsing error */
      goto error_return;
    }

  if (Error_file[0] != 0)
    {
      if (Syntax_check)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_INCOMPATIBLE_ARGS),
			 "--" LOAD_ERROR_CONTROL_FILE_L,
			 "--" LOAD_CHECK_ONLY_L);
	  status = 1;		/* parsing error */
	  goto error_return;
	}
      error_file = fopen_ex (Error_file, "rt");
      if (error_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Error_file);
	  status = 2;
	  goto error_return;
	}
      er_filter_fileset (error_file);
      fclose (error_file);
    }

  /* check if no log option can be applied */
  if (error
      || (Ignore_logging != 0 && locator_log_force_nologging () != NO_ERROR))
    {
      /* couldn't log in */
      print_log_msg (1, "%s\n", db_error_string (3));
      status = 3;
      db_shutdown ();
      goto error_return;
    }

  /* change "print_key_value_on_unique_error" parameter */
  sysprm_change_server_parameters ("print_key_value_on_unique_error=1");

  /* if schema file is specified, do schema loading */
  if (schema_file != NULL)
    {
      print_log_msg (1, "\nStart schema loading.\n");

      /*
       * CUBRID 8.2 should be compatible with earlier versions of CUBRID.
       * Therefore, we do not perform user authentication when the loader
       * is executing by DBA group user.
       */
      if (au_is_dba_group_member (Au_user))
	{
	  AU_DISABLE (au_save);
	}

      if (ldr_exec_query_from_file (Schema_file, schema_file,
				    &schema_file_start_line,
				    Periodic_commit) != 0)
	{
	  print_log_msg (1, "\nError occurred during schema loading."
			 "\nAborting current transaction...");
	  status = 3;
	  db_shutdown ();
	  print_log_msg (1,
			 " done.\n\nRestart loaddb with '-%c %s:%d' option\n",
			 LOAD_SCHEMA_FILE_S, Schema_file,
			 schema_file_start_line);
	  goto error_return;
	}

      if (au_is_dba_group_member (Au_user))
	{
	  AU_ENABLE (au_save);
	}

      print_log_msg (1, "Schema loading from %s finished.\n", Schema_file);

      /* update catalog statistics */
      AU_DISABLE (au_save);
      sm_update_all_catalog_statistics ();
      AU_ENABLE (au_save);

      print_log_msg (1,
		     "Statistics for Catalog classes have been updated.\n\n");

      db_commit_transaction ();
      fclose (schema_file);
      schema_file = NULL;

    }


  /* if index file is specified, do index creation */

  if (object_file != NULL)
    {
#if defined (SA_MODE)
      locator_Dont_check_foreign_key = true;
#endif
      print_log_msg (1, "\nStart object loading.\n");
      ldr_init (Verbose);

      /* set the flag to indicate what type of interrupts to raise
       * If logging has been disabled set commit flag.
       * If logging is enabled set abort flag.
       */

      if (Ignore_logging)
	Interrupt_type = LDR_STOP_AND_COMMIT_INTERRUPT;
      else
	Interrupt_type = LDR_STOP_AND_ABORT_INTERRUPT;

      if (Periodic_commit)
	{
	  /* register the post commit function */
#if defined(LDR_OLD_LOADDB)
	  ldr_register_post_commit_handler (&loaddb_report_num_of_commits);
#else /* !LDR_OLD_LOADDB */
	  ldr_register_post_commit_handler (&loaddb_report_num_of_commits,
					    NULL);
#endif /* LDR_OLD_LOADDB */
	}

      /* Check if we need to perform syntax checking. */
      if (!Load_only)
	{
	  print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS,
							MSGCAT_UTIL_SET_LOADDB,
							LOADDB_MSG_CHECKING));
	  do_loader_parse (object_file);
#if defined(LDR_OLD_LOADDB)
	  ldr_stats (&errors, &objects, &defaults);
#else /* !LDR_OLD_LOADDB */
	  ldr_stats (&errors, &objects, &defaults, &lastcommit);
#endif /* LDR_OLD_LOADDB */
	}
      else
	errors = 0;

      if (errors)
	print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					  MSGCAT_UTIL_SET_LOADDB,
					  LOADDB_MSG_ERROR_COUNT), errors);
      else if (!Syntax_check)
	{
	  /* now do it for real if there were no errors and we aren't
	     doing a simple syntax check */
	  ldr_start (Periodic_commit);
	  fclose (object_file);
	  object_file = fopen_ex (Object_file, "rb");	/* keep out ^Z */
	  if (object_file != NULL)
	    {
	      print_log_msg ((int) Verbose,
			     msgcat_message (MSGCAT_CATALOG_UTILS,
					     MSGCAT_UTIL_SET_LOADDB,
					     LOADDB_MSG_INSERTING));

	      /* make sure signals are caught */
	      util_arm_signal_handlers (signal_handler, signal_handler);

	      /* register function to call  and jmp environment to longjmp to
	       * after aborting or committing.
	       */
	      ldr_register_post_interrupt_handler
		(&loaddb_get_num_of_inserted_objects, &loaddb_jmp_buf);

	      if (setjmp (loaddb_jmp_buf) != 0)
		{

		  /* We have had an interrupt, the transaction should have
		   * been already been aborted or committed by the loader.
		   * If Total_objects_loaded is -1 an error occurred during
		   * rollback or commit.
		   */
		  if (Total_objects_loaded != -1)
		    print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
						      MSGCAT_UTIL_SET_LOADDB,
						      LOADDB_MSG_OBJECT_COUNT),
				   Total_objects_loaded);
#if !defined(LDR_OLD_LOADDB)
		  ldr_stats (&errors, &objects, &defaults, &lastcommit);
		  if (lastcommit > 0)
		    print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
						      MSGCAT_UTIL_SET_LOADDB,
						      LOADDB_MSG_LAST_COMMITTED_LINE),
				   lastcommit);
#endif /* !LDR_OLD_LOADDB */
		  interrupted = true;

		}
	      else
		{
		  do_loader_parse (object_file);
#if defined(LDR_OLD_LOADDB)
		  ldr_stats (&errors, &objects, &defaults);
#else /* !LDR_OLD_LOADDB */
		  ldr_stats (&errors, &objects, &defaults, &lastcommit);
#endif /* LDR_OLD_LOADDB */
		  if (errors)
		    {
#if defined(LDR_OLD_LOADDB)
		      print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
							MSGCAT_UTIL_SET_LOADDB,
							LOADDB_MSG_ERROR_COUNT),
				     errors);
#else /* !LDR_OLD_LOADDB */
		      if (lastcommit > 0)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_LAST_COMMITTED_LINE),
				       lastcommit);
#endif /* LDR_OLD_LOADDB */
		      /*
		       * don't allow the transaction to be committed at
		       * this point, note that if we ever move to a scheme
		       * where we write directly to the heap without the
		       * transaction context, we will have to unwind the
		       * changes made if errors are detected !
		       */
		      db_abort_transaction ();
		    }
		  else
		    {
		      if (objects)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_OBJECT_COUNT),
				       objects);
		      if (defaults)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_DEFAULT_COUNT),
				       defaults);
		      print_log_msg ((int) Verbose,
				     msgcat_message (MSGCAT_CATALOG_UTILS,
						     MSGCAT_UTIL_SET_LOADDB,
						     LOADDB_MSG_COMMITTING));

		      /* commit the transaction and then update statistics */
		      if (!db_commit_transaction ())
			{
			  if (!Disable_statistics)
			    {
			      if (Verbose)
				print_log_msg (1,
					       msgcat_message
					       (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_UPDATING_STATISTICS));
			      if (!ldr_update_statistics ())
				{
				  /*
				   * would it be faster to update statistics
				   * before the first commit and just have a
				   * single commit ?
				   */
				  print_log_msg ((int) Verbose,
						 msgcat_message
						 (MSGCAT_CATALOG_UTILS,
						  MSGCAT_UTIL_SET_LOADDB,
						  LOADDB_MSG_COMMITTING));
				  (void) db_commit_transaction ();
				}
			    }
			}
		    }
		}
	    }
	}
      ldr_final ();
      if (object_file != NULL)
	{
	  fclose (object_file);
	  object_file = NULL;
	}
    }

  /* create index */
  if (!interrupted && index_file != NULL)
    {
      print_log_msg (1, "\nStart index loading.\n");
      if (ldr_exec_query_from_file (Index_file, index_file,
				    &index_file_start_line,
				    Periodic_commit) != 0)
	{
	  print_log_msg (1, "\nError occurred during index loading."
			 "\nAborting current transaction...");
	  status = 3;
	  db_shutdown ();
	  print_log_msg (1,
			 " done.\n\nRestart loaddb with '-%c %s:%d' option\n",
			 LOAD_INDEX_FILE_S, Index_file,
			 index_file_start_line);
	  goto error_return;
	}
      /* update catalog statistics */
      AU_DISABLE (au_save);
      sm_update_catalog_statistics (CT_INDEX_NAME);
      sm_update_catalog_statistics (CT_INDEXKEY_NAME);
      AU_ENABLE (au_save);

      print_log_msg (1, "Index loading from %s finished.\n", Index_file);
      db_commit_transaction ();
    }
  print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_CLOSING));
  (void) db_shutdown ();

#if !defined (LDR_OLD_LOADDB)
  free_ignoreclasslist ();
#endif
  return (status);
error_return:
  if (schema_file != NULL)
    fclose (schema_file);
  if (object_file != NULL)
    fclose (object_file);
  if (index_file != NULL)
    fclose (index_file);

#if !defined (LDR_OLD_LOADDB)
  free_ignoreclasslist ();
#endif

  return status;
}
Exemple #4
0
/*
* Initialization of buffers and EduRaster structures.
*/
static void setup(){
    /* Allocate color buffer */
    color_buffer = (unsigned int*)malloc(window_width*window_height*sizeof(unsigned int));
    if(color_buffer == NULL){
        fprintf(stderr, "Unable to allocate color buffer. Out of memory\n");
        quit();
    }
    /* Allocate depth buffer */
    depth_buffer = (float* )malloc(window_width*window_height*sizeof(float));
    if(depth_buffer == NULL){
        fprintf(stderr, "Unable to allocate depth buffer. Out of memory\n");
        quit();
    }
    /* Init EduRaster */
    if(er_init() != 0) {
        fprintf(stderr, "Unable to init eduraster: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_viewport(0 , 0 , window_width, window_height);
    /* Set perspective projection */
    er_matrix_mode(ER_PROJECTION);
    er_load_identity();
    er_perspective(60.0f, (float)window_width / (float)window_height, 2.0f, 40.0f);
    er_matrix_mode(ER_MODELVIEW);
    /* Load image and create texture */
    const char *image_path = "textures/lenna.bmp";
    SDL_Surface *image = SDL_LoadBMP(image_path);
    if(image == NULL){
        fprintf(stderr, "Unable to load image %s. Error: %s\n", SDL_GetError());
        quit();
    }

    tex = er_create_texture2D(image->w, image->h, ER_RGB32F);
    if(tex == NULL){
        fprintf(stderr, "Unable to create texture %s. Error: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_texture_filtering(tex, ER_MAGNIFICATION_FILTER, ER_LINEAR);
    er_texture_filtering(tex, ER_MINIFICATION_FILTER, ER_LINEAR_MIPMAP_LINEAR);
    er_texture_wrap_mode(tex, ER_WRAP_S, ER_REPEAT);
    er_texture_wrap_mode(tex, ER_WRAP_T, ER_REPEAT);
    
    SDL_PixelFormat *format = image->format;
    SDL_LockSurface(image);
    unsigned char *src_data = image->pixels;
    float *dst_data = er_texture_ptr(tex, ER_TEXTURE_2D, 0);
    int i, j;
    unsigned int src_color = 0;
    unsigned char r, g, b;
    for(i = 0; i < image->h;i++){
        for(j = 0; j < image->w; j++){
            memcpy(&src_color, &src_data[(image->h-1-i)*image->pitch+j*format->BytesPerPixel], format->BytesPerPixel);
            SDL_GetRGB(src_color, format, &r, &g, &b);
            dst_data[i*image->w*3+j*3] = (float)r / 255.0f;
            dst_data[i*image->w*3+j*3+1] = (float)g / 255.0f;
            dst_data[i*image->w*3+j*3+2] = (float)b / 255.0f;
        }
    }
    SDL_UnlockSurface(image);
    SDL_FreeSurface(image);
    /* Generate mipmaps */
    er_generate_mipmaps(tex);
    int error = er_get_error();
    if(error != ER_NO_ERROR){
        fprintf(stderr, "%s\n",er_get_error_string(error));
        quit();
    }
    /* Create program for texture */
    prog = er_create_program();
    if(prog == NULL){
        fprintf(stderr, "Unable to create eduraster program: %s\n", er_get_error_string(er_get_error()));
        quit();
    }
    er_use_program(prog);
    er_varying_attributes(prog, 2);
    er_load_vertex_shader(prog, vs_cube);
    er_load_homogeneous_division(prog, hd_cube);
    er_load_fragment_shader(prog, fs_cube);
    er_uniform_texture_ptr(prog, 0, tex);
    /* Enable backface culling */
    er_cull_face(ER_BACK);
    er_enable(ER_CULL_FACE, ER_TRUE);

}