c-lib: strict conformance to C90
This commit is contained in:
parent
2cae8b387c
commit
33b4d7f2e8
@ -38,7 +38,8 @@ SOURCES += \
|
|||||||
../../../src/c/libstl/stlb_read.c \
|
../../../src/c/libstl/stlb_read.c \
|
||||||
../../../src/c/libstl/stlb_write.c
|
../../../src/c/libstl/stlb_write.c
|
||||||
|
|
||||||
*-g++*:QMAKE_CFLAGS += -ansi
|
*-g++*:QMAKE_CFLAGS += -ansi -pedantic-errors
|
||||||
|
*-msvc*:QMAKE_CFLAGS += -TC
|
||||||
|
|
||||||
global_inc.path = $$PREFIX_DIR/include/dataex
|
global_inc.path = $$PREFIX_DIR/include/dataex
|
||||||
global_inc.files = ../../../src/*.h
|
global_inc.files = ../../../src/*.h
|
||||||
|
@ -32,13 +32,13 @@ typedef unsigned short uint16_t;
|
|||||||
typedef int int32_t;
|
typedef int int32_t;
|
||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
|
|
||||||
# ifdef _MSC_VER
|
/*# ifdef _MSC_VER
|
||||||
typedef __int64 int64_t;
|
typedef __int64 int64_t;
|
||||||
typedef unsigned __int64 uint64_t;
|
typedef unsigned __int64 uint64_t;
|
||||||
# else
|
# else
|
||||||
typedef long long int64_t;
|
typedef long long int64_t;
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned long long uint64_t;
|
||||||
# endif /* _MSC_VER */
|
# endif*/ /* _MSC_VER */
|
||||||
|
|
||||||
#endif /* FOUG_USE_STDINT_H */
|
#endif /* FOUG_USE_STDINT_H */
|
||||||
|
|
||||||
|
@ -12,9 +12,11 @@ foug_stlb_geom_input_t* foug_stlb_geom_input_create(foug_malloc_func_t func,
|
|||||||
void* data,
|
void* data,
|
||||||
foug_stlb_geom_input_manip_t manip)
|
foug_stlb_geom_input_manip_t manip)
|
||||||
{
|
{
|
||||||
|
foug_stlb_geom_input_t* geom;
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
foug_stlb_geom_input_t* geom = (*func)(sizeof(struct _internal_foug_stlb_geom_input));
|
geom = (*func)(sizeof(struct _internal_foug_stlb_geom_input));
|
||||||
if (geom != NULL) {
|
if (geom != NULL) {
|
||||||
geom->cookie = data;
|
geom->cookie = data;
|
||||||
geom->manip = manip;
|
geom->manip = manip;
|
||||||
@ -32,55 +34,20 @@ static foug_bool_t foug_stlb_no_error(int code)
|
|||||||
return code == FOUG_STLB_READ_NO_ERROR;
|
return code == FOUG_STLB_READ_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int foug_stlb_read(foug_stlb_read_args_t args)
|
static void foug_stlb_read_facets(foug_stlb_geom_input_t* geom_input,
|
||||||
|
uint8_t* buffer,
|
||||||
|
uint32_t facet_count)
|
||||||
{
|
{
|
||||||
if (args.geom_input == NULL)
|
|
||||||
return FOUG_STLB_READ_NULL_GEOM_INPUT_ERROR;
|
|
||||||
if (args.stream == NULL)
|
|
||||||
return FOUG_STLB_READ_NULL_STREAM_ERROR;
|
|
||||||
/* if (args.buffer_size == 0)
|
|
||||||
return FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR;*/
|
|
||||||
|
|
||||||
uint8_t buffer[8192];
|
|
||||||
|
|
||||||
/* Read header */
|
|
||||||
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
|
||||||
if (foug_stream_read(args.stream, header_data, 1, FOUG_STLB_HEADER_SIZE) != FOUG_STLB_HEADER_SIZE)
|
|
||||||
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
|
||||||
|
|
||||||
if (args.geom_input->manip.process_header_func != NULL)
|
|
||||||
(*(args.geom_input->manip.process_header_func))(args.geom_input, header_data);
|
|
||||||
|
|
||||||
/* Read facet count */
|
|
||||||
if (foug_stream_read(args.stream, buffer, sizeof(uint32_t), 1) != 1)
|
|
||||||
return FOUG_STLB_READ_FACET_COUNT_ERROR;
|
|
||||||
|
|
||||||
const uint32_t total_facet_count = foug_decode_uint32_le(buffer);
|
|
||||||
if (args.geom_input->manip.begin_triangles_func != NULL)
|
|
||||||
(*(args.geom_input->manip.begin_triangles_func))(args.geom_input, total_facet_count);
|
|
||||||
|
|
||||||
foug_task_control_reset(args.task_control);
|
|
||||||
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)total_facet_count);
|
|
||||||
|
|
||||||
/* Read triangles */
|
|
||||||
const size_t buffer_facet_count = 163;
|
|
||||||
size_t accum_facet_count_read = 0;
|
|
||||||
foug_stl_triangle_t triangle;
|
foug_stl_triangle_t triangle;
|
||||||
int error = FOUG_STLB_READ_NO_ERROR;
|
uint16_t attr_byte_count;
|
||||||
while (foug_stlb_no_error(error) && accum_facet_count_read < total_facet_count) {
|
uint32_t buffer_offset;
|
||||||
const size_t facet_count_read =
|
|
||||||
foug_stream_read(args.stream, buffer, FOUG_STLB_TRIANGLE_SIZE, buffer_facet_count);
|
|
||||||
if (foug_stream_error(args.stream) != 0)
|
|
||||||
error = FOUG_STLB_READ_STREAM_ERROR;
|
|
||||||
else if (facet_count_read > 0)
|
|
||||||
error = FOUG_STLB_READ_NO_ERROR;
|
|
||||||
else
|
|
||||||
break; /* Exit if no facet to read */
|
|
||||||
|
|
||||||
if (foug_stlb_no_error(error)) {
|
|
||||||
uint32_t buffer_offset = 0;
|
|
||||||
uint32_t i_facet;
|
uint32_t i_facet;
|
||||||
for (i_facet = 0; i_facet < facet_count_read; ++i_facet) {
|
|
||||||
|
if (geom_input->manip.process_next_triangle_func == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
buffer_offset = 0;
|
||||||
|
for (i_facet = 0; i_facet < facet_count; ++i_facet) {
|
||||||
/* Read normal */
|
/* Read normal */
|
||||||
triangle.normal.x = foug_decode_real32_le(buffer + buffer_offset);
|
triangle.normal.x = foug_decode_real32_le(buffer + buffer_offset);
|
||||||
triangle.normal.y = foug_decode_real32_le(buffer + 1*sizeof(foug_real32_t) + buffer_offset);
|
triangle.normal.y = foug_decode_real32_le(buffer + 1*sizeof(foug_real32_t) + buffer_offset);
|
||||||
@ -102,19 +69,65 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
|||||||
triangle.v3.z = foug_decode_real32_le(buffer + 11*sizeof(foug_real32_t) + buffer_offset);
|
triangle.v3.z = foug_decode_real32_le(buffer + 11*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
|
||||||
/* Attribute byte count */
|
/* Attribute byte count */
|
||||||
const uint16_t attribute_byte_count =
|
attr_byte_count = foug_decode_uint16_le(buffer + 12*sizeof(foug_real32_t) + buffer_offset);
|
||||||
foug_decode_uint16_le(buffer + 12*sizeof(foug_real32_t) + buffer_offset);
|
|
||||||
|
|
||||||
/* Add triangle */
|
/* Add triangle */
|
||||||
if (args.geom_input->manip.process_next_triangle_func != NULL) {
|
(*(geom_input->manip.process_next_triangle_func))(geom_input, &triangle, attr_byte_count);
|
||||||
(*(args.geom_input->manip.process_next_triangle_func))(args.geom_input,
|
|
||||||
&triangle,
|
|
||||||
attribute_byte_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer_offset += FOUG_STLB_TRIANGLE_SIZE;
|
buffer_offset += FOUG_STLB_TRIANGLE_SIZE;
|
||||||
} /* end for */
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int foug_stlb_read(foug_stlb_read_args_t args)
|
||||||
|
{
|
||||||
|
uint8_t buffer[8192];
|
||||||
|
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
||||||
|
uint32_t total_facet_count;
|
||||||
|
size_t buffer_facet_count;
|
||||||
|
size_t accum_facet_count_read;
|
||||||
|
int error;
|
||||||
|
size_t facet_count_read;
|
||||||
|
|
||||||
|
if (args.geom_input == NULL)
|
||||||
|
return FOUG_STLB_READ_NULL_GEOM_INPUT_ERROR;
|
||||||
|
if (args.stream == NULL)
|
||||||
|
return FOUG_STLB_READ_NULL_STREAM_ERROR;
|
||||||
|
/* if (args.buffer_size == 0)
|
||||||
|
return FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR;*/
|
||||||
|
|
||||||
|
/* Read header */
|
||||||
|
if (foug_stream_read(args.stream, header_data, 1, FOUG_STLB_HEADER_SIZE) != FOUG_STLB_HEADER_SIZE)
|
||||||
|
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
||||||
|
|
||||||
|
if (args.geom_input->manip.process_header_func != NULL)
|
||||||
|
(*(args.geom_input->manip.process_header_func))(args.geom_input, header_data);
|
||||||
|
|
||||||
|
/* Read facet count */
|
||||||
|
if (foug_stream_read(args.stream, buffer, sizeof(uint32_t), 1) != 1)
|
||||||
|
return FOUG_STLB_READ_FACET_COUNT_ERROR;
|
||||||
|
|
||||||
|
total_facet_count = foug_decode_uint32_le(buffer);
|
||||||
|
if (args.geom_input->manip.begin_triangles_func != NULL)
|
||||||
|
(*(args.geom_input->manip.begin_triangles_func))(args.geom_input, total_facet_count);
|
||||||
|
|
||||||
|
foug_task_control_reset(args.task_control);
|
||||||
|
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)total_facet_count);
|
||||||
|
|
||||||
|
/* Read triangles */
|
||||||
|
buffer_facet_count = 163;
|
||||||
|
accum_facet_count_read = 0;
|
||||||
|
error = FOUG_STLB_READ_NO_ERROR;
|
||||||
|
while (foug_stlb_no_error(error) && accum_facet_count_read < total_facet_count) {
|
||||||
|
facet_count_read = foug_stream_read(args.stream,
|
||||||
|
buffer, FOUG_STLB_TRIANGLE_SIZE, buffer_facet_count);
|
||||||
|
if (foug_stream_error(args.stream) != 0)
|
||||||
|
error = FOUG_STLB_READ_STREAM_ERROR;
|
||||||
|
else if (facet_count_read > 0)
|
||||||
|
error = FOUG_STLB_READ_NO_ERROR;
|
||||||
|
else
|
||||||
|
break; /* Exit if no facet to read */
|
||||||
|
|
||||||
|
if (foug_stlb_no_error(error)) {
|
||||||
|
foug_stlb_read_facets(args.geom_input, buffer, facet_count_read);
|
||||||
accum_facet_count_read += facet_count_read;
|
accum_facet_count_read += facet_count_read;
|
||||||
if (foug_task_control_is_stop_requested(args.task_control)) {
|
if (foug_task_control_is_stop_requested(args.task_control)) {
|
||||||
error = FOUG_STLB_READ_TASK_STOPPED_ERROR;
|
error = FOUG_STLB_READ_TASK_STOPPED_ERROR;
|
||||||
|
@ -13,9 +13,11 @@ foug_stlb_geom_output_t* foug_stlb_geom_output_create(foug_malloc_func_t func,
|
|||||||
void* data,
|
void* data,
|
||||||
foug_stlb_geom_output_manip_t manip)
|
foug_stlb_geom_output_manip_t manip)
|
||||||
{
|
{
|
||||||
|
foug_stlb_geom_output_t* geom;
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
foug_stlb_geom_output_t* geom = (*func)(sizeof(struct _internal_foug_stlb_geom_output));
|
geom = (*func)(sizeof(struct _internal_foug_stlb_geom_output));
|
||||||
if (geom != NULL) {
|
if (geom != NULL) {
|
||||||
geom->cookie = data;
|
geom->cookie = data;
|
||||||
geom->manip = manip;
|
geom->manip = manip;
|
||||||
@ -35,6 +37,14 @@ static foug_bool_t foug_stlb_no_error(int code)
|
|||||||
|
|
||||||
int foug_stlb_write(foug_stlb_write_args_t args)
|
int foug_stlb_write(foug_stlb_write_args_t args)
|
||||||
{
|
{
|
||||||
|
uint8_t buffer[128];
|
||||||
|
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
||||||
|
uint32_t facet_count;
|
||||||
|
foug_stl_triangle_t triangle;
|
||||||
|
uint16_t attr_byte_count;
|
||||||
|
uint32_t i_facet;
|
||||||
|
int error;
|
||||||
|
|
||||||
if (args.geom_output == NULL)
|
if (args.geom_output == NULL)
|
||||||
return FOUG_STLB_WRITE_NULL_GEOM_OUTPUT_ERROR;
|
return FOUG_STLB_WRITE_NULL_GEOM_OUTPUT_ERROR;
|
||||||
if (args.stream == NULL)
|
if (args.stream == NULL)
|
||||||
@ -46,10 +56,7 @@ int foug_stlb_write(foug_stlb_write_args_t args)
|
|||||||
if (args.geom_output->manip.get_triangle_func == NULL)
|
if (args.geom_output->manip.get_triangle_func == NULL)
|
||||||
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC;
|
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC;
|
||||||
|
|
||||||
uint8_t buffer[128];
|
|
||||||
|
|
||||||
/* Write header */
|
/* Write header */
|
||||||
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
|
||||||
if (args.geom_output->manip.get_header_func != NULL)
|
if (args.geom_output->manip.get_header_func != NULL)
|
||||||
(*(args.geom_output->manip.get_header_func))(args.geom_output, header_data);
|
(*(args.geom_output->manip.get_header_func))(args.geom_output, header_data);
|
||||||
else
|
else
|
||||||
@ -59,7 +66,7 @@ int foug_stlb_write(foug_stlb_write_args_t args)
|
|||||||
return FOUG_STLB_WRITE_STREAM_ERROR;
|
return FOUG_STLB_WRITE_STREAM_ERROR;
|
||||||
|
|
||||||
/* Write facet count */
|
/* Write facet count */
|
||||||
const uint32_t facet_count = (*(args.geom_output->manip.get_triangle_count_func))(args.geom_output);
|
facet_count = (*(args.geom_output->manip.get_triangle_count_func))(args.geom_output);
|
||||||
foug_encode_uint32_le(facet_count, buffer);
|
foug_encode_uint32_le(facet_count, buffer);
|
||||||
if (foug_stream_write(args.stream, buffer, sizeof(uint32_t), 1) != 1)
|
if (foug_stream_write(args.stream, buffer, sizeof(uint32_t), 1) != 1)
|
||||||
return FOUG_STLB_WRITE_STREAM_ERROR;
|
return FOUG_STLB_WRITE_STREAM_ERROR;
|
||||||
@ -68,10 +75,8 @@ int foug_stlb_write(foug_stlb_write_args_t args)
|
|||||||
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)facet_count);
|
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)facet_count);
|
||||||
|
|
||||||
/* Write triangles */
|
/* Write triangles */
|
||||||
foug_stl_triangle_t triangle;
|
attr_byte_count = 0;
|
||||||
uint16_t attr_byte_count = 0;
|
error = FOUG_STLB_WRITE_NO_ERROR;
|
||||||
uint32_t i_facet;
|
|
||||||
int error = FOUG_STLB_WRITE_NO_ERROR;
|
|
||||||
for (i_facet = 0; i_facet < facet_count && foug_stlb_no_error(error); ++i_facet) {
|
for (i_facet = 0; i_facet < facet_count && foug_stlb_no_error(error); ++i_facet) {
|
||||||
(*(args.geom_output->manip.get_triangle_func))(args.geom_output, i_facet,
|
(*(args.geom_output->manip.get_triangle_func))(args.geom_output, i_facet,
|
||||||
&triangle, &attr_byte_count);
|
&triangle, &attr_byte_count);
|
||||||
|
@ -12,9 +12,11 @@ struct _internal_foug_stream
|
|||||||
|
|
||||||
foug_stream_t* foug_stream_create(foug_malloc_func_t func, void* data, foug_stream_manip_t manip)
|
foug_stream_t* foug_stream_create(foug_malloc_func_t func, void* data, foug_stream_manip_t manip)
|
||||||
{
|
{
|
||||||
|
foug_stream_t* stream;
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
foug_stream_t* stream = (*func)(sizeof(struct _internal_foug_stream));
|
stream = (*func)(sizeof(struct _internal_foug_stream));
|
||||||
if (stream != NULL) {
|
if (stream != NULL) {
|
||||||
stream->cookie = data;
|
stream->cookie = data;
|
||||||
stream->manip = manip;
|
stream->manip = manip;
|
||||||
|
@ -21,10 +21,12 @@ struct _internal_foug_task_control
|
|||||||
foug_task_control_t* foug_task_control_create(foug_malloc_func_t func,
|
foug_task_control_t* foug_task_control_create(foug_malloc_func_t func,
|
||||||
void* data, foug_task_control_manip_t manip)
|
void* data, foug_task_control_manip_t manip)
|
||||||
{
|
{
|
||||||
|
foug_task_control_t* ctrl;
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
foug_task_control_t* ctrl = (*func)(sizeof(struct _internal_foug_task_control));
|
ctrl = (*func)(sizeof(struct _internal_foug_task_control));
|
||||||
if (ctrl != 0) {
|
if (ctrl != 0) {
|
||||||
ctrl->range_min = -1.;
|
ctrl->range_min = -1.;
|
||||||
ctrl->range_max = -2.;
|
ctrl->range_max = -2.;
|
||||||
@ -86,8 +88,7 @@ foug_real32_t foug_task_control_get_progress_as_pc(const foug_task_control_t* ct
|
|||||||
{
|
{
|
||||||
if (ctrl == NULL)
|
if (ctrl == NULL)
|
||||||
return 0.;
|
return 0.;
|
||||||
const foug_real32_t result = (ctrl->progress_value - ctrl->range_min) / ctrl->range_length;
|
return fabs((ctrl->progress_value - ctrl->range_min) / ctrl->range_length);
|
||||||
return fabs(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_real32_t foug_task_control_get_progress(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_progress(const foug_task_control_t* ctrl)
|
||||||
|
Loading…
Reference in New Issue
Block a user