forked from KolibriOS/kolibrios
- Added simple function "getopt" in stdlib (tcc)
git-svn-id: svn://kolibrios.org@8380 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
38
programs/develop/ktcc/trunk/samples/getopt_ex.c
Normal file
38
programs/develop/ktcc/trunk/samples/getopt_ex.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void main(int argc, char *argv[]) {
|
||||
int c;
|
||||
if(argc<2)
|
||||
{
|
||||
puts("Usage: getopt_ex [options]\n");
|
||||
puts("-a Show 'Option a'");
|
||||
puts("-B Show 'Option B'");
|
||||
puts("-n [num] Show 'num'");
|
||||
}
|
||||
while ((c = getopt(argc, argv, "aBn:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
puts("Option 'a'");
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
puts("Option 'B'");
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
printf("Option n: value=%d\n", atoi(optarg));
|
||||
break;
|
||||
|
||||
case '?':
|
||||
printf("ERROR: illegal option %s\n", argv[optind-1]);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
printf("WARNING: no handler for option %c\n", c);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
Reference in New Issue
Block a user