X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Flib%2Fcmdline_rdline.h;h=87a17890b1679a5480d7ebdf26bb8e8e48b1acb8;hb=b1d5b169352e57df3fc14c51ffad4b83f3e5613f;hp=20f7652e1575bc6946463866007a3e8d53a91761;hpb=c60ed50ac1449a2b2bccc33598d1f68458a36fb1;p=libcmdline.git diff --git a/src/lib/cmdline_rdline.h b/src/lib/cmdline_rdline.h index 20f7652..87a1789 100644 --- a/src/lib/cmdline_rdline.h +++ b/src/lib/cmdline_rdline.h @@ -1,3 +1,37 @@ +/*- + * Copyright (c) <2010>, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + /* * Copyright (c) 2009, Olivier MATZ * All rights reserved. @@ -54,28 +88,6 @@ #include #include -#define vt100_bell "\007" -#define vt100_bs "\010" -#define vt100_bs_clear "\010 \010" -#define vt100_tab "\011" -#define vt100_crnl "\012\015" -#define vt100_clear_right "\033[0K" -#define vt100_clear_left "\033[1K" -#define vt100_clear_down "\033[0J" -#define vt100_clear_up "\033[1J" -#define vt100_clear_line "\033[2K" -#define vt100_clear_screen "\033[2J" -#define vt100_up_arr "\033\133\101" -#define vt100_down_arr "\033\133\102" -#define vt100_right_arr "\033\133\103" -#define vt100_left_arr "\033\133\104" -#define vt100_multi_right "\033\133%uC" -#define vt100_multi_left "\033\133%uD" -#define vt100_suppr "\033\133\063\176" -#define vt100_home "\033M\033E" -#define vt100_word_left "\033\142" -#define vt100_word_right "\033\146" - /* configuration */ #define RDLINE_BUF_SIZE 256 #define RDLINE_PROMPT_SIZE 32 @@ -86,11 +98,12 @@ enum rdline_status { RDLINE_INIT, RDLINE_RUNNING, + RDLINE_EXITED }; struct rdline; -typedef void (rdline_write_char_t)(struct rdline *rdl, char); +typedef int (rdline_write_char_t)(struct rdline *rdl, char); typedef void (rdline_validate_t)(struct rdline *rdl, const char *buf, unsigned int size); typedef int (rdline_complete_t)(struct rdline *rdl, const char *buf, @@ -162,7 +175,14 @@ void rdline_newline(struct rdline *rdl, const char *prompt); void rdline_stop(struct rdline *rdl); /** - * Restart after a call to rdline_stop() + * Same than rdline_stop() except that next calls to rdline_char_in() + * will return RDLINE_RES_EXITED. + * \param rdl A pointer to a struct rdline + */ +void rdline_quit(struct rdline *rdl); + +/** + * Restart after a call to rdline_stop() or rdline_quit() * \param rdl A pointer to a struct rdline */ void rdline_restart(struct rdline *rdl); @@ -174,13 +194,21 @@ void rdline_restart(struct rdline *rdl); void rdline_redisplay(struct rdline *rdl); +/* return status for rdline_char_in() */ +#define RDLINE_RES_SUCCESS 0 +#define RDLINE_RES_VALIDATED 1 +#define RDLINE_RES_COMPLETE 2 +#define RDLINE_RES_NOT_RUNNING -1 +#define RDLINE_RES_EOF -2 +#define RDLINE_RES_EXITED -3 + /** * append a char to the readline buffer. - * Return 1 when the line has been validated. - * Return 2 when the user asked to complete the buffer. - * Return -1 if it is not running. - * Return -2 if EOF (ctrl-d on an empty line). - * Else return 0. + * Return RDLINE_RES_VALIDATE when the line has been validated. + * Return RDLINE_RES_COMPLETE when the user asked to complete the buffer. + * Return RDLINE_RES_NOT_RUNNING if it is not running. + * Return RDLINE_RES_EOF if EOF (ctrl-d on an empty line). + * Else return RDLINE_RES_SUCCESS. * XXX error case when the buffer is full ? * * \param rdl A pointer to a struct rdline