RT-Thread finsh源码分析: finsh_var.h


/*
 *  Variable implementation in finsh shell.
 *
 * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
 *
 *  This file is part of RT-Thread (http://www.rt-thread.org)
 *  Maintainer: bernard.xiong <bernard.xiong at gmail.com>
 *
 *  All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, 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.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-03-22     Bernard      first version
 */
#ifndef __FINSH_VAR_H__
#define __FINSH_VAR_H__

#include <finsh.h>

/*
 * The variable in finsh is put in data segment as a global variable.
 * The 'finsh_var' structure presents the structure of variable in data segment.
 */

/*
 * finsh_var是全局变量,属于数据段
 */
struct finsh_var
{
        //数组长度加1,可以在循环中避免>=或者<=临界问题,增加代码可读性
char name[FINSH_NAME_MAX + 1];/* the name of variable */

        //错误类型
u_char type;/* the type of variable */

        //联合,模糊定义,动态扩展
/* variable value */
union {
char char_value;
short short_value;
intint_value;
longlong_value;
void*ptr;
}value;
};
//声明为全局数据,注意数组未初始化,应该放在.bss段
extern struct finsh_var global_variable[];

int finsh_var_init(void);  //数组global_variable初始化
int finsh_var_insert(const char* name, int type); //插入var到数组global_variable
int finsh_var_delete(const char* name);  //从数组移出var
struct finsh_var* finsh_var_lookup(const char* name);  //查找var

#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值