-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_type.c
More file actions
114 lines (103 loc) · 2.36 KB
/
input_type.c
File metadata and controls
114 lines (103 loc) · 2.36 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
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
113
114
/* ************************************************************************** */
/* */
/* :::::::: */
/* input_type.c :+: :+: */
/* +:+ */
/* By: lvan-vlo <lvan-vlo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/07/27 14:55:01 by lvan-vlo #+# #+# */
/* Updated: 2019/09/20 16:38:38 by rcorke ######## odam.nl */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static int only_numbers(char *str)
{
int x;
x = 0;
while (str[x] != '\0')
{
if (!ft_isdigit(str[x]))
return (0);
x++;
}
if (ft_atoi(str) == 0)
return (0);
if (ft_fits_in_int(str))
return (1);
return (0);
}
static int is_room(char *str)
{
int x;
x = 0;
if (str[0] == 'L')
return (0);
while (str[x] && str[x] != ' ')
x++;
if (!str[x] || !str[x + 1] || !ft_isdigit(str[x + 1]))
return (0);
x++;
while (str[x] && ft_isdigit(str[x]))
x++;
if (!str[x] || str[x] != ' ' || !str[x + 1] || !ft_isdigit(str[x + 1]))
return (0);
x++;
while (ft_isdigit(str[x]))
x++;
if (str[x])
return (0);
return (1);
}
static int check_around_dashes(char *str)
{
int x;
x = 0;
while (str[x] && str[x] != '-')
{
if (str[x] == ' ' || str[x] == '\t')
return (0);
x++;
}
while (str[x])
{
if (str[x] == ' ' || str[x] == '\t')
return (0);
x++;
}
return (1);
}
static int is_link(char *str, int len)
{
int x;
int dashes;
if (!str || !ft_strchr(str, '-') || str[0] == '-' || \
str[len - 1] == '-')
return (0);
x = 0;
dashes = 0;
while (str[x] != '\0')
{
if (str[x] == '-')
dashes++;
x++;
}
if (dashes != 1)
return (0);
return (check_around_dashes(str));
}
int input_type(char *str)
{
int len;
if (!str)
return (-1);
len = ft_strlen(str);
if (str && len > 0 && str[0] == '#')
return (4);
else if (only_numbers(str))
return (1);
else if (is_room(str))
return (2);
else if (is_link(str, len))
return (3);
return (-1);
}