-
Notifications
You must be signed in to change notification settings - Fork 0
/
monty.h
108 lines (95 loc) · 3.04 KB
/
monty.h
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
#ifndef _MONTY_
#define _MONTY_
/* Constants */
#define SUCSS_OP 0
#define VALID_PARM 0
#define MIN_ARGS 2
#define METH_STACK 300
#define METH_QUEUE 301
/* Common Errors */
#define ERR_BAD_INST 100
#define ERR_BAD_MALL 101
#define ERR_INVLD_PARM 102
/* Usage Errors */
#define ERR_ARG_USG 200
#define ERR_PUSH_USG 201
#define ERR_PINT_USG 202
#define ERR_POP_USG 203
#define ERR_SWAP_USG 204
#define ERR_ADD_USG 205
#define ERR_SUB_USG 206
#define ERR_DIV_USG 207
#define ERR_DIV_ZRO 208
#define ERR_MUL_USG 209
#define ERR_MOD_USG 210
#define ERR_PCH_USG 211
#define ERR_PCH_EMP 212
#include <ctype.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/**
* struct stack_s - doubly linked list representation of a stack (or queue)
* @n: integer
* @prev: points to the previous element of the stack (or queue)
* @next: points to the next element of the stack (or queue)
*
* Description: doubly linked list node structure
* for stack, queues, LIFO, FIFO Holberton project
*/
typedef struct stack_s
{
int n;
struct stack_s *prev;
struct stack_s *next;
} stack_t;
/**
* struct instruction_s - opcode and its function
* @opcode: the opcode
* @f: function to handle the opcode
*
* Description: opcode and its function
* for stack, queues, LIFO, FIFO Holberton project
*/
typedef struct instruction_s
{
char *opcode;
void (*f)(stack_t **stack, unsigned int line_number);
} instruction_t;
extern stack_t *head;
/* Stack utilites */
unsigned int count_stack(stack_t *stack);
void frees_stack(void);
void check_args_num(int argn);
FILE *open_file(char *filename);
void check_access_rights(char *filename);
int check_push_param(char *param);
int check_digits(char *s);
/* Execute functions */
int handle_execution(char *op_code, char *op_param, unsigned int line, int m);
void (*execute_func(char *s))(stack_t **, unsigned int);
/* Handle errors */
void handle_error(int errno, char *opcode, unsigned int line, char *buff);
void handle_cerror(int errno, char *opcode, unsigned int line);
void handle_uerror(int errno, unsigned int line);
void handle_more_uerror(int errno, unsigned int line);
/* op code functions */
void op_push(stack_t **stack, unsigned int param);
void op_push_queue(stack_t **stack, unsigned int param);
void op_pall(stack_t **stack, unsigned int line_number);
void op_pint(stack_t **stack, unsigned int line_number);
void op_pop(stack_t **stack, unsigned int line_number);
void op_swap(stack_t **stack, unsigned int line_number);
void op_add(stack_t **stack, unsigned int line_number);
void op_nop(stack_t **stack, unsigned int line_number);
void op_sub(stack_t **stack, unsigned int line_number);
void op_divide(stack_t **stack, unsigned int line_number);
void op_mul(stack_t **stack, unsigned int line_number);
void op_mod(stack_t **stack, unsigned int line_number);
void op_pchar(stack_t **stack, unsigned int line_number);
void op_pstr(stack_t **stack, unsigned int line_number);
void op_rotl(stack_t **stack, unsigned int line_number);
void op_rotr(stack_t **stack, unsigned int line_number);
#endif