Usage_Display
时间:2010-07-20 来源:Codeplayer
#include <stdio.h>
#include <stdlib.h>
#define OPTARGS "dkMrRsvC:"
const char *cmdname = "heartbeat";
void
usage(void)
{
const char * optionargs = OPTARGS; //#define OPTARGS "dkMrRsvC:"
const char * thislet; //
fprintf(stderr, "\nUsage: %s [-", cmdname);
for (thislet=optionargs; *thislet; ++thislet) {
if (thislet[0] != ':' && thislet[1] != ':') {
fputc(*thislet, stderr); //output one by one
}
}
fputc(']', stderr);
for (thislet=optionargs; *thislet; ++thislet) {
if (thislet[1] == ':') {
const char * desc = "unknown-flag-argument";
/* Put a switch statement here eventually... */
switch(thislet[0]) {
case 'C': desc = "Current-resource-state";
break;
}
fprintf(stderr, " [-%c %s]", *thislet, desc);
}
}
fprintf(stderr, "\n");
fprintf(stderr, "\t-C only valid with -R\n");
fprintf(stderr, "\t-r is mutually exclusive with -R\n");
exit(1);
}
int main(int argc, char ** argv){
usage();
}
=====================================================================================================================
console: gcc usage -o xxx
console:
Usage: heartbeat [-dkMrRsv] [-C Current-resource-state]
-C only valid with -R
-r is mutually exclusive with -R
#include <stdlib.h>
#define OPTARGS "dkMrRsvC:"
const char *cmdname = "heartbeat";
void
usage(void)
{
const char * optionargs = OPTARGS; //#define OPTARGS "dkMrRsvC:"
const char * thislet; //
fprintf(stderr, "\nUsage: %s [-", cmdname);
for (thislet=optionargs; *thislet; ++thislet) {
if (thislet[0] != ':' && thislet[1] != ':') {
fputc(*thislet, stderr); //output one by one
}
}
fputc(']', stderr);
for (thislet=optionargs; *thislet; ++thislet) {
if (thislet[1] == ':') {
const char * desc = "unknown-flag-argument";
/* Put a switch statement here eventually... */
switch(thislet[0]) {
case 'C': desc = "Current-resource-state";
break;
}
fprintf(stderr, " [-%c %s]", *thislet, desc);
}
}
fprintf(stderr, "\n");
fprintf(stderr, "\t-C only valid with -R\n");
fprintf(stderr, "\t-r is mutually exclusive with -R\n");
exit(1);
}
int main(int argc, char ** argv){
usage();
}
=====================================================================================================================
console: gcc usage -o xxx
console:
Usage: heartbeat [-dkMrRsv] [-C Current-resource-state]
-C only valid with -R
-r is mutually exclusive with -R
相关阅读 更多 +