-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonty_instrct_base.c
123 lines (109 loc) · 2.26 KB
/
monty_instrct_base.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
114
115
116
117
118
119
120
121
122
123
#include "monty.h"
/**
* push - Push an elem to the top of the stack
*
* @stack: The stack.
* @line_number: The num of the line
*
* Return: Nothing, cause void function
*/
void push(stack_t **stack, unsigned int line_number)
{
int num;
if (globalVar.arrayCommand[1] == NULL)
{
dprintf(STDERR_FILENO, "L%d: usage: push integer\n", line_number);
free(globalVar.lineBuff);
freeAll();
fclose(globalVar.file);
exit(EXIT_FAILURE);
}
num = isNumber(globalVar.arrayCommand[1], line_number);
if (stack == NULL)
return;
if (globalVar.etat == 0)
add_dnodeint(stack, num);
else
add_dnodeint_end(stack, num);
}
/**
* pall - Prints the value at the top of the stack, followed by a new line.
*
*@stack: Stack where are stored the value.
*@line_number: Line where we want to read.
*
* Return: Nothing cause void function
*/
void pall(stack_t **stack, __attribute__((unused)) unsigned int line_number)
{
stack_t *browse = *stack;
if (stack == NULL)
return;
while (browse != NULL)
{
printf("%d\n", browse->n);
browse = browse->next;
}
}
/**
* pint - Print the top elem of the stack
*
* @stack: The stack.
* @line_number: The num of the line
*
* Return: Nothing, cause void function
*/
void pint(stack_t **stack, unsigned int line_number)
{
if (*stack == NULL)
{
dprintf(STDERR_FILENO, "L%d: can't pint, stack empty\n", line_number);
free(globalVar.lineBuff);
freeAll();
fclose(globalVar.file);
exit(EXIT_FAILURE);
}
printf("%d\n", (*stack)->n);
}
/**
* pop - Remove the top elem of the stack
*
* @stack: The stack.
* @line_number: The num of the line
*
* Return: Nothing, cause void function
*/
void pop(stack_t **stack, unsigned int line_number)
{
stack_t *browse = *stack;
if (*stack == NULL)
{
dprintf(STDERR_FILENO, "L%d: can't pop an empty stack\n", line_number);
free(globalVar.lineBuff);
freeAll();
fclose(globalVar.file);
exit(EXIT_FAILURE);
}
if (browse->next == NULL)
*stack = NULL;
else if (browse->next != NULL)
{
browse->next->prev = NULL;
(*stack) = browse->next;
}
free(browse);
}
/**
* nop - Do nothing
*
* @stack: The stack.
* @line_number: The num of the line
*
* Return: Nothing, cause void function
*/
void nop(__attribute__((unused)) stack_t **stack, unsigned int line_number)
{
int i;
i = line_number;
line_number = i;
}