File:
[LON-CAPA] /
loncom /
debugging_tools /
dump_db.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Thu Aug 24 22:46:30 2006 UTC (18 years ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- adding scripts to allow morphing 32bit to 64 bit db
1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <unistd.h>
4: #include <gdbm.h>
5: #include <errno.h>
6: #include <string.h>
7: #include <ctype.h>
8:
9: static const char c2x_table[] = "0123456789abcdef";
10:
11: void c2x(unsigned what, unsigned char prefix, char *where,
12: unsigned int offset)
13: {
14: where[offset] = prefix;
15: where[offset+1] = c2x_table[what >> 4];
16: where[offset+2] = c2x_table[what & 0xf];
17: }
18:
19:
20: datum* http_escape(datum* data)
21: {
22: datum *escaped_data;
23: escaped_data = malloc(sizeof(datum));
24: escaped_data->dsize = (3 * data->dsize) + 3;
25: escaped_data->dptr = malloc(escaped_data->dsize);
26: unsigned int c,i,j;
27:
28: j=0;
29: for (i=0;i<data->dsize;i++) {
30: c = data->dptr[i];
31: if (!isalnum(c)) {
32: c2x(c, '%', escaped_data->dptr, j);
33: j+=3;
34: } else {
35: escaped_data->dptr[j] = c;
36: j++;
37: }
38: }
39: escaped_data->dsize=j;
40: return escaped_data;
41: }
42:
43:
44: void usage()
45: {
46: printf("\nUsage:\ngdbm_convertor -f <gdbm file to convert>\n");
47: }
48:
49: void read_db(char *filename)
50: {
51: GDBM_FILE db;
52: datum key, nextkey, content;
53: datum *escaped_key, *escaped_content;
54: db = gdbm_open(filename, 0, GDBM_READER, 0, 0);
55:
56: if (db == NULL) {
57: printf("ERROR:Unable to open db %s because of %s (%d) -- %s (%d)\n",
58: filename,gdbm_strerror(gdbm_errno),gdbm_errno,strerror(errno),
59: errno);
60: return;
61: }
62: key = gdbm_firstkey(db);
63:
64: while ( key.dptr ) {
65: content = gdbm_fetch(db, key);
66: escaped_key = http_escape(&key);
67: escaped_content = http_escape(&content);
68: fwrite(escaped_key->dptr,
69: escaped_key->dsize, sizeof(char), stdout);
70: printf(" -> ");
71: fwrite(escaped_content->dptr,
72: escaped_content->dsize, sizeof(char), stdout);
73: printf("\n");
74: free(content.dptr);
75: free(escaped_content->dptr);
76: free(escaped_content);
77: free(escaped_key->dptr);
78: free(escaped_key);
79: nextkey = gdbm_nextkey(db, key);
80: free(key.dptr);
81: key = nextkey;
82: }
83: }
84:
85: int main(int argc, char **argv)
86: {
87:
88: int c;
89: char *filename=NULL;
90: while (1) {
91: c = getopt(argc,argv,"f:");
92: if (c == -1)
93: break;
94: switch (c) {
95: case 'f':
96: filename = optarg;
97: }
98: }
99:
100: if (filename == NULL) {
101: usage();
102: return 1;
103: }
104:
105: read_db(filename);
106:
107: return 0;
108: }
109:
110:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>