2 * Copyright (c) 2012, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __BREEDLINE_H__
31 #define __BREEDLINE_H__
33 #include <breedline/macros.h>
37 /** Default history buffer size (in number of items). */
38 #define BRL_DEFAULT_HISTORY 64
40 /** Type for opaque breedline context. */
42 typedef struct brl_s brl_t;
44 /** Create a new breedline context for the given file descriptor. */
45 brl_t *brl_create(int fd, const char *prompt);
47 /** Destroy the given context. */
48 void brl_destroy(brl_t *brl);
50 /** Set breedline prompt. */
51 int brl_set_prompt(brl_t *brl, const char *prompt);
53 /** Hide breedline prompt. */
54 void brl_hide_prompt(brl_t *brl);
56 /** Show breedline prompt. */
57 void brl_show_prompt(brl_t *brl);
59 /** Limit the size of history to the given number of entries. */
60 int brl_limit_history(brl_t *brl, size_t size);
62 /** Read a single line of input and put it to the given buffer. */
63 int brl_read_line(brl_t *brl, char *buf, size_t size);
65 /** Add an entry to history. Replaces oldest entry if history buffer is full. */
66 int brl_add_history(brl_t *brl, const char *entry);
68 /** In put delivery callback type, used when running in mainloop mode. */
69 typedef void (*brl_line_cb_t)(brl_t *brl, const char *line, void *user_data);
71 /** Breedline mainloop subset abstraction. */
73 void *(*add_watch)(void *ml, int fd,
74 void (*cb)(int fd, int events, void *user_data),
76 void (*del_watch)(void *w);
79 /** Set up the given context to be pumped by the given mainloop. */
80 int brl_use_mainloop(brl_t *brl, void *ml, brl_mainloop_ops_t *ops,
81 brl_line_cb_t cb, void *user_data);
83 /** Memory allocation operations. */
85 void *(*allocfn)(size_t size, const char *file, int line, const char *func);
86 void *(*reallocfn)(void *ptr, size_t size, const char *file, int line,
88 char *(*strdupfn)(const char *str, const char *file, int line,
90 void (*freefn)(void *ptr, const char *file, int line, const char *func);
93 /** Override the default memory allocator. */
94 int brl_set_allocator(brl_allocator_t *allocator);
98 #endif /* __BREEDLINE_H__ */