Debian Codegraph @

src/tools/file/file.cpp

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw: tools
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
18 *
19 *
20 * All Rights Reserved.
21 *
22 * For minor contributions see the git repository.
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26 * in which case the provisions of the LGPLv2+ are applicable
27 * instead of those above.
28 */
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33
34 #include <iomanip>
35 #include <iostream>
36 #include <memory>
37 #include <string>
38 #include <sstream>
39
40 #include "file_internal.h"
41 #include "input.h"
42 #include "ole.h"
43 #include "rsrc.h"
44 #include "xattr.h"
45
46 #include <sys/stat.h>
47
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51
52 #ifndef VERSION
53 #define VERSION "UNKNOWN VERSION"
54 #endif
55
56 namespace libmwaw_tools
57 {
58 class Exception
59 {
60 };
61
62 struct File {
63 //! the constructor
64 explicit File(char const *path)
65 : m_fName(path ? path : "")
66 , m_fInfoCreator("")
67 , m_fInfoType("")
68 , m_fInfoResult("")
69 , m_fileVersion()
70 , m_appliVersion()
71 , m_rsrcMissingMessage("")
72 , m_rsrcResult("")
73 , m_dataResult()
74 , m_printFileName(false)
75 {
76 if (m_fName.empty()) {
77 std::cerr << "File::File: call without path\n";
78 throw libmwaw_tools::Exception();
79 }
80
81 // check if it is a regular file
82 struct stat status;
83 if (!path || stat(path, &status) == -1) {
84 std::cerr << "File::File: the file " << m_fName << " cannot be read\n";
85 throw libmwaw_tools::Exception();
86 }
87 if (!S_ISREG(status.st_mode)) {
88 std::cerr << "File::File: the file " << m_fName << " is a not a regular file\n";
89 throw libmwaw_tools::Exception();
90 }
91 }
92
93 //! operator<<
94 friend std::ostream &operator<<(std::ostream &o, File const &info)
95 {
96 if (info.m_printFileName)
97 o << info.m_fName << ":\n";
98 if (info.m_fInfoCreator.length() || info.m_fInfoType.length()) {
99 o << "------- fileInfo -------\n";
100 if (info.m_fInfoCreator.length())
101 o << "\tcreator=" << info.m_fInfoCreator << "\n";
102 if (info.m_fInfoType.length())
103 o << "\ttype=" << info.m_fInfoType << "\n";
104 if (info.m_fInfoResult.length())
105 o << "\t\t=>" << info.m_fInfoResult << "\n";
106 }
107 if (info.m_fileVersion.ok() || info.m_appliVersion.ok() ||
108 info.m_rsrcMissingMessage.length() || info.m_rsrcResult.length()) {
109 o << "------- resource fork -------\n";
110 if (info.m_fileVersion.ok())
111 o << "\tFile" << info.m_fileVersion << "\n";
112 if (info.m_appliVersion.ok())
113 o << "\tAppli" << info.m_appliVersion << "\n";
114 if (info.m_rsrcMissingMessage.length())
115 o << "\tmissingString=\"" << info.m_rsrcMissingMessage << "\"\n";
116 if (info.m_rsrcResult.length())
117 o << "\t\t=>" << info.m_rsrcResult << "\n";
118 }
119 if (info.m_dataResult.size()) {
120 o << "------- data fork -------\n";
121 for (auto const &res : info.m_dataResult)
122 o << "\t\t=>" << res << "\n";
123 }
124 return o;
125 }
126
127 //! try to read the file information
128 bool readFileInformation();
129 //! try to read the data fork
130 bool readDataInformation();
131 //! try to read the resource version data
132 bool readRSRCInformation();
133
134 //! can type the file
135 bool canPrintResult(int verbose) const
136 {
137 if (m_fInfoResult.length() || m_dataResult.size() || m_rsrcResult.length()) return true;
138 if (verbose <= 0) return false;
139 if (m_fInfoCreator.length() || m_fInfoType.length()) return true;
140 if (verbose <= 1) return false;
141 return m_fileVersion.ok() || m_appliVersion.ok();
142 }
143 //! print the file type
144 bool printResult(std::ostream &o, int verbose) const;
145
146 bool checkFInfoType(char const *type, char const *result)
147 {
148 if (m_fInfoType != type) return false;
149 m_fInfoResult=result;
150 return true;
151 }
152 bool checkFInfoType(char const *result)
153 {
154 m_fInfoResult=result;
155 if (m_fInfoType=="AAPL")
156 m_fInfoResult+="[Application]";
157 else if (m_fInfoType=="AIFF" || m_fInfoType=="AIFC")
158 m_fInfoResult+="[sound]";
159 else
160 m_fInfoResult+="["+m_fInfoType+"]";
161 return true;
162 }
163 bool checkFInfoCreator(char const *result)
164 {
165 m_fInfoResult=result;
166 if (m_fInfoCreator.length())
167 m_fInfoResult+="["+m_fInfoCreator+"]";
168 return true;
169 }
170
171 //! the file name
172 std::string m_fName;
173 //! the file info creator
174 std::string m_fInfoCreator;
175 //! the file info type
176 std::string m_fInfoType;
177 //! the result of the finfo
178 std::string m_fInfoResult;
179
180 //! the file version (extracted from the resource fork )
181 RSRC::Version m_fileVersion;
182 //! the application version (extracted from the resource fork )
183 RSRC::Version m_appliVersion;
184 //! the application missing message
185 std::string m_rsrcMissingMessage;
186 //! the result of the resource fork
187 std::string m_rsrcResult;
188
189 //! the result of the data analysis
190 std::vector<std::string> m_dataResult;
191
192 //! print or not the filename
193 bool m_printFileName;
194 };
195
196 bool File::readFileInformation()
197 {
198 if (!m_fName.length())
199 return false;
200
201 XAttr xattr(m_fName.c_str());
202 std::unique_ptr<InputStream> input{xattr.getStream("com.apple.FinderInfo")};
203 if (!input) return false;
204
205 if (input->length() < 8) {
206 return false;
207 }
208
209 input->seek(0, libmwaw_tools::InputStream::SK_SET);
210 m_fInfoType = "";
211 for (int i = 0; i < 4; i++) {
212 char c= input->read8();
213 if (c==0) break;
214 m_fInfoType+= c;
215 }
216 m_fInfoCreator="";
217 for (int i = 0; i < 4; i++) {
218 char c= input->read8();
219 if (c==0) break;
220 m_fInfoCreator+= c;
221 }
222
223 if (m_fInfoCreator=="" || m_fInfoType=="")
224 return true;
225 if (m_fInfoCreator=="2CTY") {
226 checkFInfoType("SPUB", "PublishIt") || checkFInfoType("PublishIt");
227 }
228 else if (m_fInfoCreator=="AB65") {
229 checkFInfoType("AD65", "Pagemaker6.5") ||
230 checkFInfoType("AT65", "Pagemaker6.5[template]") ||
231 checkFInfoType("Pagemaker6.5");
232 }
233 else if (m_fInfoCreator=="ACTA") {
234 checkFInfoType("OTLN", "Acta") || checkFInfoType("otln", "Acta") || checkFInfoType("Acta");
235 }
236 else if (m_fInfoCreator=="ALB3") {
237 checkFInfoType("ALD3", "Pagemaker3") || checkFInfoType("Pagemaker3");
238 }
239 else if (m_fInfoCreator=="ALB4") {
240 checkFInfoType("ALD4", "Pagemaker4") || checkFInfoType("Pagemaker4");
241 }
242 else if (m_fInfoCreator=="ALB5") {
243 checkFInfoType("ALD5", "Pagemaker5") || checkFInfoType("Pagemaker5");
244 }
245 else if (m_fInfoCreator=="ALB6") {
246 checkFInfoType("ALD6", "Pagemaker6") || checkFInfoType("Pagemaker6");
247 }
248 else if (m_fInfoCreator=="AOqc") {
249 checkFInfoType("TEXT","America Online") || checkFInfoType("ttro","America Online[readOnly]") ||
250 checkFInfoType("America Online");
251 }
252 else if (m_fInfoCreator=="AOS1") {
253 checkFInfoType("TEXT","eWorld") || checkFInfoType("ttro","eWorld[readOnly]") ||
254 checkFInfoType("eWorld");
255 }
256 else if (m_fInfoCreator=="APBP") {
257 checkFInfoType("APBL", "Drawing Table") || checkFInfoType("Drawing Table");
258 }
259 else if (m_fInfoCreator=="ARTX") {
260 checkFInfoType("RIFF","Corel Painter X") || checkFInfoType("Corel Painter X");
261 }
262 else if (m_fInfoCreator=="BOBO") {
263 checkFInfoType("CWDB","ClarisWorks/AppleWorks[Database]")||
264 checkFInfoType("CWD2","ClarisWorks/AppleWorks 2.0-3.0[Database]")||
265 checkFInfoType("sWDB","ClarisWorks/AppleWorks 2.0-3.0[Database]")||
266 checkFInfoType("CWGR","ClarisWorks/AppleWorks[Draw]")||
267 checkFInfoType("sWGR","ClarisWorks/AppleWorks 2.0-3.0[Draw]")||
268 checkFInfoType("CWSS","ClarisWorks/AppleWorks[SpreadSheet]")||
269 checkFInfoType("CWS2","ClarisWorks/AppleWorks 2.0-3.0[SpreadSheet]")||
270 checkFInfoType("sWSS","ClarisWorks/AppleWorks 2.0-3.0[SpreadSheet]")||
271 checkFInfoType("CWPR","ClarisWorks/AppleWorks[Presentation]")||
272 checkFInfoType("CWPT","ClarisWorks/AppleWorks[Paint]")||
273 checkFInfoType("CWWP","ClarisWorks/AppleWorks")||
274 checkFInfoType("CWW2","ClarisWorks/AppleWorks 2.0-3.0")||
275 checkFInfoType("sWWP","ClarisWorks/AppleWorks 2.0-3.0")||
276 checkFInfoType("ClarisWorks/AppleWorks");
277 }
278 else if (m_fInfoCreator=="BWks") {
279 checkFInfoType("BWwp","BeagleWorks/WordPerfect Works") ||
280 checkFInfoType("BWdb","BeagleWorks/WordPerfect Works[Database]") ||
281 checkFInfoType("BWss","BeagleWorks/WordPerfect Works[SpreadSheet]") ||
282 checkFInfoType("BWpt","BeagleWorks/WordPerfect Works[Paint]") ||
283 checkFInfoType("BWdr","BeagleWorks/WordPerfect Works[Draw]") ||
284 checkFInfoType("BeagleWorks/WordPerfect Works");
285 }
286 else if (m_fInfoCreator=="CARO") {
287 checkFInfoType("PDF ", "Acrobat PDF");
288 }
289 else if (m_fInfoCreator=="C#+A") {
290 checkFInfoType("C#+D","RagTime 5") || checkFInfoType("C#+F","RagTime 5[form]") ||
291 checkFInfoType("RagTime 5");
292 }
293 else if (m_fInfoCreator=="CDrw") {
294 checkFInfoType("dDrw", "ClarisDraw") || checkFInfoType("dDst", "ClarisDraw[stationary]") ||
295 checkFInfoType("iLib", "ClarisDraw[library]") || checkFInfoType("ClarisDraw");
296 }
297 else if (m_fInfoCreator=="CRDW") {
298 checkFInfoType("CKDT","CricketDraw") || checkFInfoType("CricketDraw");
299 }
300 else if (m_fInfoCreator.substr(0,3)=="DAD") {
301 if (m_fInfoCreator=="DAD2") {
302 checkFInfoType("drw2","Canvas 2-3") || checkFInfoType("Canvas 2-3");
303 }
304 else if (m_fInfoCreator=="DAD5") {
305 checkFInfoType("drw5","Canvas 5") || checkFInfoType("drwt","Canvas 5[template]") ||
306 checkFInfoType("VINF","Canvas 5[image]") || checkFInfoType("Canvas 5");
307 }
308 else if (m_fInfoCreator=="DAD6") {
309 checkFInfoType("drw6","Canvas 6") || checkFInfoType("drwt","Canvas 6[template]") ||
310 checkFInfoType("VINF","Canvas 6[image]") || checkFInfoType("Canvas 6");
311 }
312 else if (m_fInfoCreator=="DAD7") {
313 checkFInfoType("drw7","Canvas 7") || checkFInfoType("drwt","Canvas 7[template]") ||
314 checkFInfoType("VINF","Canvas 7[image]") || checkFInfoType("Canvas 7");
315 }
316 else if (m_fInfoCreator=="DAD8") {
317 checkFInfoType("drw8","Canvas 8") || checkFInfoType("drwt","Canvas 8[template]") ||
318 checkFInfoType("VINF","Canvas 8[image]") || checkFInfoType("Canvas 8");
319 }
320 else if (m_fInfoCreator=="DAD9") {
321 checkFInfoType("drwX","Canvas 9") || checkFInfoType("drwt","Canvas 9[template]") ||
322 checkFInfoType("Canvas 9");
323 }
324 else if (m_fInfoCreator=="DADX") {
325 checkFInfoType("drwX","Canvas X") || checkFInfoType("drwt","Canvas X[template]") ||
326 checkFInfoType("Canvas X");
327 }
328 }
329 else if (m_fInfoCreator=="DkmR") {
330 checkFInfoType("TEXT","Basic text(created by DOCMaker)") || checkFInfoType("DOCMaker");
331 }
332 else if (m_fInfoCreator=="Dc@P" || m_fInfoCreator=="Dk@P") {
333 checkFInfoType("APPL","DOCMaker") || checkFInfoType("DOCMaker");
334 }
335 else if (m_fInfoCreator=="DDAP") {
336 checkFInfoType("DDFL+","DiskDoubler") || checkFInfoType("DiskDoubler");
337 }
338 else if (m_fInfoCreator=="FAIR") {
339 checkFInfoType("FWXX","Fair Witness") || checkFInfoType("Fair Witness");
340 }
341 else if (m_fInfoCreator=="FH50") {
342 checkFInfoType("AGD1","FreeHand 5") || checkFInfoType("FreeHand 5");
343 }
344 else if (m_fInfoCreator=="FHA2") {
345 checkFInfoType("FHD2","FreeHand 2") || checkFInfoType("FHT2","FreeHand 2[template]") || checkFInfoType("FreeHand 2");
346 }
347 else if (m_fInfoCreator=="FHA3") {
348 checkFInfoType("FHD3","FreeHand 3") || checkFInfoType("FreeHand 3");
349 }
350 else if (m_fInfoCreator=="FMPR") {
351 checkFInfoType("FMPR","Claris FileMaker Pro") || checkFInfoType("Claris FileMaker Pro");
352 }
353 else if (m_fInfoCreator=="FS03") {
354 checkFInfoType("WRT+","WriterPlus") || checkFInfoType("WriterPlus");
355 }
356 else if (m_fInfoCreator=="FSDA") {
357 checkFInfoType("RIFF","Dabbler 1") || checkFInfoType("Dabbler 1");
358 }
359 else if (m_fInfoCreator=="FSPS") {
360 checkFInfoType("RIFF","Painter 1") || checkFInfoType("FSPP","Painter[texture]") || checkFInfoType("Painter 1");
361 }
362 else if (m_fInfoCreator=="FSX3") {
363 checkFInfoType("RIFF","Painter 3-6") || checkFInfoType("FSFS","Painter 3-6[movie]") || checkFInfoType("Painter 3-6");
364 }
365 else if (m_fInfoCreator=="Fram") {
366 checkFInfoType("FASL","FrameMaker") || checkFInfoType("MIF2","FrameMaker MIF2.0") ||
367 checkFInfoType("MIF3","FrameMaker MIF3.0") || checkFInfoType("MIF ","FrameMaker MIF") ||
368 checkFInfoType("FrameMaker");
369 }
370 else if (m_fInfoCreator=="FWRT") {
371 checkFInfoType("FWRT","FullWrite 1.0") || checkFInfoType("FWRM","FullWrite 1.0") ||
372 checkFInfoType("FWRI","FullWrite 2.0") || checkFInfoType("FullWrite");
373 }
374 else if (m_fInfoCreator=="F#+A") {
375 checkFInfoType("F#+D","RagTime Classic") || checkFInfoType("F#+F","RagTime Classic[form]") ||
376 checkFInfoType("RagTime Classic");
377 }
378 else if (m_fInfoCreator=="GM01") {
379 checkFInfoType("GfMt","MouseWrite") || checkFInfoType("MouseWrite");
380 }
381 else if (m_fInfoCreator=="JAZZ") { // Jazz Lotus
382 checkFInfoType("JWKS","Jazz(spreadsheet)") || checkFInfoType("JWPD","Jazz(text)") || checkFInfoType("Jazz");
383 }
384 else if (m_fInfoCreator=="JWrt") {
385 checkFInfoType("TEXT","JoliWrite") || checkFInfoType("ttro","JoliWrite[readOnly]") ||
386 checkFInfoType("JoliWrite");
387 }
388 else if (m_fInfoCreator=="HMiw") {
389 checkFInfoType("IWDC","HanMac Word-J") || checkFInfoType("HanMac Word-J");
390 }
391 else if (m_fInfoCreator=="HMdr") {
392 checkFInfoType("DRD2","HanMac Word-K") || checkFInfoType("HanMac Word-K");
393 }
394 else if (m_fInfoCreator=="L123") {
395 checkFInfoType("LWKS","Lotus123") || checkFInfoType("Lotus123");
396 }
397 else if (m_fInfoCreator=="LibW") {
398 checkFInfoType("Chnk","Microspot Media Assistant") || checkFInfoType("Microspot Media Assistant");
399 }
400 else if (m_fInfoCreator=="LETR") {
401 checkFInfoType("APPL","Take A Letter[auto]") || checkFInfoType("Take A Letter");
402 }
403 else if (m_fInfoCreator=="LMAN") { // tutorial installed with canvas
404 checkFInfoType("TEXT","Canvas 7") || checkFInfoType("Canvas 7");
405 }
406 else if (m_fInfoCreator=="LWTE") {
407 checkFInfoType("TEXT","LightWayText") || checkFInfoType("MACR","LightWayText[MACR]") ||
408 checkFInfoType("pref","LightWayText[Preferences]") ||
409 checkFInfoType("ttro","LightWayText[Tutorial]") || checkFInfoType("LightWayText");
410 }
411 else if (m_fInfoCreator=="LWTR") {
412 checkFInfoType("APPL","LightWayText[appli]") || checkFInfoType("LightWayText");
413 }
414 else if (m_fInfoCreator=="MACA") {
415 checkFInfoType("WORD","MacWrite") || checkFInfoType("MacWrite");
416 }
417 else if (m_fInfoCreator=="MACD") {
418 checkFInfoType("DRWG","MacDraft 1.0") || checkFInfoType("MacDraft 1.0");
419 }
420 else if (m_fInfoCreator=="MACW") {
421 checkFInfoType("MWCT","MaxWrite 1.0") || checkFInfoType("MaxWrite 1.0");
422 }
423 else if (m_fInfoCreator=="MART") {
424 checkFInfoType("RSGF","ReadySetGo 1") || checkFInfoType("RSGI","ReadySetGo 2") || checkFInfoType("ReadySetGo 1/2");
425 }
426 else if (m_fInfoCreator=="MD40") {
427 checkFInfoType("MDDC","MacDraft 4-5") || checkFInfoType("MSYM","MacDraft 4-5[lib]") ||
428 checkFInfoType("MacDraft 4-5");
429 }
430 else if (m_fInfoCreator=="MDsr") {
431 checkFInfoType("APPL","MacDoc(appli)") || checkFInfoType("MacDoc");
432 }
433 else if (m_fInfoCreator=="MDvr") {
434 checkFInfoType("MDdc","MacDoc") || checkFInfoType("MacDoc");
435 }
436 else if (m_fInfoCreator=="MDFT") {
437 checkFInfoType("DRWG","MacDraft 1.2") || checkFInfoType("MacDraft 1.2");
438 }
439 else if (m_fInfoCreator=="MDRW") {
440 checkFInfoType("DRWG","MacDraw") || checkFInfoType("MacDraw");
441 }
442 else if (m_fInfoCreator=="MDPL") {
443 checkFInfoType("DRWG","MacDraw II") || checkFInfoType("STAT","MacDraw II(template)") || checkFInfoType("MacDraw II");
444 }
445 else if (m_fInfoCreator=="MEMR") {
446 checkFInfoType("RSGR","ReadySetGo 4.5") || checkFInfoType("ReadySetGo 4.5");
447 }
448 else if (m_fInfoCreator=="MMBB") {
449 checkFInfoType("MBBT","Mariner Write") || checkFInfoType("Mariner Write");
450 }
451 else if (m_fInfoCreator=="MORE") {
452 checkFInfoType("MORE","More") || checkFInfoType("More");
453 }
454 else if (m_fInfoCreator=="MOR2") {
455 checkFInfoType("MOR2","More 2") || checkFInfoType("MOR3","More 3") ||
456 checkFInfoType("More 2-3");
457 }
458 else if (m_fInfoCreator=="MPNT") {
459 checkFInfoType("PNTG","MacPaint") || checkFInfoType("MacPaint");
460 }
461 else if (m_fInfoCreator=="MRJN") {
462 checkFInfoType("DSTD","DesignStudio 2") || checkFInfoType("DesignStudio 2");
463 }
464 else if (m_fInfoCreator=="MRSM") {
465 checkFInfoType("RSGJ","ReadySetGo 3") || checkFInfoType("RSGK","ReadySetGo 4") || checkFInfoType("ReadySetGo 3/4");
466 }
467 else if (m_fInfoCreator=="MROS") {
468 checkFInfoType("MG6F","ReadySetGo 6/7") || checkFInfoType("TEXT","ReadySetGo 6/7[text]") || checkFInfoType("ReadySetGo 6/7");
469 }
470 else if (m_fInfoCreator=="MSWD") {
471 checkFInfoType("WDBN","Microsoft Word 3-5") ||
472 checkFInfoType("GLOS","Microsoft Word 3-5[glossary]") ||
473 checkFInfoType("W6BN", "Microsoft Word 6") ||
474 checkFInfoType("W8BN", "Microsoft Word 8") ||
475 checkFInfoType("W8TN", "Microsoft Word 8[W8TN]") || // ?
476 checkFInfoType("WXBN", "Microsoft Word 97-2004") || // Office X ?
477 checkFInfoType("Microsoft Word");
478 }
479 else if (m_fInfoCreator=="MSWK") {
480 checkFInfoType("AWWP","Microsoft Works 3") ||
481 checkFInfoType("AWDB","Microsoft Works 3-4[database]") ||
482 checkFInfoType("AWDR","Microsoft Works 3-4[draw]") ||
483 checkFInfoType("AWSS","Microsoft Works 3-4[spreadsheet]") ||
484 checkFInfoType("RLRB","Microsoft Works 4") ||
485 checkFInfoType("sWRB","Microsoft Works 4[template]") ||
486 checkFInfoType("Microsoft Works 3-4");
487 }
488 else if (m_fInfoCreator=="MWII") {
489 checkFInfoType("MW2D","MacWrite II") || checkFInfoType("MacWrite II");
490 }
491 else if (m_fInfoCreator=="MWPR") {
492 checkFInfoType("MWPd","MacWrite Pro") || checkFInfoType("MacWrite Pro");
493 }
494 else if (m_fInfoCreator=="NISI") {
495 checkFInfoType("TEXT","Nisus") || checkFInfoType("GLOS","Nisus[glossary]") ||
496 checkFInfoType("SMAC","Nisus[macros]") || checkFInfoType("edtt","Nisus[lock]") ||
497 checkFInfoType("Nisus");
498 }
499 else if (m_fInfoCreator=="PaPy") {
500 checkFInfoType("PAPD","Papyrus") || checkFInfoType("Papyrus");
501 }
502 else if (m_fInfoCreator=="PANT") {
503 checkFInfoType("PANT","FullPaint") || checkFInfoType("FullPaint");
504 }
505 else if (m_fInfoCreator=="PIXR") {
506 checkFInfoType("PX01","Pixel Paint") || checkFInfoType("Pixel Paint");
507 }
508 else if (m_fInfoCreator=="PLAN") {
509 checkFInfoType("MPBN","MultiPlan") || checkFInfoType("MultiPlan");
510 }
511 else if (m_fInfoCreator=="PPNT") {
512 checkFInfoType("SLDS","Microsoft PowerPoint") || checkFInfoType("Microsoft PowerPoint v1/2");
513 }
514 else if (m_fInfoCreator=="PPT3") {
515 checkFInfoType("SLD3","Microsoft PowerPoint v3.0") || checkFInfoType("SLD8","Microsoft PowerPoint 97-2004") ||
516 checkFInfoType("Microsoft PowerPoint");
517 }
518 else if (m_fInfoCreator=="PSIP") {
519 checkFInfoType("AWWP","Microsoft Works 1.0") || checkFInfoType("Microsoft Works 1.0");
520 }
521 else if (m_fInfoCreator=="PSI2") {
522 checkFInfoType("AWWP","Microsoft Works 2.0") || checkFInfoType("AWDB","Microsoft Works 2.0[database]") ||
523 checkFInfoType("AWSS","Microsoft Works 2.0[spreadsheet]") || checkFInfoType("Microsoft Works 2.0");
524 }
525 else if (m_fInfoCreator=="PWRI") {
526 checkFInfoType("OUTL","MindWrite") || checkFInfoType("MindWrite");
527 }
528 else if (m_fInfoCreator=="R#+A") {
529 checkFInfoType("R#+D","RagTime") || checkFInfoType("R#+F","RagTime[form]") ||
530 checkFInfoType("RagTime");
531 }
532 else if (m_fInfoCreator=="RTF ") {
533 checkFInfoType("RTF ","RTF ") || checkFInfoType("RTF");
534 }
535 else if (m_fInfoCreator=="Rslv") {
536 checkFInfoType("RsWs","Claris Resolve") || checkFInfoType("Claris Resolve");
537 }
538 else if (m_fInfoCreator=="SIT!") {
539 checkFInfoType("SIT5", "archive SIT") ||
540 checkFInfoType("SITD", "archive SIT") ||
541 checkFInfoType("SIT!", "archive SIT") || checkFInfoType("SIT");
542 }
543 else if (m_fInfoCreator=="SPNT") {
544 checkFInfoType("SPTG","SuperPaint 1.") || checkFInfoType("PICT","SuperPaint 2.[pict]") ||
545 checkFInfoType("DTXR","SuperPaint 3.[texture,pict]") || /* pict without 512 header*/
546 checkFInfoType("PNTG","SuperPaint 3.[macpaint]") || /* MacPaint format*/
547 checkFInfoType("PTXR","SuperPaint 3.[texture,pict]") || /* pict without 512 header*/
548 checkFInfoType("SPn3","SuperPaint 3.[pict]") || checkFInfoType("SPSt","SuperPaint 3.[pict,stationary]") ||
549 checkFInfoType("SuperPaint");
550 }
551 else if (m_fInfoCreator=="SSIW") { // check me
552 checkFInfoType("WordPerfect 1.0");
553 }
554 else if (m_fInfoCreator==std::string("St")+char(0xd8)+"l") { // argh, not standart character
555 std::string type1=std::string("TEd")+char(0xb6); // argh, not standart character
556 checkFInfoType(type1.c_str(), "Style") || checkFInfoType("Style");
557 }
558 else if (m_fInfoCreator=="StAV") {
559 checkFInfoType("APPL", "Style[auto]") || checkFInfoType("Style");
560 }
561 else if (m_fInfoCreator=="SVsc") {
562 checkFInfoType("SVsc", "StarCalc 3.0") || checkFInfoType("StarCalc 3.0");
563 }
564 else if (m_fInfoCreator=="SVsd") {
565 checkFInfoType("SVsd", "StarDraw 3.0") || checkFInfoType("StarDraw 3.0");
566 }
567 else if (m_fInfoCreator==std::string("SW/")+char(0xa9)) {
568 std::string type1=std::string("SW/")+char(0xa9);
569 checkFInfoType(type1.c_str(), "StarWriter 3.0") || checkFInfoType("StarWriter 3.0");
570 }
571 else if (m_fInfoCreator=="SWCM") {
572 checkFInfoType("JRNL","Student Writing Center[journal]") || checkFInfoType("LTTR","Student Writing Center[letter]") ||
573 checkFInfoType("RPRT","Student Writing Center[report]") || checkFInfoType("SIGN","Student Writing Center[sign]") ||
574 checkFInfoType("Student Writing Center");
575 }
576 else if (m_fInfoCreator=="TBB5") {
577 checkFInfoType("TEXT","Tex-Edit") || checkFInfoType("ttro","Tex-Edit[readOnly]") ||
578 checkFInfoType("Tex-Edit");
579 }
580 else if (m_fInfoCreator=="VPUB") {
581 // Ventura Publisher 3
582 // For note, probably easy to create a parser but this application stores a document in multiple files.
583 checkFInfoType("Ventura Publisher");
584 }
585 else if (m_fInfoCreator=="WILD") {
586 checkFInfoType("STAK", "HyperCard") || checkFInfoType("HyperCard");
587 }
588 else if (m_fInfoCreator=="WMkr") {
589 checkFInfoType("Word","WordMaker") || checkFInfoType("WSta","WordMaker[template]") || checkFInfoType("WordMaker");
590 }
591 else if (m_fInfoCreator=="WNGZ") {
592 checkFInfoType("WZSS","Wingz[spreadsheet]") || checkFInfoType("WZSC","Wingz[script]") ||
593 checkFInfoType("Wingz");
594 }
595 else if (m_fInfoCreator=="WORD") {
596 checkFInfoType("WDBN","Microsoft Word 1") || checkFInfoType("Microsoft Word 1");
597 }
598 else if (m_fInfoCreator=="WPC2") {
599 checkFInfoType("WordPerfect");
600 }
601 else if (m_fInfoCreator=="XCEL") {
602 checkFInfoType("XCEL","Microsoft Excel 1") ||
603 checkFInfoType("XLS3","Microsoft Excel 3") ||
604 checkFInfoType("XLS4","Microsoft Excel 4") ||
605 checkFInfoType("XLS5","Microsoft Excel 5") ||
606 checkFInfoType("XLS8","Microsoft Excel 97-2004") ||
607 checkFInfoType("TEXT","Microsoft Excel[text export]") ||
608 checkFInfoType("Microsoft Excel");
609 }
610 else if (m_fInfoCreator=="XPR3") {
611 checkFInfoType("XDOC","QuarkXPress 3-4") ||
612 checkFInfoType("XTMP","QuarkXPress 3-4[template]") ||
613 checkFInfoType("XBOK","QuarkXPress 4[book]") ||
614 checkFInfoType("XLIB","QuarkXPress 3-4[library]") ||
615 checkFInfoType("QuarkXPress 3-4");
616 }
617 else if (m_fInfoCreator=="XPRS") {
618 checkFInfoType("XDOC","QuarkXPress 1-2") || checkFInfoType("QuarkXPress 1-2");
619 }
620 else if (m_fInfoCreator=="ZEBR") {
621 checkFInfoType("ZWRT","GreatWorks") || checkFInfoType("ZTRM","GreatWorks[comm]") ||
622 checkFInfoType("ZDBS","GreatWorks[database]") || checkFInfoType("ZCAL","GreatWorks[spreadsheet]") ||
623 checkFInfoType("ZOLN","GreatWorks[outline]") || checkFInfoType("PNTG","GreatWorks v1[paint]") ||
624 checkFInfoType("ZPNT","GreatWorks v2[paint]") || checkFInfoType("ZOBJ","GreatWorks[draw]") ||
625 checkFInfoType("ZCHT","GreatWorks[chart]") || checkFInfoType("GreatWorks");
626 }
627 else if (m_fInfoCreator=="ZWRT") {
628 checkFInfoType("Zart","Z-Write") || checkFInfoType("Z-Write");
629 }
630 else if (m_fInfoCreator=="aca3") {
631 checkFInfoType("acf3","FreeHand v1") || checkFInfoType("act3","FreeHand v1[template]") ||
632 checkFInfoType("FreeHand v1");
633 }
634 else if (m_fInfoCreator=="cAni") {
635 checkFInfoType("curs","CursorAnimator") || checkFInfoType("CursorAnimator");
636 }
637 else if (m_fInfoCreator=="dPro") {
638 checkFInfoType("dDoc","MacDraw Pro") || checkFInfoType("dLib","MacDraw Pro(slide)") || checkFInfoType("MacDraw Pro");
639 }
640 else if (m_fInfoCreator=="eDcR") {
641 checkFInfoType("eDoc","eDOC") || checkFInfoType("eDOC");
642 }
643 else if (m_fInfoCreator=="eSRD") {
644 checkFInfoType("APPL","eDOC(appli)") || checkFInfoType("eDOC");
645 }
646 else if (m_fInfoCreator=="nX^n") {
647 checkFInfoType("nX^d","WriteNow 2") || checkFInfoType("nX^2","WriteNow 3-4") ||
648 checkFInfoType("WriteNow");
649 }
650 else if (m_fInfoCreator=="ntxt") {
651 checkFInfoType("TEXT","Anarcho");
652 }
653 else if (m_fInfoCreator=="ttxt") {
654 if (m_fInfoType=="TEXT") {
655 /* a little complex can be Classic MacOS SimpleText/TeachText or
656 a << normal >> text file */
657 XAttr rsrcAttr(m_fName.c_str());
658 std::unique_ptr<InputStream> rsrcStream{rsrcAttr.getStream("com.apple.ResourceFork")};
659 bool ok = false;
660 if (rsrcStream && rsrcStream->length()) {
661 libmwaw_tools::RSRC rsrcManager(*rsrcStream);
662 ok = rsrcManager.hasEntry("styl", 128);
663 }
664 if (ok) checkFInfoType("TEXT","TeachText/SimpleText");
665 else checkFInfoType("TEXT","Basic text");
666 }
667 else
668 checkFInfoType("ttro","TeachText/SimpleText[readOnly]");
669 }
670 // now by type
671 else if (m_fInfoType=="AAPL") {
672 checkFInfoCreator("Application");
673 }
674 else if (m_fInfoType=="JFIF") {
675 checkFInfoCreator("JPEG");
676 }
677 if (m_fInfoCreator.length()==0) {
678 MWAW_DEBUG_MSG(("File::readFileInformation: Find unknown file info %s[%s]\n", m_fInfoCreator.c_str(), m_fInfoType.c_str()));
679 }
680 return true;
681 }
682
683 bool File::readDataInformation()
684 {
685 if (!m_fName.length())
686 return false;
687 libmwaw_tools::FileStream input(m_fName.c_str());
688 if (!input.ok()) {
689 MWAW_DEBUG_MSG(("File::readDataInformation: can not open the data fork\n"));
690 return false;
691 }
692 if (input.length() < 10)
693 return true;
694 input.seek(0, InputStream::SK_SET);
695 int val[5];
696 for (auto &v : val) v = int(input.readU16());
697 // ----------- clearly discriminant ------------------
698 if (val[2] == 0x424F && val[3] == 0x424F && (val[0]>>8) < 8) {
699 m_dataResult.push_back("ClarisWorks/AppleWorks");
700 return true;
701 }
702 if (val[0]==0x4257 && val[1]==0x6b73 && val[2]==0x4257 && val[4]==0x4257) {
703 if (val[3]==0x6462)
704 m_dataResult.push_back("BeagleWorks/WordPerfect Works[Database]");
705 else if (val[3]==0x6472)
706 m_dataResult.push_back("BeagleWorks/WordPerfect Works[Draw]");
707 else if (val[3]==0x7074)
708 m_dataResult.push_back("BeagleWorks/WordPerfect Works[Paint]");
709 else if (val[3]==0x7373)
710 m_dataResult.push_back("BeagleWorks/WordPerfect Works[Spreadsheet]");
711 else if (val[3]==0x7770)
712 m_dataResult.push_back("BeagleWorks/WordPerfect Works");
713 else
714 m_dataResult.push_back("BeagleWorks/WordPerfect Works[Unknown]");
715 return true;
716 }
717 if (val[0]==0x4323 && val[1]==0x2b44 && val[2]==0xa443 && val[3]==0x4da5 && val[4]==0x4864) {
718 m_dataResult.push_back("RagTime 5-6");
719 return true;
720 }
721 if (val[0]==0x5772 && val[1]==0x6974 && val[2]==0x654e && val[3]==0x6f77 && val[4]==2) {
722 m_dataResult.push_back("WriteNow 3-4");
723 return true;
724 }
725 if (val[0]==0x4241 && val[1]==0x545F && val[2]==0x4254 && val[3]==0x5353) {
726 m_dataResult.push_back("Claris Resolve");
727 return true;
728 }
729 if (val[0]==0x574e && val[1]==0x475a && val[2]==0x575a) {
730 if (val[3]==0x5353) {
731 m_dataResult.push_back("Wingz");
732 return true;
733 }
734 if (val[3]==0x5343) {
735 m_dataResult.push_back("Wingz[script]");
736 return true;
737 }
738 }
739 if (val[0]==3 && val[1]==0x4d52 && val[2]==0x4949 && val[3]==0x80) {
740 m_dataResult.push_back("More 2");
741 return true;
742 }
743 if (val[0]==6 && val[1]==0x4d4f && val[2]==0x5233 && val[3]==0x80) {
744 m_dataResult.push_back("More 3");
745 return true;
746 }
747 if (val[0]==2 && val[1]==0 && val[2]==2 && val[3]==0x262 && val[4]==0x262) {
748 m_dataResult.push_back("MacDraft 1");
749 return true;
750 }
751 if (val[0]==0x4646 && val[1]==0x4646 && val[2]==0x3030 && val[3]==0x3030) {
752 m_dataResult.push_back("Mariner Write");
753 return true;
754 }
755 if (val[0]==0x4452 && val[1]==0x5747) { // DRWG
756 if (val[2]==0x4d44) { // MD
757 m_dataResult.push_back("MacDraw");
758 return true;
759 }
760 if (val[2]==0 || val[2]==0x4432) { // nothing or D2
761 m_dataResult.push_back("MacDraw II");
762 return true;
763 }
764 }
765 if (val[0]==0x5354 && val[1]==0x4154 && (val[2]==0||val[2]==0x4432)) { // STATD2
766 m_dataResult.push_back("MacDraw II(template)");
767 return true;
768 }
769 if (val[0]==0x6444 && val[1]==0x6f63 && val[2]==0x4432) { // dDocD2
770 m_dataResult.push_back("MacDraw Pro");
771 return true;
772 }
773 if (val[0]==0x644c && val[1]==0x6962 && val[2]==0x4432) { // dLibD2
774 m_dataResult.push_back("MacDraw Pro(slide)");
775 return true;
776 }
777 if (val[0]==0x4859 && val[1]==0x4c53 && val[2]==0x0210) {
778 m_dataResult.push_back("HanMac Word-K");
779 return true;
780 }
781 if (val[0]==0x594c && val[1]==0x5953 && val[2]==0x100) {
782 m_dataResult.push_back("HanMac Word-J");
783 return true;
784 }
785 if (val[0]==0x6163 && val[1]==0x6633 && val[2]<9) {
786 m_dataResult.push_back("FreeHand v1");
787 return true;
788 }
789 if (val[0]==0x4648 && val[1]==0x4432 && val[2]<20) {
790 m_dataResult.push_back("FreeHand v2");
791 return true;
792 }
793 if (val[0]==0x0447 && val[1]==0x4d30 && val[2]==0x3400) { // ^DGM04
794 m_dataResult.push_back("MouseWrite");
795 return true;
796 }
797 if (val[0]==0x000c && val[1]==0x1357 && (val[2]==0x13 || val[2]==0x14) && val[3]==0) {
798 m_dataResult.push_back("Drawing Table");
799 return true;
800 }
801 if (val[0]==0x2550 && val[1]==0x4446) {
802 m_dataResult.push_back("PDF");
803 return true;
804 }
805 if (val[0]==0x2854 && val[1]==0x6869 && val[2]==0x7320 && val[3]==0x6669) {
806 m_dataResult.push_back("BinHex");
807 return true;
808 }
809 if (val[0]==0x2521 && val[1]==0x5053 && val[2]==0x2d41 && val[3] == 0x646f && val[4]==0x6265) {
810 m_dataResult.push_back("PostScript");
811 return true;
812 }
813 if (val[0]==0xc5d0 && val[1]==0xd3c6) {
814 m_dataResult.push_back("Adobe EPS");
815 return true;
816 }
817 if (val[0]==0x7b5c && val[1]==0x7274 && (val[2]>>8)==0x66) {
818 m_dataResult.push_back("RTF");
819 return true;
820 }
821 if (val[2]==0x6d6f && val[3]==0x6f76) {
822 m_dataResult.push_back("QuickTime movie");
823 return true;
824 }
825 if (val[0]==0 && (val[1]>>8)==0 && val[2]==0x6674 && val[3]==0x7970 && val[4]==0x3367) {
826 m_dataResult.push_back("MP4");
827 return true;
828 }
829 if (val[0]==0x4749 && val[1]==0x4638 && (val[2]==0x3761 || val[2]==0x3961)) {
830 m_dataResult.push_back("GIF");
831 return true;
832 }
833 if (val[0]==0x8950 && val[1]==0x4e47 && val[2]==0x0d0a && val[3]==0x1a0a) {
834 m_dataResult.push_back("PNG");
835 return true;
836 }
837 if (val[0]==0x1a54 && val[1]==0x4c43 && (val[2]&0xfeff)==0x246 && val[3]==0x4600) {
838 m_dataResult.push_back("Student Writing Center");
839 return true;
840 }
841 if (val[3]==6 && val[4]==3 && input.length()>30) {
842 input.seek(10, InputStream::SK_SET);
843 if (val[0]==0x4d44 && val[1]==0x4443 && val[2]==0x3230) {
844 m_dataResult.push_back("MacDraft 4-5");
845 return true;
846 }
847 else if (input.readU16()==0 && input.readU16()==0x48 && input.readU16()==0x48) {
848 m_dataResult.push_back("MacDraft 4-5[lib]");
849 return true;
850 }
851 }
852 if (val[0]==0 && (val[1]==1||val[1]==2) && val[2]==0x4441 && val[3]==0x4435 && val[4]==0x5052) {
853 if (val[1]==1)
854 m_dataResult.push_back("Canvas Image 5-8");
855 else
856 m_dataResult.push_back("Canvas Image 9");
857 return true;
858 }
859 if (val[0]==0x200 && val[1]==0x80) {
860 if (val[2]==0 && val[3]==0 && (val[4]>>8)<=8 && (val[4]&0xff)==0) {
861 m_dataResult.push_back("Canvas 5[mac]");
862 return true;
863 }
864 input.seek(9, InputStream::SK_SET);
865 auto len=input.readU32();
866 if (len>=0x800 && len<=0x8000) { // block size
867 auto len1=input.readU32();
868 if (len1>0x800 && len1<=0x800c) {
869 m_dataResult.push_back("Canvas 6-8[mac]");
870 return true;
871 }
872 }
873 }
874 if (val[0]==0x100 && val[1]==0x8000) {
875 if ((val[2]>=0&&val[2]<=8) && val[3]==0 && (val[4]>>8)==0) {
876 m_dataResult.push_back("Canvas 5[windows]");
877 return true;
878 }
879
880 input.seek(9, InputStream::SK_SET);
881 unsigned len=0, decal=0;
882 for (int i=0; i<4; ++i, decal+=8)
883 len |= unsigned(input.readU8())<<decal;
884 if (len>=0x800 && len<=0x8000) { // block size
885 unsigned len1=0;
886 decal=0;
887 for (int i=0; i<4; ++i, decal+=8)
888 len1 |= unsigned(input.readU8())<<decal;
889 if (len1>0x800 && len1<=0x800c) {
890 m_dataResult.push_back("Canvas 6-8[windows]");
891 return true;
892 }
893 }
894 }
895 if (val[0]==0x1e && val[1]==0 && val[2]==0x86) {
896 m_dataResult.push_back("ReadySetGo 3");
897 return true;
898 }
899 if (val[0]==0 && val[1]==0 && val[2]==0 && val[3]==0 && val[4]==0) {
900 input.seek(10, InputStream::SK_SET);
901 unsigned endian=unsigned(input.readU16());
902 if (endian==0x100 && input.readU16()==0x8000) {
903 m_dataResult.push_back("Canvas 9-11[windows]");
904 return true;
905 }
906 if (endian==0x200 && input.readU16()==0x80) {
907 m_dataResult.push_back("Canvas 9-10[mac]");
908 return true;
909 }
910 }
911 if (val[0]==0xffd8 &&
912 ((val[1]==0xffe0 && val[3]==0x4a46 && val[4] == 0x4946) ||
913 (val[1]==0xffe1 && val[3]==0x4578 && val[4] == 0x6966) ||
914 (val[1]==0xffe8 && val[3]==0x5350 && val[4] == 0x4946))) {
915 m_dataResult.push_back("JPEG");
916 return true;
917 }
918 if (val[0]==0x4949 && val[1]==0x2a00) {
919 m_dataResult.push_back("TIF");
920 return true;
921 }
922 if (val[0]==0x4d4d && val[1]==0x002a) {
923 m_dataResult.push_back("TIFF");
924 return true;
925 }
926 if (val[0]==0x4f67 && val[1]==0x6753) {
927 m_dataResult.push_back("OGG data");
928 return true;
929 }
930 // ----------- less discriminant ------------------
931 if (val[0]==0xd0cf && val[1]==0x11e0 && val[2]==0xa1b1 && val[3]==0x1ae1) {
932 libmwaw_tools::OLE ole(input);
933 for (int step=0; step < 3; step++) {
934 std::string res=step==0 ? ole.getClipName() : step==1 ? ole.getCLSIDType() : ole.getCompObjType();
935 if (res.empty())
936 continue;
937 m_dataResult.push_back(res);
938 return true;
939 }
940 m_dataResult.push_back("OLE file: can be DOC, DOT, PPS, PPT, XLA, XLS, WIZ, WPS(4.0), ...");
941 return true;
942 }
943 if (val[0]==0x100 || val[0]==0x200) {
944 if (val[1]==0x5a57 && val[2]==0x5254) {
945 m_dataResult.push_back("GreatWorks");
946 return true;
947 }
948 if (val[1]==0x5a4f && val[2]==0x4c4e) {
949 m_dataResult.push_back("GreatWorks[outline]");
950 return true;
951 }
952 if (val[1]==0x5a44 && val[2]==0x4253) {
953 m_dataResult.push_back("GreatWorks[database]");
954 return true;
955 }
956 if (val[1]==0x5a43 && val[2]==0x414c) {
957 m_dataResult.push_back("GreatWorks[spreadsheet]");
958 return true;
959 }
960 if (val[1]==0x5a4f && val[2]==0x424a) {
961 m_dataResult.push_back("GreatWorks[draw]");
962 return true;
963 }
964 if (val[1]==0x5a43 && val[2]==0x4854) {
965 m_dataResult.push_back("GreatWorks[chart]");
966 return true;
967 }
968 }
969 if (val[0]==0 && (val[1]==0x4d4d||val[1]==0x4949) && (val[2]==0x5850 || val[2]==0xd850) && (val[3]&0xff00)==0x5200) {
970 if ((val[3]&0xff)==0x33) {
971 if (val[2]==0x5850)
972 m_dataResult.push_back("QuarkXPress 3");
973 else
974 m_dataResult.push_back("QuarkXPress 3[library]");
975 return true;
976 }
977 else if ((val[3]&0xff)==0x61) {
978 if (val[2]==0x5850)
979 m_dataResult.push_back("QuarkXPress 3[khorean]");
980 else
981 m_dataResult.push_back("QuarkXPress 3[khorean,library]");
982 return true;
983 }
984 }
985 if ((val[0]==0x100||val[0]==0x200) && val[2]==0x4558 && val[3]==0x5057) {
986 if (val[0]==0x100)
987 m_dataResult.push_back("ClarisDraw");
988 else
989 m_dataResult.push_back("ClarisDraw[library]");
990 return true;
991 }
992 if (val[0]==0x4348 && val[1]==0x4e4b && val[2]==0x100 && val[3]==0) {
993 m_dataResult.push_back("Style");
994 return true;
995 }
996 if (val[0]==0x5041 && val[1]==0x5031 && (val[2]>=0x1fa0 && val[2]<=0x1fbc) && val[3]==0x0fa0) {
997 m_dataResult.push_back("Papyrus");
998 return true;
999 }
1000 // less discriminant
1001 if ((val[0]==0xfe32 && val[1]==0) || (val[0]==0xfe34 && val[1]==0) ||
1002 (val[0] == 0xfe37 && (val[1] == 0x23 || val[1] == 0x1c))) {
1003 switch (val[1]) {
1004 case 0:
1005 if (val[0]==0xfe34)
1006 m_dataResult.push_back("Microsoft Word 3.0");
1007 else if (val[0]==0xfe32)
1008 m_dataResult.push_back("Microsoft Word 1.0");
1009 break;
1010 case 0x1c:
1011 m_dataResult.push_back("Microsoft Word 4.0");
1012 break;
1013 case 0x23:
1014 m_dataResult.push_back("Microsoft Word 5.0");
1015 break;
1016 default:
1017 break;
1018 }
1019 }
1020 if (val[0]==0x464f && val[1]==0x524d)
1021 m_dataResult.push_back("WordMaker");
1022 if (val[0]==0 && input.length() > 30) {
1023 input.seek(16, InputStream::SK_SET);
1024 if (input.readU16()==0x688f && input.readU16()==0x688f) {
1025 m_dataResult.push_back("RagTime");
1026 return true;
1027 }
1028 }
1029 if (val[0]==0 && val[1]==0 && val[2]==0 && val[3]==0 &&
1030 ((val[4]>>8)==4 || (val[4]>>8)==0x44))
1031 m_dataResult.push_back("WriteNow 1-2");
1032 if (val[0] == 0x2e && val[1] == 0x2e)
1033 m_dataResult.push_back("MacWrite II");
1034 if (val[0] == 4 && val[1] == 4)
1035 m_dataResult.push_back("MacWrite Pro");
1036 if (val[0] == 0x20 && val[1] == 0x20)
1037 m_dataResult.push_back("QuarkXpress 1");
1038 if (val[0] == 0x26 && val[1] == 0x26)
1039 m_dataResult.push_back("QuarkXpress 2");
1040 if (val[0] == 0x78)
1041 m_dataResult.push_back("ReadySetGo 1[unsure]");
1042 if (val[0] == 0x7704)
1043 m_dataResult.push_back("MindWrite");
1044 if (val[0] == 0x110)
1045 m_dataResult.push_back("WriterPlus");
1046 if ((val[0] >= 400 && val[0] <= 402) && (val[1]&0xff00)==0)
1047 m_dataResult.push_back("ReadySetGo 4.0[unsure]");
1048 if ((val[0] >= 5000 && val[0] <= 5005) && (val[1]&0xff00)==0)
1049 m_dataResult.push_back("ReadySetGo 4.5[unsure]");
1050 if ((val[0] >= 6000 && val[0] <= 6003) && (val[1]&0xff00)==0)
1051 m_dataResult.push_back("ReadySetGo 6.0[unsure]");
1052 if (val[0] == 0x1bbc && (val[1]&0xff00)==0)
1053 m_dataResult.push_back("ReadySetGo 7.0[unsure]");
1054 if (val[0] == 0x13e4 && (val[1]&0xff00)==0)
1055 m_dataResult.push_back("Design Studio 2[unsure]");
1056
1057 if (val[0]==0xdba5 && val[1]==0x2d00) {
1058 m_dataResult.push_back("Microsoft Word 2.0[pc]");
1059 return true;
1060 }
1061 if (val[0]==0xabcd && val[1]==0x54) {
1062 m_dataResult.push_back("DiskDoubler[archive]");
1063 return true;
1064 }
1065 if (val[0]==0x4D44) { // MD
1066 m_dataResult.push_back("MacDraw v0[unsure]");
1067 }
1068 if (val[0]==0xbad && val[1]==0xdeed && val[2]==0) {
1069 m_dataResult.push_back("Microsoft PowerPoint Mac");
1070 return true;
1071 }
1072 if (val[0]==0xedde && val[1]==0xad0b && val[3]==0) {
1073 m_dataResult.push_back("Microsoft PowerPoint Windows");
1074 return true;
1075 }
1076 if (val[0]==0x11ab && val[1]==0x0 && val[2]==0x13e8 && val[3]==0) {
1077 m_dataResult.push_back("Microsoft Multiplan Mac");
1078 return true;
1079 }
1080 if (val[0] == 3 || val[0] == 6) {
1081 int numParaPos = val[0] == 3 ? 2 : 1;
1082 if (val[numParaPos] < 0x1000 && val[numParaPos+1] < 0x100 && val[numParaPos+2] < 0x100)
1083 m_dataResult.push_back("MacWrite[unsure]");
1084 }
1085 if (val[0]==0 && val[1]==2 && val[2]==11)
1086 m_dataResult.push_back("Jazz(spreadsheet)[unsure]");
1087 if (val[0]==0) {
1088 std::stringstream s;
1089 bool ok = true;
1090 switch (val[1]) {
1091 case 4:
1092 s << "Microsoft Works 1.0";
1093 break;
1094 case 8:
1095 s << "Microsoft Works 2.0";
1096 break;
1097 case 9:
1098 s << "Microsoft Works 3.0";
1099 break;
1100 case 11:
1101 s << "Microsoft Works 4.0";
1102 break; // all excepted a text file
1103 default:
1104 ok = false;
1105 break;
1106 }
1107 input.seek(16, InputStream::SK_SET);
1108 int type = ok ? int(input.readU16()) : -1;
1109 switch (type) {
1110 case 1:
1111 break;
1112 case 2:
1113 s << "[database]";
1114 break;
1115 case 3:
1116 s << "[spreadsheet]";
1117 break;
1118 case 12:
1119 s << "[draw]";
1120 break;
1121 default:
1122 ok = false;
1123 break;
1124 }
1125 if (ok)
1126 m_dataResult.push_back(s.str());
1127 }
1128 if (val[0]==0 && (val[1]==0x7FFF || val[1]==0x8000)) {
1129 m_dataResult.push_back("PixelPaint[unsure]");
1130 }
1131 if (val[0]>=1 && val[0]<=4) {
1132 int sSz=(val[1]>>8);
1133 if (sSz>=6 && sSz<=8) {
1134 // check if we have a date
1135 input.seek(3, InputStream::SK_SET);
1136 bool ok=true;
1137 int numSlash=0;
1138 for (int i=0; i<sSz; ++i) {
1139 auto c=char(input.readU8());
1140 if (c>='0' && c<='9')
1141 continue;
1142 if (c=='/')
1143 ++numSlash;
1144 else {
1145 ok=false;
1146 break;
1147 }
1148 }
1149 if (ok && numSlash==2)
1150 m_dataResult.push_back("Cricket Draw 1.0");
1151 }
1152 }
1153 input.seek(-4, InputStream::SK_END);
1154 int lVal[2];
1155 for (auto &v : lVal) v = int(input.readU16());
1156 if (lVal[0] == 0x4657 && lVal[1]==0x5254)
1157 m_dataResult.push_back("FullWrite 2.0");
1158 else if (lVal[0] == 0x4E4C && lVal[1]==0x544F)
1159 m_dataResult.push_back("Acta Classic");
1160 else if (lVal[1]==0 && val[0]==1 && (val[1]==1||val[1]==2))
1161 m_dataResult.push_back("Acta v2[unsure]");
1162 else if (lVal[0] == 0 && lVal[1]==1) { // Maybe a FullWrite 1.0 file, limited check
1163 input.seek(-38, InputStream::SK_END);
1164 long eof = input.length();
1165 bool ok = true;
1166 for (int i = 0; i < 2; i++) {
1167 auto pos = long(input.readU32());
1168 auto sz = long(input.read32());
1169 if (sz <= 0 || pos+sz > eof) {
1170 ok = false;
1171 break;
1172 }
1173 }
1174 if (ok)
1175 m_dataResult.push_back("FullWrite 1.0[unsure]");
1176 }
1177 #ifdef DEBUG
1178 if (m_dataResult.size()==0) {
1179 std::stringstream s;
1180 s << "Unknown: " << std::hex << std::setfill('0');
1181 for (auto v : val)
1182 s << std::setw(4) << v << " ";
1183 m_dataResult.push_back(s.str());
1184 }
1185 #endif
1186 return true;
1187 }
1188
1189 bool File::readRSRCInformation()
1190 {
1191 if (!m_fName.length())
1192 return false;
1193
1194 XAttr xattr(m_fName.c_str());
1195 std::unique_ptr<libmwaw_tools::InputStream> rsrcStream{xattr.getStream("com.apple.ResourceFork")};
1196 if (!rsrcStream) return false;
1197
1198 if (!rsrcStream->length()) {
1199 return true;
1200 }
1201 libmwaw_tools::RSRC rsrcManager(*rsrcStream);
1202 # if 0
1203 MWAW_DEBUG_MSG(("File::readRSRCInformation: find a resource fork\n"));
1204 # endif
1205 m_rsrcResult = rsrcManager.getString(-16396); // the application missing name
1206 m_rsrcMissingMessage = rsrcManager.getString(-16397);
1207 auto listVersion = rsrcManager.getVersionList();
1208 for (auto const &vers : listVersion) {
1209 switch (vers.m_id) {
1210 case 1:
1211 m_fileVersion = vers;
1212 break;
1213 case 2:
1214 if (!m_appliVersion.ok()) m_appliVersion = vers;
1215 break;
1216 case 2002:
1217 m_appliVersion = vers;
1218 break;
1219 default:
1220 break;
1221 }
1222 }
1223 return true;
1224 }
1225
1226 bool File::printResult(std::ostream &o, int verbose) const
1227 {
1228 if (!canPrintResult(verbose)) return false;
1229 if (m_printFileName)
1230 o << m_fName << ":";
1231 if (m_fInfoResult.length())
1232 o << m_fInfoResult;
1233 else if (m_rsrcResult.length())
1234 o << m_rsrcResult;
1235 else if (m_dataResult.size()) {
1236 size_t num = m_dataResult.size();
1237 if (num>1)
1238 o << "[";
1239 for (size_t i = 0; i < num; i++) {
1240 o << m_dataResult[i];
1241 if (i+1!=num)
1242 o << ",";
1243 }
1244 if (num>1)
1245 o << "]";
1246 }
1247 else
1248 o << "unknown";
1249 if (verbose > 0) {
1250 if (m_fInfoCreator.length() || m_fInfoType.length())
1251 o << ":type=" << m_fInfoCreator << "[" << m_fInfoType << "]";
1252 }
1253 if (verbose > 1) {
1254 if (m_fileVersion.ok())
1255 o << "\n\tFile" << m_fileVersion;
1256 if (m_appliVersion.ok())
1257 o << "\n\tAppli" << m_appliVersion;
1258 }
1259 o << "\n";
1260 return true;
1261 }
1262 }
1263
1264 static void usage(char const *fName)
1265 {
1266 std::cerr << "Usage: " << fName << " [OPTION] FILENAME\n";
1267 std::cerr << "\n";
1268 std::cerr << "try to find the file type of FILENAME\n";
1269 std::cerr << "\n";
1270 std::cerr << "Options:\n";
1271 std::cerr << "\t -f: Does not print the filename,\n";
1272 std::cerr << "\t -F: Prints the filename[default],\n";
1273 std::cerr << "\t -h: Shows this help message,\n";
1274 std::cerr << "\t -v: Output mwawFile version\n";
1275 std::cerr << "\t -wNum: define the verbose level.\n";
1276 }
1277
1278 static int printVersion()
1279 {
1280 std::cerr << "mwawFile " << VERSION << "\n";
1281 return 0;
1282 }
1283
1284 int main(int argc, char *const argv[])
1285 {
1286 int ch, verbose=0;
1287 bool printFileName=true;
1288
1289 while ((ch = getopt(argc, argv, "fFhvw:")) != -1) {
1290 switch (ch) {
1291 case 'w':
1292 verbose=atoi(optarg);
1293 break;
1294 case 'f':
1295 printFileName = false;
1296 break;
1297 case 'F':
1298 printFileName = true;
1299 break;
1300 case 'v':
1301 printVersion();
1302 return 0;
1303 case 'h':
1304 case '?':
1305 default:
1306 verbose=-1;
1307 break;
1308 }
1309 }
1310 if (argc != 1+optind || verbose < 0) {
1311 usage(argv[0]);
1312 return -1;
1313 }
1314 std::unique_ptr<libmwaw_tools::File> file;
1315 try {
1316 file.reset(new libmwaw_tools::File(argv[optind]));
1317 if (file)
1318 file->readFileInformation();
1319 }
1320 catch (...) {
1321 std::cerr << argv[0] << ": can not open file " << argv[optind] << "\n";
1322 return -1;
1323 }
1324 if (!file)
1325 return -1;
1326 try {
1327 file->readDataInformation();
1328 }
1329 catch (...) {
1330 }
1331 try {
1332 file->readRSRCInformation();
1333 }
1334 catch (...) {
1335 }
1336
1337 file->m_printFileName = printFileName;
1338 if (verbose >= 4)
1339 std::cout << *file;
1340 else if (file->canPrintResult(verbose))
1341 file->printResult(std::cout, verbose);
1342 return 0;
1343 }
1344 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: