Skip to content

Enhancing cat Utility #73

@jcchu0

Description

@jcchu0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions