From: Georg Baum Date: Wed, 24 May 2006 20:06:42 +0000 (+0000) Subject: From Joost Verburg: Put the clean_dvi.py script into the main distribution X-Git-Tag: 1.6.10~13195 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f0f4e2c04291c9a3590eae64234790623a4f06e7;p=features.git From Joost Verburg: Put the clean_dvi.py script into the main distribution * lib/configure.py (checkLatex): Add DraftDVI converter on windows if dv2dt and dt2dv are available (checkFormatEntries): Add DraftDVI entry on windows if dv2dt and dt2dv are available * lib/Makefile.am: add clean_dvi.py * development/Win32/packaging/build_lyxwin.sh: remove clean_dvi.py stuff * development/Win32/packaging/package_lyxwin.sh: remove configure mangling for clean_dvi.py * development/Win32/packaging/clean_dvi.py: move to lib/scripts * development/Win32/packaging/README: remove clean_dvi.py stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13924 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/Win32/packaging/README b/development/Win32/packaging/README index f4c4a41b99..de117bf226 100644 --- a/development/Win32/packaging/README +++ b/development/Win32/packaging/README @@ -24,12 +24,8 @@ the process: * Strip the binaries in $PREFIX/bin/ of all debugging info. -* Copy dt2dv.exe and dv2dt.exe to $PREFIX/bin/ and clean_dvi.py to - $PREFIX/Resources/scripts/ These are needed to enable dvips, yap - et al. to cope with "file names with spaces". - -* Add formats and converters to the $PREFIX/Resources/configure - script so that users can use the clean_dvi script transparently. +* Copy dt2dv.exe and dv2dt.exe to $PREFIX/bin/. These are needed to enable + dvips, yap et al. to cope with "file names with spaces". * Remove all stuff generated by running configure. It makes sense on your machine only, not for whoever is installing LyX. Specifically diff --git a/development/Win32/packaging/build_lyxwin.sh b/development/Win32/packaging/build_lyxwin.sh index 79dcb95599..891bcf363c 100644 --- a/development/Win32/packaging/build_lyxwin.sh +++ b/development/Win32/packaging/build_lyxwin.sh @@ -12,7 +12,7 @@ # It asks whether the Qt and LyX cvs trees are up to date. # It asks whether the Qt library has been compiled. -# It checks that qt-mt3.dll, mingw10.dll and clean_dvi.py exist. +# It checks that qt-mt3.dll and mingw10.dll exist. # It compiles the dv2dt and dt2dv utilites. # It compiles and installs LyX. @@ -30,7 +30,6 @@ QT_DIR="${HOME}"/Qt/3x-msys LYX_DIR="../../.." PACKAGING_DIR="$LYX_DIR/development/Win32/packaging" DTL_DIR="$PACKAGING_DIR/dtl" -CLEAN_DVI_DIR="$PACKAGING_DIR" ASPELL_INSTALL_DIR="c:/Aspell" LYX_ASPELL_DIR="/c/Aspell" # the Autotools don't like "C:/" syntax. @@ -43,7 +42,6 @@ MINGW_DLL="${MINGW_DIR}/bin/mingwm10.dll" DT2DV="${DTL_DIR}/dt2dv.exe" DV2DT="${DTL_DIR}/dv2dt.exe" -CLEAN_DVI_PY="${CLEAN_DVI_DIR}/clean_dvi.py" # Change this to 'mv -f' when you are confident that # the various sed scripts are working correctly. @@ -72,8 +70,8 @@ query_qt() check_files_exist() { - # Check that the dlls and clean_dvi.py exist - for file in "${QT_DLL}" "${MINGW_DLL}" "${CLEAN_DVI_PY}" + # Check that the dlls exist + for file in "${QT_DLL}" "${MINGW_DLL}" do test -r "${file}" || { echo "$file does not exist" >&2 diff --git a/development/Win32/packaging/clean_dvi.py b/development/Win32/packaging/clean_dvi.py deleted file mode 100644 index 39fde890d2..0000000000 --- a/development/Win32/packaging/clean_dvi.py +++ /dev/null @@ -1,106 +0,0 @@ -#! /usr/bin/env python - -''' -file clean_dvi.py -This file is part of LyX, the document processor. -Licence details can be found in the file COPYING -or at http://www.lyx.org/about/licence.php3 - -author Angus Leeming -Full author contact details are available in the file CREDITS -or at http://www.lyx.org/about/credits.php - -Usage: - python clean_dvi.py infile.dvi outfile.dvi - -clean_dvi modifies the input .dvi file so that -dvips and yap (a dvi viewer on Windows) can find -any embedded PostScript files whose names are protected -with "-quotes. - -It works by: -1 translating the machine readable .dvi file to human - readable .dtl form, -2 manipulating any references to external files -3 translating the .dtl file back to .dvi format. - -It requires dv2dt and dt2dv from the DTL dviware package -http://www.ctan.org/tex-archive/dviware/dtl/ -''' - -import os, re, sys - -def usage(prog_name): - return 'Usage: %s in.dvi out.dvi\n' \ - % os.path.basename(prog_name) - - -def warning(message): - sys.stderr.write(message + '\n') - - -def error(message): - sys.stderr.write(message + '\n') - sys.exit(1) - - -def manipulated_dtl(data): - psfile_re = re.compile(r'(special1 +)([0-9]+)( +\'PSfile=")(.*)(" llx=.*)') - - lines = data.split('\n') - for i in range(len(lines)): - line = lines[i] - match = psfile_re.match(line) - if match != None: - file = match.group(4) - filelen = len(file) - file = file.replace('"', '') - # Don't forget to update the length of the string too... - strlen = int(match.group(2)) - (filelen - len(file)) - - lines[i] = '%s%d%s%s%s' \ - % ( match.group(1), strlen, match.group(3), - file, match.group(5) ) - - return '\n'.join(lines) - - -def main(argv): - # First establish that the expected information has - # been input on the command line and whether the - # required executables exist. - if len(argv) != 3: - error(usage(argv[0])) - - infile = argv[1] - outfile = argv[2] - - if not os.path.exists(infile): - error('Unable to read "%s"\n' % infile) - - # Convert the input .dvi file to .dtl format. - dv2dt_call = 'dv2dt "%s"' % infile - dv2dt_stdin, dv2dt_stdout, dv2dt_stderr = \ - os.popen3(dv2dt_call, 't') - - dv2dt_stdin.close() - dv2dt_data = dv2dt_stdout.read() - dv2dt_status = dv2dt_stdout.close() - - if dv2dt_status != None or len(dv2dt_data) == 0: - dv2dt_err = dv2dt_stderr.read() - error("Failed: %s\n%s\n" % ( dv2dt_call, dv2dt_err) ) - - # Manipulate the .dtl file. - dtl_data = manipulated_dtl(dv2dt_data) - if dtl_data == None: - error("Failed to manipulate the dtl file") - - # Convert this .dtl file back to .dvi format. - dt2dv_call = 'dt2dv -si "%s"' % outfile - dt2dv_stdin = os.popen(dt2dv_call, 'w') - dt2dv_stdin.write(dtl_data) - - -if __name__ == "__main__": - main(sys.argv) diff --git a/development/Win32/packaging/package_lyxwin.sh b/development/Win32/packaging/package_lyxwin.sh index 14730c6050..5a20d2890f 100644 --- a/development/Win32/packaging/package_lyxwin.sh +++ b/development/Win32/packaging/package_lyxwin.sh @@ -7,7 +7,6 @@ # qt-mt3.dll # iconv.dll # mingw10.dll -# clean_dvi.py # dv2dt.exe # dt2dv.exe @@ -28,7 +27,6 @@ QT_DLL="$HOME/Qt/3x-msys/bin/qt-mt3.dll" ICONV_DLL="/j/MinGW/bin/iconv.dll" MINGW_DLL="/j/MinGW/bin/mingwm10.dll" -CLEAN_DVI_PY="clean_dvi.py" DTL_DIR=dtl DT2DV="$DTL_DIR/dt2dv.exe" DV2DT="$DTL_DIR/dv2dt.exe" @@ -41,7 +39,7 @@ MV='mv -f' windows_packaging() { - # Install the necessary .dlls and clean_dvi stuff. + # Install the necessary .dlls. for file in "${QT_DLL}" "${ICONV_DLL}" "${MINGW_DLL}" "${DT2DV}" "${DV2DT}" do cp "${file}" "$LYX_INSTALL_DIR"/bin/. || { @@ -50,11 +48,6 @@ windows_packaging() } done - cp "${CLEAN_DVI_PY}" "$LYX_INSTALL_DIR"/Resources/scripts/. || { - echo "Failed to copy ${CLEAN_DVI_PY} to the LyX package" >&2 - exit 1 - } - # Strip the executables ( cd "${LYX_INSTALL_DIR}/bin" @@ -64,36 +57,6 @@ windows_packaging() done ) - # Modify the configure script, - # * add a dvi2 format - # * change the latex->dvi converter to latex->dvi2 - # * add a dvi2->dvi converter - # * fix the generated chkconfig.sed so that it works with versions of - # sed that get confused by sed scripts with DOS line endings. - TMP=tmp.$$ - CONFIGURE="${LYX_INSTALL_DIR}"/Resources/configure - # Do this to make it easy to compare the before and after files. - dos2unix "${CONFIGURE}" - sed ' -# (Note that this sed script contains TAB characters.) -# Append the dvi2 format after the dvi format. -/^ *\\\\Format[ ]\{1,\}dvi[ ]\{1,\}/a\ -\\\\Format dvi2 dvi DraftDVI "" - -# Change the latex->dvi converter to latex->dvi2 -# and append the dvi2->dvi converter -/^ *\\\\converter[ ]\{1,\}latex[ ]\{1,\}dvi[ ]\{1,\}/{ -s/dvi/dvi2/ -a\ -\\\\converter dvi2 dvi "python \\\$\\\$s/scripts/clean_dvi.py \\\$\\\$i \\\$\\\$o" "" -} -' "${CONFIGURE}" > "${TMP}" - cmp -s "${CONFIGURE}" "${TMP}" || { - diff -u "${CONFIGURE}" "${TMP}" - ${MV} "${TMP}" "${CONFIGURE}" - } - rm -f "${TMP}" - # Strip the executables ( cd "${LYX_INSTALL_DIR}/Resources" diff --git a/lib/Makefile.am b/lib/Makefile.am index c52c9b39b7..17aa1f285a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -878,6 +878,7 @@ scriptsdir = $(pkgdatadir)/scripts # in install-data-hook. dist_scripts_DATA = \ scripts/TeXFiles.sh \ + scripts/clean_dvi.py \ scripts/convertDefault.sh \ scripts/fen2ascii.py \ scripts/fig2pdftex.sh \ diff --git a/lib/configure.py b/lib/configure.py index bdcde5ae78..80b4535116 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -168,8 +168,17 @@ def checkProg(description, progs, rc_entry = [], path = [] ): def checkLatex(): ''' Check latex, return lyx_check_config ''' # Find programs! Returned path is not used now - path, LATEX = checkProg( 'a Latex2e program', ['pplatex $$i', 'latex $$i', 'latex2e $$i'], - rc_entry = [ r'\converter latex dvi "%%" "latex"' ] ) + if os.name == 'nt' or sys.platform == 'cygwin': + # Windows only: DraftDVI + if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: + converter_entry = r'''\converter latex dvi2 "%%" "latex" +\converter dvi2 dvi "python $$s/scripts/clean_dvi.py $$i $$o" ""''' + else: + converter_entry = r'\converter latex dvi "%%" "latex"' + else: + converter_entry = r'\converter latex dvi "%%" "latex"' + path, LATEX = checkProg('a Latex2e program', ['pplatex $$i', 'latex $$i', 'latex2e $$i'], + rc_entry = [converter_entry]) # no latex if LATEX != 'none': # Check if latex is usable @@ -248,6 +257,10 @@ def checkFormatEntries(): # checkProg('a DVI previewer', ['xdvi', 'kdvi'], rc_entry = [ r'\Format dvi dvi DVI D "%%" "" "document"' ]) + if os.name == 'nt' or sys.platform == 'cygwin': + # Windows only: DraftDVI + if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: + addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"') # checkProg('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'], rc_entry = [ r'\Format html html HTML H "%%" "" "document"' ]) diff --git a/lib/scripts/clean_dvi.py b/lib/scripts/clean_dvi.py new file mode 100644 index 0000000000..39fde890d2 --- /dev/null +++ b/lib/scripts/clean_dvi.py @@ -0,0 +1,106 @@ +#! /usr/bin/env python + +''' +file clean_dvi.py +This file is part of LyX, the document processor. +Licence details can be found in the file COPYING +or at http://www.lyx.org/about/licence.php3 + +author Angus Leeming +Full author contact details are available in the file CREDITS +or at http://www.lyx.org/about/credits.php + +Usage: + python clean_dvi.py infile.dvi outfile.dvi + +clean_dvi modifies the input .dvi file so that +dvips and yap (a dvi viewer on Windows) can find +any embedded PostScript files whose names are protected +with "-quotes. + +It works by: +1 translating the machine readable .dvi file to human + readable .dtl form, +2 manipulating any references to external files +3 translating the .dtl file back to .dvi format. + +It requires dv2dt and dt2dv from the DTL dviware package +http://www.ctan.org/tex-archive/dviware/dtl/ +''' + +import os, re, sys + +def usage(prog_name): + return 'Usage: %s in.dvi out.dvi\n' \ + % os.path.basename(prog_name) + + +def warning(message): + sys.stderr.write(message + '\n') + + +def error(message): + sys.stderr.write(message + '\n') + sys.exit(1) + + +def manipulated_dtl(data): + psfile_re = re.compile(r'(special1 +)([0-9]+)( +\'PSfile=")(.*)(" llx=.*)') + + lines = data.split('\n') + for i in range(len(lines)): + line = lines[i] + match = psfile_re.match(line) + if match != None: + file = match.group(4) + filelen = len(file) + file = file.replace('"', '') + # Don't forget to update the length of the string too... + strlen = int(match.group(2)) - (filelen - len(file)) + + lines[i] = '%s%d%s%s%s' \ + % ( match.group(1), strlen, match.group(3), + file, match.group(5) ) + + return '\n'.join(lines) + + +def main(argv): + # First establish that the expected information has + # been input on the command line and whether the + # required executables exist. + if len(argv) != 3: + error(usage(argv[0])) + + infile = argv[1] + outfile = argv[2] + + if not os.path.exists(infile): + error('Unable to read "%s"\n' % infile) + + # Convert the input .dvi file to .dtl format. + dv2dt_call = 'dv2dt "%s"' % infile + dv2dt_stdin, dv2dt_stdout, dv2dt_stderr = \ + os.popen3(dv2dt_call, 't') + + dv2dt_stdin.close() + dv2dt_data = dv2dt_stdout.read() + dv2dt_status = dv2dt_stdout.close() + + if dv2dt_status != None or len(dv2dt_data) == 0: + dv2dt_err = dv2dt_stderr.read() + error("Failed: %s\n%s\n" % ( dv2dt_call, dv2dt_err) ) + + # Manipulate the .dtl file. + dtl_data = manipulated_dtl(dv2dt_data) + if dtl_data == None: + error("Failed to manipulate the dtl file") + + # Convert this .dtl file back to .dvi format. + dt2dv_call = 'dt2dv -si "%s"' % outfile + dt2dv_stdin = os.popen(dt2dv_call, 'w') + dt2dv_stdin.write(dtl_data) + + +if __name__ == "__main__": + main(sys.argv)