-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.c
52 lines (40 loc) · 908 Bytes
/
patterns.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
#include "commands.h"
#include "general.h"
#include "memory.h"
#include "text.h"
void analyze_patterns(general_t *info, char **arguments)
{
int i;
for (i = 0; arguments[i] != NULL; i++)
arguments[i] = pattern_handler(info, arguments[i]);
}
char *pattern_handler(general_t *info, char *string)
{
int i;
for (i = 0; string[i] != '\0'; i++)
{
if (string[i] == '$' && string[i + 1] != '\0')
string = replace_value(info, &i, string);
}
return (string);
}
char *replace_value(general_t *info, int *index, char *string)
{
int i, new_s, old_s;
char *value;
i = *index;
i++;
value = replacement(info, index, string + i);
if (value == NULL)
{
string = _strcpy(string, "");
return (string);;
}
old_s = _strlen(string);
new_s = _strlen(value) + 1;
string = _realloc(string, old_s, new_s);
string = _strcpy(string, value);
free_memory_p(value);
*index = i;
return (string);
}