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
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include "config.h"
#include "exceptions.h"
#include "linker.h"
typedef void (*sighandler_t) (int);
void invite(void)
{
fprintf(stderr, _("Linker v1.0\n\n"));
}
void usage(void)
{
fprintf(stderr, _("Usage: linker obj1 [obj2 [obj3 [...]]] binary\n"));
exit(0);
}
void init_all(int n)
{
fprintf(stderr, _(" o Initialising the linker... "));
init(n);
fprintf(stderr, _(" Done!\n"));
}
void flush_all(void)
{
flush();
}
void segfaulthand(int i)
{
exception(1, _("Signal received: segfault"));
}
int main(int argc, char **argv)
{
int i;
invite();
signal(SIGSEGV, segfaulthand);
if (argc < 3)
usage();
fprintf(stderr, _("\nPerforming initialisation...\n\n"));
init_all(argc - 2);
fprintf(stderr, _("Linking files...\n"));
for (i = 1; i < argc - 1; i++) {
addfile(argv[i]);
}
fprintf(stderr, _("Generating output file...\n"));
dumpfile(argv[i]);
fprintf(stderr, _("\nPerforming shutdown...\n\n"));
flush_all();
signal(SIGSEGV, NULL);
fprintf(stderr, _("Exitting, bye!\n"));
return 0;
}
|