💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "resources/resource-loader.hpp"
  20. #include "resources/deserialize-error.hpp"
  21. #include <physfs.h>
  22. void physfs_getline(PHYSFS_File* file, std::string& line)
  23. {
  24. line.clear();
  25. for (;;)
  26. {
  27. char c;
  28. const PHYSFS_sint64 status = PHYSFS_readBytes(file, &c, 1);
  29. if (status == 1)
  30. {
  31. if (c == '\r')
  32. {
  33. continue;
  34. }
  35. else if (c == '\n')
  36. {
  37. break;
  38. }
  39. else
  40. {
  41. line.append(1, c);
  42. }
  43. }
  44. else
  45. {
  46. if (PHYSFS_eof(file))
  47. {
  48. break;
  49. }
  50. else
  51. {
  52. throw deserialize_error(PHYSFS_getLastError());
  53. }
  54. }
  55. }
  56. }