home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 September
/
pcwk_09_96.iso
/
demo
/
wgelectr
/
pk51demo
/
files.2
/
EXAMPLES
/
TDP
/
CMDBUILD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-08
|
2KB
|
81 lines
/*------------------------------------------------------------------------------
CMDBUILD.C: Routine to build up serial commands.
Copyright 1995 KEIL Software, Inc.
------------------------------------------------------------------------------*/
#include <stdlib.h>
#include <ctype.h>
#include "tdp.h"
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
xdata char cmdbuf [1 + MAX_CMD_LEN];
xdata unsigned char cmdndx;
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void cmdb_init (void)
{
cmdndx = 0;
cmdbuf [0] = '\0';
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void cmdb_prompt (void)
{
com_puts ("COMMAND: ");
com_puts (cmdbuf);
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
const char *cmdb_scan (void)
{
int c;
/*------------------------------------------------
------------------------------------------------*/
while (1)
{
if ((c = com_getchar ()) == -1)
break;
if (c == '\r')
{
com_puts ("\r\n");
return (cmdbuf);
}
if ((c == '\b') && (cmdndx != 0))
{
com_puts ("\b \b");
cmdbuf [--cmdndx] = '\0';
continue;
}
if (!isprint (c))
{
BEEPCHAR:
com_putchar ('\x7');
continue;
}
if (cmdndx >= MAX_CMD_LEN)
goto BEEPCHAR;
com_putchar (c);
cmdbuf [cmdndx++] = (unsigned char) c;
cmdbuf [cmdndx] = '\0';
}
/*------------------------------------------------
------------------------------------------------*/
return (NULL);
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/