diff options
author | Freya Murphy <freya@freyacat.org> | 2025-03-27 11:39:12 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-03-27 11:39:12 -0400 |
commit | 0ff301cda68669c59351e5854ce98f2cf460543f (patch) | |
tree | cfe8f976261962420ada64b821559b9da0a56841 /user/progH.c | |
parent | add compile_flags.txt for clangd lsp (diff) | |
download | comus-0ff301cda68669c59351e5854ce98f2cf460543f.tar.gz comus-0ff301cda68669c59351e5854ce98f2cf460543f.tar.bz2 comus-0ff301cda68669c59351e5854ce98f2cf460543f.zip |
pull upstream changes, add auto formatting
Diffstat (limited to 'user/progH.c')
-rw-r--r-- | user/progH.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/user/progH.c b/user/progH.c index 386144d..0cef860 100644 --- a/user/progH.c +++ b/user/progH.c @@ -10,57 +10,59 @@ ** n is the number of children to spawn */ -USERMAIN( main ) { - int32_t ret = 0; // return value - int count = 5; // child count - char ch = 'h'; // default character to print +USERMAIN(main) +{ + int32_t ret = 0; // return value + int count = 5; // child count + char ch = 'h'; // default character to print char buf[128]; int whom; // process the argument(s) - switch( argc ) { - case 3: count = str2int( argv[2], 10 ); - // FALL THROUGH - case 2: ch = argv[1][0]; - break; + switch (argc) { + case 3: + count = str2int(argv[2], 10); + // FALL THROUGH + case 2: + ch = argv[1][0]; + break; default: - sprint( buf, "userH: argc %d, args: ", argc ); - cwrites( buf ); - for( int i = 0; i <= argc; ++i ) { - sprint( buf, " %s", argv[argc] ? argv[argc] : "(null)" ); - cwrites( buf ); - } - cwrites( "\n" ); + sprint(buf, "userH: argc %d, args: ", argc); + cwrites(buf); + for (int i = 0; i <= argc; ++i) { + sprint(buf, " %s", argv[argc] ? argv[argc] : "(null)"); + cwrites(buf); + } + cwrites("\n"); } // announce our presence - swritech( ch ); + swritech(ch); // we spawn user Z and then exit before it can terminate // userZ 'Z' 10 char *argsz[] = { "userZ", "Z", "10", NULL }; - for( int i = 0; i < count; ++i ) { - + for (int i = 0; i < count; ++i) { // spawn a child - whom = spawn( ProgZ, argsz ); + whom = spawn(ProgZ, argsz); // our exit status is the number of failed spawn() calls - if( whom < 0 ) { - sprint( buf, "!! %c spawn() failed, returned %d\n", ch, whom ); - cwrites( buf ); + if (whom < 0) { + sprint(buf, "!! %c spawn() failed, returned %d\n", ch, whom); + cwrites(buf); ret += 1; } } // yield the CPU so that our child(ren) can run - sleep( 0 ); + sleep(0); // announce our departure - swritech( ch ); + swritech(ch); - exit( ret ); + exit(ret); - return( 42 ); // shut the compiler up! + return (42); // shut the compiler up! } |