From 1fc767159174b183bc8356728b194f1f73e3b3e8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 11 May 2000 16:12:46 +0000 Subject: [PATCH] Remove the optional bool argument to ChangeExtension(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@730 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 12 +++ README.OS2 | 71 +++++++++++++++ development/OS2/quick_fix.patch | 155 ++++++++++++++++++++++++++++++++ src/Chktex.C | 4 +- src/ImportLaTeX.C | 2 +- src/LaTeX.C | 40 +++++---- src/LaTeXLog.C | 7 +- src/LyXSendto.C | 2 +- src/buffer.C | 18 ++-- src/bufferlist.C | 3 +- src/insets/insetbib.C | 12 ++- src/insets/insetinclude.C | 8 +- src/lyx_cb.C | 42 ++++----- src/lyxfunc.C | 6 +- src/support/filetools.C | 13 +-- src/support/filetools.h | 4 +- 16 files changed, 316 insertions(+), 83 deletions(-) create mode 100644 development/OS2/quick_fix.patch diff --git a/ChangeLog b/ChangeLog index 6978d652e1..5553394acf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ +2000-05-11 Jean-Marc Lasgouttes + + * add addendum to README.OS2 and small patch (from SMiyata) + 2000-05-10 Jean-Marc Lasgouttes + * many files: correct the calls to ChangeExtension(). + + * src/support/filetools.C (ChangeExtension): remove the no_path + argument, which does not belong there. Use OnlyFileName() instead. + + * src/insets/insetbib.C (Latex): use absolute paths for bibtex + files when LaTeXing a non-nice latex file. + * src/lyxlookup.C (isDeadEvent): use a switch statement instead of a chain of "if". Return false when deadkeys are not handled. diff --git a/README.OS2 b/README.OS2 index 4491efd1e4..895baf6aff 100644 --- a/README.OS2 +++ b/README.OS2 @@ -1,3 +1,74 @@ +These are temporary instructions from Shigeru Miyata +=========================================================================== + +(The top level) configure.cmd is obsoleted by. Please follow the +step like this: + +1. Install GNU m4, gnu?utils, aclocal/2, autoheader/2, automake/2, + autoconf/2, perl, GNU patch and a UNIX type shell like pdksh. +2. Apply the patch development/OS2/quick_fix.patch + // os2_defines.h needs a modification because bmtable.c is C. + // Now it hits me, why don't we patch "test -x" (gnufutils)? + // However, we can't modify the behavior of "test -f", so + // it is still necessary to modify script files for LyX. +3. Install xforms 0.88 and rename + forms.a -> forms_d.a + forms_s.a -> forms.a + // Ever since 1.1.5pre1, you cannot link xforms dynamically. + // If you don't like this, please ask Holger Veit to export + // fl_get_scrollbar_bounds, fl_get_scrollbar_increment and + // fl_get_scrollbar_value from the DLL. They're already there! +4. Install Hung-Chi Chu's port of GNU gettext. Other ports will + not work. +5. Set environment variables + MAKE_SHELL=sh + LIBS=-lulib -lsocket -lbsd -lshm -lstdcpp + // ulib must be linked if we use static xforms library. + // Unless you are using pgcc, we use gcc rather than g++. + // Hence stdc++ must be linked explicitely. Also please + // note that ld for pgcc often fails to link big executables + // like unstripped lyx.exe +6. From sh prompt, type + autogen.sh + and then + configure --prefix=/XFree86 --datadir=/XFree86/lib/X11 + x11make + // Please do not use make.cmd make.exe should be OK. + // x11make.exe is the safest choice + // While you are running configure, make sure that it is not + // a background process to other CPU intensive processes. + // While OS/2 kernel is much more efficient, faster and + // more responsive than other systems like LINUX (you can + // easily *FEEL* this if you stop PM/WPS and run XFree86 + // only), its TTY interface is lousy, to say the least. + // If the synchronization to the children breaks, configure + // often detects wrongfully. + +> Or it is possible to download the compiled program? + +7. If you are going to make a binary distribution, you have + to prepare lib/configure.cmd noweb2lyx.cmd and reLyX.cmd, + since end users may not have a UNIX type shell installed. + At this stage, lib/configure.cmd in the 1.1.5pre1 should work + without change. + // If Dekel Tsur introduces the converter_command tag to lyxrc, + // the situation changes. + In order to create noweb2lyx.cmd and reLyX.cmd, first rename + noweb2lyx and reLyX and open them in a text editor. You + have to remove hardcoded path in the first line: +#!perl + Also in reLyX.cmd, $lyxdir should be changed to include the + drive letter (the line 21): +$lyxdir = "$ENV{X11ROOT}/XFree86/lib/X11/lyx"; + Finally, prepend a line +extproc perl.exe -S + so that cmd.exe pass the execution control to perl. + // I know configure.cmd had done this automatically. + // So you can compare the result with the scripts in 1.0.4 + // distribution. + + +=========================================================================== README file for OS/2 version of LyX 1.0.1 by Shigeru Miyata diff --git a/development/OS2/quick_fix.patch b/development/OS2/quick_fix.patch new file mode 100644 index 0000000000..5ea8b436fb --- /dev/null +++ b/development/OS2/quick_fix.patch @@ -0,0 +1,155 @@ +diff -ubr -X g:/exclude lyx-devel/config/progtest.m4 lyx-build/config/progtest.m4 +--- lyx-devel/config/progtest.m4 Tue Feb 22 06:44:28 2000 ++++ lyx-build/config/progtest.m4 Wed May 10 10:12:44 2000 +@@ -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_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 -ubr -X g:/exclude lyx-devel/lib/configure.m4 lyx-build/lib/configure.m4 +--- lyx-devel/lib/configure.m4 Tue Feb 22 06:44:42 2000 ++++ lyx-build/lib/configure.m4 Wed May 10 07:24:02 2000 +@@ -28,6 +28,19 @@ + dnl + define(SEARCH_PROG,[dnl + changequote([,])dnl ++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 + MSG_CHECKING($1) + MSG_RESULT(($3)) + $2= +@@ -37,10 +50,12 @@ + set dummy $ac_prog ; ac_word=$[2] + if test -n "$ac_word"; then + MSG_CHECKING([for \"$ac_word\"],[+]) +- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ++ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="$PATH_IFS" + for ac_dir in $PATH; do + test -z "$ac_dir" && ac_dir=. +- if test -x [$ac_dir/$ac_word]; then ++ if test -x [$ac_dir/$ac_word] \ ++ -o -x [$ac_dir/$ac_word$EXE_EXT] \ ++ -o -x [$ac_dir/$ac_word$CMD_EXT]; then + $2="$ac_prog" + break + fi +@@ -179,8 +194,17 @@ + fi + + # Search for an installed reLyX or a ready-to-install one ++case "`uname -s 2> /dev/null`" in ++OS/2) ++save_PATH=`echo -E "$PATH" | sed 's+\\\\+/+g'` ++PATH_IFS=';' ++;; ++*) + save_PATH=${PATH} +-PATH=${PATH}:./reLyX/ ++PATH_IFS=':' ++;; ++esac ++PATH=${PATH}${PATH_IFS}./reLyX/ + SEARCH_PROG([for reLyX LaTeX-to-LyX translator],RELYX,reLyX) + PATH=${save_PATH} + +diff -ubr -X g:/exclude lyx-devel/lib/reLyX/acinclude.m4 lyx-build/lib/reLyX/acinclude.m4 +--- lyx-devel/lib/reLyX/acinclude.m4 Tue Sep 28 03:44:34 1999 ++++ lyx-build/lib/reLyX/acinclude.m4 Wed May 10 05:38:36 2000 +@@ -11,15 +11,24 @@ + 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 -ubr -X g:/exclude lyx-devel/lib/reLyX/configure.in lyx-build/lib/reLyX/configure.in +--- lyx-devel/lib/reLyX/configure.in Tue Feb 22 06:45:24 2000 ++++ lyx-build/lib/reLyX/configure.in Wed May 10 05:38:34 2000 +@@ -2,6 +2,7 @@ + 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 -ubr -X g:/exclude lyx-devel/src/os2_defines.h lyx-build/src/os2_defines.h +--- lyx-devel/src/os2_defines.h Fri Mar 10 06:25:50 2000 ++++ lyx-build/src/os2_defines.h Fri May 5 11:37:48 2000 +@@ -13,9 +13,14 @@ + #ifndef OS2_DEFINES_H + #define OS2_DEFINES_H + ++#if defined (__cplusplus) + #include +-#include + #include ++#else ++#include ++#include ++#endif ++#include + #include + #include + /* #include */ diff --git a/src/Chktex.C b/src/Chktex.C index 0dab6668c3..87a8c18972 100644 --- a/src/Chktex.C +++ b/src/Chktex.C @@ -47,7 +47,7 @@ Chktex::Chktex(string const & chktex, string const & f, string const & p) int Chktex::run(TeXErrors &terr) { // run bibtex - string log = ChangeExtension(file, ".log", true); + string log = OnlyFilename(ChangeExtension(file, ".log")); string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log; Systemcalls one; int result= one.startscript(Systemcalls::System, tmp); @@ -65,7 +65,7 @@ int Chktex::scanLogFile(TeXErrors & terr) string token; int retval = 0; - string tmp = ChangeExtension(file, ".log", true); + string tmp = OnlyFilename(ChangeExtension(file, ".log")); ifstream ifs(tmp.c_str()); while (getline(ifs, token)) { diff --git a/src/ImportLaTeX.C b/src/ImportLaTeX.C index 0ada1dc76f..acafd3b822 100644 --- a/src/ImportLaTeX.C +++ b/src/ImportLaTeX.C @@ -43,7 +43,7 @@ Buffer * ImportLaTeX::run() Buffer * buf = 0; int result = one.startscript(Systemcalls::System, tmp); if (result == 0) { - string filename = ChangeExtension(file, ".lyx", false); + string filename = ChangeExtension(file, ".lyx"); // File was generated without problems. Load it. buf = bufferlist.loadLyXFile(filename); } diff --git a/src/LaTeX.C b/src/LaTeX.C index 951e5c91e0..310cc49ec3 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -110,16 +110,18 @@ void LaTeX::deleteFilesOnError() const // but the reason for the error might be in a generated file... + string ofname = OnlyFilename(file); + // bibtex file - string bbl = ChangeExtension(file, ".bbl", true); + string bbl = ChangeExtension(ofname, ".bbl"); ::unlink(bbl.c_str()); // makeindex file - string ind = ChangeExtension(file, ".ind", true); + string ind = ChangeExtension(ofname, ".ind"); ::unlink(ind.c_str()); // Also remove the aux file - string aux = ChangeExtension(file, ".aux", true); + string aux = ChangeExtension(ofname, ".aux"); ::unlink(aux.c_str()); } @@ -222,12 +224,12 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // if needed. // run makeindex - if (head.haschanged(ChangeExtension(file, ".idx", true))) { + if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) { // no checks for now lyxerr[Debug::LATEX] << "Running MakeIndex." << endl; minib->Set(_("Running MakeIndex.")); minib->Store(); - rerun = runMakeIndex(ChangeExtension(file, ".idx", true)); + rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx"))); } // run bibtex @@ -241,7 +243,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) lyxerr[Debug::LATEX] << "Running BibTeX." << endl; minib->Set(_("Running BibTeX.")); minib->Store(); - rerun = runBibTeX(ChangeExtension(file, ".aux", true), head); + rerun = runBibTeX(OnlyFilename(ChangeExtension(file, ".aux")), + head); } // 1 @@ -288,12 +291,12 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // more after this. // run makeindex if the .idx has changed or was generated. - if (head.haschanged(ChangeExtension(file, ".idx", true))) { + if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) { // no checks for now lyxerr[Debug::LATEX] << "Running MakeIndex." << endl; minib->Set(_("Running MakeIndex.")); minib->Store(); - rerun = runMakeIndex(ChangeExtension(file, ".idx", true)); + rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx"))); } // 2 @@ -370,7 +373,7 @@ bool LaTeX::scanAux(DepTable & dep) if (dep.extchanged(".bib") || dep.extchanged(".bst")) return true; - string aux = ChangeExtension(file, ".aux", true); + string aux = OnlyFilename(ChangeExtension(file, ".aux")); ifstream ifs(aux.c_str()); string token; LRegex reg1("\\\\bibdata\\{([^}]+)\\}"); @@ -392,7 +395,7 @@ bool LaTeX::scanAux(DepTable & dep) } string full_l = findtexfile( - ChangeExtension(l, "bib", false), "bib"); + ChangeExtension(l, "bib"), "bib"); if (!full_l.empty()) { if (!dep.exist(full_l)) return true; @@ -406,7 +409,7 @@ bool LaTeX::scanAux(DepTable & dep) // pass it to the helper string full_l = findtexfile( - ChangeExtension(style, "bst", false), + ChangeExtension(style, "bst"), "bst"); if (!full_l.empty()) { if (!dep.exist(full_l)) @@ -450,7 +453,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) } string full_l = findtexfile( - ChangeExtension(l, "bib", false), + ChangeExtension(l, "bib"), "bib"); lyxerr[Debug::LATEX] << "Bibtex database: `" << full_l << "'" << endl; @@ -468,7 +471,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) // pass it to the helper string full_l = findtexfile( - ChangeExtension(style, "bst", false), + ChangeExtension(style, "bst"), "bst"); lyxerr[Debug::LATEX] << "Bibtex style: `" << full_l << "'" << endl; @@ -481,7 +484,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) if (using_bibtex) { // run bibtex and string tmp = "bibtex "; - tmp += ChangeExtension(file, string(), true); + tmp += OnlyFilename(ChangeExtension(file, string())); Systemcalls one; one.startscript(Systemcalls::System, tmp); return true; @@ -496,7 +499,7 @@ int LaTeX::scanLogFile(TeXErrors & terr) int last_line = -1; int line_count = 1; int retval = NO_ERRORS; - string tmp = ChangeExtension(file, ".log", true); + string tmp = OnlyFilename(ChangeExtension(file, ".log")); lyxerr[Debug::LATEX] << "Log file: " << tmp << endl; ifstream ifs(tmp.c_str()); @@ -615,7 +618,7 @@ void LaTeX::deplog(DepTable & head) // files used by the LaTeX run. The files are then entered into the // dependency file. - string logfile = ChangeExtension(file, ".log", true); + string logfile = OnlyFilename(ChangeExtension(file, ".log")); ifstream ifs(logfile.c_str()); while (ifs) { @@ -694,9 +697,8 @@ void LaTeX::deptex(DepTable & head) FileInfo fi; for (int i = 0; i < file_count; ++i) { if (!(all_files[i].file & except)) { - tmp = ChangeExtension(file, - all_files[i].extension, - true); + tmp = OnlyFilename(ChangeExtension(file, + all_files[i].extension)); lyxerr[Debug::DEPEND] << "deptex: " << tmp << endl; if (fi.newFile(tmp).exist()) head.insert(tmp); diff --git a/src/LaTeXLog.C b/src/LaTeXLog.C index e5b0d0e561..a79a05c637 100644 --- a/src/LaTeXLog.C +++ b/src/LaTeXLog.C @@ -24,10 +24,9 @@ void ShowLatexLog() filename = current_view->buffer()->getLatexName(); if (!filename.empty()) { - fname = ChangeExtension(filename, ".log", true); - bname = ChangeExtension(filename, - lyxrc.literate_extension + ".out", - true); + fname = OnlyFilename(ChangeExtension(filename, ".log")); + bname = OnlyFilename(ChangeExtension(filename, + lyxrc.literate_extension + ".out")); path = OnlyPath(filename); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->buffer()->tmppath; diff --git a/src/LyXSendto.C b/src/LyXSendto.C index 0ef41824f1..2730d26663 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -81,7 +81,7 @@ void SendtoApplyCB(FL_OBJECT *, long) } } - string fname = ChangeExtension(buffer->getLatexName(), ftypeext, true); + string fname = OnlyFilename(ChangeExtension(buffer->getLatexName(), ftypeext)); if (!contains(command, "$$FName")) command = "( " + command + " ) <$$FName"; command = subst(command, "$$FName", fname); diff --git a/src/buffer.C b/src/buffer.C index 46471e97dd..5ad15c8fea 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -157,8 +157,12 @@ Buffer::~Buffer() string Buffer::getLatexName(bool no_path) const { - return ChangeExtension(MakeLatexName(filename), - ".tex", no_path); + if (no_path) + return OnlyFilename(ChangeExtension(MakeLatexName(filename), + ".tex")); + else + return ChangeExtension(MakeLatexName(filename), + ".tex"); } @@ -3285,8 +3289,8 @@ int Buffer::runLiterate() // get LaTeX-Filename string name = getLatexName(); // get Literate-Filename - string lit_name = ChangeExtension (getLatexName(), - lyxrc.literate_extension, true); + string lit_name = OnlyFilename(ChangeExtension (getLatexName(), + lyxrc.literate_extension)); string path = OnlyPath(filename); @@ -3356,8 +3360,8 @@ int Buffer::buildProgram() // get LaTeX-Filename string name = getLatexName(); // get Literate-Filename - string lit_name = ChangeExtension(getLatexName(), - lyxrc.literate_extension, true); + string lit_name = OnlyFilename(ChangeExtension(getLatexName(), + lyxrc.literate_extension)); string path = OnlyPath(filename); @@ -3727,7 +3731,7 @@ string Buffer::getIncludeonlyList(char delim) && insetinc->isNoLoad()) { if (!lst.empty()) lst += delim; - lst += ChangeExtension(insetinc->getContents(), string(), true); + lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string())); } } ++pos; diff --git a/src/bufferlist.C b/src/bufferlist.C index e4497ba234..68be219fdd 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -225,8 +225,7 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir) if (!(*it)->isDepClean(mastertmpdir)) { string writefile = mastertmpdir; writefile += '/'; - writefile += ChangeExtension((*it)->fileName(), - ".tex", true); + writefile += (*it)->getLatexName(); (*it)->makeLaTeXFile(writefile, mastertmpdir, false, true); (*it)->markDepClean(mastertmpdir); diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index fa7c450341..d9dcfed3b6 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -339,9 +339,13 @@ int InsetBibtex::Latex(ostream & os, string db_in = getContents(); db_in = split(db_in, adb, ','); while(!adb.empty()) { - if (!owner->niceFile && - IsFileReadable(MakeAbsPath(adb, owner->filepath)+".bib")) - adb = MakeAbsPath(adb, owner->filepath); + if (!owner->niceFile) { + string fname + = findtexfile(ChangeExtension(adb, "bib"), + "bib"); + if (!fname.empty()) + adb = ChangeExtension(fname, string()); + } db_out += adb; db_out += ','; db_in= split(db_in, adb,','); @@ -379,7 +383,7 @@ string InsetBibtex::getKeys(char delim) string bibfiles = getContents(); bibfiles = split(bibfiles, tmp, ','); while(!tmp.empty()) { - string fil = findtexfile(ChangeExtension(tmp, "bib", false), + string fil = findtexfile(ChangeExtension(tmp, "bib"), "bib"); lyxerr[Debug::LATEX] << "Bibfile: " << fil << endl; // If we didn't find a matching file name just fail silently diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 1d28e3347b..edba5fac3c 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -358,7 +358,7 @@ int InsetInclude::Latex(ostream & os, } // write it to a file (so far the complete file) - string writefile = ChangeExtension(getFileName(), ".tex", false); + string writefile = ChangeExtension(getFileName(), ".tex"); if (!master->tmppath.empty() && !master->niceFile) { incfile = subst(incfile, '/','@'); @@ -368,7 +368,7 @@ int InsetInclude::Latex(ostream & os, writefile = AddName(master->tmppath, incfile); } else writefile = getFileName(); - writefile = ChangeExtension(writefile, ".tex", false); + writefile = ChangeExtension(writefile, ".tex"); lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -388,14 +388,14 @@ int InsetInclude::Latex(ostream & os, os << '\\' << command << '{' << incfile << '}'; } else { os << '\\' << command << '{' - << ChangeExtension(incfile, ".tex", false) + << ChangeExtension(incfile, ".tex") << '}'; } } else { // \include don't want extension and demands that the // file really have .tex os << '\\' << command << '{' - << ChangeExtension(incfile, string(), false) + << ChangeExtension(incfile, string()) << '}'; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 7ba99c9ecd..e11d0b9a99 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -431,8 +431,7 @@ bool RunScript(Buffer * buffer, bool wait, return false; /* get DVI-Filename */ if (name.empty()) - name = ChangeExtension(buffer->getLatexName(), - ".dvi", true); + name = ChangeExtension(buffer->getLatexName(), ".dvi"); path = OnlyPath(name); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { @@ -508,8 +507,8 @@ bool CreatePostscript(Buffer * buffer, bool wait = false) return false; } // Generate postscript file - string psname = ChangeExtension (buffer->fileName(), - ".ps_tmp", true); + string psname = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); string paper; @@ -596,8 +595,8 @@ bool PreviewPostscript(Buffer * buffer) // Start postscript viewer ProhibitInput(current_view); - string ps = ChangeExtension (buffer->fileName(), - ".ps_tmp", true); + string ps = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); // push directorypath, if necessary string path = OnlyPath(buffer->fileName()); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){ @@ -622,7 +621,8 @@ void MenuFax(Buffer * buffer) } // Send fax - string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true); + string ps = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); string path = OnlyPath (buffer->fileName()); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; @@ -757,8 +757,7 @@ void MenuMakeLinuxDoc(Buffer * buffer) } // Get LinuxDoc-Filename - string s = ChangeExtension(buffer->fileName(), - ".sgml", false); + string s = ChangeExtension(buffer->fileName(), ".sgml"); if (!AskOverwrite(buffer, s)) return; @@ -785,8 +784,7 @@ void MenuMakeDocBook(Buffer * buffer) } // Get DocBook-Filename - string s = ChangeExtension(buffer->fileName(), - ".sgml", false); + string s = ChangeExtension(buffer->fileName(), ".sgml"); if (!AskOverwrite(buffer, s)) return; @@ -807,8 +805,7 @@ void MenuMakeAscii(Buffer * buffer) //if (!bv->text) return; /* get LaTeX-Filename */ - string s = ChangeExtension (buffer->fileName(), - ".txt", false); + string s = ChangeExtension (buffer->fileName(), ".txt"); if (!AskOverwrite(buffer, s)) @@ -826,9 +823,8 @@ void MenuPrint(Buffer * buffer) //if (!bv->text) // return; - string input_file = ChangeExtension(buffer->fileName(), - lyxrc.print_file_extension, - true); + string input_file = OnlyFilename(ChangeExtension(buffer->fileName(), + lyxrc.print_file_extension)); fl_set_input(fd_form_print->input_file, input_file.c_str()); if (fd_form_print->form_print->visible) { @@ -853,7 +849,7 @@ void MenuMakeHTML(Buffer * buffer) // the tex file name has to be correct for // latex, but the html file name can be // anything. - string result = ChangeExtension(file, ".html", false); + string result = ChangeExtension(file, ".html"); string infile = buffer->getLatexName(false); string tmp = lyxrc.html_command; tmp = subst(tmp, "$$FName", infile); @@ -880,8 +876,8 @@ void MenuMakeHTML_LinuxDoc(Buffer * buffer) // And now, run the converter string file = buffer->fileName(); - string result = ChangeExtension(file, ".html", false); - string infile = ChangeExtension(file, ".sgml", false); + string result = ChangeExtension(file, ".html"); + string infile = ChangeExtension(file, ".sgml"); string tmp = lyxrc.linuxdoc_to_html_command; tmp = subst(tmp, "$$FName", infile); tmp = subst(tmp, "$$OutName", result); @@ -905,8 +901,8 @@ void MenuMakeHTML_DocBook(Buffer * buffer) // And now, run the converter string file = buffer->fileName(); - string result = ChangeExtension(file, ".html", false); - string infile = ChangeExtension(file, ".sgml", false); + string result = ChangeExtension(file, ".html"); + string infile = ChangeExtension(file, ".sgml"); string tmp = lyxrc.docbook_to_html_command; tmp = subst(tmp, "$$FName", infile); tmp = subst(tmp, "$$OutName", result); @@ -1269,7 +1265,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) int errorcode = 0; /* generate a path-less extension name */ - string name = ChangeExtension (filename, ".sgml", true); + string name = OnlyFilename(ChangeExtension (filename, ".sgml")); string path = OnlyPath (filename); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = bv->buffer()->tmppath; @@ -1330,7 +1326,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) int RunDocBook(int flag, string const & filename) { /* generate a path-less extension name */ - string name = ChangeExtension (filename, ".sgml", true); + string name = OnlyFilename(ChangeExtension (filename, ".sgml")); string path = OnlyPath (filename); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->buffer()->tmppath; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index f287f9b2ac..9a67ca8810 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -2108,7 +2108,7 @@ string LyXFunc::Dispatch(int ac, sscanf(argument.c_str(), " %s %d", file_name, &row); // Must replace extension of the file to be .lyx and get full path - string s = ChangeExtension(string(file_name), ".lyx", false); + string s = ChangeExtension(string(file_name), ".lyx"); // Either change buffer or load the file if (bufferlist.exists(s)) @@ -2845,7 +2845,7 @@ void LyXFunc::doImportHelper( // get absolute path of file filename = MakeAbsPath(filename); - string lyxfile = ChangeExtension(filename, ".lyx", false); + string lyxfile = ChangeExtension(filename, ".lyx"); // Check if the document already is open if (bufferlist.exists(lyxfile)) { @@ -2933,7 +2933,7 @@ bool doImportLinuxDoc(BufferView *, string const & filename) int result = one.startscript(Systemcalls::System, tmp); if (result == 0) { - string filename = ChangeExtension(filename, ".lyx", false); + string filename = ChangeExtension(filename, ".lyx"); // File was generated without problems. Load it. buf = bufferlist.loadLyXFile(filename); } diff --git a/src/support/filetools.C b/src/support/filetools.C index 1b2af682fa..33b0d1a70c 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -892,8 +892,7 @@ string AddPath(string const & path, string const & path_2) Strips path off if no_path == true. If no extension on oldname, just appends. */ -string ChangeExtension(string const & oldname, string const & extension, - bool no_path) +string ChangeExtension(string const & oldname, string const & extension) { string::size_type last_slash = oldname.rfind('/'); string::size_type last_dot = oldname.rfind('.'); @@ -906,14 +905,8 @@ string ChangeExtension(string const & oldname, string const & extension, ext= '.' + extension; else ext = extension; - string ret_str; - if (no_path && last_slash != string::npos) { - ++last_slash; // step it - ret_str = oldname.substr(last_slash, - last_dot - last_slash) + ext; - } else - ret_str = oldname.substr(0, last_dot) + ext; - return CleanupPath(ret_str); + + return CleanupPath(oldname.substr(0, last_dot) + ext); } diff --git a/src/support/filetools.h b/src/support/filetools.h index ca549b518c..ade432f04c 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -131,12 +131,10 @@ string AddName(string const & path, string const & fname); string AddPath(string const & path, string const & path2); /** Change extension of oldname to extension. - If no_path is true, the path is stripped from the filename. If oldname does not have an extension, it is appended. If the extension is empty, any extension is removed from the name. */ -string ChangeExtension(string const & oldname, string const & extension, - bool no_path); +string ChangeExtension(string const & oldname, string const & extension); /// Create absolute path. If impossible, don't do anything string ExpandPath(string const & path); -- 2.39.2