summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
Diffstat (limited to 'user')
-rw-r--r--user/idle.c29
-rw-r--r--user/init.c100
-rw-r--r--user/progABC.c63
-rw-r--r--user/progDE.c53
-rw-r--r--user/progFG.c60
-rw-r--r--user/progH.c56
-rw-r--r--user/progI.c91
-rw-r--r--user/progJ.c49
-rw-r--r--user/progKL.c60
-rw-r--r--user/progMN.c64
-rw-r--r--user/progP.c54
-rw-r--r--user/progQ.c36
-rw-r--r--user/progR.c67
-rw-r--r--user/progS.c53
-rw-r--r--user/progTUV.c124
-rw-r--r--user/progW.c58
-rw-r--r--user/progX.c45
-rw-r--r--user/progY.c47
-rw-r--r--user/progZ.c51
-rw-r--r--user/shell.c221
20 files changed, 716 insertions, 665 deletions
diff --git a/user/idle.c b/user/idle.c
index dbce885..acf8497 100644
--- a/user/idle.c
+++ b/user/idle.c
@@ -10,13 +10,14 @@
** Invoked as: idle
*/
-USERMAIN( main ) {
+USERMAIN(main)
+{
// this is the character we will repeatedly print
char ch = '.';
// ignore the command-line arguments
- (void) argc;
- (void) argv;
+ (void)argc;
+ (void)argv;
// get some current information
uint_t pid = getpid();
@@ -24,28 +25,28 @@ USERMAIN( main ) {
enum priority_e prio = getprio();
char buf[128];
- sprint( buf, "Idle [%d], started @ %u\n", pid, prio, now );
- cwrites( buf );
-
+ sprint(buf, "Idle [%d], started @ %u\n", pid, prio, now);
+ cwrites(buf);
+
// report our presence on the console
- cwrites( "Idle started\n" );
+ cwrites("Idle started\n");
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// idle() should never block - it must always be available
// for dispatching when we need to pick a new current process
- for(;;) {
+ for (;;) {
DELAY(LONG);
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
}
// we should never reach this point!
now = gettime();
- sprint( buf, "Idle [%d] EXITING @ %u!?!?!\n", pid, now );
- cwrites( buf );
+ sprint(buf, "Idle [%d] EXITING @ %u!?!?!\n", pid, now);
+ cwrites(buf);
- exit( 1 );
+ exit(1);
- return( 42 );
+ return (42);
}
diff --git a/user/init.c b/user/init.c
index 56330b1..98d9755 100644
--- a/user/init.c
+++ b/user/init.c
@@ -16,11 +16,11 @@
** to allow 'init' to respawn it when it terminates.
*/
typedef struct proc_s {
- uint_t index; // process table index
- uint_t pid; // its PID (when spawned)
- uint8_t e_prio; // process priority
- char select[3]; // identifying character, NUL, extra
- char *args[MAX_ARGS]; // argument vector strings
+ uint_t index; // process table index
+ uint_t pid; // its PID (when spawned)
+ uint8_t e_prio; // process priority
+ char select[3]; // identifying character, NUL, extra
+ char *args[MAX_ARGS]; // argument vector strings
} proc_t;
/*
@@ -28,11 +28,17 @@ typedef struct proc_s {
** as its argument buffer. We rely on the fact that the C standard
** ensures our array of pointers will be filled out with NULLs
*/
-#define PROCENT(e,p,s,...) { e, 0, p, s, { __VA_ARGS__ , NULL } }
+#define PROCENT(e, p, s, ...) \
+ { \
+ e, 0, p, s, \
+ { \
+ __VA_ARGS__, NULL \
+ } \
+ }
// sentinel value for the end of the table - must be updated
// if you have more than 90,210 user programs in the table
-#define TBLEND 90210
+#define TBLEND 90210
/*
** This table contains one entry for each process that should be
@@ -44,10 +50,10 @@ static proc_t spawn_table[] = {
// the idle process; it runs at Deferred priority,
// so it will only be dispatched when there is
// nothing else available to be dispatched
- PROCENT( Idle, PRIO_DEFERRED, "!", "idle", "." ),
+ PROCENT(Idle, PRIO_DEFERRED, "!", "idle", "."),
// the user shell
- PROCENT( Shell, PRIO_STD, "@", "shell" ),
+ PROCENT(Shell, PRIO_STD, "@", "shell"),
// PROCENT( 0, 0, 0, 0 )
{ TBLEND }
@@ -62,39 +68,33 @@ static char ch = '+';
** @param proc pointer to the spawn table entry to be used
*/
-static void process( proc_t *proc )
+static void process(proc_t *proc)
{
char buf[128];
// kick off the process
int32_t p = fork();
- if( p < 0 ) {
-
+ if (p < 0) {
// error!
- sprint( buf, "INIT: fork for #%d failed\n",
- (uint32_t) (proc->index) );
- cwrites( buf );
-
- } else if( p == 0 ) {
+ sprint(buf, "INIT: fork for #%d failed\n", (uint32_t)(proc->index));
+ cwrites(buf);
+ } else if (p == 0) {
// change child's priority
- (void) setprio( proc->e_prio );
+ (void)setprio(proc->e_prio);
// now, send it on its way
- exec( proc->index, proc->args );
+ exec(proc->index, proc->args);
// uh-oh - should never get here!
- sprint( buf, "INIT: exec(0x%08x) failed\n",
- (uint32_t) (proc->index) );
- cwrites( buf );
+ sprint(buf, "INIT: exec(0x%08x) failed\n", (uint32_t)(proc->index));
+ cwrites(buf);
} else {
-
// parent just reports that another one was started
- swritech( ch );
+ swritech(ch);
proc->pid = p;
-
}
}
@@ -103,71 +103,71 @@ static void process( proc_t *proc )
** argument; if provided, the first argument should be the ASCII
** character 'init' will print to indicate the spawning of a process.
*/
-USERMAIN( main ) {
+USERMAIN(main)
+{
char buf[128];
// check to see if we got a non-standard "spawn" character
- if( argc > 1 ) {
+ if (argc > 1) {
// maybe - check it to be sure it's printable
uint_t i = argv[1][0];
- if( i > ' ' && i < 0x7f ) {
+ if (i > ' ' && i < 0x7f) {
ch = argv[1][0];
}
}
- cwrites( "Init started\n" );
+ cwrites("Init started\n");
// home up, clear on a TVI 925
- swritech( '\x1a' );
+ swritech('\x1a');
// wait a bit
DELAY(SHORT);
// a bit of Dante to set the mood :-)
- swrites( "\n\nSpem relinquunt qui huc intrasti!\n\n\r" );
+ swrites("\n\nSpem relinquunt qui huc intrasti!\n\n\r");
/*
** Start all the user processes
*/
- cwrites( "INIT: starting user processes\n" );
+ cwrites("INIT: starting user processes\n");
proc_t *next;
- for( next = spawn_table; next->index != TBLEND; ++next ) {
- process( next );
+ for (next = spawn_table; next->index != TBLEND; ++next) {
+ process(next);
}
- swrites( " !!!\r\n\n" );
+ swrites(" !!!\r\n\n");
/*
** At this point, we go into an infinite loop waiting
** for our children (direct, or inherited) to exit.
*/
- cwrites( "INIT: transitioning to wait() mode\n" );
+ cwrites("INIT: transitioning to wait() mode\n");
- for(;;) {
+ for (;;) {
int32_t status;
- int whom = waitpid( 0, &status );
+ int whom = waitpid(0, &status);
// PIDs must be positive numbers!
- if( whom <= 0 ) {
- sprint( buf, "INIT: waitpid() returned %d???\n", whom );
- cwrites( buf );
+ if (whom <= 0) {
+ sprint(buf, "INIT: waitpid() returned %d???\n", whom);
+ cwrites(buf);
} else {
-
// got one; report it
- sprint( buf, "INIT: pid %d exit(%d)\n", whom, status );
- cwrites( buf );
+ sprint(buf, "INIT: pid %d exit(%d)\n", whom, status);
+ cwrites(buf);
// figure out if this is one of ours
- for( next = spawn_table; next->index != TBLEND; ++next ) {
- if( next->pid == whom ) {
+ for (next = spawn_table; next->index != TBLEND; ++next) {
+ if (next->pid == whom) {
// one of ours - reset the PID field
// (in case the spawn attempt fails)
next->pid = 0;
// and restart it
- process( next );
+ process(next);
break;
}
}
@@ -178,8 +178,8 @@ USERMAIN( main ) {
** SHOULD NEVER REACH HERE
*/
- cwrites( "*** INIT IS EXITING???\n" );
- exit( 1 );
+ cwrites("*** INIT IS EXITING???\n");
+ exit(1);
- return( 1 ); // shut the compiler up
+ return (1); // shut the compiler up
}
diff --git a/user/progABC.c b/user/progABC.c
index 4f7b6e6..0a4b299 100644
--- a/user/progABC.c
+++ b/user/progABC.c
@@ -11,58 +11,61 @@
** n is the iteration count
*/
-USERMAIN( main ) {
+USERMAIN(main)
+{
int count = 30; // default iteration count
- char ch = '1'; // default character to print
- char buf[128]; // local char buffer
+ char ch = '1'; // default character to print
+ char buf[128]; // local char buffer
// process the command-line arguments
- 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, "%s: argc %d, args: ", argv[0], argc );
- cwrites( buf );
- for( int i = 0; i <= argc; ++i ) {
- sprint( buf, " %s", argv[argc] ? argv[argc] : "(null)" );
- cwrites( buf );
- }
- cwrites( "\n" );
+ sprint(buf, "%s: argc %d, args: ", argv[0], 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
- int n = swritech( ch );
- if( n != 1 ) {
- sprint( buf, "== %c, write #1 returned %d\n", ch, n );
- cwrites( buf );
+ int n = swritech(ch);
+ if (n != 1) {
+ sprint(buf, "== %c, write #1 returned %d\n", ch, n);
+ cwrites(buf);
}
// iterate and print the required number of other characters
- for( int i = 0; i < count; ++i ) {
+ for (int i = 0; i < count; ++i) {
DELAY(STD);
- n = swritech( ch );
- if( n != 1 ) {
- sprint( buf, "== %c, write #2 returned %d\n", ch, n );
- cwrites( buf );
+ n = swritech(ch);
+ if (n != 1) {
+ sprint(buf, "== %c, write #2 returned %d\n", ch, n);
+ cwrites(buf);
}
}
// all done!
- exit( 0 );
+ exit(0);
// should never reach this code; if we do, something is
// wrong with exit(), so we'll report it
char msg[] = "*1*";
msg[1] = ch;
- n = write( CHAN_SIO, msg, 3 ); /* shouldn't happen! */
- if( n != 3 ) {
- sprint( buf, "User %c, write #3 returned %d\n", ch, n );
- cwrites( buf );
+ n = write(CHAN_SIO, msg, 3); /* shouldn't happen! */
+ if (n != 3) {
+ sprint(buf, "User %c, write #3 returned %d\n", ch, n);
+ cwrites(buf);
}
// this should really get us out of here
- return( 42 );
+ return (42);
}
diff --git a/user/progDE.c b/user/progDE.c
index a1aa0b3..be2dd1b 100644
--- a/user/progDE.c
+++ b/user/progDE.c
@@ -12,45 +12,48 @@
** n is the iteration count
*/
-USERMAIN( main ) {
+USERMAIN(main)
+{
int n;
- int count = 30; // default iteration count
- char ch = '2'; // default character to print
+ int count = 30; // default iteration count
+ char ch = '2'; // default character to print
char buf[128];
// process the command-line arguments
- 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, "main2: 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, "main2: 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
- n = swritech( ch );
- if( n != 1 ) {
- sprint( buf, "== %c, write #1 returned %d\n", ch, n );
- cwrites( buf );
+ n = swritech(ch);
+ if (n != 1) {
+ sprint(buf, "== %c, write #1 returned %d\n", ch, n);
+ cwrites(buf);
}
// iterate and print the required number of other characters
- for( int i = 0; i < count; ++i ) {
+ for (int i = 0; i < count; ++i) {
DELAY(STD);
- n = swritech( ch );
- if( n != 1 ) {
- sprint( buf, "== %c, write #2 returned %d\n", ch, n );
- cwrites( buf );
+ n = swritech(ch);
+ if (n != 1) {
+ sprint(buf, "== %c, write #2 returned %d\n", ch, n);
+ cwrites(buf);
}
}
// all done!
- return( 0 );
+ return (0);
}
diff --git a/user/progFG.c b/user/progFG.c
index a43ca67..8dddd56 100644
--- a/user/progFG.c
+++ b/user/progFG.c
@@ -11,45 +11,49 @@
** s is the sleep time in seconds
*/
-USERMAIN( main ) {
- char ch = '3'; // default character to print
- int nap = 10; // default sleep time
- int count = 30; // iteration count
+USERMAIN(main)
+{
+ char ch = '3'; // default character to print
+ int nap = 10; // default sleep time
+ int count = 30; // iteration count
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 4: nap = str2int( argv[3], 10 );
- // FALL THROUGH
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ nap = str2int(argv[3], 10);
+ // FALL THROUGH
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "main3: 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, "main3: 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
- int n = swritech( ch );
- if( n != 1 ) {
- sprint( buf, "=== %c, write #1 returned %d\n", ch, n );
- cwrites( buf );
+ int n = swritech(ch);
+ if (n != 1) {
+ sprint(buf, "=== %c, write #1 returned %d\n", ch, n);
+ cwrites(buf);
}
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
- for( int i = 0; i < count ; ++i ) {
- sleep( SEC_TO_MS(nap) );
- write( CHAN_SIO, &ch, 1 );
+ for (int i = 0; i < count; ++i) {
+ sleep(SEC_TO_MS(nap));
+ write(CHAN_SIO, &ch, 1);
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
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!
}
diff --git a/user/progI.c b/user/progI.c
index c37eddf..a1988e3 100644
--- a/user/progI.c
+++ b/user/progI.c
@@ -1,7 +1,7 @@
#include <common.h>
#ifndef MAX_CHILDREN
-#define MAX_CHILDREN 50
+#define MAX_CHILDREN 50
#endif
/**
@@ -15,90 +15,93 @@
** n is the number of children to spawn (defaults to 5)
*/
-USERMAIN( main ) {
- int count = 5; // default child count
- char ch = 'i'; // default character to print
- int nap = 5; // nap time
+USERMAIN(main)
+{
+ int count = 5; // default child count
+ char ch = 'i'; // default character to print
+ int nap = 5; // nap time
char buf[128];
char ch2[] = "*?*";
uint_t children[MAX_CHILDREN];
int nkids = 0;
// process the command-line arguments
- switch( argc ) {
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
- case 1: // just use the defaults
- break;
+ switch (argc) {
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
+ case 1: // just use the defaults
+ break;
default:
- sprint( buf, "userI: 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, "userI: 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");
}
// secondary output (for indicating errors)
ch2[1] = ch;
// announce our presence
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// set up the argument vector
// we run: userW 10 5
char *argsw[] = { "userW", "W", "10", "5", NULL };
- for( int i = 0; i < count; ++i ) {
- int whom = spawn( ProgW, argsw );
- if( whom < 0 ) {
- swrites( ch2 );
+ for (int i = 0; i < count; ++i) {
+ int whom = spawn(ProgW, argsw);
+ if (whom < 0) {
+ swrites(ch2);
} else {
- swritech( ch );
+ swritech(ch);
children[nkids++] = whom;
}
}
// let the children start
- sleep( SEC_TO_MS(nap) );
+ sleep(SEC_TO_MS(nap));
// kill two of them
- int32_t status = kill( children[1] );
- if( status ) {
- sprint( buf, "!! %c: kill(%d) status %d\n", ch, children[1], status );
- cwrites( buf );
+ int32_t status = kill(children[1]);
+ if (status) {
+ sprint(buf, "!! %c: kill(%d) status %d\n", ch, children[1], status);
+ cwrites(buf);
children[1] = -42;
}
- status = kill( children[3] );
- if( status ) {
- sprint( buf, "!! %c: kill(%d) status %d\n", ch, children[3], status );
- cwrites( buf );
+ status = kill(children[3]);
+ if (status) {
+ sprint(buf, "!! %c: kill(%d) status %d\n", ch, children[3], status);
+ cwrites(buf);
children[3] = -42;
}
// collect child information
- while( 1 ) {
- int n = waitpid( 0, NULL );
- if( n == E_NO_CHILDREN ) {
+ while (1) {
+ int n = waitpid(0, NULL);
+ if (n == E_NO_CHILDREN) {
// all done!
break;
}
- for( int i = 0; i < count; ++i ) {
- if( children[i] == n ) {
- sprint( buf, "== %c: child %d (%d)\n", ch, i, children[i] );
- cwrites( buf );
+ for (int i = 0; i < count; ++i) {
+ if (children[i] == n) {
+ sprint(buf, "== %c: child %d (%d)\n", ch, i, children[i]);
+ cwrites(buf);
}
}
- sleep( SEC_TO_MS(nap) );
+ sleep(SEC_TO_MS(nap));
};
// let init() clean up after us!
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progJ.c b/user/progJ.c
index 6eb4464..a1e6310 100644
--- a/user/progJ.c
+++ b/user/progJ.c
@@ -10,43 +10,46 @@
** n is the number of children to spawn (defaults to 2 * N_PROCS)
*/
-USERMAIN( main ) {
- int count = 2 * N_PROCS; // number of children to spawn
- char ch = 'j'; // default character to print
+USERMAIN(main)
+{
+ int count = 2 * N_PROCS; // number of children to spawn
+ char ch = 'j'; // default character to print
char buf[128];
// process the command-line arguments
- 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, "userJ: 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, "userJ: 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
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// set up the command-line arguments
char *argsy[] = { "userY", "Y", "10", NULL };
- for( int i = 0; i < count ; ++i ) {
- int whom = spawn( ProgY, argsy );
- if( whom < 0 ) {
- write( CHAN_SIO, "!j!", 3 );
+ for (int i = 0; i < count; ++i) {
+ int whom = spawn(ProgY, argsy);
+ if (whom < 0) {
+ write(CHAN_SIO, "!j!", 3);
} else {
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
}
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progKL.c b/user/progKL.c
index 6bfb987..aa9f039 100644
--- a/user/progKL.c
+++ b/user/progKL.c
@@ -10,52 +10,54 @@
** n is the iteration count (defaults to 5)
*/
-USERMAIN( main ) {
- int count = 5; // default iteration count
- char ch = '4'; // default character to print
- int nap = 30; // nap time
- char msg2[] = "*4*"; // "error" message to print
+USERMAIN(main)
+{
+ int count = 5; // default iteration count
+ char ch = '4'; // default character to print
+ int nap = 30; // nap time
+ char msg2[] = "*4*"; // "error" message to print
char buf[32];
// process the command-line arguments
- 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, "main4: 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, "main4: 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
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// argument vector for the processes we will spawn
char *arglist[] = { "userX", "X", buf, NULL };
- for( int i = 0; i < count ; ++i ) {
-
- write( CHAN_SIO, &ch, 1 );
+ for (int i = 0; i < count; ++i) {
+ write(CHAN_SIO, &ch, 1);
// second argument to X is 100 plus the iteration number
- sprint( buf, "%d", 100 + i );
- int whom = spawn( ProgX, arglist );
- if( whom < 0 ) {
- swrites( msg2 );
+ sprint(buf, "%d", 100 + i);
+ int whom = spawn(ProgX, arglist);
+ if (whom < 0) {
+ swrites(msg2);
} else {
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
}
- sleep( SEC_TO_MS(nap) );
+ sleep(SEC_TO_MS(nap));
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progMN.c b/user/progMN.c
index 38ccd31..d2dbe9b 100644
--- a/user/progMN.c
+++ b/user/progMN.c
@@ -12,37 +12,41 @@
** b is the w&z boolean
*/
-USERMAIN( main ) {
- int count = 5; // default iteration count
- char ch = '5'; // default character to print
- int alsoZ = 0; // also do userZ?
+USERMAIN(main)
+{
+ int count = 5; // default iteration count
+ char ch = '5'; // default character to print
+ int alsoZ = 0; // also do userZ?
char msgw[] = "*5w*";
char msgz[] = "*5z*";
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 4: alsoZ = argv[3][0] == 't';
- // FALL THROUGH
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ alsoZ = argv[3][0] == 't';
+ // FALL THROUGH
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "main5: 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, "main5: 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");
}
// update the extra message strings
msgw[1] = msgz[1] = ch;
// announce our presence
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// set up the argument vector(s)
@@ -52,21 +56,21 @@ USERMAIN( main ) {
// Z: 15 iterations
char *argsz[] = { "userZ", "Z", "15", NULL };
- for( int i = 0; i < count; ++i ) {
- write( CHAN_SIO, &ch, 1 );
- int whom = spawn( ProgW, argsw );
- if( whom < 1 ) {
- swrites( msgw );
+ for (int i = 0; i < count; ++i) {
+ write(CHAN_SIO, &ch, 1);
+ int whom = spawn(ProgW, argsw);
+ if (whom < 1) {
+ swrites(msgw);
}
- if( alsoZ ) {
- whom = spawn( ProgZ, argsz );
- if( whom < 1 ) {
- swrites( msgz );
+ if (alsoZ) {
+ whom = spawn(ProgZ, argsz);
+ if (whom < 1) {
+ swrites(msgz);
}
}
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progP.c b/user/progP.c
index 5a264a5..8909599 100644
--- a/user/progP.c
+++ b/user/progP.c
@@ -11,41 +11,45 @@
** t is the sleep time (defaults to 2 seconds)
*/
-USERMAIN( main ) {
- int count = 3; // default iteration count
- char ch = 'p'; // default character to print
- int nap = 2; // nap time
+USERMAIN(main)
+{
+ int count = 3; // default iteration count
+ char ch = 'p'; // default character to print
+ int nap = 2; // nap time
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 4: nap = str2int( argv[3], 10 );
- // FALL THROUGH
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ nap = str2int(argv[3], 10);
+ // FALL THROUGH
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "userP: 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, "userP: 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
uint32_t now = gettime();
- sprint( buf, " P@%u", now );
- swrites( buf );
+ sprint(buf, " P@%u", now);
+ swrites(buf);
- for( int i = 0; i < count; ++i ) {
- sleep( SEC_TO_MS(nap) );
- write( CHAN_SIO, &ch, 1 );
+ for (int i = 0; i < count; ++i) {
+ sleep(SEC_TO_MS(nap));
+ write(CHAN_SIO, &ch, 1);
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progQ.c b/user/progQ.c
index ecfcffc..660c2d6 100644
--- a/user/progQ.c
+++ b/user/progQ.c
@@ -9,35 +9,37 @@
** where x is the ID character
*/
-USERMAIN( main ) {
- char ch = 'q'; // default character to print
+USERMAIN(main)
+{
+ char ch = 'q'; // default character to print
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "userQ: 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, "userQ: 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
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// try something weird
bogus();
// should not have come back here!
- sprint( buf, "!!!!! %c returned from bogus syscall!?!?!\n", ch );
- cwrites( buf );
+ sprint(buf, "!!!!! %c returned from bogus syscall!?!?!\n", ch);
+ cwrites(buf);
- exit( 1 );
+ exit(1);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progR.c b/user/progR.c
index 1d47f6b..672318b 100644
--- a/user/progR.c
+++ b/user/progR.c
@@ -13,28 +13,32 @@
** s is the initial delay time (defaults to 10)
*/
-USERMAIN( main ) {
- char ch = 'r'; // default character to print
- int delay = 10; // initial delay count
- int seq = 99; // my sequence number
+USERMAIN(main)
+{
+ char ch = 'r'; // default character to print
+ int delay = 10; // initial delay count
+ int seq = 99; // my sequence number
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 4: delay = str2int( argv[3], 10 );
- // FALL THROUGH
- case 3: seq = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ delay = str2int(argv[3], 10);
+ // FALL THROUGH
+ case 3:
+ seq = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "userR: 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, "userR: 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");
}
/*
@@ -55,26 +59,26 @@ USERMAIN( main ) {
int32_t pid;
int32_t ppid;
- restart:
+restart:
// announce our presence
pid = getpid();
ppid = getppid();
- sprint( buf, " %c[%d,%d,%d]", ch, seq, pid, ppid );
- swrites( buf );
+ sprint(buf, " %c[%d,%d,%d]", ch, seq, pid, ppid);
+ swrites(buf);
- sleep( SEC_TO_MS(delay) );
+ sleep(SEC_TO_MS(delay));
// create the next child in sequence
- if( seq < 5 ) {
+ if (seq < 5) {
++seq;
int32_t n = fork();
- switch( n ) {
+ switch (n) {
case -1:
// failure?
- sprint( buf, "** R[%d] fork code %d\n", pid, n );
- cwrites( buf );
+ sprint(buf, "** R[%d] fork code %d\n", pid, n);
+ cwrites(buf);
break;
case 0:
// child
@@ -82,18 +86,17 @@ USERMAIN( main ) {
default:
// parent
--seq;
- sleep( SEC_TO_MS(delay) );
+ sleep(SEC_TO_MS(delay));
}
}
// final report - PPID may change, but PID and seq shouldn't
pid = getpid();
ppid = getppid();
- sprint( buf, " %c[%d,%d,%d]", ch, seq, pid, ppid );
- swrites( buf );
-
- exit( 0 );
+ sprint(buf, " %c[%d,%d,%d]", ch, seq, pid, ppid);
+ swrites(buf);
- return( 42 ); // shut the compiler up!
+ exit(0);
+ return (42); // shut the compiler up!
}
diff --git a/user/progS.c b/user/progS.c
index d220955..c8e0e60 100644
--- a/user/progS.c
+++ b/user/progS.c
@@ -10,41 +10,44 @@
** s is the sleep time (defaults to 20)
*/
-USERMAIN( main ) {
- char ch = 's'; // default character to print
- int nap = 20; // nap time
+USERMAIN(main)
+{
+ char ch = 's'; // default character to print
+ int nap = 20; // nap time
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 3: nap = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 3:
+ nap = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "userS: 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, "userS: 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
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
- sprint( buf, "userS sleeping %d(%d)\n", nap, SEC_TO_MS(nap) );
- cwrites( buf );
+ sprint(buf, "userS sleeping %d(%d)\n", nap, SEC_TO_MS(nap));
+ cwrites(buf);
- for(;;) {
- sleep( SEC_TO_MS(nap) );
- write( CHAN_SIO, &ch, 1 );
+ for (;;) {
+ sleep(SEC_TO_MS(nap));
+ write(CHAN_SIO, &ch, 1);
}
- sprint( buf, "!! %c exiting!?!?!?\n", ch );
- cwrites( buf );
- exit( 1 );
+ sprint(buf, "!! %c exiting!?!?!?\n", ch);
+ cwrites(buf);
+ exit(1);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progTUV.c b/user/progTUV.c
index 3d5ed49..8e69a66 100644
--- a/user/progTUV.c
+++ b/user/progTUV.c
@@ -13,14 +13,15 @@
*/
#ifndef MAX_CHILDREN
-#define MAX_CHILDREN 50
+#define MAX_CHILDREN 50
#endif
-USERMAIN( main ) {
- int count = 3; // default child count
- char ch = '6'; // default character to print
- int nap = 8; // nap time
- bool_t waiting = true; // default is waiting by PID
+USERMAIN(main)
+{
+ int count = 3; // default child count
+ char ch = '6'; // default character to print
+ int nap = 8; // nap time
+ bool_t waiting = true; // default is waiting by PID
bool_t bypid = true;
char buf[128];
uint_t children[MAX_CHILDREN];
@@ -28,44 +29,47 @@ USERMAIN( main ) {
char ch2[] = "*?*";
// process the command-line arguments
- switch( argc ) {
- case 4: waiting = argv[3][0] != 'k'; // 'w'/'W' -> wait, else -> kill
- bypid = argv[3][0] != 'w'; // 'W'/'k' -> by PID
- // FALL THROUGH
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ waiting = argv[3][0] != 'k'; // 'w'/'W' -> wait, else -> kill
+ bypid = argv[3][0] != 'w'; // 'W'/'k' -> by PID
+ // FALL THROUGH
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "main6: 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, "main6: 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");
}
// fix the secondary output message (for indicating errors)
ch2[1] = ch;
// announce our presence
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
// set up the argument vector
char *argsw[] = { "userW", "W", "10", "5", NULL };
- for( int i = 0; i < count; ++i ) {
- int whom = spawn( ProgW, argsw );
- if( whom < 0 ) {
- swrites( ch2 );
+ for (int i = 0; i < count; ++i) {
+ int whom = spawn(ProgW, argsw);
+ if (whom < 0) {
+ swrites(ch2);
} else {
children[nkids++] = whom;
}
}
// let the children start
- sleep( SEC_TO_MS(nap) );
+ sleep(SEC_TO_MS(nap));
// collect exit status information
@@ -77,57 +81,55 @@ USERMAIN( main ) {
int32_t status;
// are we waiting for or killing it?
- if( waiting ) {
- this = waitpid( bypid ? children[n] : 0, &status );
+ if (waiting) {
+ this = waitpid(bypid ? children[n] : 0, &status);
} else {
// always by PID
- this = kill( children[n] );
+ this = kill(children[n]);
}
// what was the result?
- if( this < SUCCESS ) {
-
+ if (this < SUCCESS) {
// uh-oh - something went wrong
// "no children" means we're all done
- if( this != E_NO_CHILDREN ) {
- if( waiting ) {
- sprint( buf, "!! %c: waitpid(%d) status %d\n",
- ch, bypid ? children[n] : 0, this );
+ if (this != E_NO_CHILDREN) {
+ if (waiting) {
+ sprint(buf, "!! %c: waitpid(%d) status %d\n", ch,
+ bypid ? children[n] : 0, this);
} else {
- sprint( buf, "!! %c: kill(%d) status %d\n",
- ch, children[n], this );
+ sprint(buf, "!! %c: kill(%d) status %d\n", ch, children[n],
+ this);
}
} else {
- sprint( buf, "!! %c: no children\n", ch );
+ sprint(buf, "!! %c: no children\n", ch);
}
// regardless, we're outta here
break;
} else {
-
// locate the child
int ix = -1;
// were we looking by PID?
- if( bypid ) {
+ if (bypid) {
// we should have just gotten the one we were looking for
- if( this != children[n] ) {
+ if (this != children[n]) {
// uh-oh
- sprint( buf, "** %c: wait/kill PID %d, got %d\n",
- ch, children[n], this );
- cwrites( buf );
+ sprint(buf, "** %c: wait/kill PID %d, got %d\n", ch,
+ children[n], this);
+ cwrites(buf);
} else {
ix = n;
}
}
// either not looking by PID, or the lookup failed somehow
- if( ix < 0 ) {
+ if (ix < 0) {
int i;
- for( i = 0; i < nkids; ++i ) {
- if( children[i] == this ) {
+ for (i = 0; i < nkids; ++i) {
+ if (children[i] == this) {
ix = i;
break;
}
@@ -136,34 +138,30 @@ USERMAIN( main ) {
// if ix == -1, the PID we received isn't in our list of children
- if( ix < 0 ) {
-
+ if (ix < 0) {
// didn't find an entry for this PID???
- sprint( buf, "!! %c: child PID %d term, NOT FOUND\n",
- ch, this );
+ sprint(buf, "!! %c: child PID %d term, NOT FOUND\n", ch, this);
} else {
-
// found this PID in our list of children
- if( ix != n ) {
+ if (ix != n) {
// ... but it's out of sequence
- sprint( buf, "== %c: child %d (%d,%d) status %d\n",
- ch, ix, n, this, status );
+ sprint(buf, "== %c: child %d (%d,%d) status %d\n", ch, ix,
+ n, this, status);
} else {
- sprint( buf, "== %c: child %d (%d) status %d\n",
- ch, ix, this, status );
+ sprint(buf, "== %c: child %d (%d) status %d\n", ch, ix,
+ this, status);
}
}
-
}
- cwrites( buf );
+ cwrites(buf);
++n;
- } while( n < nkids );
+ } while (n < nkids);
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progW.c b/user/progW.c
index 5903663..b71ec23 100644
--- a/user/progW.c
+++ b/user/progW.c
@@ -12,46 +12,50 @@
** s is the sleep time (defaults to 3 seconds)
*/
-USERMAIN( main ) {
- int count = 20; // default iteration count
- char ch = 'w'; // default character to print
- int nap = 3; // nap length
+USERMAIN(main)
+{
+ int count = 20; // default iteration count
+ char ch = 'w'; // default character to print
+ int nap = 3; // nap length
char buf[128];
// process the command-line arguments
- switch( argc ) {
- case 4: nap = str2int( argv[3], 10 );
- // FALL THROUGH
- case 3: count = str2int( argv[2], 10 );
- // FALL THROUGH
- case 2: ch = argv[1][0];
- break;
+ switch (argc) {
+ case 4:
+ nap = str2int(argv[3], 10);
+ // FALL THROUGH
+ case 3:
+ count = str2int(argv[2], 10);
+ // FALL THROUGH
+ case 2:
+ ch = argv[1][0];
+ break;
default:
- sprint( buf, "userW: 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, "userW: 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
int pid = getpid();
uint32_t now = gettime();
- sprint( buf, " %c[%d,%u]", ch, pid, now );
- swrites( buf );
+ sprint(buf, " %c[%d,%u]", ch, pid, now);
+ swrites(buf);
- write( CHAN_SIO, &ch, 1 );
+ write(CHAN_SIO, &ch, 1);
- for( int i = 0; i < count ; ++i ) {
+ for (int i = 0; i < count; ++i) {
now = gettime();
- sprint( buf, " %c[%d,%u] ", ch, pid, now );
- swrites( buf );
- sleep( SEC_TO_MS(nap) );
+ sprint(buf, " %c[%d,%u] ", ch, pid, now);
+ swrites(buf);
+ sleep(SEC_TO_MS(nap));
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progX.c b/user/progX.c
index ed356b9..782823e 100644
--- a/user/progX.c
+++ b/user/progX.c
@@ -11,38 +11,41 @@
** n is the iteration count
*/
-USERMAIN( main ) {
- int count = 20; // iteration count
- char ch = 'x'; // default character to print
+USERMAIN(main)
+{
+ int count = 20; // iteration count
+ char ch = 'x'; // default character to print
char buf[128];
// process the command-line arguments
- 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, "userX: 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, "userX: 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
int pid = getpid();
- sprint( buf, " %c[%d]", ch, pid );
- swrites( buf );
+ sprint(buf, " %c[%d]", ch, pid);
+ swrites(buf);
- for( int i = 0; i < count ; ++i ) {
- swrites( buf );
+ for (int i = 0; i < count; ++i) {
+ swrites(buf);
DELAY(STD);
}
- exit( 12 );
+ exit(12);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progY.c b/user/progY.c
index 194f188..43313bd 100644
--- a/user/progY.c
+++ b/user/progY.c
@@ -11,39 +11,42 @@
** n is the iteration count (defaults to 10)
*/
-USERMAIN( main ) {
- int count = 10; // default iteration count
- char ch = 'y'; // default character to print
+USERMAIN(main)
+{
+ int count = 10; // default iteration count
+ char ch = 'y'; // default character to print
char buf[128];
// process the command-line arguments
- 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, "?: 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, "?: 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");
}
// report our presence
int pid = getpid();
- sprint( buf, " %c[%d]", ch, pid );
- swrites( buf );
+ sprint(buf, " %c[%d]", ch, pid);
+ swrites(buf);
- for( int i = 0; i < count ; ++i ) {
- swrites( buf );
+ for (int i = 0; i < count; ++i) {
+ swrites(buf);
DELAY(STD);
- sleep( SEC_TO_MS(1) );
+ sleep(SEC_TO_MS(1));
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/progZ.c b/user/progZ.c
index cc394c4..fdeb888 100644
--- a/user/progZ.c
+++ b/user/progZ.c
@@ -15,43 +15,46 @@
** n is the iteration count (defaults to 10)
*/
-USERMAIN( main ) {
- int count = 10; // default iteration count
- char ch = 'z'; // default character to print
+USERMAIN(main)
+{
+ int count = 10; // default iteration count
+ char ch = 'z'; // default character to print
char buf[128];
// process the command-line arguments
- 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, "?: 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, "?: 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
int pid = getpid();
- sprint( buf, " %c[%d]", ch, pid );
- swrites( buf );
+ sprint(buf, " %c[%d]", ch, pid);
+ swrites(buf);
// iterate for a while; occasionally yield the CPU
- for( int i = 0; i < count ; ++i ) {
- sprint( buf, " %c[%d]", ch, i );
- swrites( buf );
+ for (int i = 0; i < count; ++i) {
+ sprint(buf, " %c[%d]", ch, i);
+ swrites(buf);
DELAY(STD);
- if( i & 1 ) {
- sleep( 0 );
+ if (i & 1) {
+ sleep(0);
}
}
- exit( 0 );
+ exit(0);
- return( 42 ); // shut the compiler up!
+ return (42); // shut the compiler up!
}
diff --git a/user/shell.c b/user/shell.c
index 5412033..628e9b7 100644
--- a/user/shell.c
+++ b/user/shell.c
@@ -24,10 +24,10 @@ static int children = 0;
** except this one has no place to store the PID of the child.
*/
typedef struct proc_s {
- uint_t index; // process table index
- int8_t prio; // process priority
- char select[3]; // identifying character, NUL, extra
- char *args[MAX_ARGS]; // argument vector strings
+ uint_t index; // process table index
+ int8_t prio; // process priority
+ char select[3]; // identifying character, NUL, extra
+ char *args[MAX_ARGS]; // argument vector strings
} proc_t;
/*
@@ -35,11 +35,17 @@ typedef struct proc_s {
** as its argument buffer. We rely on the fact that the C standard
** ensures our array of pointers will be filled out with NULLs
*/
-#define PROCENT(e, p, s, ...) { e, p, s, { __VA_ARGS__ , NULL } }
+#define PROCENT(e, p, s, ...) \
+ { \
+ e, p, s, \
+ { \
+ __VA_ARGS__, NULL \
+ } \
+ }
// sentinel value for the end of the table - must be updated
// if you have more than 90,210 user programs in the table
-#define TBLEND 90210
+#define TBLEND 90210
/*
** The spawn table contains entries for processes that are started
@@ -47,102 +53,102 @@ typedef struct proc_s {
*/
static proc_t spawn_table[] = {
- // Users A-C each run ProgABC, which loops printing its character
+// Users A-C each run ProgABC, which loops printing its character
#if defined(SPAWN_A)
- PROCENT( ProgABC, PRIO_STD, "A", "userA", "A", "30" ),
+ PROCENT(ProgABC, PRIO_STD, "A", "userA", "A", "30"),
#endif
#if defined(SPAWN_B)
- PROCENT( ProgABC, PRIO_STD, "B", "userB", "B", "30" ),
+ PROCENT(ProgABC, PRIO_STD, "B", "userB", "B", "30"),
#endif
#if defined(SPAWN_C)
- PROCENT( ProgABC, PRIO_STD, "C", "userC", "C", "30" ),
+ PROCENT(ProgABC, PRIO_STD, "C", "userC", "C", "30"),
#endif
- // Users D and E run ProgDE, which is like ProgABC but doesn't exit()
+// Users D and E run ProgDE, which is like ProgABC but doesn't exit()
#if defined(SPAWN_D)
- PROCENT( ProgDE, PRIO_STD, "D", "userD", "D", "20" ),
+ PROCENT(ProgDE, PRIO_STD, "D", "userD", "D", "20"),
#endif
#if defined(SPAWN_E)
- PROCENT( ProgDE, PRIO_STD, "E", "userE", "E", "20" ),
+ PROCENT(ProgDE, PRIO_STD, "E", "userE", "E", "20"),
#endif
- // Users F and G run ProgFG, which sleeps between write() calls
+// Users F and G run ProgFG, which sleeps between write() calls
#if defined(SPAWN_F)
- PROCENT( ProgFG, PRIO_STD, "F", "userF", "F", "20" ),
+ PROCENT(ProgFG, PRIO_STD, "F", "userF", "F", "20"),
#endif
#if defined(SPAWN_G)
- PROCENT( ProgFG, PRIO_STD, "G", "userG", "G", "10" ),
+ PROCENT(ProgFG, PRIO_STD, "G", "userG", "G", "10"),
#endif
- // User H tests reparenting of orphaned children
+// User H tests reparenting of orphaned children
#if defined(SPAWN_H)
- PROCENT( ProgH, PRIO_STD, "H", "userH", "H", "4" ),
+ PROCENT(ProgH, PRIO_STD, "H", "userH", "H", "4"),
#endif
- // User I spawns several children, kills one, and waits for all
+// User I spawns several children, kills one, and waits for all
#if defined(SPAWN_I)
- PROCENT( ProgI, PRIO_STD, "I", "userI", "I" ),
+ PROCENT(ProgI, PRIO_STD, "I", "userI", "I"),
#endif
- // User J tries to spawn 2 * N_PROCS children
+// User J tries to spawn 2 * N_PROCS children
#if defined(SPAWN_J)
- PROCENT( ProgJ, PRIO_STD, "J", "userJ", "J" ),
+ PROCENT(ProgJ, PRIO_STD, "J", "userJ", "J"),
#endif
- // Users K and L iterate spawning userX and sleeping
+// Users K and L iterate spawning userX and sleeping
#if defined(SPAWN_K)
- PROCENT( ProgKL, PRIO_STD, "K", "userK", "K", "8" ),
+ PROCENT(ProgKL, PRIO_STD, "K", "userK", "K", "8"),
#endif
#if defined(SPAWN_L)
- PROCENT( ProgKL, PRIO_STD, "L", "userL", "L", "5" ),
+ PROCENT(ProgKL, PRIO_STD, "L", "userL", "L", "5"),
#endif
- // Users M and N spawn copies of userW and userZ via ProgMN
+// Users M and N spawn copies of userW and userZ via ProgMN
#if defined(SPAWN_M)
- PROCENT( ProgMN, PRIO_STD, "M", "userM", "M", "5", "f" ),
+ PROCENT(ProgMN, PRIO_STD, "M", "userM", "M", "5", "f"),
#endif
#if defined(SPAWN_N)
- PROCENT( ProgMN, PRIO_STD, "N", "userN", "N", "5", "t" ),
+ PROCENT(ProgMN, PRIO_STD, "N", "userN", "N", "5", "t"),
#endif
- // There is no user O
+// There is no user O
- // User P iterates, reporting system time and stats, and sleeping
+// User P iterates, reporting system time and stats, and sleeping
#if defined(SPAWN_P)
- PROCENT( ProgP, PRIO_STD, "P", "userP", "P", "3", "2" ),
+ PROCENT(ProgP, PRIO_STD, "P", "userP", "P", "3", "2"),
#endif
- // User Q tries to execute a bad system call
+// User Q tries to execute a bad system call
#if defined(SPAWN_Q)
- PROCENT( ProgQ, PRIO_STD, "Q", "userQ", "Q" ),
+ PROCENT(ProgQ, PRIO_STD, "Q", "userQ", "Q"),
#endif
- // User R reports its PID, PPID, and sequence number; it
- // calls fork() but not exec(), with each child getting the
- // next sequence number, to a total of five copies
+// User R reports its PID, PPID, and sequence number; it
+// calls fork() but not exec(), with each child getting the
+// next sequence number, to a total of five copies
#if defined(SPAWN_R)
- PROCENT( ProgR, PRIO_STD, "R", "userR", "R", "20", "1" ),
+ PROCENT(ProgR, PRIO_STD, "R", "userR", "R", "20", "1"),
#endif
- // User S loops forever, sleeping 13 sec. on each iteration
+// User S loops forever, sleeping 13 sec. on each iteration
#if defined(SPAWN_S)
- PROCENT( ProgS, PRIO_STD, "S", "userS", "S", "13" ),
+ PROCENT(ProgS, PRIO_STD, "S", "userS", "S", "13"),
#endif
- // Users T-V run ProgTUV(); they spawn copies of userW
- // User T waits for any child
- // User U waits for each child by PID
- // User V kills each child
+// Users T-V run ProgTUV(); they spawn copies of userW
+// User T waits for any child
+// User U waits for each child by PID
+// User V kills each child
#if defined(SPAWN_T)
- PROCENT( ProgTUV, PRIO_STD, "T", "userT", "T", "6", "w" ),
+ PROCENT(ProgTUV, PRIO_STD, "T", "userT", "T", "6", "w"),
#endif
#if defined(SPAWN_U)
- PROCENT( ProgTUV, PRIO_STD, "U", "userU", "U", "6", "W" ),
+ PROCENT(ProgTUV, PRIO_STD, "U", "userU", "U", "6", "W"),
#endif
#if defined(SPAWN_V)
- PROCENT( ProgTUV, PRIO_STD, "V", "userV", "V", "6", "k" ),
+ PROCENT(ProgTUV, PRIO_STD, "V", "userV", "V", "6", "k"),
#endif
-
+
// a dummy entry to use as a sentinel
{ TBLEND }
@@ -158,51 +164,49 @@ static proc_t spawn_table[] = {
/*
** usage function
*/
-static void usage( void ) {
- swrites( "\nTests - run with '@x', where 'x' is one or more of:\n " );
+static void usage(void)
+{
+ swrites("\nTests - run with '@x', where 'x' is one or more of:\n ");
proc_t *p = spawn_table;
- while( p->index != TBLEND ) {
- swritech( ' ' );
- swritech( p->select[0] );
+ while (p->index != TBLEND) {
+ swritech(' ');
+ swritech(p->select[0]);
}
- swrites( "\nOther commands: @* (all), @h (help), @x (exit)\n" );
+ swrites("\nOther commands: @* (all), @h (help), @x (exit)\n");
}
/*
** run a program from the program table, or a builtin command
*/
-static int run( char which ) {
+static int run(char which)
+{
char buf[128];
register proc_t *p;
- if( which == 'h' ) {
-
+ if (which == 'h') {
// builtin "help" command
usage();
- } else if( which == 'x' ) {
-
+ } else if (which == 'x') {
// builtin "exit" command
time_to_stop = true;
- } else if( which == '*' ) {
-
+ } else if (which == '*') {
// torture test! run everything!
- for( p = spawn_table; p->index != TBLEND; ++p ) {
- int status = spawn( p->index, p->args );
- if( status > 0 ) {
+ for (p = spawn_table; p->index != TBLEND; ++p) {
+ int status = spawn(p->index, p->args);
+ if (status > 0) {
++children;
}
}
} else {
-
// must be a single test; find and run it
- for( p = spawn_table; p->index != TBLEND; ++p ) {
- if( p->select[0] == which ) {
+ for (p = spawn_table; p->index != TBLEND; ++p) {
+ if (p->select[0] == which) {
// found it!
- int status = spawn( p->index, p->args );
- if( status > 0 ) {
+ int status = spawn(p->index, p->args);
+ if (status > 0) {
++children;
}
return status;
@@ -210,8 +214,8 @@ static int run( char which ) {
}
// uh-oh, made it through the table without finding the program
- sprint( buf, "shell: unknown cmd '%c'\n", which );
- swrites( buf );
+ sprint(buf, "shell: unknown cmd '%c'\n", which);
+ swrites(buf);
usage();
}
@@ -224,12 +228,13 @@ static int run( char which ) {
** @param line Input line buffer
** @param n Number of valid bytes in the buffer
*/
-static int edit( char line[], int n ) {
- char *ptr = line + n - 1; // last char in buffer
+static int edit(char line[], int n)
+{
+ char *ptr = line + n - 1; // last char in buffer
// strip the EOLN sequence
- while( n > 0 ) {
- if( *ptr == '\n' || *ptr == '\r' ) {
+ while (n > 0) {
+ if (*ptr == '\n' || *ptr == '\r') {
--n;
} else {
break;
@@ -237,7 +242,7 @@ static int edit( char line[], int n ) {
}
// add a trailing NUL byte
- if( n > 0 ) {
+ if (n > 0) {
line[n] = '\0';
}
@@ -250,94 +255,92 @@ static int edit( char line[], int n ) {
** Scheduled by _kshell() when the character 'u' is typed on
** the console keyboard.
*/
-USERMAIN( main ) {
-
+USERMAIN(main)
+{
// keep the compiler happy
- (void) argc;
- (void) argv;
+ (void)argc;
+ (void)argv;
// report that we're up and running
- swrites( "Shell is ready\n" );
+ swrites("Shell is ready\n");
// print a summary of the commands we'll accept
usage();
// loop forever
- while( !time_to_stop ) {
+ while (!time_to_stop) {
char line[128];
char *ptr;
// the shell reads one line from the keyboard, parses it,
// and performs whatever command it requests.
- swrites( "\n> " );
- int n = read( CHAN_SIO, line, sizeof(line) );
-
+ swrites("\n> ");
+ int n = read(CHAN_SIO, line, sizeof(line));
+
// shortest valid command is "@?", so must have 3+ chars here
- if( n < 3 ) {
+ if (n < 3) {
// ignore it
continue;
}
// edit it as needed; new shortest command is 2+ chars
- if( (n=edit(line,n)) < 2 ) {
+ if ((n = edit(line, n)) < 2) {
continue;
}
// find the '@'
int i = 0;
- for( ptr = line; i < n; ++i, ++ptr ) {
- if( *ptr == '@' ) {
+ for (ptr = line; i < n; ++i, ++ptr) {
+ if (*ptr == '@') {
break;
}
}
// did we find an '@'?
- if( i < n ) {
-
+ if (i < n) {
// yes; process any commands that follow it
++ptr;
- for( ; *ptr != '\0'; ++ptr ) {
+ for (; *ptr != '\0'; ++ptr) {
char buf[128];
- int pid = run( *ptr );
+ int pid = run(*ptr);
- if( pid < 0 ) {
+ if (pid < 0) {
// spawn() failed
- sprint( buf, "+++ Shell spawn %c failed, code %d\n",
- *ptr, pid );
- cwrites( buf );
+ sprint(buf, "+++ Shell spawn %c failed, code %d\n", *ptr,
+ pid);
+ cwrites(buf);
}
// should we end it all?
- if( time_to_stop ) {
+ if (time_to_stop) {
break;
}
} // for
// now, wait for all the spawned children
- while( children > 0 ) {
+ while (children > 0) {
// wait for the child
int32_t status;
char buf[128];
- int whom = waitpid( 0, &status );
+ int whom = waitpid(0, &status);
// figure out the result
- if( whom == E_NO_CHILDREN ) {
+ if (whom == E_NO_CHILDREN) {
break;
- } else if( whom < 1 ) {
- sprint( buf, "shell: waitpid() returned %d\n", whom );
+ } else if (whom < 1) {
+ sprint(buf, "shell: waitpid() returned %d\n", whom);
} else {
--children;
- sprint( buf, "shell: PID %d exit status %d\n",
- whom, status );
+ sprint(buf, "shell: PID %d exit status %d\n", whom, status);
}
// report it
- swrites( buf );
+ swrites(buf);
}
- } // if i < n
- } // while
+ } // if i < n
+ } // while
- cwrites( "!!! shell exited loop???\n" );
- exit( 1 );
+ cwrites("!!! shell exited loop???\n");
+ exit(1);
}