27 #ifdef MRPT_OS_WINDOWS 31 #include <sys/utime.h> 39 #include <sys/select.h> 48 #include <sys/types.h> 52 #define _access access 64 #ifndef MRPT_OS_WINDOWS 71 struct termios oldtio, curtio;
75 tcgetattr(0, &oldtio);
80 tcgetattr(0, &curtio);
81 curtio.c_lflag &= ~(ICANON | ECHO);
82 tcsetattr(0, TCSANOW, &curtio);
84 struct pollfd pfds[1];
88 pfds[0].events = POLLIN;
89 const int ret = poll(pfds, 1, 0);
92 tcsetattr(0, TCSANOW, &oldtio);
112 return ::_mkgmtime(tm);
125 char *org_tz = getenv(
"TZ");
145 #endif // HAVE_TIMEGM 150 #include <mrpt/version.h> 161 const char *source_date_epoch = MRPT_SOURCE_DATE_EPOCH;
164 unsigned long epoch = strtoul(source_date_epoch, &endptr, 10);
165 if (epoch==0 || ((errno == ERANGE && (epoch == std::numeric_limits<unsigned long>::max() || epoch == 0)) || (errno != 0 && epoch == 0))) {
172 struct tm *build_time = gmtime(&
now);
173 const int year = build_time->tm_year + 1900;
174 const int month = build_time->tm_mon + 1;
175 const int day = build_time->tm_mday;
177 return mrpt::format(
"%i-%02i-%02i %02i:%02i:%02i UTC",year,month,day, build_time->tm_hour,build_time->tm_min, build_time->tm_sec);
185 return string(::MRPT_version_str);
199 #if defined(_MSC_VER) && (_MSC_VER>=1400) 217 #if defined(_MSC_VER) && (_MSC_VER>=1400) 231 #if defined(_MSC_VER) 234 return ::vsnprintf_s (buf,
bufSize, _TRUNCATE,
format, args);
257 #if defined(_MSC_VER) && (_MSC_VER>=1400) 260 if (0 != ::fopen_s(&f,fileName,
mode))
285 #if defined(_MSC_VER) && (_MSC_VER>=1400) 286 ::strcat_s(dest,destSize,
source);
300 #if defined(_MSC_VER) && (_MSC_VER>=1400) 301 ::strcpy_s(dest,destSize,
source);
314 return ::strcmp(str1,str2);
322 #ifdef MRPT_OS_WINDOWS 323 #if defined(_MSC_VER) && (_MSC_VER>=1400) 326 return ::strcmpi(str1,str2);
329 return ::strcasecmp(str1,str2);
338 return ::strncmp(str1,str2,
count);
346 #if defined(_MSC_VER) 349 return ::strncasecmp(str1,str2,
count);
364 #if defined(_MSC_VER) && (_MSC_VER>=1400) 365 ::memcpy_s(dest,destSize,
src,copyCount);
377 #ifdef MRPT_OS_WINDOWS 383 tcgetattr(STDIN_FILENO, &oldt);
385 newt.c_lflag &= ~(ICANON | ECHO);
386 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
388 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
398 #ifdef MRPT_OS_WINDOWS 399 #if defined(_MSC_VER) && (_MSC_VER>=1400) 400 return ::_kbhit() != 0;
418 #if defined(_MSC_VER) && (_MSC_VER>=1400) 420 result = ::vfprintf_s(fil, frm, ap);
424 result = ::vfprintf(fil, frm, ap);
437 std::cout << msg << std::endl;
446 #ifdef MRPT_OS_WINDOWS 447 int ret=::system(
"cls");
449 int ret=::system(
"clear");
452 cerr <<
"[mrpt::system::clearConsole] Error invoking 'clear screen' " << endl;
461 #ifdef MRPT_OS_WINDOWS 462 return (
int64_t) ::strtol(nptr, endptr, base);
464 return (
int64_t) ::strtoll(nptr, endptr, base);
474 #ifdef MRPT_OS_WINDOWS 475 return (
uint64_t) ::strtoul(nptr, endptr, base);
477 return (
uint64_t) ::strtoull(nptr, endptr, base);
491 static const int TS_NORMAL = 0;
492 static const int TS_BLUE = 1;
493 static const int TS_GREEN = 2;
494 static const int TS_RED = 4;
495 #ifdef MRPT_OS_WINDOWS 496 static int normal_attributes = -1;
497 HANDLE hstdout = GetStdHandle(changeStdErr ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
498 fflush(changeStdErr ? stderr: stdout);
500 if(normal_attributes < 0)
502 CONSOLE_SCREEN_BUFFER_INFO
info;
503 GetConsoleScreenBufferInfo(hstdout, &
info);
504 normal_attributes =
info.wAttributes;
507 SetConsoleTextAttribute(hstdout,
508 (WORD)(
color == TS_NORMAL ? normal_attributes :
509 ((
color & TS_BLUE ? FOREGROUND_BLUE : 0)|
510 (
color & TS_GREEN ? FOREGROUND_GREEN : 0)|
511 (
color & TS_RED ? FOREGROUND_RED : 0)|FOREGROUND_INTENSITY)));
515 if (old_color ==
color)
return;
518 static const uint8_t ansi_tab[] = { 30, 34, 32, 36, 31, 35, 33, 37 };
520 fflush(changeStdErr ? stdout:stderr);
521 if(
color != TS_NORMAL)
522 code = ansi_tab[
color & (TS_BLUE|TS_GREEN|TS_RED)];
523 fprintf(changeStdErr ? stdout:stderr,
"\x1b[%dm",
code);
528 " Mobile Robot Programming Toolkit (MRPT) \n" 529 " http://www.mrpt.org/ \n" 531 " Copyright (c) 2005-%Y, Individual contributors, see AUTHORS file \n" 532 " See: http://www.mrpt.org/Authors - All rights reserved. \n" 533 " Released under BSD License. See details in http://www.mrpt.org/License \n";
537 static bool sLicenseTextReady =
false;
540 if (!sLicenseTextReady)
544 struct tm * timeinfo;
546 timeinfo = localtime (&rawtime);
551 sLicenseTextReady=
true;
556 #include <mrpt/mrpt_paths_config.h> 559 static bool mrpt_shared_first_call =
true;
562 if (mrpt_shared_first_call)
564 mrpt_shared_first_call =
false;
566 for (
int attempt = 0; ; attempt++)
572 dir =
string(MRPT_SOURCE_BASE_DIRECTORY) +
string(
"/share/mrpt/");
575 dir =
string(MRPT_INSTALL_PREFIX_DIRECTORY) +
string(
"/share/mrpt/");
581 GetModuleFileNameA(NULL,curExe,
sizeof(curExe));
589 found_mrpt_shared_dir =
".";
593 found_mrpt_shared_dir = dir;
595 if (!found_mrpt_shared_dir.empty())
600 return found_mrpt_shared_dir;
619 if (!(
in = popen(command.c_str(),
mode.c_str()))) {
620 sout <<
"Popen Execution failed!" << endl;
621 *output = sout.str();
627 while(fgets(buff,
sizeof(buff),
in)!=NULL){
632 int exit_code = pclose(
in);
636 *output = sout.str();
642 MRPT_TODO(
"Write popen alternative for Windows")
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
GLuint GLuint GLsizei count
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
This class provides simple critical sections functionality.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
const char * sLicenseTextF
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
void BASE_IMPEXP pause(const std::string &msg=std::string("Press any key to continue...")) MRPT_NO_THROWS
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
time_t BASE_IMPEXP timegm(struct tm *tm)
An OS-independent version of timegm (which is not present in all compilers): converts a time structur...
#define THROW_EXCEPTION(msg)
void BASE_IMPEXP setConsoleColor(TConsoleColor color, bool changeStdErr=false)
Changes the text color in the console for the text written from now on.
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
std::string BASE_IMPEXP MRPT_getCompilationDate()
Returns the MRPT source code timestamp, according to the Reproducible-Builds specifications: https://...
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy.
std::string BASE_IMPEXP find_mrpt_shared_dir()
Finds the "[MRPT]/share/mrpt/" directory, if available in the system.
int BASE_IMPEXP executeCommand(const std::string &command, std::string *output=NULL, const std::string &mode="r")
Execute Generic Shell Command.
int BASE_IMPEXP getch() MRPT_NO_THROWS
An OS-independent version of getch, which waits until a key is pushed.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void BASE_IMPEXP clearConsole()
Clears the console window.
TConsoleColor
For use in setConsoleColor.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool BASE_IMPEXP kbhit() MRPT_NO_THROWS
An OS-independent version of kbhit, which returns true if a key has been pushed.
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
void my_aux_sighandler(int)
By ninjalj in http://stackoverflow.com/questions/3962263/checking-if-a-key-was-pressed.
GLsizei GLsizei GLchar * source
uint64_t BASE_IMPEXP _strtoull(const char *nptr, char **endptr, int base)
An OS-independent version of strtoull.
char BASE_IMPEXP * strcat(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcat.
int BASE_IMPEXP int BASE_IMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS
An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compile...
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
GLenum GLsizei GLenum format
bool BASE_IMPEXP directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file)...
std::string BASE_IMPEXP MRPT_getVersion()
Returns a string describing the MRPT version.
int64_t BASE_IMPEXP _strtoll(const char *nptr, char **endptr, int base)
An OS-independent version of strtoll.
int BASE_IMPEXP _strcmp(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmp.
int BASE_IMPEXP _strnicmp(const char *str, const char *subStr, size_t count) MRPT_NO_THROWS
An OS-independent version of strnicmp.
const std::string BASE_IMPEXP & getMRPTLicense()
Returns a const ref to a text with the same text that appears at the beginning of each MRPT file (use...
std::string BASE_IMPEXP extractFileDirectory(const std::string &filePath)
Extract the whole path (the directory) of a filename from a complete path plus name plus extension...
int BASE_IMPEXP _strncmp(const char *str, const char *subStr, size_t count) MRPT_NO_THROWS
An OS-independent version of strncmp.