glib学习笔记之六——处理命令行参数
2011-11-22 14:59
381 查看
官方文档:http://developer.gnome.org/glib/stable/glib-Commandline-option-parser.html
在connman中使用GOptionEntry结构体处理命令行参数,结构体形式如下:
最后,分析的过程会将GOptionEntry结构体定义的options中的各个标记进行相应的处理
在connman中使用GOptionEntry结构体处理命令行参数,结构体形式如下:
static GOptionEntry options[] = { { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_debug, "Specify debug options to enable", "DEBUG" }, { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device, "Specify networking device or interface", "DEV" }, { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice, "Specify networking interface to ignore", "DEV" }, { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin, "Specify plugins to load", "NAME,..." }, { "noplugin", 'P', 0, G_OPTION_ARG_STRING, &option_noplugin, "Specify plugins not to load", "NAME,..." }, { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi, "Specify driver for WiFi/Supplicant", "NAME" }, { "nodaemon", 'n', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &option_detach, "Don't fork daemon to background" }, { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &option_dnsproxy, "Don't enable DNS Proxy" }, { "compat", 'c', 0, G_OPTION_ARG_NONE, &option_compat, "(obsolete)" }, { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version, "Show version information and exit" }, { NULL }, };建立结构体之后,创建context,将context与GOptionEntry关联,然后将命令行参数传入到context进行分析
context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); exit(1); }
最后,分析的过程会将GOptionEntry结构体定义的options中的各个标记进行相应的处理
相关文章推荐
- shell学习笔记-命令行参数的处理
- Linux 程序设计学习笔记----命令行参数处理
- Linux 编程学习笔记----命令行参数处理
- Python 学习笔记 - socket(粘包及其处理方式)
- 【OpenCV学习笔记】【错误处理】计算机缺失MSVCP120D.dll
- spring源码学习笔记-初始化(六)-完成及异常处理
- springmvc学习笔记(20)——CRUD之删除 & 静态资源处理
- 批处理命令学习笔记——使用筛选器
- (学习笔记)spring框架入门之配置bean(处理属性中有集合的情况)
- Guava学习笔记(5)--Throwables简化异常处理
- 批处理学习笔记01
- 图像处理 基于Visual C++编程 学习笔记 (1)建立MFC工程,打开bmp文件
- 学习笔记------海量数据处理题集锦与bit-map详解
- CasperJS学习笔记--命令行参数
- 黑马程序员_文件IO流部分疑点和JDK1.7版本后新try-catch处理学习笔记
- PHP学习笔记——使用回调函数处理数组函数array_map()
- head first C#学习笔记:如何创建事件以及事件处理程序
- struts2系列学习笔记(6)---------------Action的结果处理
- 批处理命令学习笔记——硬盘杀手
- MyGeneration学习笔记(8) :dOOdad提供的数据绑定、特殊函数和事务处理