-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.c
More file actions
67 lines (55 loc) · 1.35 KB
/
dump.c
File metadata and controls
67 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
// dump.c ... show all tuples in a Relation
// part of Multi-attribute linear-hashed files
// Show tuples, bucket-by-bucket
// Last modified by John Shepherd, July 2019
// Usage: ./stats RelName
#include "defs.h"
#include "reln.h"
#include "page.h"
void showAllTuples(Page);
#define USAGE "./dump RelName"
// Main ... process args, scan data, show tuples
int main(int argc, char **argv)
{
// process command-line args
if (argc < 2) fatal(USAGE);
char *relname = argv[1];
// open relation and show stats
if (!existsRelation(relname))
fatal("No such relation");
Reln r = openRelation(relname,"r");
if (r == NULL)
fatal("Can't open relation");
for (Offset pid = 0; pid < npages(r); pid++) {
printf("Bucket[%d]\n",pid);
// show tuples in data file
Page pg = getPage(dataFile(r),pid);
showAllTuples(pg);
// show tuples in overflow pages
Page ovpg; PageID ovp;
ovp = pageOvflow(pg);
while (ovp != NO_PAGE) {
printf("Ovflow->\n");
ovpg = getPage(ovflowFile(r), ovp);
showAllTuples(ovpg);
ovp = pageOvflow(ovpg);
free(ovpg);
}
free(pg);
}
closeRelation(r);
return 0;
}
// scan all tuples in Page
void showAllTuples(Page pg)
{
Count ntups = pageNTuples(pg);
char *c = pageData(pg);
for (int i = 0; i < ntups; i++) {
printf("%s\n", c);
c += strlen(c) + 1;
}
}