1 // This file is part of Deark.
2 // Copyright (C) 2017 Jason Summers
3 // See the file COPYING for terms of use.
5 // AutoCAD Slide Library (.slb)
7 #include <deark-config.h>
8 #include <deark-private.h>
9 DE_DECLARE_MODULE(de_module_autocad_slb
);
11 static void de_run_autocad_slb(deark
*c
, de_module_params
*mparams
)
21 struct slideinfo
*si
= NULL
;
22 de_ucstring
*slidename
= NULL
;
24 de_dbg(c
, "[pass 1: recording addresses]");
26 si
= de_mallocarray(c
, si_numalloc
, sizeof(struct slideinfo
));
31 if(pos
> (c
->infile
->len
-36)) {
32 de_err(c
, "Unterminated directory");
35 if(de_getbyte(pos
)==0) {
39 k
= nslides
; // Index of the new slide
42 if(nslides
> si_numalloc
) {
43 i64 old_numalloc
, new_numalloc
;
45 if(!de_good_image_count(c
, nslides
)) {
46 de_err(c
, "Too many slides");
49 old_numalloc
= si_numalloc
;
50 new_numalloc
= old_numalloc
*2;
51 si
= de_reallocarray(c
, si
, old_numalloc
, sizeof(struct slideinfo
),
53 si_numalloc
= new_numalloc
;
56 si
[k
].pos
= de_getu32le(pos
+32);
58 if(si
[k
].pos
> c
->infile
->len
) {
59 de_err(c
, "Invalid directory");
63 if(si
[k
].pos
< si
[k
-1].pos
) {
64 de_err(c
, "Invalid directory");
70 // Set the previous slide's length.
71 si
[k
-1].len
= si
[k
].pos
- si
[k
-1].pos
;
73 // Start by assuming this slide ends at the end of the file. If this
74 // turns out not to be the last slide, this value will be changed later.
75 si
[k
].len
= c
->infile
->len
- si
[k
].pos
;
80 de_dbg(c
, "[pass 2: extracting slides]");
82 slidename
= ucstring_create(c
);
83 for(k
=0; k
<nslides
; k
++) {
86 de_dbg(c
, "slide dir entry at %d", (int)pos
);
89 ucstring_empty(slidename
);
90 dbuf_read_to_ucstring(c
->infile
, pos
, 31, slidename
,
91 DE_CONVFLAG_STOP_AT_NUL
, DE_ENCODING_ASCII
);
93 de_dbg(c
, "address: %u", (unsigned int)si
[k
].pos
);
94 de_dbg(c
, "calculated len: %u", (unsigned int)si
[k
].len
);
96 fi
= de_finfo_create(c
);
97 de_finfo_set_name_from_ucstring(c
, fi
, slidename
, 0);
98 dbuf_create_file_from_slice(c
->infile
, si
[k
].pos
, si
[k
].len
, "sld", fi
, 0);
99 de_finfo_destroy(c
, fi
);
101 de_dbg_indent(c
, -1);
106 ucstring_destroy(slidename
);
110 static int de_identify_autocad_slb(deark
*c
)
112 if(!dbuf_memcmp(c
->infile
, 0, "AutoCAD Slide Library 1.0\r\n\x1a", 28))
117 void de_module_autocad_slb(deark
*c
, struct deark_module_info
*mi
)
119 mi
->id
= "autocad_slb";
120 mi
->desc
= "AutoCAD Slide Library";
121 mi
->run_fn
= de_run_autocad_slb
;
122 mi
->identify_fn
= de_identify_autocad_slb
;