-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.c
102 lines (94 loc) · 1.97 KB
/
find.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
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
/*
** find_obj.c for in /home/walbec_h/rendu 2014-2015/Igraph/MUL_2014_rtv1
**
** Made by hugo walbecq
** Login <walbec_h@epitech.net>
**
** Started on Tue Feb 3 15:20:37 2015 hugo walbecq
** Last update Sun Mar 15 16:03:41 2015 hugo walbecq
*/
#include <stdlib.h>
#include <stdio.h>
#include "include/rtv1.h"
#include "include/my.h"
char *find_number(char *buffer, int i)
{
char *res;
int a;
int b;
a = i;
b = 0;
res = malloc(sizeof(char) * 9);
while (buffer[a] != ';')
res[b++] = buffer[a++];
res[b] = '\0';
return (res);
}
int check_all(char *buffer)
{
int i;
i = 0;
while (buffer[i] != '\0')
{
if (buffer[i] != 's' && buffer[i] != 'p' && buffer[i] != ';' &&
buffer[i] != 'l' && buffer[i] != 'i' && buffer[i] != '-' &&
buffer[i] != 'c' && buffer[i] != 'y' && buffer[i] != '\n' &&
buffer[i] != 'o' && (buffer[i] < '0' || buffer[i] > '9'))
{
my_putstr("Incorrect character: '");
my_putchar(buffer[i]);
my_putstr("' in file\n");
return (1);
}
i++;
}
return (0);
}
int check_num(char *buffer, int i)
{
if (buffer[++i] == ';')
{
my_putstr("Incorrect file : two ';' without numbers\n");
return (1);
}
if (buffer[i] != '\n')
while (buffer[i] != ';')
{
if (buffer[i] != '-' && (buffer[i] < '0' || buffer[i] > '9'))
{
my_putstr("Bad character(s) between two ';'\n");
return (1);
}
i++;
}
if (check_arg_obj(buffer) == 1)
return (1);
return (0);
}
int check_buff(char *buffer)
{
int i;
i = 0;
if (check_all(buffer) == 1)
return (1);
while (buffer[i] != '\0')
{
if (buffer[i] == '\n')
if (buffer[i - 1] != ';')
{
my_putstr("Incorrect file (help in file 'manconf')\n");
return (1);
}
if (buffer[i] == ';')
if (check_num(buffer, i) == 1)
return (1);
i++;
}
i--;
if (buffer[i] != '\n')
{
my_putstr("You must put a 'backslash n' at the end of file\n");
return (1);
}
return (0);
}