From f64a9899765c7fe247a6111b8f061d39f907af74 Mon Sep 17 00:00:00 2001 From: sbaer Date: Thu, 11 Oct 2018 16:00:48 -0700 Subject: [PATCH] tweaks for linux compile --- opennurbs_defines.cpp | 171 +++++++++++++++++----------------- opennurbs_file_utilities.cpp | 174 +++++++++++++++++------------------ opennurbs_locale.cpp | 82 ++++++++--------- opennurbs_string_format.cpp | 81 +++++++++++----- opennurbs_string_scan.cpp | 10 +- opennurbs_subd_heap.cpp | 37 ++++---- opennurbs_system.h | 2 +- opennurbs_uuid.cpp | 123 +++++++++++++------------ 8 files changed, 362 insertions(+), 318 deletions(-) diff --git a/opennurbs_defines.cpp b/opennurbs_defines.cpp index f3d9494f..9f732494 100644 --- a/opennurbs_defines.cpp +++ b/opennurbs_defines.cpp @@ -8,7 +8,7 @@ // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF // MERCHANTABILITY ARE HEREBY DISCLAIMED. -// +// // For complete openNURBS copyright information see . // //////////////////////////////////////////////////////////////// @@ -19,7 +19,7 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -27,13 +27,13 @@ #include "opennurbs_internal_defines.h" // {EA2EFFD2-C9A9-4cb1-BE15-D2F46290F1A1} -//const ON_UUID ON_MaterialRef::material_from_layer = +//const ON_UUID ON_MaterialRef::material_from_layer = //{ 0xea2effd2, 0xc9a9, 0x4cb1, { 0xbe, 0x15, 0xd2, 0xf4, 0x62, 0x90, 0xf1, 0xa1 } }; // {86EDFDE4-8AAF-4bcd-AB7C-F7111978D7FE} -//const ON_UUID ON_MaterialRef::material_from_parent = +//const ON_UUID ON_MaterialRef::material_from_parent = //{ 0x86edfde4, 0x8aaf, 0x4bcd, { 0xab, 0x7c, 0xf7, 0x11, 0x19, 0x78, 0xd7, 0xfe } }; @@ -56,9 +56,9 @@ char* on_strupr(char* s) #if defined(ON_RUNTIME_WIN) return _strupr(s); // ANSI name #else - if (s) + if (s) { - while (*s) + while (*s) { *s = toupper(*s); s++; @@ -157,10 +157,10 @@ int on_WideCharToMultiByte( { // 14 March 2011 Dale Lear // It turns out that Windows WideCharToMultiByte does correctly - // convert UTF-16 to UTF-8 in Windows 7 when the code page + // convert UTF-16 to UTF-8 in Windows 7 when the code page // is CP_ACP and calls with CP_UTF8 sometimes fail to do // any conversion. So, I wrote ON_ConvertWideCharToUTF8() - // and opennurbs will use ON_ConvertWideCharToUTF8 to get + // and opennurbs will use ON_ConvertWideCharToUTF8 to get // consistent results on all platforms. unsigned int error_status = 0; unsigned int error_mask = 0xFFFFFFFF; @@ -184,10 +184,10 @@ int on_MultiByteToWideChar( { // 14 March 2011 Dale Lear // It turns out that Windows WideCharToMultiByte does not correctly - // convert UTF-8 to UTF-16 in Windows 7 when the code page + // convert UTF-8 to UTF-16 in Windows 7 when the code page // is CP_ACP and calls with CP_UTF8 sometimes fail to do // any conversion. So, I wrote ON_ConvertUTF8ToWideChar() - // and opennurbs will use ON_ConvertUTF8ToWideChar to get + // and opennurbs will use ON_ConvertUTF8ToWideChar to get // consistent results on all platforms. unsigned int error_status = 0; unsigned int error_mask = 0xFFFFFFFF; @@ -210,9 +210,9 @@ void on_splitpath( const char** ext ) { - // The "const char* path" parameter is a UTF-8 encoded string. - // Since the unicode code point values for the characters we - // are searching for ( '/' '\' '.' ':' A-Z a-z) are all > 0 + // The "const char* path" parameter is a UTF-8 encoded string. + // Since the unicode code point values for the characters we + // are searching for ( '/' '\' '.' ':' A-Z a-z) are all > 0 // and < 128, we can simply check for an array element having // the character value and not have to worry about dealing // with UTF-8 continuation values (>= 128). @@ -251,11 +251,11 @@ void on_splitpath( } } else if ( - ON_String::Backslash == path[0] + ON_String::Backslash == path[0] && ON_String::Backslash == path[1] - &&( (path[2] >= 'A' && path[2] <= 'Z') - || (path[2] >= 'a' && path[2] <= 'z') - || (path[2] >= '0' && path[2] <= '9') + &&( (path[2] >= 'A' && path[2] <= 'Z') + || (path[2] >= 'a' && path[2] <= 'z') + || (path[2] >= '0' && path[2] <= '9') ) ) { @@ -288,7 +288,7 @@ void on_splitpath( while ( 0 != *s1 ) s1++; s = (s1 > path) ? s1 - 1 : path; - + while ( s > path && '.' != *s && slash1 != *s && slash2 != *s ) s--; @@ -305,7 +305,7 @@ void on_splitpath( if ( s >= path && s < s1 ) { - if (slash1 == *s || slash2 == *s ) + if (slash1 == *s || slash2 == *s ) { if ( s+1 < s1 ) f = s+1; @@ -344,9 +344,9 @@ void on_wsplitpath( ) { // The "const wchar_t* path" parameter is a UTF-8, UTF-16 or UTF-32 - // encoded string. Since the unicode code point values for the + // encoded string. Since the unicode code point values for the // characters we are searching for ( '/' '\' '.' ':' A-Z a-z) are - // all > 0 and < 128, we can simply check for an array element + // all > 0 and < 128, we can simply check for an array element // having the character value and not have to worry about dealing // with UTF-16 surrogate pair values (0xD800-0xDBFF and DC00-DFFF) // and UTF-8 continuation values (>= 128). @@ -385,11 +385,11 @@ void on_wsplitpath( } } else if ( - ON_wString::Backslash == path[0] + ON_wString::Backslash == path[0] && ON_wString::Backslash == path[1] - &&( (path[2] >= 'A' && path[2] <= 'Z') - || (path[2] >= 'a' && path[2] <= 'z') - || (path[2] >= '0' && path[2] <= '9') + &&( (path[2] >= 'A' && path[2] <= 'Z') + || (path[2] >= 'a' && path[2] <= 'z') + || (path[2] >= '0' && path[2] <= '9') ) ) { @@ -422,7 +422,7 @@ void on_wsplitpath( while ( 0 != *s1 ) s1++; s = (s1 > path) ? s1 - 1 : path; - + while ( s > path && '.' != *s && slash1 != *s && slash2 != *s ) s--; @@ -439,7 +439,7 @@ void on_wsplitpath( if ( s >= path && s < s1 ) { - if (slash1 == *s || slash2 == *s ) + if (slash1 == *s || slash2 == *s ) { if ( s+1 < s1 ) f = s+1; @@ -503,7 +503,7 @@ int ON::CloseAllFiles() //fcloseall is not supported on OS X return EOF; #elif defined(ON_COMPILER_GNU) -#error TODO - call gcc fcloseall() + fcloseall(); #else // I can't find an fcloseall() or _fcloseall() in // gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) @@ -806,9 +806,9 @@ ON::LengthUnitSystem ON::ModelLengthUnitSystem( ON__UINT_PTR model_serial_number ) { - return - (nullptr == Internal_func_ModelLengthUnitSystemCallback - || 0 == model_serial_number + return + (nullptr == Internal_func_ModelLengthUnitSystemCallback + || 0 == model_serial_number || model_serial_number >= ON_UNSET_UINT_INDEX ) ? ON::LengthUnitSystem::None @@ -844,12 +844,12 @@ double ON::AngleUnitScale( // the default cases are here to keep lint quiet double scale = 1.0; - + if ( us_from != us_to && ((int)us_to) > 0 && ((int)us_to) < 6 // switch weeds out bogus values of us_from - ) - switch( us_from ) + ) + switch( us_from ) { case ON::AngleUnitSystem::Turns: switch(us_to) @@ -1006,7 +1006,7 @@ double ON::AngleUnitScale( double ON::UnitScale( - const class ON_3dmUnitsAndTolerances& u_and_t_from, + const class ON_3dmUnitsAndTolerances& u_and_t_from, const class ON_3dmUnitsAndTolerances& u_and_t_to ) { @@ -1020,7 +1020,7 @@ double ON::UnitScale( { ON::LengthUnitSystem us1 = us_to.UnitSystem(); if ( - ON::LengthUnitSystem::Unset == us_from + ON::LengthUnitSystem::Unset == us_from || ON::LengthUnitSystem::Unset == us1 || us_from != ON::LengthUnitSystemFromUnsigned(static_cast(us_from)) || us1 != ON::LengthUnitSystemFromUnsigned(static_cast(us1)) @@ -1045,7 +1045,7 @@ double ON::UnitScale( } double scale = 1.0; - if ( ON::LengthUnitSystem::CustomUnits == us1 + if ( ON::LengthUnitSystem::CustomUnits == us1 && ON::LengthUnitSystem::None != us_from && ON::LengthUnitSystem::CustomUnits != us_from ) @@ -1061,7 +1061,7 @@ double ON::UnitScale( } double ON::UnitScale( - const class ON_UnitSystem& us_from, + const class ON_UnitSystem& us_from, ON::LengthUnitSystem us_to ) { @@ -1091,7 +1091,7 @@ double ON::UnitScale( return 1.0; double scale = 1.0; - if ( ON::LengthUnitSystem::CustomUnits == us0 + if ( ON::LengthUnitSystem::CustomUnits == us0 && ON::LengthUnitSystem::None != us_to && ON::LengthUnitSystem::CustomUnits != us_to ) @@ -1107,7 +1107,7 @@ double ON::UnitScale( } double ON::UnitScale( - const class ON_UnitSystem& u_and_t_from, + const class ON_UnitSystem& u_and_t_from, const class ON_UnitSystem& u_and_t_to ) { @@ -1137,8 +1137,8 @@ double ON::UnitScale( if (meters_per_unit_from == meters_per_unit_to) return 1.0; double scale = 1.0; - if ( ON::LengthUnitSystem::CustomUnits == us_from - && meters_per_unit_from > 0.0 + if ( ON::LengthUnitSystem::CustomUnits == us_from + && meters_per_unit_from > 0.0 && meters_per_unit_from < ON_UNSET_POSITIVE_VALUE ) { @@ -1146,9 +1146,9 @@ double ON::UnitScale( us_from = ON::LengthUnitSystem::Meters; } - if ( ON::LengthUnitSystem::CustomUnits == us_to - && meters_per_unit_to > 0.0 - && meters_per_unit_to < ON_UNSET_POSITIVE_VALUE + if ( ON::LengthUnitSystem::CustomUnits == us_to + && meters_per_unit_to > 0.0 + && meters_per_unit_to < ON_UNSET_POSITIVE_VALUE ) { scale *= meters_per_unit_to; @@ -1180,10 +1180,10 @@ double ON::UnitScale( ) { // Scale factor for changing unit systems - // Examples - // 100.0 = UnitScale( ON::LengthUnitSystem::Meters, ON::LengthUnitSystem::Centimeters ) - // 2.54 = UnitScale( ON::LengthUnitSystem::Inches, ON::LengthUnitSystem::Centimeters ) - // 12.0 = UnitScale( ON::LengthUnitSystem::Feet, ON::LengthUnitSystem::Inches ) + // Examples + // 100.0 = UnitScale( ON::LengthUnitSystem::Meters, ON::LengthUnitSystem::Centimeters ) + // 2.54 = UnitScale( ON::LengthUnitSystem::Inches, ON::LengthUnitSystem::Centimeters ) + // 12.0 = UnitScale( ON::LengthUnitSystem::Feet, ON::LengthUnitSystem::Inches ) if (ON::LengthUnitSystem::Unset == u0 || ON::LengthUnitSystem::Unset == u1) { @@ -1219,7 +1219,7 @@ double ON::UnitScale( // the default cases are here to keep lint quiet double scale = 1.0; - switch( u0 ) + switch( u0 ) { case ON::LengthUnitSystem::Angstroms: scale = UnitScale( ON::LengthUnitSystem::Meters, u1)*1.0e-10; @@ -1234,7 +1234,7 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Millimeters: - switch( u1 ) + switch( u1 ) { case ON::LengthUnitSystem::Meters: scale = 1.0e-3; break; case ON::LengthUnitSystem::Microns: scale = 1.0e+3; break; @@ -1249,7 +1249,7 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Centimeters: - switch( u1 ) + switch( u1 ) { case ON::LengthUnitSystem::Meters: scale = 1.0e-2; break; case ON::LengthUnitSystem::Millimeters: scale = 1.0e+1; break; @@ -1269,7 +1269,7 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Meters: - switch( u1 ) + switch( u1 ) { case ON::LengthUnitSystem::Angstroms: scale = 1.0e+10; break; case ON::LengthUnitSystem::Nanometers: scale = 1.0e+9; break; @@ -1327,7 +1327,7 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Inches: - switch( u1 ) + switch( u1 ) { case ON::LengthUnitSystem::Angstroms: scale = 2.54e+8; break; case ON::LengthUnitSystem::Nanometers: scale = 2.54e+7; break; @@ -1358,8 +1358,8 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Feet: - switch( u1 ) - { + switch( u1 ) + { case ON::LengthUnitSystem::Yards: scale = 1.0/3.0; break; @@ -1373,8 +1373,8 @@ double ON::UnitScale( break; case ON::LengthUnitSystem::Yards: - switch( u1 ) - { + switch( u1 ) + { case ON::LengthUnitSystem::Feet: scale = 3.0; break; case ON::LengthUnitSystem::Miles: scale = 1.0/1760.0; break; default: @@ -1410,8 +1410,8 @@ double ON::UnitScale( case ON::LengthUnitSystem::AstronomicalUnits: // 1.4959787e+11 http://en.wikipedia.org/wiki/Astronomical_unit - // 1.495979e+11 http://units.nist.gov/Pubs/SP811/appenB9.htm - // An astronomical unit (au) is the mean distance from the + // 1.495979e+11 http://units.nist.gov/Pubs/SP811/appenB9.htm + // An astronomical unit (au) is the mean distance from the // center of the earth to the center of the sun. scale = UnitScale( ON::LengthUnitSystem::Meters, u1 )*1.4959787e+11; break; @@ -1421,14 +1421,14 @@ double ON::UnitScale( // 9.46073e+15 meters http://units.nist.gov/Pubs/SP811/appenB9.htm // A light year is the distance light travels in one Julian year. // The speed of light is exactly 299792458 meters/second. - // A Julian year is exactly 365.25 * 86400 seconds and is + // A Julian year is exactly 365.25 * 86400 seconds and is // approximately the time it takes for one earth orbit. scale = UnitScale( ON::LengthUnitSystem::Meters, u1 )*9.4607304725808e+15; break; case ON::LengthUnitSystem::Parsecs: // 3.08567758e+16 // http://en.wikipedia.org/wiki/Parsec - // 3.085678e+16 // http://units.nist.gov/Pubs/SP811/appenB9.htm + // 3.085678e+16 // http://units.nist.gov/Pubs/SP811/appenB9.htm scale = UnitScale( ON::LengthUnitSystem::Meters, u1 )*3.08567758e+16; break; @@ -1449,7 +1449,7 @@ double ON::UnitScale( ON::OBSOLETE_DistanceDisplayMode ON::DistanceDisplayModeFromUnsigned(unsigned int distance_display_mode_as_unsigned) { - switch (distance_display_mode_as_unsigned) + switch (distance_display_mode_as_unsigned) { ON_ENUM_FROM_UNSIGNED_CASE(ON::OBSOLETE_DistanceDisplayMode::Decimal); ON_ENUM_FROM_UNSIGNED_CASE(ON::OBSOLETE_DistanceDisplayMode::Fractional); @@ -1501,7 +1501,7 @@ ON::continuity ON::Continuity(int i) case (int)ON::continuity::C2_continuous: c = ON::continuity::C2_continuous; break; case (int)ON::continuity::G1_continuous: c = ON::continuity::G1_continuous; break; case (int)ON::continuity::G2_continuous: c = ON::continuity::G2_continuous; break; - + // 30 March 2003 Dale Lear added these case (int)ON::continuity::C0_locus_continuous: c = ON::continuity::C0_locus_continuous; break; case (int)ON::continuity::C1_locus_continuous: c = ON::continuity::C1_locus_continuous; break; @@ -1591,7 +1591,7 @@ ON::surface_style ON::SurfaceStyle(int i) { //convertintegertosurface_styleenum surface_style ss = unknown_surface_style; - + switch (i) { case plane: ss = plane; break; case circular_cylinder: ss = circular_cylinder; break; @@ -1611,7 +1611,7 @@ ON::surface_style ON::SurfaceStyle(int i) ON::sort_algorithm ON::SortAlgorithm(int i) { sort_algorithm sa = ON::sort_algorithm::quick_sort; - + switch (i) { case (int)ON::sort_algorithm::heap_sort: sa = ON::sort_algorithm::heap_sort; break; case (int)ON::sort_algorithm::quick_sort: sa = ON::sort_algorithm::quick_sort; break; @@ -1655,7 +1655,7 @@ ON::view_projection ON::ViewProjection(int i) { // convert integer to view_projection enum view_projection v = ON::unknown_view; - switch(i) + switch(i) { case ON::parallel_view: v = ON::parallel_view; break; case ON::perspective_view: v = ON::perspective_view; break; @@ -1730,7 +1730,7 @@ ON::object_color_source ON::ObjectColorSource(int i) { // convert integer to object_mode enum ON::object_color_source cs = color_from_layer; - switch (i) + switch (i) { case color_from_layer: // use color assigned to layer cs = color_from_layer; @@ -1752,7 +1752,7 @@ ON::plot_color_source ON::PlotColorSource(int i) { // convert integer to object_mode enum ON::plot_color_source cs = plot_color_from_layer; - switch (i) + switch (i) { case plot_color_from_layer: cs = plot_color_from_layer; @@ -1760,7 +1760,7 @@ ON::plot_color_source ON::PlotColorSource(int i) case plot_color_from_object: cs = plot_color_from_object; break; - case plot_color_from_display: + case plot_color_from_display: cs = plot_color_from_display; break; case plot_color_from_parent: @@ -1851,11 +1851,11 @@ ON::curvature_style ON::CurvatureStyle(int i) case mean_curvature: cs = mean_curvature; break; - case min_curvature: + case min_curvature: // minimum unsigned radius of curvature cs = min_curvature; break; - case max_curvature: + case max_curvature: // maximum unsigned radius of curvature cs = max_curvature; break; @@ -1879,7 +1879,7 @@ ON::curvature_style ON::CurvatureStyle(int i) { model_view_type = 0, plot_page_view_type = 1, - nested_view_type = 2 + nested_view_type = 2 };*/ ON::view_type ON::ViewType(int vt) @@ -1909,7 +1909,7 @@ ON::v3_display_mode ON::V3DisplayMode(int i) case ON::v3_shaded_display: dm = ON::v3_shaded_display; break; - case ON::v3_renderpreview_display: + case ON::v3_renderpreview_display: dm = ON::v3_renderpreview_display; break; } @@ -1942,7 +1942,7 @@ ON::object_type ON::ObjectType(int i) { // convert integer to object_type enum object_type ot = ON::object_type::unknown_object_type; - switch(i) + switch(i) { case ON::object_type::unknown_object_type: ot = ON::object_type::unknown_object_type; break; @@ -2095,7 +2095,7 @@ ON::mesh_type ON::MeshType(int i) ON_INTERNAL_OBSOLETE::V5_eAnnotationType ON_INTERNAL_OBSOLETE::V5AnnotationTypeFromUnsigned(unsigned int v5_annotation_type_as_unsigned) { // convert integer to eAnnotationType enum - switch(v5_annotation_type_as_unsigned) + switch(v5_annotation_type_as_unsigned) { ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_eAnnotationType::dtNothing); ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_eAnnotationType::dtDimLinear); @@ -2194,30 +2194,30 @@ ON::TextVerticalAlignment ON_INTERNAL_OBSOLETE::V6VerticalAlignmentFromV5Vertica switch (V5_vertical_alignment) { case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Centered: - valign = ON::TextVerticalAlignment::Middle; + valign = ON::TextVerticalAlignment::Middle; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Above: // V5 text "above" dim line means "bottom" of text bbox is at insertion point above dim line - valign = ON::TextVerticalAlignment::Bottom; + valign = ON::TextVerticalAlignment::Bottom; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Below: // V5 text "below" dim line means "top" of text bbox is at insertion point below dim line - valign = ON::TextVerticalAlignment::Top; + valign = ON::TextVerticalAlignment::Top; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Top: - valign = ON::TextVerticalAlignment::Top; + valign = ON::TextVerticalAlignment::Top; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::FirstLine: - valign = ON::TextVerticalAlignment::MiddleOfTop; + valign = ON::TextVerticalAlignment::MiddleOfTop; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Middle: - valign = ON::TextVerticalAlignment::Middle; + valign = ON::TextVerticalAlignment::Middle; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::LastLine: - valign = ON::TextVerticalAlignment::MiddleOfBottom; + valign = ON::TextVerticalAlignment::MiddleOfBottom; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Bottom: - valign = ON::TextVerticalAlignment::Bottom; + valign = ON::TextVerticalAlignment::Bottom; break; case ON_INTERNAL_OBSOLETE::V5_vertical_alignment::Underlined: valign = ON::TextVerticalAlignment::BottomOfBoundingBox; @@ -2260,7 +2260,7 @@ ON_INTERNAL_OBSOLETE::V5_horizontal_alignment ON_INTERNAL_OBSOLETE::V5Horizontal case ON::TextHorizontalAlignment::Right: halign = ON_INTERNAL_OBSOLETE::V5_horizontal_alignment::Right; break; - } + } return halign; } @@ -2504,4 +2504,3 @@ ON_4udex::ON_4udex( , k(kValue) , l(lValue) {} - diff --git a/opennurbs_file_utilities.cpp b/opennurbs_file_utilities.cpp index d8b1307c..4ae71983 100644 --- a/opennurbs_file_utilities.cpp +++ b/opennurbs_file_utilities.cpp @@ -7,7 +7,7 @@ // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF // MERCHANTABILITY ARE HEREBY DISCLAIMED. -// +// // For complete openNURBS copyright information see . // //////////////////////////////////////////////////////////////// @@ -18,19 +18,19 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif #if defined(ON_COMPILER_MSC) && defined(ON_RUNTIME_WIN) // November 2015: Visual Studo 2013 (and probably others) -// Shlwapi.h and Shlobj.h are not included in opennurbs_system.h +// Shlwapi.h and Shlobj.h are not included in opennurbs_system.h // because the have gems like "#define small ..." (Thank You Microsoft!). -// Turns out there is plenty of code that uses opennurbs where crazy +// Turns out there is plenty of code that uses opennurbs where crazy // developers thought "small" would be a reasonable name for a local // variable. Reminds me of dealing with AutoDesk's old #define X 0 -// in their headers from 20 years ago. +// in their headers from 20 years ago. #pragma ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE #include #pragma ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE @@ -263,7 +263,7 @@ void ON_wString::SplitPath( ON_wString* ext ) { - ON_FileSystemPath::SplitPath( + ON_FileSystemPath::SplitPath( path, drive, dir, @@ -343,7 +343,7 @@ void ON_FileSystemPath::SplitPath( } -void ON_FileSystemPath::SplitPath( +void ON_FileSystemPath::SplitPath( const wchar_t* path, ON_wString* drive, ON_wString* dir, @@ -566,13 +566,13 @@ const ON_wString ON_FileSystemPath::CurrentDirectory( // TODO implement for Apple OS's ON_ERROR("ON_FileSystemPath::CurrentDirectory() not implemented."); - return ON_wString::EmptyString; + return ON_wString::EmptyString; #else // unsupported OS ON_ERROR("ON_FileSystemPath::CurrentDirectory() not implemented."); - return ON_wString::EmptyString; + return ON_wString::EmptyString; #endif } @@ -621,7 +621,7 @@ const ON_wString ON_FileSystemPath::RemoveFileName( const wchar_t* dir = nullptr; const wchar_t* fname = nullptr; on_wsplitpath(path, &vol, &dir, &fname, nullptr); - + const size_t length = (nullptr != fname && nullptr != path && path <= fname) ? (int)(fname - path) @@ -649,7 +649,7 @@ const ON_wString ON_FileSystemPath::CombinePaths( : ON_FileSystemPath::CleanPath(left_side); ON_wString rhs_fname; - ON_wString rhs + ON_wString rhs = bRightSideContainsFileName ? ON_FileSystemPath::RemoveFileName(right_side,&rhs_fname) : ON_FileSystemPath::CleanPath(right_side); @@ -665,10 +665,10 @@ const ON_wString ON_FileSystemPath::CombinePaths( } ON_wString path = lhs; - bool bPathEndsDirectorySeparator + bool bPathEndsDirectorySeparator = path.IsNotEmpty() && ON_FileSystemPath::IsDirectorySeparator(path[path.Length() - 1], true); - + if (rhs.IsNotEmpty()) { if (path.IsNotEmpty() && false == bPathEndsDirectorySeparator) @@ -678,7 +678,7 @@ const ON_wString ON_FileSystemPath::CombinePaths( if (lhs.IsNotEmpty() && ON_FileSystemPath::IsRelativePath(rhs)) path = ON_FileSystemPath::CleanPath(path); - bPathEndsDirectorySeparator + bPathEndsDirectorySeparator = path.IsNotEmpty() && ON_FileSystemPath::IsDirectorySeparator(path[path.Length() - 1], true); } @@ -692,7 +692,7 @@ const ON_wString ON_FileSystemPath::CombinePaths( { const wchar_t* vol = nullptr; const wchar_t* dir = nullptr; - // on_wsplitpath is called to avoid appending a directory separator to a + // on_wsplitpath is called to avoid appending a directory separator to a on_wsplitpath(static_cast(path), &vol, &dir, nullptr, nullptr); if (nullptr != dir && false == ON_FileSystemPath::IsDirectorySeparator(path[path.Length() - 1], true)) path += ON_FileSystemPath::DirectorySeparator; @@ -781,8 +781,8 @@ const ON_wString ON_FileSystemPath::CleanPath( dirty_path = local_dirty_path; - const bool bIsUNCHostName - = bAllowWindowsUNCHostNameOrDiskLetter + const bool bIsUNCHostName + = bAllowWindowsUNCHostNameOrDiskLetter && local_dirty_path.Length() >= 3 && ON_wString::Backslash == local_dirty_path[0] && ON_wString::Backslash == local_dirty_path[1] @@ -790,7 +790,7 @@ const ON_wString ON_FileSystemPath::CleanPath( && (IsAtoZ(local_dirty_path[2]) || Is0to9(local_dirty_path[2]) || local_dirty_path[2] > 127) ; - const bool bIsWindowsDrive + const bool bIsWindowsDrive = bAllowWindowsUNCHostNameOrDiskLetter && (false == bIsUNCHostName) && local_dirty_path.Length() >= 3 @@ -804,10 +804,10 @@ const ON_wString ON_FileSystemPath::CleanPath( if (bIsUNCHostName) { clean_start += 3; // skip \\ and first charater of host name - + // skip rest of host name while ( IsPermittedInHostName(*clean_start) ) - clean_start++; + clean_start++; if (false == IsDirSep(*clean_start)) return ON_wString_CleanPathFailed(); } @@ -912,7 +912,7 @@ const ON_wString ON_FileSystemPath::CleanPath( } if (IsDotDotDir(src + 1)) { - // replace dir/../ with ./ and recursively clean + // replace dir/../ with ./ and recursively clean dst = dir; dst[0] = '.'; dst[1] = src[3]; @@ -960,7 +960,7 @@ const ON_wString ON_FileSystemPath::CleanPath( return clean_path; } - // recursively clean + // recursively clean const ON_wString clean_tail = ON_FileSystemPath::CleanPath(false,false,false,false,0,clean_start); if (clean_head < clean_start) { @@ -1177,7 +1177,7 @@ bool ON_FileSystem::IsDirectoryWithWriteAccess( // The purpose of this function is to test if a file can be opened and // written to using the same tools that write .3dm files. // - // It is possible to have create and write permissions but not have + // It is possible to have create and write permissions but not have // read permissions. For this reason, we do not attempt to read the tmp file. break; } @@ -1186,11 +1186,11 @@ bool ON_FileSystem::IsDirectoryWithWriteAccess( // The purpose of this function is to test if a file can be opened and // written to using the same tools that write .3dm files. // - // There is speculation that when a directory is managed by dropbox - // or perhaps other network storage devices, there may be significant - // latency in the file systems that results in a time lag between calling + // There is speculation that when a directory is managed by dropbox + // or perhaps other network storage devices, there may be significant + // latency in the file systems that results in a time lag between calling // unlink() and having ON_FileSystem::IsFile() report false. - // For that reason, we do not check success codes on unlink + // For that reason, we do not check success codes on unlink // or verify the tmp file is gone. ON_FileSystem::RemoveFile(tmpfilename); } @@ -1225,7 +1225,7 @@ const ON_wString ON_FileSystemPath::FullPathFromRelativePath( return ON_wString::EmptyString; if (!(base_path < base_path_end)) return ON_wString::EmptyString; - + ON_wString dirty_full_path; dirty_full_path.Append(base_path,(int)(base_path_end - base_path)); if ( false == ON_FileSystemPath::IsDirectorySeparator(base_path_end[-1],true) ) @@ -1259,7 +1259,7 @@ static bool CleanAndRemoveFileName( if (nullptr == d || 0 == d[0]) break; - + clean_path = d; if (bPathIncludesFileName) @@ -1365,7 +1365,7 @@ const ON_wString ON_FileSystemPath::RelativePath( bool bBaseDirSep = IsDirSep(*base1); if (false == bFullDirSep && false == bBaseDirSep) { - // skipping an element of a directory name + // skipping an element of a directory name base1++; full1++; continue; @@ -1408,7 +1408,7 @@ const ON_wString ON_FileSystemPath::RelativePath( // It is reasonable for base_tail to be nullptr if (nullptr != base_tail && IsDirSep(*base_tail) ) return best_answer; - + // set dotdot_count to number of directories left in base_tail int dotdot_count = 0; while (0 != *base_tail) @@ -1461,7 +1461,7 @@ FILE* ON_FileStream::Open( const wchar_t* filename, const wchar_t* mode ) return fp; #if defined(ON_COMPILER_MSC) && defined(ON_RUNTIME_WIN) - errno_t e = _wfopen_s(&fp,filename,mode); + errno_t e = _wfopen_s(&fp,filename,mode); if ( 0 != e && 0 == fp ) fp = 0; // reference e to keep lint quiet. #else @@ -1483,7 +1483,7 @@ FILE* ON_FileStream::Open( const char* filename, const char* mode ) return fp; #if defined(ON_COMPILER_MSC) && defined(ON_RUNTIME_WIN) - errno_t e = fopen_s(&fp,filename,mode); + errno_t e = fopen_s(&fp,filename,mode); if ( 0 != e && 0 == fp ) fp = 0; // reference e to keep lint quiet. #else @@ -1633,7 +1633,7 @@ bool ON_FileSystemPath::IsValidFileName( if (file_name_length > 256) return false; - // note that all illegal symbols currently tested for have + // note that all illegal symbols currently tested for have // UNICODE code points <= U+07F, so we can simply test c const wchar_t c = file_name[file_name_length]; if (ON_FileSystemPath::IsDirectorySeparator(c, bAllPlatforms)) @@ -1654,7 +1654,7 @@ bool ON_FileSystemPath::IsValidFileName( #endif break; - //// Most windows apps have these restrictions, but the file system supports + //// Most windows apps have these restrictions, but the file system supports //// names with these characters. //// case ':': //// case '~': @@ -1675,7 +1675,7 @@ bool ON_FileSystemPath::IsValidFileName( //// if (bAllPlatforms) //// return false; ////#endif - //// + //// } prev_c = c; @@ -1687,7 +1687,7 @@ bool ON_FileSystemPath::IsValidFileName( if (1 == file_name_length) return false; if (2 == file_name_length && bDoubleDot) - return false; + return false; break; case '~': @@ -1750,7 +1750,7 @@ const ON_wString ON_FileSystemPath::PlatformPath( ON_FileSystemPath::PathId path #elif defined(ON_RUNTIME_APPLE_OBJECTIVE_C_AVAILABLE) NSArray *apple_paths = NSSearchPathForDirectoriesInDomains(platform_path_id, NSUserDomainMask, YES); - if ([apple_paths count] > 0) + if ([apple_paths count] > 0) { NSString* apple_path = [apple_paths objectAtIndex:0]; if ( nullptr != apple_path ) @@ -1789,7 +1789,7 @@ static unsigned int ON_Internal_SeekTo3DGeometryFileFormatMark( if (0 != ON_String::CompareOrdinal(tag, 24, buffer, 24, false)) { - // it's not a "pure" .3DM file + // it's not a "pure" .3DM file // - see if we have a .3DM file with MS OLE-goo at the start // (generally, there is around 6kb of goo. I keep looking // for up to 32mb just in case.) @@ -1930,7 +1930,7 @@ bool ON_FileStream::Seek( FILE* fp, ON__INT64 offset, int origin ) if ( 0 == offset && SEEK_CUR == origin ) return true; - + #if defined(ON_COMPILER_MSC) && defined(ON_RUNTIME_WIN) if (0 != _fseeki64(fp, offset, origin)) return false; @@ -2060,7 +2060,7 @@ bool ON_FileStream::GetFileInformation( return rc; } -bool ON_FileStream::GetFileInformation( +bool ON_FileStream::GetFileInformation( FILE* fp, ON__UINT64* file_size, ON__UINT64* file_metadata_last_modified_time, @@ -2083,18 +2083,18 @@ bool ON_FileStream::GetFileInformation( // Microsoft compilers #if (_MSC_VER >= 1400) - // VC 8 (2005) - // works for file sizes > 4GB + // VC 8 (2005) + // works for file sizes > 4GB // when size_t is a 64 bit integer struct _stat64 sb; memset(&sb,0,sizeof(sb)); - int fd = _fileno(fp); + int fd = _fileno(fp); int fstat_rc = _fstat64(fd, &sb); #else // VC6 compiler struct _stat sb; memset(&sb,0,sizeof(sb)); - int fd = _fileno(fp); + int fd = _fileno(fp); int fstat_rc = _fstat(fd, &sb); #endif @@ -2229,7 +2229,7 @@ static bool IsDotOrDotDotDir( const char* s ) return rc; } -bool ON_FileIterator::Initialize( +bool ON_FileIterator::Initialize( const wchar_t* directory_name ) { @@ -2237,8 +2237,8 @@ bool ON_FileIterator::Initialize( return Initialize(directory_name,item_name_filter); } -bool ON_FileIterator::Initialize( - const wchar_t* directory_name, +bool ON_FileIterator::Initialize( + const wchar_t* directory_name, const wchar_t* item_name_filter ) { @@ -2262,7 +2262,7 @@ bool ON_FileIterator::Initialize( return true; } -bool ON_FileIterator::Initialize( +bool ON_FileIterator::Initialize( const char* directory_name ) { @@ -2280,7 +2280,7 @@ bool ON_FileIterator::Initialize( return Initialize( static_cast(local_directory_name), static_cast(local_item_name_filter) - ); + ); } bool ON_FileIterator::FirstItem() @@ -2314,7 +2314,7 @@ bool ON_FileIterator::FirstItem() if (0 == item_name_filter) { - // A null file file_name_filter means iterate + // A null file file_name_filter means iterate // through all items in the directory. To do // this using Windows' ::FindFirstFile, set the // filter to "*.*", even though some items will @@ -2460,7 +2460,7 @@ bool ON_FileIterator::NextItem() // Only *.ext filters work at this time for non-windows const wchar_t* file_name_filter = m_impl->m_ws_file_name_filter; if ( 0 != file_name_filter - && '*' == file_name_filter[0] + && '*' == file_name_filter[0] && '.' == file_name_filter[1] && 0 != file_name_filter[2] && '*' != file_name_filter[2] ) @@ -2468,8 +2468,8 @@ bool ON_FileIterator::NextItem() // assume this is a *.extension filter const wchar_t* current_name_ext = 0; on_wsplitpath(current_name,0,0,0,¤t_name_ext); - if ( 0 == current_name_ext - || 0 != wcscmp(file_name_filter+1,current_name_ext) + if ( 0 == current_name_ext + || 0 != wcscmp(file_name_filter+1,current_name_ext) ) { // current_name does pass match file_name_filter @@ -2626,9 +2626,9 @@ ON__UINT64 ON_SecondsSinceJanOne1970UTC() #if defined(ON_COMPILER_MSC) __time64_t t = _time64(nullptr); - return (ON__UINT64)t; + return (ON__UINT64)t; -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) //__time64_t t = _time64(nullptr); time_t t = time(nullptr); @@ -2637,7 +2637,7 @@ ON__UINT64 ON_SecondsSinceJanOne1970UTC() #else __time64_t t = _time64(nullptr); - return (ON__UINT64)t; + return (ON__UINT64)t; #endif } @@ -2668,7 +2668,7 @@ const ON_wString SecondsSinceJanOne1970UTCToString( sec = uct.tm_sec; } -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) const time_t t = (time_t)seconds_since_epoch; const struct tm* ptr = gmtime( &t ); @@ -2723,7 +2723,7 @@ static ON__UINT64 SecondsSinceJanOne1970( FILETIME ft ) { // The FILETIME is in 100-nanosecond intervals since January 1, 1601 UCT. // - // Between midnight January 1, 1601 and midnight January 1, 1970 there + // Between midnight January 1, 1601 and midnight January 1, 1970 there // were 134774 days = 11644473600 seconds. Each second has 10^7 intervals // that are one hundred nanoseconds long. So, if N = number of one hundred // nanosecond intervals since midnight January 1, 1601, then @@ -2731,9 +2731,9 @@ static ON__UINT64 SecondsSinceJanOne1970( FILETIME ft ) // January 1, 1970. // // January 1, 1601 was the start of a Gregorian calendary 400 year cycle - // and "the internet" sometimes cites that as the reason that date is + // and "the internet" sometimes cites that as the reason that date is // the "beginning of time" for Windows' FILETIME values. This convention - // would slightly simplify the formulae used to account for leap years, + // would slightly simplify the formulae used to account for leap years, // so it is plausable this might might even be true. ON__UINT64 ft_since_jan_1_1601 = ft.dwHighDateTime; @@ -2743,7 +2743,7 @@ static ON__UINT64 SecondsSinceJanOne1970( FILETIME ft ) ON__UINT64 hundrednanoseconds_per_second = 10000000; ON__UINT64 seconds_since_jan_1_1601 = ft_since_jan_1_1601 / hundrednanoseconds_per_second; - + ON__UINT64 seconds_since_jan_1_1970 = seconds_since_jan_1_1601 - 11644473600; return seconds_since_jan_1_1970; @@ -2776,20 +2776,20 @@ ON_ContentHash ON_ContentHash::Create( ) { ON_ContentHash hash; - + if ( 0 == hash_time ) hash_time = ON_SecondsSinceJanOne1970UTC(); hash.m_byte_count = (byte_count > 0) ? byte_count : 0; hash.m_hash_time = hash_time; - - hash.m_content_time - = (content_last_modified_time <= hash_time) + + hash.m_content_time + = (content_last_modified_time <= hash_time) ? content_last_modified_time : 0; - + hash.m_sha1_name_hash = sha1_name_hash; - hash.m_sha1_content_hash + hash.m_sha1_content_hash = (hash.m_byte_count > 0) ? sha1_content_hash : ON_SHA1_Hash::EmptyContentHash @@ -2798,7 +2798,7 @@ ON_ContentHash ON_ContentHash::Create( return hash; } -ON_ContentHash ON_ContentHash::CreateFromBuffer( +ON_ContentHash ON_ContentHash::CreateFromBuffer( ON_SHA1_Hash sha1_name_hash, const void* buffer, size_t byte_count @@ -2811,7 +2811,7 @@ ON_ContentHash ON_ContentHash::CreateFromBuffer( return ON_ContentHash::Create(sha1_name_hash,hash_byte_count,sha1_content_hash,hash_time,content_last_modifed_time); } -ON_ContentHash ON_ContentHash::CreateFromFile( +ON_ContentHash ON_ContentHash::CreateFromFile( ON_SHA1_Hash sha1_file_name_hash, FILE* fp ) @@ -2829,7 +2829,7 @@ ON_ContentHash ON_ContentHash::CreateFromFile( } -ON_ContentHash ON_ContentHash::CreateFromFile( +ON_ContentHash ON_ContentHash::CreateFromFile( const wchar_t* filename ) { @@ -2840,7 +2840,7 @@ ON_ContentHash ON_ContentHash::CreateFromFile( return hash; } -ON_ContentHash ON_ContentHash::CreateFromFile( +ON_ContentHash ON_ContentHash::CreateFromFile( const char* filename ) { @@ -2936,7 +2936,7 @@ bool ON_ContentHash::IsSet() const { if ( 0 == m_hash_time ) return false; - return + return (0 == m_byte_count) ? (ON_SHA1_Hash::EmptyContentHash == m_sha1_content_hash) : (ON_SHA1_Hash::EmptyContentHash != m_sha1_content_hash); @@ -2976,7 +2976,7 @@ ON_SHA1_Hash ON_ContentHash::NameHash() const { return m_sha1_name_hash; } - + bool ON_ContentHash::IsSameBufferContent( const void* buffer, @@ -2987,21 +2987,21 @@ bool ON_ContentHash::IsSameBufferContent( } -bool ON_ContentHash::IsSameFileContent( +bool ON_ContentHash::IsSameFileContent( FILE* fp ) const { return ON_ContentHash::EqualContent(*this, ON_ContentHash::CreateFromFile(ON_SHA1_Hash::ZeroDigest,fp)); } -bool ON_ContentHash::IsSameFileContent( +bool ON_ContentHash::IsSameFileContent( const wchar_t* filename ) const { return ON_ContentHash::EqualContent(*this, ON_ContentHash::CreateFromFile(filename)); } -bool ON_ContentHash::IsSameFileContent( +bool ON_ContentHash::IsSameFileContent( const char* filename ) const { @@ -3096,12 +3096,12 @@ ON_ContentHash::CompareResult ON_ContentHash::Compare( if ( m_byte_count == file_content_hash.m_byte_count && m_sha1_content_hash == file_content_hash.m_sha1_content_hash ) return ON_ContentHash::CompareResult::EqualContent; const ON__UINT64 current_time = ON_SecondsSinceJanOne1970UTC(); - bool bValidTimes - = m_content_time > 0 - && m_hash_time >= m_content_time + bool bValidTimes + = m_content_time > 0 + && m_hash_time >= m_content_time && current_time >= m_hash_time - && file_content_hash.m_content_time > 0 - && file_content_hash.m_hash_time >= file_content_hash.m_content_time + && file_content_hash.m_content_time > 0 + && file_content_hash.m_hash_time >= file_content_hash.m_content_time && current_time >= file_content_hash.m_hash_time ; if (bValidTimes) @@ -3487,7 +3487,7 @@ ON_FileReference::FindFilePreference ON_FileReference::Internal_FindFile( base_path = local_base_path; } } - + // Clean up file preferences and append defaults ON_FileReference::FindFilePreference default_pref[] = @@ -3772,7 +3772,7 @@ bool ON_FileReference::Write( if (!archive.WriteString(full_path)) break; - const ON_wString relative_path + const ON_wString relative_path = (bBasePathIsEmpty || m_full_path.IsEmpty() ) ? m_relative_path : ON_FileSystemPath::RelativePath(m_full_path,true,base_path,bBasePathIncludesFileName); @@ -3835,13 +3835,13 @@ bool ON_FileReference::Read( break; if (!m_content_hash.Read(archive)) break; - + unsigned int full_path_status_as_unsigned = 0; if (!archive.ReadInt(&full_path_status_as_unsigned)) break; //m_full_path_status = ON_FileReference::StatusFromUnsigned(full_path_status_as_unsigned); // The full path status must be validated after each read. - m_full_path_status = ON_FileReference::Status::Unknown; + m_full_path_status = ON_FileReference::Status::Unknown; if (minor_version >= 1) { @@ -3913,7 +3913,7 @@ void ON_FileReference::SetFullPath( else if (bFullPathChanged) { m_content_hash = ON_ContentHash::Unset; - m_full_path_status + m_full_path_status = ON_FileSystem::IsFile(m_full_path) ? ON_FileReference::Status::FullPathValid : ON_FileReference::Status::FileNotFound; diff --git a/opennurbs_locale.cpp b/opennurbs_locale.cpp index 1f1a516b..fc5ec21d 100644 --- a/opennurbs_locale.cpp +++ b/opennurbs_locale.cpp @@ -8,7 +8,7 @@ // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF // MERCHANTABILITY ARE HEREBY DISCLAIMED. -// +// // For complete openNURBS copyright information see . // //////////////////////////////////////////////////////////////// @@ -19,7 +19,7 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -41,7 +41,7 @@ static ON_CRT_locale_t ON_CRT_C_locale() ON_C_locale = _create_locale(category, locale); #endif } - + return ON_C_locale; } @@ -64,8 +64,8 @@ static ON_CRT_locale_t ON_CRT_create_locale_ALL( const char * locale ) && ('X' == locale[4] || 'x' == locale[4]) && 0 == locale[5] ) - return ON_CRT_C_locale(); - + return ON_CRT_C_locale(); + #if defined(ON_RUNTIME_WIN) return _create_locale(LC_ALL, locale); #elif defined(ON_RUNTIME_APPLE) @@ -361,7 +361,7 @@ static bool ZeroWideBuffer( size_t sizeof_buffer_element ) { - bool rc + bool rc = (nullptr != buffer && buffer_capacity > 0 && sizeof_buffer_element > 0 ) || 0 == buffer_capacity; if (nullptr == buffer || buffer_capacity <= 0 || sizeof_buffer_element <= 0 ) @@ -382,7 +382,7 @@ static bool ZeroCharBuffer( size_t sizeof_buffer_element ) { - bool rc + bool rc = (nullptr != buffer && buffer_capacity > 0 && sizeof_buffer_element > 0 ) || 0 == buffer_capacity; if (nullptr == buffer || buffer_capacity <= 0 || sizeof_buffer_element <= 0 ) @@ -594,7 +594,7 @@ bool ON_Locale::ParseName( sname[i] = (char)w; } sname[locale_name_element_count] = 0; - + const size_t ON_S_CAPACITY = 64; char slanguage_code[ON_S_CAPACITY] = { 0 }; char sextlang_code[ON_S_CAPACITY] = { 0 }; @@ -806,7 +806,7 @@ ON_Locale ON_Locale::FromWindowsLCID( locale.m_windows_lcid = (ON__UINT32)windows_lcid; return locale; } - + #if defined(ON_RUNTIME_WIN) wchar_t wide_locale_name[LOCALE_NAME_MAX_LENGTH + 1] = { 0 }; @@ -906,7 +906,7 @@ ON_Locale ON_Locale::FromWindowsLCIDAndName( { return ON_Locale::InvariantCulture; } - + ON_Locale locale; locale.m_windows_lcid = windows_lcid; @@ -947,7 +947,7 @@ ON_Locale ON_Locale::FromWindowsLCIDAndName( ON_ERROR("Unable to create m_bcp47_language_tag."); return ON_Locale::Ordinal; } - + locale.m_numeric_locale = ON_CRT_C_locale(); locale.m_string_coll_map_locale = ON_CRT_create_locale_ALL( locale.m_bcp47_language_tag ); @@ -1053,20 +1053,20 @@ ON_Locale ON_Locale::FromWindowsName( { // Apple uses "zh-Hans" to mean BCP 47 "zh-CN" if ( 0 == region_subtag[0] || ON_String::EqualOrdinal("CN", -1, region_subtag, -1, true) ) - ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_CN_LCID, "zh-CN" ); + ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_CN_LCID, "zh-CN" ); } else if (ON_String::EqualOrdinal("Hant", -1, script_subtag, -1, true)) { // Apple uses "zh-Hant" to mean BCP 47 "zh-CN" if ( 0 == region_subtag[0] || ON_String::EqualOrdinal("TW", -1, region_subtag, -1, true) ) - ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); + ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); } else if ( ON_String::EqualOrdinal("CN", -1, region_subtag, -1, true) ) - ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_CN_LCID, "zh-CN" ); + ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_CN_LCID, "zh-CN" ); else if ( ON_String::EqualOrdinal("TW", -1, region_subtag, -1, true) ) - ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); + ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); else - ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); + ON_Locale::FromWindowsLCIDAndName(ON_Locale::zh_TW_LCID, "zh-TW" ); } else { @@ -1079,7 +1079,7 @@ ON_Locale ON_Locale::FromWindowsName( cleaned_loc += '_'; cleaned_loc += windows_sortorder; } - + #define LANG_CASE(lcid,lang) if (ON_String::EqualOrdinal(lang, -1, cleaned_loc, -1, true)) return ON_Locale::FromWindowsLCIDAndName(lcid, lang ) LANG_CASE( ON_Locale::cs_CZ_LCID, "cs-CZ" ); LANG_CASE( ON_Locale::de_DE_LCID, "de-DE" ); @@ -1093,7 +1093,7 @@ ON_Locale ON_Locale::FromWindowsName( LANG_CASE( ON_Locale::pl_PL_LCID, "pl-PL" ); LANG_CASE( ON_Locale::pt_PT_LCID, "pt-PT" ); #undef LANG_CASE - + // Bail out clause to handle string like fr-US. #define LANG_CASE_2(two_letter_lang_code,lcid,lang) if (ON_String::EqualOrdinal(two_letter_lang_code, -1, language_subtag, -1, true)) return ON_Locale::FromWindowsLCIDAndName(lcid, lang ) LANG_CASE_2( "cs", ON_Locale::cs_CZ_LCID, "cs-CZ" ); @@ -1146,28 +1146,28 @@ ON_Locale ON_Locale::FromAppleName( // Apple "language" names have hyphens before or no in the case of Chinese ON_String buffer(apple_name); - buffer.Replace('_', '-'); + buffer.Replace('_', '-'); apple_name = buffer; // According to https://en.wikipedia.org/wiki/Chinese_language, Chinese is a family of language // varieties, often mutually unintelligible. Specifying both Script and REGION - // (zh-Hans-CN or zh-Hant-TW) doesn't narrow things down nearly enough. + // (zh-Hans-CN or zh-Hant-TW) doesn't narrow things down nearly enough. // - // Basically we have to hope the string collate and mapping functions supplied by the OS and - // the translations supplied by our staff work well for our customers who select from the + // Basically we have to hope the string collate and mapping functions supplied by the OS and + // the translations supplied by our staff work well for our customers who select from the // two types of "Chinese" Rhino offers. // if (ON_String::EqualOrdinal("zh-Hans", -1, apple_name, -1, true) || ON_String::EqualOrdinal("zh-CN", -1, apple_name, -1, true)) { - // Apple uses "zh-Hanx" for the "language" name and "zh_CN" for the "locale" name + // Apple uses "zh-Hanx" for the "language" name and "zh_CN" for the "locale" name // when identifying OS X string services that might be useful to people who live // in the Peoples Republic of China. return ON_Locale::FromWindowsLCIDAndName(ON_Locale::WindowsLCID::zh_CN_LCID, "zh-CN"); } - + if (ON_String::EqualOrdinal("zh-Hant", -1, apple_name, -1, true) || ON_String::EqualOrdinal("zh-TW", -1, apple_name, -1, true)) { - // Apple uses "zh-Hant" for the "language" name and "zh_TW" for the "locale" name + // Apple uses "zh-Hant" for the "language" name and "zh_TW" for the "locale" name // when identifying OS X string services that might be useful to people who live // in Tiawan. return ON_Locale::FromWindowsLCIDAndName(ON_Locale::WindowsLCID::zh_TW_LCID, "zh-TW"); @@ -1289,19 +1289,19 @@ ON_CRT_locale_t ON_Locale::StringCollateAndMapLocalePtr() const bool ON_Locale::IsInvariantCulture() const { - return - 0x0027 == m_windows_lcid - && 0 != m_numeric_locale - && ON_CRT_C_locale() == m_numeric_locale + return + 0x0027 == m_windows_lcid + && 0 != m_numeric_locale + && ON_CRT_C_locale() == m_numeric_locale && m_numeric_locale == m_string_coll_map_locale; } bool ON_Locale::IsOrdinal() const { - return - 0 == m_windows_lcid - && 0 != m_numeric_locale - && ON_CRT_C_locale() == m_numeric_locale + return + 0 == m_windows_lcid + && 0 != m_numeric_locale + && ON_CRT_C_locale() == m_numeric_locale && m_numeric_locale == m_string_coll_map_locale; } @@ -1324,7 +1324,7 @@ public: static bool Validate_sprintf_s() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Test formatted printing char buffer[64] = { 0 }; size_t buffer_capacity = (sizeof(buffer) / sizeof(buffer[0])) - 1; @@ -1343,7 +1343,7 @@ public: static bool Validate_sprintf_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted printing char buffer[64] = { 0 }; @@ -1368,7 +1368,7 @@ public: static bool Validate_sprintf_s_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted printing char buffer[64] = { 0 }; @@ -1405,7 +1405,7 @@ public: static bool Validate_sscanf_s() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Test formatted scanning double a = ON_UNSET_VALUE; // Testing C-runtime - do not using ON_String::Scan @@ -1422,7 +1422,7 @@ public: static bool Validate_sscanf_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted scanning double a = ON_UNSET_VALUE; @@ -1447,7 +1447,7 @@ public: static bool Validate_sscanf_s_l() { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) // Test formatted scanning double a = ON_UNSET_VALUE; @@ -1602,7 +1602,7 @@ bool ON_Locale::SetPeriodAsCRuntimeDecimalPoint() if (prev_type != _DISABLE_PER_THREAD_LOCALE && prev_type >= 0) _configthreadlocale(prev_type); -#elif defined(ON_COMPILER_CLANG) +#elif defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // Apple's Clang compiler const char* s = setlocale(LC_NUMERIC, "C"); rc = (0 != s && 'C' == s[0] && 0 == s[1]); @@ -1631,7 +1631,7 @@ unsigned int ON_Locale::EnforcePeriodAsCRuntimeDecimalPoint() if (false == ON_Locale::SetPeriodAsCRuntimeDecimalPoint()) return 0; // attempt to set decimal point = period failed - + if (false == ON_Locale::PeriodIsCRuntimeDecimalPoint()) return 0; // decimal point != period diff --git a/opennurbs_string_format.cpp b/opennurbs_string_format.cpp index 272ae593..154c4921 100644 --- a/opennurbs_string_format.cpp +++ b/opennurbs_string_format.cpp @@ -19,7 +19,7 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -689,7 +689,7 @@ int ON_String::FormatVargsIntoBuffer( if (0 == buffer || buffer_capacity <= 0) return -1; buffer[0] = 0; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // CLang modifies args so a copy is required va_list args_copy; va_copy (args_copy, args); @@ -740,7 +740,7 @@ int ON_String::FormatVargsOutputCount( if ( nullptr == format || 0 == format[0] ) return 0; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_COMPILER_GNU) // CLang modifies args so a copy is required va_list args_copy; va_copy (args_copy, args); @@ -885,7 +885,7 @@ static const wchar_t* ConvertToCLangFormat( if ( !clang_format_buffer.GrowBuffer(format_capacity) ) return format; - wchar_t* ls = clang_format_buffer.m_buffer; + wchar_t* ls = clang_format_buffer.m_buffer; if ( nullptr == ls ) return format; @@ -942,7 +942,7 @@ int ON_wString::FormatVargsIntoBuffer( if ( nullptr == format || 0 == format[0] ) return 0; - + #if defined(ON_COMPILER_CLANG) // CLang requires %ls to properly format a const wchar_t* parameter wchar_t clang_format_stack_buffer[128]; @@ -954,17 +954,25 @@ int ON_wString::FormatVargsIntoBuffer( va_list args_copy; va_copy (args_copy, args); - // Cannot use Apple's vswprintf_l() because it's buggy. + // Cannot use Apple's vswprintf_l() because it's buggy. // This means we cannot be certain that a period will be used for a decimal point in formatted printing. // For details, see comments below in ON_wString::FormatVargsOutputCount(). //int len = vswprintf_l(buffer, buffer_capacity, ON_Locale::Ordinal.NumericLocalePtr(), format, args_copy); int len = vswprintf(buffer, buffer_capacity, format, args_copy); va_end(args_copy); - + #else - // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period + +#if defined(ON_COMPILER_GNU) + va_list args_copy; + va_copy (args_copy, args); + int len = vswprintf(buffer, buffer_capacity, format, args_copy); + va_end(args_copy); +#else + // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period // will be use for the decimal point in formatted printing. int len = _vswprintf_p_l(buffer, buffer_capacity, format, ON_Locale::Ordinal.NumericLocalePtr(), args); +#endif #endif if (((size_t)len) >= buffer_capacity) len = -1; @@ -1005,9 +1013,9 @@ int ON_wString::FormatVargsOutputCount( return 0; #if defined(ON_COMPILER_CLANG) - // Unlike _vscwprintf_p_l(), CLang's vswprintf() does not tell you how many characters would have - // been written if there was space enough in the buffer. - // It reports an error when there is not enough space. + // Unlike _vscwprintf_p_l(), CLang's vswprintf() does not tell you how many characters would have + // been written if there was space enough in the buffer. + // It reports an error when there is not enough space. // Assume a moderately large machine so kilobytes of wchar_t on the stack is not a problem. // CLang requires %ls to properly format a const wchar_t* parameter @@ -1025,7 +1033,7 @@ int ON_wString::FormatVargsOutputCount( ////const int formatted_string_count = vswprintf_l(nullptr, 0, ON_Locale::Ordinal.NumericLocalePtr(), format, args_copy); ////va_end(args_copy); ////return (formatted_string_count >= 0) ? formatted_string_count : -1; - + wchar_t stack_buffer[1024]; ON_wStringBuffer buffer(stack_buffer, sizeof(stack_buffer) / sizeof(stack_buffer[0])); size_t buffer_capacity = buffer.m_buffer_capacity; @@ -1035,7 +1043,7 @@ int ON_wString::FormatVargsOutputCount( va_copy(args_copy, args); // NOTE: - // Cannot use Apple's vswprintf_l() because it's buggy. + // Cannot use Apple's vswprintf_l() because it's buggy. // This means we cannot be certain that a period will be used for a decimal point in formatted printing. // // Apple's OS X 10.4 (July 2015) formatted printing functions are buggy when locale is specified. @@ -1049,7 +1057,7 @@ int ON_wString::FormatVargsOutputCount( //// va_end(args); //// return count; //// } - //// + //// //// int ON_VARGS_FUNC_CDECL VargsFormatFuncB(const wchar_t* format, ...) //// { //// va_list args; @@ -1062,25 +1070,25 @@ int ON_wString::FormatVargsOutputCount( //// #endif //// va_end(args); //// return count; - //// } //// - //// + //// } //// + //// //// Tests() //// { //// const wchar_t str1[5] = {'T', 'e', 's', 't', 0}; //// const wchar_t str2[5] = {'T', 0xFFFD,'s', 't', 0}; - //// + //// //// int Acount1 = VargsFormatFuncA(L"%ls",str1); //// int Acount2 = VargsFormatFuncA(L"%ls",str2); - //// + //// //// RhinoApp().Print("Acount1 = %d Acount2 = %d\n",Acount1,Acount2); - //// + //// //// int Bcount1 = VargsFormatFuncB(L"%ls",str1); //// int Bcount2 = VargsFormatFuncB(L"%ls",str2); - //// + //// //// // Windows Results: Acount1 = 4, Acount2 = 4, Bcount1 = 4, Bcount2 = 4 //// // Apple Results: Acount1 = 4, Acount2 = 4, Bcount1 = 4, Bcount2 = -1 //// } - //// + //// //const int formatted_string_count = vswprintf_l(buffer.m_buffer, buffer.m_buffer_capacity, ON_Locale::Ordinal.NumericLocalePtr(), format, args_copy); const int formatted_string_count = vswprintf(buffer.m_buffer, buffer.m_buffer_capacity, format, args_copy); va_end(args_copy); @@ -1101,8 +1109,37 @@ int ON_wString::FormatVargsOutputCount( } return -1; #else - // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period +#if defined(ON_COMPILER_GNU) + wchar_t stack_buffer[1024]; + ON_wStringBuffer buffer(stack_buffer, sizeof(stack_buffer) / sizeof(stack_buffer[0])); + size_t buffer_capacity = buffer.m_buffer_capacity; + for(;;) + { + va_list args_copy; + va_copy(args_copy, args); + + const int formatted_string_count = vswprintf(buffer.m_buffer, buffer.m_buffer_capacity, format, args_copy); + va_end(args_copy); + if (formatted_string_count >= 0) + { + // formatted_string_count = number of wchar_t elements not including null terminator + return formatted_string_count; + } + if ( buffer_capacity >= 1024*16*16*16 ) + break; + buffer_capacity *= 16; + if (false == buffer.GrowBuffer(buffer_capacity)) + break; + if (nullptr == buffer.m_buffer) + break; + if (buffer_capacity < buffer.m_buffer_capacity) + break; + } + return -1; +#else + // Using ON_Locale::Ordinal.NumericLocalePtr() insures that a period // will be use for the decimal point in formatted printing. return _vscwprintf_p_l(format, ON_Locale::Ordinal.NumericLocalePtr(), args); #endif +#endif } diff --git a/opennurbs_string_scan.cpp b/opennurbs_string_scan.cpp index c2b84946..6a664f7b 100644 --- a/opennurbs_string_scan.cpp +++ b/opennurbs_string_scan.cpp @@ -19,7 +19,7 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -85,7 +85,7 @@ int ON_String::ScanBufferVargs( va_list args ) { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (nullptr == buffer || nullptr == format) return -1; @@ -148,7 +148,7 @@ int ON_wString::ScanBufferVargs( va_list args ) { -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (nullptr == buffer || nullptr == format) return -1; @@ -397,7 +397,7 @@ const char* ON_String::ToNumber( local_buffer[local_buffer_count++] = 0; double x = value_on_failure; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (1 == sscanf(local_buffer, "%lg", &x)) { @@ -639,7 +639,7 @@ const wchar_t* ON_wString::ToNumber( local_buffer[local_buffer_count++] = 0; double x = value_on_failure; -#if defined(ON_COMPILER_CLANG) +#if defined(ON_COMPILER_CLANG) || defined(ON_RUNTIME_LINUX) #if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) if (1 == sscanf(local_buffer, "%lg", &x)) { diff --git a/opennurbs_subd_heap.cpp b/opennurbs_subd_heap.cpp index 3d8b6380..a9f522c2 100644 --- a/opennurbs_subd_heap.cpp +++ b/opennurbs_subd_heap.cpp @@ -3,7 +3,7 @@ #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -188,7 +188,7 @@ bool ON_SubD_FixedSizeHeap::ReserveSubDWorkspace( = bTri ? (extraordinary_valence + 14) : (3 * extraordinary_valence + 12); // quads or unset - + // const unsigned int f_capacity = extraordinary_valence + 7 for tris // const unsigned int f_capacity = extraordinary_valence + 5 for quads // 7 is alwasy used to accomodate unset as well @@ -228,7 +228,7 @@ ON_SubDVertex* ON_SubD_FixedSizeHeap::AllocateVertex( memset(v, 0, sizeof(*v)); if (m_v_index > 0) { - // code in ON_SubDFaceNeighborhood.Subdivide() relies on + // code in ON_SubDFaceNeighborhood.Subdivide() relies on // m_next_vertex being set this way. m_v[m_v_index - 1].m_next_vertex = v; v->m_prev_vertex = &m_v[m_v_index - 1]; @@ -268,17 +268,17 @@ ON_SubDVertex* ON_SubD_FixedSizeHeap::AllocateVertex( { if ( nullptr == vertex0) return ON_SUBD_RETURN_ERROR(nullptr); - + double subdP[3]; if (false == vertex0->GetSubdivisionPoint(subdivision_type,bUseSavedSubdivisionPoint,subdP)) return ON_SUBD_RETURN_ERROR(nullptr); ON_SubDVertex* v1 = AllocateVertex(subdP,edge_capacity,face_capacity); - + if ( nullptr == v1) return ON_SUBD_RETURN_ERROR(nullptr); v1->m_level = vertex0->m_level+1; - + v1->m_vertex_tag = vertex0->m_vertex_tag; //if ( ON_SubD::SubDType::QuadCatmullClark == subdivision_type) @@ -298,7 +298,7 @@ ON_SubDVertex* ON_SubD_FixedSizeHeap::AllocateVertex( } } } - + return v1; } @@ -312,17 +312,17 @@ ON_SubDVertex* ON_SubD_FixedSizeHeap::AllocateVertex( { if ( nullptr == edge0) return ON_SUBD_RETURN_ERROR(nullptr); - + double subdP[3]; if (false == edge0->GetSubdivisionPoint(subdivision_type,bUseSavedSubdivisionPoint,subdP)) return ON_SUBD_RETURN_ERROR(nullptr); - + ON_SubDVertex* v1 = AllocateVertex(subdP,edge_capacity,face_capacity); if ( nullptr == v1) return ON_SUBD_RETURN_ERROR(nullptr); v1->m_level = edge0->m_level+1; - + if (ON_SubD::EdgeTag::Smooth == edge0->m_edge_tag || ON_SubD::EdgeTag::X == edge0->m_edge_tag) v1->m_vertex_tag = ON_SubD::VertexTag::Smooth; else if (ON_SubD::EdgeTag::Crease == edge0->m_edge_tag) @@ -438,7 +438,7 @@ ON_SubDEdge* ON_SubD_FixedSizeHeap::AllocateEdge( } e->m_id = ++m_e_index; - + if (nullptr != v0) { e->m_vertex[0] = v0; @@ -474,7 +474,7 @@ ON_SubDFace* ON_SubD_FixedSizeHeap::AllocateFace( memset(f, 0, sizeof(*f)); if (m_f_index > 0) { - // code in ON_SubDFaceNeighborhood.Subdivide() relies on + // code in ON_SubDFaceNeighborhood.Subdivide() relies on // m_next_face being set this way. m_f[m_f_index-1].m_next_face = f; f->m_prev_face = &m_f[m_f_index-1]; @@ -531,7 +531,7 @@ ON_SubDFace* ON_SubD_FixedSizeHeap::AllocateQuad( return ON_SUBD_RETURN_ERROR(nullptr); if (nullptr == vertices[3] || nullptr == vertices[3]->m_faces || vertices[3]->m_face_count >= vertices[3]->m_face_capacity || vertices[3] != edges[2]->m_vertex[1-edgedirs[2]]) return ON_SUBD_RETURN_ERROR(nullptr); - + ON_SubDFace* f = AllocateFace(zero_face_id,parent_face_id); if (nullptr == f) return ON_SUBD_RETURN_ERROR(nullptr); @@ -599,7 +599,7 @@ ON_SubDFace* ON_SubD_FixedSizeHeap::AllocateTri( return ON_SUBD_RETURN_ERROR(nullptr); if (nullptr == vertices[2] || nullptr == vertices[2]->m_faces || vertices[2]->m_face_count >= vertices[2]->m_face_capacity || vertices[2] != edges[1]->m_vertex[1-edgedirs[1]]) return ON_SUBD_RETURN_ERROR(nullptr); - + ON_SubDFace* f = AllocateFace(zero_face_id,parent_face_id); if (nullptr == f) return ON_SUBD_RETURN_ERROR(nullptr); @@ -660,7 +660,7 @@ bool ON_SubD_FixedSizeHeap::ReturnPtrArray( m_p_index -= capacity; return true; } - return ON_SUBD_RETURN_ERROR(nullptr); + return ON_SUBD_RETURN_ERROR(false); } @@ -703,7 +703,7 @@ class ON_SubDVertex* ON_SubDHeap::AllocateVertexAndSetId(unsigned int& max_verte // In order for m_fspv.ElementFromId() to work, it is critical that // once a vertex is allocated from m_fspv, the value of m_id never // changes. This is imporant because the value of m_id must persist - // in binary archives in order for ON_COMPONENT_INDEX values to + // in binary archives in order for ON_COMPONENT_INDEX values to // persist in binary archives. ON_SubDVertex* v; if (m_unused_vertex) @@ -749,7 +749,7 @@ class ON_SubDEdge* ON_SubDHeap::AllocateEdgeAndSetId(unsigned int& max_edge_id) // In order for m_fspe.ElementFromId() to work, it is critical that // once a edge is allocated from m_fspe, the value of m_id never // changes. This is imporant because the value of m_id must persist - // in binary archives in order for ON_COMPONENT_INDEX values to + // in binary archives in order for ON_COMPONENT_INDEX values to // persist in binary archives. ON_SubDEdge* e; if (m_unused_edge) @@ -796,7 +796,7 @@ class ON_SubDFace* ON_SubDHeap::AllocateFaceAndSetId(unsigned int& max_face_id) // In order for m_fspf.ElementFromId() to work, it is critical that // once a face is allocated from m_fspf, the value of m_id never // changes. This is imporant because the value of m_id must persist - // in binary archives in order for ON_COMPONENT_INDEX values to + // in binary archives in order for ON_COMPONENT_INDEX values to // persist in binary archives. ON_SubDFace* f; if (m_unused_face) @@ -1357,4 +1357,3 @@ void ON_SubDHeap::ReturnArray( } return; } - diff --git a/opennurbs_system.h b/opennurbs_system.h index c6e059b2..0bcbf9f4 100644 --- a/opennurbs_system.h +++ b/opennurbs_system.h @@ -539,7 +539,7 @@ typedef ON__UINT32 wchar_t; #pragma ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE #pragma ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE -#if defined(ON_RUNTIME_ANDROID) +#if defined(ON_RUNTIME_ANDROID) || defined(ON_RUNTIME_LINUX) #include "android_uuid/uuid.h" #else #include diff --git a/opennurbs_uuid.cpp b/opennurbs_uuid.cpp index 68e5f57b..5d15508e 100644 --- a/opennurbs_uuid.cpp +++ b/opennurbs_uuid.cpp @@ -8,18 +8,20 @@ // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF // MERCHANTABILITY ARE HEREBY DISCLAIMED. -// +// // For complete openNURBS copyright information see . // //////////////////////////////////////////////////////////////// */ #include "opennurbs.h" - +#if defined(ON_RUNTIME_LINUX) +#include "android_uuid/uuid.h" +#endif #if !defined(ON_COMPILING_OPENNURBS) // This check is included in all opennurbs source .c and .cpp files to insure // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled. -// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined +// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined // and the opennurbs .h files alter what is declared and how it is declared. #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif @@ -29,7 +31,7 @@ // When ON_UUID is a typdef for Microsoft 's UUID, // the Microsoft compiler handles == and !=. // When a ON_UUID is not a typedef for a Microsoft UUID, -// it is declared as a class and operator== and operator!= +// it is declared as a class and operator== and operator!= // need to be explicitly defined. bool operator==(const struct ON_UUID_struct& a, const struct ON_UUID_struct& b) @@ -53,7 +55,7 @@ static const int little_endian_rho[16] = {3,2,1,0, 5,4, 7,6, 8,9, 10,11,12,13,14 // for big endian CPUs (Motorola, MIPS, Sparc, etc.) static const int big_endian_rho[16] = {0,1,2,3, 4,5, 6,7, 8,9, 10,11,12,13,14,15}; - + ON_UUID ON_CreateId() { ON_UUID id; @@ -168,7 +170,7 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) #if defined(ON_COMPILER_MSC) // Header: Declared in Rpcdce.h. - // Library: Use Rpcrt4.lib + // Library: Use Rpcrt4.lib #pragma comment(lib, "Rpcrt4.lib") ::UuidCreate(&new_uuid); //::UuidCreateSequential(&new_uuid); // faster but computer MAC address @@ -180,7 +182,7 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) if ( ON::endian::little_endian == ON::Endian() ) { // Intel cpu mac - // The uuid_generate() function returns a UUID in network or + // The uuid_generate() function returns a UUID in network or // big-endian order. The rest of OpenNURBS assumes that a UUID // is stored in native byte order, so we switch the byte order // of the UUID. @@ -188,29 +190,29 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) uuid_generate(apple_osx_uuid); unsigned char* dst = (unsigned char*)&new_uuid; const unsigned char* src = (const unsigned char*)&apple_osx_uuid; - *dst++ = src[little_endian_rho[ 0]]; - *dst++ = src[little_endian_rho[ 1]]; - *dst++ = src[little_endian_rho[ 2]]; - *dst++ = src[little_endian_rho[ 3]]; - *dst++ = src[little_endian_rho[ 4]]; - *dst++ = src[little_endian_rho[ 5]]; - *dst++ = src[little_endian_rho[ 6]]; - *dst++ = src[little_endian_rho[ 7]]; - *dst++ = src[little_endian_rho[ 8]]; - *dst++ = src[little_endian_rho[ 9]]; - *dst++ = src[little_endian_rho[10]]; - *dst++ = src[little_endian_rho[11]]; - *dst++ = src[little_endian_rho[12]]; - *dst++ = src[little_endian_rho[13]]; - *dst++ = src[little_endian_rho[14]]; - *dst = src[little_endian_rho[15]]; + *dst++ = src[little_endian_rho[ 0]]; + *dst++ = src[little_endian_rho[ 1]]; + *dst++ = src[little_endian_rho[ 2]]; + *dst++ = src[little_endian_rho[ 3]]; + *dst++ = src[little_endian_rho[ 4]]; + *dst++ = src[little_endian_rho[ 5]]; + *dst++ = src[little_endian_rho[ 6]]; + *dst++ = src[little_endian_rho[ 7]]; + *dst++ = src[little_endian_rho[ 8]]; + *dst++ = src[little_endian_rho[ 9]]; + *dst++ = src[little_endian_rho[10]]; + *dst++ = src[little_endian_rho[11]]; + *dst++ = src[little_endian_rho[12]]; + *dst++ = src[little_endian_rho[13]]; + *dst++ = src[little_endian_rho[14]]; + *dst = src[little_endian_rho[15]]; } else { // Motorola cpu mac uuid_generate((unsigned char*)&new_uuid); } - + #if defined (ON_DEBUG) // OS X generates version 4 UUIDs. Check that this is still true after changing the byte order. if ((new_uuid.Data3 & 0xF000) != 0x4000) @@ -221,13 +223,20 @@ bool ON_CreateUuid( ON_UUID& new_uuid ) return true; #else - // You must supply a way to create unique ids or you + +#if defined(ON_RUNTIME_LINUX) + uuid_generate((unsigned char*)&new_uuid); + return true; +#else + + // You must supply a way to create unique ids or you // will not be able to write 3dm files. #error TODO - generate uuid memset(&new_uuid,0,sizeof(ON_UUID)); return false; #endif +#endif #endif } @@ -235,7 +244,7 @@ const char* ON_ParseUuidString(const char* sUUID, ON_UUID* uuid) { // NOTE WELL: This code has to work on non-Windows OSs and on // both big and little endian CPUs. On Windows OSs - // is must return the same result as + // is must return the same result as // Windows's UuidFromString(). // @@ -272,7 +281,7 @@ const char* ON_ParseUuidString(const char* sUUID, ON_UUID* uuid) unsigned char byte_value[2]; memset(&u, 0, sizeof(u)); - //for ( bi = 0; bi < 16; bi++ ) + //for ( bi = 0; bi < 16; bi++ ) // u.b[bi] = 0; bFailed = sUUID ? false : true; @@ -312,7 +321,7 @@ const char* ON_ParseUuidString(const char* sUUID, ON_UUID* uuid) } } - if (bFailed) + if (bFailed) { // 09 August 2006 John Morse // There are times when Rhino is looking for a plug-in but the SDK or command @@ -331,12 +340,12 @@ const char* ON_ParseUuidString(const char* sUUID, ON_UUID* uuid) return bFailed ? 0 : sUUID; } - + ON_UUID ON_UuidFromString( const char* sUUID ) { // NOTE WELL: This code has to work on non-Windows OSs and on // both big and little endian CPUs. On Windows OSs - // is must return the same result as + // is must return the same result as // Windows's UuidFromString(). // @@ -349,7 +358,7 @@ ON_UUID ON_UuidFromString( const char* sUUID ) /* #if defined(ON_DEBUG) && defined(ON_RUNTIME_WIN) RPC_STATUS st; - union + union { ON_UUID uuid; unsigned char b[16]; @@ -359,10 +368,10 @@ ON_UUID ON_UuidFromString( const char* sUUID ) */ static const int* rho = (ON::endian::big_endian == ON::Endian()) - ? big_endian_rho + ? big_endian_rho : little_endian_rho; - union + union { ON_UUID uuid; unsigned char b[16]; @@ -373,7 +382,7 @@ ON_UUID ON_UuidFromString( const char* sUUID ) unsigned char byte_value[2]; memset(&u,0,sizeof(u)); - //for ( bi = 0; bi < 16; bi++ ) + //for ( bi = 0; bi < 16; bi++ ) // u.b[bi] = 0; bFailed = sUUID ? false : true; @@ -463,7 +472,7 @@ ON_UUID ON_UuidFromString( const wchar_t* sUUID ) s[i++] = (char)w; else if ( w >= 'a' && w <= 'f' ) s[i++] = (char)w; - else if ( w != '-' ) + else if ( w != '-' ) break; } s[i] = 0; @@ -471,7 +480,7 @@ ON_UUID ON_UuidFromString( const wchar_t* sUUID ) return ON_UuidFromString(s); } - + int ON_UuidIndex::CompareIdAndIndex( const ON_UuidIndex* a, const ON_UuidIndex* b ) { int i; @@ -533,7 +542,7 @@ int ON_UuidIndex::CompareIndex( const ON_UuidIndex* a, const ON_UuidIndex* b ) return 0; } - + int ON_UuidPtr::CompareIdAndPtr( const ON_UuidPtr* a, const ON_UuidPtr* b ) { int i; @@ -619,9 +628,9 @@ int ON_UuidPtr::ComparePtr( const ON_UuidPtr* a, const ON_UuidPtr* b ) //// z = ::UuidCompare(&a,&b,&rpc_status); //// if ( y != z ) //// { -//// int mscomparediff = 99; +//// int mscomparediff = 99; //// } -//// } +//// } //// } //// } ////} @@ -634,10 +643,10 @@ int ON_UuidCompare( const ON_UUID* a, const ON_UUID* b ) // taking into account the way ON_UUIDs // are read/written by ON_BinaryArchive. // - // On Windows, ::UuidCompare() must agree + // On Windows, ::UuidCompare() must agree // with this function. - if ( !a ) + if ( !a ) { return b ? -1 : 0; } @@ -654,14 +663,14 @@ int ON_UuidCompare( const ON_UUID* a, const ON_UUID* b ) if ( a->Data3 > b->Data3 ) return 1; return memcmp(a->Data4,b->Data4,sizeof(a->Data4)); } - + int ON_UuidCompare( const ON_UUID& a, const ON_UUID& b) { return ON_UuidCompare(&a,&b); } -bool ON_UuidIsNil( - const ON_UUID& uuid +bool ON_UuidIsNil( + const ON_UUID& uuid ) { const ON__INT32* p = (const ON__INT32*)&uuid; @@ -669,8 +678,8 @@ bool ON_UuidIsNil( } -bool ON_UuidIsNotNil( - const ON_UUID& uuid +bool ON_UuidIsNotNil( + const ON_UUID& uuid ) { const ON__INT32* p = (const ON__INT32*)&uuid; @@ -680,11 +689,11 @@ bool ON_UuidIsNotNil( char* ON_UuidToString( const ON_UUID& uuid, char* s) { - // s - [out] The s[] char array must have length >= 37. - // The returned char array will have a 36 + // s - [out] The s[] char array must have length >= 37. + // The returned char array will have a 36 // character uuid in s[0..35] and a null in s[36]. - // NOTE WELL: + // NOTE WELL: // This code has to work on non-Windows OSs and on both big and // little endian CPUs. The result must satisfy // uuid == ON_UuidFromString(ON_UuidToString(uuid,s)) @@ -698,13 +707,13 @@ char* ON_UuidToString( const ON_UUID& uuid, char* s) const unsigned char* b = (const unsigned char*)&uuid; char* p; int i; - + static const int* rho = (ON::endian::big_endian == ON::Endian()) - ? big_endian_rho + ? big_endian_rho : little_endian_rho; // 5 December 2002 Dale Lear: - // There is either a bug in Purify (likely) or perhaps a bug in the + // There is either a bug in Purify (likely) or perhaps a bug in the // way Microsoft compiles c>>4 when c is an unsigned char. In any // case, changing c to an unsigned int makes purify happy and should // work just as well. @@ -739,11 +748,11 @@ char* ON_UuidToString( const ON_UUID& uuid, char* s) wchar_t* ON_UuidToString( const ON_UUID& uuid, wchar_t* s) { - // s - [out] The s[] char array must have length >= 37. - // The returned char array will have a 36 + // s - [out] The s[] char array must have length >= 37. + // The returned char array will have a 36 // character uuid in s[0..35] and a null in s[36]. - // NOTE WELL: + // NOTE WELL: // This code has to work on non-Windows OSs and on both big and // little endian CPUs. The result must satisfy // uuid == ON_UuidFromString(ON_UuidToString(uuid,s)) @@ -763,7 +772,7 @@ wchar_t* ON_UuidToString( const ON_UUID& uuid, wchar_t* s) return s; } - + const char* ON_UuidToString( const ON_UUID& uuid, ON_String& s ) { char x[37]; @@ -771,7 +780,7 @@ const char* ON_UuidToString( const ON_UUID& uuid, ON_String& s ) return s.Array(); } - + const wchar_t* ON_UuidToString( const ON_UUID& uuid, ON_wString& s ) { wchar_t x[37];