-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.c
More file actions
executable file
·65 lines (60 loc) · 1.29 KB
/
match.c
File metadata and controls
executable file
·65 lines (60 loc) · 1.29 KB
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
#include "main.h"
/**
* get_op_func - function searches for a match between opcode and text
* and returns the corresponding function
* @line: struct containing line contents and line number
* @meta: struct containing all allocated memory
*
* Return: pointer to the matching function
*/
void (*get_op_func(line_t line, meta_t *meta))(stack_t **, unsigned int)
{
unsigned int i = 0;
instruction_t ops[] = {
{"push", push},
{"pall", pall},
{"add", opadd},
{"sub", opsub},
{"div", opdiv},
{"mul", opmult},
{"mod", opmod},
{"nop", nop},
{"pint", pint},
{"pop", pop},
{"swap", swap},
{"pchar", pchar},
{"pstr", pstr},
{"rotl", rotlop},
{"rotr", rotrop},
{"stack", addst},
{"queue", addqu},
{NULL, NULL}
};
if (comment_check(line))
return (nop);
while (ops[i].opcode)
{
if (strcmp(ops[i].opcode, line.content[0]) == 0)
{
push_check(line, meta, ops[i].opcode);
if (arg.flag == 1 &&
strcmp(ops[i].opcode, "push") == 0)
{
if (line.content)
free(line.content);
return (qpush);
}
free(line.content);
return (ops[i].f);
}
i++;
}
fprintf(stderr, "L%d: unknown instruction %s\n", line.number,
line.content[0]);
free(line.content);
free(meta->buf);
free_stack(&(meta->stack));
fclose(meta->file);
free(meta);
exit(EXIT_FAILURE);
}