int is_error_in_args(int argc, char **argv) { int i; i = 1; if (argc < 2) return (-1); while (i < argc) { if (is_options(argv[i])) { if ((is_numbers(argv[i + 1])) == -1 && my_strcmp(argv[i], "-d") != 0) return (-1); i += 2; } else { if (is_file_dot_cor(argv[i]) == -1) return (-1); i += 1; } } if (is_one_file_cor(argc, argv) == -1) return (-1); return (0); }
t_getopt ft_getopt(int ac, char **av, const char *opt_str) { static t_getopt opt = {0, 1, 0, 0, NULL}; static char *opt_ptr = NULL; static int *elem_ind = NULL; if (elem_ind == NULL) { if ((elem_ind = (int *)malloc(ac * sizeof(int))) == NULL) exit(1); ft_memset(elem_ind, 0, ac * sizeof(int)); } opt.arg = NULL; opt.is_arg = 0; while (opt.ind < ac && !is_options(&opt, &opt_ptr, av, opt_str)) { elem_ind[opt.ind++] = 1; opt_ptr = NULL; } if (opt.ind >= ac) { opt.ret = -1; sort_opt(ac, av, elem_ind, &opt); return (opt); } get_opt(&opt, &opt_ptr, ac, av); return (opt); }
options get_global_options(lua_State * L) { lua_pushlightuserdata(L, static_cast<void *>(&g_options_key)); lua_gettable(L, LUA_REGISTRYINDEX); options r; if (is_options(L, -1)) r = to_options(L, -1); lua_pop(L, 1); return r; }
int opt_name_team(t_info *info, char **argv, int i) { t_team *team; int flag; while (pop_list(&info->team)); flag = 0; while (argv[i] && (is_options(argv[i]) == -1)) { flag = 1; team = xmalloc(sizeof(*team)); team->name = argv[i]; team->nb = 0; team->max = info->nb_player; push_list(&info->team, team); i++; } return (flag == 1 ? i : -1); }
void parse_args(int argc, char **argv, t_info *info) { int flag; int idx; int i; fill_default_info(info); i = 1; flag = 0; while (i < argc) { if (((idx = is_options(argv[i])) != -1) && argv[++i]) { flag |= gl_opt_srv[idx].opt; i = gl_opt_srv[idx].fun(info, argv, i); if (i == -1) usage_server(); } else usage_server(); } /* if (!check_flag(flag)) */ /* usage_server(); */ }