comparison toys/hello.c @ 403:f6ffc6685a9e

Fluff out documentation and skeleton code.
author Rob Landley <rob@landley.net>
date Mon, 16 Jan 2012 01:44:17 -0600
parents 5d4dacab7be0
children a3e014fdeb35
comparison
equal deleted inserted replaced
402:2551e517b800 403:f6ffc6685a9e
1 /* vi: set sw=4 ts=4: 1 /* vi: set sw=4 ts=4:
2 * 2 *
3 * hello.c - A hello world program. 3 * hello.c - A hello world program.
4 * 4 *
5 * Copyright 2006 Rob Landley <rob@landley.net> 5 * Copyright 2012 Rob Landley <rob@landley.net>
6 * 6 *
7 * Not in SUSv3. 7 * Not in SUSv4.
8 * See http://opengroup.org/onlinepubs/9699919799/utilities/ 8 * See http://opengroup.org/onlinepubs/9699919799/utilities/
9 9
10 USE_HELLO(NEWTOY(hello, "e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN)) 10 USE_HELLO(NEWTOY(hello, "e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN))
11 11
12 config HELLO 12 config HELLO
13 bool "hello" 13 bool "hello"
14 default n 14 default n
15 help 15 help
16 usage: hello [-a] [-b string] [-c number] [-d list] [-e count] [...]
17
16 A hello world program. You don't need this. 18 A hello world program. You don't need this.
17 19
18 Mostly used as an example/skeleton file for adding new commands, 20 Mostly used as an example/skeleton file for adding new commands,
19 occasionally nice to test kernel booting via "init=/bin/hello". 21 occasionally nice to test kernel booting via "init=/bin/hello".
20 */ 22 */
32 int more_globals; 34 int more_globals;
33 ) 35 )
34 36
35 #define TT this.hello 37 #define TT this.hello
36 38
39 #define FLAG_a 1
40 #define FLAG_b 2
41 #define FLAG_c 4
42 #define FLAG_d 8
43 #define FLAG_e 16
44
37 void hello_main(void) 45 void hello_main(void)
38 { 46 {
39 printf("Hello world\n"); 47 printf("Hello world\n");
48
49 if (toys.optflags & FLAG_a) printf("Saw a\n");
50 if (toys.optflags & FLAG_b) printf("b=%s\n", TT.b_string);
51 if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.c_number);
52 while (TT.d_list) {
53 printf("d=%s\n", TT.d_list->arg);
54 TT.d_list = TT.d_list->next;
55 }
56 if (TT.e_count) printf("e was seen %ld times", TT.e_count);
57
58 while (*toys.optargs) printf("optarg=%s\n", *(toys.optargs++));
40 } 59 }