Example #1
0
int string_insertchar(string* s, char c, size_t pos) {
  assert(s);
  if (string_expand(s, s->len+1)) goto err_exit;
  // shift chars from pos, inclusive, down one
  memmove(s->data+pos+1, s->data+pos, s->len-pos+1);
  s->data[pos] = c; ++s->len;
  return 0;
err_exit: return 1;
}
Example #2
0
int main(int argc, char **argv)
{
    char str1[] = "-a-d-z-fa-d-sfa--zadsf";
    char str2[100] = {0};

    printf("%s\n", str1);
    string_expand(str2, str1);
    printf("expand string : %s\n", str2);

    return 0;
}
Example #3
0
File: draw.c Project: jlsandell/tig
static bool
draw_text_expanded(struct view *view, enum line_type type, const char *string, int max_len, bool use_tilde)
{
	static char text[SIZEOF_STR];

	do {
		size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);

		if (draw_chars(view, type, text, max_len, use_tilde))
			return TRUE;
		string += pos;
	} while (*string);

	return VIEW_MAX_LEN(view) <= 0;
}
Example #4
0
File: branch.c Project: ebruck/tig
static bool
branch_read(struct view *view, char *line)
{
	struct branch_state *state = view->private;
	const char *title = NULL;
	const struct ident *author = NULL;
	struct time time = {};
	size_t i;

	if (!line)
		return TRUE;

	switch (get_line_type(line)) {
	case LINE_COMMIT:
		string_copy_rev_from_commit_line(state->id, line);
		return TRUE;

	case LINE_AUTHOR:
		parse_author_line(line + STRING_SIZE("author "), &author, &time);
		break;

	default:
		title = line + STRING_SIZE("title ");
	}

	for (i = 0; i < view->lines; i++) {
		struct branch *branch = view->line[i].data;

		if (strcmp(branch->ref->id, state->id))
			continue;

		if (author) {
			branch->author = author;
			branch->time = time;
		}

		if (title)
			string_expand(branch->title, sizeof(branch->title), title, 1);

		view->line[i].dirty = TRUE;
	}

	return TRUE;
}
Example #5
0
static bool
draw_text_expanded(struct view *view, enum line_type type, const char *string, int length, int max_width, bool use_tilde)
{
	static char text[SIZEOF_STR];

	if (length == -1)
		length = strlen(string);

	do {
		size_t pos = string_expand(text, sizeof(text), string, length, opt_tab_size);

		if (draw_chars(view, type, text, -1, max_width, use_tilde))
			return true;
		string += pos;
		length -= pos;
	} while (*string && length > 0);

	return VIEW_MAX_LEN(view) <= 0;
}
Example #6
0
File: xxx.c Project: yaomoon/GT2440
static bool default_render(struct view *view, unsigned int lineno)
{
	struct fileinfo *fileinfo;
	enum line_type type;
	int col = 0;
	size_t namelen;
    char *fname, *fnumber;
    int opt_file_name = 25;
	char text[SIZEOF_STR];

	if (view->offset + lineno >= view->lines)
		return false;

	fileinfo = view->line[view->offset + lineno];
	if (!*fileinfo->name)
		return false;

    fnumber = fileinfo->number;
    fname = blankspace(fileinfo->name);
	wmove(view->win, lineno, col);

	if (view->offset + lineno == view->lineno) {
        snprintf(vim_cmd, sizeof(vim_cmd), VIM_CMD, fnumber, fname);
		type = LINE_CURSOR;
		wattrset(view->win, get_line_attr(type));
		wchgat(view->win, -1, 0, type, NULL);
        string_copy(view->file, fileinfo->name);

	} else {
		type = LINE_FILE_LINCON;
        wchgat(view->win, -1, 0, type, NULL);
		wattrset(view->win, get_line_attr(LINE_FILE_NAME));
	}

    namelen = strlen(fileinfo->name);
    if (namelen > opt_file_name){
        int n = namelen-opt_file_name;
	    if (type != LINE_CURSOR)
            wattrset(view->win, get_line_attr(LINE_DELIMITER));
        waddch(view->win, '~');
	    if (type != LINE_CURSOR)
            wattrset(view->win, get_line_attr(LINE_FILE_NAME));
    	waddnstr(view->win, fileinfo->name + n, opt_file_name);
    }
    else
        waddstr(view->win, fileinfo->name);

    col += opt_file_name + 2;
	wmove(view->win, lineno, col);
	if (type != LINE_CURSOR)
		wattrset(view->win, get_line_attr(LINE_FILE_LINUM));

	waddstr(view->win, fileinfo->number);

    col += 9;
	if (type != LINE_CURSOR)
		wattrset(view->win, A_NORMAL);

	wmove(view->win, lineno, col);

	if (type != LINE_CURSOR)
		wattrset(view->win, get_line_attr(type));

    int contentlen = strlength(fileinfo->content);
    string_expand(text, sizeof(text), fileinfo->content, opt_tab_size);

    if (col + contentlen > view->width){
        contentlen = view->width - col;
        if (contentlen < 0)
            return TRUE;
        else {
            waddnstr(view->win, text, contentlen-1);
            if (type != LINE_CURSOR)
                wattrset(view->win, get_line_attr(LINE_DELIMITER));
            waddch(view->win, '~');
        }
    }
    else { 
        waddstr(view->win, fileinfo->content);
    }

	return TRUE;
}