-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.c
70 lines (56 loc) · 1.57 KB
/
validation.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "validation.h"
/*
Função: validaargumentos
- Verifica se argumentos recebidos, via linha de comando, são válidos.
Parâmetros:
- argc: Quantidade de argumentos recebidos
- argv: Lista de argumentos recebidos
- arguments: Variável que armazena os argumentos convertidos para o tipo int
Retorno:
- valor verdadeiro: Caso algum argumento seja inválido
- valor falso: caso Todos os argumentos estejam corretos
*/
int validateArguments(int argc, char ***argv, tArguments *arguments)
{
if (argc != 4 && argc != 5)
{
//Erro na quantidade de argumentos
return 501;
}
//Converte primeiro argumento para o tipo int
arguments->method = atoi((*argv)[1]);
if (arguments->method < 1 || arguments->method > 4)
{
//Metodo esta fora do intervalo especificado
return 502;
}
//Converte segundo argumento para o tipo int
arguments->quantity = atoi((*argv)[2]);
if (arguments->quantity != 200 &&
arguments->quantity != 2000 &&
arguments->quantity != 20000 &&
arguments->quantity != 200000 &&
arguments->quantity != 471705)
{
//Quantidade de registros incorreta
return 503;
}
//Converte terceiro argumento para o tipo int
arguments->situation = atoi((*argv)[3]);
if (arguments->situation < 1 || arguments->situation > 3)
{
return 504;
}
//Verifica se o argumento "-P" foi informado
if (argc == 5)
{
if (strcmp((*argv)[4], "-P") == 0)
arguments->showData = 1;
else
return 505;
}
return 0;
}