Ejemplo n.º 1
0
/*
 * Describe an object's activation, if any.
 */
static bool describe_activation(const object_type *o_ptr, u32b f3)
{
	/* Check for the activation flag */
	if (f3 & TR3_ACTIVATE)
	{
		char act_desc[120];

		u16b size;

		my_strcpy(act_desc, "It activates for ", sizeof(act_desc));

		/*get the size of the file*/
		size = strlen(act_desc);

		describe_item_activation(o_ptr, act_desc, sizeof(act_desc));

		/*if the previous function added length, we have an activation, so print it out*/
		if (strlen(act_desc) > size)
		{

			my_strcat(act_desc, format(".  "), sizeof(act_desc));

			/*print it out*/
			p_text_out(act_desc);

			return (TRUE);
		}
	}

	/* No activation */
	return (FALSE);
}
Ejemplo n.º 2
0
static void	proc_status(t_proc *proc, char *path, t_task *task)
{
  t_pars	*cast;
  int		fd;
  struct passwd	*pss_wd;

  if ((fd = open(path, O_RDONLY)) == -1)
    return ;
  close(fd);
  path = my_strcat(path, "/status");
  if (list_parsing(path, ' ', task->pars->next))
    return ;
  cast = task->pars->next->data;
  proc->command = my_strdup(cast->wordtab[1]);
  cast = task->pars->next->next->data;
  proc->status = cast->wordtab[1][0];
  cast = task->pars->next->next->next->data;
  if (cast && (pss_wd = getpwuid(atoi(cast->wordtab[1]))))
    {
      free(proc->user);
      proc->user = NULL;
      proc->user = my_strdup(pss_wd->pw_name);
    }
  free(path);
  delete_pars(task->pars);
}
Ejemplo n.º 3
0
char		*recursive_execve(char **path, char **command, char **tabenv, int i)
{
  char		*filename;

  filename = NULL;
  if (!test_file('.', '/', command))
    {
      if (((filename = command[0]) && (access(command[0], R_OK | X_OK) == -1))
	  || (execve(filename, command, tabenv) == -1))
	return ("Permissions denied.");
    }
  else if (command[0][0] != '/')
    filename = my_strcat(path[i++], command[0], 1);
  else if (!test_file(' ', '/', command))
    if (((filename = command[0]) && (access(command[0], R_OK | X_OK) == -1))
	|| (execve(filename, command, tabenv) == -1))
      return ("Permissions denied.");
  if (filename != NULL)
    {
      execve(filename, command, tabenv);
      recursive_execve(path, command, tabenv, i);
    }
  else
    return (NULL);
  return (0);
}
Ejemplo n.º 4
0
int		my_cd(char *str, t_struct *pile)
{
  struct stat	s;
  int		n;
  char		*tmp;

  n = 0;
  tmp = NULL;
  if ((str != NULL) && (*str == 0))
    str = my_aff_param_list(pile->my_env, HOME);
  if (str == NULL)
    str = my_strdup(pile->home);
  if ((str != NULL) && (str[0] != '/') && (str[0] != '-') && str[0] != '.')
    tmp = my_strcat("./", str);
  else if (str != NULL)
    tmp = my_strdup(str);
  if ((str != NULL) && (str[0] != '-') && (stat(tmp, &s) < 0))
    {
      msg_error(str, NO_FILE_DIR, pile);
      return (0);
    }
  if ((str != NULL) && ((str[0] == '-') || (check_perm(s, tmp) == 0)))
    find_cd(tmp, pile);
  else
    msg_error(str, ": Permission denied\n", pile);
  cd_check(tmp);
  return (0);
}
Ejemplo n.º 5
0
int main(void)
{
	char * A = "Hello!";
	char * B = "Hello from Chicago";
	char * C = " Excellent. Perfect.";

	char result[1024] = "Hi ";

	printf("Test 1: ");
	printf("%s\n", my_strcat(result, A));
	   
	   printf("Test 2: ");
	   printf("%s\n", my_strncpy(result, B, 2));

	   printf("Test 3: ");
	   printf("%s\n", my_strncpy(result, B, 100));

	   printf("Test 4: ");
	   printf("%s\n", my_strncat(result, C, 10));

	   printf("Test 5: ");
	   printf("%d\n", my_strncmp(A, B, 5));

	   printf("Test 6: ");
	   printf("%d\n", my_strncmp(A, B, 10));

	return 0;
}
Ejemplo n.º 6
0
void	pause_vm(t_vm *vm, int deb)
{
  int	run;
  SDL_Event	event;
  SDL_Surface	*texte;
  SDL_Color	color;
  SDL_Rect	pos;
  char		buff[4096];

  color.r = 255;
  color.g = 255;
  color.b = 255;
  run = 1;
  while (run)
  {
    if (deb != 0)
      SDL_FillRect(vm->screen, NULL, SDL_MapRGB(vm->screen->format, 0, 0, 0));
    my_strcpy(buff, "Appuyer sur une touche pour ");
    my_strcat(buff, deb != 0 ? "commencer" : "terminer");
    if ((texte = TTF_RenderText_Solid(vm->police, buff, color)) == NULL)
      err_TTF();
    pos.x = vm->screen->w / 2 - texte->w / 2;
    pos.y = vm->screen->h / 2 - texte->h / 2;
    SDL_BlitSurface(texte, NULL, vm->screen, &pos);
    SDL_FreeSurface(texte);
    SDL_Flip(vm->screen);
    SDL_WaitEvent(&event);
    if (event.type == SDL_KEYDOWN)
      run = 0;
  }
}
Ejemplo n.º 7
0
Archivo: delete.c Proyecto: kokaz/42sh
char	*my_back_space(int buf, char *str, t_line *line)
{
  char	*cpy;

  if (!line->rk)
    return (str);
  if (!str[line->rk])
    {
      str[line->rk - 1] = 0;
      my_left(buf, str, line);
      write(line->fd, " ", 1);
      go_left();
      if (line->x == line->win_x - 1)
	go_right();
      return (str);
    }
  my_left(buf, str, line);
  if ((cpy = strdup(&str[line->rk + 1])) == NULL)
    return (NULL);
  write(line->fd, &str[line->rk + 1], strlen(&str[line->rk]));
  str[line->rk] = 0;
  if ((cpy = my_strcat(str, cpy)) == NULL)
    return (NULL);
  recup_position(cpy, line, str, 0);
  return (cpy);
}
Ejemplo n.º 8
0
int	main()
{
  char	*s;
  char	*get;
  int	i;
  int	repeat;

  if ((s = malloc(sizeof(char) * (1))) == NULL)
    return (-1);
  s[0] = '\0';
  while ((get = get_next_line(0)) != NULL)
    {
      s = my_strcat(s, get);
      free(get);
    }
  i = 0;
  repeat = strlen(s) / 220;
  if (check_error_format(s, repeat) == -1)
    return (-1);
  while (repeat > 0)
    {
      resolve_sudo(s, (220 * i));
      i++;
      repeat--;
    }
  free(s);
  return (0);
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    char in[40], out[40], *ptr;
    int len;
    
    printf("Input a short string\n");
    scanf("%39s", in);

    printf("Input another string\n");
    scanf("%39s", out);

    printf("You typed %s \n", in);
    printf("And %s \n", out);

    len = my_strlen ( in );
    printf("'In' is %d characters long\n", len);

    len = my_strlen ( out );
    printf("'Out' is %d characters long\n", len);

    ptr = my_strcat ( out, in );

    printf("%s\n\n", ptr);

    printf("Hit enter to quit\n");
    getchar();
    return 0;
}
Ejemplo n.º 10
0
static FLAG	match_end(t_get **words, char **bad_sintax)
{
  FLAG	r;
  t_get *link;

  link = *words;
  if (match_these(link->word))
    {
      *bad_sintax = my_strcat(WRONG_SEP_TOKEN, link->word);
      return (FALSE);
    }
  while (link)
    {
      if (lvl_parents(&link, bad_sintax) == FALSE)
	return (FALSE);
      *words = link;
      if (!link)
	return (NONE);
      if ((r = match_these(link->word)))
	return (r);
      link = link->next;
      *words = link;
    }
  return (NONE);
}
Ejemplo n.º 11
0
/**
 * Get the integer argument from a value expression and the index in the
 * value_type array of the suffix used to build the value string
 * \param value the integer value
 * \param index the information on where to put it (eg array index)
 * \param value_type the variable suffix of the possible value strings
 * \param prefix the constant prefix of the possible value strings
 * \param name_and_value the value expression being matched
 * \return 0 if successful, otherwise an error value
 */
errr grab_index_and_int(int *value, int *index, const char **value_type,
						const char *prefix, const char *name_and_value)
{
	int i;
	char value_name[80];
	char value_string[80];

	/* Get a rewritable string */
	my_strcpy(value_name, name_and_value, strlen(name_and_value));

	/* Parse the value expression */
	if (!find_value_arg(value_name, NULL, value))
		return PARSE_ERROR_INVALID_VALUE;

	/* Compose the value string and look for it */
	for (i = 0; value_type[i]; i++) {
		my_strcpy(value_string, prefix, sizeof(value_string));
		my_strcat(value_string, value_type[i],
				  sizeof(value_string) - strlen(value_string));
		if (streq(value_string, value_name)) break;
	}

	if (value_type[i])
		*index = i;

	return value_type[i] ? PARSE_ERROR_NONE : PARSE_ERROR_INTERNAL;
}
Ejemplo n.º 12
0
void            ajust_links_columns(t_list *list, t_list *ptr, char *tmp, int links)
{
  int           i;

  ptr = list;
  while (ptr != NULL)
    {
      i = 0;
      if (my_strlen(ptr->link) < links)
        {
          if ((tmp = malloc(sizeof(*tmp) * links + 1)) == NULL)
	    exit(-1);
          while (i < links - my_strlen(ptr->link))
            {
              tmp[i] = ' ';
              i = i + 1;
            }
          tmp[i] = '\0';
          my_strcat(tmp, ptr->link);
          free(ptr->link);
          ptr->link = my_strdup(tmp);
          free(tmp);
        }
      ptr = ptr->next;
    }
}
Ejemplo n.º 13
0
int		my_recursive(t_opt t, char *root)
{
  DIR		*d;
  struct dirent	*e;
  struct stat	s;
  char		*file;

  if ((d = catch_error(root)) == NULL)
    return (1);
  my_printf("\033[32m%s:\033[0m\n", root);
  (t.l || t.g) ? list_column_dir(root, &t) : list_simple_dir(root);
  while ((e = readdir(d)))
    {
      file = format_dir(root, e->d_name);
      if ((stat(file, &s)) == -1)
	{
	  closedir(d);
	  perror("stat");
	  return (1);
	}
      (IS_DIR_OK) ? file = my_strcat(file, "/") : 0;
      (IS_DIR_OK) ? my_recursive(t, file) : 0;
      free(file);
    }
  closedir(d);
  return (0);
}
Ejemplo n.º 14
0
void            ajust_size_columns(t_list *list, t_list *ptr, char *tmp, int size)
{
  int           i;

  ptr = list;
  while (ptr != NULL)
    {
      i = 0;
      if (my_strlen(ptr->size) < size)
        {
          if ((tmp = malloc(sizeof(*tmp) * size + 1)) == NULL)
	    exit(-1);
          while (i < size - my_strlen(ptr->size))
            {
              tmp[i] = ' ';
              i = i + 1;
            }
          tmp[i] = '\0';
          my_strcat(tmp, ptr->size);
          free(ptr->size);
          ptr->size = my_strdup(tmp);
          free(tmp);
        }
      ptr = ptr->next;
    }
}
Ejemplo n.º 15
0
/**
 * Ask for a "user pref file" and process it.
 *
 * This function should only be used by standard interaction commands,
 * in which a standard "Command:" prompt is present on the given row.
 *
 * Allow absolute file names?  XXX XXX XXX
 */
static void do_cmd_pref_file_hack(long row)
{
	char ftmp[80];

	screen_save();

	/* Prompt */
	prt("Command: Load a user pref file", row, 0);

	/* Prompt */
	prt("File: ", row + 2, 0);

	/* Get the filesystem-safe name and append .prf */
	player_safe_name(ftmp, sizeof(ftmp), player->full_name, true);
	my_strcat(ftmp, ".prf", sizeof(ftmp));

	/* Ask for a file (or cancel) */
	if (askfor_aux(ftmp, sizeof ftmp, NULL)) {
		/* Process the given filename */
		if (process_pref_file(ftmp, false, true) == false) {
			/* Mention failure */
			prt("", 0, 0);
			msg("Failed to load '%s'!", ftmp);
		} else {
			/* Mention success */
			prt("", 0, 0);
			msg("Loaded '%s'.", ftmp);
		}
	}

	screen_load();
}
Ejemplo n.º 16
0
/**
 * Prompt the user for a filename to save the pref file to.
 */
static bool get_pref_path(const char *what, int row, char *buf, size_t max)
{
	char ftmp[80];
	bool ok;

	screen_save();

	/* Prompt */
	prt(format("%s to a pref file", what), row, 0);
	prt("File: ", row + 2, 0);

	/* Get the filesystem-safe name and append .prf */
	player_safe_name(ftmp, sizeof(ftmp), player->full_name, true);
	my_strcat(ftmp, ".prf", sizeof(ftmp));

	/* Get a filename */
	ok = askfor_aux(ftmp, sizeof ftmp, NULL);
	screen_load();

	/* Build the filename */
	if (ok)
		path_build(buf, max, ANGBAND_DIR_USER, ftmp);

	return ok;
}
Ejemplo n.º 17
0
/**
 * Describe an item's origin
 */
static bool describe_origin(textblock *tb, const struct object *obj, bool terse)
{
	char loot_spot[80];
	char name[80];
	int origin;
	const char *dropper = NULL;
	const char *article;
	bool unique = false;

	/* Only give this info in chardumps if wieldable */
	if (terse && !obj_can_wear(obj))
		return false;

	/* Set the origin - care needed for mimics */
	if ((obj->origin == ORIGIN_DROP_MIMIC) && (obj->mimicking_m_idx != 0))
		origin = ORIGIN_FLOOR;
	else
		origin = obj->origin;

	/* Name the place of origin */
	if (obj->origin_depth)
		strnfmt(loot_spot, sizeof(loot_spot), "at %d feet (level %d)",
		        obj->origin_depth * 50, obj->origin_depth);
	else
		my_strcpy(loot_spot, "in town", sizeof(loot_spot));

	/* Name the monster of origin */
	if (obj->origin_race) {
		dropper = obj->origin_race->name;
		if (rf_has(obj->origin_race->flags, RF_UNIQUE)) {
			unique = true;
		}
	} else {
		dropper = "monster lost to history";
	}
	article = is_a_vowel(dropper[0]) ? "an " : "a ";
	if (unique)
		my_strcpy(name, dropper, sizeof(name));
	else {
		my_strcpy(name, article, sizeof(name));
		my_strcat(name, dropper, sizeof(name));
	}

	/* Print an appropriate description */
	switch (origins[origin].args)
	{
		case -1: return false;
		case 0: textblock_append(tb, origins[origin].desc); break;
		case 1: textblock_append(tb, origins[origin].desc, loot_spot);
				break;
		case 2:
			textblock_append(tb, origins[origin].desc, name, loot_spot);
			break;
	}

	textblock_append(tb, "\n\n");

	return true;
}
Ejemplo n.º 18
0
void testMY_STRCAT(void){
    char* str = NULL;

    if(temp_file != NULL){
        str = (char*)xmalloc((15 + 1) * sizeof(char));
        str[0] = '\0';
        str = my_strcat(str, "test");
        CU_ASSERT_STRING_EQUAL(str, "test");
        str = my_strcat(str, "ing");
        CU_ASSERT_STRING_EQUAL(str, "testing");
        str = my_strcat(str, NULL);
        CU_ASSERT_STRING_EQUAL(str, "testing");
        free(str);
        str = my_strcat(NULL, "test");
        CU_ASSERT(str == NULL);
    }
}
Ejemplo n.º 19
0
char			*tab_to_cmd(char **tab)
{
  int			i;
  char			*str;

  i = 0;
  if ((str = malloc(sizeof(char))) == NULL)
    return (NULL);
  str[0] = '\0';
  while (tab[i])
    {
      str = my_strcat(str, tab[i]);
      str = my_strcat(str, " ");
      i++;
    }
  return (str);
}
Ejemplo n.º 20
0
int main()
{
    char s[100] = "foo";
    char t[10]  = "bar";
    my_strcat(s, t);
    printf("%s\n", s);
    printf("end\n");
}
Ejemplo n.º 21
0
int main()
{
	char a[] = "Hello\0                        ";
	char b[] = ", world!";
	printf("strcat(\"%s\", \"%s\") = ", a, b);
	my_strcat(a, b);
	printf("\"%s\"", a);
}
Ejemplo n.º 22
0
/*
**construit une chaine a partir dun label et dune valeur
*/
char	*mk_line2(char *label, char *value)
{
  char	*new_line;
  int	len;

  if ((label == NULL) || (value == NULL))
    return (NULL);
  len = my_strlen(label);
  len = len + my_strlen(value) + 1;
  if ((new_line = malloc(sizeof(*new_line) * len)) == NULL)
    exit(-1);
  my_strcat(new_line, "");
  my_strcpy(new_line, label);
  my_strcat(new_line, "=");
  my_strcat(new_line, value);
  return (new_line);
}
Ejemplo n.º 23
0
int main(int argc, const char *argv[])
{
	char a[100]="saddhna";
	char b[]="lkjlkh";
	my_strcat(a,b);
	printf("%s\n",a);
	return 0;
}
Ejemplo n.º 24
0
Archivo: ex5_3.c Proyecto: yufw/kr
int main()
{
    char s[80] = "hello";
    char t[80] = "world";
    my_strcat(s, t);
    printf("%s\n", s);
    return 0;
}
char		*get_home_via_username(t_vars *v)
{
  char		*home;
  char		*tmp;

  home = NULL;
  tmp = get_env_var(v, "USERNAME");
  if (tmp)
    {
      home = my_strcat("/home/", tmp);
      tmp = my_xxfree(tmp);
      tmp = home;
      home = my_strcat(tmp, "/");
      tmp = my_xxfree(tmp);
    }
  return (home);
}
Ejemplo n.º 26
0
int main()
{
  char str[100]="hello world";
  char ptr[100]="kkkk";
  my_strcat(ptr,str);
  printf("%s\n",ptr);
  
  return 0;
}
Ejemplo n.º 27
0
/**
 * Display an ego-item type on the screen.
 */
int ego_item_name(char *buf, size_t buf_size, struct ego_desc *desc)
{
	size_t i;
	int end;
	size_t prefix_size;
	const char *long_name;

	struct ego_item *ego = &e_info[desc->e_idx];

	/* Find the ignore type */
	for (i = 0; i < N_ELEMENTS(quality_choices); i++)
		if (desc->itype == i) break;

	if (i == N_ELEMENTS(quality_choices)) return 0;

	/* Initialize the buffer */
	end = my_strcat(buf, "[ ] ", buf_size);

	/* Append the name */
	end += my_strcat(buf, quality_choices[i].name, buf_size);

	/* Append an extra space */
	end += my_strcat(buf, " ", buf_size);

	/* Get the full ego-item name */
	long_name = ego->name;

	/* Get the length of the common prefix, if any */
	prefix_size = (desc->short_name - long_name);

	/* Found a prefix? */
	if (prefix_size > 0) {
		char prefix[100];

		/* Get a copy of the prefix */
		my_strcpy(prefix, long_name, prefix_size + 1);

		/* Append the prefix */
		end += my_strcat(buf, prefix, buf_size);
	}
	/* Set the name to the right length */
	return end;
}
Ejemplo n.º 28
0
int main()
{
  char a[100],b[100];
  scanf("%s %s",a,b);
  print_str(a);
  rev_print_str(a);
  puts(my_strcat(a,b));
 puts(my_strcpy(a,b));
  return 0;
}
Ejemplo n.º 29
0
static FD	open_it(void)
{
  FD	file;
  char	*name;

  name = my_strcat(get_env("HOME"), ".Slashrc");
  file = open(name, O_RDONLY);
  free(name);
  return (file);
}
Ejemplo n.º 30
0
int main(void) {
    char s[100] = "Hello ";
    char t[] = "World";

    my_strcat(s, t);

    puts(s);

    return 0;
}