annotate toys/hello.c @ 651:ba40e1852ce8

Check in the updated news and status web pages.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 11:51:25 -0500
parents a3e014fdeb35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
2 *
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * hello.c - A hello world program.
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
4 *
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
5 * Copyright 2012 Rob Landley <rob@landley.net>
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
6 *
617
a3e014fdeb35 Add LSB link to the template, for reference.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
7 * Not in SUSv4/LSB.
381
5d4dacab7be0 SUSv4 is out, update template link.
Rob Landley <rob@landley.net>
parents: 339
diff changeset
8 * See http://opengroup.org/onlinepubs/9699919799/utilities/
617
a3e014fdeb35 Add LSB link to the template, for reference.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
9 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
10
239
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
11 USE_HELLO(NEWTOY(hello, "e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN))
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
12
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
13 config HELLO
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
14 bool "hello"
339
157eab6dcdd2 Hello shouldn't be enabled in defconfig.
Rob Landley <rob@landley.net>
parents: 239
diff changeset
15 default n
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
16 help
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
17 usage: hello [-a] [-b string] [-c number] [-d list] [-e count] [...]
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
18
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
19 A hello world program. You don't need this.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
20
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
21 Mostly used as an example/skeleton file for adding new commands,
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
22 occasionally nice to test kernel booting via "init=/bin/hello".
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
23 */
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
24
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 #include "toys.h"
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
26
239
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
27 // Hello doesn't use these globals, they're here for example/skeleton purposes.
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
28
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
29 DEFINE_GLOBALS(
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
30 char *b_string;
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
31 long c_number;
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
32 struct arg_list *d_list;
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
33 long e_count;
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
34
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
35 int more_globals;
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
36 )
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
37
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
38 #define TT this.hello
4f1ca01db000 Fluff out hello.c to supply more example code as a skeleton for new commands,
Rob Landley <rob@landley.net>
parents: 234
diff changeset
39
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
40 #define FLAG_a 1
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
41 #define FLAG_b 2
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
42 #define FLAG_c 4
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
43 #define FLAG_d 8
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
44 #define FLAG_e 16
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
45
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 13
diff changeset
46 void hello_main(void)
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 {
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 printf("Hello world\n");
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
49
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
50 if (toys.optflags & FLAG_a) printf("Saw a\n");
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
51 if (toys.optflags & FLAG_b) printf("b=%s\n", TT.b_string);
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
52 if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.c_number);
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
53 while (TT.d_list) {
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
54 printf("d=%s\n", TT.d_list->arg);
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
55 TT.d_list = TT.d_list->next;
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
56 }
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
57 if (TT.e_count) printf("e was seen %ld times", TT.e_count);
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
58
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
59 while (*toys.optargs) printf("optarg=%s\n", *(toys.optargs++));
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 }