1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
20 * Encoding conversion.
23 #define ENCODING_UTF8 "UTF-8"
27 struct encoding
*encoding_open(const char *fromcode
);
28 char *encoding_convert(struct encoding
*encoding
, char *line
);
29 const char *encoding_iconv(iconv_t iconv_out
, const char *string
, size_t length
);
30 struct encoding
*get_path_encoding(const char *path
, struct encoding
*default_encoding
);
32 extern char encoding_arg
[];
33 extern struct encoding
*default_encoding
;
36 * Executing external commands.
40 IO_RD_FORWARD_STDIN
, /* Forward stdin from parent process to child. */
41 IO_RD_WITH_STDERR
, /* Redirect stderr to stdin. */
45 IO_FD
, /* File descriptor based IO. */
46 IO_BG
, /* Execute command in the background. */
47 IO_FG
, /* Execute command with same std{in,out,err}. */
48 IO_RD
, /* Read only fork+exec IO. */
49 IO_WR
, /* Write only fork+exec IO. */
50 IO_AP
, /* Append fork+exec output to file. */
54 int pipe
; /* Pipe end for reading or writing. */
55 pid_t pid
; /* PID of spawned process. */
56 int error
; /* Error status. */
57 char *buf
; /* Read buffer. */
58 size_t bufalloc
; /* Allocated buffer size. */
59 size_t bufsize
; /* Buffer content size. */
60 char *bufpos
; /* Current buffer position. */
61 unsigned int eof
:1; /* Has end of file been reached. */
62 unsigned int span
:1; /* Support commands spanning multiple lines. */
63 int status
:8; /* Status exit code. */
66 typedef int (*io_read_fn
)(char *, size_t, char *, size_t, void *data
);
68 bool io_open(struct io
*io
, const char *fmt
, ...) PRINTF_LIKE(2, 3);
69 bool io_from_string(struct io
*io
, const char *str
);
70 bool io_kill(struct io
*io
);
71 bool io_done(struct io
*io
);
72 bool io_exec(struct io
*io
, enum io_type type
, const char *dir
, char * const env
[], const char *argv
[], int custom
);
73 bool io_run(struct io
*io
, enum io_type type
, const char *dir
, char * const env
[], const char *argv
[]);
74 bool io_run_bg(const char **argv
);
75 bool io_run_fg(const char **argv
, const char *dir
);
76 bool io_run_append(const char **argv
, int fd
);
77 bool io_eof(struct io
*io
);
78 int io_error(struct io
*io
);
79 char * io_strerror(struct io
*io
);
80 bool io_can_read(struct io
*io
, bool can_block
);
81 ssize_t
io_read(struct io
*io
, void *buf
, size_t bufsize
);
82 char * io_get(struct io
*io
, int c
, bool can_read
);
83 bool io_write(struct io
*io
, const void *buf
, size_t bufsize
);
84 bool io_printf(struct io
*io
, const char *fmt
, ...) PRINTF_LIKE(2, 3);
85 bool io_read_buf(struct io
*io
, char buf
[], size_t bufsize
);
86 bool io_run_buf(const char **argv
, char buf
[], size_t bufsize
);
87 int io_load(struct io
*io
, const char *separators
,
88 io_read_fn read_property
, void *data
);
89 int io_load_span(struct io
*io
, const char *separators
,
90 size_t *lineno
, io_read_fn read_property
, void *data
);
91 int io_run_load(const char **argv
, const char *separators
,
92 io_read_fn read_property
, void *data
);
93 char *io_memchr(struct io
*io
, char *data
, int c
);
95 const char *get_temp_dir(void);
97 bool io_trace(const char *fmt
, ...);
100 /* vim: set ts=8 sw=8 noexpandtab: */