Skip to content

Conversation

@manasakri
Copy link

Description
This PR adds and documents user-space utilities echo, less, and more for FogOS/xv6.

echo

  • Prints arguments to stdout separated by spaces.
  • Supports -n to suppress the trailing newline.
  • Supports --help to display usage.
    New features
  • -n: do not output the trailing newline
  • --help: show usage and exit
    Testing
    Commands verified inside QEMU:
  • echo hello world
  • echo -n "no newline"
  • echo --help

more

  • Simple pager that pauses after each screenful (24 lines).
  • Shows --More-- prompt for navigation.
  • Supports --help to display usage.
    Navigation keys
  • Space + Enter: next page
  • Enter: next line
  • q + Enter: quit
  • Any other key + Enter: show help
    Testing
    Commands verified inside QEMU:
  • more --help
  • more user/moreTest.txt
  • more moreLessTest1.txt
  • more moreLessEmptyTest.txt (empty file behavior)

less

  • Interactive pager that loads a file into memory and supports navigation.
  • Shows --Less-- prompt while awaiting input.
  • Supports --help to display usage and key 
    Navigation keys
  • Space: next page
  • Enter: next line
  • b: previous page
  • g: go to beginning
  • G: go to end
  • Up/Down arrows: scroll one line
  • q: quit
    Testing
    Commands verified inside QEMU:
  • less --help
  • less user/moreTest.txt
  • less moreLessEmptyTest.txt (empty file behavior)

Build and run

  • make clean && make qemu builds and runs successfully.

Documents
docs/readmemore.md
docs/readmeLess.md
docs/readmeEcho.md

Test
moreLessTest1.txt
moreLessTest2.txt
moreLessEmptyTest.txt
user/echo-testing.txt

Checklist

  • ✔ Documentation included (usage and key bindings via --help)
  • ✔ Manual tests included and verified inside QEMU
  • ✔ Code follows xv6/FogOS style and builds cleanly
  • ✔ No regressions in build/run

@hnunez02
Copy link

hnunez02 commented Oct 3, 2025

Verification
Original task of implementing more, less, and echo were successfully implementing into OS. No functionalities missing.

Testing
Current tests look good. They run with the implementations you have which is good. I would like to see more tests maybe start off with whitespaces or longer lines to see if it breaks the commands.

I did find one bug when testing the 'more' command. I noticed when entered an invalid key when inside the more process it clearly states my input is invalid and displays a list of available commands.

However, if I enter " someinvalidinput" the program does display both the next page and error since it detected the space at the start of the input
EX.
`--More--
x

Unknown command. Available commands:

more - Displays the contents of a file one screen at a time
-----------------------More--prompt-----------------------

+ <Return/Enter> - Display next page of file
<Return/Enter> - Display next line of file
anykey + <Return/Enter> - Display help
q + <Return/Enter> - Exit/quit from more
--More--
someinvalidinput

Line 51: Welcome to page 3!
Line 52: Testing continues
Line 53: Multiple pages help test scrolling
Line 54: Forward and backward
Line 55: Buffer
Line 56: Testing
Line 57: Old pages get overwritten
Line 58: But only after 100 pages
Line 59: Memory issues
Line 60: While maintaining functionality
Line 61: Testing scenarios
Line 62: Testing is an important part
Line 63: What happens at the end?
Line 64: The (END) prompt should appear
Line 65: Pressing 'g' goes to start
Line 66: Pressing 'G' goes to end
Line 67: These are useful shortcuts
Line 68: For navigating large files
Line 69: Files can be very long
Line 70: Configuration
Line 71: Documentation as well
Line 72: Helps
Line 73: This is near the end
Line 74: Just a few more lines
--More--

Unknown command. Available commands:

more - Displays the contents of a file one screen at a time
-----------------------More--prompt-----------------------

+ <Return/Enter> - Display next page of file
<Return/Enter> - Display next line of file
anykey + <Return/Enter> - Display help
q + <Return/Enter> - Exit/quit from more
--More--

Unknown command. Available commands:

more - Displays the contents of a file one screen at a time
-----------------------More--prompt-----------------------

+ <Return/Enter> - Display next page of file
<Return/Enter> - Display next line of file
anykey + <Return/Enter> - Display help
q + <Return/Enter> - Exit/quit from more
--More--
`

Code Walkthrough

Suggestion to fix switch case in more.c. If the program detects an invalid key it will go to default and display error but if it keeps detecting invalid keys it will keep displaying errors. We could change this to read the entire line at once to see if we have a valid input:
default: // Any other key - help // Throw away the Enter that follows read(0, &key, 1); printf("\n"); printf("Unknown command. Available commands:\n\n"); print_help(); printf("--More--\n"); // Recursively wait for next command after help User_command(); break;

Formatting
Formatting is clear based on documentation, it states what we should expect when running commands

High Level Checks:

  • PR fully resolves the task/issue
  • [ x ] Does the PR have tests?
  • [ x ] Does the PR follow project code formatting standards?
  • [ x ] Does the OS still compile and run?
  • [ x ] Is documentation included?

Code Checks:

  • [ x ] Does the code achieve its intended purpose?
  • [ ] Were all edge cases considered? (See code walkthrough section for one)
  • [ x ] Is the code organized and maintainable?
  • [ x ] Does the code maintain the same level of performance? (no performance regressions)

@MiloCrespo
Copy link

MiloCrespo commented Oct 4, 2025

CODE REVIEW #2

Checking to make sure the functionality delivered matches the original goals?
Functionality matches project description and branch comment information.

Correcting any minor formatting or documentation issues
Tests;
Manual tests documented, but... No automated tests
Test files included (moreLessTest1.txt, etc.), echo-testing.txt documents test cases
Missing: Edge case tests (empty files, large files, binary files)

Proposing ways to refactor the code to improve readability, efficiency, or correctness

More.c
Location: Line 95
Function: User_command()Issue: Recursive call in default case can cause stack overflow

Replace Recursion with Loop in more.c - Line 95.

void User_command(void) {
while (1) { // Keep asking until valid command
char key;
read(0, &key, 1);

    more_flags.space = 0;
    more_flags.enter = 0; 
    more_flags.quit = 0;

    switch (key) {
        case ' ':
            more_flags.space = 1;
            read(0, &key, 1);  // consume Enter
            return;  // Exit loop on valid command
        case '\n':
            more_flags.enter = 1;
            return;
        case 'q':
            more_flags.quit = 1;
            read(0, &key, 1);  // consume Enter
            return;
        default:
            // Consume rest of line
            while (read(0, &key, 1) > 0 && key != '\n');
            printf("\nUnknown command. Available commands:\n\n");
            print_help();
            printf("--More--\n");
            // Loop continues, asking for input again
            break;
    }
}

}

issue: Each invalid command adds a new stack frame. A malicious or confused user could crash the program
Fix: Fix: Use loop instead

You should also verify each item in the following checklist:

High Level Checks:

  • Is documentation included? This should explain how to build, run, and test the software.
    • This is included in the /docs folder from what I saw.
  • PR fully resolves the task/issue
  • Does the PR have tests? - Included in test.md
  • Does the PR follow project code formatting standards?
  • Does the OS still compile and run?

Code Checks:

  • Does the code achieve its intended purpose?
  • Were all edge cases considered?
  • Is the code organized and maintainable?
  • Does the code maintain the same level of performance? (no performance regressions)

@malensek
Copy link
Contributor

This looks great, although I think the interactive claims are a bit misleading in less especially. Hitting isn't going to actually cause anything to happen, it's space + enter, G + enter, etc. to move around. The up arrow does not work in my testing. Down arrow goes down two lines, I guess once for down and once for enter.

This makes sense because there is no way to read raw input from the terminal, but I think it would've been better to be up front about it and redesign the interface in such a way that a user of the normal more/less on a unix machine won't be confused. Perhaps come up with a set of single-character commands that the user can enter, e.g., n + enter goes to the next line, p + enter goes up one, etc. so everything is consistent.

Cool project and nice job implementing it. Getting this to work perfectly is not so easy.

4.5/5

+0.5 -> fix keybindings and make consistent across more / less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants