getopt_long(argc, argv, "", OPTIONS, NULL)分析
2011-08-02 11:09
525 查看
static const struct option OPTIONS[] = {
{ "factory_test", no_argument, NULL, 'f'+'t'},
{ "send_intent", required_argument, NULL, 's' },
{ "update_image", required_argument, NULL, 'u' },
{ "recover_image", required_argument, NULL, 'r' },
{ "wipe_all", no_argument, NULL, 'w'+'a' },
{ "wipe_data", no_argument, NULL, 'w' },
}
while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1)
{
switch (arg) {
case 'p': previous_runs = atoi(optarg); break;
case 's': send_intent = optarg; break;
case 'u': update_image = optarg; break;
case 'r': recover_image = optarg; break;
case 'w': wipe_flags |= default_factory_reset;break;
case 'w'+'a': wipe_flags |= WIPE_ALL; break;
case '?':
LOGE("Invalid command argument\n");
continue;
}
}
上面贴的是android在recovery.c中的代码,当接收到参数时,在OPTION中寻找和参数相同的一项,之后getopt_long返回短选项,如"send_intent",返回“s”。
argc, argv
第一个参数是总共参数的数目,包括可执行文件本身
第二个参数是具体的参数
getopt_long是用来解析参数的使用getopt_long(),需要引入头文件#include <getopt.h>
/gingerbread/bootable/recovery下有Android.mk,里面LOCAL_MODULE := recovery编译后生成recovery应用,
这个可执行文件会被最后编译成固件,如recovery.img烧写进板子
{ "factory_test", no_argument, NULL, 'f'+'t'},
{ "send_intent", required_argument, NULL, 's' },
{ "update_image", required_argument, NULL, 'u' },
{ "recover_image", required_argument, NULL, 'r' },
{ "wipe_all", no_argument, NULL, 'w'+'a' },
{ "wipe_data", no_argument, NULL, 'w' },
}
while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1)
{
switch (arg) {
case 'p': previous_runs = atoi(optarg); break;
case 's': send_intent = optarg; break;
case 'u': update_image = optarg; break;
case 'r': recover_image = optarg; break;
case 'w': wipe_flags |= default_factory_reset;break;
case 'w'+'a': wipe_flags |= WIPE_ALL; break;
case '?':
LOGE("Invalid command argument\n");
continue;
}
}
上面贴的是android在recovery.c中的代码,当接收到参数时,在OPTION中寻找和参数相同的一项,之后getopt_long返回短选项,如"send_intent",返回“s”。
argc, argv
第一个参数是总共参数的数目,包括可执行文件本身
第二个参数是具体的参数
getopt_long是用来解析参数的使用getopt_long(),需要引入头文件#include <getopt.h>
/gingerbread/bootable/recovery下有Android.mk,里面LOCAL_MODULE := recovery编译后生成recovery应用,
这个可执行文件会被最后编译成固件,如recovery.img烧写进板子
相关文章推荐
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- struts中post方式上传文件,enctype="multipart/form-data",request.getParameter("file") 是null的问题分析
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- CoreData____.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "T
- IGraphBuilder *pGraph->RenderFile(argv[1], NULL); //L"C:////Example.avi", NULL);
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- java中分析""和null
- Document root element *, must match DOCTYPE root "null"分析及解决方法
- mysql 【null】【not null】 ""
- JAVA中isEmpty和null以及""的区别
- JS中undefined,null,"",0和false的区分 .
- null和" "的区别
- For input string: "null"
- C语言中的"NULL"到底是什么?又不是什么?有什么用?怎么用?
- VB中 0、""(空字串)、Null、Empty、与 Nothing 的区别
- null 与 "" 的区别
- 解决Error[Pe147]: declaration is incompatible with "__nounwind __interwork __softfp unsigned long __ge
- ognl.OgnlException: target is null for setProperty(null, "y", [Ljava.lang.St