-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop2.c
113 lines (102 loc) · 1.72 KB
/
pop2.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
113
#include "main.h"
/**
* _myhistory - it displays the hist list
* @info: Struc
* Return: 0
*/
int _myhistory(info_t *info)
{
print_list(info->history);
return (0);
}
/**
* unset_alias - it sets name
* @info: para stru
* @str: str
*
* Return: its 0 on success and 1 on error
*/
int unset_alias(info_t *info, char *str)
{
char *x, y;
int ret;
x = _strchr(str, '=');
if (!x)
return (1);
y = *x;
*x = 0;
ret = delete_node_at_index(&(info->alias),
get_node_index(info->alias, node_starts_with(info->alias, str, -1)));
*x = y;
return (ret);
}
/**
* set_alias - it sets alias
* @info: its para struct
* @str: its str
*
* Return: 0 on success and 1 on error
*/
int set_alias(info_t *info, char *str)
{
char *x;
x = _strchr(str, '=');
if (!x)
return (1);
if (!*++x)
return (unset_alias(info, str));
unset_alias(info, str);
return (add_node_end(&(info->alias), str, 0) == NULL);
}
/**
* print_alias - it prints name
* @node: node
*
* Return: its 0 on success and 1 on error
*/
int print_alias(list_t *node)
{
char *x = NULL, *a = NULL;
if (node)
{
x = _strchr(node->str, '=');
for (a = node->str; a <= x; a++)
_putchar(*a);
_putchar('\'');
_puts(x + 1);
_puts("'\n");
return (0);
}
return (1);
}
/**
* _myalias - imittates the alias
* @info: Struc
*
* Return: 0
*/
int _myalias(info_t *info)
{
int a = 0;
char *x = NULL;
list_t *node = NULL;
if (info->argc == 1)
{
node = info->alias;
while (node)
{
print_alias(node);
node = node->next;
}
return (0);
}
for (a = 1; info->argv[a]; a++)
{
x = _strchr(info->argv[a], '=');
if (x)
set_alias(info, info->argv[a]);
else
print_alias(node_starts_with(info->alias, info->argv[a], '='));
}
return (0);
}