6 static void read_line (char line[], size_t);
7 static bool backspace (char **pos, char line[]);
12 printf ("Shell starting...\n");
19 read_line (command, sizeof command);
21 /* Execute command. */
22 if (!strcmp (command, "exit"))
24 else if (command[0] == '\0')
30 pid_t pid = exec (command);
32 printf ("\"%s\": exit code %d\n", command, wait (pid));
34 printf ("exec failed\n");
38 printf ("Shell exiting.");
42 /* Reads a line of input from the user into LINE, which has room
43 for SIZE bytes. Handles backspace and Ctrl+U in the ways
44 expected by Unix users. On return, LINE will always be
45 null-terminated and will not end in a new-line character. */
47 read_line (char line[], size_t size)
53 read (STDIN_FILENO, &c, 1);
63 backspace (&pos, line);
66 case ('U' - 'A') + 1: /* Ctrl+U. */
67 while (backspace (&pos, line))
72 /* Add character to line. */
73 if (pos < line + size - 1)
83 /* If *POS is past the beginning of LINE, backs up one character
84 position. Returns true if successful, false if nothing was
87 backspace (char **pos, char line[])
91 /* Back up cursor, overwrite character, back up