-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_func.c
99 lines (88 loc) · 1.82 KB
/
exec_func.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
#include "monty.h"
/**
* exec_push - pushes an element to the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_push(stack_t **stack, unsigned int line_number, char *data_arg)
{
if (global->mode)
{
push(stack, line_number, data_arg);
}
else
enqueue(stack, line_number, data_arg);
}
/**
* exec_pall - prints all the values on the stack
* starting from the top of the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_pall(stack_t **stack, unsigned int line_number, char *data_arg)
{
stack_t *current = *stack;
(void)line_number;
(void)data_arg;
while (current)
{
printf("%d\n", current->n);
current = current->next;
}
}
/**
* exec_pint - print top opcode function
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_pint(stack_t **stack, unsigned int line_number, char *data_arg)
{
(void)data_arg;
if (*stack)
printf("%d\n", (*stack)->n);
else
{
fprintf(stderr, "L%d: can't pint, stack empty\n", line_number);
exit_failure(global);
}
}
/**
* exec_pop - pop opcode function
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_pop(stack_t **stack, unsigned int line_number, char *data_arg)
{
stack_t *del;
(void)data_arg;
if (stack == NULL || *stack == NULL)
{
fprintf(stderr, "L%d: can't pop an empty stack\n", line_number);
exit_failure(global);
}
del = *stack;
if (del->next != NULL)
{
*stack = del->next;
del->next->prev = del->prev;
}
else
*stack = NULL;
free(del);
}
/**
* exec_nop - does nothing
* @stack: stack pointer
* @line_number: line number
* @data_arg: data arg
*/
void exec_nop(stack_t **stack, unsigned int line_number, char *data_arg)
{
(void)stack;
(void)line_number;
(void)data_arg;
}