Skip to content

Commit

Permalink
[CORE] Add history support to vmm_cgets and vmm_gets
Browse files Browse the repository at this point in the history
vmm_cgets and vmm_gets now takes an additional pointer to a vmm_history object.
If non-NULL the history object is used for storing and accessing list of
strings entered on use of UP/DN arrow keys.

Signed-off-by: Anup Patel <anup@brainfault.org>
  • Loading branch information
sukantoghosh authored and avpatel committed Dec 23, 2012
1 parent b2d76d3 commit 1bf927e
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 60 deletions.
37 changes: 31 additions & 6 deletions core/include/vmm_stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Expand All @@ -27,6 +27,7 @@
#include <vmm_compiler.h>
#include <vmm_spinlocks.h>
#include <vmm_chardev.h>
#include <vmm_heap.h>
#include <libs/stacktrace.h>

#define BUG_ON(x) \
Expand Down Expand Up @@ -60,6 +61,26 @@
(x); \
})

/** Representation of input history for use with (c)gets */
struct vmm_history {
int length; /* Number of entries in the history table */
int width; /* Width of each entry */
char **table; /* Circular History Table */
int tail; /* Last entry */
};

/** Initialize vmm_history pointer h having l length and w width */
#define INIT_HISTORY(h,l,w) \
{ int iter = 0; \
(h)->length = (l); \
(h)->width = (w); \
(h)->table = vmm_malloc((l) * sizeof(char *)); \
for (iter = 0; iter < (l) ; iter++) { \
(h)->table[iter] = vmm_malloc((w) * sizeof(char));\
(h)->table[iter][0] = '\0'; \
} \
(h)->tail = 0; \
}

/** Check if a character is a control character */
bool vmm_iscontrol(char c);
Expand Down Expand Up @@ -106,11 +127,15 @@ char vmm_cgetc(struct vmm_chardev *cdev) ;
/** Get character from default device */
char vmm_getc(void);

/** Get string from character device */
char *vmm_cgets(struct vmm_chardev *cdev, char *s, int maxwidth, char endchar);
/** Get string from character device
* If history is NULL does not support UP/DN keys */
char *vmm_cgets(struct vmm_chardev *cdev, char *s, int maxwidth,
char endchar, struct vmm_history *history);

/** Get string from default device */
char *vmm_gets(char *s, int maxwidth, char endchar);
/** Get string from default device
* If history is NULL does not support UP/DN keys */
char *vmm_gets(char *s, int maxwidth, char endchar,
struct vmm_history *history);

/** Get default character device used by stdio */
struct vmm_chardev *vmm_stdio_device(void);
Expand Down
Loading

0 comments on commit 1bf927e

Please sign in to comment.