sedProcess.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Filename: sedProcess.cxx
  2. // Created by: drose (24Oct00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #include "sedProcess.h"
  6. #include "sedContext.h"
  7. ////////////////////////////////////////////////////////////////////
  8. // Function: SedProcess::Constructor
  9. // Access: Public
  10. // Description:
  11. ////////////////////////////////////////////////////////////////////
  12. SedProcess::
  13. SedProcess() {
  14. }
  15. ////////////////////////////////////////////////////////////////////
  16. // Function: SedProcess::Destructor
  17. // Access: Public
  18. // Description:
  19. ////////////////////////////////////////////////////////////////////
  20. SedProcess::
  21. ~SedProcess() {
  22. }
  23. ////////////////////////////////////////////////////////////////////
  24. // Function: SedProcess::add_script_line
  25. // Access: Public
  26. // Description: Appends the indicated line to the end of the script
  27. // that will be executed for each line of the input
  28. // stream. This may be called as many times as you
  29. // like.
  30. //
  31. // The return value is true if the line was added
  32. // successfully, or false if there was an error in the
  33. // line (in which case, some commands on the line might
  34. // have been added, and others not).
  35. ////////////////////////////////////////////////////////////////////
  36. bool SedProcess::
  37. add_script_line(const string &line) {
  38. return _script.add_line(line);
  39. }
  40. ////////////////////////////////////////////////////////////////////
  41. // Function: SedProcess::run
  42. // Access: Public
  43. // Description: Reads the input stream and executes the script once
  44. // for each line on the input stream. Output is written
  45. // to the indicated output stream.
  46. ////////////////////////////////////////////////////////////////////
  47. void SedProcess::
  48. run(istream &in, ostream &out) {
  49. SedContext context(out);
  50. string line;
  51. getline(in, line);
  52. while (!in.fail() && !in.eof()) {
  53. context._pattern_space = line;
  54. context._line_number++;
  55. getline(in, line);
  56. if (in.eof()) {
  57. context._is_last_line = true;
  58. }
  59. _script.run(context);
  60. }
  61. }