~ubuntu-branches/ubuntu/edgy/djvulibre/edgy

« back to all changes in this revision

Viewing changes to tools/djvused.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-07-03 11:38:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113823-un2te7742kk04c63
Tags: 3.5.17-1ubuntu1
* Sync with Debian
* debian/rules:
  - use dh_iconcache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
53
53
//
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 $
56
56
 
57
57
#ifdef HAVE_CONFIG_H
58
58
# include "config.h"
184
184
ParsingByteStream::write(const void *, size_t )
185
185
{
186
186
  G_THROW("Cannot write() into a ParsingByteStream");
 
187
  return 0;
187
188
}
188
189
 
189
190
long int
190
191
ParsingByteStream::tell() const
191
192
192
193
  G_THROW("Cannot tell() a ParsingByteStream");
 
194
  return 0;
193
195
}
194
196
 
195
197
inline int 
264
266
              else if (c>='0' && c<='7')
265
267
                {
266
268
                  int x = 0;
267
 
                  for (int i=0; i<3 && c>='0' && c<='7'; i++) 
 
269
                  { // extra nesting for windows
 
270
                    for (int i=0; i<3 && c>='0' && c<='7'; i++) 
268
271
                    {
269
272
                      x = x * 8 + c - '0';
270
273
                      c = get();
271
274
                    }
 
275
                  }
272
276
                  unget(c);
273
277
                  c = x;
274
278
                }
276
280
                {
277
281
                  char *tr1 = "tnrbfva";
278
282
                  char *tr2 = "\t\n\r\b\f\013\007";
279
 
                  for (int i=0; tr1[i]; i++)
280
 
                    if (c == tr1[i])
281
 
                      c = tr2[i];
 
283
                  { // extra nesting for windows
 
284
                    for (int i=0; tr1[i]; i++)
 
285
                    {
 
286
                      if (c == tr1[i])
 
287
                        c = tr2[i];
 
288
                    }
 
289
                  }
282
290
                }
283
291
            }
284
292
          if (c != EOF)
362
370
            }
363
371
          else
364
372
            {
365
 
              for (char *m=skip; m<s; m++)
366
 
                out.write8(*m);
 
373
              { // extra nesting for windows
 
374
                for (char *m=skip; m<s; m++)
 
375
                  out.write8(*m);
 
376
              }
367
377
              s = skip;
368
378
              state = 0;
369
379
              if (c == '\n')
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])
421
 
              buf[1] = tr1[i];
 
429
          { // extra nesting for windows
 
430
            for (int i=0; tr2[i]; i++)
 
431
              if (*(char*)data == tr2[i])
 
432
                buf[1] = tr1[i];
 
433
          }
422
434
          if (buf[1]<'0' || buf[1]>'3')
423
435
            buf[2] = 0;
424
436
          out.write(buf, ((buf[2]) ? 4 : 2));
434
446
{
435
447
  int pagenum = 0;
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) 
438
451
    {
439
452
      GP<DjVmDir::File> f = lst[p];
440
453
      if (f->is_page())
447
460
        fprintf(stdout,"     A ");
448
461
      else
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();
 
466
      if (name != id)
 
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");
452
472
    }
 
473
  }
453
474
  if (g().doc->get_thumbnails_num() == g().doc->get_pages_num())
454
475
    fprintf(stdout,"     T %8s  %s\n", "", "<thumbnails>");
455
476
}
459
480
{
460
481
  int pagenum = 0;
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) 
463
485
    {
464
486
      GP<DjVmDir::File> f = lst[p];
465
487
      if (f->is_page())
466
488
        ++pagenum;
467
489
    }
 
490
  }
468
491
  fprintf(stdout,"%d\n", pagenum); 
469
492
}
470
493
 
521
544
command_size(ParsingByteStream &)
522
545
{
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)
525
549
    {
526
550
      if (lst[p]->is_page())
527
551
        {
530
554
          print_size(f);
531
555
        }
532
556
    }
 
557
  }
533
558
}
534
559
 
535
560
static void
646
671
{
647
672
  int pagenum = 0;
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) 
650
676
    {
651
677
      GP<DjVmDir::File> f = lst[p];
652
678
      if (f->is_page())
659
685
        fprintf(stdout,"     A ");
660
686
      else
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();
 
691
      if (name != id)
 
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");
664
697
    }
 
698
  }
665
699
  if (g().doc->get_thumbnails_num() == g().doc->get_pages_num())
666
700
    fprintf(stdout,"     T %8s  %s\n", "", "<thumbnails>");
667
701
}
668
702
 
 
703
void
 
704
command_set_page_title(ParsingByteStream &pbs)
 
705
{
 
706
  if (! g().file)
 
707
    verror("must select a single page first");
 
708
  GUTF8String fname = pbs.get_native_token();
 
709
  if (! fname)
 
710
    verror("must provide a name");
 
711
  GPList<DjVmDir::File> &lst = g().selected;
 
712
  GPosition pos = lst;
 
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);
 
717
  modified = true;
 
718
}
 
719
 
 
720
 
669
721
#define DELMETA     1
670
722
#define CHKCOMPAT   2
671
723
#define EIGHTBIT    4
857
909
command_remove_ant(ParsingByteStream &)
858
910
{
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)
861
914
    {
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);
865
918
    }
 
919
  }
866
920
}
867
921
 
868
922
void
901
955
      }
902
956
      if (ok)
903
957
        {
904
 
          for (GPosition pos=ant->metadata; pos; ++pos)
 
958
          { // extra nesting for windows
 
959
            for (GPosition pos=ant->metadata; pos; ++pos)
905
960
            { 
906
961
              GUTF8String tmp;
907
962
              tmp=ant->metadata.key(pos);
911
966
              print_c_string((const char*)tmp, tmp.length(), out);
912
967
              out.write8('\n');
913
968
            }
 
969
          }
914
970
        }
915
971
      iff.close_chunk();
916
972
    }
949
1005
  if (newmeta && !newmeta->isempty())
950
1006
    {
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)
953
1010
        {
954
1011
          GUTF8String key = newmeta->key(pos); 
955
1012
          GUTF8String val = (*newmeta)[pos];
960
1017
                         *newant, true);
961
1018
          newant->write(")",1);
962
1019
        }
 
1020
      }
963
1021
      newant->write(" )\n",3);
964
1022
      changed = true;
965
1023
    }
996
1054
command_remove_meta(ParsingByteStream &)
997
1055
{
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)
1000
1059
    {
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);
1004
1063
    }
 
1064
  }
1005
1065
}
1006
1066
 
1007
1067
void
1169
1229
{
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())
1174
1235
      {
1175
1236
        GUTF8String id = lst[p]->get_load_name();
1176
1237
        const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1180
1241
        else
1181
1242
          out->write("(page 0 0 0 0 \"\")\n",18);
1182
1243
      }
 
1244
  }
1183
1245
}
1184
1246
 
1185
1247
void
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)
1192
1255
    {
1193
1256
      GUTF8String id = lst[p]->get_load_name();
1194
1257
      const GP<DjVuFile> f(g().doc->get_djvu_file(id));
1199
1262
        }
1200
1263
      out->write("\f",1);
1201
1264
    }
 
1265
  }
1202
1266
}
1203
1267
 
1204
1268
static void
1234
1298
command_remove_txt(ParsingByteStream &)
1235
1299
{
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)
1238
1303
    {
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);
1242
1307
    }
 
1308
  }
1243
1309
}
1244
1310
 
1245
1311
void
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)
1427
1494
        {
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);
1431
1498
        }
 
1499
      }
1432
1500
    }
1433
1501
}
1434
1502
 
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)
1449
1518
        {
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);
1453
1522
        }
 
1523
      }
1454
1524
    }
1455
1525
}
1456
1526
 
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)
1471
1542
        {
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);
1475
1546
        }
 
1547
      }
1476
1548
    }
1477
1549
}
1478
1550
 
1485
1557
  while (count > 0 && pos < nav->getBookMarkCount())
1486
1558
    {
1487
1559
      out->write("\n",1);
1488
 
      for (int i=0; i<indent; i++)
1489
 
        out->write(" ",1);
 
1560
      { // extra nesting for windows
 
1561
        for (int i=0; i<indent; i++)
 
1562
          out->write(" ",1);
 
1563
      }
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++)
1496
 
        out->write(" ",1);
 
1569
      { // extra nesting for windows
 
1570
        for (int i=0; i<indent; i++)
 
1571
          out->write(" ",1);
 
1572
      }
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]);
1894
1972
  G_TRY
1895
1973
     {
1896
 
      for (int i=1; i<argc; i++)
1897
 
        if (!strcmp(argv[i],"-v"))
1898
 
          verbose = true;
1899
 
        else if (!strcmp(argv[i],"-s"))
1900
 
          save = true; 
1901
 
        else if (!strcmp(argv[i],"-n"))
1902
 
          nosave = true;
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];
1909
 
        else
1910
 
          usage();
 
1974
      { // extra nesting for windows
 
1975
        for (int i=1; i<argc; i++)
 
1976
          if (!strcmp(argv[i],"-v"))
 
1977
            verbose = true;
 
1978
          else if (!strcmp(argv[i],"-s"))
 
1979
            save = true; 
 
1980
          else if (!strcmp(argv[i],"-n"))
 
1981
            nosave = true;
 
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];
 
1988
          else
 
1989
            usage();
 
1990
      }
1911
1991
      if (!g().djvufile)
1912
1992
        usage();
1913
1993
      // Open file