-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.h
112 lines (98 loc) · 3.05 KB
/
Parser.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
109
110
111
112
#ifndef HW3_PARSER_H
#define HW3_PARSER_H
#include <string.h>
#include <stdbool.h>
#include "Game.h"
#include "FilesAux.h"
#include "MainAux.h"
#include <stdio.h>
#include <stdlib.h>
/**
*Parser Summary:
*
* This module is in charge of parsing the entered input of the user to the console
* and to use the specified commands or to print a specific error message
* to the console.
* It also checks whether each command was used in the correct state of the program
* and if not - prints a specific error message
*
* It supports the following functions (the main ones):
*
* command_to_code - translates the command entered by the user to a number that represents it
* interpret_command - receives the input from the user and disassembles it to command and its parameters
* execute_command - according to the number of the command and its parameters - uses the suitable func
*
* additionally it supports auxiliary functions to those 3 functions, mainly checking for errors functions
**/
extern char *strtok_r(char *, const char *, char **);
/**/
/**
* compares two strings
* @param first string
* @param second string
* @return 0 if the strings the same, otherwise the strings are different
* */
int str_equals(char *str1, char *str2);
/**
* checks if a given char is a digit (0 to 9 only)
* @param char c
* @return True (1) if c is a digit, otherwise False (0)
*/
bool is_digit(char c);
/**
* checks if a given char is a dot
* @param char c
* @return True (1) if c is a dot, otherwise False (0)
*/
bool is_dot(char c);
/**
* checks if a given string is a valid path to a file
* @param string path
* @return True (1) if the string is a valid path, otherwise False (0)
*/
bool is_valid_path(char* path);
/**
* calculates a in the power of b (a ^ b)
* @param int a
* @param int b
* @return a in the power of b (a ^ b)
*/
int my_pow(int a, int b);
/**
* checks if a given string is an integer
* @param string s
* @return 1 if s is an integer, otherwise 0
*/
int is_integer(char* s);
/**
* checks if a given string is a double
* @param string s
* @return 1 if s is a double, otherwise 0
*/
bool is_double(char* s);
/**
* checks if the parameters to the command are valid
* @param command_code - the number represents the command
* @param command_data - array of strings which are the parameters
* @return True (1) if the parameters are valid, False (0) otherwise
*/
bool is_valid_param(int command_code, char command_data[4][258]);
/**
* checks if the input string is one of the optional commands
* @param string input
* @return the command_code, its the number that represents the command
*/
int command_to_code(char* input) ;
/**
* gets the input from the user and disassembles it to command and
* parameters
*/
void interpret_command();
/**
* according to the command_code(# of command) and command_data(parameters)-
* activate the command with the given parameters or prints an error
* @param command_code
* @param command_data
*/
void execute_command(int command_code, char command_data[4][258]);
#endif