GNU中的一个软件包,包名叫hello,呵呵,看来很简单啦。
#include "system.h"
#include "errno.h"
#include "error.h"
#include "progname.h"
#include "xalloc.h"
static const struct option longopts[] = {
{"greeting", required_argument, NULL, 'g'}, 需要参数
{"help", no_argument, NULL, 'h'}, 不需要参数
{"traditional", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0} 通过man getopt_long发现,这个结构体需要以NULL结束。
};
/* Forward declarations. */ 前向声明,估计调用在实现之前。
static void print_help (void);
static void print_version (void);
int
main (int argc, char *argv[]) 关键的入口函数在这里啦。
{
int optc;
int lose = 0;
const char *greeting_msg;
wchar_t *mb_greeting;
size_t len;
set_program_name (argv[0]);
/* Set locale
今天就来分析一下,GNU的目的是通过这个说明一下,GNU标准软件包所应遵守的规则,以及一些必须的测试,编译脚本文件等。
俺就不分析其他的了,直接上最具价值的代码,其他忽略,这个程序实在是太小了,最重要的是一个getopt_long函数的应用,
用于解析命令行参数的。
#include "system.h"
#include "errno.h"
#include "error.h"
#include "progname.h"
#include "xalloc.h"
static const struct option longopts[] = {
{"greeting", required_argument, NULL, 'g'}, 需要参数
{"help", no_argument, NULL, 'h'}, 不需要参数
{"traditional", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0} 通过man getopt_long发现,这个结构体需要以NULL结束。
};
/* Forward declarations. */ 前向声明,估计调用在实现之前。
static void print_help (void);
static void print_version (void);
int
main (int argc, char *argv[]) 关键的入口函数在这里啦。
{
int optc;
int lose = 0;
const char *greeting_msg;
wchar_t *mb_greeting;
size_t len;
set_program_name (argv[0]);
/* Set locale