Exemple #1
0
int execute_commands(StringList commands, StringList arguments){
    FILE *file;
    int ret = 0;
    background = 0;
    String command = new_string();
    int position;
    String tmp;
	//verifica se o ultimo caracter do comand PATH é & se for remove e seta flag background pra 1
    if(list_find_char_at_last(commands, '&') != -1){
        while((tmp = list_next(&commands))){
            remove_last_char(&tmp);
        }
        background = 1;
	//verifica se omultimo caractere dos comandos é & se sim remove e seta a flag background pra 1
    }if((position = list_find_char_at_last(arguments, '&'))){
        if(position != -1){
            remove_last_char(&arguments.string[position]);
            background = 1;
        }
    }
    reset_index(&commands);
	// abre o arquivo a partir do comand PATH, se encontrar o arquivo tenta executar o comando
    while((command = list_next(&commands))){
        file = fopen(command, "r");
        if(!file)
            continue;
        fclose(file);
        ret = try_execute(command, arguments);
    }
    dispose_string(&command);
    return ret;
}
Exemple #2
0
char *get_command_string() {
  char *data = 0;
  size_t sth = 0;
  printf("-> ");
  getline(&data, &sth, stdin);
  return remove_last_char(data);
}
	void streamtools_object::test<16>()
	{
		std::string str;
		std::string expected_result;
		bool ret;

		str = "SecondLife is a 3D World";

		ret = remove_last_char('d',str);
		expected_result = "SecondLife is a 3D Worl";
		ensure_equals("remove_last_char: should remove last char", str, expected_result);

		str = "SecondLife is a 3D World";
		ret = remove_last_char('W',str);
		expected_result = "SecondLife is a 3D World";
		ensure_equals("remove_last_char: should not remove as it is not last char", str, expected_result);
		ensure("remove_last_char: should return false", ret == false);

		str = "SecondLife is a 3D World\n";
		ret = remove_last_char('\n',str);
		expected_result = "SecondLife is a 3D World";
		ensure_equals("remove_last_char: should remove last newline", str, expected_result);
		ensure("remove_last_char: should remove newline and return true", ret == true);
	}
Exemple #4
0
strings* complete(trie root, char* prefix) {
  uint32_t i, len;
  len = strlen(prefix);
  trie n = root;

  for(i = 0; n != NULL && i < len; i++) {
    n = get_child(n, prefix[i]);
  }

  if(n == NULL) {
    return NULL;
  } else {
    GSList* suffixes = reversed_suffixes(n);
    uint32_t len, prefix_len;
    len = g_slist_length(suffixes);
    prefix_len = strlen(prefix);
    strings* res = make_strings(len);
    string* str;
    int i,j;
    char c;

    // Loop through each suffix. We can't check if i >= 0, since i is unsigned.
    for(i = len; i--;) {
      str = g_slist_nth_data(suffixes, 0);

      // We don't want to include the last item in the prefix
      // (since it's going to be in the generated suffixes)
      for(j = 0; j < (int) prefix_len-1; j++) {
	append_char(string_at(res, i), prefix[j]);
      }
      while((c = remove_last_char(str)) != '\0') {
	append_char(string_at(res, i), c);
      }

      suffixes = g_slist_remove(suffixes, str);
      free(str);
    }

    return res;
  }
}