Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing cat Utility #73

Open
jcchu0 opened this issue Sep 17, 2024 · 1 comment
Open

Enhancing cat Utility #73

jcchu0 opened this issue Sep 17, 2024 · 1 comment

Comments

@jcchu0
Copy link

jcchu0 commented Sep 17, 2024

Objective: Enhance the cat utility to add line numbers to the output and a flag to display non-printing characters.

Approach: Update the cat utility to support two new flags: -n for adding line numbers and -v for displaying non-printing characters in a visible format. The utility will read from files or standard input and process the content based on the provided flags.

Files to be Modified/Added:

  1. user/cat.c: Modify the existing cat utility to handle new flags and implement the required features.

Detailed Steps:

  1. Update cat Function:
  • Modify the cat function to accept additional parameters for line numbering and non-printing character display.
  • Implement logic to add line numbers at the beginning of each line if the -n flag is set.
  • Implement logic to convert non-printing characters to a visible format if the -v flag is set.
  1. Parse Command-Line Arguments:
  • Update the main function to parse the -n and -v flags.
  • Pass the parsed flags to the cat function.
  1. Implement Line Numbering:
  • In the cat function, maintain a line counter.
  • Print the line number at the beginning of each line if the -n flag is set.
  1. Display Non-Printing Characters:
  • In the cat function, check each character.
  • If the character is non-printing (ASCII value < 32 or 127), convert it to a visible format (e.g., ^A for ASCII 1).

Future Development:

  1. Add Support for Additional Flags:
  • Implement a -b flag to number non-blank lines only.
  • Implement a -E flag to display $ at the end of each line.
  1. Improve Performance:
  • Optimize the reading and writing process to handle larger files more efficiently.
  1. Add Unit Tests:
  • Create unit tests to verify the functionality of the new features and ensure they work correctly under various conditions.
@malensek
Copy link
Contributor

This is a good project as long as the "future development" section is included in the project scope instead.

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

No branches or pull requests

2 participants