glue.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <iostream>
  2. #include "simple/file.hpp"
  3. #include "simple/file/string_stack.h"
  4. using namespace std;
  5. using namespace simple;
  6. using namespace file::operators;
  7. void glue(string path)
  8. {
  9. auto info = file::ropex(path);
  10. file::string_stack::pop(path);
  11. string name;
  12. getline(info, name);
  13. file::size_type expected_size;
  14. info >> expected_size;
  15. info.ignore();
  16. auto output = file::bwopex(path + name);
  17. string piece;
  18. while(info.peek()|1 && !info.eof() && getline(info, piece))
  19. output <<= file::bropex(path + piece);
  20. auto diff = file::size(output) - expected_size;
  21. if(diff)
  22. cerr << "Output size differs from expected by " << diff << '\n';
  23. }
  24. void process_arguments(int argc, char const * argv[])
  25. {
  26. for(int i = 1; i < argc; ++i)
  27. glue(argv[i]);
  28. }
  29. void process_input()
  30. {
  31. string target;
  32. while(getline(cin, target))
  33. glue(target);
  34. }
  35. int main(int argc, char const * argv[]) try
  36. {
  37. if(argc < 2)
  38. process_input();
  39. else
  40. process_arguments(argc, argv);
  41. return 0;
  42. }
  43. catch(...)
  44. {
  45. if(errno)
  46. std::perror("Oh nooo!");
  47. throw;
  48. }