-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
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:
- user/cat.c: Modify the existing cat utility to handle new flags and implement the required features.
Detailed Steps:
- 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.
- Parse Command-Line Arguments:
- Update the main function to parse the -n and -v flags.
- Pass the parsed flags to the cat function.
- 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.
- 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:
- 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.
- Improve Performance:
- Optimize the reading and writing process to handle larger files more efficiently.
- Add Unit Tests:
- Create unit tests to verify the functionality of the new features and ensure they work correctly under various conditions.
Metadata
Metadata
Assignees
Labels
No labels