int			load_scene_open_beg_bis(t_prog *prog, char **file,
						char *get)
{
  if ((get = get_field(file, "scene:view:background")) == NULL)
    return (my_printf(2, "Could not find scene:view:background\n") - 1);
  if ((prog->background_path = malloc(my_strlen(get) + 1)) == NULL)
    return (-1);
  prog->background_path[0] = '\0';
  prog->background_path = my_strcat(prog->background_path, get);
        if (my_strcmp(get, "NULL") == 0)
    {
      if ((prog->background = create_text_uni(prog->win_size.x,
						    prog->win_size.x,
						    0xff000000)) == NULL)
	return (-1);
    }
  else
    {
      if ((prog->background = load_image(get)) == NULL)
	return (-1);
      place_into_hitbox(prog->background, prog->background,
			      create_hitbox(0, 0, prog->win_size.x,
				      prog->win_size.y));
    }
  free(get);
  return (0);
}
Beispiel #2
0
char	*get_varenv(char **env, char *str)
{
  char	*var;
  int	i;
  int	j;
  int	length;

  i = -1;
  if (env == NULL || env[0] == NULL)
    return (NULL);
  while (env[++i] != NULL && !my_strcmp(str, env[i]));
  if (env[i] == NULL)
    return (NULL);
  j = 0;
  while (env[i][j] != '=')
    ++j;
  ++j;
  length = -1;
  length = my_strlen(env[i]) - j;
  if ((var = malloc(sizeof(char) * (length + 1))) == NULL)
    return (NULL);
  var[length] = 0;
  length = -1;
  --j;
  while (env[i][++j])
    var[++length] = env[i][j];
  return (var);
}
Beispiel #3
0
int		echo(t_plist *plist, char **tab, char **env)
{
  int		j;
  int		i;
  t_list	*list;

  list = plist->begin;
  i = 1;
  j = 0;
  if (tab[i] && ((my_strcmp("-n", tab[i])) == 0))
    echo_n(tab);
  else if (tab[i] && (tab[i][0] == '$'))
    echo_valuenv(tab, list);
  else
    {
      while (tab[i])
	{
	  if (check_quote(tab, env) == -1)
	    return (error_quote());
	  custom_putstr(tab, i, j);
	  i++;
	  j = 0;
	}
      my_putchar('\n');
    }
  return (0);
}
Beispiel #4
0
int			is_built_in_child(char **lexed, char ***env,\
					  t_redir *redir)
{
  char			*name[3];
  int			(*func[3])(char ***env, char **lexed);
  int			i;
  int			ret;

  name[0] = "history";
  name[1] = "echo";
  name[2] = NULL;
  func[0] = aff_history;
  func[1] = my_echo;
  func[2] = NULL;
  i = -1;
  while (name[++i])
  {
    if (my_strcmp(lexed[0], name[i]) == 0)
    {
      ret = execute_builtin(func[i], lexed, env, redir);
      return (ret);
    }
  }
  return (1);
}
Beispiel #5
0
static int	my_set_var(t_object *object, char *str, int i)
{
  if (i == 0)
    my_position_x(object, my_getnbr(str));
  else if (i == 1)
    my_position_y(object, my_getnbr(str));
  else if (i == 2)
    my_position_z(object, my_getnbr(str));
  else if (i == 3)
    my_rotation_x(object, my_getnbr(str));
  else if (i == 4)
    my_rotation_y(object, my_getnbr(str));
  else if (i == 5)
    my_rotation_z(object, my_getnbr(str));
  else if (i == 6)
    {
      object->rayon = my_getnbr(str);
      if (my_strcmp(object->name, "cone") == 0)
	object->rayon = tan(object->rayon * MY_PI / 180);
    }
  else if (i == 7)
    object->color.color = my_getnbr_base(str, "0123456789ABCDEF");
  else
    return (-1);
  return (i);
}
int main()
{
	char a[10000],b[10000];
	while(scanf("%s%s",a,b))
		printf("%d\n",my_strcmp(a,b));
	return 0;
}
Beispiel #7
0
int     do_it3(t_cmd_labels *cmd_tmp, int fd, t_labels *list, int pos)
{
  int   i;
  int   o;
  int   pos_tmp;

  o = 0;
  pos_tmp = pos - 1;
  if (cmd_tmp->params[1] != NULL)
    pos_tmp = pos - 2;
  if (my_strcmp(cmd_tmp->cmd, "zjmp") == 0)
    o = 42;
  i = 0;
  while (cmd_tmp->params[i] != NULL)
    {
      o = do_it3_o(cmd_tmp, i, o);
      if (cmd_tmp->params[i][0] == 'r')
        pos = pos + assembleur(my_getnbr_final(&cmd_tmp->params[i][1]), 1, fd);
      else if (cmd_tmp->params[i][0] == '%' && cmd_tmp->params[i][1] != ':' &&
               o == 0 && cmd_tmp->params[i][1] != '-')
        pos = print_param1(cmd_tmp, fd, pos, i);
      else
	pos = aff_res(pos, calc_modul(cmd_tmp, pos_tmp, list, i), fd);
      o = do_it3_o2(cmd_tmp, o, i);
      i++;
    }
  return (pos);
}
int		check_case(char *cmd, char *to_find, int pos)
{
  char		*s;
  char		**tabstr;
  int		i;

  i = 0;
  s = del_bn_2(my_strdup(cmd));
  if (s[1] == ',')
    {
      free(s);
      return (0);
    }
  tabstr = my_str_sep(s + 1, ",");
  if (check_error(tabstr, pos, s) == -1 && pos > 0)
    return (-1);
  if (check_error(tabstr, pos, s) == 0 && pos > 0)
    return (0);
  tabstr = do_str_sep(tabstr, s, pos);
  while (tabstr && tabstr[i])
    if (my_strcmp(tabstr[i++], to_find) == 0)
      {
	xfree_n(tabstr, s, (void *) -1);
	return (1);
      }
  xfree_n(tabstr, s, (void *) -1);
  return (0);
}
int		check_inventaire(char *cmd, char *to_find, int nbr)
{
  char		*s;
  char		**tabstr;
  int		i;
  int		nb;
  char		**params;

  if (nbr == 0)
    return (1);
  i = 0;
  s = del_bn_2(my_strdup(cmd));
  tabstr = my_str_sep(s + 1, ",");
  if (tabstr)
    while (tabstr[i])
      {
	params = my_str_sep(tabstr[i], " ");
	nb = my_atoi(params[1]);
	if (my_strcmp(tabstr[i++], to_find) == 0 && nb >= nbr)
	  {
	    xfree_n(tabstr, params, s,(void *) -1);
	    return (1);
	  }
	free(params);
      }
  xfree_n(tabstr, s, (void *) -1);
  return (0);
}
Beispiel #10
0
/*
 * getout()
 *
 * Quit the program
 *
 * Precondition: input is not null
 * Postcondition: Program exits
 *
 * @param char* input The input character
 */
void    getout(char* input)
{
    int count;

    if(input != NULL)
    {
        if(!my_strcmp(input, "\n"))
        {
            restore_terminal();
            for(count = 0; count < gl_env.nbelems; count++)
            {
                if(gl_env.elements[count].mode)
                {
                    my_str(gl_env.elements[count].elem);
                    my_str(" ");
                }
            }
            my_char('\n');
            exit(0);
        }
        else if(!my_strcmp(input, "\E"))
        {
            restore_terminal();
            exit(0);
        }
    }
}
int special_strcmp(const char* str1, const char* str2, int fold[MAX_FIELDS], int directory[MAX_FIELDS]) {
    printf("special strcmp\n");
    char buffer1[MAX_LEN+1];
    char buffer2[MAX_LEN+1];
    int pos1, pos2;
    int result;

    pos1 = pos2 = 0;
    for (int i=0; i<MAX_FIELDS; i++) {
        while (str1[pos1] && str1[pos1] != '%') {
            buffer1[pos1] = str1[pos1];
            pos1++;
        }
        buffer1[pos1] = '\0';
        while (str2[pos2] && str2[pos2] != '%') {
            buffer2[pos2] = str2[pos2];
            pos2++;
        }
        buffer2[pos2] = '\0';
        result = my_strcmp(buffer1, buffer2, fold[i], directory[i]);
        if (result != 0) {
            return result;
        } else if (!str1[pos1] && str2[pos2]) {
            return -1;
        } else if (str1[pos1] && !str2[pos2]) {
            return 1;
        } else if (!str1[pos1] && !str2[pos2]) {
            return 0;
        }
        pos1++;
        pos2++;
    }
    return 0;
}
Beispiel #12
0
bool is_or_node(t_node* node)
{
	if(my_strcmp(node->type,"or") == 0)
		return true;
	else 
		return false;
}
Beispiel #13
0
void				connection()
{
	extern t_client		t;
	struct sockaddr_in	sin;

	t.s = socket(PF_INET, SOCK_STREAM, 0);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(t.port);
	sin.sin_addr.s_addr = inet_addr(t.adresse);
	connect(t.s, (struct sockaddr *)&sin, sizeof (sin));
	t.buf = malloc(4096 * sizeof(*t.buf));
	t.size = recv(t.s, t.buf, 256, 0);
	t.buf[t.size] = '\0';
	if (my_strcmp(t.buf, "BIENVENUE\n") == 0)
	{
		my_putstr("BIENVENUE\n");
		t.equipe = my_strcat(t.equipe, "\n");
		send(t.s, t.equipe, my_strlen(t.equipe), 0);
		t.size = recv(t.s, t.buf, 256, 0);
		t.buf[t.size] = '\0';
		if (my_getnbr(t.buf) >= 1)
		{
			my_putstr(t.buf);
			send(t.s, "msz\n", 4, 0);
			t.size = recv(t.s, t.buf, 256, 0);
			t.buf[t.size] = '\0';
			my_putstr(t.buf);
			t.continuer = 1;
			t.level = 1;
			while (t.continuer)
				ia_drone();
		}
	}
	close(t.s);
}
Beispiel #14
0
int			check_piece(char		*str)
{
  int			i;
  int			i2;

  if (my_strcmp(str, ".") == 0 || my_strcmp(str, "..") == 0)
    return (1);
  if ((i = my_strstr_end(str, ".tetrimino")) == -1)
    return (1);
  i2 = i;
  while (str[i2] != '\0')
    i2++;
  if (i + 10 != i2)
    return (1);
  return (0);
}
Beispiel #15
0
void	exec(t_env *envp, char *buffer)
{
  char	**tab;
  char	*link;
  char	**path;
  int	i;

  tab = my_str_to_wordtab(buffer);
  while (envp != NULL && my_strcmp(envp->name, "PATH") != 0)
    envp = envp->next;
  if (envp != NULL)
    {
      path = my_wordtab(envp->content);
      i = 0;
      while (tab[0] != NULL && path != NULL && path[i] != NULL)
	{
	  link = link_cat(tab[0], path[i]);
	  access(link, X_OK) == 0 ? execve(link, tab, environ) : i++;
	  free(link);
	}
    }
  if (tab[0] != NULL)
    access(tab[0], X_OK) == 0 ? execve(tab[0], tab, environ) : i++;
  if (tab[0] != NULL)
    my_printf("[%s] : command not found\n", tab[0]);
  make_free(&tab, &path);
}
Beispiel #16
0
int     check_null(char **args)
{
  int   i;

  i = 0;
  while (args[i] && my_strlen(args[i]) > 0 && args[i][0] == '-')
    {
      if (my_strcmp(args[i], "-0") == 0 || my_strcmp(args[i], "--null") == 0)
        {
          fprintf(stderr, "%s%s%s", CANNOT_NULL1, CANNOT_NULL2, CANNOT_NULL3);
          return (EXIT_FAILURE);
        }
      i++;
    }
  return (EXIT_SUCCESS);
}
Beispiel #17
0
int	my_print_sympa(char *str, int time)
{
  int	i;
  int	len;
  int	done;
  char	*moving;

  i = 0;
  len = my_strlen(str);
  done = 0;
  moving = my_initialize_str(str);
  while (!done)
    {
      my_putstr(moving);
      i = 0;
      while (i < len)
	{
	  if (moving[i] != str[i])
	    moving[i] = (moving[i] == '~') ? ' ' : moving[i] + 1;
	  i = i + 1;
	}
      if (my_strcmp(str, moving) == 0)
	done = 1;
      my_putchar('\r');
      usleep(time);
    }
  my_putstr(moving);
}
Beispiel #18
0
unsigned char NtxHwCfg_FldStrVal2Val(int iFldIdx,char *szFldStrVal)
{
	int iTotalVals;
	int i;
	unsigned char bRet = 0xff;
	
	if(iFldIdx>=_TOTOAL_HWCONFIG_FIELDS) {
		return 0xff;
	}
	if(gtHwConfigFields[iFldIdx].wFieldType != FIELD_TYPE_IDXSTR) {
		return 0xff;
	}
	iTotalVals = gtHwConfigFields[iFldIdx].iFieldValueCnt;
	ASSERT(iTotalVals<255);
	for(i=0;i<iTotalVals;i++) 
	{
		if(0==my_strcmp(gtHwConfigFields[iFldIdx].szFieldValueA[i],szFldStrVal)) 
		{
			bRet = (unsigned char)i;
			break;
		}
	}
	
	return bRet;
	
}
Beispiel #19
0
/*
**		chdir HOME / chdir OLDPWD for cd ~ or cd -
*/
char		*my_cd_options(char **env, char *arg)
{
  char		*var;
  char		*home;

  var = "HOME";
  if (arg && arg[0] == '-')
    var = "OLDPWD";
  if (*env == NULL || (home = my_find_in_env(env, var)) == NULL)
    {
      msg_error("mysh: cd: ");
      msg_error(var);
      msg_error(" not set.\n");
      return (NULL + 1);
    }
  if ((home = my_strdup(home)) == NULL)
    return (NULL);
  if (my_strcmp(var, "HOME"))
    {
      my_putstr(home);
      my_putchar('\n');
    }
  if (chdir(home) == FAILURE && my_perror(home, 0))
    return (NULL + 1);
  return (home);
}
Beispiel #20
0
int main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    char *ret;
    int ctr;
    int fail;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strncpy() function");
    CYG_TEST_INFO("This testcase tests robustness, and may take some time");

    fail = 0;
    for (ctr = 0; ctr < NUM_ROBUSTNESS_RUNS; ctr++) {
        my_strcpy(x, "Green plastic watering can, ");
        my_strcpy(y, "for her fake Chineese rubber plant");
        ret = strncpy(x, y, my_strlen(y)+1);
        if ( (my_strcmp(x, "for her fake Chineese rubber plant") != 0) ||
             ( ret != x ) )
        {
            fail = 1;
            break;
        } // if
    } // for
    CYG_TEST_PASS_FAIL( (fail == 0), "Robustness test" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strncpy() function");
} // main()
Beispiel #21
0
static int file_cmp( const char *f1, const char *f2 )
{
  int is_sjis = FALSE;
  int c;

  if( f1 == NULL || f2 == NULL ) return FALSE;
  if( f1 == f2 ) return TRUE;

  while( (c = (int)*f1) ){

    if( is_sjis ){				/* シフトJISの2バイト目	*/
      if( *f1 != *f2 ) return FALSE;
      is_sjis = FALSE;
    }
    else if( (c >= 0x81 && c <= 0x9f) ||	/* シフトJISの1バイト目 */
	     (c >= 0xe0 && c <= 0xfc) ){
      if( *f1 != *f2 ) return FALSE;
      is_sjis = TRUE;
    }
    else{					/* 英数字半角カナ文字	*/
      if( my_strcmp( f1, f2 ) != 0 ) return FALSE;
    }

    f1 ++;
    f2 ++;
  }

  if( *f2 == '\0' ) return TRUE;
  else              return FALSE;
}
Beispiel #22
0
/*
** brief: get all the parameters for the virtual machine
** @argc: number of arguments pass to the program
** @argv: each arguments pass to the program
** @corewar: our structure for the virtual machine
** return: {0 if succeed} {1 if error during parsing}
*/
static unsigned int	my_get_params(int argc, char **argv, t_corewar *corewar)
{
  t_champion		*champion;
  int			i;

  i = 1;
  if (!my_strcmp(argv[i], "-dump"))
    {
      if (i + 1 >= argc || my_str_isnum(argv[i + 1]) ||
	  (corewar->dump = my_getnbr(argv[i + 1])) < 0)
	return (my_fprintf(2, "Dump must have a positive number.\n"));
      i += 2;
    }
  else
    corewar->dump = -1;
  while (i < argc)
    {
      if (!(champion = my_malloc(sizeof(*champion))))
	return (my_fprintf(2, "At my_get_params : Malloc failed.\n"));
      if (my_champion(argc, argv, &i, champion))
	return (1);
      if (my_order_champion(corewar, champion))
	return (1);
    }
  return (0);
}
Beispiel #23
0
int		my_unsetenv(char **args)
{
  t_env		*parse;
  t_env		*begin;
  int		count;

  begin = gl_st.st_env;
  count = 1;
  if (my_tablen(args) < 2)
    {
      fprintf(stderr, "unsetenv: Too few arguments.\n");
      return (EXIT_FAILURE);
    }
  else if (begin)
    while ((begin) && (args[count]))
      {
	parse = begin;
	while ((parse) && my_strcmp(parse->var, args[count]) != '=')
	  parse = parse->next;
	if (parse)
	  _unset_elem(&begin, parse);
	count++;
      }
  gl_st.st_env = begin;
  return (EXIT_SUCCESS);
}
Beispiel #24
0
void	my_cd2(t_lnv *env, char *path, char *npath, char *pwd)
{
  if (env == NULL)
    return;
  pwd = get_value(env, "PWD");
  if (path == NULL)
    npath = get_value(env, "HOME");
  else if (pwd == NULL)
    npath = my_strdup(path);
  else if (!my_strcmp("-", path) && get_value(env, "OLDPWD") != NULL)
    {
      npath = get_value(env, "OLDPWD");
      set_value(env, "OLDPWD", pwd);
    }
  else
    {
      npath = "";
      set_oldpwd(env, &pwd, &path, &npath);
    }
  if (npath)
    {
      set_value(env, "PWD", npath);
      chdir(npath);
    }
  gbgc_free(NULL, npath);
}
Beispiel #25
0
int	my_print_flag(int fd, char *str_flag, va_list *ap)
{
  int	i;
  int	ret;

  i = 0;
  ret = 0;
  if (str_flag[0] == '%')
    my_fdputchar(fd, '%');
  else
    {
      while ((g_interf + i)->flag && ret == 0)
	{
	  if (my_strcmp((g_interf + i)->flag, str_flag) == 0)
	    ret = (g_interf + i)->print(fd, ap);
	  i += 1;
	}
      if (ret == 0)
	{
	  my_putchar('%');
	  my_putstr(str_flag);
	}
    }
  return (ret);
}
Beispiel #26
0
t_xtree	*xml_find_in_tree(t_xtree *tree, char *find)
{
  char	**tab;
  int	i;
  t_xtree	*tmp;
  t_xtree	*tmp2;

  tab = my_strtok(find, "/ \n\t", TOK_DELIM);
  i = 0;
  tmp = NULL;
  while (tree && tab && tab[i])
    {
      if (tmp == NULL)
	tmp = tree;
      tmp2 = tmp;
      tmp = NULL;
      while (tmp2 && !tmp)
	{
	  if (!tab[i + 1] && my_strcmp(tmp2->name, tab[i]) == 0)
	    {
	      my_free_tab(tab);
	      return (tmp2);
	    }
	  tmp = xml_find_one_node(tmp2->sun, tab[i]);
	  if (tmp == NULL)
	    tmp2 = tmp2->next;
	}
      i++;
    }
  my_free_tab(tab);
  return (tmp);
}
Beispiel #27
0
int		mode_passif(t_link *link, char **av, char **env)
{
  char		**cmd;
  char		**cmd_two;

  if (av[1] == NULL)
    return (FALSE);
  if (av[2] == NULL)
    {
      my_printf("Mode_passif : ./42sh -c string\n");
      return (FALSE);
    }
  else if (my_strcmp(av[1], "-c") == 0)
    {
      cmd = edit_command(link, my_epur_str(av[2]));
      cmd_two = my_explode(my_epur_str(av[2]), ' ');
      if (cmd == NULL)
	my_printf("%s : command not found\n", av[2]);
      else if (access(cmd_two[0], X_OK) == 0 && is_exec(cmd_two[0]))
	my_printf("%s : command not found\n", av[2]);
      else
	execve(cmd[0], cmd, env);
      my_printf("%s : command not found\n", av[2]);
      return (TRUE);
    }
  my_printf("Mode_passif : ./42sh -c string\n");
  return (FALSE);
}
Beispiel #28
0
void		find_champ(t_dlist *list,
			   t_vm *vm,
			   unsigned char *board,
			   int i)
{
  t_list	*tmp;
  t_lcmd	*info;
  t_champ	*new_elem;
  int		j;

  tmp = inifind(list, &j);
  new_elem = xmalloc(sizeof(t_champ));
  while (tmp)
    {
      if (my_strcmp(&tmp->arg[my_strlen(tmp->arg) - 4], ".cor") == 0)
	{
	  info = xmalloc(sizeof(t_lcmd));
	  info->p = j++;
	  info_champ(list, i, info, tmp->arg);
	  if (create_champ(new_elem, info, board) == -1)
	    exit(0);
	  i = 0;
	  add_list_end_vm(vm, new_elem);
	  pop_list_begin(list);
	  tmp = list->begin;
	}
      else
	tmp = tmp->next;
      i++;
    }
}
Beispiel #29
0
t_pars		*my_pars(t_struct *struc, char ***env, t_pars *pars)
{
  int	pid;

  if (*env == NULL)
    return (error_env(pars));
  if ((my_pars_check(pars, struc)) == 1)
    {
      pars->last_op = struc->operateur;
      pars->tab = my_str_to_wordtab(struc->instruction);
      if ((my_echo_check(pars, struc, *env, pid)) == NULL)
	return (pars);
      pars = my_echo_check(pars, struc, *env, pid);
      pars = my_path_remp(struc, *env, pars, 0);
      if (my_strcmp(pars->tab[0], "cd") == 0)
	env = my_cd(pars->tab, env);
      else if (pars->path != NULL)
	{
	  pid = fork();
	  if (pid == 0)
	    pars = pars_norme(struc, pars, env);
	  wait(&pid);
	}
      else
	pars = error_execve(struc->instruction, pars);
    }
  return (pars);
}
Beispiel #30
0
int toto()
{
  char	toto[] = "Coucou Ca Va ?";
  char	test[20];
  char	dest[7];

  printf("sa marche ? toto fait %d char\n", my_strlen("toto"));
  my_memcpy(dest, toto, 14);
  dest[14] = 0;
  printf("dest = [%s]\n", dest);
  printf("strchr = [%s]\n", my_strchr(toto, 'a'));
  printf("strcmp toto, dest = %d\n", my_strcmp(toto + 1, dest));
  dest[3] = 'a';
  printf("strncmp toto, dest = %d\n", my_strncmp(toto, dest, 3));
  my_bzero(toto, 5);
  printf("bzero = [%s]\n", toto + 5);
  printf("strcasecmp = %d\n", strcasecmp("SALUT", "123456"));
  my_write(1, "test\n", 5);
  printf("rindex my toto with the char 'a' : [%s]\n",
  	 my_rindex("caca coco coucou", 'i'));
  test[14] = 0;
  printf("apres le memset = [%s]\n", my_memset(test, 'A', 14));
  strcpy(dest, "Coucou");
  printf("memmove result = [%s]\n", memmove(dest, dest + 1, 20));
  printf("dest = [%s]\n", dest);
}