to do a proper Linux/unix styled application, what is the best choice (eg. afaik ls uses getopt_long but for example ffmpeg getopt_long_only). Which one do you recommend?
干杯 (gān bēi)
to do a proper Linux/unix styled application, what is the best choice (eg. afaik ls uses getopt_long but for example ffmpeg getopt_long_only). Which one do you recommend?
干杯 (gān bēi)
在我看来,以下事情通常是真实的:
如果一个程序足够大,它最终将耗尽短选项的组合,这些组合与规范选项相比没有任何意义。例如,-Z可能与以完全不同字母开头的长选项相同。在这一点上,特别是对于单个维护者,选项解析代码将成为一个头痛的维护问题。
当发生这种情况时,你们有几种选择:
在不同的位置混合在一起,你真正开始抓住痛苦。
当我坐下来写一个需要很多选项的工具时,我通常的第一件事就是编写解析参数的代码,这有助于规划程序的流程并成为大纲。之后你只需要让每个选项都能正常工作即可。
换言之,如果你到达了期权成为一种长期痛苦的地步,通常表明计划已经迅速超出了预期。
总之,为了结束我冗长的回答,尽可能保持兼容性的 getopt() 行为通常更好。从用户获取指令的代码只是商业活动的成本,因此你应该关注的是在可能的情况下如何提供更好的用户体验。
我会说对于“适当的 GNU/Linux 风格”,你应该使用 getopt_long() 并为大多数选项提供长选项(有时仅为长选项)。大多数命令行界面都遵循这种方式。
两者都不是。使用 argp_parse 或 libpopt。
我从未使用过getopt_long_only,但它似乎需要进行更多的查找,因为如果一个未知的标志以单个 -
开头,它必须查看长选项和短选项:
If an option that starts with - (not -- ) doesn t match a long option, but does match a short option, it is parsed as a short option instead.
man getopt_long_only 的中文翻译是: man getopt_long_only
For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...
How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks
i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...
Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...
I ve just installed Zend Studio 7.0.2 on my Linux-Ubuntu 9.10 system. There were no problems during the installation but when I try to create a new project, the New Project form hangs when I click ...
I am running valgrind as follows:- /usr/local/bin/valgrind "process_name" After excecution its giving me following error ==21731== ==21731== Warning: Can t execute setuid/setgid executable: ==...
I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...
Is there anything other than DDD that will draw diagrams of my data structures like DDD does that runs on Linux? ddd is okay and runs, just kind of has an old klunky feeling to it, just wanted to ...