~ubuntu-branches/ubuntu/oneiric/djvulibre/oneiric

« back to all changes in this revision

Viewing changes to .pc/debian-changes-3.5.24-7/tools/djvm.cpp

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2011-06-22 11:48:22 UTC
  • mfrom: (12.2.20 sid)
  • Revision ID: package-import@ubuntu.com-20110622114822-fmb095f2y3ehozva
Tags: 3.5.24-8
ddjvu_anno_get_xmp consistent prototype vs implementation (closes: #613547)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//C-  -*- C++ -*-
2
 
//C- -------------------------------------------------------------------
3
 
//C- DjVuLibre-3.5
4
 
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5
 
//C- Copyright (c) 2001  AT&T
6
 
//C-
7
 
//C- This software is subject to, and may be distributed under, the
8
 
//C- GNU General Public License, either Version 2 of the license,
9
 
//C- or (at your option) any later version. The license should have
10
 
//C- accompanied the software or you may obtain a copy of the license
11
 
//C- from the Free Software Foundation at http://www.fsf.org .
12
 
//C-
13
 
//C- This program is distributed in the hope that it will be useful,
14
 
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
//C- GNU General Public License for more details.
17
 
//C- 
18
 
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19
 
//C- Lizardtech Software.  Lizardtech Software has authorized us to
20
 
//C- replace the original DjVu(r) Reference Library notice by the following
21
 
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
22
 
//C-
23
 
//C-  ------------------------------------------------------------------
24
 
//C- | DjVu (r) Reference Library (v. 3.5)
25
 
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26
 
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27
 
//C- | 6,058,214 and patents pending.
28
 
//C- |
29
 
//C- | This software is subject to, and may be distributed under, the
30
 
//C- | GNU General Public License, either Version 2 of the license,
31
 
//C- | or (at your option) any later version. The license should have
32
 
//C- | accompanied the software or you may obtain a copy of the license
33
 
//C- | from the Free Software Foundation at http://www.fsf.org .
34
 
//C- |
35
 
//C- | The computer code originally released by LizardTech under this
36
 
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37
 
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
38
 
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
39
 
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
40
 
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
41
 
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
42
 
//C- | General Public License.   This grant only confers the right to 
43
 
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
44
 
//C- | the extent such infringement is reasonably necessary to enable 
45
 
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
46
 
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
47
 
//C- | any greater extent that may be necessary to utilize further 
48
 
//C- | modifications or combinations.
49
 
//C- |
50
 
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51
 
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52
 
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53
 
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54
 
//C- +------------------------------------------------------------------
55
 
 
56
 
#ifdef HAVE_CONFIG_H
57
 
# include "config.h"
58
 
#endif
59
 
#if NEED_GNUG_PRAGMAS
60
 
# pragma implementation
61
 
#endif
62
 
 
63
 
/** @name djvm
64
 
 
65
 
    {\bf Synopsis}\\
66
 
    \begin{verbatim}
67
 
        djvm [options] <djvu_doc_name> [djvufiles] [pagenum]
68
 
    \end{verbatim}
69
 
 
70
 
    {\bf Description} ---
71
 
    File #"djvm.cpp"# and program #djvm# illustrate how class \Ref{DjVuDocEditor}
72
 
    can be used to create and modify DjVu multipage documents. The program
73
 
    demonstrates how to pack several DjVu single-page files together,
74
 
    how to remove pages from a multipage document or how to insert new.
75
 
    
76
 
    {\bf Arguments} ---
77
 
    Depending on the task to be performed, the number and types of arguments
78
 
    differ:
79
 
    \begin{itemize}
80
 
       \item To create a new document
81
 
 
82
 
             #djvm -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>#
83
 
 
84
 
             This will package pages represented by files #<page_1.djvu>#
85
 
             ... #<page_n.djvu># into #BUNDLED# multipage DjVu document
86
 
             #<doc.djvu># (see \Ref{DjVuDocument} for the explanation of
87
 
             the #BUNDLED# format). The specified page files may include other
88
 
             files (by means of #INCL# chunks). They will also be packed
89
 
             into the document.
90
 
 
91
 
       \item To insert a page
92
 
 
93
 
             #djvm -i[nsert] <doc.djvu> <page.djvu> [<page_num>]#
94
 
 
95
 
             This will insert page represented by file #<page.djvu># into
96
 
             document #<doc.djvu># as page number #<page_num># (page
97
 
             numbering starts from #1#). Negative or missing #<page_num>#
98
 
             means to append the page.
99
 
 
100
 
             The #<page.djvu># file can actually be another
101
 
             multipage DjVu document. In this cases, all pages from that
102
 
             document will be inserted into #<doc.djvu># starting from
103
 
             page #<page_num>#.
104
 
 
105
 
       \item To delete a page
106
 
 
107
 
             #djvm -d[elete] <doc.djvu> <page_num>#
108
 
 
109
 
             This will remove page number #<page_num># from document
110
 
             #<doc.djvu>#. If there is only one page left in #<doc.djvu>#
111
 
             after deletion, it will automatically be converted to a
112
 
             single page DjVu file format. Page numbering starts from #1#.
113
 
 
114
 
       \item To view document contents
115
 
 
116
 
             #djvm -l[ist] <doc.djvu>#
117
 
 
118
 
             This will list all files composing the given document #<doc.djvu>#.
119
 
             The files list includes the names of page files plus names
120
 
             of any files included into the page files by means of
121
 
             #INCL# chunk.
122
 
    \end{itemize}
123
 
 
124
 
    @memo
125
 
    DjVu multipage documents creator.
126
 
    @author
127
 
    Andrei Erofeev <eaf@geocities.com>
128
 
*/
129
 
//@{
130
 
//@}
131
 
 
132
 
#include "GException.h"
133
 
#include "DjVuDocEditor.h"
134
 
#include "GOS.h"
135
 
#include "DjVuMessage.h"
136
 
 
137
 
#include <locale.h>
138
 
#include <stdlib.h>
139
 
#include <stdio.h>
140
 
#include <stdlib.h>
141
 
 
142
 
static const char * progname;
143
 
 
144
 
static void
145
 
usage(void)
146
 
{
147
 
   DjVuPrintErrorUTF8(
148
 
#ifdef DJVULIBRE_VERSION
149
 
           "DJVM --- DjVuLibre-" DJVULIBRE_VERSION "\n"
150
 
#endif
151
 
           "DjVu multipage document manipulation utility\n"
152
 
           "\n"
153
 
           "Usage:\n"
154
 
           "   To compose a multipage document:\n"
155
 
           "      %s -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>\n"
156
 
           "      where <doc.djvu> is the name of the BUNDLED document to be\n"
157
 
           "      created, <page_n.djvu> are the names of the page files to\n"
158
 
           "      be packed together.\n"
159
 
           "\n"
160
 
           "   To insert a new page into an existing document:\n"
161
 
           "      %s -i[nsert] <doc.djvu> <page.djvu> [<page_num>]\n"
162
 
           "      where <doc.djvu> is the name of the BUNDLED DjVu document to be\n"
163
 
           "      modified, <page.djvu> is the name of the single-page DjVu document\n"
164
 
           "      file to be inserted as page <page_num> (page numbers start from 1).\n"
165
 
           "      Negative or omitted <page_num> means to append the page.\n"
166
 
           "      <page.djvu> can be another multipage DjVu document, in which case\n"
167
 
           "      all pages of that document will be inserted into <doc.djvu>\n"
168
 
           "      starting starting at page <page_num>\n"
169
 
           "\n"
170
 
           "   To delete a page from an existing document:\n"
171
 
           "      %s -d[elete] <doc.djvu> <page_num>\n"
172
 
           "      where <doc.djvu> is the name of the docyment to be modified\n"
173
 
           "      and <page_num> is the number of the page to be deleted\n"
174
 
           "\n"
175
 
           "   To list document contents:\n"
176
 
           "      %s -l[ist] <doc.djvu>\n"
177
 
           "\n"
178
 
           "Pages being inserted may reference other files by means of INCL chunks.\n"
179
 
           "Moreover, files shared between pages will be stored into the document\n"
180
 
           "only once.\n"
181
 
           "\n", progname, progname, progname, progname );
182
 
}
183
 
 
184
 
static void
185
 
create(GArray<GUTF8String> &argv)
186
 
      // djvm -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>
187
 
      // doc.djvu will be overwritten
188
 
{
189
 
   const int argc=argv.hbound()+1;
190
 
   if (argc<4) { usage(); exit(1); }
191
 
 
192
 
      // Initialize the DjVuDocEditor class
193
 
   GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait();
194
 
 
195
 
      // Insert pages
196
 
   GList<GURL> list;
197
 
   for(int i=3;i<argc;i++)
198
 
      list.append(GURL::Filename::UTF8(argv[i]));
199
 
   doc->insert_group(list);
200
 
 
201
 
   const GURL::Filename::UTF8 url(argv[2]);
202
 
      // Save in BUNDLED format
203
 
   doc->save_as(url, true);
204
 
}
205
 
 
206
 
static void
207
 
insert(GArray<GUTF8String> &argv)
208
 
      // djvm -i[nsert] <doc.djvu> <page.djvu> <page_num>
209
 
{
210
 
   const int argc=argv.hbound()+1;
211
 
   if (argc!=4 && argc!=5) { usage(); exit(1); }
212
 
 
213
 
      // Initialize DjVuDocEditor class
214
 
   const GURL::Filename::UTF8 url(argv[2]);
215
 
   GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait(url);
216
 
 
217
 
      // Insert page
218
 
   int page_num=-1;
219
 
   if (argc==5) page_num=atoi(argv[4])-1;
220
 
   doc->insert_page(GURL::Filename::UTF8(argv[3]), page_num);
221
 
 
222
 
      // Save the document
223
 
   doc->save();
224
 
}
225
 
 
226
 
static void
227
 
del(GArray<GUTF8String> &argv)
228
 
      // djvm -d[elete] <doc.djvu> <page_num>
229
 
{
230
 
   const int argc=argv.hbound()+1;
231
 
   if (argc!=4) { usage(); exit(1); }
232
 
 
233
 
      // Initialize DjVuDocEditor class
234
 
   const GURL::Filename::UTF8 url(argv[2]);
235
 
   GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait(url);
236
 
 
237
 
      // Delete the page
238
 
   int page_num=atoi(argv[3])-1;
239
 
   if (page_num<0)
240
 
   {
241
 
     DjVuPrintErrorUTF8("%s","Page number must be positive.\n");
242
 
     exit(1);
243
 
   }
244
 
   doc->remove_page(page_num);
245
 
 
246
 
      // Save the document
247
 
   doc->save();
248
 
}
249
 
 
250
 
static void
251
 
list(GArray<GUTF8String> &argv)
252
 
      // djvm -l[ist] <doc.djvu>
253
 
{
254
 
   const int argc=argv.hbound()+1;
255
 
   if (argc!=3) { usage(); exit(1); }
256
 
 
257
 
   const GURL::Filename::UTF8 url(argv[2]);
258
 
   GP<DjVmDoc> doc=DjVmDoc::create();
259
 
   doc->read(url);
260
 
   
261
 
   GP<DjVmDir> dir=doc->get_djvm_dir();
262
 
   if (dir)
263
 
   {
264
 
      GPList<DjVmDir::File> files_list=dir->get_files_list();
265
 
      printf("Size     Type        Name\n");
266
 
      printf("--------------------------\n");
267
 
      for(GPosition pos=files_list;pos;++pos)
268
 
      {
269
 
         GP<DjVmDir::File> file=files_list[pos];
270
 
         printf("%6d   ", file->size);
271
 
         if (file->is_page())
272
 
         {
273
 
            char buffer[128];
274
 
            sprintf(buffer, "PAGE #%d", file->get_page_num()+1);
275
 
            printf("%s", buffer);
276
 
            for(int i=strlen(buffer);i<9;i++)
277
 
               putchar(' ');
278
 
         } else if (file->is_include())
279
 
         {
280
 
            printf("%s", "INCLUDE  ");
281
 
         } else if (file->is_shared_anno())
282
 
         {
283
 
            printf("%s", "SHARED_ANNO  ");
284
 
         }else if (file->is_thumbnails())
285
 
         {
286
 
            printf("%s", "THUMBNAIL");
287
 
         } else
288
 
         {
289
 
           printf("%s", "UNKNOWN  ");
290
 
         }
291
 
         printf("   %s\n", (const char *) file->get_save_name());
292
 
      }
293
 
   }
294
 
}
295
 
 
296
 
int
297
 
main(int argc, char ** argv)
298
 
{
299
 
  setlocale(LC_ALL,"");
300
 
  setlocale(LC_NUMERIC,"C");
301
 
  djvu_programname(argv[0]);
302
 
  GArray<GUTF8String> dargv(0,argc-1);
303
 
  for(int i=0;i<argc;++i)
304
 
    dargv[i]=GNativeString(argv[i]);
305
 
  progname=dargv[0]=GOS::basename(dargv[0]);
306
 
   
307
 
   G_TRY {
308
 
      if (argc<2) { usage(); exit(1); }
309
 
      if (!dargv[1].cmp("-c", 2)) create(dargv);
310
 
      else if (!dargv[1].cmp("-i", 2)) insert(dargv);
311
 
      else if (!dargv[1].cmp("-d", 2)) del(dargv);
312
 
      else if (!dargv[1].cmp("-l", 2)) list(dargv);
313
 
      else { usage(); exit(1); }
314
 
   } G_CATCH(exc) {
315
 
      exc.perror();
316
 
      exit(1);
317
 
   } G_ENDCATCH;
318
 
   return 0; 
319
 
}
320