//C- -*- C++ -*- //C- ------------------------------------------------------------------- //C- DjVuLibre-3.5 //C- Copyright (c) 2002 Leon Bottou and Yann Le Cun. //C- Copyright (c) 2001 AT&T //C- //C- This software is subject to, and may be distributed under, the //C- GNU General Public License, either Version 2 of the license, //C- or (at your option) any later version. The license should have //C- accompanied the software or you may obtain a copy of the license //C- from the Free Software Foundation at http://www.fsf.org . //C- //C- This program is distributed in the hope that it will be useful, //C- but WITHOUT ANY WARRANTY; without even the implied warranty of //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //C- GNU General Public License for more details. //C- //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from //C- Lizardtech Software. Lizardtech Software has authorized us to //C- replace the original DjVu(r) Reference Library notice by the following //C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu): //C- //C- ------------------------------------------------------------------ //C- | DjVu (r) Reference Library (v. 3.5) //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved. //C- | The DjVu Reference Library is protected by U.S. Pat. No. //C- | 6,058,214 and patents pending. //C- | //C- | This software is subject to, and may be distributed under, the //C- | GNU General Public License, either Version 2 of the license, //C- | or (at your option) any later version. The license should have //C- | accompanied the software or you may obtain a copy of the license //C- | from the Free Software Foundation at http://www.fsf.org . //C- | //C- | The computer code originally released by LizardTech under this //C- | license and unmodified by other parties is deemed "the LIZARDTECH //C- | ORIGINAL CODE." Subject to any third party intellectual property //C- | claims, LizardTech grants recipient a worldwide, royalty-free, //C- | non-exclusive license to make, use, sell, or otherwise dispose of //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU //C- | General Public License. This grant only confers the right to //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to //C- | the extent such infringement is reasonably necessary to enable //C- | recipient to make, have made, practice, sell, or otherwise dispose //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to //C- | any greater extent that may be necessary to utilize further //C- | modifications or combinations. //C- | //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. //C- +------------------------------------------------------------------ #ifdef HAVE_CONFIG_H # include "config.h" #endif #if NEED_GNUG_PRAGMAS # pragma implementation #endif /** @name djvm {\bf Synopsis}\\ \begin{verbatim} djvm [options] [djvufiles] [pagenum] \end{verbatim} {\bf Description} --- File #"djvm.cpp"# and program #djvm# illustrate how class \Ref{DjVuDocEditor} can be used to create and modify DjVu multipage documents. The program demonstrates how to pack several DjVu single-page files together, how to remove pages from a multipage document or how to insert new. {\bf Arguments} --- Depending on the task to be performed, the number and types of arguments differ: \begin{itemize} \item To create a new document #djvm -c[reate] ... # This will package pages represented by files ## ... ## into #BUNDLED# multipage DjVu document ## (see \Ref{DjVuDocument} for the explanation of the #BUNDLED# format). The specified page files may include other files (by means of #INCL# chunks). They will also be packed into the document. \item To insert a page #djvm -i[nsert] []# This will insert page represented by file ## into document ## as page number ## (page numbering starts from #1#). Negative or missing ## means to append the page. The ## file can actually be another multipage DjVu document. In this cases, all pages from that document will be inserted into ## starting from page ##. \item To delete a page #djvm -d[elete] # This will remove page number ## from document ##. If there is only one page left in ## after deletion, it will automatically be converted to a single page DjVu file format. Page numbering starts from #1#. \item To view document contents #djvm -l[ist] # This will list all files composing the given document ##. The files list includes the names of page files plus names of any files included into the page files by means of #INCL# chunk. \end{itemize} @memo DjVu multipage documents creator. @author Andrei Erofeev */ //@{ //@} #include "GException.h" #include "DjVuDocEditor.h" #include "GOS.h" #include "DjVuMessage.h" #include "common.h" static const char * progname; static void usage(void) { DjVuPrintErrorUTF8( #ifdef DJVULIBRE_VERSION "DJVM --- DjVuLibre-" DJVULIBRE_VERSION "\n" #endif "DjVu multipage document manipulation utility\n" "\n" "Usage:\n" " To compose a multipage document:\n" " %s -c[reate] ... \n" " where is the name of the BUNDLED document to be\n" " created, are the names of the page files to\n" " be packed together.\n" "\n" " To insert a new page into an existing document:\n" " %s -i[nsert] []\n" " where is the name of the BUNDLED DjVu document to be\n" " modified, is the name of the single-page DjVu document\n" " file to be inserted as page (page numbers start from 1).\n" " Negative or omitted means to append the page.\n" " can be another multipage DjVu document, in which case\n" " all pages of that document will be inserted into \n" " starting starting at page \n" "\n" " To delete a page from an existing document:\n" " %s -d[elete] \n" " where is the name of the docyment to be modified\n" " and is the number of the page to be deleted\n" "\n" " To list document contents:\n" " %s -l[ist] \n" "\n" "Pages being inserted may reference other files by means of INCL chunks.\n" "Moreover, files shared between pages will be stored into the document\n" "only once.\n" "\n", progname, progname, progname, progname ); } static void create(GArray &argv) // djvm -c[reate] ... // doc.djvu will be overwritten { const int argc=argv.hbound()+1; if (argc<4) { usage(); exit(1); } // Initialize the DjVuDocEditor class GP doc=DjVuDocEditor::create_wait(); // Insert pages GList list; for(int i=3;iinsert_group(list); const GURL::Filename::UTF8 url(argv[2]); // Save in BUNDLED format doc->save_as(url, true); } static void insert(GArray &argv) // djvm -i[nsert] { const int argc=argv.hbound()+1; if (argc!=4 && argc!=5) { usage(); exit(1); } // Initialize DjVuDocEditor class const GURL::Filename::UTF8 url(argv[2]); GP doc=DjVuDocEditor::create_wait(url); // Insert page int page_num=-1; if (argc==5) page_num=atoi(argv[4])-1; doc->insert_page(GURL::Filename::UTF8(argv[3]), page_num); // Save the document doc->save(); } static void del(GArray &argv) // djvm -d[elete] { const int argc=argv.hbound()+1; if (argc!=4) { usage(); exit(1); } // Initialize DjVuDocEditor class const GURL::Filename::UTF8 url(argv[2]); GP doc=DjVuDocEditor::create_wait(url); // Delete the page int page_num=atoi(argv[3])-1; if (page_num<0) { DjVuPrintErrorUTF8("%s","Page number must be positive.\n"); exit(1); } doc->remove_page(page_num); // Save the document doc->save(); } static void list(GArray &argv) // djvm -l[ist] { const int argc=argv.hbound()+1; if (argc!=3) { usage(); exit(1); } const GURL::Filename::UTF8 url(argv[2]); GP doc=DjVmDoc::create(); doc->read(url); GP dir=doc->get_djvm_dir(); if (dir) { GPList files_list=dir->get_files_list(); printf("Size Type Name\n"); printf("--------------------------\n"); for(GPosition pos=files_list;pos;++pos) { GP file=files_list[pos]; printf("%6d ", file->size); if (file->is_page()) { char buffer[128]; sprintf(buffer, "PAGE #%d", file->get_page_num()+1); printf("%s", buffer); for(int i=strlen(buffer);i<9;i++) putchar(' '); } else if (file->is_include()) { printf("%s", "INCLUDE "); } else if (file->is_shared_anno()) { printf("%s", "SHARED_ANNO "); }else if (file->is_thumbnails()) { printf("%s", "THUMBNAIL"); } else { printf("%s", "UNKNOWN "); } printf(" %s\n", (const char *) file->get_save_name()); } } } int main(int argc, char ** argv) { DJVU_LOCALE; GArray dargv(0,argc-1); for(int i=0;i