Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You may use C or C++ for this. y You will use the GNU readline library which reads a line of input from a user

You may use C or C++ for this.

y

You will use the GNU readline library which reads a line of input from a user and allows editing of the line.

Print a command prompt > and read a line of data using function readline (char * readline(char *prompt)). In general, more detail about library functions can be had by typing man functionname at a UNIX prompt. Take the string that is returned and from it create a linked list of tokens. Each token should be in a structure that has a character pointer to the token value and a next pointer that is either NULL or points to the next token. Your program will then print the contents of the linked Roch p. 2 list in square [ ] brackets. The token values will be surrounded by curly braces { } and separated by a comma.

The rules for tokens are as follows and are loosely based on rules used by many UNIX shells:

1. Whitespace (space, tab, etc) ends a token and is skipped unless it is in quotes (see below). You will find the function int isspace(char) useful for detecting whitespace characters.

2. Several characters are considered special tokens: | ; < > & When one of these characters is encountered, the token being built is completed and a new token consisting of the character is created.

3. The special character \ is an escape character. The next character will be part (or the start) of a token. For example, normally the string now;is would be three tokens: [{now},{;},{is}]. However, now\;is results in a single token: [{now;is}].

4. Items between single or double quotes are treated as parts of the current token: > me gusta UNIX -> [{me},{gusta},{UNIX}] vs. > me" gusta UNIX" -> [{me gusta UNIX}]

5. Characters that do not meet the above rules are added on to the current token being built.

Examples:

> let\'s do some "crazy \"air quotes\"" [{let's},{do},{some},{crazy "air quotes"}]

> ls | sort >sorted_files.txt [{ls},{|},{sort},{>},{sorted_files.txt}]

> cat -n /etc/fstab [{cat},{-n},{/etc/fstab}]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago