|
- /*!
- * \file
- * Snel.cpp
- * \brief A shell implementation for A.U.TH (Operating systems Lab)
- *
- * Created on: Feb, 2019
- * Author: Christos Choutouridis AEM: 8997
- * email : <cchoutou@ece.auth.gr>
- */
- #include "sequencer.h"
-
- /*!
- * \mainpage
- * Snel is a shell implementation for A.U.TH (Operating systems Lab).
- * The shell execute the user commands in separate child processes.
- *
- * It supports:
- * * Interactive mode
- * * Batch mode
- * * # line comments
- * * std redirection
- * * &&, || operators and ; seperator
- * * pipes
- *
- * The implementation is based on a 2 dimensional sequencer. One dimension
- * is the command chains, namely the commands separated with ';' and the other
- * is the chains (the commands to run as one expression like ls && date).
- * For more information look at \see Sequencer.
- */
-
- /*!
- * Main program routine
- */
- int main(int argc, char* argv[]) try {
- snel::Sequencer seq{};
- std::string line, filtered;
-
- if (argc > 1) { // batch mode
- std::ifstream file(argv[1]);
-
- while (std::getline (file, line, '\n')) {
- //^ We use \n as delimiter. No further parsing here
- filtered = snel::filter(line); // simple filtering
- if (filtered == "quit")
- break;
- seq.parse(filtered).execute();
- }
- }
- else { // interactive mode
- std::cout << "Snel. A shell implementation for A.U.TH (OS Lab)." << std::endl;
- do {
- std::cout << "Choutouridis_8997>";
- std::getline (std::cin, line, '\n'); //< We use \n as delimiter. No parsing here
- filtered = snel::filter(line); // simple filtering
- if (filtered == "quit")
- break;
- seq.parse(filtered).execute();
- } while (1);
- }
- return 0;
-
- } catch (std::exception& e) {
- // we probably pollute the user's screen. Comment `cerr << ...` if you don't like it.
- // std::cerr << e.what() << '\n';
- exit(1);
- }
|