void print_names(bstnode<std::string> *root, std::string pattern) {
    if (root == nullptr)
        return;

    int cmp = root->val.compare(0, pattern.length(), pattern, 0, pattern.length());
    if (cmp == 0) {
        std::cout << root->val;
        print_names(root->left, pattern);
        print_names(root->right, pattern);
    } else if (cmp < 0)
        print_names(root->right, pattern);
    else if (cmp > 0)
        print_names(root->left, pattern);
}
Example #2
0
void	disp_files(int i, int fd, int ac, char **av)
{
	char	buffer;
	int		offset;
	int		readed;
	int		size_file;

	size_file = size_files(i, av);
	readed = 0;
	offset = ft_atoi(av[2]);
	print_names(i, ac, av);
	if (av[2][0] == '+')
	{
		while (readed != offset - 1)
			readed += read(fd, &buffer, 1);
		while (read(fd, &buffer, 1))
			write(1, &buffer, 1);
	}
	else
	{
		while (readed < (size_file - offset))
			readed += read(fd, &buffer, 1);
		while (read(fd, &buffer, 1))
			write(1, &buffer, 1);
	}
}
Example #3
0
int		main(int argc, char **argv)
{
	int	i;
	int	sign;
	int	tail;
	int	size;

	sign = 0;
	i = 3;
	if (argc < 4)
		return (1);
	tail = number(argv);
	if (tail == -1)
		return (1);
	if (argv[2][0] == '+')
		sign = 1;
	while (i < argc)
	{
		if (argc > 4)
			print_names(i, argv[i]);
		size = size_files(argv[i]);
		ft_puterr(argv[0], argv[i], ft_tail(sign, tail, size, argv[i]));
		i++;
	}
	return (0);
}
/*
  Função que traduz comandos básicos tanto para plural como para singular.
*/
char *put_command_simple(char *verb, int token_type){

	char *command;

	if( check_agreement(token_type) == FALSE ){
		yyerror("Use correct form of plural and singular");
	}

	if(!strcmp(verb, "mostrar") || !strcmp(verb, "exibir") || !strcmp(verb, "ver"))
		command = (token_type == T_FOLDER || token_type == T_FOLDERS) ? "ls -a" : "cat";
	else if(!strcmp(verb, "criar") || !strcmp(verb, "gerar"))
		command = (token_type == T_FOLDER || token_type == T_FOLDERS) ? "mkdir" : "touch";
	else if(!strcmp(verb, "remover") || !strcmp(verb, "apagar"))
		command = (token_type == T_FOLDER || token_type == T_FOLDERS) ? "rm -R" : "rm";
	else if(!strcmp(verb, "listar") && (token_type == T_FOLDER || token_type == T_FOLDERS))
		command = "ls -a";
	else{
		yyerror("There's no command to this verb\n");
	}

	fprintf(yyout, "%s", command);
	print_names();

	return strdup(command);
}
char *put_command_sed(char *verb, char *regex_find, char *regex_replace, int token_type){

	char *command, *rc1, *rc2;

	if( check_agreement(token_type) == FALSE){
		yyerror("Use correct form of plural and singular");
	}

	if(!strcmp(verb, "substituir") || !strcmp(verb, "trocar"))
		command = "sed";
	else{
		yyerror("There's no command to this verb\n");
	}

	rc1 = get_text_regex(regex_find);
	rc2 = get_text_regex(regex_replace);

	fprintf(yyout, "%s \"s/%s/%s/g\"", command, rc1, rc2);	
	print_names();

	free(rc1);
	free(rc2);

	return strdup(command);
}
Example #6
0
void print_names(grib_action* a) {
	while (a) {
		if (a->op && !strcmp(a->op,"label") ) { a=a->next; continue; }
		if (!strcmp(a->cclass->name,"action_class_noop") || 
			!strcmp(a->cclass->name,"action_class_when") ) 
			{ a=a->next; continue; }

		if (!strcmp(a->cclass->name,"action_class_list")) {
			grib_action_list* al=(grib_action_list*)a;
			printf("%s\n",a->name);
			print_names(al->block_list);
		} else if (!strcmp(a->cclass->name,"action_class_if")) {
			grib_action_if* ai=(grib_action_if*)a;
			print_names(ai->block_false);
			print_names(ai->block_true);
		} else {
			/* printf("%s (%s %s)\n",a->name,a->op,a->cclass->name); */
			printf("%s\n",a->name);
		}

		a=a->next;
	}
}
Example #7
0
File: main.c Project: d5h/gah
static void
show_msg(void)
{
  clear_msg();
  if (msg_text)
    {
      wprintw(wmsg, "%s", msg_text);
      FREE(msg_text);
    }
  else
    {
      print_names(wmsg, cursan);
      wmove(wmsg, 2, 1);
      if (~cursan->type & T_GROUP)
	print_value(wmsg, cursan);
    }
  wrefresh(wmsg);
}
/*
  Função que traduz comando grep tanto para plural como para singular.
*/
char *put_command_grep(char *verb, char *regex, int token_type){

	char *command;

	if( check_agreement(token_type) == FALSE ){
		yyerror("Use correct form of plural and singular");
	}

	if(!strcmp(verb, "buscar") || !strcmp(verb, "encontrar") || !strcmp(verb, "filtrar"))
		command = (token_type == T_FILE || token_type == T_FILES) ? "grep -i" : "grep -r -i";
	else{
		yyerror("There's no command to this verb\n");
	}

	fprintf(yyout, "%s %s", command, regex);
	print_names();

	return strdup(command);
}
Example #9
0
int main(int argc, char *argv[])
{
  int i = 0;
  int fail = 0;

  grib_context* c = grib_context_get_default();
  grib_action* a=NULL;

  for(i = 1; i < argc; i++){
    /* printf("%s ... \n",argv[i]);fflush(stdout); */
    if(!(a=grib_parse_file(c,argv[i])))
    {
      fail++;
      printf("FAILED\n");
      exit(1);
    } else print_names(a);
  }

  return fail;
}
/*
	Função para traduzir comando cp no Plural. São trados os seguintes casos:

	Copiar Arquivos /home/arq1 /etc/arq2 /sys/arq3 para diretorio /opt	cp /home/arq1/ /etc/arq2 /opt 
	Copiar diretorios /home/dir1 /etc/dir2 /sys/dir3 para diretorio /opt	cp -R /home/dir1 /home/dir2 /opt 
*/
char *put_command_cp_plural(char *verb, int s_token, char *target){

	char *command;

	if( check_agreement(s_token) == FALSE ){
		yyerror("Use correct form of plural and singular");
	}

	if(!strcmp(verb, "copiar"))
		command = (s_token == T_FILES) ? "cp" : "cp -R";
	else{
		yyerror("There's no command to this verb\n");
	}

	fprintf(yyout, "%s", command);
	print_names();
	fprintf(yyout, " %s", target);

	return strdup(command);
}
Example #11
0
File: main.c Project: d5h/gah
static size_t
print_names(WINDOW *w, struct annot *an)
{
  if (an == top)
    return 0;
  else
    {
      size_t cursoff = offset + cursor;
      size_t paroff = print_names(w, an->parent);
      size_t off = paroff + an->reloff;
      size_t index = (cursoff - off) / an->len;
      if (an->parent != top)
	wprintw(w, ".");
      wprintw(w, "%s", an->name);
      if (an->repeats)
	wprintw(w, "[%zi]", index);
      if (an->has_param)
	wprintw(w, "(%s)", valstr(&an->param));
      return off + index * an->len;
    }
}