mdb_cmdbuf.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The MDB command buffer is a simple structure that keeps track of the
* command history list, and provides operations to manipulate the current
* buffer according to the various emacs editing options. The terminal
* code uses this code to keep track of the actual contents of the command
* line, and then uses this content to perform redraw operations.
*/
#include <strings.h>
#include <stdio.h>
#include <ctype.h>
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_cmdbuf.h>
#include <mdb/mdb_debug.h>
static void
{
}
void
{
size_t i;
/*
* This is pretty weak, but good enough for the moment: just allocate
* BUFSIZ-sized chunks in advance for every history element. Later
* it would be nice to replace this with either code that allocates
* space for the history list on-the-fly so as not to waste so much
* memory, or that keeps a mapped history file like the shell.
*/
cmd->cmd_buflen = 0;
cmd->cmd_bufidx = 0;
}
void
{
size_t i;
for (i = 0; i < cmd->cmd_histlen; i++)
}
int
{
}
int
{
return (cmd->cmd_bufidx == 0);
}
int
{
}
int
{
if (c == '\t') {
int i;
for (i = 0; i < CMDBUF_TABLEN; i++)
return (0);
}
return (-1);
}
if (c < ' ' || c > '~')
return (-1);
cmd->cmd_buflen++;
return (0);
}
return (-1);
}
const char *
{
/*
* Don't bother inserting empty buffers into the history ring.
*/
else
}
cmd->cmd_bufidx = 0;
cmd->cmd_buflen = 0;
return ((const char *)cmd->cmd_linebuf);
}
return (NULL);
}
/*ARGSUSED*/
int
{
if (cmd->cmd_bufidx > 0) {
}
cmd->cmd_bufidx--;
cmd->cmd_buflen--;
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
}
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
cmd->cmd_bufidx++;
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
if (cmd->cmd_bufidx > 0) {
cmd->cmd_bufidx--;
return (0);
}
return (-1);
}
int
{
} else {
}
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
cmd->cmd_bufidx = 0;
return (0);
}
/*ARGSUSED*/
int
{
return (0);
}
static size_t
{
i++;
i++;
while (i < cmd->cmd_buflen &&
i++;
return (i);
}
/*ARGSUSED*/
int
{
return (-1);
return (0);
}
/*ARGSUSED*/
int
{
size_t i;
return (-1);
i = fwdword_index(cmd);
cmd->cmd_buflen - i);
return (0);
}
static size_t
{
i--;
i--;
i--;
if (i != 0)
i++;
return (i);
}
/*ARGSUSED*/
int
{
if (cmd->cmd_bufidx == 0)
return (-1);
return (0);
}
/*ARGSUSED*/
int
{
size_t i;
if (cmd->cmd_bufidx == 0)
return (-1);
i = backword_index(cmd);
cmd->cmd_bufidx = i;
return (0);
}
/*ARGSUSED*/
int
{
return (0);
}
/*ARGSUSED*/
int
{
cmd->cmd_buflen = 0;
cmd->cmd_bufidx = 0;
return (0);
}
/*ARGSUSED*/
int
{
}
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
} else {
}
return (0);
}
return (-1);
}
/*ARGSUSED*/
int
{
ssize_t i, n;
if (cmd->cmd_buflen != 0) {
}
if (--i < 0)
return (0);
}
}
cmd->cmd_bufidx = 0;
cmd->cmd_buflen = 0;
return (-1);
}