error.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* tripl/error.c
  2. *
  3. * This file is part of tripl.
  4. *
  5. * tripl is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * tripl is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with tripl. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <tripl/tripl.h>
  19. #include <tripl/limits.h>
  20. #include <string.h>
  21. extern char *line_eof;
  22. int generic_error(char *msg, char *line, int lno) {
  23. char *buffer = strndup(line, line_eof - line + 1);
  24. ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_WHITE, BG_BLACK);
  25. fprintf(stderr, "tripl: %s:%d: ", fname, lno);
  26. ansi_csi_ed(stderr);
  27. ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_RED, BG_BLACK);
  28. fprintf(stderr, "error: ");
  29. ansi_csi_ed(stderr);
  30. fprintf(stderr, "%s\n", msg);
  31. fprintf(stderr, "%5d | ", lno);
  32. ansi_csi_st(stderr, MODE_LINE, FG_WHITE, BG_BLACK);
  33. fprintf(stderr, "%s\n", buffer);
  34. ansi_csi_ed(stderr);
  35. free(buffer);
  36. return 1;
  37. }