Exemplo n.º 1
0
void
prnt_Prompt(const char* prprompt)
{
    if (tty) {
	PROMPT_MOVE();
	(void) ClrEOL();
	SetStandout();
	(void) printf("%s", prprompt);
	(void) ClrStandout();
	(void) fflush(stdout);
    }
    return;
}
Exemplo n.º 2
0
void
prnt_Scroll(const char *fmt, ...)
{
    va_list ap;
    /* We use the same lock as malloc.  Sys-call or mem lock, really */
    bu_semaphore_acquire(BU_SEM_SYSCALL);		/* lock */
    va_start(ap, fmt);
    if (tty) {
	/* Only move cursor and scroll if newline is output.	*/
	static int newline = 1;
	if (CS != NULL) {
	    SetScrlReg(TOP_SCROLL_WIN, PROMPT_LINE - 1);
	    if (newline) {
		SCROLL_PR_MOVE();
		(void) ClrEOL();
	    }
	    (void)vfprintf(stdout, fmt, ap);
	    (void) ResetScrlReg();
	} else if (DL != NULL) {
	    if (newline) {
		SCROLL_DL_MOVE();
		(void) DeleteLn();
		SCROLL_PR_MOVE();
		(void) ClrEOL();
	    }
	    (void)vfprintf(stdout, fmt, ap);
	} else
	    (void)vfprintf(stdout, fmt, ap);

	/* End of line detected by existence of a newline. */
	newline = fmt[strlen(fmt)-1] == '\n';
	hmredraw();
    } else
	(void)vfprintf(stderr, fmt, ap);
    va_end(ap);
    bu_semaphore_release(BU_SEM_SYSCALL);		/* unlock */
    return;
}
Exemplo n.º 3
0
/*	g e t _ R e g i o n _ N a m e ( )
	TENEX-style name completion.
	Returns a linked-list of pointers to octree leaf nodes.
*/
OcList	*
get_Region_Name(char *inbuf, int bufsz, char *msg)
{
    static char	buffer[BUFSIZ];
    char	*p = buffer;
    int	c;
    OcList		*oclistp = OCLIST_NULL;
    if ( tty )
    {
	save_Tty( 0 );
	set_Raw( 0 );
	clr_Echo( 0 );
    }
    prnt_Prompt( msg );
    *p = NUL;
    do
    {
	(void) fflush( stdout );
	c = hm_getchar();
	switch ( c )
	{
	    case SP :
	    {
		if (	reg_triep == TRIE_NULL
			||	(oclistp = get_Trie( buffer, reg_triep ))
			== OCLIST_NULL
		    )
		    (void) putchar( BEL );
		for (; p > buffer; p-- )
		    (void) putchar( BS );
		(void) printf( "%s", buffer );
		(void) ClrEOL();
		(void) fflush( stdout );
		p += strlen( buffer );
		break;
	    }
	    case Ctrl('A') : /* Cursor to beginning of line.	*/
		if ( p == buffer )
		{
		    ring_Bell();
		    break;
		}
		for (; p > buffer; p-- )
		    (void) putchar( BS );
		break;
	    case Ctrl('B') :
	    case BS : /* Move cursor back one character.		*/
		if ( p == buffer )
		{
		    ring_Bell();
		    break;
		}
		(void) putchar( BS );
		--p;
		break;
	    case Ctrl('D') : /* Delete character under cursor.	*/
	    {
		char	*q = p;
		if ( *p == NUL )
		{
		    ring_Bell();
		    break;
		}
		for (; *q != NUL; ++q )
		{
		    *q = *(q+1);
		    (void) putchar( *q != NUL ? *q : SP );
		}
		for (; q > p; --q )
		    (void) putchar( BS );
		break;
	    }
	    case Ctrl('E') : /* Cursor to end of line.		*/
		if ( *p == NUL )
		{
		    ring_Bell();
		    break;
		}
		(void) printf( "%s", p );
		p += strlen( p );
		break;
	    case Ctrl('F') : /* Cursor forward one character.	*/
		if ( *p == NUL || p-buffer >= bufsz-2 )
		{
		    ring_Bell();
		    break;
		}
		(void) putchar( *p++ );
		break;
	    case Ctrl('G') : /* Abort input.			*/
		ring_Bell();
		prnt_Event( "Aborted." );
		goto	clean_return;
	    case Ctrl('K') : /* Erase from cursor to end of line.	*/
		if ( *p == NUL )
		{
		    ring_Bell();
		    break;
		}
		ClrEOL();
		*p = NUL;
		break;
	    case Ctrl('P') : /* Yank previous contents of "inbuf".	*/
	    {
		int	len = strlen( inbuf );
		if ( (p + len) - buffer >= BUFSIZ )
		{
		    ring_Bell();
		    break;
		}
		bu_strlcpy( p, inbuf, (size_t)bufsz );
		printf( "%s", p );
		p += len;
		break;
	    }
	    case Ctrl('U') : /* Erase from start of line to cursor.	*/
		if ( p == buffer )
		{
		    ring_Bell();
		    break;
		}
		for (; p > buffer; --p )
		{
		    char	*q = p;
		    (void) putchar( BS );
		    for (; *(q-1) != NUL; ++q )
		    {
			*(q-1) = *q;
			(void) putchar( *q != NUL ? *q : SP );
		    }
		    for (; q > p; --q )
			(void) putchar( BS );
		}
		break;
	    case Ctrl('R') : /* Print line, cursor doesn't move.	*/
	    {
		int	i;
		if ( buffer[0] == NUL )
		    break;
		for ( i = p - buffer; i > 0; i-- )
		    (void) putchar( BS );
		(void) printf( "%s", buffer );
		for ( i = strlen( buffer ) - (p - buffer); i > 0; i-- )
		    (void) putchar( BS );
		break;
	    }
	    case DEL : /* Delete character behind cursor.		*/
	    {
		char	*q = p;
		if ( p == buffer )
		{
		    ring_Bell();
		    break;
		}
		(void) putchar( BS );
		for (; *(q-1) != NUL; ++q )
		{
		    *(q-1) = *q;
		    (void) putchar( *q != NUL ? *q : SP );
		}
		for (; q > p; --q )
		    (void) putchar( BS );
		p--;
		break;
	    }
	    case CR :
	    case LF :
	    case EOF :
		if (	reg_triep == TRIE_NULL
			||	(oclistp = get_Trie( buffer, reg_triep ))
			== OCLIST_NULL
		    )
		{
		    (void) putchar( BEL );
		    break;
		}
		else
		{
		    bu_strlcpy( inbuf, buffer, (size_t)bufsz );
		    prnt_Event( "" );
		    goto clean_return;
		}
	    case Ctrl('V') :
		/* Escape character, do not process next char.	*/
		c = hm_getchar();
		/* Fall through to default case!		*/
	    default : /* Insert character at cursor.		*/
	    {
		char	*q = p;
		int	len = strlen( p );
		/* Scroll characters forward.			*/
		if ( c >= NUL && c < SP )
		    (void) printf( "%s", char_To_String( c ) );
		else
		    (void) putchar( c );
		for (; len >= 0; len--, q++ )
		    (void) putchar( *q == NUL ? SP : *q );
		for (; q > p; q-- )
		{
		    (void) putchar( BS );
		    *q = *(q-1);
		}
		*p++ = c;
		break;
	    }
	} /* End switch. */
    }
    while ( strlen( buffer ) < BUFSIZ);
    ring_Bell();
    prnt_Event( "Buffer full." );
    clean_return :
	prnt_Prompt( "" );
    if ( tty )
	reset_Tty( 0 );
    return	oclistp;
}