【发布时间】:2012-08-31 15:35:50
【问题描述】:
如果有人使用 argtable 作为 C 代码的 命令行参数解析器,这是我的问题:
我的意图
我正在使用最新版本的 argtable2 库在 Linux 平台上使用 C 语言进行编程。
我想要归档的是有一个接受多个输入文件和一个可选选项的程序(我们称之为-o)。如果-o 未提供作为 shell 调用中的选项,则程序不会写入任何输出。如果-o由它自己提供,程序的输出将写入一个名为“output.txt”的默认文件。如果选项与文件名一起提供,例如-o other.txt,输出应写入给定的文件名 - 在本例中为“other.txt”。
问题
在我所有的尝试中 argtable 行为不端。它解释与-o 一起给出的可选值作为输入文件。所以./program -o other.txt inputfile1.dat inputfile2.dat inputfile3.dat 会被解释为有四个输入文件——三个“inputfile*.dat”和应该是输出文件的“other.txt”。
重现问题
这是一个shell会话来说明,我的意思。它使用产生问题的minimal example。我不确定是我做错了什么还是libargtable2 中的错误:
confus@confusion:~$ gcc -o argbug argbug.c -largtable2
confus@confusion:~$ ./argbug
Error: missing option INPUT-FILES
Usage:
./argbug [-o [<file>]] INPUT-FILES
-o [<file>] File to write output to. Default is 'output.txt'.
Omit whole option to discard all output
INPUT-FILES Input files
confus@confusion:~$ ./argbug inputfile1.dat inputfile2.dat inputfile3.dat -o other.txt
inputfile[0] = inputfile1.dat # this is okay output
inputfile[1] = inputfile2.dat # as is this line
inputfile[2] = inputfile3.dat # also okay output
inputfile[3] = other.txt # "other.txt" is falsely recognized as an input file
outputfile = output.txt # should be "other.txt" instead of the default "output.txt"
无论是我还是 Steward,argtable 的作者似乎都没有时间真正研究我的问题。有什么想法吗?
【问题讨论】:
-
看起来你的要求是模棱两可的:图书馆如何决定你是指
-o之后的文件名是输入还是输出?-o input.txt看起来和-o output.txt完全一样
标签: c shared-libraries command-line-arguments