From 58c3445d82221ddd0fe3c2dd0023cab22ed9bcd1 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 8 Jun 2012 06:55:23 -0500 Subject: [PATCH] win console. --- H/pl-incl.h | 3 +- Makefile.in | 14 +++---- configure | 79 ++++++++++++++++++++++++++++++++++- configure.in | 2 + console/LGPL/pl-ntmain.c | 10 ++--- library/dialect/swi/fli/swi.c | 0 misc/yap.nsi | 11 ++--- misc/yap64.nsi | 11 ++--- os/pl-file.c | 3 ++ os/pl-nt.c | 39 +++++++++++++++++ pl/boot.yap | 0 pl/flags.yap | 64 ++++++++-------------------- pl/init.yap | 4 ++ pl/protect.yap | 1 + pl/qly.yap | 4 ++ 15 files changed, 169 insertions(+), 76 deletions(-) mode change 100644 => 100755 H/pl-incl.h mode change 100644 => 100755 Makefile.in mode change 100644 => 100755 console/LGPL/pl-ntmain.c mode change 100644 => 100755 library/dialect/swi/fli/swi.c mode change 100644 => 100755 misc/yap.nsi mode change 100644 => 100755 os/pl-file.c mode change 100644 => 100755 os/pl-nt.c mode change 100644 => 100755 pl/boot.yap mode change 100644 => 100755 pl/flags.yap mode change 100644 => 100755 pl/init.yap mode change 100644 => 100755 pl/protect.yap mode change 100644 => 100755 pl/qly.yap diff --git a/H/pl-incl.h b/H/pl-incl.h old mode 100644 new mode 100755 index 0820efcb3..784937ee9 --- a/H/pl-incl.h +++ b/H/pl-incl.h @@ -864,7 +864,7 @@ skip_list(Word l, Word *tailp ARG_LD) { static inline word valHandle__LD(term_t r ARG_LD) { - return (word)YAP_GetFromSlot(r); + return (word)YAP_GetFromSlot((Int)r); } static inline void *allocHeap__LD(size_t n ARG_LD) @@ -886,4 +886,5 @@ extern const PL_extension PL_predicates_from_read[]; extern const PL_extension PL_predicates_from_tai[]; extern const PL_extension PL_predicates_from_write[]; extern const PL_extension PL_predicates_from_prologflag[]; +extern const PL_extension PL_predicates_from_win[]; diff --git a/Makefile.in b/Makefile.in old mode 100644 new mode 100755 index 6ae577a2c..2ee0ffda9 --- a/Makefile.in +++ b/Makefile.in @@ -406,7 +406,7 @@ PLCONS_OBJECTS = \ pl-ntconsole.o \ pl-ntmain.o -all: parms.h startup.yss @ENABLE_WINCONSOLE@ pl-yap@EXEC_SUFFIX@ +all: parms.h startup.yss @ENABLE_WINCONSOLE@ yap-win@EXEC_SUFFIX@ Makefile: $(srcdir)/Makefile.in @@ -725,13 +725,13 @@ startup.yss: yap@EXEC_SUFFIX@ $(PL_SOURCES) yap@EXEC_SUFFIX@: $(HEADERS) yap.o @YAPLIB@ $(MPI_CC) $(EXECUTABLE_CFLAGS) $(LDFLAGS) -o yap yap.o @YAPLIB@ $(LIBS) @MPI_LIBS@ -plyap: pl-yap@EXEC_SUFFIX@ +yap-win: yap-win@EXEC_SUFFIX@ -pl-yap: pl-yap@EXEC_SUFFIX@ +yapwin: yap-win@EXEC_SUFFIX@ -pl-yap@EXEC_SUFFIX@: $(PLCONS_OBJECTS) $(HEADERS) @YAPLIB@ +yap-win@EXEC_SUFFIX@: $(PLCONS_OBJECTS) $(HEADERS) @YAPLIB@ (cd LGPL/swi_console; $(MAKE)) - $(MPI_CC) -municode -DUNICODE -D_UNICODE $(EXECUTABLE_CFLAGS) $(LDFLAGS) -Wl,-subsystem,windows -o pl-yap $(PLCONS_OBJECTS) plterm.dll @YAPLIB@ $(LIBS) @MPI_LIBS@ + $(MPI_CC) -municode -DUNICODE -D_UNICODE $(EXECUTABLE_CFLAGS) $(LDFLAGS) -Wl,-subsystem,windows -o yap-win $(PLCONS_OBJECTS) plterm.dll @YAPLIB@ $(LIBS) @MPI_LIBS@ libYap.a: $(LIB_OBJECTS) -rm -f libYap.a @@ -797,14 +797,14 @@ install_unix: startup.yss libYap.a @ENABLE_CUDD@ (cd packages/ProbLog/simplecudd_lfi; $(MAKE) install) -install_win32: startup.yss @ENABLE_WINCONSOLE@ pl-yap@EXEC_SUFFIX@ +install_win32: startup.yss @ENABLE_WINCONSOLE@ yap-win@EXEC_SUFFIX@ mkdir -p $(DESTDIR)$(BINDIR) mkdir -p $(DESTDIR)$(LIBDIR) mkdir -p $(DESTDIR)$(YAPLIBDIR) mkdir -p $(DESTDIR)$(INCLUDEDIR) $(INSTALL_PROGRAM) -m 755 yap.exe $(DESTDIR)$(BINDIR)/yap.exe $(INSTALL_PROGRAM) -m 755 yap.dll $(DESTDIR)$(BINDIR)/yap.dll - @ENABLE_WINCONSOLE@ $(INSTALL_PROGRAM) -m 755 pl-yap.exe $(DESTDIR)$(BINDIR)/pl-yap.exe + @ENABLE_WINCONSOLE@ $(INSTALL_PROGRAM) -m 755 yap-win.exe $(DESTDIR)$(BINDIR)/yap-win.exe @ENABLE_WINCONSOLE@ $(INSTALL_PROGRAM) -m 755 plterm.dll $(DESTDIR)$(BINDIR)/plterm.dll $(INSTALL_PROGRAM) -m 755 @YAPLIB@ $(DESTDIR)$(YAPLIBDIR)/@YAPLIB@ $(INSTALL_PROGRAM) -m 755 startup.yss $(DESTDIR)$(YAPLIBDIR)/startup.yss diff --git a/configure b/configure index d8559aa0a..742521dc4 100755 --- a/configure +++ b/configure @@ -5769,6 +5769,45 @@ _ACEOF LIBS="-lws2_32 $LIBS" +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lcomdlg32" >&5 +$as_echo_n "checking for main in -lcomdlg32... " >&6; } +if ${ac_cv_lib_comdlg32_main+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lcomdlg32 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ +return main (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_comdlg32_main=yes +else + ac_cv_lib_comdlg32_main=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_comdlg32_main" >&5 +$as_echo "$ac_cv_lib_comdlg32_main" >&6; } +if test "x$ac_cv_lib_comdlg32_main" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBCOMDLG32 1 +_ACEOF + + LIBS="-lcomdlg32 $LIBS" + fi EXTRA_LIBS_FOR_DLLS="-lws2_32" @@ -5813,6 +5852,45 @@ _ACEOF LIBS="-lwsock32 $LIBS" +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lcomdlg32" >&5 +$as_echo_n "checking for main in -lcomdlg32... " >&6; } +if ${ac_cv_lib_comdlg32_main+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lcomdlg32 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ +return main (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_comdlg32_main=yes +else + ac_cv_lib_comdlg32_main=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_comdlg32_main" >&5 +$as_echo "$ac_cv_lib_comdlg32_main" >&6; } +if test "x$ac_cv_lib_comdlg32_main" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBCOMDLG32 1 +_ACEOF + + LIBS="-lcomdlg32 $LIBS" + fi else @@ -6693,7 +6771,6 @@ if test "$yap_cv_cudd" != no; then fi cudd_dir=/usr/local fi - echo $cudd_dir here if test -d "$cudd_dir/lib64/cudd" -a "$YAP_TARGET" = amd64; then LIBS="$LIBS -L $cudd_dir/lib64/cudd" elif test -d "$cudd_dir/lib64" -a "$YAP_TARGET" = amd64; then diff --git a/configure.in b/configure.in index fffd11712..a367736f4 100755 --- a/configure.in +++ b/configure.in @@ -674,12 +674,14 @@ then target_cpu=x86_64 YAP_TARGET=amd64 AC_CHECK_LIB(ws2_32,main) + AC_CHECK_LIB(comdlg32,main) EXTRA_LIBS_FOR_DLLS="-lws2_32" elif test "$target_os" = "cygwin" then CC="${CC} -mno-cygwin" CXX="${CXX} -mno-cygwin" AC_CHECK_LIB(wsock32,main) + AC_CHECK_LIB(comdlg32,main) else AC_CHECK_LIB(wsock32,main) fi diff --git a/console/LGPL/pl-ntmain.c b/console/LGPL/pl-ntmain.c old mode 100644 new mode 100755 index 4f213e393..d4a2c97e7 --- a/console/LGPL/pl-ntmain.c +++ b/console/LGPL/pl-ntmain.c @@ -654,8 +654,8 @@ pl_window_pos(term_t options) static void call_menu(const TCHAR *name) { fid_t fid = PL_open_foreign_frame(); - predicate_t pred = PL_predicate("on_menu", 1, "prolog"); - module_t m = PL_new_module(PL_new_atom("prolog")); + predicate_t pred = PL_predicate("on_menu", 1, "system"); + module_t m = PL_new_module(PL_new_atom("system")); term_t a0 = PL_new_term_ref(); size_t len = _tcslen(name); @@ -667,7 +667,7 @@ call_menu(const TCHAR *name) foreign_t -pl_win_insert_menu_item(foreign_t menu, foreign_t label, foreign_t before) +pl_win_insert_menu_item(term_t menu, term_t label, term_t before) { TCHAR *m, *l, *b; if ( !PL_get_wchars(menu, NULL, &m, CVT_ATOM) || @@ -685,7 +685,7 @@ pl_win_insert_menu_item(foreign_t menu, foreign_t label, foreign_t before) foreign_t -pl_win_insert_menu(foreign_t label, foreign_t before) +pl_win_insert_menu(term_t label, term_t before) { TCHAR *l, *b; if ( !PL_get_wchars(label, NULL, &l, CVT_ATOM) || @@ -1026,7 +1026,7 @@ win32main(rlc_console c, int argc, TCHAR **argv) #if !defined(O_DEBUG) && !defined(_DEBUG) initSignals(); #endif - PL_register_foreign_in_module("system", "win_open_console", 5, + PL_register_foreign_in_module("prolog", "win_open_console", 5, pl_win_open_console, 0); if ( argc > MAX_ARGC ) diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c old mode 100644 new mode 100755 diff --git a/misc/yap.nsi b/misc/yap.nsi old mode 100644 new mode 100755 index c3a3432f3..3f38d615f --- a/misc/yap.nsi +++ b/misc/yap.nsi @@ -50,7 +50,7 @@ Section "Base system (required)" SetOutPath $INSTDIR\bin File c:\Yap\bin\yap.exe File c:\Yap\bin\yap.dll - File c:\Yap\bin\pl-yap.exe + File c:\Yap\bin\yap-win.exe File c:\Yap\bin\plterm.dll SetOutPath $INSTDIR\bin @@ -89,15 +89,10 @@ Section "Start Menu shortcuts" SectionIn 1 2 3 SetOutPath ${CWD} CreateDirectory "$SMPROGRAMS\${GRP}" - CreateShortCut "$SMPROGRAMS\${GRP}\Prolog.lnk" \ - "$INSTDIR\bin\yap.exe" \ - "" \ - "$INSTDIR\bin\yap.exe" \ - 0 CreateShortCut "$SMPROGRAMS\${GRP}\PLYap.lnk" \ - "$INSTDIR\bin\pl-yap.exe" \ + "$INSTDIR\bin\yap-win.exe" \ "" \ - "$INSTDIR\bin\pl-yap.exe" \ + "$INSTDIR\bin\yap-win.exe" \ 0 SetOutPath $INSTDIR CreateShortCut "$SMPROGRAMS\${GRP}\Readme.lnk" \ diff --git a/misc/yap64.nsi b/misc/yap64.nsi index 59378f4bd..77375c87f 100755 --- a/misc/yap64.nsi +++ b/misc/yap64.nsi @@ -47,7 +47,7 @@ Section "Base system (required)" SetOutPath $INSTDIR\bin File c:\Yap64\bin\yap.exe File c:\Yap64\bin\yap.dll - File c:\Yap64\bin\pl-yap.exe + File c:\Yap64\bin\yap-win.exe File c:\Yap64\bin\plterm.dll SetOutPath $INSTDIR\bin @@ -86,15 +86,10 @@ Section "Start Menu shortcuts" SectionIn 1 2 3 SetOutPath ${CWD} CreateDirectory "$SMPROGRAMS\${GRP}" - CreateShortCut "$SMPROGRAMS\${GRP}\Prolog.lnk" \ - "$INSTDIR\bin\yap.exe" \ - "" \ - "$INSTDIR\bin\yap.exe" \ - 0 CreateShortCut "$SMPROGRAMS\${GRP}\PLYap.lnk" \ - "$INSTDIR\bin\pl-yap.exe" \ + "$INSTDIR\bin\yap-win.exe" \ "" \ - "$INSTDIR\bin\pl-yap.exe" \ + "$INSTDIR\bin\yap-win.exe" \ 0 SetOutPath $INSTDIR CreateShortCut "$SMPROGRAMS\${GRP}\Readme.lnk" \ diff --git a/os/pl-file.c b/os/pl-file.c old mode 100644 new mode 100755 index 742ef700b..2fc2635e8 --- a/os/pl-file.c +++ b/os/pl-file.c @@ -4820,6 +4820,9 @@ init_yap(void) PL_register_extensions(PL_predicates_from_read); PL_register_extensions(PL_predicates_from_tai); PL_register_extensions(PL_predicates_from_prologflag); +#ifdef __WINDOWS__ + PL_register_extensions(PL_predicates_from_win); +#endif PL_register_extensions(foreigns); fileerrors = TRUE; SinitStreams(); diff --git a/os/pl-nt.c b/os/pl-nt.c old mode 100644 new mode 100755 index f88e87504..3dd8fe66c --- a/os/pl-nt.c +++ b/os/pl-nt.c @@ -942,6 +942,44 @@ getDefaultsFromRegistry() } } +static +PRED_IMPL("win_open_file_name", 3, win_open_file_name, 0) +{ GET_LD + OPENFILENAMEW ofn; + wchar_t szFileName[MAX_PATH]; + void *x; + HWND hwnd; + wchar_t *yap_cwd; + + if(!PL_get_pointer(A1, &x)) + return FALSE; + if(!PL_get_wchars(A2, NULL, &yap_cwd, CVT_ATOM|CVT_EXCEPTION)) + return FALSE; + hwnd = (HWND)x; + ZeroMemory(&ofn, sizeof(ofn)); + + ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW + ofn.hwndOwner = hwnd; + ofn.lpstrFilter = L"Prolog Files (*.pl;*.yap)\0*.pl;*.yap\0All Files (*.*)\0*.*\0"; + ofn.lpstrFile = szFileName; + ofn.lpstrInitialDir = yap_cwd; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST + //| OFN_HIDEREADONLY + //|OFN_ALLOWMULTISELECT + ; + ofn.lpstrDefExt = "pl"; + + if(GetOpenFileNameW(&ofn)) + { + // Do something usefull with the filename stored in szFileName + return PL_unify_wchars(A3, PL_ATOM, + MAX_PATH-1, szFileName); + } + return TRUE; +} + + /******************************* * PUBLISH PREDICATES * *******************************/ @@ -949,6 +987,7 @@ getDefaultsFromRegistry() BeginPredDefs(win) PRED_DEF("win_shell", 2, win_shell2, 0) PRED_DEF("win_shell", 3, win_shell3, 0) + PRED_DEF("win_open_file_name", 3, win_open_file_name, 0) PRED_DEF("win_registry_get_value", 3, win_registry_get_value, 0) PRED_DEF("win_folder", 2, win_folder, PL_FA_NONDETERMINISTIC) EndPredDefs diff --git a/pl/boot.yap b/pl/boot.yap old mode 100644 new mode 100755 diff --git a/pl/flags.yap b/pl/flags.yap old mode 100644 new mode 100755 index e0593418e..99ef38c95 --- a/pl/flags.yap +++ b/pl/flags.yap @@ -25,6 +25,18 @@ yap_flag(V,Out) :- ), '$user_flag_value'(V, Out). +yap_flag(V,Out) :- + ( var(V) -> + '$swi_current_prolog_flag'(V, Out) + ; + '$swi_current_prolog_flag'(V, Current) + -> + (var(Out) -> + Current = Out + ; + '$swi_set_prolog_flag'(V, Out) + ) + ). yap_flag(V,Out) :- var(V), !, '$show_yap_flag_opts'(V,Out). @@ -53,34 +65,6 @@ yap_flag(executable,L) :- '$executable'(L). yap_flag(hide,Atom) :- !, hide(Atom). yap_flag(unhide,Atom) :- !, unhide(Atom). -% character encoding... -yap_flag(encoding,X) :- - var(X), !, - '$swi_current_prolog_flag'(encoding, X). -yap_flag(encoding,X) :- - '$swi_set_prolog_flag'(encoding, X). - -% file_name_variables... -yap_flag(file_name_variables,X) :- - var(X), !, - '$swi_current_prolog_flag'(file_name_variables, X). -yap_flag(file_name_variables,X) :- - '$swi_set_prolog_flag'(file_name_variables, X). - -% fileerrors... -yap_flag(fileerrors,X) :- - var(X), !, - '$swi_current_prolog_flag'(fileerrors, X). -yap_flag(fileerrors,X) :- - '$swi_set_prolog_flag'(fileerrors, X). - -% -O optimisation -yap_flag(optimise,X) :- - var(X), !, - '$swi_current_prolog_flag'(optimise, X). -yap_flag(optimise,X) :- - '$swi_set_prolog_flag'(optimise, X). - % control garbage collection yap_flag(gc,V) :- var(V), !, @@ -259,12 +243,6 @@ yap_flag(home,X) :- '$transl_to_index_mode'(3, on). % default is multi argument indexing '$transl_to_index_mode'(4, max). -yap_flag(readline,X) :- - var(X), !, - '$swi_current_prolog_flag'(readline, X). -yap_flag(readline,X) :- - '$swi_set_prolog_flag'(readline, X). - % tabling mode yap_flag(tabling_mode,Options) :- var(Options), !, @@ -300,12 +278,6 @@ yap_flag(informational_messages,off) :- !, yap_flag(informational_messages,X) :- '$do_error'(domain_error(flag_value,informational_messages+X),yap_flag(informational_messages,X)). -yap_flag(timezone,X) :- - var(X), !, - '$swi_current_prolog_flag'(timezone, X). -yap_flag(timezone,X) :- - '$swi_set_prolog_flag'(timezone, X). - yap_flag(verbose,X) :- var(X), !, get_value('$verbose',X0), (X0 == on -> X = normal ; X = silent). @@ -863,11 +835,11 @@ yap_flag(dialect,yap). '$yap_system_flag'(discontiguous_warnings). '$yap_system_flag'(dollar_as_lower_case). '$yap_system_flag'(double_quotes). -'$yap_system_flag'(encoding). +% '$yap_system_flag'(encoding). '$yap_system_flag'(executable). % V = fast ; -'$yap_system_flag'(file_name_variables). -'$yap_system_flag'(fileerrors ). +% '$yap_system_flag'(file_name_variables). +% '$yap_system_flag'(fileerrors ). '$yap_system_flag'(float_format). % V = float_mantissa_digits ; % V = float_epsilon ; @@ -897,10 +869,10 @@ yap_flag(dialect,yap). '$yap_system_flag'(occurs_check). '$yap_system_flag'(open_expands_filename). '$yap_system_flag'(open_shared_object). -'$yap_system_flag'(optimise). +% '$yap_system_flag'(optimise). '$yap_system_flag'(profiling). '$yap_system_flag'(prompt_alternatives_on). -'$yap_system_flag'(readline). +% '$yap_system_flag'(readline). '$yap_system_flag'(redefine_warnings). '$yap_system_flag'(shared_object_search_path). '$yap_system_flag'(shared_object_extension). @@ -909,7 +881,7 @@ yap_flag(dialect,yap). '$yap_system_flag'(strict_iso). '$yap_system_flag'(syntax_errors). '$yap_system_flag'(system_options). -'$yap_system_flag'(timezone). +% '$yap_system_flag'(timezone). '$yap_system_flag'(to_chars_mode). '$yap_system_flag'(toplevel_hook). '$yap_system_flag'(toplevel_print_options). diff --git a/pl/init.yap b/pl/init.yap old mode 100644 new mode 100755 index 510962c06..fdcdfed69 --- a/pl/init.yap +++ b/pl/init.yap @@ -141,6 +141,8 @@ system_mode(verbose,off) :- set_value('$verbose',off). :- use_module('dbload.yap'). :- use_module('swi.yap'). :- use_module('../LGPL/predopts.pl'). +:- use_module('../LGPL/menu.pl'). + '$system_module'('$attributes'). '$system_module'('$coroutining'). @@ -149,6 +151,8 @@ system_mode(verbose,off) :- set_value('$verbose',off). '$system_module'('$messages'). '$system_module'('$predopts'). '$system_module'('$swi'). +'$system_module'('$win_menu'). + yap_hacks:cut_by(CP) :- '$$cut_by'(CP). diff --git a/pl/protect.yap b/pl/protect.yap old mode 100644 new mode 100755 index bdf761731..3643da1d7 --- a/pl/protect.yap +++ b/pl/protect.yap @@ -47,5 +47,6 @@ '$hide'('$declare_module') :- !, fail. '$hide'('$store_clause') :- !, fail. '$hide'('$skip_list') :- !, fail. +'$hide'('$win_insert_menu_item') :- !, fail. '$hide'(Name) :- hide(Name), fail. diff --git a/pl/qly.yap b/pl/qly.yap old mode 100644 new mode 100755 index f2267047b..0f4656ba7 --- a/pl/qly.yap +++ b/pl/qly.yap @@ -72,6 +72,10 @@ qsave_program(File) :- '$init_path_extensions', fail. % use if we come from a save_program and we have SWI's shlib +'$init_from_saved_state_and_args' :- + current_prolog_flag(hwnd, _HWND), + load_files(library(win_menu), [silent(true)]), + fail. '$init_from_saved_state_and_args' :- recorded('$reload_foreign_libraries',G,R), erase(R),