Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Handle error if arg is a number but not preceded by valid option
Close #19
  • Loading branch information
fpetras committed Apr 25, 2018
1 parent 2e7f1da commit 6d7fb8a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
7 changes: 4 additions & 3 deletions include/ft_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/19 21:39:11 by rnugroho #+# #+# */
/* Updated: 2018/04/25 03:14:13 by rnugroho ### ########.fr */
/* Updated: 2018/04/25 07:37:37 by fpetras ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -64,10 +64,11 @@ typedef struct s_champ

typedef struct s_vm
{
int valid_arg[2];
int dump;
int check_nbr;
int v_lvl[6];
char *players[MAX_PLAYERS + 2];
char *players[MAX_PLAYERS + 1];
t_champ champ[4];
int process_size;
int champ_size;
Expand Down Expand Up @@ -113,7 +114,7 @@ void vm_and_print(t_process p);
void vm_live_print(t_process p);
void vm_zjmp_print(t_process p);

int vm_valid_arg(char *arg);
int vm_valid_arg(char *arg, t_vm *vm);
int vm_valid_verbosity_lvl(int lvl);
int vm_lvl_to_index(int index);
int ft_isnumber(char *str);
Expand Down
29 changes: 21 additions & 8 deletions src/ft_vm/vm_helper_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,42 @@
/* ::: :::::::: */
/* vm_helper_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rnugroho <rnugroho@student.42.fr> +#+ +:+ +#+ */
/* By: fpetras <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/20 14:58:02 by fpetras #+# #+# */
/* Updated: 2018/04/25 02:59:45 by rnugroho ### ########.fr */
/* Updated: 2018/04/25 07:59:18 by fpetras ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_vm.h"

int vm_valid_arg(char *arg)
int vm_valid_arg(char *arg, t_vm *vm)
{
if (!ft_strcmp(arg, "-dump") || !ft_strcmp(arg, "-v") ||
!ft_strcmp(arg, "-n"))
return (1);
{
if (!ft_strcmp(arg, "-dump"))
return (vm->valid_arg[0] = 1);
else
return (vm->valid_arg[1] = 1);
}
else if ((!ft_strncmp(arg, "-v", 2) || !ft_strncmp(arg, "-n", 2)) &&
ft_isnumber(&arg[2]))
{
return (vm->valid_arg[1] = 1);
}
else if (ft_isnumber(arg) && (vm->valid_arg[0] || vm->valid_arg[1]))
{
vm->valid_arg[0] = 0;
return (1);
else if (ft_isnumber(arg))
return (1);
}
else if (!ft_strcmp(&arg[ft_strlen(arg) - 4], ".cor"))
{
vm->valid_arg[0] = 0;
vm->valid_arg[1] = 0;
return (1);
else
return (0);
}
return (0);
}

int vm_valid_verbosity_lvl(int v)
Expand Down
8 changes: 4 additions & 4 deletions src/ft_vm/vm_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* vm_options.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rnugroho <rnugroho@student.42.fr> +#+ +:+ +#+ */
/* By: fpetras <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/20 15:11:44 by fpetras #+# #+# */
/* Updated: 2018/04/25 00:55:49 by rnugroho ### ########.fr */
/* Updated: 2018/04/25 07:33:21 by fpetras ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -120,6 +120,8 @@ int vm_options(char **av, t_vm *vm)
i = 0;
while (av[++i])
{
if (!vm_valid_arg(av[i], vm))
return (-1);
if (!ft_strcmp(av[i], "-dump"))
{
if ((vm->dump = ft_atoi(av[i + 1])) <= 0)
Expand All @@ -129,8 +131,6 @@ int vm_options(char **av, t_vm *vm)
return (-1);
else if (vm_option_v(i, av, vm) == -1)
return (-1);
if (!vm_valid_arg(av[i]))
return (-1);
}
return (0);
}

0 comments on commit 6d7fb8a

Please sign in to comment.