A quick and dirty shell implementation for A.U.TH. (Operating systems Lab)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

67 lignes
1.9 KiB

  1. /*!
  2. * \file
  3. * Snel.cpp
  4. * \brief A shell implementation for A.U.TH (Operating systems Lab)
  5. *
  6. * Created on: Feb, 2019
  7. * Author: Christos Choutouridis AEM: 8997
  8. * email : <cchoutou@ece.auth.gr>
  9. */
  10. #include "sequencer.h"
  11. /*!
  12. * \mainpage
  13. * Snel is a shell implementation for A.U.TH (Operating systems Lab).
  14. * The shell execute the user commands in separate child processes.
  15. *
  16. * It supports:
  17. * * Interactive mode
  18. * * Batch mode
  19. * * # line comments
  20. * * std redirection
  21. * * &&, || operators and ; seperator
  22. * * pipes
  23. *
  24. * The implementation is based on a 2 dimensional sequencer. One dimension
  25. * is the command chains, namely the commands separated with ';' and the other
  26. * is the chains (the commands to run as one expression like ls && date).
  27. * For more information look at \see Sequencer.
  28. */
  29. /*!
  30. * Main program routine
  31. */
  32. int main(int argc, char* argv[]) try {
  33. snel::Sequencer seq{};
  34. std::string line, filtered;
  35. if (argc > 1) { // batch mode
  36. std::ifstream file(argv[1]);
  37. while (std::getline (file, line, '\n')) {
  38. //^ We use \n as delimiter. No further parsing here
  39. filtered = snel::filter(line); // simple filtering
  40. if (filtered == "quit")
  41. break;
  42. seq.parse(filtered).execute();
  43. }
  44. }
  45. else { // interactive mode
  46. std::cout << "Snel. A shell implementation for A.U.TH (OS Lab)." << std::endl;
  47. do {
  48. std::cout << "Choutouridis_8997>";
  49. std::getline (std::cin, line, '\n'); //< We use \n as delimiter. No parsing here
  50. filtered = snel::filter(line); // simple filtering
  51. if (filtered == "quit")
  52. break;
  53. seq.parse(filtered).execute();
  54. } while (1);
  55. }
  56. return 0;
  57. } catch (std::exception& e) {
  58. // we probably pollute the user's screen. Comment `cerr << ...` if you don't like it.
  59. // std::cerr << e.what() << '\n';
  60. exit(1);
  61. }