-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadFile.cpp
More file actions
62 lines (58 loc) · 1.84 KB
/
readFile.cpp
File metadata and controls
62 lines (58 loc) · 1.84 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
#include "filesystem.h"
int FileSystem::readFile(const char *title) {
/*
objective: to read a single file from multiple non-continuous sectors
input:
title: title of file
return:
0: success
1: error
effect: contents of file are printed, if success
*/
TypeCastEntry entry;
if (strlen(title) == 0) {
std::cout << "File title: ";
std::cin >> entry.entry.name;
std::cin.ignore(32767, '\n');
} else {
strcpy(entry.entry.name, title);
}
entry.entry.startsAt = 0;
char buf[kSectorSize];
TypeCastEntry test;
for (int i = 0; i < sectorsForDir; ++i) {
readSector(currentDir + i, buf);
for (int j = 0; j < kSectorSize; j += 32) {
for (int k = 0; k < 32; ++k) {
test.str[k] = buf[j+k];
}
if (strcmp(test.entry.name, entry.entry.name) == 0) {
entry.entry.startsAt = test.entry.startsAt;
entry.entry.size = test.entry.size;
entry.entry.parent = test.entry.parent;
if (test.entry.type != 'F') return 1;
break;
}
}
if (entry.entry.startsAt != 0) break;
}
if (entry.entry.startsAt == 0) {
std::cout << "file not found" << std::endl;
return 1;
} else {
// read file content
std::cout << "READING FILE WITH" << std::endl;
std::cout << "TITLE = " << test.entry.name << std::endl;
std::cout << "SIZE = " << entry.entry.size << " bytes." << std::endl;
int sec = entry.entry.startsAt;
while (sec != 1) {
readSector(sec, buf);
for (int i = 0; i < kSectorSize; ++i) {
std::cout << buf[i];
}
sec = getStatus(sec);
}
std::cout << std::endl;
}
return 0;
}