Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please ues Visual Studio for this program This assignment gives you an opportunity to use C++'s OOP features in the context of a larger program.

Please ues Visual Studio for this program

This assignment gives you an opportunity to use C++'s OOP features in the context of a larger program.

Be sure you are fully up to date with the source code of the Y editor. To clone the full source of Y, along with the two supporting projects it requires, use commands such as:

 $ git clone https://github.com/pchapin/spica.git Spica $ git clone https://github.com/pchapin/scr.git Scr $ git clone https://github.com/pchapin/yeditor.git Y 

Be mindful of the case used for the names. The build control files depend on these names spelled in exactly this way.

If you already have the source code cloned, go into each folder and do:

 $ git pull 

This ensures you have the latest version. Next execute the following commands, in this order, to build the supporting projects and then Y itself:

 $ cd Spica/Cpp $ make $ cd ../../Scr $ make $ cd ../Y/src $ make 

The purpose of this assignment is to add a feature to Y so that it can run arbitrary processes and then execute the Y macros produced by those processes. Recall that Y continuously executes "macro words" that it obtains from some kind of word source.

Start by modifying WordSource.hpp and WordSource.cpp to add a class PipeWord that is derived from WordSource. The constructor of PipeWord should take a string that it will interpret to be a command (such as you might type at a shell prompt). It should then "open" the command for reading using the library popen function. See the manual page for popen for more information. Class PipeWord also needs to override get and unget since they are pure virtual methods in the base class. However, it should be able to just inherit get_word. See the implementation of FileWord for inspiration.

Once PipeWord is ready it is now necessary to hook it into Y's execution engine so it can be used. Start by creating a command function that can be used to execute processes. In the file command_e.cpp add a function such as:

 bool execute_process_command( ); 

The logic can be quite similar to that of execute_file_command except that it should call a function start_macro_process.

Add the function start_macro_process to the file macro_stack.cpp in a manner similar to the way start_macro_file is implemented.

Next it is necessary to associate a command name with the command function you just implemented. In command_table.cpp add an entry that associates the name "execute_process" with your implementation function.

At this point one might want to associate a keystroke with the newly created command so that users can invoke the command by typing some appropriate key combination. However, it is not necessary to do this because Y has a feature that allows users to enter arbitrary macro text at any time. Thus you are now ready to try the new feature.

You will need a program that generates Y macro text. One simple possibility would be to use the standard cat program on a text file. This is a bit unsatisfying, however, because Y already has a feature that allows you to execute macro text stored in a file. Instead consider the following Perl program:

 #!/usr/bin/perl print "\"Hello, Macro Processes!\"" . " add_text"; 

The dot operator is Perl's string concatenation operator. Save this program to example.pl and use a command such as:

 $ chmod 755 example.pl 

to make it executable. If you run it at the prompt it should output:

 "Hello, Macro Processes!" add_text 

Imagine that this program computes the macro text in some complex way. Now run Y on a scratch file such as afile.txt. Inside Y use 'Ctrl+A m' (this is Ctrl+A followed by m) to open a box for entering arbitrary macro commands. Try running:

 "example.pl" execute_process 

If everything works as desired the output of the Perl program should be executed by Y causing "Hello, Macro Processes!" to be added to the current file. Use 'Ctrl+A q' to exit Y without saving any files.

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions