1 Star 0 Fork 43

yuexiaodong/sarudp

forked from yuanhack/sarudp
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
yharguments.c 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
yuanhack 提交于 2015-09-06 00:19 . stash: solve the time-calc problem
#include "yharguments.h"
#include "yherror.h"
int port = -1;
int daemond = 0;
int optp;
static struct option opt[] = {
{"port", 1, 0, 'p'},
{"daemon", 0, 0, 'd'},
{"help", 0, 0, 'h'},
{0,0,0,0}
};
void usage(int argc, char **argv)
{
err_msg("usage: %s [port] [option[=value]]...", argv[0]);
err_msg(" -p, --port=number Service port(range 1~65535), like [port]");
err_msg(" but the priority is higher than [port]");
err_msg(" -d, --daemon Daemon mode");
err_msg(" -h, --help Usage help");
}
void port_check(int argc, char **argv, int port, char *strport)
{
if (port <= 0) {
err_msg("bad parameter: port %s", strport);
usage(argc, argv);
exit(1);
}
}
void arguments(int argc, char **argv)
{
char c;
opterr = 1;
while ((c = getopt_long(argc,argv,"p:dh", opt, 0)) != -1) {
switch (c) {
case 'p':
port = atoi(optarg);
port_check(argc, argv, port, optarg);
optp = 1;
break;
case 'd':
daemond = 1;
break;
case 'h':
usage(argc, argv);
exit(0);
case '?':
err_quit("Try '%s --help' for more information.", argv[0]);
default :
usage(argc, argv);
exit(1);
}
}
if (optp == 0) {
port = atoi(argv[argc-1]);
port_check(argc, argv, port, argv[argc-1]);
optp = 1;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/yuexiaodong/sarudp.git
[email protected]:yuexiaodong/sarudp.git
yuexiaodong
sarudp
sarudp
master

搜索帮助