dbt.c

来自「基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7」· C语言 代码 · 共 462 行 · 第 1/2 页

C
462
字号
/***********************************************************************
*                                                                      
*            Copyright (c) 1994-2000 Accelerated Technology, Inc.      
*                                                                      
* PROPRIETARY RIGHTS of Accelerated Technology are involved in the     
* subject matter of this material.  All manufacturing, reproduction,   
* use, and sales rights pertaining to this subject matter are governed 
* by the license agreement.  The recipient of this software implicitly 
* accepts the terms of the license.                                    
*                                                                      
************************************************************************/
/************************************************************************
*                                                                      
*   FILE NAME                                           VERSION         
*                                                                      
*       dbt.c                                           DBUG+  1.2      
*                                                                      
*   COMPONENT                                                            
*                                                                      
*       DEBUG       Nucleus PLUS Debugger                               
*                                                                      
*   DESCRIPTION                                                          
*                                                                      
*       This file contains Nucleus debugger routines.                   
*                                                                      
*   DATA STRUCTURES                                                      
*                                                                      
*       None                                                            
*                                                                      
*   FUNCTIONS                                                            
*                                                                      
*       DBT_Get_Char                                                    
*       DBT_Put_Char                                                    
*       DBT_ASCII_To_Integer                                            
*       DBT_HEX_ASCII_To_Long                                           
*       DBT_Name_Compare                                                
*       DBT_String_Compare                                              
*       DBT_String_Cat                                                  
*                                                                      
*   DEPENDENCIES                                                         
*                                                                      
*       stdio.h
*       stdlib.h
*       string.h
*       nucleus.h
*       sockdefs.h
*       externs.h
*       protocol.h
*       db_defs.h
*       db_extr.h
*       n_ansi.h
*       windat.h
*       tel_extr.h
*                                                                      
***********************************************************************/

/* Include the necessary files. */
#include  <stdio.h>
#include  <stdlib.h>
#include  <string.h>
#include  "plus/nucleus.h"
#include  "net/inc/sockdefs.h"
#include  "net/inc/externs.h"
#include  "demo/xprot/db_defs.h"
#include  "demo/xprot/db_extr.h"
#include  "telnet/inc/n_ansi.h"
#include  "telnet/inc/windat.h"
#include  "telnet/inc/tel_extr.h"
#include  "net/inc/ncl.h"

/* the following two MACROs is needed to adjust the size of output to match
    the size of terminal of client */
#undef  COL
#undef  ROW
#define COL his_side.width
#define ROW his_side.rows

/* we need set the maximun row and column for global variables */
#define  MAXCOL  85
#define  MAXROW  25

extern INT16 telnet_socket;

/***********************************************************************
*                                                                      
*   FUNCTION
*
*       DBT_Get_Char                                                   
*                                                                      
*   DESCRIPTION                                                         
*                                                                      
*       This function is used to pick up char from STDIN                
*                                                                      
*   INPUTS                                                              
*                                                                      
*       None                                                            
*                                                                      
*   OUTPUTS                                                             
*                                                                      
*       A Character                                               
*                                                                      
***********************************************************************/
CHAR  DBT_Get_Char()
{
CHAR  alpha, block = 1;

#ifdef NETWORK
    /* get a character from telnet client and block flag must be set, here */
    alpha = NU_Telnet_Get_Filtered_Char((INT)telnet_socket, (INT)block);

    if ((tn_session[telnet_socket]->echo) && (alpha != ERR_RETURN))
        DBT_Put_Char(alpha);
#else
     /* Simple polling to see if a character is present.  */
     while (!kbhit())
     {

         /* Sleep to free up time for the other processes.  */
         NU_Sleep(3);
     }

    /* Character is present - get a character.  */
    alpha =  (CHAR)getch();

    /* Determine if we need to echo the character back to the user.  */
    #ifdef DUPLEX
         DBT_Put_Char(alpha);
    #endif
#endif

    /* Return character to the caller.  */
    return(alpha);
}

/***********************************************************************
*                                                                      
*   FUNCTION
*
*       DBT_Put_Char                                                   
*                                                                      
*   DESCRIPTION                                                         
*                                                                      
*       This function will print a line, character by character.        
*                                                                      
*   INPUTS                                                              
*                                                                      
*       alpha       Character to print          
*                                                                      
*   OUTPUTS                                                             
*                                                                      
*       Character to STDOUT                                             
*                                                                      
***********************************************************************/
VOID DBT_Put_Char(CHAR alpha)
{
#ifdef NETWORK
    if (alpha=='\n')
        NU_Send((INT)telnet_socket, "\n\r", 2, 0);
    else if (alpha!='\r')
        NU_Send((INT)telnet_socket, &alpha, 1, 0);
#else
    putch(alpha);                        /* Prints value of alpha       */
#endif
}

/***********************************************************************
*                                                                      
*   FUNCTION
*
*       DBT_ASCII_To_Integer                                           
*                                                                      
*   DESCRIPTION                                                         
*                                                                      
*       This function will attempt to convert the input string into     
*       an integer and place the new integer in the specified location. 
*                                                                      
*   INPUTS                                                              
*                                                                      
*       string              String to convert           
*       num_ptr             Pointer to integer dest.    
*                                                                      
*   OUTPUTS                                                             
*                                                                      
*       return(DB_SUCCESS)  If successful conversion    
*       return(DB_ERROR)    If an error exists          
*       *num_ptr            Converted integer value     
*                                                                      
***********************************************************************/
INT  DBT_ASCII_To_Integer(CHAR *string, INT *num_ptr)
{

INT  i;
INT  status;

    /* Check for a sign character at the beginning of the string.  */
    if ((string[0] == '+') || (string[0] == '-'))

       /* Start checking at the next character.  */
       i =  1;
    else

       /* Start checking right at the beginning.  */
       i =  0;

    /* Check to see if the string contains a valid ASCII representation of
       an integer.  */
    do {

        /* Check for a valid character.  */
        if ((string[i] < '0') || (string[i] > '9'))

            /* An error is present.  */
            status =  DB_ERROR;
        else

            /* Everything is still okay.  */
            status =  DB_SUCCESS;

        /* Increment the character index in the string.  */
        i++;
    }  while ((i <= COL) && (string[i] != NUL) && (status == DB_SUCCESS));

    /* If the string represents an ASCII number convert it.  */
    if (status == DB_SUCCESS)

        /* Call the library routine "NU_ATOI" to convert the integer.  */
        *num_ptr =  NU_ATOI(string);

    /* Return status to the caller.  */
    return(status);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?