blob: af15d3e8f21f022e8088f3c363d44bbb0cddc05f [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9/*
10 * if_perlsfio.c: Special I/O functions for Perl interface.
11 */
12
Bram Moolenaar2ab2e862019-12-04 21:24:53 +010013#define _memory_h // avoid memset redeclaration
14#define IN_PERL_FILE // don't include if_perl.pro from prot.h
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
16#include "vim.h"
17
18#if defined(USE_SFIO) || defined(PROTO)
19
Bram Moolenaar2ab2e862019-12-04 21:24:53 +010020#ifndef USE_SFIO // just generating prototypes
Bram Moolenaar071d4272004-06-13 20:20:40 +000021# define Sfio_t int
22# define Sfdisc_t int
23#endif
24
25#define NIL(type) ((type)0)
26
27 static int
Bram Moolenaar68c2f632016-01-30 17:24:07 +010028sfvimwrite(
Bram Moolenaar2ab2e862019-12-04 21:24:53 +010029 Sfio_t *f, // stream involved
30 char *buf, // buffer to read from
31 int n, // number of bytes to write
32 Sfdisc_t *disc) // discipline
Bram Moolenaar071d4272004-06-13 20:20:40 +000033{
34 char_u *str;
35
36 str = vim_strnsave((char_u *)buf, n);
37 if (str == NULL)
38 return 0;
39 msg_split((char *)str);
40 vim_free(str);
41
42 return n;
43}
44
45/*
46 * sfdcnewnvi --
47 * Create Vim discipline
48 */
49 Sfdisc_t *
Bram Moolenaar68c2f632016-01-30 17:24:07 +010050sfdcnewvim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000051{
52 Sfdisc_t *disc;
53
Bram Moolenaarc799fe22019-05-28 23:08:19 +020054 disc = ALLOC_ONE(Sfdisc_t);
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 if (disc == NULL)
56 return NULL;
57
58 disc->readf = (Sfread_f)NULL;
59 disc->writef = sfvimwrite;
60 disc->seekf = (Sfseek_f)NULL;
61 disc->exceptf = (Sfexcept_f)NULL;
62
63 return disc;
64}
65
Bram Moolenaar2ab2e862019-12-04 21:24:53 +010066#endif // USE_SFIO