-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportFiles.c
More file actions
78 lines (70 loc) · 1.94 KB
/
exportFiles.c
File metadata and controls
78 lines (70 loc) · 1.94 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
68
69
70
71
72
73
74
75
76
77
78
#include "data.h"
extern void fileCreationFailure(char *fileName);
static char *(*baseFileName)() = &getFileNamePath;
/* void exportFilesMainHandler()
This function calls other functions that will create the .ob file,
.ent file and .ext file if there are any entry labels, and .ext file
if there are any external labels.*/
void exportFilesMainHandler()
{
printf("Finished Successfully, about to export files!\n");
generateObFile();
if (areEntriesExist())
createEntriesFile();
if (areExternalsExist())
createExternalsFile();
}
/* void generateObFile()
This function generates the .ob files by writing the memory image,
if the file can't be generate it yields error */
void generateObFile()
{
FILE *ob;
char *fileName = (*baseFileName)();
strcat(fileName, ".ob");
ob = fopen(fileName, "w+");
if (ob != NULL)
{
writeMemoryImageToObFile(ob);
fclose(ob);
free(fileName);
}
else
fileCreationFailure(fileName);
}
/* void createEntriesFile()
This function generates the .ent files (as long as there are entry labels) by writing
it into the file, if the file can't be generate it yields error */
void createEntriesFile()
{
FILE *ent;
char *fileName = (*baseFileName)();
strcat(fileName, ".ent");
ent = fopen(fileName, "w+");
if (ent != NULL)
{
writeEntriesToFile(ent);
fclose(ent);
free(fileName);
}
else
fileCreationFailure(fileName);
}
/* createExternalsFile()
This function generates the .ext files (as long as there are external labels)
by writing it into the file, if the file can't be generate it yields error */
void createExternalsFile()
{
FILE *ext;
char *fileName = (*baseFileName)();
strcat(fileName, ".ext");
ext = fopen(fileName, "w+");
if (ext != NULL)
{
writeExternalsToFile(ext);
fclose(ext);
free(fileName);
}
else
fileCreationFailure(fileName);
}