~ubuntu-branches/ubuntu/karmic/mdbtools/karmic

« back to all changes in this revision

Viewing changes to src/libmdb/kkd.c

  • Committer: Bazaar Package Importer
  • Author(s): Filip Van Raemdonck
  • Date: 2004-02-18 19:05:35 UTC
  • Revision ID: james.westby@ubuntu.com-20040218190535-605n6otjeg9xa8za
Tags: upstream-0.5.99
ImportĀ upstreamĀ versionĀ 0.5.99

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* MDB Tools - A library for reading MS Access database file
 
2
 * Copyright (C) 2000 Brian Bruns
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "mdbtools.h"
 
21
 
 
22
#ifdef DMALLOC
 
23
#include "dmalloc.h"
 
24
#endif
 
25
 
 
26
 
 
27
/*
 
28
** Note: This code is mostly garbage right now...just a test to parse out the
 
29
**       KKD structures.
 
30
*/
 
31
 
 
32
GArray *mdb_get_column_props(MdbCatalogEntry *entry, int start)
 
33
{
 
34
int pos, cnt=0;
 
35
int len, tmp, cplen;
 
36
MdbColumnProp prop;
 
37
MdbHandle *mdb = entry->mdb;
 
38
 
 
39
        entry->props = g_array_new(FALSE,FALSE,sizeof(MdbColumnProp));
 
40
        len = mdb_pg_get_int16(mdb,start);
 
41
        pos = start + 6;
 
42
        while (pos < start+len) {
 
43
                tmp = mdb_pg_get_int16(mdb,pos); /* length of string */
 
44
                pos += 2;
 
45
                cplen = tmp > MDB_MAX_OBJ_NAME ? MDB_MAX_OBJ_NAME : tmp;
 
46
                g_memmove(prop.name,&mdb->pg_buf[pos],cplen);
 
47
                prop.name[cplen]='\0';
 
48
                pos += tmp; 
 
49
                g_array_append_val(entry->props, prop.name);
 
50
                cnt++;
 
51
        }
 
52
        entry->num_props = cnt;
 
53
        return entry->props;
 
54
}
 
55
 
 
56
GHashTable *mdb_get_column_def(MdbCatalogEntry *entry, int start)
 
57
{
 
58
GHashTable *hash;
 
59
MdbHandle *mdb = entry->mdb;
 
60
MdbColumnProp prop;
 
61
int tmp, pos, col_num, val_len, i;
 
62
int len, col_type;
 
63
unsigned char c;
 
64
int end;
 
65
 
 
66
        fprintf(stdout,"\n data\n");
 
67
        fprintf(stdout,"-------\n");
 
68
        len = mdb_pg_get_int16(mdb,start);
 
69
        fprintf(stdout,"length = %3d\n",len);
 
70
        pos = start + 6;
 
71
        end = start + len;
 
72
        while (pos < end) {
 
73
                fprintf(stdout,"pos = %3d\n",pos);
 
74
                start = pos;
 
75
                tmp = mdb_pg_get_int16(mdb,pos); /* length of field */
 
76
                pos += 2;
 
77
                col_type = mdb_pg_get_int16(mdb,pos); /* ??? */
 
78
                pos += 2;
 
79
                col_num = 0;
 
80
                if (col_type) {
 
81
                        col_num = mdb_pg_get_int16(mdb,pos); 
 
82
                        pos += 2;
 
83
                }
 
84
                val_len = mdb_pg_get_int16(mdb,pos);
 
85
                pos += 2;
 
86
                fprintf(stdout,"length = %3d %04x %2d %2d ",tmp, col_type, col_num, val_len);
 
87
                for (i=0;i<val_len;i++) {
 
88
                        c = mdb->pg_buf[pos+i];
 
89
                        if (isprint(c))
 
90
                                fprintf(stdout,"  %c",c);
 
91
                        else 
 
92
                                fprintf(stdout," %02x",c);
 
93
 
 
94
                }
 
95
                pos = start + tmp; 
 
96
                prop = g_array_index(entry->props,MdbColumnProp,col_num);
 
97
                fprintf(stdout," Property %s",prop.name); 
 
98
                fprintf(stdout,"\n");
 
99
        }
 
100
        return hash;
 
101
}
 
102
void mdb_kkd_dump(MdbCatalogEntry *entry)
 
103
{
 
104
int rows;
 
105
int kkd_start, kkd_end;
 
106
int i, tmp, pos, row_type, datapos=0;
 
107
MdbColumnProp prop;
 
108
MdbHandle *mdb = entry->mdb;
 
109
int rowid = entry->kkd_rowid;
 
110
 
 
111
 
 
112
        mdb_read_pg(mdb, entry->kkd_pg);
 
113
        rows = mdb_pg_get_int16(mdb,8);
 
114
        fprintf(stdout,"number of rows = %d\n",rows);
 
115
        kkd_start = mdb_pg_get_int16(mdb,10+rowid*2);
 
116
        fprintf(stdout,"kkd start = %d %04x\n",kkd_start,kkd_start);
 
117
        kkd_end = mdb->fmt->pg_size;
 
118
        for (i=0;i<rows;i++) {
 
119
                tmp = mdb_pg_get_int16(mdb, 10+i*2);
 
120
                if (tmp < mdb->fmt->pg_size &&
 
121
                    tmp > kkd_start &&
 
122
                    tmp < kkd_end) {
 
123
                        kkd_end = tmp;
 
124
                }
 
125
        }
 
126
        fprintf(stdout,"kkd end = %d %04x\n",kkd_end,kkd_end);
 
127
        pos = kkd_start + 4; /* 4 = K K D \0 */
 
128
        while (pos < kkd_end) {
 
129
                tmp = mdb_pg_get_int16(mdb,pos);
 
130
                row_type = mdb_pg_get_int16(mdb,pos+4);
 
131
                fprintf(stdout,"row size = %3d type = 0x%02x\n",tmp,row_type);
 
132
                if (row_type==0x80)  {
 
133
                        fprintf(stdout,"\nColumn Properties\n");
 
134
                        fprintf(stdout,"-----------------\n");
 
135
                        mdb_get_column_props(entry,pos);
 
136
                        for (i=0;i<entry->num_props;i++) {
 
137
                                prop = g_array_index(entry->props,MdbColumnProp,i);
 
138
                                fprintf(stdout,"%3d %s\n",i,prop.name); 
 
139
                        }
 
140
                }
 
141
                if (row_type==0x01) datapos = pos;
 
142
                pos += tmp;
 
143
        }
 
144
        
 
145
        if (datapos) {
 
146
                mdb_get_column_def(entry, datapos);
 
147
        }
 
148
}
 
149