?login_element?

Subversion Repositories NedoOS

Rev

Rev 129 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  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. const char pathBadSlash = '\\';
  34. const char pathGoodSlash = '/';
  35.  
  36. FILE* dbg_fopen(const char* fname, const char* modes) {
  37.         FILE* f = fopen(fname, modes);
  38.         printf("fopen = %p modes [%s]\tname (%lu) [%s]\n", (void*)f, modes, strlen(fname), fname);
  39.         return f;
  40. }
  41.  
  42. void SJ_GetCurrentDirectory(int whatever, char* pad) {
  43.         pad[0] = 0;
  44.         //TODO implement this one? And decide what to do with it?
  45.         // Will affect "--fullpath" paths if implemented correctly (as GetCurrentDirectory on windows)
  46. }
  47.  
  48. static bool isAnySlash(const char c) {
  49.         return pathGoodSlash == c || pathBadSlash == c;
  50. }
  51.  
  52. /**
  53.  * @brief Check if the path does start with MS windows drive-letter and colon, but accepts
  54.  * only absolute form with slash after colon, otherwise warns about relative way not supported.
  55.  *
  56.  * @param filePath p_filePath: filename to check
  57.  * @return bool true if the filename contains drive-letter with ABSOLUTE path
  58.  */
  59. static bool isWindowsDrivePathStart(const char* filePath) {
  60.         if (!filePath || !filePath[0] || ':' != filePath[1]) return false;
  61.         const char driveLetter = toupper(filePath[0]);
  62.         if (driveLetter < 'A' || 'Z' < driveLetter) return false;
  63.         if (!isAnySlash(filePath[2])) {
  64.                 Warning("Relative file path with drive letter detected (not supported)", filePath, W_EARLY);
  65.                 return false;
  66.         }
  67.         return true;
  68. }
  69.  
  70. int SJ_SearchPath(const char* oudzp, const char* filename, const char*, int maxlen, char* nieuwzp, char** ach) {
  71.         FILE* fp;
  72.         if (isAnySlash(filename[0]) || isWindowsDrivePathStart(filename)) {
  73.                 STRCPY(nieuwzp, maxlen, filename);
  74.         } else {
  75.                 STRCPY(nieuwzp, maxlen, oudzp);
  76.                 if (*nieuwzp) {
  77.                         char *lastChar = nieuwzp + strlen(nieuwzp) - 1;
  78.                         if (!isAnySlash(*lastChar)) {
  79.                                 lastChar[1] = pathGoodSlash;
  80.                                 lastChar[2] = 0;
  81.                         }
  82.                 }
  83.                 STRCAT(nieuwzp, maxlen, filename);
  84.         }
  85.         if (ach) {
  86.                 char* p = *ach = nieuwzp;
  87.                 while (*p) {
  88.                         if (isAnySlash(*p++)) *ach = p;
  89.                 }
  90.         }
  91.         if (FOPEN_ISOK(fp, nieuwzp, "r")) {
  92.                 fclose(fp);
  93.                 return 1;
  94.         }
  95.         return 0;
  96. }
  97.  
  98. #ifndef WIN32
  99.  
  100. long GetTickCount() {
  101.         struct timeval tv1[1];
  102.         gettimeofday(tv1, 0);
  103.         return tv1->tv_sec * 1000 + tv1->tv_usec / 1000;
  104. }
  105.  
  106. #endif  // #ifndef WIN32
  107.  
  108. #ifdef _WIN32
  109. #include <fcntl.h>
  110. #include <io.h>
  111. #endif
  112.  
  113. void switchStdOutIntoBinaryMode() {
  114. #ifdef __CYGWIN__
  115.         setmode(1, O_BINARY);
  116. #elif _WIN32
  117.         _setmode(1, _O_BINARY);
  118. #else
  119.         // nothing on systems with no text-vs-binary mode
  120. #endif
  121. }
  122.  
  123. #ifdef USE_LUA
  124.  
  125. void LuaShellExec(char *command) {
  126. #ifdef WIN32
  127.         WinExec(command, SW_SHOWNORMAL);
  128. #else
  129.         int ret = system(command);
  130.         if ( ret == -1 ) {
  131.                 Error("[LUASHELEXEC] Unable to start child process for command", command, IF_FIRST);
  132.         }
  133. #endif
  134. }
  135. #endif //USE_LUA
  136.  
  137. //eof support.cpp
  138.