Wednesday, May 20, 2020

Programming in FreeDOS - using getopt_long()

In an earlier video, I showed how you can parse a command line using the getopt function. getopt makes it really easy to examine the command line and pull out options. This means your program can respond to the user in different ways, depending on the options that were passed to your program.

But getopt is limited in a few ways. It only accepts single-letter options, and each option must be set off with a hyphen (-) instead of a slash (/).

If you want to parse long DOS-style options, you need a different library. The getopt_long function is a variant of getopt that deals with these longer options, and uses a slash to start the option.

This video shows how to use getopt_long to parse a command line from a C program:

I originally produced this video as a bonus for my Patreon supporters. I have a Patreon to help me set aside time to work on FreeDOS. I've used Patreon to make YouTube videos about FreeDOS, completely update the FreeDOS website, and start updating the FreeDOS wiki. With more support, I'm planning to dedicate more time to fix bugs, port programs to FreeDOS, and write new FreeDOS programs and games.

If you'd like to support me on Patreon, click the "Become a Patron" link below. There's no obligation to support me on Patreon, but it really does help. Thanks!

Become a Patron!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.