Skip to content

Commit

Permalink
Merge pull request #156 from am11/libsass/pr/1774
Browse files Browse the repository at this point in the history
Converts ANSI argv to UTF8 array
  • Loading branch information
xzyfer committed Dec 27, 2015
2 parents 7efa9c4 + 748b664 commit e2db5c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/building/windows-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ In `PowerShell`, the above variant would be:
cd projects\libsass\sassc
# debug build:
"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\sassc.sln
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\sassc.sln
# or release build:
"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\sassc.sln /p:Configuration=Release
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\sassc.sln /p:Configuration=Release
```

The executable will be in the bin folder under sassc (`sassc\bin\sassc.exe`). To run it, simply try something like
Expand Down
27 changes: 27 additions & 0 deletions sassc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
#define PATH_SEP ':'
#endif

#ifdef _WIN32
#include <windows.h>

int get_argv_utf8(int* argc_ptr, char*** argv_ptr) {
int argc;
char** argv;
wchar_t** argv_utf16 = CommandLineToArgvW(GetCommandLineW(), &argc);
int i;
int offset = (argc + 1) * sizeof(char*);
int size = offset;
for (i = 0; i < argc; i++)
size += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1, 0, 0, 0, 0);
argv = malloc(size);
for (i = 0; i < argc; i++) {
argv[i] = (char*) argv + offset;
offset += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1,
argv[i], size-offset, 0, 0);
}
*argc_ptr = argc;
*argv_ptr = argv;
return 0;
}
#endif

int output(int error_status, const char* error_message, const char* output_string, const char* outfile) {
if (error_status) {
if (error_message) {
Expand Down Expand Up @@ -174,6 +198,9 @@ void invalid_usage(char* argv0) {
}

int main(int argc, char** argv) {
#ifdef _WIN32
get_argv_utf8(&argc, &argv);
#endif
char *outfile = 0;
int from_stdin = 0;
bool generate_source_map = false;
Expand Down

0 comments on commit e2db5c7

Please sign in to comment.