error.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /***************************************************************************
  2. * error.c
  3. *
  4. * Mon Apr 18 15:00:13 2005
  5. * Copyright 2005 Benjamin Ducke
  6. ****************************************************************************/
  7. /*
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <stdarg.h>
  23. #include "globals.h"
  24. /*
  25. Displays an error message
  26. */
  27. void print_error(int err_code, char *msg, ...)
  28. {
  29. char buffer[MAXSTR];
  30. va_list ap;
  31. va_start(ap, msg);
  32. vsprintf(buffer, msg, ap);
  33. va_end(ap);
  34. fprintf(stderr, "\033[1;31m\nERROR:\033[0m %s", buffer);
  35. ERROR = err_code;
  36. exit(err_code);
  37. }
  38. /*
  39. Displays a warning message
  40. */
  41. void print_warning(char *msg, ...)
  42. {
  43. char buffer[MAXSTR];
  44. va_list ap;
  45. va_start(ap, msg);
  46. vsprintf(buffer, msg, ap);
  47. va_end(ap);
  48. fprintf(stderr, "\033[0;33m\nWARNING:\033[0m %s", buffer);
  49. WARNINGS = WARNINGS + 1;
  50. }
  51. /*
  52. Prints a fancy "DONE." on the screen
  53. */
  54. void print_done(void)
  55. {
  56. fprintf(stdout, "\033[0;32mDONE.\n\033[0m");
  57. }