📄 cmdlist.c
字号:
//-----------------------------------------------------------------------------
// Contents: main module of a simple firmware
//
// Copyright: Inventec Electronics(Tianjin) Co., Ltd.
// $Archive: cmdlist.c
// $Date: 2007-08-06
// $Revision: 1.00
//
//-----------------------------------------------------------------------------
// Copyright 2006, xsh.han@itc.inventec
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cmdlist.h"
//global variable
struct command_list * g_cmdlist = NULL;
struct command_list * g_retlist = NULL;
//--------------------------------------------------------------------------------
//get command list tail
//--------------------------------------------------------------------------------
struct command_list * get_cmdlist_tail()
{
struct command_list *plist;
plist=g_cmdlist;
if (plist!=NULL){
while(plist->next!=NULL)
plist=plist->next;
}
return plist;
}
//--------------------------------------------------------------------------------
//add a command to list
//--------------------------------------------------------------------------------
struct command_list * add_to_cmdlist(char * cmd)
{
struct command_list *plist;
struct command_list *ptemp;
if (strlen(cmd)>=MAX_CMD_LENGTH) //too long
return NULL;
ptemp=malloc(sizeof(struct command_list));
if(ptemp==NULL) //alloc error
return NULL;
memset(ptemp,0,sizeof(struct command_list));
strcpy(ptemp->message,cmd);
plist=get_cmdlist_tail();
if (plist==NULL){
g_cmdlist=ptemp;
}else{
plist->next=ptemp;
}
return ptemp;
}
//--------------------------------------------------------------------------------
//free command list
//--------------------------------------------------------------------------------
void free_cmdlist()
{
struct command_list *plist;
plist=g_cmdlist;
while(plist!=NULL){
g_cmdlist=g_cmdlist->next;
free(plist);
plist=g_cmdlist;
}
g_cmdlist = NULL;
return;
}
//=============================================================================
/*
* The Interface description:
* get ret_msg_list tail pointer
* Parameters:
* <none>
* Return Value:
* pointer for g_cmd_info.cmd_msg
* Remark:
*
*/
//=============================================================================
struct command_list * get_retlist_tail()
{
struct command_list *plist;
plist = g_retlist;
if (plist != NULL){
while(plist->next!=NULL) {
plist=plist->next;
}
}
return plist;
}
//=============================================================================
/*
* The Interface description:
* add return message to g_cmd_info.ret_msg_list
* for output to cli as echo message
* Parameters:
* cmd[in]: cmd string from cli,
* Return Value:
* pointer for new message_st, NULL if error
* Remark:
*
*/
//=============================================================================
struct command_list * add_to_retlist(char * cmd)
{
struct command_list *plist;
struct command_list *ptemp;
if (strlen(cmd) > MAX_CMD_LENGTH) {//too long
return NULL;
}
ptemp = malloc(sizeof(struct command_list));
if(ptemp == NULL) {//alloc error
return NULL;
}
memset(ptemp,0,sizeof(struct command_list));
strcpy(ptemp->message,cmd);
plist = get_retlist_tail();
if (plist == NULL){
g_retlist = ptemp;
}else{
plist->next = ptemp;
}
return ptemp;
}
//=============================================================================
/*
* The Interface description:
* free g_cmd_info.ret_msg_list
* Parameters:
* <none>
* Return Value:
* <none>
* Remark:
*
*/
//=============================================================================
void free_retlist()
{
struct command_list *plist;
plist = g_retlist;
while(plist != NULL){
g_retlist=g_retlist->next;
free(plist);
plist = g_retlist;
}
g_retlist = NULL;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -