| 1 | // Copyright (c) 1998-1999 Matra Datavision |
| 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 3 | // |
| 4 | // This file is part of Open CASCADE Technology software library. |
| 5 | // |
| 6 | // This library is free software; you can redistribute it and/or modify it under |
| 7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 8 | // by the Free Software Foundation, with special exception defined in the file |
| 9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 10 | // distribution for complete text of the license and disclaimer of any warranty. |
| 11 | // |
| 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 13 | // commercial license or contractual agreement. |
| 14 | |
| 15 | #include <OSD.hxx> |
| 16 | |
| 17 | #include <Standard_CString.hxx> |
| 18 | |
| 19 | //======================================================================= |
| 20 | //function : RealToCString |
| 21 | //purpose : |
| 22 | //======================================================================= |
| 23 | Standard_Boolean OSD::RealToCString(const Standard_Real aReal, |
| 24 | Standard_PCharacter& aString) |
| 25 | { |
| 26 | char *p, *q ; |
| 27 | |
| 28 | if (Sprintf(aString,"%.17e",aReal) <= 0) //BUC60808 |
| 29 | return Standard_False ; |
| 30 | |
| 31 | // Suppress "e+00" and unsignificant 0's |
| 32 | |
| 33 | p = strchr(aString,'e'); |
| 34 | if (p) { |
| 35 | if (!strcmp(p,"e+00")) |
| 36 | *p = 0 ; |
| 37 | for (q = p-1 ; *q == '0' ; q--) ; |
| 38 | if (q != p-1) { |
| 39 | if (*q != '.') q++ ; |
| 40 | while (*p) |
| 41 | *q++ = *p++ ; |
| 42 | *q = 0 ; |
| 43 | } |
| 44 | } |
| 45 | return Standard_True ; |
| 46 | } |
| 47 | |
| 48 | // Make the RealToCString reciprocal conversion. |
| 49 | |
| 50 | Standard_Boolean OSD::CStringToReal(const Standard_CString aString, |
| 51 | Standard_Real& aReal) |
| 52 | { |
| 53 | char *endptr ; |
| 54 | aReal = Strtod(aString, &endptr); |
| 55 | if (*endptr) |
| 56 | return Standard_False ; |
| 57 | return Standard_True; |
| 58 | } |
| 59 | |
| 60 | #ifdef _WIN32 |
| 61 | #include <windows.h> |
| 62 | #else |
| 63 | #include <unistd.h> |
| 64 | #endif |
| 65 | |
| 66 | //======================================================================= |
| 67 | //function : OSDSecSleep |
| 68 | //purpose : Cause the process to sleep during a amount of seconds |
| 69 | //======================================================================= |
| 70 | void OSD::SecSleep (const Standard_Integer theSeconds) |
| 71 | { |
| 72 | #ifdef _WIN32 |
| 73 | Sleep (theSeconds * 1000); |
| 74 | #else |
| 75 | usleep (theSeconds * 1000 * 1000); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | //======================================================================= |
| 80 | //function : MilliSecSleep |
| 81 | //purpose : Cause the process to sleep during a amount of milliseconds |
| 82 | //======================================================================= |
| 83 | void OSD::MilliSecSleep (const Standard_Integer theMilliseconds) |
| 84 | { |
| 85 | #ifdef _WIN32 |
| 86 | Sleep (theMilliseconds); |
| 87 | #else |
| 88 | usleep (theMilliseconds * 1000); |
| 89 | #endif |
| 90 | } |