support-relative-paths.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --- a/main.cpp
  2. +++ b/main.cpp
  3. @@ -564,6 +564,11 @@ int main( int argc, const char **argv )
  4. "\" is the same as the input file" << endp;
  5. }
  6. + for (char* p = (char*)id.inputFileName; *p != 0; p++) {
  7. + if (*p == '\\')
  8. + *p = '/';
  9. + }
  10. +
  11. process( id );
  12. return 0;
  13. --- a/rlscan.cpp
  14. +++ b/rlscan.cpp
  15. @@ -45,12 +45,6 @@ enum InlineBlockType
  16. SemiTerminated
  17. };
  18. -#ifdef _WIN32
  19. -#define PATH_SEP '\\'
  20. -#else
  21. -#define PATH_SEP '/'
  22. -#endif
  23. -
  24. /*
  25. * The Scanner for Importing
  26. @@ -811,12 +805,26 @@ void Scanner::endSection( )
  27. bool isAbsolutePath( const char *path )
  28. {
  29. #ifdef _WIN32
  30. - return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
  31. + return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
  32. #else
  33. return path[0] == '/';
  34. #endif
  35. }
  36. +inline char* resolvePath(const char* rel, const char* abs) {
  37. + const size_t l1 = strlen(rel);
  38. + const size_t l2 = strlen(abs);
  39. + char* ret = new char[l1 + l2 + 1];
  40. +
  41. + const char* p = strrchr(abs, '/') + 1;
  42. + const size_t l3 = p - abs;
  43. +
  44. + memcpy(ret, abs, l3);
  45. + strcpy(ret + l3, rel);
  46. +
  47. + return ret;
  48. +}
  49. +
  50. char **Scanner::makeIncludePathChecks( const char *thisFileName,
  51. const char *fileName, int fnlen )
  52. {
  53. @@ -836,17 +844,11 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
  54. checks = new char*[2 + id.includePaths.length()];
  55. /* Search from the the location of the current file. */
  56. - const char *lastSlash = strrchr( thisFileName, PATH_SEP );
  57. + const char *lastSlash = strrchr( thisFileName, '/' );
  58. if ( lastSlash == 0 )
  59. checks[nextCheck++] = data;
  60. else {
  61. - long givenPathLen = (lastSlash - thisFileName) + 1;
  62. - long checklen = givenPathLen + length;
  63. - char *check = new char[checklen+1];
  64. - memcpy( check, thisFileName, givenPathLen );
  65. - memcpy( check+givenPathLen, data, length );
  66. - check[checklen] = 0;
  67. - checks[nextCheck++] = check;
  68. + checks[nextCheck++] = resolvePath(data, thisFileName);
  69. }
  70. /* Search from the include paths given on the command line. */
  71. @@ -855,7 +857,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
  72. long checkLen = pathLen + 1 + length;
  73. char *check = new char[checkLen+1];
  74. memcpy( check, *incp, pathLen );
  75. - check[pathLen] = PATH_SEP;
  76. + check[pathLen] = '/';
  77. memcpy( check+pathLen+1, data, length );
  78. check[checkLen] = 0;
  79. checks[nextCheck++] = check;
  80. --- a/rlscan.rl
  81. +++ b/rlscan.rl
  82. @@ -43,12 +43,6 @@ enum InlineBlockType
  83. SemiTerminated
  84. };
  85. -#ifdef _WIN32
  86. -#define PATH_SEP '\\'
  87. -#else
  88. -#define PATH_SEP '/'
  89. -#endif
  90. -
  91. /*
  92. * The Scanner for Importing
  93. @@ -548,12 +542,26 @@ void Scanner::endSection( )
  94. bool isAbsolutePath( const char *path )
  95. {
  96. #ifdef _WIN32
  97. - return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
  98. + return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
  99. #else
  100. return path[0] == '/';
  101. #endif
  102. }
  103. +inline char* resolvePath(const char* rel, const char* abs) {
  104. + const size_t l1 = strlen(rel);
  105. + const size_t l2 = strlen(abs);
  106. + char* ret = new char[l1 + l2 + 1];
  107. +
  108. + const char* p = strrchr(abs, '/') + 1;
  109. + const size_t l3 = p - abs;
  110. +
  111. + memcpy(ret, abs, l3);
  112. + strcpy(ret + l3, rel);
  113. +
  114. + return ret;
  115. +}
  116. +
  117. char **Scanner::makeIncludePathChecks( const char *thisFileName,
  118. const char *fileName, int fnlen )
  119. {
  120. @@ -573,17 +581,11 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
  121. checks = new char*[2 + id.includePaths.length()];
  122. /* Search from the the location of the current file. */
  123. - const char *lastSlash = strrchr( thisFileName, PATH_SEP );
  124. + const char *lastSlash = strrchr( thisFileName, '/' );
  125. if ( lastSlash == 0 )
  126. checks[nextCheck++] = data;
  127. else {
  128. - long givenPathLen = (lastSlash - thisFileName) + 1;
  129. - long checklen = givenPathLen + length;
  130. - char *check = new char[checklen+1];
  131. - memcpy( check, thisFileName, givenPathLen );
  132. - memcpy( check+givenPathLen, data, length );
  133. - check[checklen] = 0;
  134. - checks[nextCheck++] = check;
  135. + checks[nextCheck++] = resolvePath(data, thisFileName);
  136. }
  137. /* Search from the include paths given on the command line. */
  138. @@ -592,7 +594,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
  139. long checkLen = pathLen + 1 + length;
  140. char *check = new char[checkLen+1];
  141. memcpy( check, *incp, pathLen );
  142. - check[pathLen] = PATH_SEP;
  143. + check[pathLen] = '/';
  144. memcpy( check+pathLen+1, data, length );
  145. check[checkLen] = 0;
  146. checks[nextCheck++] = check;