51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
54
// $Id: djvused.cpp,v 1.24 2005/05/27 17:36:23 leonb Exp $
55
// $Name: debian_version_3_5_16-1 $
54
// $Id: djvused.cpp,v 1.27 2006/04/04 22:06:17 leonb Exp $
55
// $Name: debian_version_3_5_17-1 $
57
57
#ifdef HAVE_CONFIG_H
58
58
# include "config.h"
184
184
ParsingByteStream::write(const void *, size_t )
186
186
G_THROW("Cannot write() into a ParsingByteStream");
190
191
ParsingByteStream::tell() const
192
193
G_THROW("Cannot tell() a ParsingByteStream");
416
426
static char *tr1 = "\"\\tnrbf";
417
427
static char *tr2 = "\"\\\t\n\r\b\f";
418
428
sprintf(buf,"\\%03o", (int)(((unsigned char*)data)[0]));
419
for (int i=0; tr2[i]; i++)
420
if (*(char*)data == tr2[i])
429
{ // extra nesting for windows
430
for (int i=0; tr2[i]; i++)
431
if (*(char*)data == tr2[i])
422
434
if (buf[1]<'0' || buf[1]>'3')
424
436
out.write(buf, ((buf[2]) ? 4 : 2));
436
448
GPList<DjVmDir::File> lst = g().doc->get_djvm_dir()->get_files_list();
437
for (GPosition p=lst; p; ++p)
449
{ // extra nesting for windows
450
for (GPosition p=lst; p; ++p)
439
452
GP<DjVmDir::File> f = lst[p];
440
453
if (f->is_page())
447
460
fprintf(stdout," A ");
449
462
fprintf(stdout," ? ");
450
GUTF8String id = f->get_load_name();
451
fprintf(stdout,"%8d %s\n", f->size, (const char*)(GNativeString)id);
463
GNativeString id = f->get_load_name();
464
fprintf(stdout,"%8d %s", f->size, (const char*)(GNativeString)id);
465
GNativeString name = f->get_save_name();
467
fprintf(stdout," F=%s", (const char*)name);
468
GNativeString title = f->get_title();
469
if (title != id && f->is_page())
470
fprintf(stdout," T=%s", (const char*)title);
471
fprintf(stdout,"\n");
453
474
if (g().doc->get_thumbnails_num() == g().doc->get_pages_num())
454
475
fprintf(stdout," T %8s %s\n", "", "<thumbnails>");
461
482
GPList<DjVmDir::File> lst = g().doc->get_djvm_dir()->get_files_list();
462
for (GPosition p=lst; p; ++p)
483
{ // extra nesting for windows
484
for (GPosition p=lst; p; ++p)
464
486
GP<DjVmDir::File> f = lst[p];
465
487
if (f->is_page())
468
491
fprintf(stdout,"%d\n", pagenum);
521
544
command_size(ParsingByteStream &)
523
546
GPList<DjVmDir::File> &lst = g().selected;
524
for (GPosition p=lst; p; ++p)
547
{ // extra nesting for windows
548
for (GPosition p=lst; p; ++p)
526
550
if (lst[p]->is_page())
648
673
GPList<DjVmDir::File> &lst = g().selected;
649
for (GPosition p=lst; p; ++p)
674
{ // extra nesting for windows
675
for (GPosition p=lst; p; ++p)
651
677
GP<DjVmDir::File> f = lst[p];
652
678
if (f->is_page())
659
685
fprintf(stdout," A ");
661
687
fprintf(stdout," ? ");
662
GUTF8String id = f->get_load_name();
663
fprintf(stdout,"%8d %s\n", f->size, (const char*)(GNativeString)id);
688
GNativeString id = f->get_load_name();
689
fprintf(stdout,"%8d %s", f->size, (const char*)(GNativeString)id);
690
GNativeString name = f->get_save_name();
692
fprintf(stdout," F=%s", (const char*)name);
693
GNativeString title = f->get_title();
694
if (title != id && f->is_page())
695
fprintf(stdout," T=%s", (const char*)title);
696
fprintf(stdout,"\n");
665
699
if (g().doc->get_thumbnails_num() == g().doc->get_pages_num())
666
700
fprintf(stdout," T %8s %s\n", "", "<thumbnails>");
704
command_set_page_title(ParsingByteStream &pbs)
707
verror("must select a single page first");
708
GUTF8String fname = pbs.get_native_token();
710
verror("must provide a name");
711
GPList<DjVmDir::File> &lst = g().selected;
713
if (! lst[pos]->is_page())
714
verror("component file is not a page");
715
g().doc->set_file_title(g().fileid, fname);
716
vprint("set-page-title: modified \"%s\"", (const char*)(GNativeString)g().fileid);
669
721
#define DELMETA 1
670
722
#define CHKCOMPAT 2
671
723
#define EIGHTBIT 4
857
909
command_remove_ant(ParsingByteStream &)
859
911
GPList<DjVmDir::File> & lst = g().selected;
860
for (GPosition p=lst; p; ++p)
912
{ // extra nesting for windows
913
for (GPosition p=lst; p; ++p)
862
915
GUTF8String id = lst[p]->get_load_name();
863
916
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
864
917
file_remove_ant(f, id);
949
1005
if (newmeta && !newmeta->isempty())
951
1007
newant->writestring(GUTF8String("(metadata"));
952
for (GPosition pos=newmeta->firstpos(); pos; ++pos)
1008
{ // extra nesting for windows
1009
for (GPosition pos=newmeta->firstpos(); pos; ++pos)
954
1011
GUTF8String key = newmeta->key(pos);
955
1012
GUTF8String val = (*newmeta)[pos];
996
1054
command_remove_meta(ParsingByteStream &)
998
1056
GPList<DjVmDir::File> &lst = g().selected;
999
for (GPosition p=lst; p; ++p)
1057
{ // extra nesting for windows
1058
for (GPosition p=lst; p; ++p)
1001
1060
GUTF8String id = lst[p]->get_load_name();
1002
1061
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1003
1062
file_remove_meta(f, id);
1170
1230
const GP<ByteStream> out = ByteStream::create("w");
1171
1231
GPList<DjVmDir::File> &lst = g().selected;
1172
for (GPosition p=lst; p; ++p)
1173
if (lst[p]->is_page())
1232
{ // extra nesting for windows
1233
for (GPosition p=lst; p; ++p)
1234
if (lst[p]->is_page())
1175
1236
GUTF8String id = lst[p]->get_load_name();
1176
1237
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1188
1250
const GP<ByteStream> out = ByteStream::create("w");
1189
1251
GP<DjVuTXT> txt;
1190
1252
GPList<DjVmDir::File> &lst = g().selected;
1191
for (GPosition p=lst; p; ++p)
1253
{ // extra nesting for windows
1254
for (GPosition p=lst; p; ++p)
1193
1256
GUTF8String id = lst[p]->get_load_name();
1194
1257
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1234
1298
command_remove_txt(ParsingByteStream &)
1236
1300
GPList<DjVmDir::File> &lst = g().selected;
1237
for (GPosition p=lst; p; ++p)
1301
{ // extra nesting for windows
1302
for (GPosition p=lst; p; ++p)
1239
1304
GUTF8String id = lst[p]->get_load_name();
1240
1305
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1241
1306
file_remove_txt(f, id);
1423
1489
const char *pre = "select; remove-ant\n";
1424
1490
out->write(pre, strlen(pre));
1425
1491
GPList<DjVmDir::File> &lst = g().selected;
1426
for (GPosition p=lst; p; ++p)
1492
{ // extra nesting for windows
1493
for (GPosition p=lst; p; ++p)
1428
1495
GUTF8String id = lst[p]->get_load_name();
1429
1496
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1430
1497
output(f, out, 1, id);
1445
1513
const char *pre = "select; remove-txt\n";
1446
1514
out->write(pre, strlen(pre));
1447
1515
GPList<DjVmDir::File> &lst = g().selected;
1448
for (GPosition p=lst; p; ++p)
1516
{ // extra nesting for windows
1517
for (GPosition p=lst; p; ++p)
1450
1519
GUTF8String id = lst[p]->get_load_name();
1451
1520
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1452
1521
output(f, out, 2, id);
1467
1537
const char *pre = "select; remove-ant; remove-txt\n";
1468
1538
out->write(pre, strlen(pre));
1469
1539
GPList<DjVmDir::File> &lst = g().selected;
1470
for (GPosition p=lst; p; ++p)
1540
{ // extra nesting for windows
1541
for (GPosition p=lst; p; ++p)
1472
1543
GUTF8String id = lst[p]->get_load_name();
1473
1544
const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1474
1545
output(f, out, 3, id);
1485
1557
while (count > 0 && pos < nav->getBookMarkCount())
1487
1559
out->write("\n",1);
1488
for (int i=0; i<indent; i++)
1560
{ // extra nesting for windows
1561
for (int i=0; i<indent; i++)
1490
1564
nav->getBookMark(entry, pos++);
1491
1565
out->write("(",2);
1492
1566
str = entry->displayname;
1493
1567
print_c_string(str, str.length(), *out);
1494
1568
out->write("\n ",2);
1495
for (int i=0; i<indent; i++)
1569
{ // extra nesting for windows
1570
for (int i=0; i<indent; i++)
1497
1573
str = entry->url;
1498
1574
print_c_string(str, str.length(), *out);
1499
1575
print_outline_sub(nav, pos, entry->count, out, indent+1);
1739
1815
" remove-txt -- removes hidden text\n"
1740
1816
" _ remove-outline -- removes outline (bookmarks)\n"
1741
1817
" _ remove-thumbnails -- removes all thumbnails\n"
1818
" . set-page-title <title> -- sets an alternate page title\n"
1742
1819
" . save-page <name> -- saves selected page/file as is\n"
1743
1820
" . save-page-with <name> -- saves selected page/file, inserting all included files\n"
1744
1821
" _ save-bundled <name> -- saves as bundled document under fname\n"
1801
1878
xcommand_map["remove-meta"] = command_remove_meta;
1802
1879
xcommand_map["remove-txt"] = command_remove_txt;
1803
1880
xcommand_map["remove-thumbnails"] = command_remove_thumbnails;
1881
xcommand_map["set-page-title"] = command_set_page_title;
1804
1882
xcommand_map["save-page"] = command_save_page;
1805
1883
xcommand_map["save-page-with"] = command_save_page_with;
1806
1884
xcommand_map["save-bundled"] = command_save_bundled;
1893
1971
djvu_programname(argv[0]);
1896
for (int i=1; i<argc; i++)
1897
if (!strcmp(argv[i],"-v"))
1899
else if (!strcmp(argv[i],"-s"))
1901
else if (!strcmp(argv[i],"-n"))
1903
else if (!strcmp(argv[i],"-f") && i+1<argc && !g().cmdbs)
1904
g().cmdbs = ByteStream::create(GURL::Filename::UTF8(argv[++i]), "r");
1905
else if (!strcmp(argv[i],"-e") && !g().cmdbs && ++i<argc)
1906
g().cmdbs = ByteStream::create_static(argv[i],strlen(argv[i]));
1907
else if (argv[i][0] != '-' && !g().djvufile)
1908
g().djvufile = argv[i];
1974
{ // extra nesting for windows
1975
for (int i=1; i<argc; i++)
1976
if (!strcmp(argv[i],"-v"))
1978
else if (!strcmp(argv[i],"-s"))
1980
else if (!strcmp(argv[i],"-n"))
1982
else if (!strcmp(argv[i],"-f") && i+1<argc && !g().cmdbs)
1983
g().cmdbs = ByteStream::create(GURL::Filename::UTF8(argv[++i]), "r");
1984
else if (!strcmp(argv[i],"-e") && !g().cmdbs && ++i<argc)
1985
g().cmdbs = ByteStream::create_static(argv[i],strlen(argv[i]));
1986
else if (argv[i][0] != '-' && !g().djvufile)
1987
g().djvufile = argv[i];
1911
1991
if (!g().djvufile)