<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ww8scan.hxx,v $
 *
 *  $Revision: 1.75 $
 *
 *  last change: $Author: hr $ $Date: 2006-01-26 18:22:52 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */

#ifndef _WW8SCAN_HXX
#define _WW8SCAN_HXX

#ifndef LONG_MAX
#include <limits.h>
#endif
#include <stack>
#include <vector>
#include <list>
#include <algorithm>

#ifndef _SOLAR_H
#include <tools/solar.h>        // UINTXX
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif

#ifndef _ERRHDL_HXX
#include <errhdl.hxx>       // ASSERT()
#endif

#ifndef WW_SORTEDARRAY_HXX
#include "sortedarray.hxx"
#endif

#ifndef WW8STRUC_HXX
#include "ww8struc.hxx"         // FIB, STSHI, STD...
#endif
#ifndef _TYPES_HXX
#include <types.hxx>
#endif

#define APPEND_CONST_ASC(s) AppendAscii(RTL_CONSTASCII_STRINGPARAM(s))
#define ASSIGN_CONST_ASC(s) AssignAscii(RTL_CONSTASCII_STRINGPARAM(s))
#define CREATE_CONST_ASC(s) String::CreateFromAscii( \
    RTL_CONSTASCII_STRINGPARAM(s))

#ifndef C2U
#define C2U(s) rtl::OUString::createFromAscii(s)
#endif

//--Line below which the code has meaningful comments

//Commonly used string literals for stream and storage names in word docs
namespace SL
{
#   define DEFCONSTSTRINGARRAY(X) extern const char a##X[sizeof("" #X "")]
    DEFCONSTSTRINGARRAY(ObjectPool);
    DEFCONSTSTRINGARRAY(1Table);
    DEFCONSTSTRINGARRAY(0Table);
    DEFCONSTSTRINGARRAY(Data);
    DEFCONSTSTRINGARRAY(CheckBox);
    DEFCONSTSTRINGARRAY(ListBox);
    DEFCONSTSTRINGARRAY(TextBox);
    DEFCONSTSTRINGARRAY(TextField);
    DEFCONSTSTRINGARRAY(MSMacroCmds);
}

/*
 winword strings are typically Belt and Braces strings preceeded with a
 pascal style count, and ending with a c style 0 terminator. 16bit chars
 and count for ww8+ and 8bit chars and count for ww7-. The count and 0
 can be checked for integrity to catch errors (e.g. lotus created documents)
 where in error 8bit strings are used instead of 16bits strings for style
 names.
*/
template<class C> class wwString
{
public:
    static bool TestBeltAndBraces(const SvStream& rStrm);
    //move the other string related code into this class as time goes by
};

typedef wwString<sal_uInt16> ww8String;

struct SprmInfo
{
    sal_uInt16 nId;         //A ww8 sprm is hardcoded as 16bits
    unsigned int nLen : 6;
    unsigned int nVari : 2;
};

//a managed sorted sequence of sprminfos
typedef ww::SortedArray<SprmInfo> wwSprmSearcher;
//a managed sorted sequence of sprms
typedef ww::SortedArray<sal_uInt16> wwSprmSequence;

//wwSprmParser knows how to take a sequence of bytes and split it up into
//sprms and their arguments
class wwSprmParser
{
private:
    ww::WordVersion meVersion;
    BYTE mnDelta;
    const wwSprmSearcher *mpKnownSprms;
    static const wwSprmSearcher* GetWW8SprmSearcher();
    static const wwSprmSearcher* GetWW6SprmSearcher();
    static const wwSprmSearcher* GetWW2SprmSearcher();

    SprmInfo GetSprmInfo(sal_uInt16 nId) const;

    BYTE SprmDataOfs(sal_uInt16 nId) const;

    enum SprmType {L_FIX=0, L_VAR=1, L_VAR2=2};
public:
    //7- ids are very different to 8+ ones
    wwSprmParser(ww::WordVersion eVersion);
    //Return the SPRM id at the beginning of this byte sequence
    sal_uInt16 GetSprmId(const sal_uInt8* pSp) const;

    USHORT GetSprmSize(sal_uInt16 nId, const sal_uInt8* pSprm) const;

    //Get known len of a sprms head, the bytes of the sprm id + any bytes
    //reserved to hold a variable length
    USHORT DistanceToData(sal_uInt16 nId) const;

    //Get len of a sprms data area, ignoring the bytes of the sprm id and
    //ignoring any len bytes. Reports the remaining data after those bytes
    USHORT GetSprmTailLen(sal_uInt16 nId, const sal_uInt8 * pSprm) const;

    //The minimum acceptable sprm len possible for this type of parser
    int MinSprmLen() const { return (IsSevenMinus(meVersion)) ? 2 : 3; }

    inline int getVersion() const { return meVersion; } //cmc, I'm dubious about the usage of this, how can it be 0
};

//--Line abovewhich the code has meaningful comments

class  WW8Fib;
class  WW8ScannerBase;
class  WW8PLCFspecial;
struct WW8PLCFxDesc;
class  WW8PLCFx_PCD;

String WW8ReadPString( SvStream& rStrm, rtl_TextEncoding eEnc,
    bool bAtEndSeekRel1 = true);

/*
 The following method reads a 2Byte unicode string.  If bAtEndSeekRel1 is set,
 exactly ONE byte is skipped If nChars is set then that number of characters
 (not bytes) is read, if its not set, the first character read is the length
*/
String WW8Read_xstz(SvStream& rStrm, USHORT nChars, bool bAtEndSeekRel1);

/*
 reads array of strings (see MS documentation: STring TaBle stored in File)
 returns NOT the original pascal strings but an array of converted char*

 attention: the *extra data* of each string are SKIPPED and ignored
 */
void WW8ReadSTTBF(bool bVer8, SvStream& rStrm, UINT32 nStart, INT32 nLen,
    USHORT nExtraLen, rtl_TextEncoding eCS, ::std::vector<String> &rArray,
    ::std::vector<ww::bytes>* pExtraArray = 0);

struct WW8FieldDesc
{
    long nLen;              // Gesamtlaenge ( zum Text ueberlesen )
    WW8_CP nSCode;           // Anfang Befehlscode
    long nLCode;            // Laenge
    WW8_CP nSRes;           // Anfang Ergebnis
    long nLRes;             // Laenge ( == 0, falls kein Ergebnis )
    USHORT nId;             // WW-Id fuer Felder
    BYTE nOpt;              // WW-Flags ( z.B.: vom User geaendert )
    BYTE bCodeNest:1;       // Befehl rekursiv verwendet<commit_msg>INTEGRATION: CWS rtfpp2 (1.74.38); FILE MERGED 2005/12/16 10:29:05 flr 172.16.17.32: #129053# import document variables as meta information<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ww8scan.hxx,v $
 *
 *  $Revision: 1.76 $
 *
 *  last change: $Author: rt $ $Date: 2006-02-09 13:48:16 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */

#ifndef _WW8SCAN_HXX
#define _WW8SCAN_HXX

#ifndef LONG_MAX
#include <limits.h>
#endif
#include <stack>
#include <vector>
#include <list>
#include <algorithm>

#ifndef _SOLAR_H
#include <tools/solar.h>        // UINTXX
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif

#ifndef _ERRHDL_HXX
#include <errhdl.hxx>       // ASSERT()
#endif

#ifndef WW_SORTEDARRAY_HXX
#include "sortedarray.hxx"
#endif

#ifndef WW8STRUC_HXX
#include "ww8struc.hxx"         // FIB, STSHI, STD...
#endif
#ifndef _TYPES_HXX
#include <types.hxx>
#endif

#define APPEND_CONST_ASC(s) AppendAscii(RTL_CONSTASCII_STRINGPARAM(s))
#define ASSIGN_CONST_ASC(s) AssignAscii(RTL_CONSTASCII_STRINGPARAM(s))
#define CREATE_CONST_ASC(s) String::CreateFromAscii( \
    RTL_CONSTASCII_STRINGPARAM(s))

#ifndef C2U
#define C2U(s) rtl::OUString::createFromAscii(s)
#endif

//--Line below which the code has meaningful comments

//Commonly used string literals for stream and storage names in word docs
namespace SL
{
#   define DEFCONSTSTRINGARRAY(X) extern const char a##X[sizeof("" #X "")]
    DEFCONSTSTRINGARRAY(ObjectPool);
    DEFCONSTSTRINGARRAY(1Table);
    DEFCONSTSTRINGARRAY(0Table);
    DEFCONSTSTRINGARRAY(Data);
    DEFCONSTSTRINGARRAY(CheckBox);
    DEFCONSTSTRINGARRAY(ListBox);
    DEFCONSTSTRINGARRAY(TextBox);
    DEFCONSTSTRINGARRAY(TextField);
    DEFCONSTSTRINGARRAY(MSMacroCmds);
}

/*
 winword strings are typically Belt and Braces strings preceeded with a
 pascal style count, and ending with a c style 0 terminator. 16bit chars
 and count for ww8+ and 8bit chars and count for ww7-. The count and 0
 can be checked for integrity to catch errors (e.g. lotus created documents)
 where in error 8bit strings are used instead of 16bits strings for style
 names.
*/
template<class C> class wwString
{
public:
    static bool TestBeltAndBraces(const SvStream& rStrm);
    //move the other string related code into this class as time goes by
};

typedef wwString<sal_uInt16> ww8String;

struct SprmInfo
{
    sal_uInt16 nId;         //A ww8 sprm is hardcoded as 16bits
    unsigned int nLen : 6;
    unsigned int nVari : 2;
};

//a managed sorted sequence of sprminfos
typedef ww::SortedArray<SprmInfo> wwSprmSearcher;
//a managed sorted sequence of sprms
typedef ww::SortedArray<sal_uInt16> wwSprmSequence;

//wwSprmParser knows how to take a sequence of bytes and split it up into
//sprms and their arguments
class wwSprmParser
{
private:
    ww::WordVersion meVersion;
    BYTE mnDelta;
    const wwSprmSearcher *mpKnownSprms;
    static const wwSprmSearcher* GetWW8SprmSearcher();
    static const wwSprmSearcher* GetWW6SprmSearcher();
    static const wwSprmSearcher* GetWW2SprmSearcher();

    SprmInfo GetSprmInfo(sal_uInt16 nId) const;

    BYTE SprmDataOfs(sal_uInt16 nId) const;

    enum SprmType {L_FIX=0, L_VAR=1, L_VAR2=2};
public:
    //7- ids are very different to 8+ ones
    wwSprmParser(ww::WordVersion eVersion);
    //Return the SPRM id at the beginning of this byte sequence
    sal_uInt16 GetSprmId(const sal_uInt8* pSp) const;

    USHORT GetSprmSize(sal_uInt16 nId, const sal_uInt8* pSprm) const;

    //Get known len of a sprms head, the bytes of the sprm id + any bytes
    //reserved to hold a variable length
    USHORT DistanceToData(sal_uInt16 nId) const;

    //Get len of a sprms data area, ignoring the bytes of the sprm id and
    //ignoring any len bytes. Reports the remaining data after those bytes
    USHORT GetSprmTailLen(sal_uInt16 nId, const sal_uInt8 * pSprm) const;

    //The minimum acceptable sprm len possible for this type of parser
    int MinSprmLen() const { return (IsSevenMinus(meVersion)) ? 2 : 3; }

    inline int getVersion() const { return meVersion; } //cmc, I'm dubious about the usage of this, how can it be 0
};

//--Line abovewhich the code has meaningful comments

class  WW8Fib;
class  WW8ScannerBase;
class  WW8PLCFspecial;
struct WW8PLCFxDesc;
class  WW8PLCFx_PCD;

String WW8ReadPString( SvStream& rStrm, rtl_TextEncoding eEnc,
    bool bAtEndSeekRel1 = true);

/*
 The following method reads a 2Byte unicode string.  If bAtEndSeekRel1 is set,
 exactly ONE byte is skipped If nChars is set then that number of characters
 (not bytes) is read, if its not set, the first character read is the length
*/
String WW8Read_xstz(SvStream& rStrm, USHORT nChars, bool bAtEndSeekRel1);

/*
 reads array of strings (see MS documentation: STring TaBle stored in File)
 returns NOT the original pascal strings but an array of converted char*

 attention: the *extra data* of each string are SKIPPED and ignored
 */
void WW8ReadSTTBF(bool bVer8, SvStream& rStrm, UINT32 nStart, INT32 nLen,
    USHORT nExtraLen, rtl_TextEncoding eCS, ::std::vector<String> &rArray,
    ::std::vector<ww::bytes>* pExtraArray = 0, ::std::vector<String>* pValueArray = 0);

struct WW8FieldDesc
{
    long nLen;              // Gesamtlaenge ( zum Text ueberlesen )
    WW8_CP nSCode;           // Anfang Befehlscode
    long nLCode;            // Laenge
    WW8_CP nSRes;           // Anfang Ergebnis
    long nLRes;             // Laenge ( == 0, falls kein Ergebnis )
    USHORT nId;             // WW-Id fuer Felder
    BYTE nOpt;              // WW-Flags ( z.B.: vom User geaendert )
    BYTE bCodeNest:1;       // Befehl rekursiv verwendet
{'fraction_non_alphanumeric': 0.10773800898420519, 'fraction_numerical': 0.02159107375742646, 'mean_word_length': 3.7728215767634854, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469431', 'n_tokens_mistral': 4761, 'n_tokens_neox': 4443, 'n_words': 1552}