是否有“getopt”的实现。为Delphi? [英] Is there an implementation of "getopt" for Delphi?

查看:199
本文介绍了是否有“getopt”的实现。为Delphi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用getopt()来解析C / C ++中的命令行参数并不容易。

It doesn't get much easier than using getopt() to parse command line parameters in C/C++.

Delphi有什么相似之处吗?或者理想情况下,使用相同的语法?我知道Delphi支持FindCmdLineSwitch和ParamStr(),但是这些仍然需要一些额外的解析。

Is there anything similar for Delphi? Or ideally, with the same syntax? I know Delphi supports FindCmdLineSwitch and ParamStr(), but those still require some additional parsing.

我想要的东西在getopt切换开关,以及在切换之后捕获值。下面看一些例子C代码看看我在说什么:

I want something that works like getopt() in C. Something that easily allows basic toggle switches, as well as capturing a value after a switch. See below for some example C code to see what I'm talking about:

void print_help()
{
        printf("usage:\n") ;
        printf("\t\t-i set input file\n") ;
        printf("\t\t-o set output file\n") ;
        printf("\t\t-c set config file\n") ;
        printf("\t\t-h print this help information\n") ;
        printf("\t\t-v print version\n") ;
}
 char* input_file = NULL ;
        char *query=NULL;
          char opt_char=0;
        while ((opt_char = getopt(argc, argv, "i:q:vh")) != -1)
        {
                switch(opt_char)
                {
                        case 'h':
                                print_help();
                                exit(-1);
                                break;
                        case 'v':
                                print_version() ;
                                exit(-1) ;
                                break ;
                        case 'i':
                                input_file= optarg ;
                                break ;
                        case 'q':
                                query= optarg ;
                                break ;
                        default:
                                print_help();
                                exit(-1);
                                break;
                }
        }


推荐答案

是一个实现TGetOpt,声称

There is an implementation TGetOpt, claiming to


为Delphi实现getopt变体。它是几乎POSIX兼容,支持长选项,必需,可选和没有参数

implement a getopt variant for Delphi. It is nearly POSIX compatible, supporting long options, required, optional and no arguments

你可以找到它此处

这篇关于是否有“getopt”的实现。为Delphi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆