Exemple #1
0
int		find_backquote(char **str, t_tab *tab, int i)
{
  int		length;
  int		index;
  char		c;

  index = i + 1;
  length = 0;
  c = 0;
  while (((*str)[index]) && (((*str)[index] != '`') ||
			     (!is_backslash(*str, index))))
    {
      if ((*str)[index++] != ' ')
	c = 1;
      ++length;
    }
  if (!(*str)[index] || !isatty(0))
    {
      free(*str);
      *str = NULL;
      mismatch_thing(NULL, 2);
      return (-1);
    }
  if (c == 1)
    return (fill_str(str, tab, i, length));
  return (replace_quote(str, NULL));
}
Exemple #2
0
void ScreenData::fill(const QChar &character)
{
    clear();
    auto it = --m_screen_blocks.end();
    for (int i = 0; i < m_block_count; --it, i++) {
        QString fill_str(m_screen->width(), character);
        (*it)->replaceAtPos(0, fill_str, m_screen->defaultTextStyle());
    }
}
Exemple #3
0
/*Tests if the file exists and fills the string if so*/
void txt_to_char(FILE* file, char* str){
  file = fopen("1.txt", "r");
  if (file == NULL){
    printf("ERROR - Cannot open file\n");
    exit(0);
  }
  fill_str(str, BIGSTR_SIZE, file);
  fclose(file);
}
Exemple #4
0
static int lb_alloc(lua_State *L) {
    buffer *b = lb_checkbuffer(L, 1);
    if (lb_realloc(L, b, luaL_checkint(L, 2))) {
        size_t len = 0;
        const char *str = lb_optlstring(L, 3, NULL, &len);
        size_t pos = real_range(L, 4, &len);
        fill_str(b, 0, b->len, &str[pos], len);
    }
    lua_settop(L, 1);
    lua_pushinteger(L, b->len);
    return 2;
}
Exemple #5
0
std::string string2string(const std::string &str,
                          const std::size_t fieldLength, const bool leftAlign,
                          const bool allow_cut_off)
{
    if (!fieldLength || str.length() == fieldLength)
        return str;

    if (str.length() > fieldLength)
        return (allow_cut_off ? str.substr(0, fieldLength) : str);

    std::string fill_str(fieldLength - str.length(), ' ');
    return (leftAlign ? str + fill_str : fill_str + str);
}
Exemple #6
0
static int lb_rep(lua_State *L) {
    buffer *b = lb_checkbuffer(L, 1);
    size_t len = b->len;
    const char *str = NULL;
    int rep = 0;
    if (lua_type(L, 2) == LUA_TNUMBER)
        rep = lua_tointeger(L, 2);
    else if ((str = lb_tolstring(L, 2, &len)) != NULL)
        rep = luaL_checkint(L, 3);
    else luaL_typerror(L, 2, "number, buffer or string");
    if (lb_realloc(L, b, len * (rep >= 0 ? rep : 0)))
        fill_str(b, 0, b->len, str != NULL ? str : b->str, len);
    lua_settop(L, 1);
    return 1;
}
Exemple #7
0
static int do_cmd(lua_State *L, buffer *b, int narg, enum cmd c) {
    int pos;
    switch (c) {
        case cmd_append:
            pos = b->len; break;
        case cmd_insert: case cmd_set:
            pos = real_offset(luaL_checkint(L, narg++), b->len); break;
        default:
            pos = 0; break;
    }

    if (lb_isbufferorstring(L, narg)) {
        size_t len;
        const char *str = lb_tolstring(L, narg, &len);
        size_t i = real_range(L, narg+1, &len);
        if (prepare_cmd(L, b, c, pos, len))
            memcpy(&b->str[pos], &str[i], len);
    }
    else if (lua_type(L, narg) == LUA_TNUMBER) {
        size_t fill_len = lua_tointeger(L, narg);
        size_t len = 0;
        const char *str = NULL;
        if (!lua_isnoneornil(L, narg+1)) {
            if ((str = lb_tolstring(L, narg+1, &len)) != NULL)
                str += real_range(L, narg+2, &len);
            else if ((str = udtolstring(L, narg+1, &len)) == NULL)
                luaL_typerror(L, narg+1, "string, buffer or userdata");
        }
        if (prepare_cmd(L, b, c, pos, fill_len))
            fill_str(b, pos, fill_len, str, len);
    }
    else if (lua_isuserdata(L, narg)) {
        size_t len = 0;
        const char *str = udtolstring(L, narg, &len);
        if (prepare_cmd(L, b, c, pos, len))
            memcpy(&b->str[pos], str, len);
    }
    else if (!lua_isnoneornil(L, narg))
        luaL_typerror(L, narg, "string, buffer, number or userdata");
    lua_settop(L, narg-1);
    return 1;
}
Exemple #8
0
static void doaction(const struct lookfor *l, const char *filename) {
	char **args;
	pid_t child;
	size_t i;
	static const int exceptions[3] = { 0, 1, 2};

	// TODO: what about getting output from the childs and mailing
	// it somewhere?

	// todo: only if verbose and with full arguments (and filename escaped)...
	dolog("Will call action %s for: %s\n", l->action, filename);

	child = fork();
	if (child == (pid_t)-1) {
		int e = errno;
		logerror("Error forking: %s(%d)\n",
				strerror(e), e);
		return;
	}
	if (child > 0) {
		int status;
		pid_t w;
		do {
			w = waitpid(child, &status, 0);
		} while (w == (pid_t)-1 && errno==EINTR && !termsignaled);
		if (w == child) {
			if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
				// todo: full escaped action string...
				logerror("Action '%s' returned exitcode %d\n",
						l->action,
						(int)(WEXITSTATUS(status)));
			} else if (WIFSIGNALED(status)) {
				// todo: full escaped action string...
				logerror("Action '%s' died by signal %d\n",
						l->action,
						(int)(WTERMSIG(status)));
			}
		}
		return;
	}
	/* in the fork */
	args = calloc((l->num_arguments+2), sizeof(char *));
	if (args == NULL)
		logerror_die("Out of memory in child!\n");
	args[0] = l->action;
	for (i = 0 ; i < l->num_arguments; i++) {
		struct argument *a = &l->arguments[i];
		if (a->substitute != (size_t)-1) {
			args[i+1] = fill_str(a->argument, a->len,
					a->substitute, filename);
			if (args[i+1] == NULL)
				logerror_die("Out of memory in child!\n");
		} else
			args[i+1] = a->argument;
	}
	args[l->num_arguments+1] = NULL;
	if (l->dir != NULL && chdir(l->dir) != 0) {
		int e = errno;
		logerror_die("Could not change to directory '%s' in child: "
				"%s(%d)\n", l->dir, strerror(e), e);
	}
	if (logfile != NULL) {
		if (l->logstdout && dup2(fileno(logfile), 1) == -1) {
			int e = errno;
			logerror_die("Could not redirect stdout to logfile: "
					"%s(%d)\n", strerror(e), e);
		}
		if (l->logstderr && dup2(fileno(logfile), 2) == -1) {
			int e = errno;
			logerror_die("Could not redirect stderr to logfile: "
					"%s(%d)\n", strerror(e), e);
		}
		fclose(logfile);
	}
	closeallopenfds(exceptions, 3);
	execvp(args[0], args);
}