Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit



Editor

CMPUT 175 Assignment 3



ed” is a line-oriented editor for text. It was developed in the late 1960s as part of the creation of the UNIX computer operating system. (Linux is the popular open-source descendent of UNIX.) Your assignment is to build an ed-like editor. The commands are based on those of ed but have been simplified both in terms of the number of commands supported and the complexity of the commands. Once this assignment is complete, you will have a functional text editor.

Note that because of the pared down functionality, some editing operations are awkward. Of course, after submitting the assignment, you are free to enhance its capabilities!

Example

The following is sample output from running your editor. Text beginning with a # are comments to help explain what is happening. Commands are followed by 0, 1 or 2 arguments, each separated by spaces.

Note in the following that the line last accessed in the file is considered the “current” line. Any commands that talk about a relative position in the file do so relative to the current line.


Welcome to ed379

>l A3-sample.txt # Read in a file

A3-sample.txt (10) # file name (#lines read)

>1 # Go to line 1

>p 100 # Print line 1 and the next

1: It was the best of times, # 100 lines (it does not  2: it was the worst of times, # matter if the number is 3: it was the age of wisdom, # bigger than the number of 4: it was the age of foolishness, # lines in the file

5: it was the epoch of belief,

6: it was the epoch of incredulity, 7: it was the season of light,

8: it was the season of darkness, 9: it was the spring of hope,

10: it was the winter of despair.

>5 # Go to line 5

> # Null command. Print the

6: it was the epoch of incredulity, # next line

> # Null command

7: it was the season of light,

> # Null command

8:

it

was

the

season of darkness,

>p -4

#

Print the 4 previous lines

4:

it

was

the

age of foolishness,

#

to the current line and

5:

it

was

the

epoch of belief,

#

then the current line

6:

it

was

the

epoch of incredulity,

7:

it

was

the

season of light,

8:

it

was

the

season of darkness,

>a

#

Append text after current


[In Edmonton, the season is six months # line (8) long, but in Hawaii it is much less!]

# An empty line ends input

>p -5 # Print the current line and

5: it was the epoch of belief, # the 5 previous ones 6: it was the epoch of incredulity,

7: it was the season of light,

8: it was the season of darkness,

9: [In Edmonton, the season is six months 10: long, but in Hawaii it is much less!]

>8 # Go to line 8

>i # Insert text before

[In Edmonton, May, June, July, and August # current line are our season of light. Sadly, it is not

long enough!]

# An empty line ends input

>1 # Go to line 1

>p 100 # Print

1: It was the best of times, 2: it was the worst of times, 3: it was the age of wisdom,

4: it was the age of foolishness, 5: it was the epoch of belief,

6: it was the epoch of incredulity, 7: it was the season of light,

8: [In Edmonton, May, June, July, and August 9: are our season of light. Sadly, it is not

10: long enough!]

11: it was the season of darkness,

12: [In Edmonton, the season is six months 13: long, but in Hawaii it is much less!] 14: it was the spring of hope,

15: it was the winter of despair.

>8 # Go to line 8

>d 2 # Delete current line + 2

>p # Print current line

8: it was the season of darkness,

> # Null command

9: [In Edmonton, the season is six months

>d 1 # Delete current line + 1

>p # Print current line

9: it was the spring of hope,

>1 # Go to line 1

>p 100 # Print

1: It was the best of times, 2: it was the worst of times, 3: it was the age of wisdom,

4: it was the age of foolishness, 5: it was the epoch of belief,

6: it was the epoch of incredulity, 7: it was the season of light,

8: it was the season of darkness, 9: it was the spring of hope,

10: it was the winter of despair.

>? belief # Search backward for belief


5: it was the epoch of belief, # only find 1st occurrence

>? "best of times" # Search backwards 1: It was the best of times,

>? worst # Search backwards, wrapping

2: it was the worst of times, # around

>/ hope # Search forward

9: it was the spring of hope, # only find 1st occurrence

>/ was # Search forward

10: it was the winter of despair.

>/ was # Search forward, wrapping

1: It was the best of times, # around

>r best BEST # Replace “best” with 1: It was the BEST of times, # “BEST”

>r "of times" "OF EVERYTHING!" # Replace 1: It was the BEST OF EVERYTHING!,

>i # Insert at current line (1)

With apologies to Charles Dickens...


>p 100 # Print

1: With apologies to Charles Dickens... 2: It was the BEST OF EVERYTHING!,

3: it was the worst of times, 4: it was the age of wisdom,

5: it was the age of foolishness, 6: it was the epoch of belief,

7: it was the epoch of incredulity, 8: it was the season of light,

9: it was the season of darkness, 10: it was the spring of hope,

11: it was the winter of despair.

>s # Sort (ascending)

>p -100 # Print

1: It was the BEST OF EVERYTHING!,

2: With apologies to Charles Dickens... 3: it was the age of foolishness,

4: it was the age of wisdom, 5: it was the epoch of belief,

6: it was the epoch of incredulity, 7: it was the season of darkness, 8: it was the season of light,

9: it was the spring of hope, 10: it was the winter of despair. 11: it was the worst of times,

>w A3-newfile.txt # Write out file

A3-newfile.txt (11) # file name (#lines written)

>q # Quit

Good-bye

Commands

This section provides a list of the commands that your program will support. Commands can take the following forms, with each part separated by one or more spaces. A command can be preceded by white space.

· <> An empty line; no non-blank characters.

·  Line number (n), a positive integer



·  Command (c), one of “a”, “d”, “i”, “”l”, p”, “q”, “r”, ”s”, “w”, “/”, “?”

·   Command (c) and an integer (i) offset (can be negative)

·   Command (c) and a text parameter (text1)

·    Command and two text parameters (text1, text2)

Below is a table summarizing the commands. The last line accessed by a command is called the “current line.” Some commands result in moving around in the file, causing the current line to change. How a command changes the current line is documented in the table.