技术标签: UEFI应用与编程 uefi getopt edk2 udk
Cmd.c
/*
* Cmd.c
*
* Created on: 2017年11月29日
* Author:
*/
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
#include <stdio.h>
#include <getopt.c>
int
main(int argc, char *argv[])
{
int oc;
//char *b_opt_arg;
while ((oc = getopt(argc, argv, "ab:c:d:")) != -1) {
printf("%c\r\n",oc);
switch (oc) {
case 'a': printf("option a:'%s'\n",optarg); break;
case 'b': printf("option b:'%s'\n",optarg); break;
case 'c': printf("option c:'%s'\n",optarg); break;
case 'd': printf("option d:'%s'\n",optarg); break;
default: printf("other option :%c %c\n",oc,optarg);
}
}
return 0;
}
getopt.c
/*****************************************************************************
*
* MODULE NAME : GETOPT.C
*
* COPYRIGHTS:
* This module contains code made available by IBM
* Corporation on an AS IS basis. Any one receiving the
* module is considered to be licensed under IBM copyrights
* to use the IBM-provided source code in any way he or she
* deems fit, including copying it, compiling it, modifying
* it, and redistributing it, with or without
* modifications. No license under any IBM patents or
* patent applications is to be implied from this copyright
* license.
*
* A user of the module should understand that IBM cannot
* provide technical support for the module and will not be
* responsible for any consequences of use of the program.
*
* Any notices, including this one, are not to be removed
* from the module without the prior written consent of
* IBM.
*
* AUTHOR: Original author:
* G. R. Blair (BOBBLAIR at AUSVM1)
* Internet: [email protected]
*
* Extensively revised by:
* John Q. Walker II, Ph.D. (JOHHQ at RALVM6)
* Internet: [email protected]
*
*****************************************************************************/
/******************************************************************************
* getopt()
*
* The getopt() function is a command line parser. It returns the next
* option character in argv that matches an option character in opstring.
*
* The argv argument points to an array of argc+1 elements containing argc
* pointers to character strings followed by a null pointer.
*
* The opstring argument points to a string of option characters; if an
* option character is followed by a colon, the option is expected to have
* an argument that may or may not be separated from it by white space.
* The external variable optarg is set to point to the start of the option
* argument on return from getopt().
*
* The getopt() function places in optind the argv index of the next argument
* to be processed. The system initializes the external variable optind to
* 1 before the first call to getopt().
*
* When all options have been processed (that is, up to the first nonoption
* argument), getopt() returns EOF. The special option "--" may be used to
* delimit the end of the options; EOF will be returned, and "--" will be
* skipped.
*
* The getopt() function returns a question mark (?) when it encounters an
* option character not included in opstring. This error message can be
* disabled by setting opterr to zero. Otherwise, it returns the option
* character that was detected.
*
* If the special option "--" is detected, or all options have been
* processed, EOF is returned.
*
* Options are marked by either a minus sign (-) or a slash (/).
*
* No errors are defined.
*****************************************************************************/
#include <stdio.h> /* for EOF */
#include <string.h> /* for strchr() */
/* static (global) variables that are specified as exported by getopt() */
char *optarg = NULL; /* pointer to the start of the option argument */
int optind = 1; /* number of the next argv[] to be evaluated */
int opterr = 1; /* non-zero if a question mark should be returned
when a non-valid option character is detected */
/* handle possible future character set concerns by putting this in a macro */
#define _next_char(string) (char)(*(string+1))
int getopt(int argc, char *argv[], char *opstring)
{
static char *pIndexPosition = NULL; /* place inside current argv string */
char *pArgString = NULL; /* where to start from next */
char *pOptString; /* the string in our program */
if (pIndexPosition != NULL) {
/* we last left off inside an argv string */
if (*(++pIndexPosition)) {
/* there is more to come in the most recent argv */
pArgString = pIndexPosition;
}
}
if (pArgString == NULL) {
/* we didn't leave off in the middle of an argv string */
if (optind >= argc) {
/* more command-line arguments than the argument count */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* used up all command-line arguments */
}
/*---------------------------------------------------------------------
* If the next argv[] is not an option, there can be no more options.
*-------------------------------------------------------------------*/
pArgString = argv[optind++]; /* set this to the next argument ptr */
if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */
('-' != *pArgString)) {
--optind; /* point to current arg once we're done */
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* used up all the command-line flags */
}
/* check for special end-of-flags markers */
if ((strcmp(pArgString, "-") == 0) ||
(strcmp(pArgString, "--") == 0)) {
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* encountered the special flag */
}
pArgString++; /* look past the / or - */
}
if (':' == *pArgString) { /* is it a colon? */
/*---------------------------------------------------------------------
* Rare case: if opterr is non-zero, return a question mark;
* otherwise, just return the colon we're on.
*-------------------------------------------------------------------*/
return (opterr ? (int)'?' : (int)':');
}
else if ((pOptString = strchr(opstring, *pArgString)) == 0) {
/*---------------------------------------------------------------------
* The letter on the command-line wasn't any good.
*-------------------------------------------------------------------*/
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return (opterr ? (int)'?' : (int)*pArgString);
}
else {
/*---------------------------------------------------------------------
* The letter on the command-line matches one we expect to see
*-------------------------------------------------------------------*/
if (':' == _next_char(pOptString)) { /* is the next letter a colon? */
/* It is a colon. Look for an argument string. */
if ('\0' != _next_char(pArgString)) { /* argument in this argv? */
optarg = &pArgString[1]; /* Yes, it is */
}
else {
/*-------------------------------------------------------------
* The argument string must be in the next argv.
* But, what if there is none (bad input from the user)?
* In that case, return the letter, and optarg as NULL.
*-----------------------------------------------------------*/
if (optind < argc)
optarg = argv[optind++];
else {
optarg = NULL;
return (opterr ? (int)'?' : (int)*pArgString);
}
}
pIndexPosition = NULL; /* not in the middle of anything */
}
else {
/* it's not a colon, so just return the letter */
optarg = NULL; /* no argument follows the option */
pIndexPosition = pArgString; /* point to the letter we're on */
}
return (int)*pArgString; /* return the letter that matched */
}
}
Cmd.inf
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = cmd
FILE_GUID = dc72d2c7-a48a-42fd-80b6-9d229d9943c8
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = ShellCEntryLib
[Sources]
Cmd.c
getopt.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
StdLib/StdLib.dec
[LibraryClasses]
UefiLib
IoLib
#ShellCEntryLib
LibStdio #important
[Protocols]
[Ppis]
[Guids]
[BuildOptions]
[Pcd]
[PcdEx]
[FixedPcd]
[FeaturePcd]
[PatchPcd]
http://blog.sina.com.cn/s/blog_61332ec601016hj6.html**CCM(Core Coupled Memory)是给F4内核专用的全速64KB RAM, 它们没有经过总线矩阵, F4内核与之直接相连, 地址空间在0x1000_0000 ~ 0x1000_FFFF.由于其地址空间和常规的SRAM不连续, 加之DMA和外设也无法直接使用它们, 就使...
一、原题View the Exhibit and examine the data in the EMPLOYEES table:You want to display all the employee names and their corresponding manager names.Evaluate the following query:SQL> SELECT e.emp
如果是在Windows Server 2012本地控制台下,直接按Win(键盘上的微软徽标键)+R,输入:rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0回车后,勾选所需要的桌面图标的名称,确定即可。
程序员离职后收到原公司 2400 元,被告违反竞业协议赔 18 万!到底是怎么回事?
转载自:http://blog.sina.com.cn/s/blog_71715bf8010166qf.html开篇大话: Object-C语言的异常处理符号和C++、JAVA相似。再加上使用NSException,NSError或者自定义的类,你可以在你的应用程序里添加强大的错误处理机制。异常处理机制是由这个四个关键字支持的:@try,@catch,@thorw,@finally。当代码
问题一:node-sass npm ERR! command failed解决:1、删除 npm uninstall node-sass2、安装 npm install node-sass问题二:npm ERR! gyp info it worked if it ends with oknpm ERR! gyp info using [email protected] ERR! gyp info using [email protected] | win32 | x64npm ERR! gyp ERR!
我的sublime text 3 快捷键配置。强烈推荐下面标红的快捷键,谁用谁知道,编码的时候再也不用依赖方向键和鼠标了。[//=======================我的快捷键=======================//// 删除当前行{ "keys": ["ctrl+d"], "command":"run_macro_file", "args":
下面列出了几个linux学习中的shell脚本题目1、九九乘法表#!/bin/bashecho "九九乘法表"#注意((之间不能有空格、加减乘除的格式、还有转义字符\*、-nefor (( i=1; i<=9; i=i+1 ))do for (( j=1; j<=i; j=j+1 )) do ((result=$i*$j)) ec...
代码范例clc,clear;T=0.001;k1=-1:T:5;f1=2*((k1>0)-(k1>4)); %f1(t)的 MATLAB描述k2=-1:T:3;f2=(k2>0)-(k2>2); %f2(t)信号的描述%画图程序subplot(3,1,1)plot(k1,f1);axis([-1,5,0,2.2]) %f1的显示范围title('f1');
很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明。MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本。mysql 下载地址 http://www.jb51.net/softs/2193.html下面的是MySQL安装的图解,用的可执行文件安装的
题目来自于网络,答案是笔者整理的。仅供参考,欢迎指正来源: https://mp.weixin.qq.com/s?__biz=MzI1NDQ3MjQxNA==&amp;mid=2247485779&amp;idx=1&amp;sn=3b06b9923df7f40f887ead8b8a53e50e&amp;chksm=e9c5f0e2deb279f47fbfc3a12a70896bf95fa8c...
Add the content later...