// PCompress
// Copyright (C) 1999 Britt Yenne
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program 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 General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 
// To contact the author, visit:  http://www.jump.net/~syenne/pilot/

// Database information structure (for GUI table view)
//
typedef struct {
  UInt card;
  LocalID id;
  UInt flags;
  ULong size;
  ULong origSize;
  ULong type;
  ULong creator;
  char name[33];
  Boolean compressed;
  Boolean resourceDB;
  Boolean valid;
} DBInfo;

// Database views (categories)
//
typedef enum {
  DBViewAll,		// view all databases
  DBViewComp,		// view all compressed databases
  DBViewUncomp		// view all uncompressed databases
} DBViewType;

// Compressed database header.  This header is the first compressed
// record in each database.  It contains the information about the
// compressed database as returned from DmDatabaseInfo().
//
typedef struct {
  //
  // These first fields are the compress application magic and algorithm
  // version numbers.  This version indicates the method used for
  // storing compressed records of a database.  This is a different
  // version number than PCompVersion which indicates how data is
  // compressed at a low level.
  //
# define AppMagic	0x6ed9
  UShort appMagic;
# define AppVersion	0
  UShort appVersion;

  //
  // These fields indicate optional structure members which may
  // be associated with this database, like AppInfo or SortInfo
  // blocks which need to be uncompressed.
  //
  UShort hasAppInfo : 1;
  UShort hasSortInfo : 1;

  //
  // These remaining fields are the information as returned by
  // DmDatabaseInfo().
  //
  char name[32];
  UInt flags;
  UInt version;
  ULong size;
  ULong crDate;
  ULong modDate;
  ULong bckUpDate;
  ULong modNum;
  ULong type;
  ULong creator;
} DBInfoHdr;

// Record information headers.  These headers occur every N records
// in the compressed database, and store record-specific information.
// N starts at the second record and is variable depending on how
// many records-worth of information headers are written out at a
// time.  The first is for normal database records and the second
// is for resource database records.
//
typedef union {
  struct {
    UInt attr;
    ULong uniqueID;
  } rec;
  struct {
    Int resID;
    ULong resType;
  } res;
} DBRecordHdr;

//
// We need our own record attribute flag for marking when a record
// has no data due to being deleted but not removed.  Since record
// attributes are stored as 8 bits but implemented using 16, we
// steal one of the top 8.  This may be a Bad Thing for future
// releases of PalmOS, but it saves us a deal of grief for the moment.
// The rationale is this:  if they change PalmOS we'll need to redo
// some of this stuff anyway, so don't worry about it.
//
// NOTE: these bits can't actually get stored into the Palm device --
// they just get placed into the appropriate DBRecordHdr's of the
// compressed file.
//
#define dmRecAttrNoData		0x4000
