Now inbound_cap_ls() can enable extensions when a bouncer uses a namespace for the...
[rofl0r-ixchat.git] / src / common / history.c
blob1cd6b50826e7ba9bd7d87a8fd7c5aa281e955a22
1 /* X-Chat
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
19 #include <string.h>
20 #include <stdlib.h>
21 #include "history.h"
23 void
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);
29 his->realpos++;
30 if (his->realpos == HISTORY_SIZE)
31 his->realpos = 0;
32 his->pos = his->realpos;
35 void
36 history_free (struct history *his)
38 int i;
39 for (i = 0; i < HISTORY_SIZE; i++)
41 if (his->lines[i])
43 free (his->lines[i]);
44 his->lines[i] = 0;
49 char *
50 history_down (struct history *his)
52 int next;
54 if (his->pos == his->realpos) /* allow down only after up */
55 return 0;
56 if (his->realpos == 0)
58 if (his->pos == HISTORY_SIZE - 1)
60 his->pos = 0;
61 return "";
63 } else
65 if (his->pos == his->realpos - 1)
67 his->pos++;
68 return "";
72 next = 0;
73 if (his->pos < HISTORY_SIZE - 1)
74 next = his->pos + 1;
76 if (his->lines[next])
78 his->pos = next;
79 return his->lines[his->pos];
82 return 0;
85 char *
86 history_up (struct history *his, char *current_text)
88 int next;
90 if (his->realpos == HISTORY_SIZE - 1)
92 if (his->pos == 0)
93 return 0;
94 } else
96 if (his->pos == his->realpos + 1)
97 return 0;
100 next = HISTORY_SIZE - 1;
101 if (his->pos != 0)
102 next = his->pos - 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);
116 his->pos = next;
117 return his->lines[his->pos];
120 return 0;