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


你可能感兴趣的:(shell,RT-Thread,finsh)