static void readline_hist_add(ReadLineState *rs, const char *cmdline)

{

    char *hist_entry, *new_entry;

    int idx;



    if (cmdline[0] == '\0')

	return;

    new_entry = NULL;

    if (rs->hist_entry != -1) {

	/* We were editing an existing history entry: replace it */

	hist_entry = rs->history[rs->hist_entry];

	idx = rs->hist_entry;

	if (strcmp(hist_entry, cmdline) == 0) {

	    goto same_entry;

	}

    }

    /* Search cmdline in history buffers */

    for (idx = 0; idx < READLINE_MAX_CMDS; idx++) {

	hist_entry = rs->history[idx];

	if (hist_entry == NULL)

	    break;

	if (strcmp(hist_entry, cmdline) == 0) {

	same_entry:

	    new_entry = hist_entry;

	    /* Put this entry at the end of history */

	    memmove(&rs->history[idx], &rs->history[idx + 1],

		    (READLINE_MAX_CMDS - idx + 1) * sizeof(char *));

	    rs->history[READLINE_MAX_CMDS - 1] = NULL;

	    for (; idx < READLINE_MAX_CMDS; idx++) {

		if (rs->history[idx] == NULL)

		    break;

	    }

	    break;

	}

    }

    if (idx == READLINE_MAX_CMDS) {

	/* Need to get one free slot */

	free(rs->history[0]);

	memcpy(rs->history, &rs->history[1],

	       (READLINE_MAX_CMDS - 1) * sizeof(char *));

	rs->history[READLINE_MAX_CMDS - 1] = NULL;

	idx = READLINE_MAX_CMDS - 1;

    }

    if (new_entry == NULL)

	new_entry = strdup(cmdline);

    rs->history[idx] = new_entry;

    rs->hist_entry = -1;

}

static void readline_hist_add(ReadLineState *rs, const char *cmdline)

{

    char *hist_entry, *new_entry;

    int idx;



    if (cmdline[0] == '\0')

	return;

    new_entry = NULL;

    if (rs->hist_entry != -1) {

	

	hist_entry = rs->history[rs->hist_entry];

	idx = rs->hist_entry;

	if (strcmp(hist_entry, cmdline) == 0) {

	    goto same_entry;

	}

    }

    

    for (idx = 0; idx < READLINE_MAX_CMDS; idx++) {

	hist_entry = rs->history[idx];

	if (hist_entry == NULL)

	    break;

	if (strcmp(hist_entry, cmdline) == 0) {

	same_entry:

	    new_entry = hist_entry;

	    

	    memmove(&rs->history[idx], &rs->history[idx + 1],

		    (READLINE_MAX_CMDS - idx + 1) * sizeof(char *));

	    rs->history[READLINE_MAX_CMDS - 1] = NULL;

	    for (; idx < READLINE_MAX_CMDS; idx++) {

		if (rs->history[idx] == NULL)

		    break;

	    }

	    break;

	}

    }

    if (idx == READLINE_MAX_CMDS) {

	

	free(rs->history[0]);

	memcpy(rs->history, &rs->history[1],

	       (READLINE_MAX_CMDS - 1) * sizeof(char *));

	rs->history[READLINE_MAX_CMDS - 1] = NULL;

	idx = READLINE_MAX_CMDS - 1;

    }

    if (new_entry == NULL)

	new_entry = strdup(cmdline);

    rs->history[idx] = new_entry;

    rs->hist_entry = -1;

}

		    (READLINE_MAX_CMDS - idx + 1) * sizeof(char *));
static void FUNC_0(ReadLineState *VAR_0, const char *VAR_1)

{

    char *VAR_2, *VAR_3;

    int VAR_4;



    if (VAR_1[0] == '\0')

	return;

    VAR_3 = NULL;

    if (VAR_0->VAR_2 != -1) {

	

	VAR_2 = VAR_0->history[VAR_0->VAR_2];

	VAR_4 = VAR_0->VAR_2;

	if (strcmp(VAR_2, VAR_1) == 0) {

	    goto same_entry;

	}

    }

    

    for (VAR_4 = 0; VAR_4 < READLINE_MAX_CMDS; VAR_4++) {

	VAR_2 = VAR_0->history[VAR_4];

	if (VAR_2 == NULL)

	    break;

	if (strcmp(VAR_2, VAR_1) == 0) {

	same_entry:

	    VAR_3 = VAR_2;

	    

	    memmove(&VAR_0->history[VAR_4], &VAR_0->history[VAR_4 + 1],

		    (READLINE_MAX_CMDS - VAR_4 + 1) * sizeof(char *));

	    VAR_0->history[READLINE_MAX_CMDS - 1] = NULL;

	    for (; VAR_4 < READLINE_MAX_CMDS; VAR_4++) {

		if (VAR_0->history[VAR_4] == NULL)

		    break;

	    }

	    break;

	}

    }

    if (VAR_4 == READLINE_MAX_CMDS) {

	

	free(VAR_0->history[0]);

	memcpy(VAR_0->history, &VAR_0->history[1],

	       (READLINE_MAX_CMDS - 1) * sizeof(char *));

	VAR_0->history[READLINE_MAX_CMDS - 1] = NULL;

	VAR_4 = READLINE_MAX_CMDS - 1;

    }

    if (VAR_3 == NULL)

	VAR_3 = strdup(VAR_1);

    VAR_0->history[VAR_4] = VAR_3;

    VAR_0->VAR_2 = -1;

}

static void FUNC_0(ReadLineState *VAR_0, const char *VAR_1)
{ char *VAR_2, *VAR_3; int VAR_4; if (VAR_1[0] == '\0')
return; VAR_3 = NULL; if (VAR_0->VAR_2 != -1) { VAR_2 = VAR_0->history[VAR_0->VAR_2]; VAR_4 = VAR_0->VAR_2; if (strcmp(VAR_2, VAR_1) == 0) { goto same_entry; } } for (VAR_4 = 0; VAR_4 < READLINE_MAX_CMDS; VAR_4++) { VAR_2 = VAR_0->history[VAR_4]; if (VAR_2 == NULL)
break; if (strcmp(VAR_2, VAR_1) == 0) { same_entry:
VAR_3 = VAR_2; memmove(&VAR_0->history[VAR_4], &VAR_0->history[VAR_4 + 1],
(READLINE_MAX_CMDS - VAR_4 + 1) * sizeof(char *)); VAR_0->history[READLINE_MAX_CMDS - 1] = NULL; for (; VAR_4 < READLINE_MAX_CMDS; VAR_4++) { if (VAR_0->history[VAR_4] == NULL)
break; } break; } } if (VAR_4 == READLINE_MAX_CMDS) { free(VAR_0->history[0]); memcpy(VAR_0->history, &VAR_0->history[1],
(READLINE_MAX_CMDS - 1) * sizeof(char *)); VAR_0->history[READLINE_MAX_CMDS - 1] = NULL; VAR_4 = READLINE_MAX_CMDS - 1; } if (VAR_3 == NULL)
VAR_3 = strdup(VAR_1); VAR_0->history[VAR_4] = VAR_3; VAR_0->VAR_2 = -1; }