-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_numlst_up_magni.c
112 lines (103 loc) · 2.66 KB
/
ft_numlst_up_magni.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_numlst_up_magni.c :+: :+: */
/* +:+ */
/* By: aholster <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/08/13 15:24:32 by aholster #+# #+# */
/* Updated: 2019/09/05 12:04:49 by aholster ######## odam.nl */
/* */
/* ************************************************************************** */
#include "float_tech.h"
static int navigate_to_magni(t_numlst *product, const char digit,\
size_t index, unsigned char magni)
{
char *txt;
while (1)
{
txt = product->mem;
while (index > 0)
{
index--;
if (txt[index] != '.')
{
magni--;
if (magni == 0)
{
product->mem[index] = digit;
return (1);
}
}
}
if (product->prev == NULL)
if (ft_numlst_prefix(product, 1) == -1)
return (-1);
product = product->prev;
index = product->mem_size;
}
}
static int ft_numlst_magni(t_numlst *product, const t_numlst *source,\
unsigned char magni)
{
size_t index;
size_t size;
char *txt;
while (source != NULL)
{
index = 0;
size = source->mem_size;
txt = source->mem;
while (index < size)
{
if (txt[index] != '.')
{
if (navigate_to_magni(product,\
txt[index], index, magni - 1) == -1)
return (-1);
}
index++;
}
product = product->next;
source = source->next;
}
return (1);
}
static void dst_cleanup(t_numlst *dst)
{
t_numlst *traveler;
traveler = dst->next;
while (traveler != NULL)
{
ft_memset(traveler->mem, '0', traveler->mem_size);
traveler = traveler->next;
}
traveler = dst->prev;
while (traveler != NULL)
{
ft_memset(traveler->mem, '0', traveler->mem_size);
traveler = traveler->prev;
}
dst->mem[0] = '0';
dst->mem[1] = '.';
dst->mem[2] = '0';
}
int ft_numlst_up_magni(const t_numlst *source, t_numlst *dst,\
unsigned char mag)
{
t_numlst *prod_trav;
const t_numlst *src_trav;
dst_cleanup(dst);
if (ft_numlst_minsize(dst, source) == -1)
return (-1);
src_trav = source;
prod_trav = dst;
while (src_trav->prev != NULL)
{
prod_trav = prod_trav->prev;
src_trav = src_trav->prev;
}
if (ft_numlst_magni(prod_trav, src_trav, mag) == -1)
return (-1);
return (1);
}