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.1  2008/02/08 15:06:42  james
14  * *** empty log message ***
15  *
16  */
17
18 #include "project.h"
19
20 History *history_new(int n)
21 {
22 History *ret;
23
24 ret=(History *) malloc(sizeof(History));
25 ret->lines=malloc(n*sizeof(History_ent));
26 memset(ret->lines,0,n*sizeof(History_ent));
27
28 ret->wptr=0;
29 ret->nlines=n;
30
31 return ret;
32 }
33
34 void history_free(History *h)
35 {
36 if (!h) return;
37 if (h->lines) free(h->lines);
38 free(h);
39 }
40
41
42 void history_add(History *h,CRT_CA *c)
43 {
44 if (!h) return;
45
46 memcpy(h->lines[h->wptr].line,c,sizeof(CRT_CA)*CRT_COLS);
47 h->wptr++;
48
49 if (h->wptr==h->nlines)
50         h->wptr=0;
51
52