123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- #ifndef oERROR_SOURCE
- #define oERROR_SOURCE
- #include <iostream>
- #include <cstdarg>
- #include <cstdlib>
- #include <cstring>
- #include <cerrno>
- #include "../classes/oerror.hpp"
- void oerror::print (char const *format, ...)
- {
- extern char const * program_name;
- if ((program_name) && (*program_name))
- {
- std::cerr << program_name << ": ";
- }
- if ((format) && (*format))
- {
- va_list argp;
- va_start (argp, format);
- std::vfprintf (stderr, format, argp);
- va_end (argp);
- }
- std::cerr << std::endl;
- return;
- }
- void oerror::error (char const *format, ...)
- {
- extern char const * program_name;
- if ((program_name) && (*program_name))
- {
- std::cerr << program_name << ": ";
- }
- if (errno)
- {
- std::cerr << std::strerror (errno) << ": ";
- errno = 0;
- }
- if ((format) && (*format))
- {
- va_list argp;
- va_start (argp, format);
- std::vfprintf (stderr, format, argp);
- va_end (argp);
- }
- std::cerr << std::endl;
- return;
- }
- void oerror::error (int status, errno_t number, char const *format, ...)
- {
- extern char const * program_name;
- if ((program_name) && (*program_name))
- {
- std::cerr << program_name << ": ";
- }
- if (number)
- {
- std::cerr << std::strerror (number) << ": ";
- errno = 0;
- }
- if ((format) && (*format))
- {
- va_list arglist;
- va_start (arglist, format);
- std::vfprintf (stderr, format, arglist);
- va_end (arglist);
- }
- std::cerr << std::endl;
- if (status)
- {
- std::exit (status);
- }
- return;
- }
- void oerror::error_at_line (int status, errno_t number, char const *file, unsigned line, char const *format, ...)
- {
- extern char const * program_name;
- if ((program_name) && (*program_name))
- {
- std::cerr << program_name << ": ";
- }
- if ((file) && (*file))
- {
- std::cerr << file << " (" << line << "): ";
- }
- if (number)
- {
- std::cerr << std::strerror (number) << ": ";
- }
- if ((format) && (*format))
- {
- va_list arglist;
- va_start (arglist, format);
- std::vfprintf (stderr, format, arglist);
- va_end (arglist);
- }
- std::cerr << std::endl;
- if (status)
- {
- std::exit (status);
- }
- return;
- }
- oerror::oerror ()
- {
- extern char const * program_name;
- if ((!program_name) || (!*program_name))
- {
- program_name = "unamed program";
- }
- errno = 0;
- return;
- }
- oerror::~oerror ()
- {
- extern char const * program_name;
- if (!(program_name) || !(*program_name))
- {
- program_name = "unamed program";
- }
- return;
- }
- #endif
|