void parse_str char pp char ps while ps if ps pp ps char add_str_rec 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
void parse_str(char** pp, char* ps)
{
while (*ps) {if(*ps++ == '/') *pp++ = ps;}
}
char* add_str_rec(char* pr, char* ps, char var, char** ptz)
{
char curvar = 0, *pz;
while (*ps && (*ps != '/')) {
if (*ps >= '#' && *ps <= '&') {curvar = *ps++; continue;}
if (curvar && (curvar != var)) {ps++; continue;}
if ((*ps >= '0' && *ps <= '9') || (*ps >= 'A' && *ps <= 'Z')){
pz = *(ptz + (*ps - ((*ps <= '9') ? 48 : 55)));
pr = add_str_rec(pr, pz, var, ptz);
ps++; continue;
}
*pr++ = *ps++;
}
return pr;
}
char* add_str(char* pr, char* ps, char var, char** ptz)
{
char *prstart = pr;
pr = add_str_rec(pr, ps, var, ptz);
if (pr > prstart) *pr++ = ' ';
return pr;
}
void int2fullString(int n, char* r)
{
char Sigh[] = "минус";
char *ptria[4], tria[] = "//тысяч$а%и/мE#ов%а/бE#ов%а";
char triaGen[] = "#$##";
char triaVar[] = "#$%%%#####";
char *phuns[10], huns[] = "//Fо/GеFи/3Fа/4еFа/5ьA/6ьA/7ьA/8ьA/9ьA";
char *ptens[10], tens[] = "///GаB/3B/сорок/5ьC/6ьC/7ьC/8ьC/HвяноFо";
char *pones[20], ones[] = "//1/2/3/4е/5ь/6ь/7ь/8ь/9ь/Hсять/одинD/GеD/3D/4D/5D/6D/7D/8D/9D";
char *ptz[20], tz[] = "//од#ин$на/дв#а$е/три/четыр/пят/шест/сем/восем/девят/сот/дцать/десят/надцать/иллион/ст/дв/де";
int nr[20], *pnr = nr, k;
char *pr = r, *pst, v;
parse_str(ptria, tria);
parse_str(phuns, huns);
parse_str(ptens, tens);
parse_str(pones, ones);
parse_str(ptz, tz);
if (n < 0) {n = -n; pr = add_str(pr, Sigh, '-', ptz);}
k = 0;
while (n) {*pnr++ = n%10; n = n/10; k++;}
while (k%3) {*pnr++ = 0; k++;}
pnr--;
k = k/3;
while (k-- > 0) {
pst = pr;
pr = add_str(pr, phuns[*pnr--], triaGen[k], ptz);
n = *pnr--;
v = (n == 1) ? triaVar[0] : 0;
if (n < 2) {
pr = add_str(pr, pones[n*10 + *pnr], triaGen[k], ptz);
}else{
pr = add_str(pr, ptens[n], triaGen[k], ptz);
pr = add_str(pr, pones[*pnr], triaGen[k], ptz);
}
n = *pnr--;
if (pr != pst) {
if (!v) {v = triaVar[n];}
pr = add_str(pr, ptria[k], v, ptz);
}
}
*pr = 0;
}