@@ -69,8 +69,7 @@ static int dxf_3dsolid (Bit_Chain *restrict dat,
69
69
const Dwg_Object * restrict obj ,
70
70
Dwg_Entity_3DSOLID * restrict _obj );
71
71
static void dxf_fixup_string (Bit_Chain * restrict dat , char * restrict str ,
72
- const int opts , const int dxf ,
73
- const int dxfcont );
72
+ const int opts , const int dxf );
74
73
static void dxf_CMC (Bit_Chain * restrict dat , Dwg_Color * restrict color ,
75
74
const int dxf , const int opt );
76
75
@@ -90,14 +89,12 @@ static void dxf_CMC (Bit_Chain *restrict dat, Dwg_Color *restrict color,
90
89
91
90
#define VALUE_TV (value , dxf ) \
92
91
{ \
93
- GROUP (dxf); \
94
- dxf_fixup_string (dat, (char *)value, 1, dxf, dxf); \
92
+ dxf_fixup_string (dat, (char *)value, 1, dxf); \
95
93
}
96
94
#define VALUE_TV0 (value , dxf ) \
97
95
if (dxf && value && *value) \
98
96
{ \
99
- GROUP (dxf); \
100
- dxf_fixup_string (dat, (char *)value, 1, dxf, dxf); \
97
+ dxf_fixup_string (dat, (char *)value, 1, dxf); \
101
98
}
102
99
// in_json writes all strings as TV, in_dxf and decode not.
103
100
#define VALUE_TU (wstr , dxf ) \
@@ -109,23 +106,15 @@ static void dxf_CMC (Bit_Chain *restrict dat, Dwg_Color *restrict color,
109
106
else if (dxf) \
110
107
{ \
111
108
char *u8 = bit_convert_TU ((BITCODE_TU)wstr); \
112
- GROUP (dxf); \
109
+ dxf_fixup_string (dat, u8, 1, dxf); \
113
110
if (u8) \
114
- { \
115
- dxf_fixup_string (dat, u8, 1, dxf, dxf); \
116
- } \
117
- else \
118
- fprintf (dat->fh, "\r\n"); \
119
- free (u8); \
111
+ free (u8); \
120
112
} \
121
113
}
122
114
#define VALUE_TFF (str , dxf ) \
123
115
{ \
124
116
if (dxf) \
125
- { \
126
- GROUP (dxf); \
127
- dxf_fixup_string (dat, (char *)str, 0, dxf, dxf); \
128
- } \
117
+ dxf_fixup_string (dat, (char *)str, 0, dxf); \
129
118
}
130
119
#define VALUE_BINARY (value , size , dxf ) \
131
120
{ \
@@ -1240,64 +1229,65 @@ cquote (char *restrict dest, const size_t len, const char *restrict src)
1240
1229
/* If opts 1:
1241
1230
quote \n => ^J
1242
1231
\M+xxxxx => \U+XXXX (shift-jis)
1243
- Splits overlong (len>255) lines into dxf 3 chunks with group 1
1232
+ Splits overlong (len>255) lines into dxf 3 chunks ending with group dxf
1233
+ only TFF sets opts=0, TV and TU to 1.
1244
1234
*/
1245
1235
static void
1246
1236
dxf_fixup_string (Bit_Chain * restrict dat , char * restrict str , const int opts ,
1247
- const int dxf , const int dxfcont )
1237
+ const int dxf )
1248
1238
{
1249
1239
if (str && * str )
1250
1240
{
1251
1241
if (opts
1252
1242
&& (strchr (str , '\n' ) || strchr (str , '\r' )
1253
1243
|| strstr (str , "\\M+1" )))
1254
1244
{
1255
- static char _buf [1024 ] = { 0 };
1245
+ static char * cbuf ;
1246
+ static char _sbuf [1024 ] = { 0 };
1256
1247
const size_t origlen = strlen (str );
1257
1248
long len = (long )((2 * origlen ) + 1 );
1258
- if ( len > 1024 )
1259
- { // FIXME: maybe we need this for chunked strings
1260
- fprintf ( dat -> fh , "\r\n" );
1261
- LOG_ERROR ("Overlarge DXF string, len=%" PRIuSIZE , origlen );
1249
+ bool need_free = false;
1250
+ if ( len < 0 )
1251
+ {
1252
+ LOG_ERROR ("Overlong DXF string" );
1262
1253
return ;
1263
1254
}
1264
- * _buf = '\0' ;
1265
- len = (long )strlen (cquote (_buf , len , str ));
1266
- if (len > 255 && dxf == 1 )
1255
+ if (len > 1024 )
1267
1256
{
1268
- char * bufp = & _buf [0 ];
1269
- // GROUP 1 already printed
1270
- while (len > 0 )
1257
+ cbuf = malloc (len );
1258
+ if (!cbuf )
1271
1259
{
1272
- int rlen = len > 255 ? 255 : len ;
1273
- fprintf (dat -> fh , "%.*s\r\n" , rlen , bufp );
1274
- len -= 255 ;
1275
- bufp += 255 ;
1276
- if (len > 0 )
1277
- fprintf (dat -> fh , "%3d\r\n" , dxfcont );
1260
+ LOG_ERROR ("Out of memory" );
1261
+ return ;
1278
1262
}
1263
+ * cbuf = '\0' ;
1264
+ need_free = true;
1279
1265
}
1280
1266
else
1281
- fprintf (dat -> fh , "%s\r\n" , _buf );
1267
+ cbuf = & _sbuf [0 ];
1268
+ {
1269
+ len = (long )strlen (cquote (cbuf , len , str ));
1270
+ while (len > 0 )
1271
+ {
1272
+ fprintf (dat -> fh , "%3d\r\n" , len < 250 ? dxf : 3 );
1273
+ fprintf (dat -> fh , "%.*s\r\n" , len > 250 ? 250 : (int )len , cbuf );
1274
+ len -= 250 ;
1275
+ cbuf += 250 ;
1276
+ }
1277
+ }
1278
+ if (need_free )
1279
+ free (cbuf );
1282
1280
}
1283
- else
1281
+ else // TFF
1284
1282
{
1285
1283
long len = (long )strlen (str );
1286
- if (len > 255 && dxf == 1 )
1284
+ while (len > 0 )
1287
1285
{
1288
- // GROUP 1 already printed
1289
- while (len > 0 )
1290
- {
1291
- int rlen = len > 255 ? 255 : len ;
1292
- fprintf (dat -> fh , "%.*s\r\n" , (int )rlen , str );
1293
- len -= 255 ;
1294
- str += 255 ;
1295
- if (len > 255 )
1296
- fprintf (dat -> fh , " 3\r\n" );
1297
- }
1286
+ fprintf (dat -> fh , "%3d\r\n" , len < 250 ? dxf : 3 );
1287
+ fprintf (dat -> fh , "%.*s\r\n" , len > 250 ? 250 : (int )len , str );
1288
+ len -= 250 ;
1289
+ str += 250 ;
1298
1290
}
1299
- else
1300
- fprintf (dat -> fh , "%s\r\n" , str );
1301
1291
}
1302
1292
}
1303
1293
else
0 commit comments