Debian Codegraph @

podofo/tools/podofoincrementalupdates/incrementalupdates.cpp

raw
1 /**
2 * SPDX-FileCopyrightText: (C) 2009 Dominik Seichter <[email protected]>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include <podofo/podofo.h>
7
8 #include <cstdlib>
9 #include <cstdio>
10
11 #include <podofo/private/PdfParser.h>
12
13 using namespace std;
14 using namespace PoDoFo;
15
16 void print_help()
17 {
18 printf("Usage: podofoincrementalupdates [-e N out.pdf] file.pdf\n\n");
19 printf(" This tool prints information of incremental updates to file.pdf.\n");
20 printf(" By default the number of incremental updates will be printed.\n");
21 printf(" -e N out.pdf\n");
22 printf(" Extract the Nth update from file.pdf and write it to out.pdf.\n");
23 printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING);
24 }
25
26 int get_info(const string_view& filepath)
27 {
28 (void)filepath;
29 int updateCount = 0;
30 /* FIX-ME: Broken after PdfIndirectObjectList API review
31 PdfIndirectObjectList objects;
32 PdfParser parser(objects);
33
34 FileStreamDevice input(filepath);
35 parser.Parse(input);
36
37 updateCount = parser.GetNumberOfIncrementalUpdates();
38
39 printf("%s\t=\t%i\t(Number of incremental updates)\n", filepath.data(), updateCount);
40 */
41 return updateCount;
42 }
43
44 void extract(const string_view& filePath, int requestedNthUpdate, const string_view& outputFilePath)
45 {
46 (void)filePath;
47 (void)requestedNthUpdate;
48 (void)outputFilePath;
49 // TODO
50 fprintf(stderr, "extraction is not implemented\n");
51 exit(-2);
52 }
53
54 void Main(const cspan<string_view>& args)
55 {
56 PdfCommon::SetMaxLoggingSeverity(PdfLogSeverity::None);
57
58 if (args.size() != 2 && args.size() != 5)
59 {
60 print_help();
61 exit(-1);
62 }
63
64 string_view inputPath;
65 string_view outputPath;
66 int requestedNthUpdate = -1;
67
68 if (args.size() == 2)
69 {
70 inputPath = args[1];
71 get_info(inputPath);
72 }
73 else if (args.size() == 5)
74 {
75 requestedNthUpdate = strtol(args[2].data(), NULL, 10);
76 outputPath = args[3];
77 inputPath = args[4];
78 extract(inputPath, requestedNthUpdate, outputPath);
79 }
80 }