mirror of https://github.com/vitalif/openscad
first version of Windows(TM) unicode file write. fix up winconsole.c also
parent
f6382d91af
commit
91d00304be
|
@ -83,6 +83,7 @@ string get_os_info()
|
|||
string offscreen_context_getinfo(OffscreenContext *ctx)
|
||||
{
|
||||
// should probably get some info from WGL context here?
|
||||
(void)ctx;
|
||||
stringstream out;
|
||||
out << "GL context creator: WGL\n"
|
||||
<< "PNG generator: lodepng\n"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "PlatformUtils.h"
|
||||
#include "boosty.h"
|
||||
|
||||
#include "printutils.h"
|
||||
#include <glib.h>
|
||||
|
||||
bool PlatformUtils::createLibraryPath()
|
||||
|
|
|
@ -3,26 +3,30 @@
|
|||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "stl-utils.h"
|
||||
|
||||
namespace PlatformUtils {
|
||||
|
||||
std::string documentsPath();
|
||||
std::string libraryPath();
|
||||
bool createLibraryPath();
|
||||
std::string info();
|
||||
std::string utf16_to_utf8( const std::wstring &w );
|
||||
std::wstring utf8_to_utf16( const std::string &s );
|
||||
|
||||
#if !defined( __MINGW32__ ) && !defined ( __MINGW64__ )
|
||||
typedef std::ifstream ifstream;
|
||||
typedef std::ofstream ofstream;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if defined( __MINGW32__ ) || defined ( __MINGW64__ )
|
||||
#if defined( __MINGW32__ ) || defined( __MINGW64__ )
|
||||
#define __MINGW_FSTREAM__
|
||||
namespace PlatformUtils {
|
||||
std::string utf16_to_utf8( const std::wstring &w );
|
||||
std::wstring utf8_to_utf16( const std::string &s );
|
||||
}
|
||||
#include "../patches/mingstream"
|
||||
#endif
|
||||
namespace PlatformUtils {
|
||||
typedef imingstream ifstream;
|
||||
typedef omingstream ofstream;
|
||||
}
|
||||
#else //mingw
|
||||
namespace PlatformUtils {
|
||||
typedef std::ifstream ifstream;
|
||||
typedef std::ofstream ofstream;
|
||||
}
|
||||
#endif //mingw
|
||||
|
||||
#endif
|
||||
#endif // PLATFORMUTILS_H_
|
||||
|
|
|
@ -34,19 +34,3 @@ std::string lookup_file(const std::string &filename,
|
|||
return resultfile;
|
||||
}
|
||||
|
||||
|
||||
// retrieve all data from file stream into result string
|
||||
std::string getfile( PlatformUtils::ifstream &ifs )
|
||||
{
|
||||
int bufsize = 1024*4;
|
||||
std::string text;
|
||||
char tmp[bufsize];
|
||||
while (!ifs.eof()) {
|
||||
size_t result = ifs.read(tmp,bufsize);
|
||||
tmp[result]='\0';
|
||||
text += std::string(tmp);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,5 @@
|
|||
#include "PlatformUtils.h"
|
||||
|
||||
std::string lookup_file(const std::string &filename, const std::string &path, const std::string &fallbackpath);
|
||||
std::string getfile( PlatformUtils::ifstream &ifs );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -256,14 +256,17 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c
|
|||
handle_dep(filename.c_str());
|
||||
|
||||
pu::ifstream ifs(filename.c_str());
|
||||
//std::ifstream ifs(filename.c_str());
|
||||
if (!ifs.is_open()) {
|
||||
PRINTB("Can't open input file '%s'!\n", filename.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string text = getfile( ifs );
|
||||
//std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
|
||||
#if defined( __MINGW_FSTREAM__ )
|
||||
std::string text = ifs.mingw_getfile();
|
||||
#else
|
||||
std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
#endif // MINGW_FSTREAM
|
||||
text += "\n" + commandline_commands;
|
||||
fs::path abspath = boosty::absolute(filename);
|
||||
std::string parentpath = boosty::stringy(abspath.parent_path());
|
||||
|
@ -369,7 +372,8 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c
|
|||
PRINT("Current top level object is not a 3D object.\n");
|
||||
return 1;
|
||||
}
|
||||
std::ofstream fstream(stl_output_file);
|
||||
//std::ofstream fstream(stl_output_file);
|
||||
pu::ofstream fstream(stl_output_file);
|
||||
if (!fstream.is_open()) {
|
||||
PRINTB("Can't open file \"%s\" for export", stl_output_file);
|
||||
}
|
||||
|
@ -565,20 +569,19 @@ int main( int argc, char **argv )
|
|||
// In Win(TM) all cmdline opts & filenames are UTF16. We convert to UTF8
|
||||
// for all internal OpenSCAD work... but sometimes convert back to UTF16
|
||||
// when needed (for reading/writing files, etc)
|
||||
#if defined( __MINGW32__ ) || defined( __MINGW64__ ) || defined( _MSCVER )
|
||||
#ifdef __MINGW_FSTREAM__
|
||||
int wargc;
|
||||
wchar_t * wcmdline = GetCommandLineW();
|
||||
wchar_t ** wargv = CommandLineToArgvW( wcmdline, &wargc );
|
||||
std::vector<std::string> utf8args;
|
||||
std::vector<char *> utf8arg_ptrs;
|
||||
for (int i=0;i<wargc;i++) {
|
||||
std::wstring warg(wargv[i]);
|
||||
std::string tmp = pu::utf16_to_utf8( warg );
|
||||
std::string tmp = pu::utf16_to_utf8( std::wstring(wargv[i]) );
|
||||
utf8args.push_back( tmp );
|
||||
//utf8arg_ptrs.push_back( utf8args[i].c_str() );
|
||||
argv[i] = const_cast<char *>(utf8args[i].c_str());
|
||||
}
|
||||
#endif // mingw / msvc
|
||||
#endif // MINGW_FSTREAM
|
||||
|
||||
int rc = 0;
|
||||
#ifdef Q_WS_MAC
|
||||
|
|
|
@ -17,10 +17,10 @@ void print_messages_push();
|
|||
void print_messages_pop();
|
||||
|
||||
void PRINT(const std::string &msg);
|
||||
#define PRINTB(_fmt, _arg) do { PRINT(str(boost::format(_fmt) % _arg)); } while (0)
|
||||
#define PRINTB(_fmt, _arg) do { PRINT(boost::str(boost::format(_fmt) % _arg)); } while (0)
|
||||
|
||||
void PRINT_NOCACHE(const std::string &msg);
|
||||
#define PRINTB_NOCACHE(_fmt, _arg) do { PRINT_NOCACHE(str(boost::format(_fmt) % _arg)); } while (0)
|
||||
#define PRINTB_NOCACHE(_fmt, _arg) do { PRINT_NOCACHE(boost::str(boost::format(_fmt) % _arg)); } while (0)
|
||||
|
||||
|
||||
void PRINT_CONTEXT(const class Context *ctx, const class Module *mod, const class ModuleInstantiation *inst);
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
The .com version is a 'wrapper' for the .exe version. If you call
|
||||
'openscad' with no extension from a script or shell, the .com version
|
||||
is prioritized by the OS and feeds the GUI stdout to the console. We use
|
||||
pure C to minimize binary size when cross-compiling (~10kbytes). See Also:
|
||||
is prioritized by the OS and feeds the GUI stdout to the console.
|
||||
See Also:
|
||||
|
||||
http://stackoverflow.com/questions/493536/can-one-executable-be-both-a-console-and-gui-app
|
||||
http://blogs.msdn.com/b/oldnewthing/archive/2009/01/01/9259142.aspx
|
||||
|
@ -19,64 +19,98 @@
|
|||
Open Group popen() documentation
|
||||
inkscapec by Jos Hirth work at http://kaioa.com
|
||||
Nop Head's OpenSCAD_cl at github.com
|
||||
ImageMagick's utilities, like convert.cc
|
||||
http://www.i18nguy.com/unicode/c-unicode.html
|
||||
|
||||
TODO:
|
||||
Work with unicode: http://www.i18nguy.com/unicode/c-unicode.html
|
||||
Convert to plain C to save binary file size.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#define MAXCMDLEN 64000
|
||||
#define BUFFSIZE 42
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
wchar_t * marker;
|
||||
int wargc;
|
||||
wchar_t * wcmdline = GetCommandLineW();
|
||||
wchar_t ** wargv = CommandLineToArgvW( wcmdline, &wargc );
|
||||
wchar_t wcmd[MAXCMDLEN*4];
|
||||
|
||||
lstrcatW(wcmd,L"\0");
|
||||
lstrcatW(wcmd,L"openscad.exe ");
|
||||
if (wargc>1) {
|
||||
marker = StrStrW(wcmdline, wargv[1]);
|
||||
if (marker!=NULL) {
|
||||
lstrcatW(wcmd, marker);
|
||||
} else {
|
||||
wprintf(L"Error can't find 2nd arg %s\n",wargv[1]);
|
||||
wprintf(L"...in cmdline %s",wcmdline);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//(void) wargv;
|
||||
//(void) wargc;
|
||||
//int usequotes = 0;
|
||||
//int i,j;
|
||||
/* lstrcatW( wcmd, L"\0" );
|
||||
lstrcatW( wcmd, L"openscad.exe" );
|
||||
for ( i = 1 ; i < wargc ; ++i ) {
|
||||
lstrcatW( wcmd, L" " );
|
||||
for ( j = 0 ; wargv[i][j]!=L'\0'; j++ ) {
|
||||
if (wargv[i][j]==L' ') usequotes = 1 ;
|
||||
}
|
||||
if (usequotes) lstrcatW( wcmd, L"\"" );
|
||||
lstrcatW( wcmd, wargv[i] );
|
||||
if (usequotes) lstrcatW( wcmd, L"\"" );
|
||||
usequotes = 0;
|
||||
}
|
||||
lstrcatW( wcmd, L" ");
|
||||
lstrcatW( wcmd, L" 2>&1"); // capture stderr and stdout
|
||||
*/
|
||||
|
||||
FILE *cmd_stdout;
|
||||
char cmd[MAXCMDLEN];
|
||||
char buffer[BUFFSIZE];
|
||||
char *fgets_result;
|
||||
wchar_t buffer[BUFFSIZE];
|
||||
wchar_t *fgets_result;
|
||||
int eof = 0;
|
||||
int pclose_result;
|
||||
int i;
|
||||
int result = 0;
|
||||
|
||||
strcat( cmd, "\0" );
|
||||
strcat( cmd, "openscad.exe" );
|
||||
for ( i = 1 ; i < argc ; ++i ) {
|
||||
strcat( cmd, " " );
|
||||
strcat( cmd, argv[i] );
|
||||
}
|
||||
strcat( cmd, " ");
|
||||
strcat( cmd, " 2>&1"); // capture stderr and stdout
|
||||
|
||||
cmd_stdout = _popen( cmd, "rt" );
|
||||
wprintf(L"openscad.com: running %s\n", wcmd);
|
||||
cmd_stdout = _wpopen( wcmd, L"rt" );
|
||||
//cmd_stdout = _wpopen( wcmd, L"rb" );
|
||||
if ( cmd_stdout == NULL ) {
|
||||
printf( "Error opening _popen for command: %s", cmd );
|
||||
perror( "Error message:" );
|
||||
wprintf( L"Error opening _wpopen for command: %s\n", wcmd );
|
||||
//_wperror( L"Error message:" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ( !eof )
|
||||
{
|
||||
fgets_result = fgets( buffer, BUFFSIZE, cmd_stdout );
|
||||
fgets_result = fgetws( buffer, BUFFSIZE, cmd_stdout );
|
||||
if ( fgets_result == NULL ) {
|
||||
if ( ferror( cmd_stdout ) ) {
|
||||
printf("Error reading from stdout of %s\n", cmd);
|
||||
wprintf(L"Error reading from stdout of %s\n", wcmd);
|
||||
result = 1;
|
||||
}
|
||||
if ( feof( cmd_stdout ) ) {
|
||||
eof = 1;
|
||||
}
|
||||
} else {
|
||||
fprintf( stdout, "%s", buffer );
|
||||
fwprintf( stdout, L"%s", buffer );
|
||||
}
|
||||
}
|
||||
|
||||
pclose_result = _pclose( cmd_stdout );
|
||||
if ( pclose_result < 0 ) {
|
||||
perror("Error while closing stdout for command:");
|
||||
_wperror(L"Error while closing stdout for command.");
|
||||
result = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ CONFIG(winconsole) {
|
|||
SOURCES = src/winconsole.c
|
||||
CONFIG += console # sets IMAGE_SUBSYSTEM_WINDOWS_CUI in binary
|
||||
LIBS -= $$LIBS
|
||||
LIBS += mingw-cross-env/lib/libshlwapi.a
|
||||
RC_FILE -= $$RC_FILE
|
||||
QMAKE_POST_LINK = cd $(DESTDIR) && mv openscad_winconsole.exe openscad.com
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue