15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
55129044dSC.J. Collier *   All rights reserved.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier/*
355129044dSC.J. Collier * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
365129044dSC.J. Collier * All rights reserved.
375129044dSC.J. Collier * Redistribution and use in source and binary forms, with or without
385129044dSC.J. Collier * modification, are permitted provided that the following conditions are met:
395129044dSC.J. Collier *
405129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
415129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
425129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
435129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in the
445129044dSC.J. Collier *       documentation and/or other materials provided with the distribution.
455129044dSC.J. Collier *     * Neither the name of the University of California, Berkeley nor the
465129044dSC.J. Collier *       names of its contributors may be used to endorse or promote products
475129044dSC.J. Collier *       derived from this software without specific prior written permission.
485129044dSC.J. Collier *
495129044dSC.J. Collier * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
505129044dSC.J. Collier * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
515129044dSC.J. Collier * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
525129044dSC.J. Collier * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
535129044dSC.J. Collier * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
545129044dSC.J. Collier * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
555129044dSC.J. Collier * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
565129044dSC.J. Collier * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
575129044dSC.J. Collier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
585129044dSC.J. Collier * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
595129044dSC.J. Collier */
605129044dSC.J. Collier
615129044dSC.J. Collier#ifndef _CMDLINE_VT100_H_
625129044dSC.J. Collier#define _CMDLINE_VT100_H_
635129044dSC.J. Collier
645129044dSC.J. Collier#include <stdint.h>
655129044dSC.J. Collier
665129044dSC.J. Collier#ifdef __cplusplus
675129044dSC.J. Collierextern "C" {
685129044dSC.J. Collier#endif
695129044dSC.J. Collier
705129044dSC.J. Collier#define vt100_bell         "\007"
715129044dSC.J. Collier#define vt100_bs           "\010"
725129044dSC.J. Collier#define vt100_bs_clear     "\010 \010"
735129044dSC.J. Collier#define vt100_tab          "\011"
745129044dSC.J. Collier#define vt100_crnl         "\012\015"
755129044dSC.J. Collier#define vt100_clear_right  "\033[0K"
765129044dSC.J. Collier#define vt100_clear_left   "\033[1K"
775129044dSC.J. Collier#define vt100_clear_down   "\033[0J"
785129044dSC.J. Collier#define vt100_clear_up     "\033[1J"
795129044dSC.J. Collier#define vt100_clear_line   "\033[2K"
805129044dSC.J. Collier#define vt100_clear_screen "\033[2J"
815129044dSC.J. Collier#define vt100_up_arr       "\033\133\101"
825129044dSC.J. Collier#define vt100_down_arr     "\033\133\102"
835129044dSC.J. Collier#define vt100_right_arr    "\033\133\103"
845129044dSC.J. Collier#define vt100_left_arr     "\033\133\104"
855129044dSC.J. Collier#define vt100_multi_right  "\033\133%uC"
865129044dSC.J. Collier#define vt100_multi_left   "\033\133%uD"
875129044dSC.J. Collier#define vt100_suppr        "\033\133\063\176"
885129044dSC.J. Collier#define vt100_home         "\033M\033E"
895129044dSC.J. Collier#define vt100_word_left    "\033\142"
905129044dSC.J. Collier#define vt100_word_right   "\033\146"
915129044dSC.J. Collier
925129044dSC.J. Collier/* Result of parsing : it must be synchronized with
935129044dSC.J. Collier * cmdline_vt100_commands[] in vt100.c */
945129044dSC.J. Collier#define CMDLINE_KEY_UP_ARR 0
955129044dSC.J. Collier#define CMDLINE_KEY_DOWN_ARR 1
965129044dSC.J. Collier#define CMDLINE_KEY_RIGHT_ARR 2
975129044dSC.J. Collier#define CMDLINE_KEY_LEFT_ARR 3
985129044dSC.J. Collier#define CMDLINE_KEY_BKSPACE 4
995129044dSC.J. Collier#define CMDLINE_KEY_RETURN 5
1005129044dSC.J. Collier#define CMDLINE_KEY_CTRL_A 6
1015129044dSC.J. Collier#define CMDLINE_KEY_CTRL_E 7
1025129044dSC.J. Collier#define CMDLINE_KEY_CTRL_K 8
1035129044dSC.J. Collier#define CMDLINE_KEY_CTRL_Y 9
1045129044dSC.J. Collier#define CMDLINE_KEY_CTRL_C 10
1055129044dSC.J. Collier#define CMDLINE_KEY_CTRL_F 11
1065129044dSC.J. Collier#define CMDLINE_KEY_CTRL_B 12
1075129044dSC.J. Collier#define CMDLINE_KEY_SUPPR 13
1085129044dSC.J. Collier#define CMDLINE_KEY_TAB 14
1095129044dSC.J. Collier#define CMDLINE_KEY_CTRL_D 15
1105129044dSC.J. Collier#define CMDLINE_KEY_CTRL_L 16
1115129044dSC.J. Collier#define CMDLINE_KEY_RETURN2 17
1125129044dSC.J. Collier#define CMDLINE_KEY_META_BKSPACE 18
1135129044dSC.J. Collier#define CMDLINE_KEY_WLEFT 19
1145129044dSC.J. Collier#define CMDLINE_KEY_WRIGHT 20
1155129044dSC.J. Collier#define CMDLINE_KEY_HELP 21
1165129044dSC.J. Collier#define CMDLINE_KEY_CTRL_W 22
1175129044dSC.J. Collier#define CMDLINE_KEY_CTRL_P 23
1185129044dSC.J. Collier#define CMDLINE_KEY_CTRL_N 24
1195129044dSC.J. Collier#define CMDLINE_KEY_META_D 25
1205129044dSC.J. Collier
1215129044dSC.J. Collierextern const char *cmdline_vt100_commands[];
1225129044dSC.J. Collier
1235129044dSC.J. Collierenum cmdline_vt100_parser_state {
1245129044dSC.J. Collier	CMDLINE_VT100_INIT,
1255129044dSC.J. Collier	CMDLINE_VT100_ESCAPE,
1265129044dSC.J. Collier	CMDLINE_VT100_ESCAPE_CSI
1275129044dSC.J. Collier};
1285129044dSC.J. Collier
1295129044dSC.J. Collier#define CMDLINE_VT100_BUF_SIZE 8
1305129044dSC.J. Collierstruct cmdline_vt100 {
1315129044dSC.J. Collier	uint8_t bufpos;
1325129044dSC.J. Collier	char buf[CMDLINE_VT100_BUF_SIZE];
1335129044dSC.J. Collier	enum cmdline_vt100_parser_state state;
1345129044dSC.J. Collier};
1355129044dSC.J. Collier
1365129044dSC.J. Collier/**
1375129044dSC.J. Collier * Init
1385129044dSC.J. Collier */
1395129044dSC.J. Colliervoid vt100_init(struct cmdline_vt100 *vt);
1405129044dSC.J. Collier
1415129044dSC.J. Collier/**
1425129044dSC.J. Collier * Input a new character.
1435129044dSC.J. Collier * Return -1 if the character is not part of a control sequence
1445129044dSC.J. Collier * Return -2 if c is not the last char of a control sequence
1455129044dSC.J. Collier * Else return the index in vt100_commands[]
1465129044dSC.J. Collier */
1475129044dSC.J. Collierint vt100_parser(struct cmdline_vt100 *vt, char c);
1485129044dSC.J. Collier
1495129044dSC.J. Collier#ifdef __cplusplus
1505129044dSC.J. Collier}
1515129044dSC.J. Collier#endif
1525129044dSC.J. Collier
1535129044dSC.J. Collier#endif
154