?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  
  3.   SjASMPlus Z80 Cross Compiler
  4.  
  5.   This is modified sources of SjASM by Aprisobal - aprisobal@tut.by
  6.  
  7.   Copyright (c) 2005 Sjoerd Mastijn
  8.  
  9.   This software is provided 'as-is', without any express or implied warranty.
  10.   In no event will the authors be held liable for any damages arising from the
  11.   use of this software.
  12.  
  13.   Permission is granted to anyone to use this software for any purpose,
  14.   including commercial applications, and to alter it and redistribute it freely,
  15.   subject to the following restrictions:
  16.  
  17.   1. The origin of this software must not be misrepresented; you must not claim
  18.          that you wrote the original software. If you use this software in a product,
  19.          an acknowledgment in the product documentation would be appreciated but is
  20.          not required.
  21.  
  22.   2. Altered source versions must be plainly marked as such, and must not be
  23.          misrepresented as being the original software.
  24.  
  25.   3. This notice may not be removed or altered from any source distribution.
  26.  
  27. */
  28.  
  29. // support.cpp
  30.  
  31. #include "sjdefs.h"
  32.  
  33. FILE* SJ_fopen(const char* fname, const char* mode) {
  34.         if (nullptr == fname || nullptr == mode || !*fname) return nullptr;
  35.         return fopen(fname, mode);
  36. }
  37.  
  38. /*
  39. FILE* dbg_fopen(const char* fname, const char* modes) {
  40.         FILE* f = fopen(fname, modes);
  41.         printf("fopen = %p modes [%s]\tname (%lu) [%s]\n", (void*)f, modes, strlen(fname), fname);
  42.         return f;
  43. }
  44. */
  45.  
  46. void SJ_GetCurrentDirectory(int whatever, char* pad) {
  47.         pad[0] = 0;
  48.         //TODO implement this one? And decide what to do with it?
  49.         // Will affect "--fullpath" paths if implemented correctly (as GetCurrentDirectory on windows)
  50. }
  51.  
  52. static bool isAnySlash(const char c) {
  53.         return pathGoodSlash == c || pathBadSlash == c;
  54. }
  55.  
  56. /**
  57.  * @brief Check if the path does start with MS windows drive-letter and colon, but accepts
  58.  * only absolute form with slash after colon, otherwise warns about relative way not supported.
  59.  *
  60.  * @param filePath p_filePath: filename to check
  61.  * @return bool true if the filename contains drive-letter with ABSOLUTE path
  62.  */
  63. static bool isWindowsDrivePathStart(const char* filePath) {
  64.         if (!filePath || !filePath[0] || ':' != filePath[1]) return false;
  65.         const char driveLetter = toupper(filePath[0]);
  66.         if (driveLetter < 'A' || 'Z' < driveLetter) return false;
  67.         if (!isAnySlash(filePath[2])) {
  68.                 Warning("Relative file path with drive letter detected (not supported)", filePath, W_EARLY);
  69.                 return false;
  70.         }
  71.         return true;
  72. }
  73.  
  74. int SJ_SearchPath(const char* oudzp, const char* filename, const char*, int maxlen, char* nieuwzp, char** ach) {
  75.         assert(nieuwzp);
  76.         *nieuwzp = 0;
  77.         if (nullptr == filename) return 0;
  78.         if (isAnySlash(filename[0]) || isWindowsDrivePathStart(filename)) {
  79.                 STRCPY(nieuwzp, maxlen, filename);
  80.         } else {
  81.                 STRCPY(nieuwzp, maxlen, oudzp);
  82.                 if (*nieuwzp) {
  83.                         char *lastChar = nieuwzp + strlen(nieuwzp) - 1;
  84.                         if (!isAnySlash(*lastChar)) {
  85.                                 lastChar[1] = pathGoodSlash;
  86.                                 lastChar[2] = 0;
  87.                         }
  88.                 }
  89.                 STRCAT(nieuwzp, maxlen, filename);
  90.         }
  91.         if (ach) {
  92.                 char* p = *ach = nieuwzp;
  93.                 while (*p) {
  94.                         if (isAnySlash(*p++)) *ach = p;
  95.                 }
  96.         }
  97.         FILE* fp;
  98.         if (FOPEN_ISOK(fp, nieuwzp, "r")) {
  99.                 fclose(fp);
  100.                 return 1;
  101.         }
  102.         return 0;
  103. }
  104.  
  105. #ifndef WIN32
  106.  
  107. long GetTickCount() {
  108.         struct timeval tv1[1];
  109.         gettimeofday(tv1, 0);
  110.         return tv1->tv_sec * 1000 + tv1->tv_usec / 1000;
  111. }
  112.  
  113. #endif  // #ifndef WIN32
  114.  
  115. #if defined (_WIN32) || defined (__CYGWIN__)
  116.         // cygwin: O_BINARY is in fcntl.h, setmode is in io.h
  117.         // MSVC: _O_BINARY and _setmode
  118.         #include <fcntl.h>
  119.         #include <io.h>
  120. #endif
  121.  
  122. void switchStdOutIntoBinaryMode() {
  123. #ifdef __CYGWIN__
  124.         setmode(1, O_BINARY);
  125. #elif _WIN32
  126.         _setmode(1, _O_BINARY);
  127. #else
  128.         // nothing on systems with no text-vs-binary mode
  129. #endif
  130. }
  131.  
  132. #ifdef USE_LUA
  133.  
  134. void LuaShellExec(const char *command) {
  135. #ifdef WIN32
  136.         WinExec(command, SW_SHOWNORMAL);
  137. #else
  138.         int ret = system(command);
  139.         if ( ret == -1 ) {
  140.                 Error("[LUASHELEXEC] Unable to start child process for command", command, IF_FIRST);
  141.         }
  142. #endif
  143. }
  144. #endif //USE_LUA
  145.  
  146. //eof support.cpp
  147.