-
Notifications
You must be signed in to change notification settings - Fork 0
/
sic.c
75 lines (61 loc) · 1.31 KB
/
sic.c
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
#include <stdio.h>
#include <stdlib.h>
#ifdef CONFIG_CALCULATE_TIME
#include <sys/time.h>
#include "time.h"
#endif
#include "sic.h"
#ifdef CONFIG_LARGE_ADDRESS
long long atoll(const char *nptr); /* for -ansi compilation switch */
#define ATOL(X) atoll(X)
#define STR_NUMERIC_FMT "%llu"
#else
#define ATOL(X) atol(X)
#define STR_NUMERIC_FMT "%lu"
#endif
#define STR_ALPHANUMERIC_FMT "%c"
static ADDR_SPC_T sic_args[MAX_ARGS];
static int sic_args_atol(int argc, char *argv[])
{
int i;
if (argc > MAX_ARGS)
return -1;
for (i = 0; i < argc; i++)
sic_args[i] = ATOL(argv[i]);
return 0;
}
int main(int argc, char *argv[])
{
int i = 0, j;
char *format = NULL;
#ifdef CONFIG_CALCULATE_TIME
timeval tv1, tv2;
time_clear(&tv1);
time_clear(&tv2);
#endif
if (sic_args_atol(argc - 1, argv + 1) || sic_init(argc - 1, sic_args))
return -1;
#ifdef CONFIG_CALCULATE_TIME
if (gettimeofday(&tv1, NULL))
return -1;
#endif
while (M[i] || M[i+1] || M[i+2]) {
if ((M[M[i]] -= M[M[i+1]]) < 0)
i = M[i+2];
else
i += 3;
}
#ifdef CONFIG_CALCULATE_TIME
if (gettimeofday(&tv2, NULL))
return -1;
#endif
format = M[0] ? STR_NUMERIC_FMT : STR_ALPHANUMERIC_FMT;
for (i = M[1], j = M[2]; i > 0; --i, ++j)
printf(format, M[j]);
printf("\n");
#ifdef CONFIG_CALCULATE_TIME
if (M[0])
print_time(&tv1, &tv2);
#endif
return 0;
}