chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / history.c
1 /*
2  * history.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.2  2008/02/12 22:36:46  james
14  * *** empty log message ***
15  *
16  * Revision 1.1  2008/02/08 15:06:42  james
17  * *** empty log message ***
18  *
19  */
20
21 #include "project.h"
22
23 History *
24 history_new (int n)
25 {
26   History *ret;
27
28   ret = (History *) malloc (sizeof (History));
29   ret->lines = malloc (n * sizeof (History_ent));
30   memset (ret->lines, 0, n * sizeof (History_ent));
31
32   ret->wptr = 0;
33   ret->nlines = n;
34
35   return ret;
36 }
37
38 void
39 history_free (History * h)
40 {
41   if (!h)
42     return;
43   if (h->lines)
44     free (h->lines);
45   free (h);
46 }
47
48
49 void
50 history_add (History * h, CRT_CA * c)
51 {
52   if (!h)
53     return;
54
55   memcpy (h->lines[h->wptr].line, c, sizeof (CRT_CA) * CRT_COLS);
56   h->wptr++;
57
58   if (h->wptr == h->nlines)
59     h->wptr = 0;
60
61 }