nvparse_errors.cpp 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "nvparse_errors.h"
  5. nvparse_errors::nvparse_errors()
  6. {
  7. num_errors = 0;
  8. reset();
  9. }
  10. nvparse_errors::~nvparse_errors()
  11. {
  12. reset();
  13. }
  14. void nvparse_errors::reset()
  15. {
  16. for(int i=0; i < num_errors; i++)
  17. free(elist[i]);//FIXME detail_nmap something is writing 0x2 to elist[1] blah!
  18. for(int j=0; j <= NVPARSE_MAX_ERRORS; j++)
  19. elist[j] = 0;
  20. num_errors = 0;
  21. }
  22. void nvparse_errors::set(const char * e)
  23. {
  24. if(num_errors < NVPARSE_MAX_ERRORS)
  25. elist[num_errors++] = strdup(e);
  26. }
  27. void nvparse_errors::set(const char * e, int line_number)
  28. {
  29. char buff[256];
  30. sprintf(buff, "error on line %d: %s", line_number, e);
  31. if(num_errors < NVPARSE_MAX_ERRORS)
  32. elist[num_errors++] = strdup(buff);
  33. }
  34. char * const * const nvparse_errors::get_errors()
  35. {
  36. return elist;
  37. }