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.3  2008/02/13 16:57:29  james
14  * *** empty log message ***
15  *
16  * Revision 1.2  2008/02/12 22:36:46  james
17  * *** empty log message ***
18  *
19  * Revision 1.1  2008/02/08 15:06:42  james
20  * *** empty log message ***
21  *
22  */
23
24 #include "project.h"
25
26 History *
27 history_new (int n)
28 {
29   History *ret;
30
31   ret = (History *) malloc (sizeof (History));
32   ret->lines = malloc (n * sizeof (History_ent));
33   memset (ret->lines, 0, n * sizeof (History_ent));
34
35   ret->wptr = 0;
36   ret->nlines = n;
37
38   return ret;
39 }
40
41 void
42 history_free (History * h)
43 {
44   if (!h)
45     return;
46   if (h->lines)
47     free (h->lines);
48   free (h);
49 }
50
51
52 void
53 history_add (History * h, CRT_CA * c)
54 {
55   History_ent *e;
56   if (!h)
57     return;
58
59   e = &h->lines[h->wptr];
60   HISTORY_INC (h, h->wptr);
61
62   memcpy (e->line, c, sizeof (CRT_CA) * CRT_COLS);
63   time (&e->t);
64   e->valid = 1;
65
66 #if 0
67   {
68     int i = CRT_COLS;
69     while (i--)
70       {
71         fputc (c->chr, stderr);
72         c++;
73       }
74     fputc ('\n', stderr);
75   }
76 #endif
77
78
79 }