Changing Behavior By Name
Now it’s time to let the user control the program behavior. One easy way is to look at the name the user used to invoke the program. There is a Linux utility called BusyBox that implements many of the standard Unix command-line programs in one small executable, changing its behavior based on the name. On your system you probably have a /usr/bin/ranlib which is a symbolic link to the libtool program. In this case, libtool works like ranlib when invoked using the ranlib name.
Example 4.1 changes the program’s behavior depending on if it is run as “upcase” or “downcase.” To do this, look at the argv array that is passed to main. argv is a contraction of the phrase “argument vector.” You could call that parameter anything ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access