textfile.h 583 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef TEXT_FILE_WRITER
  2. #define TEXT_FILE_WRITER
  3. class TextFile
  4. {
  5. char OutBuffer[16384];
  6. FILE* fp;
  7. public:
  8. TextFile(const char* filename)
  9. {
  10. fp = crt_fopen( filename, "w" );
  11. }
  12. ~TextFile()
  13. {
  14. if (!fp) return;
  15. fclose (fp);
  16. }
  17. void Write (int tabs, const char * format, ...)
  18. {
  19. if (!fp) return;
  20. va_list args;
  21. va_start(args, format);
  22. crt_vsnprintf(OutBuffer, sizeof(OutBuffer) - 4, format, args);
  23. va_end(args);
  24. for (int i = 0; i < tabs; i++)
  25. {
  26. fprintf(fp, " ");
  27. }
  28. fprintf(fp, "%s", OutBuffer);
  29. }
  30. };
  31. #endif