Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: third_party/sqlite/src/tool/showdb.c

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** A utility for printing all or part of an SQLite database file. 2 ** A utility for printing all or part of an SQLite database file.
3 */ 3 */
4 #include <stdio.h> 4 #include <stdio.h>
5 #include <ctype.h> 5 #include <ctype.h>
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9
10 #if !defined(_MSC_VER)
9 #include <unistd.h> 11 #include <unistd.h>
12 #else
13 #include <io.h>
14 #endif
15
10 #include <stdlib.h> 16 #include <stdlib.h>
11 #include <string.h> 17 #include <string.h>
18 #include "sqlite3.h"
12 19
13 20
14 static int pagesize = 1024; /* Size of a database page */ 21 static int pagesize = 1024; /* Size of a database page */
15 static int db = -1; /* File descriptor for reading the DB */ 22 static int db = -1; /* File descriptor for reading the DB */
16 static int mxPage = 0; /* Last page number */ 23 static int mxPage = 0; /* Last page number */
17 static int perLine = 16; /* HEX elements to print per line */ 24 static int perLine = 16; /* HEX elements to print per line */
18 25
19 typedef long long int i64; /* Datatype for 64-bit integers */ 26 typedef long long int i64; /* Datatype for 64-bit integers */
20 27
21 28
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ** 61 **
55 ** Space to hold the content is obtained from malloc() and needs to be 62 ** Space to hold the content is obtained from malloc() and needs to be
56 ** freed by the caller. 63 ** freed by the caller.
57 */ 64 */
58 static unsigned char *getContent(int ofst, int nByte){ 65 static unsigned char *getContent(int ofst, int nByte){
59 unsigned char *aData; 66 unsigned char *aData;
60 aData = malloc(nByte+32); 67 aData = malloc(nByte+32);
61 if( aData==0 ) out_of_memory(); 68 if( aData==0 ) out_of_memory();
62 memset(aData, 0, nByte+32); 69 memset(aData, 0, nByte+32);
63 lseek(db, ofst, SEEK_SET); 70 lseek(db, ofst, SEEK_SET);
64 read(db, aData, nByte); 71 if( read(db, aData, nByte)<nByte ) memset(aData, 0, nByte);
65 return aData; 72 return aData;
66 } 73 }
67 74
68 /* 75 /*
69 ** Print a range of bytes as hex and as ascii. 76 ** Print a range of bytes as hex and as ascii.
70 */ 77 */
71 static unsigned char *print_byte_range( 78 static unsigned char *print_byte_range(
72 int ofst, /* First byte in the range of bytes to print */ 79 int ofst, /* First byte in the range of bytes to print */
73 int nByte, /* Number of bytes to print */ 80 int nByte, /* Number of bytes to print */
74 int printOfst /* Add this amount to the index on the left column */ 81 int printOfst /* Add this amount to the index on the left column */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 114 }
108 } 115 }
109 fprintf(stdout,"\n"); 116 fprintf(stdout,"\n");
110 } 117 }
111 return aData; 118 return aData;
112 } 119 }
113 120
114 /* 121 /*
115 ** Print an entire page of content as hex 122 ** Print an entire page of content as hex
116 */ 123 */
117 static print_page(int iPg){ 124 static void print_page(int iPg){
118 int iStart; 125 int iStart;
119 unsigned char *aData; 126 unsigned char *aData;
120 iStart = (iPg-1)*pagesize; 127 iStart = (iPg-1)*pagesize;
121 fprintf(stdout, "Page %d: (offsets 0x%x..0x%x)\n", 128 fprintf(stdout, "Page %d: (offsets 0x%x..0x%x)\n",
122 iPg, iStart, iStart+pagesize-1); 129 iPg, iStart, iStart+pagesize-1);
123 aData = print_byte_range(iStart, pagesize, 0); 130 aData = print_byte_range(iStart, pagesize, 0);
124 free(aData); 131 free(aData);
125 } 132 }
126 133
134
127 /* Print a line of decode output showing a 4-byte integer. 135 /* Print a line of decode output showing a 4-byte integer.
128 */ 136 */
129 static print_decode_line( 137 static void print_decode_line(
130 unsigned char *aData, /* Content being decoded */ 138 unsigned char *aData, /* Content being decoded */
131 int ofst, int nByte, /* Start and size of decode */ 139 int ofst, int nByte, /* Start and size of decode */
132 const char *zMsg /* Message to append */ 140 const char *zMsg /* Message to append */
133 ){ 141 ){
134 int i, j; 142 int i, j;
135 int val = aData[ofst]; 143 int val = aData[ofst];
136 char zBuf[100]; 144 char zBuf[100];
137 sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]); 145 sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]);
138 i = strlen(zBuf); 146 i = (int)strlen(zBuf);
139 for(j=1; j<4; j++){ 147 for(j=1; j<4; j++){
140 if( j>=nByte ){ 148 if( j>=nByte ){
141 sprintf(&zBuf[i], " "); 149 sprintf(&zBuf[i], " ");
142 }else{ 150 }else{
143 sprintf(&zBuf[i], " %02x", aData[ofst+j]); 151 sprintf(&zBuf[i], " %02x", aData[ofst+j]);
144 val = val*256 + aData[ofst+j]; 152 val = val*256 + aData[ofst+j];
145 } 153 }
146 i += strlen(&zBuf[i]); 154 i += (int)strlen(&zBuf[i]);
147 } 155 }
148 sprintf(&zBuf[i], " %9d", val); 156 sprintf(&zBuf[i], " %9d", val);
149 printf("%s %s\n", zBuf, zMsg); 157 printf("%s %s\n", zBuf, zMsg);
150 } 158 }
151 159
152 /* 160 /*
153 ** Decode the database header. 161 ** Decode the database header.
154 */ 162 */
155 static void print_db_header(void){ 163 static void print_db_header(void){
156 unsigned char *aData; 164 unsigned char *aData;
157 aData = print_byte_range(0, 100, 0); 165 aData = print_byte_range(0, 100, 0);
158 printf("Decoded:\n"); 166 printf("Decoded:\n");
159 print_decode_line(aData, 16, 2, "Database page size"); 167 print_decode_line(aData, 16, 2, "Database page size");
160 print_decode_line(aData, 18, 1, "File format write version"); 168 print_decode_line(aData, 18, 1, "File format write version");
161 print_decode_line(aData, 19, 1, "File format read version"); 169 print_decode_line(aData, 19, 1, "File format read version");
162 print_decode_line(aData, 20, 1, "Reserved space at end of page"); 170 print_decode_line(aData, 20, 1, "Reserved space at end of page");
163 print_decode_line(aData, 24, 4, "File change counter"); 171 print_decode_line(aData, 24, 4, "File change counter");
164 print_decode_line(aData, 28, 4, "Size of database in pages"); 172 print_decode_line(aData, 28, 4, "Size of database in pages");
165 print_decode_line(aData, 32, 4, "Page number of first freelist page"); 173 print_decode_line(aData, 32, 4, "Page number of first freelist page");
166 print_decode_line(aData, 36, 4, "Number of freelist pages"); 174 print_decode_line(aData, 36, 4, "Number of freelist pages");
167 print_decode_line(aData, 40, 4, "Schema cookie"); 175 print_decode_line(aData, 40, 4, "Schema cookie");
168 print_decode_line(aData, 44, 4, "Schema format version"); 176 print_decode_line(aData, 44, 4, "Schema format version");
169 print_decode_line(aData, 48, 4, "Default page cache size"); 177 print_decode_line(aData, 48, 4, "Default page cache size");
170 print_decode_line(aData, 52, 4, "Largest auto-vac root page"); 178 print_decode_line(aData, 52, 4, "Largest auto-vac root page");
171 print_decode_line(aData, 56, 4, "Text encoding"); 179 print_decode_line(aData, 56, 4, "Text encoding");
172 print_decode_line(aData, 60, 4, "User version"); 180 print_decode_line(aData, 60, 4, "User version");
173 print_decode_line(aData, 64, 4, "Incremental-vacuum mode"); 181 print_decode_line(aData, 64, 4, "Incremental-vacuum mode");
174 print_decode_line(aData, 68, 4, "meta[7]"); 182 print_decode_line(aData, 68, 4, "Application ID");
175 print_decode_line(aData, 72, 4, "meta[8]"); 183 print_decode_line(aData, 72, 4, "meta[8]");
176 print_decode_line(aData, 76, 4, "meta[9]"); 184 print_decode_line(aData, 76, 4, "meta[9]");
177 print_decode_line(aData, 80, 4, "meta[10]"); 185 print_decode_line(aData, 80, 4, "meta[10]");
178 print_decode_line(aData, 84, 4, "meta[11]"); 186 print_decode_line(aData, 84, 4, "meta[11]");
179 print_decode_line(aData, 88, 4, "meta[12]"); 187 print_decode_line(aData, 88, 4, "meta[12]");
180 print_decode_line(aData, 92, 4, "Change counter for version number"); 188 print_decode_line(aData, 92, 4, "Change counter for version number");
181 print_decode_line(aData, 96, 4, "SQLite version number"); 189 print_decode_line(aData, 96, 4, "SQLite version number");
182 } 190 }
183 191
184 /* 192 /*
185 ** Describe cell content. 193 ** Describe cell content.
186 */ 194 */
187 static int describeContent( 195 static i64 describeContent(
188 unsigned char *a, /* Cell content */ 196 unsigned char *a, /* Cell content */
189 int nLocal, /* Bytes in a[] */ 197 i64 nLocal, /* Bytes in a[] */
190 char *zDesc /* Write description here */ 198 char *zDesc /* Write description here */
191 ){ 199 ){
192 int nDesc = 0; 200 i64 nDesc = 0;
193 int n, i, j; 201 int n, j;
194 i64 x, v; 202 i64 i, x, v;
195 const unsigned char *pData; 203 const unsigned char *pData;
196 const unsigned char *pLimit; 204 const unsigned char *pLimit;
197 char sep = ' '; 205 char sep = ' ';
198 206
199 pLimit = &a[nLocal]; 207 pLimit = &a[nLocal];
200 n = decodeVarint(a, &x); 208 n = decodeVarint(a, &x);
201 pData = &a[x]; 209 pData = &a[x];
202 a += n; 210 a += n;
203 i = x - n; 211 i = x - n;
204 while( i>0 && pData<=pLimit ){ 212 while( i>0 && pData<=pLimit ){
(...skipping 19 matching lines...) Expand all
224 } 232 }
225 sprintf(zDesc, "%lld", v); 233 sprintf(zDesc, "%lld", v);
226 }else if( x==7 ){ 234 }else if( x==7 ){
227 sprintf(zDesc, "real"); 235 sprintf(zDesc, "real");
228 pData += 8; 236 pData += 8;
229 }else if( x==8 ){ 237 }else if( x==8 ){
230 sprintf(zDesc, "0"); 238 sprintf(zDesc, "0");
231 }else if( x==9 ){ 239 }else if( x==9 ){
232 sprintf(zDesc, "1"); 240 sprintf(zDesc, "1");
233 }else if( x>=12 ){ 241 }else if( x>=12 ){
234 int size = (x-12)/2; 242 i64 size = (x-12)/2;
235 if( (x&1)==0 ){ 243 if( (x&1)==0 ){
236 sprintf(zDesc, "blob(%d)", size); 244 sprintf(zDesc, "blob(%lld)", size);
237 }else{ 245 }else{
238 sprintf(zDesc, "txt(%d)", size); 246 sprintf(zDesc, "txt(%lld)", size);
239 } 247 }
240 pData += size; 248 pData += size;
241 } 249 }
242 j = strlen(zDesc); 250 j = (int)strlen(zDesc);
243 zDesc += j; 251 zDesc += j;
244 nDesc += j; 252 nDesc += j;
245 } 253 }
246 return nDesc; 254 return nDesc;
247 } 255 }
248 256
249 /* 257 /*
250 ** Compute the local payload size given the total payload size and 258 ** Compute the local payload size given the total payload size and
251 ** the page size. 259 ** the page size.
252 */ 260 */
253 static int localPayload(i64 nPayload, char cType){ 261 static i64 localPayload(i64 nPayload, char cType){
254 int maxLocal; 262 i64 maxLocal;
255 int minLocal; 263 i64 minLocal;
256 int surplus; 264 i64 surplus;
257 int nLocal; 265 i64 nLocal;
258 if( cType==13 ){ 266 if( cType==13 ){
259 /* Table leaf */ 267 /* Table leaf */
260 maxLocal = pagesize-35; 268 maxLocal = pagesize-35;
261 minLocal = (pagesize-12)*32/255-23; 269 minLocal = (pagesize-12)*32/255-23;
262 }else{ 270 }else{
263 maxLocal = (pagesize-12)*64/255-23; 271 maxLocal = (pagesize-12)*64/255-23;
264 minLocal = (pagesize-12)*32/255-23; 272 minLocal = (pagesize-12)*32/255-23;
265 } 273 }
266 if( nPayload>maxLocal ){ 274 if( nPayload>maxLocal ){
267 surplus = minLocal + (nPayload-minLocal)%(pagesize-4); 275 surplus = minLocal + (nPayload-minLocal)%(pagesize-4);
268 if( surplus<=maxLocal ){ 276 if( surplus<=maxLocal ){
269 nLocal = surplus; 277 nLocal = surplus;
270 }else{ 278 }else{
271 nLocal = minLocal; 279 nLocal = minLocal;
272 } 280 }
273 }else{ 281 }else{
274 nLocal = nPayload; 282 nLocal = nPayload;
275 } 283 }
276 return nLocal; 284 return nLocal;
277 } 285 }
278 286
279 287
280 /* 288 /*
281 ** Create a description for a single cell. 289 ** Create a description for a single cell.
282 ** 290 **
283 ** The return value is the local cell size. 291 ** The return value is the local cell size.
284 */ 292 */
285 static int describeCell( 293 static i64 describeCell(
286 unsigned char cType, /* Page type */ 294 unsigned char cType, /* Page type */
287 unsigned char *a, /* Cell content */ 295 unsigned char *a, /* Cell content */
288 int showCellContent, /* Show cell content if true */ 296 int showCellContent, /* Show cell content if true */
289 char **pzDesc /* Store description here */ 297 char **pzDesc /* Store description here */
290 ){ 298 ){
291 int i; 299 int i;
292 int nDesc = 0; 300 i64 nDesc = 0;
293 int n = 0; 301 int n = 0;
294 int leftChild; 302 int leftChild;
295 i64 nPayload; 303 i64 nPayload;
296 i64 rowid; 304 i64 rowid;
297 int nLocal; 305 i64 nLocal;
298 static char zDesc[1000]; 306 static char zDesc[1000];
299 i = 0; 307 i = 0;
300 if( cType<=5 ){ 308 if( cType<=5 ){
301 leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3]; 309 leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
302 a += 4; 310 a += 4;
303 n += 4; 311 n += 4;
304 sprintf(zDesc, "lx: %d ", leftChild); 312 sprintf(zDesc, "lx: %d ", leftChild);
305 nDesc = strlen(zDesc); 313 nDesc = strlen(zDesc);
306 } 314 }
307 if( cType!=5 ){ 315 if( cType!=5 ){
(...skipping 21 matching lines...) Expand all
329 nDesc += strlen(&zDesc[nDesc]); 337 nDesc += strlen(&zDesc[nDesc]);
330 n += 4; 338 n += 4;
331 } 339 }
332 if( showCellContent && cType!=5 ){ 340 if( showCellContent && cType!=5 ){
333 nDesc += describeContent(a, nLocal, &zDesc[nDesc-1]); 341 nDesc += describeContent(a, nLocal, &zDesc[nDesc-1]);
334 } 342 }
335 *pzDesc = zDesc; 343 *pzDesc = zDesc;
336 return nLocal+n; 344 return nLocal+n;
337 } 345 }
338 346
347 /* Print an offset followed by nByte bytes. Add extra white-space
348 ** at the end so that subsequent text is aligned.
349 */
350 static void printBytes(
351 unsigned char *aData, /* Content being decoded */
352 unsigned char *aStart, /* Start of content to be printed */
353 int nByte /* Number of bytes to print */
354 ){
355 int j;
356 printf(" %03x: ", (int)(aStart-aData));
357 for(j=0; j<9; j++){
358 if( j>=nByte ){
359 printf(" ");
360 }else{
361 printf("%02x ", aStart[j]);
362 }
363 }
364 }
365
366
367 /*
368 ** Write a full decode on stdout for the cell at a[ofst].
369 ** Assume the page contains a header of size szPgHdr bytes.
370 */
371 static void decodeCell(
372 unsigned char *a, /* Page content (without the page-1 header) */
373 unsigned pgno, /* Page number */
374 int iCell, /* Cell index */
375 int szPgHdr, /* Size of the page header. 0 or 100 */
376 int ofst /* Cell begins at a[ofst] */
377 ){
378 int i, j;
379 int leftChild;
380 i64 k;
381 i64 nPayload;
382 i64 rowid;
383 i64 nHdr;
384 i64 iType;
385 i64 nLocal;
386 unsigned char *x = a + ofst;
387 unsigned char *end;
388 unsigned char cType = a[0];
389 int nCol = 0;
390 int szCol[2000];
391 int ofstCol[2000];
392 int typeCol[2000];
393
394 printf("Cell[%d]:\n", iCell);
395 if( cType<=5 ){
396 leftChild = ((x[0]*256 + x[1])*256 + x[2])*256 + x[3];
397 printBytes(a, x, 4);
398 printf("left child page:: %d\n", leftChild);
399 x += 4;
400 }
401 if( cType!=5 ){
402 i = decodeVarint(x, &nPayload);
403 printBytes(a, x, i);
404 nLocal = localPayload(nPayload, cType);
405 if( nLocal==nPayload ){
406 printf("payload-size: %lld\n", nPayload);
407 }else{
408 printf("payload-size: %lld (%lld local, %lld overflow)\n",
409 nPayload, nLocal, nPayload-nLocal);
410 }
411 x += i;
412 }else{
413 nPayload = nLocal = 0;
414 }
415 end = x + nLocal;
416 if( cType==5 || cType==13 ){
417 i = decodeVarint(x, &rowid);
418 printBytes(a, x, i);
419 printf("rowid: %lld\n", rowid);
420 x += i;
421 }
422 if( nLocal>0 ){
423 i = decodeVarint(x, &nHdr);
424 printBytes(a, x, i);
425 printf("record-header-size: %d\n", (int)nHdr);
426 j = i;
427 nCol = 0;
428 k = nHdr;
429 while( x+j<end && j<nHdr ){
430 const char *zTypeName;
431 int sz = 0;
432 char zNm[30];
433 i = decodeVarint(x+j, &iType);
434 printBytes(a, x+j, i);
435 printf("typecode[%d]: %d - ", nCol, (int)iType);
436 switch( iType ){
437 case 0: zTypeName = "NULL"; sz = 0; break;
438 case 1: zTypeName = "int8"; sz = 1; break;
439 case 2: zTypeName = "int16"; sz = 2; break;
440 case 3: zTypeName = "int24"; sz = 3; break;
441 case 4: zTypeName = "int32"; sz = 4; break;
442 case 5: zTypeName = "int48"; sz = 6; break;
443 case 6: zTypeName = "int64"; sz = 8; break;
444 case 7: zTypeName = "double"; sz = 8; break;
445 case 8: zTypeName = "zero"; sz = 0; break;
446 case 9: zTypeName = "one"; sz = 0; break;
447 case 10:
448 case 11: zTypeName = "error"; sz = 0; break;
449 default: {
450 sz = (int)(iType-12)/2;
451 sprintf(zNm, (iType&1)==0 ? "blob(%d)" : "text(%d)", sz);
452 zTypeName = zNm;
453 break;
454 }
455 }
456 printf("%s\n", zTypeName);
457 szCol[nCol] = sz;
458 ofstCol[nCol] = (int)k;
459 typeCol[nCol] = (int)iType;
460 k += sz;
461 nCol++;
462 j += i;
463 }
464 for(i=0; i<nCol && ofstCol[i]+szCol[i]<=nLocal; i++){
465 int s = ofstCol[i];
466 i64 v;
467 const unsigned char *pData;
468 if( szCol[i]==0 ) continue;
469 printBytes(a, x+s, szCol[i]);
470 printf("data[%d]: ", i);
471 pData = x+s;
472 if( typeCol[i]<=7 ){
473 v = (signed char)pData[0];
474 for(k=1; k<szCol[i]; k++){
475 v = (v<<8) + pData[k];
476 }
477 if( typeCol[i]==7 ){
478 double r;
479 memcpy(&r, &v, sizeof(r));
480 printf("%#g\n", r);
481 }else{
482 printf("%lld\n", v);
483 }
484 }else{
485 int ii, jj;
486 char zConst[32];
487 if( (typeCol[i]&1)==0 ){
488 zConst[0] = 'x';
489 zConst[1] = '\'';
490 for(ii=2, jj=0; jj<szCol[i] && ii<24; jj++, ii+=2){
491 sprintf(zConst+ii, "%02x", pData[jj]);
492 }
493 }else{
494 zConst[0] = '\'';
495 for(ii=1, jj=0; jj<szCol[i] && ii<24; jj++, ii++){
496 zConst[ii] = isprint(pData[jj]) ? pData[jj] : '.';
497 }
498 zConst[ii] = 0;
499 }
500 if( jj<szCol[i] ){
501 memcpy(zConst+ii, "...'", 5);
502 }else{
503 memcpy(zConst+ii, "'", 2);
504 }
505 printf("%s\n", zConst);
506 }
507 j = ofstCol[i] + szCol[i];
508 }
509 }
510 if( j<nLocal ){
511 printBytes(a, x+j, 0);
512 printf("... %lld bytes of content ...\n", nLocal-j);
513 }
514 if( nLocal<nPayload ){
515 printBytes(a, x+nLocal, 4);
516 printf("overflow-page: %d\n", decodeInt32(x+nLocal));
517 }
518 }
519
520
339 /* 521 /*
340 ** Decode a btree page 522 ** Decode a btree page
341 */ 523 */
342 static void decode_btree_page( 524 static void decode_btree_page(
343 unsigned char *a, /* Page content */ 525 unsigned char *a, /* Page content */
344 int pgno, /* Page number */ 526 int pgno, /* Page number */
345 int hdrSize, /* Size of the page header. 0 or 100 */ 527 int hdrSize, /* Size of the page header. 0 or 100 */
346 char *zArgs /* Flags to control formatting */ 528 char *zArgs /* Flags to control formatting */
347 ){ 529 ){
348 const char *zType = "unknown"; 530 const char *zType = "unknown";
349 int nCell; 531 int nCell;
350 int i, j; 532 int i, j;
351 int iCellPtr; 533 int iCellPtr;
352 int showCellContent = 0; 534 int showCellContent = 0;
353 int showMap = 0; 535 int showMap = 0;
536 int cellToDecode = -2;
354 char *zMap = 0; 537 char *zMap = 0;
355 switch( a[0] ){ 538 switch( a[0] ){
356 case 2: zType = "index interior node"; break; 539 case 2: zType = "index interior node"; break;
357 case 5: zType = "table interior node"; break; 540 case 5: zType = "table interior node"; break;
358 case 10: zType = "index leaf"; break; 541 case 10: zType = "index leaf"; break;
359 case 13: zType = "table leaf"; break; 542 case 13: zType = "table leaf"; break;
360 } 543 }
361 while( zArgs[0] ){ 544 while( zArgs[0] ){
362 switch( zArgs[0] ){ 545 switch( zArgs[0] ){
363 case 'c': showCellContent = 1; break; 546 case 'c': showCellContent = 1; break;
364 case 'm': showMap = 1; break; 547 case 'm': showMap = 1; break;
548 case 'd': {
549 if( !isdigit(zArgs[1]) ){
550 cellToDecode = -1;
551 }else{
552 cellToDecode = 0;
553 while( isdigit(zArgs[1]) ){
554 zArgs++;
555 cellToDecode = cellToDecode*10 + zArgs[0] - '0';
556 }
557 }
558 break;
559 }
365 } 560 }
366 zArgs++; 561 zArgs++;
367 } 562 }
368 printf("Decode of btree page %d:\n", pgno); 563 nCell = a[3]*256 + a[4];
564 iCellPtr = (a[0]==2 || a[0]==5) ? 12 : 8;
565 if( cellToDecode>=nCell ){
566 printf("Page %d has only %d cells\n", pgno, nCell);
567 return;
568 }
569 printf("Header on btree page %d:\n", pgno);
369 print_decode_line(a, 0, 1, zType); 570 print_decode_line(a, 0, 1, zType);
370 print_decode_line(a, 1, 2, "Offset to first freeblock"); 571 print_decode_line(a, 1, 2, "Offset to first freeblock");
371 print_decode_line(a, 3, 2, "Number of cells on this page"); 572 print_decode_line(a, 3, 2, "Number of cells on this page");
372 nCell = a[3]*256 + a[4];
373 print_decode_line(a, 5, 2, "Offset to cell content area"); 573 print_decode_line(a, 5, 2, "Offset to cell content area");
374 print_decode_line(a, 7, 1, "Fragmented byte count"); 574 print_decode_line(a, 7, 1, "Fragmented byte count");
375 if( a[0]==2 || a[0]==5 ){ 575 if( a[0]==2 || a[0]==5 ){
376 print_decode_line(a, 8, 4, "Right child"); 576 print_decode_line(a, 8, 4, "Right child");
377 iCellPtr = 12;
378 }else{
379 iCellPtr = 8;
380 } 577 }
381 if( nCell>0 ){ 578 if( cellToDecode==(-2) && nCell>0 ){
382 printf(" key: lx=left-child n=payload-size r=rowid\n"); 579 printf(" key: lx=left-child n=payload-size r=rowid\n");
383 } 580 }
384 if( showMap ){ 581 if( showMap ){
385 zMap = malloc(pagesize); 582 zMap = malloc(pagesize);
386 memset(zMap, '.', pagesize); 583 memset(zMap, '.', pagesize);
387 memset(zMap, '1', hdrSize); 584 memset(zMap, '1', hdrSize);
388 memset(&zMap[hdrSize], 'H', iCellPtr); 585 memset(&zMap[hdrSize], 'H', iCellPtr);
389 memset(&zMap[hdrSize+iCellPtr], 'P', 2*nCell); 586 memset(&zMap[hdrSize+iCellPtr], 'P', 2*nCell);
390 } 587 }
391 for(i=0; i<nCell; i++){ 588 for(i=0; i<nCell; i++){
392 int cofst = iCellPtr + i*2; 589 int cofst = iCellPtr + i*2;
393 char *zDesc; 590 char *zDesc;
394 int n; 591 i64 n;
395 592
396 cofst = a[cofst]*256 + a[cofst+1]; 593 cofst = a[cofst]*256 + a[cofst+1];
397 n = describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc); 594 n = describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc);
398 if( showMap ){ 595 if( showMap ){
399 char zBuf[30]; 596 char zBuf[30];
400 memset(&zMap[cofst], '*', n); 597 memset(&zMap[cofst], '*', (size_t)n);
401 zMap[cofst] = '['; 598 zMap[cofst] = '[';
402 zMap[cofst+n-1] = ']'; 599 zMap[cofst+n-1] = ']';
403 sprintf(zBuf, "%d", i); 600 sprintf(zBuf, "%d", i);
404 j = strlen(zBuf); 601 j = (int)strlen(zBuf);
405 if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j); 602 if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j);
406 } 603 }
407 printf(" %03x: cell[%d] %s\n", cofst, i, zDesc); 604 if( cellToDecode==(-2) ){
605 printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);
606 }else if( cellToDecode==(-1) || cellToDecode==i ){
607 decodeCell(a, pgno, i, hdrSize, cofst-hdrSize);
608 }
408 } 609 }
409 if( showMap ){ 610 if( showMap ){
611 printf("Page map: (H=header P=cell-index 1=page-1-header .=free-space)\n");
410 for(i=0; i<pagesize; i+=64){ 612 for(i=0; i<pagesize; i+=64){
411 printf(" %03x: %.64s\n", i, &zMap[i]); 613 printf(" %03x: %.64s\n", i, &zMap[i]);
412 } 614 }
413 free(zMap); 615 free(zMap);
414 } 616 }
415 } 617 }
416 618
417 /* 619 /*
418 ** Decode a freelist trunk page. 620 ** Decode a freelist trunk page.
419 */ 621 */
420 static void decode_trunk_page( 622 static void decode_trunk_page(
421 int pgno, /* The page number */ 623 int pgno, /* The page number */
422 int pagesize, /* Size of each page */ 624 int pagesize, /* Size of each page */
423 int detail, /* Show leaf pages if true */ 625 int detail, /* Show leaf pages if true */
424 int recursive /* Follow the trunk change if true */ 626 int recursive /* Follow the trunk change if true */
425 ){ 627 ){
426 int n, i, k; 628 int n, i;
427 unsigned char *a; 629 unsigned char *a;
428 while( pgno>0 ){ 630 while( pgno>0 ){
429 a = getContent((pgno-1)*pagesize, pagesize); 631 a = getContent((pgno-1)*pagesize, pagesize);
430 printf("Decode of freelist trunk page %d:\n", pgno); 632 printf("Decode of freelist trunk page %d:\n", pgno);
431 print_decode_line(a, 0, 4, "Next freelist trunk page"); 633 print_decode_line(a, 0, 4, "Next freelist trunk page");
432 print_decode_line(a, 4, 4, "Number of entries on this page"); 634 print_decode_line(a, 4, 4, "Number of entries on this page");
433 if( detail ){ 635 if( detail ){
434 n = (int)decodeInt32(&a[4]); 636 n = (int)decodeInt32(&a[4]);
435 for(i=0; i<n; i++){ 637 for(i=0; i<n; i++){
436 unsigned int x = decodeInt32(&a[8+4*i]); 638 unsigned int x = decodeInt32(&a[8+4*i]);
437 char zIdx[10]; 639 char zIdx[10];
438 sprintf(zIdx, "[%d]", i); 640 sprintf(zIdx, "[%d]", i);
439 printf(" %5s %7u", zIdx, x); 641 printf(" %5s %7u", zIdx, x);
440 if( i%5==4 ) printf("\n"); 642 if( i%5==4 ) printf("\n");
441 } 643 }
442 if( i%5!=0 ) printf("\n"); 644 if( i%5!=0 ) printf("\n");
443 } 645 }
444 if( !recursive ){ 646 if( !recursive ){
445 pgno = 0; 647 pgno = 0;
446 }else{ 648 }else{
447 pgno = (int)decodeInt32(&a[0]); 649 pgno = (int)decodeInt32(&a[0]);
448 } 650 }
449 free(a); 651 free(a);
450 } 652 }
451 } 653 }
452 654
453 /* 655 /*
656 ** A short text comment on the use of each page.
657 */
658 static char **zPageUse;
659
660 /*
661 ** Add a comment on the use of a page.
662 */
663 static void page_usage_msg(int pgno, const char *zFormat, ...){
664 va_list ap;
665 char *zMsg;
666
667 va_start(ap, zFormat);
668 zMsg = sqlite3_vmprintf(zFormat, ap);
669 va_end(ap);
670 if( pgno<=0 || pgno>mxPage ){
671 printf("ERROR: page %d out of range 1..%d: %s\n",
672 pgno, mxPage, zMsg);
673 sqlite3_free(zMsg);
674 return;
675 }
676 if( zPageUse[pgno]!=0 ){
677 printf("ERROR: page %d used multiple times:\n", pgno);
678 printf("ERROR: previous: %s\n", zPageUse[pgno]);
679 printf("ERROR: current: %s\n", zMsg);
680 sqlite3_free(zPageUse[pgno]);
681 }
682 zPageUse[pgno] = zMsg;
683 }
684
685 /*
686 ** Find overflow pages of a cell and describe their usage.
687 */
688 static void page_usage_cell(
689 unsigned char cType, /* Page type */
690 unsigned char *a, /* Cell content */
691 int pgno, /* page containing the cell */
692 int cellno /* Index of the cell on the page */
693 ){
694 int i;
695 int n = 0;
696 i64 nPayload;
697 i64 rowid;
698 i64 nLocal;
699 i = 0;
700 if( cType<=5 ){
701 a += 4;
702 n += 4;
703 }
704 if( cType!=5 ){
705 i = decodeVarint(a, &nPayload);
706 a += i;
707 n += i;
708 nLocal = localPayload(nPayload, cType);
709 }else{
710 nPayload = nLocal = 0;
711 }
712 if( cType==5 || cType==13 ){
713 i = decodeVarint(a, &rowid);
714 a += i;
715 n += i;
716 }
717 if( nLocal<nPayload ){
718 int ovfl = decodeInt32(a+nLocal);
719 int cnt = 0;
720 while( ovfl && (cnt++)<mxPage ){
721 page_usage_msg(ovfl, "overflow %d from cell %d of page %d",
722 cnt, cellno, pgno);
723 a = getContent((ovfl-1)*pagesize, 4);
724 ovfl = decodeInt32(a);
725 free(a);
726 }
727 }
728 }
729
730
731 /*
732 ** Describe the usages of a b-tree page
733 */
734 static void page_usage_btree(
735 int pgno, /* Page to describe */
736 int parent, /* Parent of this page. 0 for root pages */
737 int idx, /* Which child of the parent */
738 const char *zName /* Name of the table */
739 ){
740 unsigned char *a;
741 const char *zType = "corrupt node";
742 int nCell;
743 int i;
744 int hdr = pgno==1 ? 100 : 0;
745
746 if( pgno<=0 || pgno>mxPage ) return;
747 a = getContent((pgno-1)*pagesize, pagesize);
748 switch( a[hdr] ){
749 case 2: zType = "interior node of index"; break;
750 case 5: zType = "interior node of table"; break;
751 case 10: zType = "leaf of index"; break;
752 case 13: zType = "leaf of table"; break;
753 }
754 if( parent ){
755 page_usage_msg(pgno, "%s [%s], child %d of page %d",
756 zType, zName, idx, parent);
757 }else{
758 page_usage_msg(pgno, "root %s [%s]", zType, zName);
759 }
760 nCell = a[hdr+3]*256 + a[hdr+4];
761 if( a[hdr]==2 || a[hdr]==5 ){
762 int cellstart = hdr+12;
763 unsigned int child;
764 for(i=0; i<nCell; i++){
765 int ofst;
766
767 ofst = cellstart + i*2;
768 ofst = a[ofst]*256 + a[ofst+1];
769 child = decodeInt32(a+ofst);
770 page_usage_btree(child, pgno, i, zName);
771 }
772 child = decodeInt32(a+cellstart-4);
773 page_usage_btree(child, pgno, i, zName);
774 }
775 if( a[hdr]==2 || a[hdr]==10 || a[hdr]==13 ){
776 int cellstart = hdr + 8 + 4*(a[hdr]<=5);
777 for(i=0; i<nCell; i++){
778 int ofst;
779 ofst = cellstart + i*2;
780 ofst = a[ofst]*256 + a[ofst+1];
781 page_usage_cell(a[hdr], a+ofst, pgno, i);
782 }
783 }
784 free(a);
785 }
786
787 /*
788 ** Determine page usage by the freelist
789 */
790 static void page_usage_freelist(int pgno){
791 unsigned char *a;
792 int cnt = 0;
793 int i;
794 int n;
795 int iNext;
796 int parent = 1;
797
798 while( pgno>0 && pgno<=mxPage && (cnt++)<mxPage ){
799 page_usage_msg(pgno, "freelist trunk #%d child of %d", cnt, parent);
800 a = getContent((pgno-1)*pagesize, pagesize);
801 iNext = decodeInt32(a);
802 n = decodeInt32(a+4);
803 for(i=0; i<n; i++){
804 int child = decodeInt32(a + (i*4+8));
805 page_usage_msg(child, "freelist leaf, child %d of trunk page %d",
806 i, pgno);
807 }
808 free(a);
809 parent = pgno;
810 pgno = iNext;
811 }
812 }
813
814 /*
815 ** Determine pages used as PTRMAP pages
816 */
817 static void page_usage_ptrmap(unsigned char *a){
818 if( a[55] ){
819 int usable = pagesize - a[20];
820 int pgno = 2;
821 int perPage = usable/5;
822 while( pgno<=mxPage ){
823 page_usage_msg(pgno, "PTRMAP page covering %d..%d",
824 pgno+1, pgno+perPage);
825 pgno += perPage + 1;
826 }
827 }
828 }
829
830 /*
831 ** Try to figure out how every page in the database file is being used.
832 */
833 static void page_usage_report(const char *zDbName){
834 int i, j;
835 int rc;
836 sqlite3 *db;
837 sqlite3_stmt *pStmt;
838 unsigned char *a;
839 char zQuery[200];
840
841 /* Avoid the pathological case */
842 if( mxPage<1 ){
843 printf("empty database\n");
844 return;
845 }
846
847 /* Open the database file */
848 rc = sqlite3_open(zDbName, &db);
849 if( rc ){
850 printf("cannot open database: %s\n", sqlite3_errmsg(db));
851 sqlite3_close(db);
852 return;
853 }
854
855 /* Set up global variables zPageUse[] and mxPage to record page
856 ** usages */
857 zPageUse = sqlite3_malloc( sizeof(zPageUse[0])*(mxPage+1) );
858 if( zPageUse==0 ) out_of_memory();
859 memset(zPageUse, 0, sizeof(zPageUse[0])*(mxPage+1));
860
861 /* Discover the usage of each page */
862 a = getContent(0, 100);
863 page_usage_freelist(decodeInt32(a+32));
864 page_usage_ptrmap(a);
865 free(a);
866 page_usage_btree(1, 0, 0, "sqlite_master");
867 sqlite3_exec(db, "PRAGMA writable_schema=ON", 0, 0, 0);
868 for(j=0; j<2; j++){
869 sqlite3_snprintf(sizeof(zQuery), zQuery,
870 "SELECT type, name, rootpage FROM SQLITE_MASTER WHERE rootpage"
871 " ORDER BY rowid %s", j?"DESC":"");
872 rc = sqlite3_prepare_v2(db, zQuery, -1, &pStmt, 0);
873 if( rc==SQLITE_OK ){
874 while( sqlite3_step(pStmt)==SQLITE_ROW ){
875 int pgno = sqlite3_column_int(pStmt, 2);
876 page_usage_btree(pgno, 0, 0, (const char*)sqlite3_column_text(pStmt,1));
877 }
878 }else{
879 printf("ERROR: cannot query database: %s\n", sqlite3_errmsg(db));
880 }
881 rc = sqlite3_finalize(pStmt);
882 if( rc==SQLITE_OK ) break;
883 }
884 sqlite3_close(db);
885
886 /* Print the report and free memory used */
887 for(i=1; i<=mxPage; i++){
888 printf("%5d: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
889 sqlite3_free(zPageUse[i]);
890 }
891 sqlite3_free(zPageUse);
892 zPageUse = 0;
893 }
894
895 /*
896 ** Try to figure out how every page in the database file is being used.
897 */
898 static void ptrmap_coverage_report(const char *zDbName){
899 int pgno;
900 unsigned char *aHdr;
901 unsigned char *a;
902 int usable;
903 int perPage;
904 int i;
905
906 /* Avoid the pathological case */
907 if( mxPage<1 ){
908 printf("empty database\n");
909 return;
910 }
911
912 /* Make sure PTRMAPs are used in this database */
913 aHdr = getContent(0, 100);
914 if( aHdr[55]==0 ){
915 printf("database does not use PTRMAP pages\n");
916 return;
917 }
918 usable = pagesize - aHdr[20];
919 perPage = usable/5;
920 free(aHdr);
921 printf("%5d: root of sqlite_master\n", 1);
922 for(pgno=2; pgno<=mxPage; pgno += perPage+1){
923 printf("%5d: PTRMAP page covering %d..%d\n", pgno,
924 pgno+1, pgno+perPage);
925 a = getContent((pgno-1)*pagesize, usable);
926 for(i=0; i+5<=usable && pgno+1+i/5<=mxPage; i+=5){
927 const char *zType = "???";
928 unsigned int iFrom = decodeInt32(&a[i+1]);
929 switch( a[i] ){
930 case 1: zType = "b-tree root page"; break;
931 case 2: zType = "freelist page"; break;
932 case 3: zType = "first page of overflow"; break;
933 case 4: zType = "later page of overflow"; break;
934 case 5: zType = "b-tree non-root page"; break;
935 }
936 printf("%5d: %s, parent=%u\n", pgno+1+i/5, zType, iFrom);
937 }
938 free(a);
939 }
940 }
941
942 /*
454 ** Print a usage comment 943 ** Print a usage comment
455 */ 944 */
456 static void usage(const char *argv0){ 945 static void usage(const char *argv0){
457 fprintf(stderr, "Usage %s FILENAME ?args...?\n\n", argv0); 946 fprintf(stderr, "Usage %s FILENAME ?args...?\n\n", argv0);
458 fprintf(stderr, 947 fprintf(stderr,
459 "args:\n" 948 "args:\n"
460 " dbheader Show database header\n" 949 " dbheader Show database header\n"
950 " pgidx Index of how each page is used\n"
951 " ptrmap Show all PTRMAP page content\n"
461 " NNN..MMM Show hex of pages NNN through MMM\n" 952 " NNN..MMM Show hex of pages NNN through MMM\n"
462 " NNN..end Show hex of pages NNN through end of file\n" 953 " NNN..end Show hex of pages NNN through end of file\n"
463 " NNNb Decode btree page NNN\n" 954 " NNNb Decode btree page NNN\n"
464 " NNNbc Decode btree page NNN and show content\n" 955 " NNNbc Decode btree page NNN and show content\n"
465 " NNNbm Decode btree page NNN and show a layout map\n" 956 " NNNbm Decode btree page NNN and show a layout map\n"
957 " NNNbdCCC Decode cell CCC on btree page NNN\n"
466 " NNNt Decode freelist trunk page NNN\n" 958 " NNNt Decode freelist trunk page NNN\n"
467 " NNNtd Show leave freelist pages on the decode\n" 959 " NNNtd Show leaf freelist pages on the decode\n"
468 " NNNtr Recurisvely decode freelist starting at NNN\n" 960 " NNNtr Recursively decode freelist starting at NNN\n"
469 ); 961 );
470 } 962 }
471 963
472 int main(int argc, char **argv){ 964 int main(int argc, char **argv){
473 struct stat sbuf; 965 struct stat sbuf;
474 unsigned char zPgSz[2]; 966 unsigned char zPgSz[2];
475 if( argc<2 ){ 967 if( argc<2 ){
476 usage(argv[0]); 968 usage(argv[0]);
477 exit(1); 969 exit(1);
478 } 970 }
479 db = open(argv[1], O_RDONLY); 971 db = open(argv[1], O_RDONLY);
480 if( db<0 ){ 972 if( db<0 ){
481 fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]); 973 fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
482 exit(1); 974 exit(1);
483 } 975 }
484 zPgSz[0] = 0; 976 zPgSz[0] = 0;
485 zPgSz[1] = 0; 977 zPgSz[1] = 0;
486 lseek(db, 16, SEEK_SET); 978 lseek(db, 16, SEEK_SET);
487 read(db, zPgSz, 2); 979 if( read(db, zPgSz, 2)<2 ) memset(zPgSz, 0, 2);
488 pagesize = zPgSz[0]*256 + zPgSz[1]*65536; 980 pagesize = zPgSz[0]*256 + zPgSz[1]*65536;
489 if( pagesize==0 ) pagesize = 1024; 981 if( pagesize==0 ) pagesize = 1024;
490 printf("Pagesize: %d\n", pagesize); 982 printf("Pagesize: %d\n", pagesize);
491 fstat(db, &sbuf); 983 fstat(db, &sbuf);
492 mxPage = sbuf.st_size/pagesize; 984 mxPage = sbuf.st_size/pagesize;
493 printf("Available pages: 1..%d\n", mxPage); 985 printf("Available pages: 1..%d\n", mxPage);
494 if( argc==2 ){ 986 if( argc==2 ){
495 int i; 987 int i;
496 for(i=1; i<=mxPage; i++) print_page(i); 988 for(i=1; i<=mxPage; i++) print_page(i);
497 }else{ 989 }else{
498 int i; 990 int i;
499 for(i=2; i<argc; i++){ 991 for(i=2; i<argc; i++){
500 int iStart, iEnd; 992 int iStart, iEnd;
501 char *zLeft; 993 char *zLeft;
502 if( strcmp(argv[i], "dbheader")==0 ){ 994 if( strcmp(argv[i], "dbheader")==0 ){
503 print_db_header(); 995 print_db_header();
504 continue; 996 continue;
505 } 997 }
998 if( strcmp(argv[i], "pgidx")==0 ){
999 page_usage_report(argv[1]);
1000 continue;
1001 }
1002 if( strcmp(argv[i], "ptrmap")==0 ){
1003 ptrmap_coverage_report(argv[1]);
1004 continue;
1005 }
1006 if( strcmp(argv[i], "help")==0 ){
1007 usage(argv[0]);
1008 continue;
1009 }
506 if( !isdigit(argv[i][0]) ){ 1010 if( !isdigit(argv[i][0]) ){
507 fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]); 1011 fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]);
508 continue; 1012 continue;
509 } 1013 }
510 iStart = strtol(argv[i], &zLeft, 0); 1014 iStart = strtol(argv[i], &zLeft, 0);
511 if( zLeft && strcmp(zLeft,"..end")==0 ){ 1015 if( zLeft && strcmp(zLeft,"..end")==0 ){
512 iEnd = mxPage; 1016 iEnd = mxPage;
513 }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){ 1017 }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){
514 iEnd = strtol(&zLeft[2], 0, 0); 1018 iEnd = strtol(&zLeft[2], 0, 0);
515 }else if( zLeft && zLeft[0]=='b' ){ 1019 }else if( zLeft && zLeft[0]=='b' ){
516 int ofst, nByte, hdrSize; 1020 int ofst, nByte, hdrSize;
517 unsigned char *a; 1021 unsigned char *a;
518 if( iStart==1 ){ 1022 if( iStart==1 ){
519 ofst = hdrSize = 100; 1023 ofst = hdrSize = 100;
520 nByte = pagesize-100; 1024 nByte = pagesize-100;
521 }else{ 1025 }else{
522 hdrSize = 0; 1026 hdrSize = 0;
523 ofst = (iStart-1)*pagesize; 1027 ofst = (iStart-1)*pagesize;
524 nByte = pagesize; 1028 nByte = pagesize;
525 } 1029 }
526 a = getContent(ofst, nByte); 1030 a = getContent(ofst, nByte);
527 decode_btree_page(a, iStart, hdrSize, &zLeft[1]); 1031 decode_btree_page(a, iStart, hdrSize, &zLeft[1]);
528 free(a); 1032 free(a);
529 continue; 1033 continue;
530 }else if( zLeft && zLeft[0]=='t' ){ 1034 }else if( zLeft && zLeft[0]=='t' ){
531 unsigned char *a;
532 int detail = 0; 1035 int detail = 0;
533 int recursive = 0; 1036 int recursive = 0;
534 int i; 1037 int i;
535 for(i=1; zLeft[i]; i++){ 1038 for(i=1; zLeft[i]; i++){
536 if( zLeft[i]=='r' ) recursive = 1; 1039 if( zLeft[i]=='r' ) recursive = 1;
537 if( zLeft[i]=='d' ) detail = 1; 1040 if( zLeft[i]=='d' ) detail = 1;
538 } 1041 }
539 decode_trunk_page(iStart, pagesize, detail, recursive); 1042 decode_trunk_page(iStart, pagesize, detail, recursive);
540 continue; 1043 continue;
541 }else{ 1044 }else{
542 iEnd = iStart; 1045 iEnd = iStart;
543 } 1046 }
544 if( iStart<1 || iEnd<iStart || iEnd>mxPage ){ 1047 if( iStart<1 || iEnd<iStart || iEnd>mxPage ){
545 fprintf(stderr, 1048 fprintf(stderr,
546 "Page argument should be LOWER?..UPPER?. Range 1 to %d\n", 1049 "Page argument should be LOWER?..UPPER?. Range 1 to %d\n",
547 mxPage); 1050 mxPage);
548 exit(1); 1051 exit(1);
549 } 1052 }
550 while( iStart<=iEnd ){ 1053 while( iStart<=iEnd ){
551 print_page(iStart); 1054 print_page(iStart);
552 iStart++; 1055 iStart++;
553 } 1056 }
554 } 1057 }
555 } 1058 }
556 close(db); 1059 close(db);
1060 return 0;
557 } 1061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698