diff options
-rw-r--r-- | openscad.pro | 5 | ||||
-rw-r--r-- | scripts/installer.nsi | 1 | ||||
-rwxr-xr-x | scripts/release-common.sh | 9 | ||||
-rw-r--r-- | src/AboutDialog.html | 2 | ||||
-rw-r--r-- | src/winconsole.c | 84 | ||||
-rw-r--r-- | winconsole.pri | 28 |
6 files changed, 128 insertions, 1 deletions
diff --git a/openscad.pro b/openscad.pro index b11f45b..a7088ec 100644 --- a/openscad.pro +++ b/openscad.pro @@ -344,3 +344,8 @@ INSTALLS += applications icons.path = $$PREFIX/share/pixmaps icons.files = icons/openscad.png INSTALLS += icons + +CONFIG(winconsole) { + include(winconsole.pri) +} + diff --git a/scripts/installer.nsi b/scripts/installer.nsi index 87ec18d..1841431 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -6,6 +6,7 @@ DirText "This will install OpenSCAD on your computer. Choose a directory" Section "install" SetOutPath $INSTDIR File openscad.exe +File openscad.com File /r /x mingw-cross-env examples File /r /x mingw-cross-env libraries ${registerExtension} "$INSTDIR\openscad.exe" ".scad" "OpenSCAD_File" diff --git a/scripts/release-common.sh b/scripts/release-common.sh index ae856df..de14cb1 100755 --- a/scripts/release-common.sh +++ b/scripts/release-common.sh @@ -166,7 +166,14 @@ fi case $OS in LINXWIN) # dont use paralell builds, it can error-out on parser_yacc. + + # make main openscad.exe cd $DEPLOYDIR && make $TARGET + + # make console pipe-able openscad.com - see winconsole.pri for info + i686-pc-mingw32-qmake CONFIG+=winconsole ../openscad.pro + make + cd $OPENSCADDIR ;; *) @@ -232,6 +239,7 @@ case $OS in #package cp win32deps/* openscad-$VERSION cp $TARGET/openscad.exe openscad-$VERSION + cp $TARGET/openscad.com openscad-$VERSION rm -f openscad-$VERSION.zip "$ZIP" $ZIPARGS openscad-$VERSION.zip openscad-$VERSION rm -rf openscad-$VERSION @@ -242,6 +250,7 @@ case $OS in echo "Creating binary package" cd $DEPLOYDIR cp $TARGET/openscad.exe openscad-$VERSION + cp $TARGET/openscad.com openscad-$VERSION rm -f OpenSCAD-$VERSION.zip "$ZIP" $ZIPARGS OpenSCAD-$VERSION.zip openscad-$VERSION cd $OPENSCADDIR diff --git a/src/AboutDialog.html b/src/AboutDialog.html index 34e8127..6203e83 100644 --- a/src/AboutDialog.html +++ b/src/AboutDialog.html @@ -115,7 +115,7 @@ Brett Sutton, hmnapier, Eero af Heurlin, caliston, 5263, ghost, 42loop, uniqx, Michael Thomson, Michael Ivko, Pierre Doucet, myglc2, Alan Cox, Peter Falke, Michael Ambrus, Gordon Wrigley, Ed Nisley, Stony Smith, Pasca Andrei, David Goodenough, William A Adams, mrrobinson, 1i7, -benhowes ... and many others +benhowes, 5263, Craig Trader, Miro HronĨok, ... and many others <p> <b>Hosting & resources</b> diff --git a/src/winconsole.c b/src/winconsole.c new file mode 100644 index 0000000..de8e682 --- /dev/null +++ b/src/winconsole.c @@ -0,0 +1,84 @@ +/* + Enable easy piping under Windows(TM) command line. + + We use the 'devenv'(TM) method, which means we have two binary files: + + openscad.com, with IMAGE_SUBSYSTEM_WINDOWS_CUI flag set + openscad.exe, with IMAGE_SUBSYSTEM_WINDOWS_GUI flag set + + 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: + + 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 + http://blogs.msdn.com/b/junfeng/archive/2004/02/06/68531.aspx + http://msdn.microsoft.com/en-us/library/aa298534%28v=vs.60%29.aspx + http://cournape.wordpress.com/2008/07/29/redirecting-stderrstdout-in-cmdexe/ + Open Group popen() documentation + inkscapec by Jos Hirth work at http://kaioa.com + Nop Head's OpenSCAD_cl at github.com + + TODO: + Work with unicode: http://www.i18nguy.com/unicode/c-unicode.html +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#define MAXCMDLEN 64000 +#define BUFFSIZE 42 + +int main( int argc, char * argv[] ) +{ + FILE *cmd_stdout; + char cmd[MAXCMDLEN]; + char buffer[BUFFSIZE]; + char *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" ); + if ( cmd_stdout == NULL ) { + printf( "Error opening _popen for command: %s", cmd ); + perror( "Error message:" ); + return 1; + } + + while ( !eof ) + { + fgets_result = fgets( buffer, BUFFSIZE, cmd_stdout ); + if ( fgets_result == NULL ) { + if ( ferror( cmd_stdout ) ) { + printf("Error reading from stdout of %s\n", cmd); + result = 1; + } + if ( feof( cmd_stdout ) ) { + eof = 1; + } + } else { + fprintf( stdout, "%s", buffer ); + } + } + + pclose_result = _pclose( cmd_stdout ); + if ( pclose_result < 0 ) { + perror("Error while closing stdout for command:"); + result = 1; + } + + return result; +} diff --git a/winconsole.pri b/winconsole.pri new file mode 100644 index 0000000..a3991ae --- /dev/null +++ b/winconsole.pri @@ -0,0 +1,28 @@ +# Windows console issues workaround stub. +# +# Usage: put at the end of .pro file, then run qmake CONFIG+=winconsole +# +# This attempts to solve the problem of piping OpenSCAD under windows +# command line (GUI mode programs in Windows dont allow this). We use +# the 'devenv' solution, which means building two binaries: +# openscad.exe, and openscad.com, the latter being a wrapper for the +# former. See src/winconsole.c for more details. +# +# Qmake doesn't like building two binaries in the same directory so we +# depend on release-common.sh to call qmake twice and package the file properly + +CONFIG(winconsole) { + TEMPLATE = app + TARGET = openscad_winconsole + FORMS = + HEADERS = + FLEXSOURCES = + BISONSOURCES = + RESOURCES = + SOURCES = src/winconsole.c + CONFIG += console # sets IMAGE_SUBSYSTEM_WINDOWS_CUI in binary + LIBS -= $$LIBS + RC_FILE -= $$RC_FILE + QMAKE_POST_LINK = cd $(DESTDIR) && mv openscad_winconsole.exe openscad.com +} + |