-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathndom.c
89 lines (77 loc) · 1.56 KB
/
ndom.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <string.h>
#include "ndom.h"
#define COPY_STRING(d, p, s) \
{ char *_s = s; while (*_s) *((d)+(p)++) = *_s++; }
char *int_to_ndom(int value, char *str)
{
if (value < 1 || value > 143) {
return NULL;
}
int pos = 0;
if (value >= 6*6*3) {
COPY_STRING(str, pos, "nif ithin");
value -= 6*6*3;
}
else if (value >= 6*6*2) {
COPY_STRING(str, pos, "nif thef");
value -= 6*6*2;
}
else if (value >= 6*6) {
COPY_STRING(str, pos, "nif");
value -= 6*6;
}
if (value >= 6*3) {
if (pos)
COPY_STRING(str, pos, " abo ");
COPY_STRING(str, pos, "tondor");
value -= 6*3;
}
if (value >= 6*2) {
if (pos)
COPY_STRING(str, pos, " abo ");
COPY_STRING(str, pos, "mer an thef");
value -= 6*2;
}
else if (value >= 6) {
if (pos)
COPY_STRING(str, pos, " abo ");
COPY_STRING(str, pos, "mer");
value -= 6;
}
if (value > 0) {
if (pos)
COPY_STRING(str, pos, " abo ");
switch (value) {
case 1:
COPY_STRING(str, pos, "sas");
break;
case 2:
COPY_STRING(str, pos, "thef");
break;
case 3:
COPY_STRING(str, pos, "ithin");
break;
case 4:
COPY_STRING(str, pos, "thonith");
break;
case 5:
COPY_STRING(str, pos, "meregh");
break;
}
}
str[pos] = '\0';
return str;
}
int ndom_test(void)
{
char ndom_string[NDOM_CHARS_MAX+1];
for (int i=1; i<=143; i++) {
if (!int_to_ndom(i, ndom_string)) {
return -1;
}
if (ndom_to_int(ndom_string) < 0) {
return -1;
}
}
return 0;
}