treg.c - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
treg.c (816B)
---
1 #include <ctype.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "vi.h"
5
6 static char *bufs[256];
7 static int lnmode[256];
8
9 char *reg_get(int c, int *ln)
10 {
11 *ln = lnmode[c];
12 return bufs[c];
13 }
14
15 static void reg_putraw(int c, char *s, int ln)
16 {
17 char *pre = isupper(c) && bufs[tolower(c)] ? bufs[tolower(c)] : "";
18 char *buf = malloc(strlen(pre) + strlen(s) + 1);
19 strcpy(buf, pre);
20 strcat(buf, s);
21 free(bufs[tolower(c)]);
22 bufs[tolower(c)] = buf;
23 lnmode[tolower(c)] = ln;
24 }
25
26 void reg_put(int c, char *s, int ln)
27 {
28 int i, i_ln;
29 char *i_s;
30 if (ln || strchr(s, '\n')) {
31 for (i = 8; i > 0; i--)
32 if ((i_s = reg_get('0' + i, &i_ln)))
33 reg_putraw('0' + i + 1, i_s, i_ln);
34 reg_putraw('1', s, ln);
35 }
36 reg_putraw(c, s, ln);
37 }
38
39 void reg_done(void)
40 {
41 int i;
42 for (i = 0; i < LEN(bufs); i++)
43 free(bufs[i]);
44 }