Rev 3311 | Rev 3346 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3311 | Rev 3319 | ||
---|---|---|---|
1 | /* Automatically generated by mknewcmd on Wed Aug 13 15:41:09 PHT 2008 |
1 | /* Automatically generated by mknewcmd on Wed Aug 13 15:41:09 PHT 2008 |
2 | * This is machine generated output. The author of mknewcmd claims no |
2 | * This is machine generated output. The author of mknewcmd claims no |
3 | * copyright over the contents of this file. Where legally permitted, the |
3 | * copyright over the contents of this file. Where legally permitted, the |
4 | * contents herein are donated to the public domain. |
4 | * contents herein are donated to the public domain. |
5 | * |
5 | * |
6 | * You should apply any license and copyright that you wish to this file, |
6 | * You should apply any license and copyright that you wish to this file, |
7 | * replacing this header in its entirety. */ |
7 | * replacing this header in its entirety. */ |
8 | 8 | ||
9 | #include <stdio.h> |
9 | #include <stdio.h> |
10 | #include <stdlib.h> |
10 | #include <stdlib.h> |
- | 11 | #include <getopt.h> |
|
- | 12 | ||
11 | #include "config.h" |
13 | #include "config.h" |
12 | #include "util.h" |
14 | #include "util.h" |
13 | #include "errors.h" |
15 | #include "errors.h" |
14 | #include "entry.h" |
16 | #include "entry.h" |
15 | #include "cat.h" |
17 | #include "cat.h" |
16 | #include "cmds.h" |
18 | #include "cmds.h" |
17 | 19 | ||
18 | static char *cmdname = "cat"; |
20 | static char *cmdname = "cat"; |
19 | 21 | ||
- | 22 | static struct option long_options[] = { |
|
- | 23 | { "help", no_argument, 0, 'h' }, |
|
- | 24 | { "version", no_argument, 0, 'v' }, |
|
- | 25 | { "file", required_argument, 0, 'f' }, |
|
- | 26 | { 0, 0, 0, 0 } |
|
- | 27 | }; |
|
- | 28 | ||
20 | /* Dispays help for cat in various levels */ |
29 | /* Dispays help for cat in various levels */ |
21 | void * help_cmd_cat(unsigned int level) |
30 | void * help_cmd_cat(unsigned int level) |
22 | { |
31 | { |
23 | printf("This is the %s help for '%s'.\n", |
32 | printf("This is the %s help for '%s'.\n", |
24 | level ? EXT_HELP : SHORT_HELP, cmdname); |
33 | level ? EXT_HELP : SHORT_HELP, cmdname); |
25 | return CMD_VOID; |
34 | return CMD_VOID; |
26 | } |
35 | } |
27 | 36 | ||
28 | /* Main entry point for cat, accepts an array of arguments */ |
37 | /* Main entry point for cat, accepts an array of arguments */ |
29 | int * cmd_cat(char **argv) |
38 | int * cmd_cat(char **argv) |
30 | { |
39 | { |
31 | unsigned int argc; |
40 | unsigned int argc; |
32 | unsigned int i; |
41 | unsigned int i; |
- | 42 | int c, opt_ind; |
|
33 | 43 | ||
34 | /* Count the arguments */ |
44 | /* Count the arguments */ |
35 | for (argc = 0; argv[argc] != NULL; argc ++); |
45 | for (argc = 0; argv[argc] != NULL; argc ++); |
36 | 46 | ||
37 | printf("%s %s\n", TEST_ANNOUNCE, cmdname); |
47 | printf("%s %s\n", TEST_ANNOUNCE, cmdname); |
38 | printf("%d arguments passed to %s", argc - 1, cmdname); |
48 | printf("%d arguments passed to %s\n", argc - 1, cmdname); |
39 | - | ||
40 | if (argc < 2) { |
- | |
41 | printf("\n"); |
- | |
42 | return CMD_SUCCESS; |
- | |
43 | } |
- | |
44 | 49 | ||
45 | printf(":\n"); |
- | |
46 | for (i = 1; i < argc; i++) |
50 | for (i = 1; i < argc; i++) |
47 | printf("[%d] -> %s\n", i, argv[i]); |
51 | printf("[%d] -> %s\n", i, argv[i]); |
48 | 52 | ||
- | 53 | for (c = 0, optind = 0, opt_ind = 0; c != -1;) { |
|
- | 54 | c = getopt_long(argc, argv, "f:hv", long_options, &opt_ind); |
|
- | 55 | switch (c) { |
|
- | 56 | case 'h': |
|
- | 57 | help_cmd_cat(HELP_SHORT); |
|
- | 58 | break; |
|
- | 59 | case 'v': |
|
- | 60 | printf("I have no version, sorry.\n"); |
|
- | 61 | break; |
|
- | 62 | case 'f': |
|
- | 63 | printf("File : %s\n", optarg); |
|
- | 64 | break; |
|
- | 65 | } |
|
- | 66 | } |
|
- | 67 | ||
- | 68 | printf("argc = %d, optind = %d\n", argc, optind); |
|
- | 69 | ||
49 | return CMD_SUCCESS; |
70 | return CMD_SUCCESS; |
50 | } |
71 | } |
51 | 72 | ||
52 | 73 |