Nut/OS  4.10.3
API Reference
edline.h
Go to the documentation of this file.
00001 #ifndef _GORP_EDLINE_EDLINE_H_
00002 #define _GORP_EDLINE_EDLINE_H_
00003 
00004 /*
00005  * Copyright 2009 by egnite GmbH
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  */
00037 
00038 #include <compiler.h>
00039 #include <stdint.h>
00040 
00041 /*
00042  * \file include/gorp/edline.h
00043  * \brief Simple line editor definitions.
00044  *
00045  * \verbatim
00046  * $Id$
00047  * \endverbatim
00048  */
00049 
00054 
00063 #define EDIT_MODE_ECHO      0x0001
00064 
00065 #define EDIT_MODE_BINARY    0x0002
00066 
00067 #define EDIT_MODE_HISTORY   0x0004
00068 
00076 #ifndef EDIT_KEY_IGNORE
00077 
00078 #define EDIT_KEY_IGNORE  0x00 /* CTRL-@ '\0' */
00079 #endif
00080 #ifndef EDIT_KEY_HOME
00081 
00082 #define EDIT_KEY_HOME    0x01 /* CTRL-A */
00083 #endif
00084 #ifndef EDIT_KEY_LEFT
00085 
00086 #define EDIT_KEY_LEFT    0x02 /* CTRL-B */
00087 #endif
00088 #ifndef EDIT_KEY_END
00089 
00090 #define EDIT_KEY_END     0x05 /* CTRL-E */
00091 #endif
00092 #ifndef EDIT_KEY_RIGHT
00093 
00094 #define EDIT_KEY_RIGHT   0x06 /* CTRL-F */
00095 #endif
00096 #ifndef EDIT_KEY_REMOVE
00097 
00098 #define EDIT_KEY_REMOVE  0x08 /* CTRL-H '\b' */
00099 #endif
00100 #ifndef EDIT_KEY_ENTER
00101 
00102 #define EDIT_KEY_ENTER   0x0a /* CTRL-J '\n' */
00103 #endif
00104 #ifndef EDIT_DISABLE_HISTORY
00105 #ifndef EDIT_KEY_UP
00106 
00107 #define EDIT_KEY_UP      0x12 /* CTRL-R */
00108 #endif
00109 #ifndef EDIT_KEY_DOWN
00110 
00111 #define EDIT_KEY_DOWN    0x16 /* CTRL-V */
00112 #endif
00113 #ifndef EDIT_KEY_RESTORE
00114 
00115 #define EDIT_KEY_RESTORE 0x1b /* CTRL-[ '\e' */
00116 #endif
00117 #endif /* EDIT_DISABLE_HISTORY */
00118 
00126 #ifndef EDIT_CHAR_SPACE
00127 
00128 #define EDIT_CHAR_SPACE ' '
00129 #endif
00130 #ifndef EDIT_CHAR_BACKSPACE
00131 
00132 #define EDIT_CHAR_BACKSPACE '\b'
00133 #endif
00134 #ifndef EDIT_CHAR_ALARM
00135 
00136 #define EDIT_CHAR_ALARM '\a'
00137 #endif
00138 #ifndef EDIT_STR_EOL
00139 
00140 #define EDIT_STR_EOL    "\r\n"
00141 #endif
00142 
00144 #ifndef EDIT_DISABLE_HISTORY
00145 
00146 typedef struct _EDITHISTORY {
00148     int hist_siz;
00150     char **hist_tab;
00151 } EDITHISTORY;
00152 #endif
00153 
00155 typedef int (*EDLINEGET) (void *);
00157 typedef int (*EDLINEPUT) (void *, int);
00159 typedef int (*EDLINEMAP) (int, int *);
00160 
00162 typedef struct _EDLINE {
00164     EDLINEGET el_get;
00166     void *el_iparm;
00168     EDLINEPUT el_put;
00170     void *el_oparm;
00172     EDLINEMAP el_map;
00174     uint_fast16_t el_mode;
00176     int el_seq;
00177 #ifndef EDIT_DISABLE_HISTORY
00178 
00179     EDITHISTORY *el_hist;
00180 #endif
00181 } EDLINE;
00182 
00185 __BEGIN_DECLS
00186 /* */
00187 extern EDLINE *EdLineOpen(uint16_t mode);
00188 extern void EdLineClose(EDLINE *el);
00189 extern int EdLineRead(EDLINE *el, char *buf, int siz);
00190 
00191 #ifndef EDIT_DISABLE_HISTORY
00192 extern EDITHISTORY *EditHistoryCreate(int siz);
00193 extern void EditHistoryDestroy(EDITHISTORY *hist);
00194 extern void EditHistorySet(EDITHISTORY *hist, int idx, char *buf);
00195 extern int EditHistoryGet(EDITHISTORY *hist, int idx, char *buf, int siz);
00196 extern void EditHistoryInsert(EDITHISTORY *hist, int idx, char *buf);
00197 #endif
00198 
00199 extern void EdLineRegisterKeymap(EDLINE *el, EDLINEMAP map);
00200 extern int EdLineKeyMap(int key, int *seq);
00201 extern int EdLineKeyMapVt100(int key, int *seq);
00202 
00203 extern void EdLineRegisterInput(EDLINE *el, EDLINEGET get, void *iparm);
00204 extern void EdLineRegisterOutput(EDLINE *el, EDLINEPUT put, void *oparm);
00205 
00206 __END_DECLS
00207 /* */
00208 #endif