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

dwgadd: fix read* logic, add tests #1010

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/oda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ concurrency:

jobs:
oda:
runs-on: ubuntu-22.04
#ubuntu-22.04
runs-on: self-hosted
timeout-minutes: 50
strategy:
fail-fast: true
Expand All @@ -27,14 +28,15 @@ jobs:
with:
python-version: '3.10'
- uses: pyvista/setup-headless-display-action@v1
- run: |
wget -q https://download.opendesign.com/guestfiles/Demo/ODAFileConverter_QT5_lnxX64_8.3dll_25.5.deb
sudo add-apt-repository -y ppa:linuxuprising/libpng12
sudo apt update
sudo apt-get -y install libpng12-0 qt5dxcb-plugin
sudo dpkg -i ODAFileConverter_QT5_lnxX64_8.3dll_25.5.deb
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libxcb-util.so.1 libxcb-util.so.0
#- run: |
# deb=ODAFileConverter_QT6_lnxX64_8.3dll_25.7.deb
# wget https://download.opendesign.com/guestfiles/Demo/$deb
# sudo add-apt-repository -y ppa:linuxuprising/libpng12
# sudo apt update
# sudo apt-get -y install libpng12-0 qt5dxcb-plugin
# sudo dpkg -i $deb
# cd /usr/lib/x86_64-linux-gnu
# sudo ln -s libxcb-util.so.1 libxcb-util.so.0
- run: |
export QT_DEBUG_PLUGINS=1
ODAFileConverter test/test-data . ACAD2000 DXF 0 0 example_2000.dwg || true
Expand Down
44 changes: 26 additions & 18 deletions examples/dwgadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ static unsigned int loglevel;
# define FMT_NAME "%[a-zA-Z0-9_]"
# define FMT_TAG "%[^ !]"
# define FMT_TBL "\"%[a-zA-Z0-9._ -]\""
# define FMT_PATH "\"%[a-zA-Z0-9_. \\-]\""
# define FMT_PATH "\"%[a-zA-Z0-9_. \\-/]\""
# define FMT_ANY "\"%[^\"]\""
#else
# define SSCANF_S sscanf
# define SZ
# define FMT_NAME "%119[a-zA-Z0-9_]"
# define FMT_TAG "%119[^ !]"
# define FMT_TBL "\"%119[a-zA-Z0-9._ -]\""
# define FMT_PATH "\"%119[a-zA-Z0-9_. \\-]\""
# define FMT_PATH "\"%119[a-zA-Z0-9_. \\-/]\""
# define FMT_ANY "\"%119[^\"]\""
#endif

Expand Down Expand Up @@ -332,6 +332,7 @@ main (int argc, char *argv[])
if (!out_dat.fh)
{
LOG_ERROR ("Could not write %s", outfile)
free (dat.chain);
exit (1);
}
out_dat.from_version = dwg.header.from_version;
Expand Down Expand Up @@ -607,6 +608,12 @@ fn_error (const char *msg)
if (!hdr) \
fn_error ("Missing block header\n");

#define ADD_INITIAL \
mspace = dwg_model_space_object (dwg); \
hdr = mspace ? mspace->tio.object->tio.BLOCK_HEADER : NULL; \
orig_num = dwg->num_objects; \
initial = 0

static int
dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
{
Expand Down Expand Up @@ -729,21 +736,22 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
LOG_INSANE ("< \"%.*s\"...\n\n", 80, p);
if (memBEGINc (p, "readdwg"))
{
if (dwg)
if (!initial || dwg->num_objects)
{
LOG_ERROR ("readdwg seen, but DWG already exists");
LOG_ERROR ("readdwg seen, but DWG already initialized");
exit (1);
}
if (1 == SSCANF_S (p, "readdwg " FMT_PATH, text SZ))
{
LOG_INFO ("readdwg %s\n", text)
if ((error = dwg_read_file (text, *dwgp)) > DWG_ERR_CRITICAL)
if ((error = dwg_read_file (text, *dwgp)) >= DWG_ERR_CRITICAL)
{
LOG_ERROR ("Invalid readdwg \"%s\" => error 0x%x", text,
error);
exit (1);
}
dwg = *dwgp;
ADD_INITIAL;
p = next_line (p, end);
continue;
}
Expand All @@ -755,21 +763,22 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
}
else if (memBEGINc (p, "readdxf"))
{
if (dwg)
if (!initial || dwg->num_objects)
{
LOG_ERROR ("readdxf seen, but DWG already exists");
LOG_ERROR ("readdxf seen, but DWG already initialized");
exit (1);
}
if (1 == SSCANF_S (p, "readdxf " FMT_PATH, text SZ))
{
LOG_INFO ("readdxf %s\n", text)
if ((error = dxf_read_file (text, *dwgp)) > DWG_ERR_CRITICAL)
if ((error = dxf_read_file (text, *dwgp)) >= DWG_ERR_CRITICAL)
{
LOG_ERROR ("Invalid readdxf \"%s\" => error 0x%x", text,
error);
exit (1);
}
dwg = *dwgp;
ADD_INITIAL;
p = next_line (p, end);
continue;
}
Expand All @@ -781,9 +790,9 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
}
else if (memBEGINc (p, "readjson"))
{
if (dwg)
if (!initial || dwg->num_objects)
{
LOG_ERROR ("readjson seen, but DWG already exists");
LOG_ERROR ("readjson seen, but DWG already initialized");
exit (1);
}
if (1 == SSCANF_S (p, "readjson " FMT_PATH, text SZ))
Expand All @@ -795,14 +804,17 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
dat_read_file (&in_dat, in_dat.fh, text);
if (!in_dat.fh
|| (error = dwg_read_json (&in_dat, *dwgp))
> DWG_ERR_CRITICAL)
>= DWG_ERR_CRITICAL)
{
LOG_ERROR ("Invalid readjson \"%s\" => error 0x%x", text,
error);
free (in_dat.chain);
exit (1);
}
fclose (in_dat.fh);
free (in_dat.chain);
dwg = *dwgp;
ADD_INITIAL;
p = next_line (p, end);
continue;
}
Expand All @@ -814,7 +826,7 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
}
else if (memBEGINc (p, "imperial"))
{
if (!initial)
if (!initial || dwg->num_objects)
{
LOG_ERROR ("`imperial' directive out of header section");
exit (1);
Expand All @@ -829,7 +841,7 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
double f_ver;
char s_ver[16];

if (!initial)
if (!initial || dwg->num_objects)
{
LOG_ERROR ("`version' directive out of header section");
exit (1);
Expand Down Expand Up @@ -865,11 +877,7 @@ dwg_add_dat (Dwg_Data **dwgp, Bit_Chain *dat)
else
dwg_add_Document (dwg, imperial);
*dwgp = dwg;

mspace = dwg_model_space_object (dwg);
hdr = mspace ? mspace->tio.object->tio.BLOCK_HEADER : NULL;
orig_num = dwg->num_objects;
initial = 0;
ADD_INITIAL;
LOG_TRACE ("==========================================\n");
}

Expand Down
45 changes: 42 additions & 3 deletions examples/dwgadd_test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ abs_builddir="@abs_builddir@"
top_builddir="@top_builddir@"
EXEEXT="@EXEEXT@"
TESTS_ENVIRONMENT="@AM_TESTS_ENVIRONMENT@"
HAVE_ASAN="@HAVE_ASAN@"
srcdir="@abs_srcdir@"
echo srcdir: "$srcdir"

Expand Down Expand Up @@ -34,7 +35,7 @@ dwgaddtest() {
ret=$?
else
#PRE=
#if test "$V" = "r1.4" -a -n "@HAVE_ASAN@"
#if test "$V" = "r1.4" -a -n $HAVE_ASAN
#then
# PRE="env ASAN_OPTIONS=detect_leaks=0"
#fi
Expand Down Expand Up @@ -102,8 +103,46 @@ dwgaddtest AC1015 r2000 $tmp

echo "point (0 0 0)" >$tmp
cat $tmp
dwgaddtest AC1015 r2000 $tmp
dwgaddtest AC1009 r11 $tmp
dwgaddtest AC1015 r2000 $tmp

echo "readdwg \"dwgadd_test.dwg\"" >$tmp
echo "point (10 0 0)" >>$tmp
cat $tmp
dwgaddtest AC1015 r2000 $tmp

if [ -f "$abs_builddir"/../dxf ]; then
cd "$abs_builddir"/.. || exit 1
./dxf -o examples/dwgadd_test.dxf examples/dwgadd_test.dwg
rm -f -- ./dwgadd_test_examples.log
cd "$abs_builddir" || exit 1
if [ -f dwgadd_test.dxf ]; then
echo "readdxf \"dwgadd_test.dxf\"" >$tmp
echo "point (10 0 0)" >>$tmp
cat $tmp
if [ "$HAVE_ASAN" = "yes" ]
then
env ASAN_OPTIONS=detect_leaks=0 dwgaddtest AC1015 r2000 $tmp
else
dwgaddtest AC1015 r2000 $tmp
fi
fi
fi

if [ -f "$abs_builddir"/../json ]; then
cd "$abs_builddir"/.. || exit 1
cp examples/dwgadd_test.dwg .
./json dwgadd_test.dwg
mv dwgadd_test.json examples/
rm -f dwgadd_test.dwg dwgadd_test.log
cd "$abs_builddir" || exit 1
if [ -f dwgadd_test.json ]; then
echo "readjson \"dwgadd_test.json\"" >$tmp
echo "point (20 0 0)" >>$tmp
cat $tmp
dwgaddtest AC1015 r2000 $tmp
fi
fi

# cleanup
rm -f dwgadd_test.dwg $tmp
rm -f -- dwgadd_test.dwg dwgadd_test.dxf dwgadd_test.json $tmp
Loading