Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Import] DXF make codepage case insensitive #9712

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Mod/Import/App/dxf/dxf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "PreCompiled.h"

//required by windows for M_PI definition
#define _USE_MATH_DEFINES

Check warning on line 9 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

declaration uses identifier '_USE_MATH_DEFINES', which is a reserved identifier [bugprone-reserved-identifier]
#include <cmath>
#include <fstream>
#include <iomanip>
Expand All @@ -24,23 +24,23 @@

using namespace std;

Base::Vector3d toVector3d(const double* a)

Check warning on line 27 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

parameter name 'a' is too short, expected at least 2 characters [readability-identifier-length]
{
Base::Vector3d result;
result.x = a[0];

Check warning on line 30 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
result.y = a[1];

Check warning on line 31 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
result.z = a[2];

Check warning on line 32 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
return result;
}

CDxfWrite::CDxfWrite(const char* filepath) :

Check warning on line 36 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

constructor does not initialize these fields: m_entityHandle, m_layerHandle, m_blockHandle, m_blkRecordHandle [cppcoreguidelines-pro-type-member-init]
//TODO: these should probably be parameters in config file
//handles:
//boilerplate 0 - A00
//used by dxf.cpp A01 - FFFE
//ACAD HANDSEED FFFF

m_handle(0xA00), //room for 2560 handles in boilerplate files

Check warning on line 43 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

0xA00 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
//m_entityHandle(0x300), //don't need special ranges for handles
//m_layerHandle(0x30),
//m_blockHandle(0x210),
Expand All @@ -49,8 +49,8 @@
m_layerName("none")
{
// start the file
m_fail = false;

Check warning on line 52 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'm_fail' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
m_version = 12;

Check warning on line 53 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'm_version' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]

Check warning on line 53 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

12 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
Base::FileInfo fi(filepath);
m_ofs = new Base::ofstream(fi, ios::out);
m_ssBlock = new std::ostringstream();
Expand Down Expand Up @@ -1753,7 +1753,7 @@
m_ColorIndex = 0;
m_eUnits = eMillimeters;
m_measurement_inch = false;
strcpy(m_layer_name, "0"); // Default layer name

Check warning on line 1756 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
memset( m_section_name, '\0', sizeof(m_section_name) );
memset( m_block_name, '\0', sizeof(m_block_name) );
m_ignore_errors = true;
Expand Down Expand Up @@ -1849,7 +1849,7 @@

case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 1852 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 6: // line style name follows
Expand Down Expand Up @@ -1946,7 +1946,7 @@

case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 1949 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 10:
Expand Down Expand Up @@ -2030,7 +2030,7 @@

case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2033 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 6: // line style name follows
Expand Down Expand Up @@ -2133,7 +2133,7 @@
return true;
case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2136 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;
case 62:
// color index
Expand Down Expand Up @@ -2314,7 +2314,7 @@

case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2317 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 10:
Expand Down Expand Up @@ -2387,7 +2387,7 @@
return false;
case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2390 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 10:
Expand Down Expand Up @@ -2487,7 +2487,7 @@
return true;
case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2490 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 10:
Expand Down Expand Up @@ -2665,7 +2665,7 @@
break;
case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2668 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;
case 10:
// x
Expand Down Expand Up @@ -2764,7 +2764,7 @@

case 8: // Layer name follows
get_line();
strcpy(m_layer_name, m_str);

Check warning on line 2767 in src/Mod/Import/App/dxf/dxf.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Almost always, snprintf is better than strcpy [runtime/printf] [4]
break;

case 10:
Expand Down Expand Up @@ -3345,8 +3345,11 @@
else {
// Codepage names may be of the form "ansi_1252" which we map to "cp1252" but we don't map "ansi_x3xxxx" (which happens to mean "ascii")
std::string* p = new std::string(*m_CodePage);
if (strncmp(p->c_str(), "ansi_", 5) == 0
&& strncmp(p->c_str(), "ansi_x3", 7) != 0)
std::string p_lower;
for (std::string::const_iterator i = p->begin(); i != p->end(); ++i)
p_lower += tolower(*i);
if (p_lower.substr(0, 5) == "ansi_"
&& p_lower.substr(0, 7) != "ansi_x3")
p->replace(0, 5, "cp");
m_encoding = p;
// At this point we want to recognize synonyms for "utf_8" and use the custom decoder function.
Expand Down