From cdcb9b2cc09bed252d5247d89602bbef698a1487 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 17 May 2001 15:11:01 +0000 Subject: [PATCH] os:: patch from Ruurd + bindings display fix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2005 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 4 + README.Win32 | 39 +++++++++ config/ChangeLog | 4 + config/progtest.m4 | 19 ++++- development/ChangeLog | 4 + development/Win32/lyxprofile | 27 ++++++ development/Win32/lyxwin32.C | 32 +++++++ lib/ChangeLog | 7 ++ lib/configure | 10 ++- lib/configure.m4 | 8 +- lib/reLyX/acinclude.m4 | 13 ++- lib/reLyX/configure.in | 1 + po/POTFILES.in | 60 ++++++------- src/ChangeLog | 16 ++++ src/buffer.C | 5 +- src/insets/ChangeLog | 5 ++ src/insets/figinset.C | 3 +- src/insets/insetbib.C | 3 +- src/kbmap.C | 16 ++-- src/kbmap.h | 3 +- src/lyx_gui.C | 2 + src/lyx_main.C | 30 ++----- src/lyx_main.h | 2 +- src/main.C | 6 +- src/os2_defines.h | 10 ++- src/support/ChangeLog | 17 ++++ src/support/FileInfo.h | 5 ++ src/support/Makefile.am | 2 + src/support/filetools.C | 114 ++++++++++--------------- src/support/filetools.h | 3 - src/support/os.C | 11 +++ src/support/os.h | 66 +++++++++++++++ src/support/os_os2.C | 160 +++++++++++++++++++++++++++++++++++ src/support/os_unix.C | 69 +++++++++++++++ src/support/os_win32.C | 83 ++++++++++++++++++ src/support/rename.C | 3 + src/support/syscall.C | 30 +++---- src/support/tempname.C | 6 +- 38 files changed, 721 insertions(+), 177 deletions(-) create mode 100644 README.Win32 create mode 100644 development/Win32/lyxprofile create mode 100644 development/Win32/lyxwin32.C create mode 100644 src/support/os.C create mode 100644 src/support/os.h create mode 100644 src/support/os_os2.C create mode 100644 src/support/os_unix.C create mode 100644 src/support/os_win32.C diff --git a/ChangeLog b/ChangeLog index 545322f3e0..202b5a1b9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-05-16 Ruurd Reitsma + + * Added README.Win32 + 2001-04-15 Allan Rae * Makefile.am (sourcedoc/Doxyfile): ensure modifications to doxygen diff --git a/README.Win32 b/README.Win32 new file mode 100644 index 0000000000..16f26d76b7 --- /dev/null +++ b/README.Win32 @@ -0,0 +1,39 @@ +================================================================ +README for Win32 by Ruurd Reitsma (R.A.Reitsma@wbmt.tudelft.nl) +================================================================ + +Lyx has been ported to Win32 using the Cygwin environement. The port +consists of a few small tweaks to deal with DOS-style pathnames, so +LyX can use Win32 TeX distros like fptex and MiKTeX. There's also a +cygwin TeTeX port, but the native Win32 ports have a definite speed +advantage. Besides that, nothing fancy. + +The prerequisites are (obviously?): + +* cygwin installation (http://www.cygwin.com/). +* decent X server; eXceed, X-Win32, or maybe even Cygwin/XFree86. +* working TeX installation; fpTex, MikTex. + +It should compile out of the box, but there might be some libraries +missing in the final link step. You'll have to add them to the Makefile +by hand. Be sure to include -lregex, because cygwin's builtin regex is +sortof weird (filedialogs will turn up empty...) + +If you want to run lyx with no console windows open, there's a small +program in development/Win32 that will set the proper environment vars +and start lyx. + +Compile with: + +gcc lyxwin32.C -O2 -o lyxwin32 -static -Wall -Wno-format \ +-Wstrict-prototypes -Wmissing-prototypes -mwindows -e _mainCRTStartup + +Also make sure the latex binaries are in your Windows path. Windvi and +Yap are auto detected, and you might want to make a symlink to Adobe +Acrobat so it's detected too: + +ln -s //c/Program\ Files/adobe/Acrobat\ 4.0/Reader/AcroRd32.exe \ +/usr/bin/acroread + +Many thanks to Steven van Dijk, Claus Hentschel and Miyata Shigeru for +starting the porting business. diff --git a/config/ChangeLog b/config/ChangeLog index 8adb5b5b58..56ceedf995 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2001-05-16 Ruurd Reitsma + + * progtest.m4: added OS2 detection + 2001-04-04 Lars Gullik Bjønnes * lyxinclude.m4: remove support for gcc 2.97 simplify calling for diff --git a/config/progtest.m4 b/config/progtest.m4 index 2482d4a9bf..5bbead0dcf 100644 --- a/config/progtest.m4 +++ b/config/progtest.m4 @@ -11,6 +11,19 @@ dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) AC_DEFUN(AM_PATH_PROG_WITH_TEST, +[case "`uname -s 2> /dev/null`" in +OS/2) + PATH=`echo -E "$PATH" | sed 's+\\\\+/+g'` + PATH_IFS=';' + EXE_EXT='.exe' + CMD_EXT='.cmd' + ;; +*) + PATH_IFS=':' + EXE_EXT='' + CMD_EXT='' + ;; +esac] [# Extract the first word of "$2", so it can be a program name with args. set dummy $2; ac_word=[$]2 AC_MSG_CHECKING([for $ac_word]) @@ -20,10 +33,12 @@ AC_CACHE_VAL(ac_cv_path_$1, ac_cv_path_$1="[$]$1" # Let the user override the test with a path. ;; *) - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}$PATH_IFS" for ac_dir in ifelse([$5], , $PATH, [$5]); do test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then + if test -f $ac_dir/$ac_word \ + -o -f $ac_dir/$ac_word$EXE_EXT \ + -o -f $ac_dir/$ac_word$CMD_EXT; then if [$3]; then ac_cv_path_$1="$ac_dir/$ac_word" break diff --git a/development/ChangeLog b/development/ChangeLog index 59e7d50c78..53c8794b6f 100644 --- a/development/ChangeLog +++ b/development/ChangeLog @@ -1,3 +1,7 @@ +2001-05-16 Ruurd Reitsma + + * Win32/lyxwin32.C added. + 2001-04-17 Allan Rae * tools/makeLyXsigc.sh: put the important local changes into sed diff --git a/development/Win32/lyxprofile b/development/Win32/lyxprofile new file mode 100644 index 0000000000..9bfa4a8a1f --- /dev/null +++ b/development/Win32/lyxprofile @@ -0,0 +1,27 @@ +PATH="/usr/local/lyx/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin:/bin:$PATH" +unset DOSDRIVE +unset DOSDIR +unset TMPDIR +unset TMP + +USER="`id -un`" + +# Set up USER's home directory; no spaces allowed in the path! +export HOME=//c/Docs/Lyx + +export USER PATH + +for i in /etc/profile.d/*.sh ; do + if [ -f $i ]; then + . $i + fi +done + +export DISPLAY=localhost:0 + +export MAKE_MODE=unix + + +cd "$HOME" + +test -f ./.bashrc && . ./.bashrc diff --git a/development/Win32/lyxwin32.C b/development/Win32/lyxwin32.C new file mode 100644 index 0000000000..e479ef55ba --- /dev/null +++ b/development/Win32/lyxwin32.C @@ -0,0 +1,32 @@ +#include /* standard io library */ +#include /* standard library */ +#include /* sleep , fork & exec */ +#include /* standard string library */ +#include + +int main ( int argc, char *argv[] ) +{ +/*char cmd [32000] = "lyx " ; */ /* user command */ +char cmd [32000] = "lyx " ; +char *nargs [4 ] = { "/bin/bash", "-c" , cmd , NULL } ; /* execute with login /bin/bash */ +int i=1; + +putenv ( "BASH_ENV=/etc/lyxprofile" ) ; /* ensure bash reads my global env changes */ + +while ( i < argc ) /* do for all "real" args */ + { + strcat ( cmd , "\"" ) ; /* add quote before */ + strcat ( cmd , argv [ i ] ) ; /* add the argument */ + strcat ( cmd , "\" " ) ; /* add closing quote */ + i ++ ; + } + +strcat ( cmd, "/dev/null"); + +fprintf ( stderr , "Command is: |%s|\n" , cmd ); +execv ( "/bin/bash" , nargs ) ; /* exec sub command */ + +/* we should never reach here */ +fprintf ( stderr , "Execute failed, error = %d\n" , errno ) ; +return ( 0 ) ; /* exit with no error */ +} diff --git a/lib/ChangeLog b/lib/ChangeLog index 817e6e827a..57eee6adf9 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2001-05-16 Ruurd Reitsma + + * configure.m4: detect cygwin, windvi and yap + + * reLyX/acinclude.m4 : + * reLyX/configure.in : OS/2 fixes + 2001-05-17 Lars Gullik Bjønnes * bind/latinkeys.bind: fixup more bindings. diff --git a/lib/configure b/lib/configure index a7c567b32f..3361f42776 100755 --- a/lib/configure +++ b/lib/configure @@ -72,6 +72,12 @@ if test ! -r ${srcdir}/chkconfig.ltx ; then exit 1 fi +#### Adjust PATH for Win32 (Cygwin) +if test "x$OSTYPE" = xcygwin; then + echo "configure: cygwin detected; path correction" + srcdir=`cygpath -w "${srcdir}" | tr '\\\\' /` + echo "srcdir=${srcdir}" +fi #### Create the build directories if necessary for dir in bind clipart doc examples images kbd layouts reLyX \ @@ -522,9 +528,9 @@ fi # Search something to preview dvi echo $ac_n "checking for a DVI previewer""... $ac_c" -echo "$ac_t""(xdvi)" +echo "$ac_t""(xdvi windvi yap)" DVI_VIEWER= -for ac_prog in xdvi +for ac_prog in xdvi windvi yap do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog ; ac_word=$2 diff --git a/lib/configure.m4 b/lib/configure.m4 index 10913e9d57..6cfa32a414 100644 --- a/lib/configure.m4 +++ b/lib/configure.m4 @@ -148,6 +148,12 @@ if test ! -r ${srcdir}/chkconfig.ltx ; then exit 1 fi +#### Adjust PATH for Win32 (Cygwin) +if test "x$OSTYPE" = xcygwin; then + echo "configure: cygwin detected; path correction" + srcdir=`cygpath -w "${srcdir}" | tr '\\\\' /` + echo "srcdir=${srcdir}" +fi #### Create the build directories if necessary for dir in bind clipart doc examples images kbd layouts reLyX \ @@ -219,7 +225,7 @@ SEARCH_PROG([for a Postscript previewer],GHOSTVIEW,gv ghostview) SEARCH_PROG([for a PDF preview],PDF_VIEWER,acroread gv ghostview xpdf) # Search something to preview dvi -SEARCH_PROG([for a DVI previewer],DVI_VIEWER, xdvi) +SEARCH_PROG([for a DVI previewer],DVI_VIEWER, xdvi windvi yap) # Search something to preview html SEARCH_PROG([for a HTML previewer],HTML_VIEWER, netscape) diff --git a/lib/reLyX/acinclude.m4 b/lib/reLyX/acinclude.m4 index be15785219..f8d00c594d 100644 --- a/lib/reLyX/acinclude.m4 +++ b/lib/reLyX/acinclude.m4 @@ -10,15 +10,24 @@ relyx_warning=yes]) dnl RELYX_SEARCH_PROG(VARIABLE-NAME,PROGRAMS-LIST,ACTION-IF-FOUND) dnl define(RELYX_SEARCH_PROG,[dnl +case "`uname -s 2> /dev/null`" in +OS/2) + PATH=`echo -E "$PATH" | sed 's+\\\\+/+g'` + PATH_IFS=';' + ;; +*) + PATH_IFS=':' + ;; +esac for ac_prog in $2 ; do # Extract the first word of "$ac_prog", so it can be a program name with # args. set dummy $ac_prog ; ac_word=$[2] if test ! -n "[$]$1"; then - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}$PATH_IFS" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. - if test -f [$ac_dir/$ac_word]; then + if test -f [$ac_dir/$ac_word] -o -f [$ac_dir/$ac_word$ac_exeext]; then $1="$ac_prog" break fi diff --git a/lib/reLyX/configure.in b/lib/reLyX/configure.in index eac77d53e8..913a25e986 100644 --- a/lib/reLyX/configure.in +++ b/lib/reLyX/configure.in @@ -2,6 +2,7 @@ dnl Process with autoconf to generate configure script -*- sh -*- AC_INIT(reLyX.in) AC_PREREQ(2.13) dnl We want to use autoconf 2.13 AC_CONFIG_AUX_DIR(../../config) +AC_EXEEXT dnl PACKAGE=reLyX dnl Do this to install in $datadir/lyx/reLyX instead of $datadir/reLyX/reLyX diff --git a/po/POTFILES.in b/po/POTFILES.in index 04b1702eba..ce1833e689 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -10,8 +10,8 @@ src/CutAndPaste.C src/debug.C src/exporter.C src/ext_l10n.h -src/figure_form.C src/figureForm.C +src/figure_form.C src/FontLoader.C src/frontends/controllers/ButtonController.h src/frontends/controllers/character.C @@ -90,67 +90,67 @@ src/frontends/qt2/paragraphdlgimpl.C src/frontends/qt2/tabularcreatedlgimpl.C src/frontends/xforms/combox.C src/frontends/xforms/FileDialog.C -src/frontends/xforms/form_bibitem.C src/frontends/xforms/FormBibitem.C -src/frontends/xforms/form_bibtex.C +src/frontends/xforms/form_bibitem.C src/frontends/xforms/FormBibtex.C +src/frontends/xforms/form_bibtex.C src/frontends/xforms/form_browser.C -src/frontends/xforms/form_character.C src/frontends/xforms/FormCharacter.C -src/frontends/xforms/form_citation.C +src/frontends/xforms/form_character.C src/frontends/xforms/FormCitation.C -src/frontends/xforms/form_copyright.C +src/frontends/xforms/form_citation.C src/frontends/xforms/FormCopyright.C -src/frontends/xforms/form_credits.C +src/frontends/xforms/form_copyright.C src/frontends/xforms/FormCredits.C -src/frontends/xforms/form_document.C +src/frontends/xforms/form_credits.C src/frontends/xforms/FormDocument.C -src/frontends/xforms/form_error.C +src/frontends/xforms/form_document.C src/frontends/xforms/FormError.C -src/frontends/xforms/form_external.C +src/frontends/xforms/form_error.C src/frontends/xforms/FormExternal.C -src/frontends/xforms/form_filedialog.C +src/frontends/xforms/form_external.C src/frontends/xforms/FormFiledialog.C -src/frontends/xforms/form_graphics.C +src/frontends/xforms/form_filedialog.C src/frontends/xforms/FormGraphics.C -src/frontends/xforms/form_include.C +src/frontends/xforms/form_graphics.C src/frontends/xforms/FormInclude.C -src/frontends/xforms/form_index.C +src/frontends/xforms/form_include.C src/frontends/xforms/FormIndex.C +src/frontends/xforms/form_index.C src/frontends/xforms/FormLog.C src/frontends/xforms/FormMathsBitmap.C -src/frontends/xforms/form_maths_deco.C src/frontends/xforms/FormMathsDeco.C -src/frontends/xforms/form_maths_delim.C +src/frontends/xforms/form_maths_deco.C src/frontends/xforms/FormMathsDelim.C -src/frontends/xforms/form_maths_matrix.C +src/frontends/xforms/form_maths_delim.C src/frontends/xforms/FormMathsMatrix.C -src/frontends/xforms/form_maths_panel.C +src/frontends/xforms/form_maths_matrix.C src/frontends/xforms/FormMathsPanel.C -src/frontends/xforms/form_maths_space.C +src/frontends/xforms/form_maths_panel.C src/frontends/xforms/FormMathsSpace.C -src/frontends/xforms/form_minipage.C +src/frontends/xforms/form_maths_space.C src/frontends/xforms/FormMinipage.C -src/frontends/xforms/form_paragraph.C +src/frontends/xforms/form_minipage.C src/frontends/xforms/FormParagraph.C -src/frontends/xforms/form_preamble.C +src/frontends/xforms/form_paragraph.C src/frontends/xforms/FormPreamble.C -src/frontends/xforms/form_preferences.C +src/frontends/xforms/form_preamble.C src/frontends/xforms/FormPreferences.C -src/frontends/xforms/form_print.C +src/frontends/xforms/form_preferences.C src/frontends/xforms/FormPrint.C -src/frontends/xforms/form_ref.C +src/frontends/xforms/form_print.C src/frontends/xforms/FormRef.C -src/frontends/xforms/form_search.C +src/frontends/xforms/form_ref.C src/frontends/xforms/FormSearch.C -src/frontends/xforms/form_tabular.C +src/frontends/xforms/form_search.C src/frontends/xforms/FormTabular.C -src/frontends/xforms/form_tabular_create.C +src/frontends/xforms/form_tabular.C src/frontends/xforms/FormTabularCreate.C -src/frontends/xforms/form_toc.C +src/frontends/xforms/form_tabular_create.C src/frontends/xforms/FormToc.C -src/frontends/xforms/form_url.C +src/frontends/xforms/form_toc.C src/frontends/xforms/FormUrl.C +src/frontends/xforms/form_url.C src/frontends/xforms/FormVCLog.C src/frontends/xforms/input_validators.C src/frontends/xforms/Menubar_pimpl.C diff --git a/src/ChangeLog b/src/ChangeLog index b1cd932c7f..243eebf123 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2001-05-16 Jean-Marc Lasgouttes + + * kbmap.C (findbinding): clean it up and make it work correctly. + + * lyx_main.C (init): do not pass argc and argv as parameters + +2001-05-16 Ruurd Reitsma + + * buffer.C: fix path for OS/2 & Win32 + + * lyx_gui.C + * lyx_main + * lyx_main.C: Added os:: class. + + * os2_defines.h: update + 2001-05-17 Lars Gullik Bjønnes * lyxfunc.[Ch] (processKeySym): return void. Handle unknown actions diff --git a/src/buffer.C b/src/buffer.C index c1b139a2cc..b70fca7b63 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -80,6 +80,7 @@ #include "insets/insetfloatlist.h" #include "support/filetools.h" #include "support/path.h" +#include "support/os.h" #include "LaTeX.h" #include "Chktex.h" #include "LyXView.h" @@ -1341,7 +1342,7 @@ bool Buffer::save() const s = fileName() + '~'; if (!lyxrc.backupdir_path.empty()) s = AddName(lyxrc.backupdir_path, - subst(CleanupPath(s),'/','!')); + subst(os::slashify_path(s),'/','!')); // Rename is the wrong way of making a backup, // this is the correct way. @@ -1769,7 +1770,7 @@ void Buffer::makeLaTeXFile(string const & fname, if (!original_path.empty()) { ofs << "\\makeatletter\n" << "\\def\\input@path{{" - << original_path << "/}}\n" + << os::external_path(original_path) << "/}}\n" << "\\makeatother\n"; texrow.newline(); texrow.newline(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9fa20f49c2..689db689a1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-05-16 Ruurd Reitsma + + * figinset.C + * insetbib.C: fix path for OS/2 & Win32 + 2001-05-10 Lars Gullik Bjønnes * insetfoot.C (Latex): don't use % after footnote. diff --git a/src/insets/figinset.C b/src/insets/figinset.C index a2c20d44cb..f1e0ad7779 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -57,6 +57,7 @@ #include "lyx_gui_misc.h" // CancelCloseBoxCB #include "support/FileInfo.h" #include "support/lyxlib.h" +#include "support/os.h" #include "Painter.h" #include "font.h" #include "bufferview_funcs.h" @@ -1919,7 +1920,7 @@ void InsetFig::Preview(string const & p) if (GetExtension(tfname).empty()) tfname += ".eps"; string buf1 = OnlyPath(owner->fileName()); - string buf2 = MakeAbsPath(tfname, buf1); + string buf2 = os::external_path(MakeAbsPath(tfname, buf1)); if (!formats.View(owner, buf2, "eps")) lyxerr << "Can't view " << buf2 << endl; } diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 6db97e73a2..cca2c271fc 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -17,6 +17,7 @@ #include "lyxtext.h" #include "support/filetools.h" #include "support/path.h" +#include "support/os.h" #include "lyxrc.h" #include "font.h" #include "LyXView.h" @@ -141,7 +142,7 @@ int InsetBibtex::Latex(Buffer const * buffer, ostream & os, while(!adb.empty()) { if (!buffer->niceFile && IsFileReadable(MakeAbsPath(adb, buffer->filepath)+".bib")) - adb = MakeAbsPath(adb, buffer->filepath); + adb = os::external_path(MakeAbsPath(adb, buffer->filepath)); db_out += adb; db_out += ','; diff --git a/src/kbmap.C b/src/kbmap.C index 51d9ecbfdc..5f53a2552a 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -234,7 +234,7 @@ string const kb_keymap::keyname(kb_key const & k) // Finds a key for a keyaction, if possible -string const kb_keymap::findbinding(int act) const +string const kb_keymap::findbinding(int act, string const & prefix) const { string res; if (table.empty()) return res; @@ -243,17 +243,13 @@ string const kb_keymap::findbinding(int act) const for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { if ((*cit).table.get()) { - string suffix = (*cit).table->findbinding(act); - suffix = strip(suffix, ' '); - suffix = strip(suffix, ']'); - suffix = frontStrip(suffix, '['); - if (!suffix.empty()) { - res += "[" + keyname((*cit)) + " " - + suffix + "] "; - } + res += (*cit).table->findbinding(act, + prefix + + keyname((*cit)) + + " "); } else if ((*cit).action == act) { res += "["; - res += keyname((*cit)); + res += prefix + keyname((*cit)); res += "] "; } } diff --git a/src/kbmap.h b/src/kbmap.h index 3bc02f6a52..3a0ae1e70c 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -36,7 +36,8 @@ public: unsigned int mod, kb_sequence * seq) const; /// Given an action, find all keybindings. - string const findbinding(int action) const; + string const findbinding(int action, + string const & prefix = string()) const; private: /// struct kb_key { diff --git a/src/lyx_gui.C b/src/lyx_gui.C index 9ed81a8323..c7cd7262df 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -19,6 +19,7 @@ #include "lyx_gui.h" #include FORMS_H_LOCATION #include "support/filetools.h" +#include "support/os.h" #include "figure_form.h" #include "print_form.h" #include "tex-strings.h" @@ -117,6 +118,7 @@ LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI) Display * display = fl_get_display(); if (!display) { lyxerr << "LyX: unable to access X display, exiting" << endl; + os::warn("Unable to access X display, exiting"); exit(1); } fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC); diff --git a/src/lyx_main.C b/src/lyx_main.C index de3c9089fd..c3122ef1e7 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -41,6 +41,7 @@ #include "encoding.h" #include "converter.h" #include "language.h" +#include "support/os.h" using std::endl; @@ -106,7 +107,7 @@ LyX::LyX(int * argc, char * argv[]) // Initialization of LyX (reads lyxrc and more) lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl; - init(argc, argv, gui); + init(gui); lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl; lyxGUI->init(); @@ -184,7 +185,7 @@ LyX::~LyX() extern "C" void error_handler(int err_sig); -void LyX::init(int */*argc*/, char **argv, bool gui) +void LyX::init(bool gui) { // Install the signal handlers signal(SIGHUP, error_handler); @@ -198,27 +199,9 @@ void LyX::init(int */*argc*/, char **argv, bool gui) // string fullbinpath; - string binpath = subst(argv[0], '\\', '/'); - string binname = OnlyFilename(argv[0]); - // Sorry for system specific code. (SMiyata) - if (suffixIs(binname, ".exe")) - binname.erase(binname.length()-4, string::npos); - - binpath = ExpandPath(binpath); // This expands ./ and ~/ - - if (!AbsolutePath(binpath)) { - string binsearchpath = GetEnvPath("PATH"); - // This will make "src/lyx" work always :-) - binsearchpath += ";."; - binpath = FileOpenSearch(binsearchpath, argv[0]); - } - + string binpath = os::binpath(); + string binname = os::binname(); fullbinpath = binpath; - binpath = MakeAbsPath(OnlyPath(binpath)); - - // In case we are running in place and compiled with shared libraries - if (suffixIs(binpath, "/.libs/")) - binpath.erase(binpath.length()-6, string::npos); if (binpath.empty()) { lyxerr << _("Warning: could not determine path of binary.") @@ -444,7 +427,8 @@ void LyX::init(int */*argc*/, char **argv, bool gui) } // Create temp directory - system_tempdir = CreateLyXTmpDir(lyxrc.tempdir_path); + os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path)); + system_tempdir = os::getTmpDir(); if (lyxerr.debugging(Debug::INIT)) { lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl; } diff --git a/src/lyx_main.h b/src/lyx_main.h index 087b8fb043..1c836f6c93 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -61,7 +61,7 @@ private: /// void runtime(); /// - void init(int * argc, char * argv[], bool); + void init(bool); /// void defaultKeyBindings(kb_keymap * kbmap); /// diff --git a/src/main.C b/src/main.C index 770b5aedca..5b4fbc6424 100644 --- a/src/main.C +++ b/src/main.C @@ -14,11 +14,13 @@ #include "gettext.h" #include "LString.h" #include "support/filetools.h" +#include "support/os.h" #include "frontends/GUIRunTime.h" int main(int argc, char * argv[]) { + os::init(&argc, &argv); int const val = GUIRunTime::initApplication(argc, argv); if (val) return val; @@ -33,10 +35,6 @@ int main(int argc, char * argv[]) locale_init(); gettext_init(lyx_localedir); -#ifdef __EMX__ - _wildcard(&argc, &argv); -#endif - LyX lyx(&argc, argv); return 0; // SUCCESS } diff --git a/src/os2_defines.h b/src/os2_defines.h index de9c6c6760..f7fea77f07 100644 --- a/src/os2_defines.h +++ b/src/os2_defines.h @@ -13,16 +13,22 @@ #ifndef OS2_DEFINES_H #define OS2_DEFINES_H +#if defined (__cplusplus) #include -#include #include +extern "C" inline int readlink(const char *, char *, size_t) {return -1;} +#else +#include +#include +#define readlink(s, t, l) (-1) +#endif +#include #include #include /* #include */ #define lstat stat #define S_ISLNK(x) false #define S_ISBLK(x) false -#define readlink(s, t, l) (strcpy(t, s), strlen(t)) /*#define mkfifo(p, m) (0) *//* LyXserver is temporary disabled. */ #define chdir _chdir2 #define strcasecmp stricmp diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 1a66882283..0b8f11cd5f 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,20 @@ +2001-05-16 Ruurd Reitsma + + * FileInfo.h: X_OK workaround for cygwin + + * Makefile.am: + * os.C: + * os.h: + * os_os2.C: + * os_unix.C: + * os_win32.C: + * filetools.C: + * filetools.h: Added os:: class. + + * rename.C: + * syscall.C: + * tempname.C: OS/2 fixes + 2001-05-03 Lars Gullik Bjønnes * textutils.h: remvoe !NEW_INSETS cruft diff --git a/src/support/FileInfo.h b/src/support/FileInfo.h index 8f965731ce..806c374c85 100644 --- a/src/support/FileInfo.h +++ b/src/support/FileInfo.h @@ -24,6 +24,11 @@ #include #include "LString.h" +#if defined(__CYGWIN__) //Cygwin has it's own concept of X_OK ??? +#undef X_OK +#define X_OK 1 +#endif + /** Use objects of this class to get information about files. */ class FileInfo : boost::noncopyable { diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 1aa751be3c..164b2ae74b 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -29,6 +29,8 @@ libsupport_la_SOURCES = \ LRegex.h \ LSubstring.C \ LSubstring.h \ + os.C \ + os.h \ StrPool.C \ StrPool.h \ abort.C \ diff --git a/src/support/filetools.C b/src/support/filetools.C index d284417e24..366f57097d 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -34,6 +34,7 @@ #include "support/path.h" // I know it's OS/2 specific (SMiyata) #include "gettext.h" #include "lyxlib.h" +#include "os.h" // Which part of this is still necessary? (JMarc). #if HAVE_DIRENT_H @@ -103,12 +104,9 @@ string const MakeLatexName(string const & file) // Substitutes spaces with underscores in filename (and path) string const QuoteName(string const & name) { - // CHECK Add proper emx support here! -#ifndef __EMX__ - return "\'" + name + "\'"; -#else - return name; -#endif + return (os::shell() == os::UNIX) ? + "\'" + name + "\'": + "\"" + name + "\""; } @@ -172,7 +170,7 @@ string const FileOpenSearch (string const & path, string const & name, string tmppath = split(path, path_element, ';'); while (notfound && !path_element.empty()) { - path_element = CleanupPath(path_element); + path_element = os::slashify_path(path_element); if (!suffixIs(path_element, '/')) path_element+= '/'; path_element = subst(path_element, "$$LyX", system_lyxdir); @@ -249,7 +247,6 @@ string const FileSearch(string const & path, string const & name, // Expand Environmentvariables in 'name' string const tmpname = ReplaceEnvironmentPath(name); string fullname = MakeAbsPath(tmpname, path); - // search first without extension, then with it. if (IsFileReadable(fullname)) return fullname; @@ -321,7 +318,7 @@ string const GetEnvPath(string const & name) #ifndef __EMX__ string const pathlist = subst(GetEnv(name), ':', ';'); #else - string const pathlist = subst(GetEnv(name), '\\', '/'); + string const pathlist = os::slashify_path(GetEnv(name)); #endif return strip(pathlist, ';'); } @@ -469,7 +466,18 @@ int DestroyTmpDir(string const & tmpdir, bool Allfiles) string const CreateBufferTmpDir(string const & pathfor) { - return CreateTmpDir(pathfor, "lyx_tmpbuf"); + static int count = 0; + static string const tmpdir(pathfor.empty() ? os::getTmpDir() : pathfor); + // We are in our own directory. Why bother to mangle name? + // In fact I wrote this code to circumvent a problematic behaviour (bug?) + // of EMX mkstemp(). + string tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++); + if (lyx::mkdir(tmpfl, 0777)) { + WriteFSAlert(_("Error! Couldn't create temporary directory:"), + tmpdir); + return string(); + } + return tmpfl; } @@ -509,7 +517,7 @@ int DestroyLyXTmpDir(string const & tmpdir) // Creates directory. Returns true if succesfull bool createDirectory(string const & path, int permission) { - string temp(strip(CleanupPath(path), '/')); + string temp(strip(os::slashify_path(path), '/')); if (temp.empty()) { WriteAlert(_("Internal error!"), @@ -546,32 +554,21 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath) { // checks for already absolute path if (AbsolutePath(RelPath)) -#ifdef __EMX__ - if (RelPath[0]!= '/' && RelPath[0]!= '\\') -#endif return RelPath; // Copies given paths - string TempRel(CleanupPath(RelPath)); + string TempRel(os::slashify_path(RelPath)); + lyxerr << "TempRel=" << TempRel <(path[0])) && path.length()>1 && path[1] == ':'))); + return (!path.empty() && isalpha(static_cast(path[0])) && path.length() > 1 && path[1] == ':'); #endif } @@ -726,18 +726,6 @@ string const NormalizePath(string const & path) } -string const CleanupPath(string const & path) -{ -#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */ - string temppath = subst(path, '\\', '/'); - temppath = subst(temppath, "//", "/"); - return lowercase(temppath); -#else // On unix, nothing to do - return path; -#endif -} - - string const GetFileContents(string const & fname) { FileInfo finfo(fname); @@ -849,33 +837,16 @@ string const ReplaceEnvironmentPath(string const & path) // Make relative path out of two absolute paths -string const MakeRelPath(string const & abspath0, string const & basepath0) +string const MakeRelPath(string const & abspath, string const & basepath) // Makes relative path out of absolute path. If it is deeper than basepath, // it's easy. If basepath and abspath share something (they are all deeper // than some directory), it'll be rendered using ..'s. If they are completely // different, then the absolute path will be used as relative path. { - // This is a hack. It should probaly be done in another way. Lgb. - string const abspath = CleanupPath(abspath0); - string const basepath = CleanupPath(basepath0); - if (abspath.empty()) - return ""; - string::size_type const abslen = abspath.length(); string::size_type const baselen = basepath.length(); - - // Find first different character - string::size_type i = 0; - while (i < abslen && i < baselen && abspath[i] == basepath[i]) ++i; - // Go back to last / - if (i < abslen && i < baselen - || (i < abslen && abspath[i] != '/' && i == baselen) - || (i < baselen && basepath[i] != '/' && i == abslen)) - { - if (i) --i; // here was the last match - while (i && abspath[i] != '/') --i; - } + string::size_type i = os::common_path(abspath, basepath); if (i == 0) { // actually no match - cannot make it relative @@ -912,17 +883,20 @@ string const MakeRelPath(string const & abspath0, string const & basepath0) string const AddPath(string const & path, string const & path_2) { string buf; - string const path2 = CleanupPath(path_2); + string const path2 = os::slashify_path(path_2); if (!path.empty() && path != "." && path != "./") { - buf = CleanupPath(path); + buf = os::slashify_path(path); if (path[path.length() - 1] != '/') buf += '/'; } - if (!path2.empty()) - buf += frontStrip(strip(path2, '/'), '/') + '/'; - + if (!path2.empty()) { + string::size_type const p2start = path2.find_first_not_of('/'); + string::size_type const p2end = path2.find_last_not_of('/'); + string const tmp = path2.substr(p2start, p2end - p2start + 1); + buf += tmp + '/'; + } return buf; } @@ -947,7 +921,7 @@ ChangeExtension(string const & oldname, string const & extension) else ext = extension; - return CleanupPath(oldname.substr(0, last_dot) + ext); + return os::slashify_path(oldname.substr(0, last_dot) + ext); } diff --git a/src/support/filetools.h b/src/support/filetools.h index c373562d1a..4772103429 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -182,9 +182,6 @@ string const OnlyFilename(string const & fname); /// Get the contents of a file as a huge string string const GetFileContents(string const & fname); -/// Cleanup a path if necessary. Currently only useful with OS/2 -string const CleanupPath(string const & path); - /** Check and Replace Environmentvariables ${NAME} in Path. Replaces all occurences of these, if they are found in the environment. diff --git a/src/support/os.C b/src/support/os.C new file mode 100644 index 0000000000..cafcb27ac2 --- /dev/null +++ b/src/support/os.C @@ -0,0 +1,11 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#ifdef __EMX__ +#include "os_os2.C" +#elif defined(__CYGWIN__) || defined( __CYGWIN32__) +#include "os_win32.C" +#else +#include "os_unix.C" +#endif diff --git a/src/support/os.h b/src/support/os.h new file mode 100644 index 0000000000..7abe2d0a4d --- /dev/null +++ b/src/support/os.h @@ -0,0 +1,66 @@ +// os.h copyright "Ruurd A. Reitsma" + +#ifndef OS_H +#define OS_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "LString.h" + +/// Do we need a base class for this? +class os { +public: + // + enum shell_type { + UNIX, // Do we have to distinguish sh and csh? + CMD_EXE + }; + + // + static void init(int * argc, char ** argv[]); + + // + static string binpath() {return binpath_;}; + + // + static string binname() {return binname_;}; + + // system_tempdir actually doesn't belong here. + // I put it here only to avoid a global variable. + static void setTmpDir(string p) {tmpdir_ = p;}; + + // + static string getTmpDir() {return tmpdir_;}; + + // + static string current_root(); + + // + static os::shell_type shell() {return _shell;}; + + // DBCS aware! + static string::size_type common_path(string const &p1, string const &p2); + + // no-op on UNIX, '\\'->'/' on OS/2 and Win32, ':'->'/' on MacOS, etc. + static string slashify_path(string p); + static string external_path(string p); + static void warn(string mesg); +private: + static string binpath_; + static string binname_; + static string tmpdir_; + static os::shell_type _shell; + static unsigned long cp_; // Used only on OS/2 to determine file system encoding. + + // Never initialize static variables in the header! + // Anyway I bet this class will never be constructed. + os() {}; + + // Ignore warning! + ~os() {}; + +}; + +#endif diff --git a/src/support/os_os2.C b/src/support/os_os2.C new file mode 100644 index 0000000000..fd79f697a9 --- /dev/null +++ b/src/support/os_os2.C @@ -0,0 +1,160 @@ +// os_os2.C + +// Various OS specific functions +#include + +#ifdef __GNUG__ +#pragma implementation "os.h" +#endif + +#include "os.h" +#include "support/filetools.h" +#define INCL_DOSFILEMGR +#define INCL_DOSMODULEMGR +#define INCL_DOSPROCESS +#define INCL_DOSNLS +#define INCL_DOSERRORS +#include + +string os::binpath_ = string(); +string os::binname_ = string(); +string os::tmpdir_ = string(); +os::shell_type os::_shell = os::UNIX; +unsigned long os::cp_ = 0; + +void os::init(int * argc, char ** argv[]) { + if (argc != 0 /* This is a hack! */) { + _wildcard(argc, argv); + PTIB ptib = new TIB[1]; + PPIB ppib = new PIB[1]; + APIRET rc = DosGetInfoBlocks(&ptib, &ppib); + if (rc != NO_ERROR) + exit(rc); + char* tmp = new char[256]; + // This is the only reliable way to retrieve the executable name. + rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp); + if (rc != NO_ERROR) + exit(rc); + string p(tmp); + p = slashify_path(p); + binname_ = OnlyFilename(p); + binname_.erase(binname_.length()-4, string::npos); + binpath_ = OnlyPath(p); + + // OS/2 cmd.exe has another use for '&' + string sh = OnlyFilename(GetEnvPath("EMXSHELL")); + if (sh.empty()) { + // COMSPEC is set, unless user unsets + sh = OnlyFilename(GetEnvPath("COMSPEC")); + if (sh.empty()) + sh = "cmd.exe"; + } + sh = lowercase(sh); // DosMapCase() is an overkill here + if (contains(sh, "cmd.exe") + || contains(sh, "4os2.exe")) + _shell = os::CMD_EXE; + else + _shell = os::UNIX; + } + static bool initialized = false; + if (initialized) return; + initialized = true; + ULONG CPList[3] = {0}, CPList_size; + APIRET rc = DosQueryCp(3 * sizeof(ULONG), CPList, &CPList_size); + if (rc != NO_ERROR) + exit(rc); + // CPList[0] == process current codepage, + // CPList[1] == system default codepage, the rest are auxilary. + // Once cp_ is correctly set, you can call other routines. + cp_ = CPList[1]; +} + +void os::warn(string /*mesg*/) { + return; +} + +string os::current_root() { + APIRET rc; + ULONG drv_num, drv_map; + rc = DosQueryCurrentDisk(&drv_num, &drv_map); + if (rc != NO_ERROR) + exit(rc); + char drive = 'A' + drv_num -1; + string tmp(1, drive); + tmp += ":/"; + return tmp; +} + +string::size_type os::common_path(string const &p1, string const &p2) { + static bool initialized = false; + if (!initialized) { + init(0, 0); + initialized = true; + } + COUNTRYCODE cntry; + cntry.country = 0; + cntry.codepage = cp_; + string temp1 = slashify_path(p1); + string temp2 = slashify_path(p2); + char * tmp1 = const_cast (temp1.c_str()); + char * tmp2 = const_cast (temp2.c_str()); + /* rc = */ DosMapCase(p1.length(), &cntry, tmp1); + // if (rc != NO_ERROR) + // exit(rc); + /* rc = */ DosMapCase(p2.length(), &cntry, tmp2); + // if (rc != NO_ERROR) + // exit(rc); + // This algorithm works only if paths are slashified on DBCS systems. + string::size_type i = 0, + p1_len = p1.length(), + p2_len = p2.length(); + while (i < p1_len && i < p2_len && tmp1[i] == tmp2[i]) ++i; + if ((i < p1_len && i < p2_len) + || (i < p1_len && tmp1[i] != '/' && i == p2_len) + || (i < p2_len && tmp2[i] != '/' && i == p1_len)) { + if (i) --i; // here was the last match + while (i && tmp1[i] != '/') --i; + } + return i; +} + +string os::slashify_path(string p) { + static bool initialized = false; + static bool leadbyte[256] = {false}; + if (!initialized) { + init(0, 0); + COUNTRYCODE cntry; + cntry.country = 0; + cntry.codepage = cp_; + unsigned char *DBCSinfo = new unsigned char[12]; + /* rc = */ DosQueryDBCSEnv(12, &cntry, (char*) DBCSinfo); + // if (rc != NO_ERROR) + // exit(rc); + for (int j = 1; j < 12; j += 2) + DBCSinfo[j]++; + unsigned char i = 0; + bool isLeadByte = false; + while (*DBCSinfo != 0) { + if (i == *DBCSinfo) { + isLeadByte = !isLeadByte; + DBCSinfo++; + } + leadbyte[i++] = isLeadByte; + } + initialized = true; + } + string::iterator lit = p.begin(); + string::iterator end = p.end(); + for (; lit < end; ++lit) { + if (leadbyte[(*lit)]) + lit += 2; + if ((*lit) == '\\') + (*lit) = '/'; + } + p = subst(p, "//", "/"); + return p; +} + +string os::external_path(string p) { + return p; +} diff --git a/src/support/os_unix.C b/src/support/os_unix.C new file mode 100644 index 0000000000..fd02ab9934 --- /dev/null +++ b/src/support/os_unix.C @@ -0,0 +1,69 @@ +// os_unix.C + +// Various OS specific functions +#include + +#include "os.h" +#include "support/filetools.h" + +string os::binpath_ = string(); +string os::binname_ = string(); +string os::tmpdir_ = string(); +os::shell_type os::_shell = os::UNIX; +unsigned long os::cp_ = 0; + +void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ { + static bool initialized = false; + + if (initialized) + return; + + initialized = true; + string tmp = *argv[0]; + binname_ = OnlyFilename(tmp); + tmp = ExpandPath(tmp); // This expands ./ and ~/ + if (!AbsolutePath(tmp)) { + string binsearchpath = GetEnvPath("PATH"); + // This will make "src/lyx" work always :-) + binsearchpath += ";."; + tmp = FileOpenSearch(binsearchpath, tmp); + } + + tmp = MakeAbsPath(OnlyPath(tmp)); + + // In case we are running in place and compiled with shared libraries + if (suffixIs(tmp, "/.libs/")) + tmp.erase(tmp.length()-6, string::npos); + binpath_ = tmp; +} + +void os::warn(string /*mesg*/) { + return; +} + +string os::current_root() { + return string("/"); +} + +string::size_type os::common_path(string const &p1, string const &p2) { + string::size_type i = 0, + p1_len = p1.length(), + p2_len = p2.length(); + while (i < p1_len && i < p2_len && p1[i] == p2[i]) ++i; + if ((i < p1_len && i < p2_len) + || (i < p1_len && p1[i] != '/' && i == p2_len) + || (i < p2_len && p2[i] != '/' && i == p1_len)) { + if (i) --i; // here was the last match + while (i && p1[i] != '/') --i; + } + return i; +} + +string os::slashify_path(string p) { + return p; +} + +string os::external_path(string p) { + return p; +} + diff --git a/src/support/os_win32.C b/src/support/os_win32.C new file mode 100644 index 0000000000..73abf6ef2d --- /dev/null +++ b/src/support/os_win32.C @@ -0,0 +1,83 @@ +// os_win32.C copyright "Ruurd A. Reitsma" + +// Various OS specific functions +#include + +#include "os.h" +#include "support/filetools.h" + +#include +#include +#include + + +string os::binpath_ = string(); +string os::binname_ = string(); +string os::tmpdir_ = string(); +os::shell_type os::_shell = os::UNIX; +unsigned long os::cp_ = 0; + +void os::init(int * argc, char ** argv[]) { + static bool initialized = false; + if (initialized) return; + initialized = true; + string tmp = *argv[0]; + binname_ = OnlyFilename(tmp); + tmp = ExpandPath(tmp); // This expands ./ and ~/ + + if (!AbsolutePath(tmp)) { + string binsearchpath = GetEnvPath("PATH"); + // This will make "src/lyx" work always :-) + binsearchpath += ";."; + tmp = *argv[0]; + tmp = FileOpenSearch(binsearchpath, tmp); + } + + tmp = MakeAbsPath(OnlyPath(tmp)); + + // In case we are running in place and compiled with shared libraries + if (suffixIs(tmp, "/.libs/")) + tmp.erase(tmp.length()-6, string::npos); + binpath_ = tmp; +} + +void os::warn(string mesg) { + MessageBox(0, mesg.c_str(), "LyX error", + MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); + } + +string os::current_root() { + return string("/"); +} + +string::size_type os::common_path(string const &p1, string const &p2) { + string::size_type i = 0, + p1_len = p1.length(), + p2_len = p2.length(); + while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i])) ++i; + if ((i < p1_len && i < p2_len) + || (i < p1_len && p1[i] != '/' && i == p2_len) + || (i < p2_len && p2[i] != '/' && i == p1_len)) { + if (i) --i; // here was the last match + while (i && p1[i] != '/') --i; + } + return i; +} + +string os::slashify_path(string p) { + return subst(p, '\\', '/'); +} + +string os::external_path(string p) { + string dos_path=p; + if (AbsolutePath(p)) { + char dp[255]; + cygwin_conv_to_full_win32_path(p.c_str(), dp); + dos_path=subst(dp,'\\','/'); + } + lyxerr[Debug::LATEX] + << " [" + << p << "]->>[" + << dos_path << "]" << endl; + return dos_path; +} \ No newline at end of file diff --git a/src/support/rename.C b/src/support/rename.C index f6a3367062..7c079a2100 100644 --- a/src/support/rename.C +++ b/src/support/rename.C @@ -6,6 +6,9 @@ bool lyx::rename(string const & from, string const & to) { +#ifdef __EMX__ + lyx::unlink(to.c_str()); +#endif if (::rename(from.c_str(), to.c_str()) == -1) if (lyx::copy(from, to)) { lyx::unlink(from); diff --git a/src/support/syscall.C b/src/support/syscall.C index 46591cc82a..6735aad5c2 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -15,6 +15,8 @@ #include "syscontr.h" #include "support/lstrings.h" #include "support/lyxlib.h" +#include "support/filetools.h" +#include "support/os.h" using std::endl; @@ -137,8 +139,10 @@ void Systemcalls::waitForChild() { pid_t Systemcalls::fork() { + #ifndef __EMX__ pid_t cpid= ::fork(); if (cpid == 0) { // child + #endif // TODO: Consider doing all of this before the fork, otherwise me // might have troubles with multi-threaded access. (Baruch 20010228) string childcommand(command); // copy @@ -169,10 +173,15 @@ pid_t Systemcalls::fork() } argv[index] = 0; // replace by command. Expand using PATH-environment-var. +#ifndef __EMX__ execvp(syscmd, argv); // If something goes wrong, we end up here: lyxerr << "LyX: execvp failed: " << strerror(errno) << endl; } else if (cpid < 0) { // error +#else + pid_t cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND, syscmd, argv); + if (cpid < 0) { // error +#endif lyxerr << "LyX: Could not fork: " << strerror(errno) << endl; } else { // parent return cpid; @@ -193,25 +202,8 @@ int Systemcalls::startscript(Starttype how, string const & what, retval = 0; if (how == SystemDontWait) { -#ifndef __EMX__ - command += " &"; -#else - // OS/2 cmd.exe has another use for '&' - // This is not NLS safe, but it's OK, I think. - string sh = OnlyFilename(GetEnvPath("EMXSHELL")); - if (sh.empty()) { - // COMSPEC is set, unless user unsets - sh = OnlyFilename(GetEnvPath("COMSPEC")); - if (sh.empty()) - sh = "cmd.exe"; - } - sh = lowercase(sh); - if (contains(sh, "cmd.exe") - || contains(sh, "4os2.exe")) - command = "start /min/n " + command; - else - command += " &"; -#endif + (os::shell() == os::UNIX) ? command += " &" + : command = "start /min/n " + command; } return startscript(); diff --git a/src/support/tempname.C b/src/support/tempname.C index 9c7f3824fc..8a7785cc1a 100644 --- a/src/support/tempname.C +++ b/src/support/tempname.C @@ -7,10 +7,10 @@ #include "support/lyxlib.h" #include "support/filetools.h" #include "debug.h" +#include "os.h" using std::endl; -extern string system_tempdir; namespace { @@ -23,7 +23,7 @@ int make_tempfile(char * templ) #ifdef HAVE_MKTEMP // This probably just barely works... ::mktemp(templ); - return ::open(templ, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); #else #ifdef WITH_WARNINGS #warning FIX FIX FIX @@ -37,7 +37,7 @@ int make_tempfile(char * templ) string const lyx::tempName(string const & dir, string const & mask) { - string const tmpdir(dir.empty() ? system_tempdir : dir); + string const tmpdir(dir.empty() ? os::getTmpDir() : dir); string tmpfl(AddName(tmpdir, mask)); tmpfl += tostr(getpid()); tmpfl += "XXXXXX";