~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kspread/excel/sidewinder/pole.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
    void load();
157
157
    void create();
158
158
 
159
 
    unsigned long loadBigBlocks(std::vector<unsigned long> blocks, unsigned char* buffer, unsigned long maxlen);
 
159
    unsigned long loadBigBlocks(const std::vector<unsigned long>& blocks, unsigned char* buffer, unsigned long maxlen);
 
160
    unsigned long loadBigBlocks(const unsigned long* blocks, unsigned blockCount, unsigned char* buffer, unsigned long maxlen);
160
161
 
161
162
    unsigned long loadBigBlock(unsigned long block, unsigned char* buffer, unsigned long maxlen);
162
163
 
163
 
    unsigned long loadSmallBlocks(std::vector<unsigned long> blocks, unsigned char* buffer, unsigned long maxlen);
 
164
    unsigned long loadSmallBlocks(const std::vector<unsigned long>& blocks, unsigned char* buffer, unsigned long maxlen);
 
165
    unsigned long loadSmallBlocks(const unsigned long* blocks, unsigned blockCount, unsigned char* buffer, unsigned long maxlen);
164
166
 
165
167
    unsigned long loadSmallBlock(unsigned long block, unsigned char* buffer, unsigned long maxlen);
166
168
 
392
394
    }
393
395
}
394
396
 
 
397
// TODO: optimize this with better search
 
398
static bool already_exist(const std::vector<unsigned long>& chain, unsigned long item)
 
399
{
 
400
    for(unsigned i = 0; i < chain.size(); i++)
 
401
        if(chain[i] == item) return true;
 
402
    return false;
 
403
}
 
404
 
395
405
// follow
396
406
std::vector<unsigned long> AllocTable::follow(unsigned long start)
397
407
{
404
414
        if (p == (unsigned long)Eof) break;
405
415
        if (p == (unsigned long)Bat) break;
406
416
        if (p == (unsigned long)MetaBat) break;
407
 
        if (p >= count()) break;
 
417
        if (already_exist(chain, p)) break;
408
418
        chain.push_back(p);
409
419
        if (data[p] >= count()) break;
410
420
        p = data[ p ];
507
517
    // and check if one of the children is 'index'
508
518
    for (unsigned j = 0; j < entryCount(); j++) {
509
519
        std::vector<unsigned> chi = children(j);
510
 
        for (unsigned i = 0; i < chi.size();i++)
 
520
        for (unsigned i = 0; i < chi.size(); i++)
511
521
            if (chi[i] == index)
512
522
                return j;
513
523
    }
681
691
        e.next = readU32(buffer + 0x48 + p);
682
692
        e.child = readU32(buffer + 0x4C + p);
683
693
        e.dir = (type != 2);
684
 
        
 
694
 
685
695
        // sanity checks
686
696
        if ((type != 2) && (type != 1) && (type != 5)) e.valid = false;
687
697
        if (name_len < 1) e.valid = false;
688
698
 
689
699
        // CLSID, contains a object class GUI if this entry is a storage or root
690
700
        // storage or all zero if not.
691
 
        printf("DirTree::load name=%s type=%i prev=%i next=%i child=%i start=%i size=%i clsid=%i.%i.%i.%i\n",
692
 
               name.c_str(),type,e.prev,e.next,e.child,e.start,e.size,readU32(buffer+0x50+p),readU32(buffer+0x54+p),readU32(buffer+0x58+p),readU32(buffer+0x5C+p));
 
701
        printf("DirTree::load name=%s type=%i prev=%i next=%i child=%i start=%lu size=%lu clsid=%lu.%lu.%lu.%lu\n",
 
702
               name.c_str(), type, e.prev, e.next, e.child, e.start, e.size, readU32(buffer + 0x50 + p), readU32(buffer + 0x54 + p), readU32(buffer + 0x58 + p), readU32(buffer + 0x5C + p));
693
703
 
694
704
        entries.push_back(e);
695
705
    }
988
998
    return result;
989
999
}
990
1000
 
991
 
unsigned long StorageIO::loadBigBlocks(std::vector<unsigned long> blocks,
 
1001
unsigned long StorageIO::loadBigBlocks(const std::vector<unsigned long>& blocks,
992
1002
                                       unsigned char* data, unsigned long maxlen)
993
1003
{
 
1004
    return loadBigBlocks(blocks.data(), blocks.size(), data, maxlen);
 
1005
}
 
1006
 
 
1007
unsigned long StorageIO::loadBigBlocks(const unsigned long *blocks, unsigned blockCount,
 
1008
                                       unsigned char *data, unsigned long maxlen)
 
1009
{
994
1010
    // sentinel
995
1011
    if (!data) return 0;
996
1012
    if (!file.good()) return 0;
997
 
    if (blocks.size() < 1) return 0;
 
1013
    if (!blocks) return 0;
 
1014
    if (blockCount < 1) return 0;
998
1015
    if (maxlen == 0) return 0;
999
1016
 
1000
1017
    // read block one by one, seems fast enough
1001
1018
    unsigned long bytes = 0;
1002
 
    for (unsigned long i = 0; (i < blocks.size()) && (bytes < maxlen); i++) {
 
1019
    for (unsigned long i = 0; (i < blockCount) && (bytes < maxlen); i++) {
1003
1020
        unsigned long block = blocks[i];
1004
1021
        unsigned long pos =  bbat->blockSize * (block + 1);
1005
1022
        unsigned long p = (bbat->blockSize < maxlen - bytes) ? bbat->blockSize : maxlen - bytes;
1020
1037
    if (!data) return 0;
1021
1038
    if (!file.good()) return 0;
1022
1039
 
1023
 
    // wraps call for loadBigBlocks
1024
 
    std::vector<unsigned long> blocks;
1025
 
    blocks.resize(1);
1026
 
    blocks[ 0 ] = block;
1027
 
 
1028
 
    return loadBigBlocks(blocks, data, maxlen);
 
1040
    return loadBigBlocks(&block, 1, data, maxlen);
1029
1041
}
1030
1042
 
1031
1043
// return number of bytes which has been read
1032
 
unsigned long StorageIO::loadSmallBlocks(std::vector<unsigned long> blocks,
 
1044
unsigned long StorageIO::loadSmallBlocks(const std::vector<unsigned long>& blocks,
1033
1045
        unsigned char* data, unsigned long maxlen)
1034
1046
{
 
1047
    return loadSmallBlocks(blocks.data(), blocks.size(), data, maxlen);
 
1048
}
 
1049
 
 
1050
unsigned long StorageIO::loadSmallBlocks(const unsigned long *blocks, unsigned blockCount,
 
1051
                                         unsigned char *data, unsigned long maxlen)
 
1052
{
1035
1053
    // sentinel
1036
1054
    if (!data) return 0;
1037
1055
    if (!file.good()) return 0;
1038
 
    if (blocks.size() < 1) return 0;
 
1056
    if (!blocks) return 0;
 
1057
    if (blockCount < 1) return 0;
1039
1058
    if (maxlen == 0) return 0;
1040
1059
 
1041
1060
    // our own local buffer
1043
1062
 
1044
1063
    // read small block one by one
1045
1064
    unsigned long bytes = 0;
1046
 
    for (unsigned long i = 0; (i < blocks.size()) && (bytes < maxlen); i++) {
 
1065
    for (unsigned long i = 0; (i < blockCount) && (bytes < maxlen); i++) {
1047
1066
        unsigned long block = blocks[i];
1048
1067
 
1049
1068
        // find where the small-block exactly is
1077
1096
    if (!data) return 0;
1078
1097
    if (!file.good()) return 0;
1079
1098
 
1080
 
    // wraps call for loadSmallBlocks
1081
 
    std::vector<unsigned long> blocks;
1082
 
    blocks.resize(1);
1083
 
    blocks.assign(1, block);
1084
 
 
1085
 
    return loadSmallBlocks(blocks, data, maxlen);
 
1099
    return loadSmallBlocks(&block, 1, data, maxlen);
1086
1100
}
1087
1101
 
1088
1102
// =========== StreamIO ==========