annotate toys/example/hello.c @ 1539:3e85af1f7e22 draft

First batch of sed tests. Only good for TEST_HOST=1 at the moment because the test infrastructure itself depends on sed, so if an unfinished sed is in the $PATH it goes boing. But hey, corner cases! I have... more.
author Rob Landley <rob@landley.net>
date Wed, 29 Oct 2014 18:44:33 -0500
parents dd2fd057111f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
1 /* hello.c - A hello world program. (Simple template for new commands.)
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
2 *
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
3 * 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
4 *
729
aaa638e82e51 The open group changed their website stupidly, so opengroup.org/onlinepubs forwards to a dead server and you have to use pubs.opengroup.org/onlinepubs now. Change the hello template to note the new location. (Waiting to see if they fix it upstream before touching every command in toys/posix.)
Rob Landley <rob@landley.net>
parents: 694
diff changeset
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
617
a3e014fdeb35 Add LSB link to the template, for reference.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
6 * 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
7
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
8 USE_HELLO(NEWTOY(hello, 0, 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
9
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 config HELLO
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
11 bool "hello"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
12 default n
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
13 help
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
14 usage: hello [-s]
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
15
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
16 A hello world program. You don't need this.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
17
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
18 Mostly used as a simple template for adding new commands.
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
19 Occasionally nice to smoketest kernel booting via "init=/usr/bin/hello".
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
20 */
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
22 #define FOR_hello
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 #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
24
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
25 GLOBALS(
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
26 int unused;
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 )
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
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 13
diff changeset
29 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
30 {
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
31 xprintf("Hello world\n");
403
f6ffc6685a9e Fluff out documentation and skeleton code.
Rob Landley <rob@landley.net>
parents: 381
diff changeset
32
1267
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
33 // Avoid kernel panic if run as init.
dd2fd057111f Add example directory, move hello.c into it, add skeleton.c to demonstrate more complciated stuff (multiple commands per file, etc), and have genconfig.sh sort backwards so posix is first and example last in menuconfig.
Rob Landley <rob@landley.net>
parents: 1261
diff changeset
34 if (getpid() == 1) wait(&TT.unused);
13
d87d8a056295 Add a hello world applet, partly as an example and partly for testing purposes.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 }