📄 command_list.c
字号:
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003,2004,2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)/**************************************************************************//* Mantis Commander: *//* This is an application which will allow interfacing with a nymph from *//* a computer over the serial line, it provides arbitrary functions. *//**************************************************************************/#include "mos.h"#ifndef SCONS#include <config.h>#endif#include "command_list.h"#include <string.h>#ifdef PLATFORM_LINUX#include <stdio.h>#else#include "printf.h"#endifmos_mutex_t command_mutex;bool command_parse(command_list_t in_list[], char *command_string, uint16_t max_command_count){ uint16_t i; mos_mutex_lock(&command_mutex); for(i = 0; i < max_command_count; i++) { if(in_list[i].input) { if(!strcmp(in_list[i].input, command_string)) { in_list[i].func_pointer(); mos_mutex_unlock(&command_mutex); return true; } } } mos_mutex_unlock(&command_mutex); return false;}bool register_function(command_list_t in_list[], char * name, void (*func_pointer)(void), uint16_t max_command_count){ uint16_t i; bool ret; mos_mutex_lock(&command_mutex); for(i = 0; i < max_command_count && in_list[i].input != NULL; i++) ; if(i == max_command_count) { ret = false; } if(i < max_command_count) { in_list[i].input = name; in_list[i].func_pointer = func_pointer; in_list[++i].input = NULL; ret = true; } else { ret = false; //must have been past max command count } mos_mutex_unlock(&command_mutex); return ret;}int16_t help_list(command_list_t in_list[], uint16_t max_command_count){ uint16_t i; uint8_t wrap = 1; printf("cmds: \n"); for(i = 0; i < max_command_count && in_list[i].input != NULL; i++) { if(wrap++ % 6 == 0) printf("\n"); printf("[%s] ", in_list[i].input); } printf(".\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -