-
Notifications
You must be signed in to change notification settings - Fork 1
/
monty_funcs_3.c
59 lines (51 loc) · 1.56 KB
/
monty_funcs_3.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
#include "monty.h"
void monty_nop(stack_t **stack, unsigned int line_number);
void monty_pchar(stack_t **stack, unsigned int line_number);
void monty_pstr(stack_t **stack, unsigned int line_number);
/**
* monty_nop - Does absolutely nothing for the Monty opcode 'nop'.
* @stack: A pointer to the top mode node of a stack_t linked list.
* @line_number: The current working line number of a Monty bytecodes file.
*/
void monty_nop(stack_t **stack, unsigned int line_number)
{
(void)stack;
(void)line_number;
}
/**
* monty_pchar - Prints the character in the top value
* node of a stack_t linked list.
* @stack: A pointer to the top mode node of a stack_t linked list.
* @line_number: The current working line number of a Monty bytecodes file.
*/
void monty_pchar(stack_t **stack, unsigned int line_number)
{
if ((*stack)->next == NULL)
{
set_op_tok_error(pchar_error(line_number, "stack empty"));
return;
}
if ((*stack)->next->n < 0 || (*stack)->next->n > 127)
{
set_op_tok_error(pchar_error(line_number,
"value out of range"));
return;
}
printf("%c\n", (*stack)->next->n);
}
/**
* monty_pstr - Prints the string contained in a stack_t linked list.
* @stack: A pointer to the top mode node of a stack_t linked list.
* @line_number: The current working line number of a Monty bytecodes file.
*/
void monty_pstr(stack_t **stack, unsigned int line_number)
{
stack_t *tmp = (*stack)->next;
while (tmp && tmp->n != 0 && (tmp->n > 0 && tmp->n <= 127))
{
printf("%c", tmp->n);
tmp = tmp->next;
}
printf("\n");
(void)line_number;
}