Ejemplo n.º 1
0
void cmd_insert (char *cp)

{
    Line *line;
    String *string;

    if (range_single (cp, &cp, &cur_position) < 0) return;		/* see where to insert */
    if (*cp == ';')  							/* if ;, insert the remaining string before current line */
    {
        cur_position.offset = 0;
        string = string_create (strlen (cp + 1), cp + 1);
        string_concat (string, 1, "\n");
        buffer_dirty (cur_position.buffer, 1);
        line_insert (cur_position.buffer, cur_position.line, string);
        return;
    }
    if (!eoltest (cp)) return;						/* otherwise, that's all there should be */

    /* Read tty input until eof into the current buffer just before the current line */

    cur_position.offset = 0;
    while ((string = jnl_readprompt ("\r\n               >")) != NULL)
    {
        string_concat (string, 1, "\n");					/* put line terminator on string */
        buffer_dirty (cur_position.buffer, 1);
        line_insert (cur_position.buffer, cur_position.line, string);	/* insert line just before current line */
    }
}
Ejemplo n.º 2
0
int Dinsertfile(f,n)
{
	int s,nline,nbytes;
	WINDOW *wp;
	char fname[NFILEN],*line;

	fname[0] = 0;
	if (mlreply("Insert file: ",fname,NFILEN) == FALSE)
		return FALSE;

	s = ffropen(fname);		/* open file for reading	*/
	switch (s)
	{
	    case FIOFNF:
		mlwrite("File not found");
	    case FIOERR:
		return FALSE;
	}
	mlwrite("[Reading file]");
	nline = 0;
	while ((s = ffgetline(&line,&nbytes)) == FIOSUC)
	{	register char *p;

		for (p = line; nbytes; p++,nbytes--)
		{
			if (line_insert(1,*p) == FALSE)
				return FALSE;
		}
		if (random_newline(FALSE,1) == FALSE)
			return FALSE;
		++nline;
	}
	ffclose();
        if (s == FIOEOF) {                      /* Don't zap message!   */
                if (nline == 1)
                        mlwrite("[Read 1 line]");
                else
                        mlwrite("[Read %d lines]", nline);
        }
        for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) {
                if (wp->w_bufp == curbp) {
                        wp->w_flag |= WFMODE|WFHARD;
                }
        }
	return s != FIOERR;
}
Ejemplo n.º 3
0
int			on_key_down_arrow(t_context *context, t_line_edit *line_edit)
{
	char	*str;

	on_key_ctrl_u(context, line_edit);
	if (context->history && context->history_ptr)
	{
		if (context->history_ptr != context->history->previous)
			context->history_ptr = context->history_ptr->next;
		else
			context->history_ptr = 0;
		if (context->history_ptr)
		{
			str = ((t_history *)(context->history_ptr->content))->entry;
			line_insert(line_edit, str, ft_strlen(str));
		}
	}
	return (READ_CONTINUE);
}