0

So, i was given a task to implement simple version of cat utility. It should support some of GNU keys, for given text returns the same results as real cat utility and i was given this synopsis:

cat [OPTION] [FILE]... 

What i want to know can my utility be called with multiple keys or just with one?

cat -b file 

or

cat -b -s -e file 

POSIX(in BaseDefinions, chapter 12) says:

The notation used for the SYNOPSIS sections imposes requirements on the implementors of the standard utilities and provides a simple reference for the application developer or system user.

And it the same chapter POSIX says:

Ellipses ( "..." ) are used to denote that one or more occurrences of an operand are allowed.


So if OPTION can be repeated, why there is no ellipsis after it in synopsis? For example, there is an ellipsis man7.org:

cat [OPTION]... [FILE]... 

but not gnu.org( but this cat allows many options):

cat [option] [file]... 

Can someone explain should my program work with many keys at a time and why? And why gnu.org doesn't follow this(ellipsis) utility syntax convetion?

15
  • This question has already been on SO and superuser. If the question still does not correspond to the site, then please tell me where it is better to post it. Commented May 29 at 11:17
  • "Some of these programs recognize the --help and --version options only when one of them is the sole command line argument." (gnu.org/software/coreutils/manual/html_node/Common-options.html), so specifying ... will be incorrect for --version and/of --help, but might be correct for other options.... Commented May 29 at 11:26
  • 3
    It is irrelevant what POSIX says. It is irrelevant what GNU says. If the person who gave you this task gave you unclear requirements, then the only person in the world who can clear up those requirements is the person who gave you the requirements. That's Software Engineering 101: make sure the requirements are clear. How to do that is beyond the scope of a Stack Exchange Answer box. It is literally the subject of a 3 year degree, and thousands of books. Commented May 29 at 11:36
  • Yes, I'm afraid only your professor can answer. However, I have never seen any tool anywhere that only accepts one option at a time. That would be very strange and, if anything, harder to implement since any library you use for this will support multiple options by default. Commented May 29 at 11:39
  • @JörgWMittag , thank you. Later will delete this Commented May 29 at 11:46

1 Answer 1

2

I'd like to echo what Jörg said, namely that neither POSIX nor GNU are setting your requirements. The only party doing that is the person / institution giving you that assignment.

As an author of software, and here's how I do contradict Jörg, I'd call the requirements "clear enough for work", and I'd call it your "job" to interpret requirements sensibly, not minimally.

Existing cat implementations that your assigner must have thought of when formulating the assignment, take multiple options at once, as far as sensible.

So, when they said "some GNU options": were they thinking of mutually exclusive ones, or ones that can be sensibly combined?

If the latter, then you're probably expected to implement that.

Honestly, when implementing a command line parser, you should never reinvent the wheel, as that has been done a literal million times for command line parsing, and was very rarely a good idea. There's so many OK to good command line parsing libraries out there. Look for (ctrl+f) "argv" in the list on https://github.com/r-lyeh/single_file_libs , unless, of course, your assignment was less about the functionality of cat and more about learning to write a parser; check out the kgargs example (In which case, oddly specific assignment, because in practice, whenever you deliver a hand-written command line parser in a professional context, people will tell you to no, don't do that, use an existing parser of the hundreds that can be be freely used in your code.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.