2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 history_add (struct history
*his
, char *text
)
26 if (his
->lines
[his
->realpos
])
27 free (his
->lines
[his
->realpos
]);
28 his
->lines
[his
->realpos
] = strdup (text
);
30 if (his
->realpos
== HISTORY_SIZE
)
32 his
->pos
= his
->realpos
;
36 history_free (struct history
*his
)
39 for (i
= 0; i
< HISTORY_SIZE
; i
++)
50 history_down (struct history
*his
)
54 if (his
->pos
== his
->realpos
) /* allow down only after up */
56 if (his
->realpos
== 0)
58 if (his
->pos
== HISTORY_SIZE
- 1)
65 if (his
->pos
== his
->realpos
- 1)
73 if (his
->pos
< HISTORY_SIZE
- 1)
79 return his
->lines
[his
->pos
];
86 history_up (struct history
*his
, char *current_text
)
90 if (his
->realpos
== HISTORY_SIZE
- 1)
96 if (his
->pos
== his
->realpos
+ 1)
100 next
= HISTORY_SIZE
- 1;
104 if (his
->lines
[next
])
108 current_text
[0] && strcmp(current_text
, his
->lines
[next
]) &&
109 (!his
->lines
[his
->pos
] || strcmp(current_text
, his
->lines
[his
->pos
])) &&
110 (!his
->lines
[his
->realpos
] || strcmp(current_text
, his
->lines
[his
->pos
]))
113 history_add (his
, current_text
);
117 return his
->lines
[his
->pos
];