diff options
author | dan miller | 2007-10-21 08:36:32 +0000 |
---|---|---|
committer | dan miller | 2007-10-21 08:36:32 +0000 |
commit | 2f8d7092bc2c9609fa98d6888106b96f38b22828 (patch) | |
tree | da6c37579258cc965b52a75aee6135fe44237698 /libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c | |
parent | * Committing new PolicyManager based on an ACL system. (diff) | |
download | opensim-SC-2f8d7092bc2c9609fa98d6888106b96f38b22828.zip opensim-SC-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.gz opensim-SC-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.bz2 opensim-SC-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.xz |
libraries moved to opensim-libs, a new repository
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c b/libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c deleted file mode 100644 index b2ed562..0000000 --- a/libraries/sqlite/unix/sqlite-3.5.1/tool/showdb.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* | ||
2 | ** A utility for printing all or part of an SQLite database file. | ||
3 | */ | ||
4 | #include <stdio.h> | ||
5 | #include <ctype.h> | ||
6 | #include <sys/types.h> | ||
7 | #include <sys/stat.h> | ||
8 | #include <fcntl.h> | ||
9 | #include <unistd.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | |||
13 | static int pagesize = 1024; | ||
14 | static int db = -1; | ||
15 | static int mxPage = 0; | ||
16 | static int perLine = 32; | ||
17 | |||
18 | static void out_of_memory(void){ | ||
19 | fprintf(stderr,"Out of memory...\n"); | ||
20 | exit(1); | ||
21 | } | ||
22 | |||
23 | static print_page(int iPg){ | ||
24 | unsigned char *aData; | ||
25 | int i, j; | ||
26 | aData = malloc(pagesize); | ||
27 | if( aData==0 ) out_of_memory(); | ||
28 | lseek(db, (iPg-1)*pagesize, SEEK_SET); | ||
29 | read(db, aData, pagesize); | ||
30 | fprintf(stdout, "Page %d:\n", iPg); | ||
31 | for(i=0; i<pagesize; i += perLine){ | ||
32 | fprintf(stdout, " %03x: ",i); | ||
33 | for(j=0; j<perLine; j++){ | ||
34 | fprintf(stdout,"%02x ", aData[i+j]); | ||
35 | } | ||
36 | for(j=0; j<perLine; j++){ | ||
37 | fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.'); | ||
38 | } | ||
39 | fprintf(stdout,"\n"); | ||
40 | } | ||
41 | free(aData); | ||
42 | } | ||
43 | |||
44 | int main(int argc, char **argv){ | ||
45 | struct stat sbuf; | ||
46 | if( argc<2 ){ | ||
47 | fprintf(stderr,"Usage: %s FILENAME ?PAGE? ...\n", argv[0]); | ||
48 | exit(1); | ||
49 | } | ||
50 | db = open(argv[1], O_RDONLY); | ||
51 | if( db<0 ){ | ||
52 | fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]); | ||
53 | exit(1); | ||
54 | } | ||
55 | fstat(db, &sbuf); | ||
56 | mxPage = sbuf.st_size/pagesize + 1; | ||
57 | if( argc==2 ){ | ||
58 | int i; | ||
59 | for(i=1; i<=mxPage; i++) print_page(i); | ||
60 | }else{ | ||
61 | int i; | ||
62 | for(i=2; i<argc; i++){ | ||
63 | int iStart, iEnd; | ||
64 | char *zLeft; | ||
65 | iStart = strtol(argv[i], &zLeft, 0); | ||
66 | if( zLeft && strcmp(zLeft,"..end")==0 ){ | ||
67 | iEnd = mxPage; | ||
68 | }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){ | ||
69 | iEnd = strtol(&zLeft[2], 0, 0); | ||
70 | }else{ | ||
71 | iEnd = iStart; | ||
72 | } | ||
73 | if( iStart<1 || iEnd<iStart || iEnd>mxPage ){ | ||
74 | fprintf(stderr, | ||
75 | "Page argument should be LOWER?..UPPER?. Range 1 to %d\n", | ||
76 | mxPage); | ||
77 | exit(1); | ||
78 | } | ||
79 | while( iStart<=iEnd ){ | ||
80 | print_page(iStart); | ||
81 | iStart++; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | close(db); | ||
86 | } | ||