From 355a127454c52c9b592631e0b60a1e7d567960de Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 8 Jul 2016 21:46:04 +0000 Subject: texosquery (8jul16) git-svn-id: svn://tug.org/texlive/trunk@41663 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/texk/texlive/linked_scripts/Makefile.am | 1 + .../source/texk/texlive/linked_scripts/Makefile.in | 1 + .../texlive/linked_scripts/texosquery/texosquery | 4 + Master/bin/amd64-freebsd/texosquery | 1 + Master/bin/amd64-netbsd/texosquery | 1 + Master/bin/armel-linux/texosquery | 1 + Master/bin/armhf-linux/texosquery | 1 + Master/bin/i386-cygwin/texosquery | 1 + Master/bin/i386-freebsd/texosquery | 1 + Master/bin/i386-linux/texosquery | 1 + Master/bin/i386-netbsd/texosquery | 1 + Master/bin/i386-solaris/texosquery | 1 + Master/bin/powerpc-linux/texosquery | 1 + Master/bin/sparc-solaris/texosquery | 1 + Master/bin/universal-darwin/texosquery | 1 + Master/bin/win32/texosquery.exe | Bin 0 -> 1536 bytes Master/bin/x86_64-cygwin/texosquery | 1 + Master/bin/x86_64-darwin/texosquery | 1 + Master/bin/x86_64-linux/texosquery | 1 + Master/bin/x86_64-solaris/texosquery | 1 + .../texmf-dist/doc/support/texosquery/Manifest.txt | 2 + Master/texmf-dist/doc/support/texosquery/README.md | 167 +++++ .../doc/support/texosquery/texosquery.pdf | Bin 0 -> 247702 bytes .../doc/support/texosquery/texosquery.tex | 138 ++++ Master/texmf-dist/scripts/texosquery/texosquery | 4 + .../texmf-dist/scripts/texosquery/texosquery.jar | Bin 0 -> 6548 bytes .../source/support/texosquery/TeXOSQuery.java | 681 +++++++++++++++++++ .../source/support/texosquery/texosquery.dtx | 725 +++++++++++++++++++++ .../source/support/texosquery/texosquery.ins | 45 ++ .../texmf-dist/tex/latex/texosquery/texosquery.sty | 48 ++ Master/tlpkg/bin/tlpkg-ctan-check | 2 +- Master/tlpkg/libexec/ctan2tds | 3 + Master/tlpkg/tlpsrc/collection-binextra.tlpsrc | 1 + Master/tlpkg/tlpsrc/texosquery.tlpsrc | 2 + 34 files changed, 1839 insertions(+), 1 deletion(-) create mode 100755 Build/source/texk/texlive/linked_scripts/texosquery/texosquery create mode 120000 Master/bin/amd64-freebsd/texosquery create mode 120000 Master/bin/amd64-netbsd/texosquery create mode 120000 Master/bin/armel-linux/texosquery create mode 120000 Master/bin/armhf-linux/texosquery create mode 120000 Master/bin/i386-cygwin/texosquery create mode 120000 Master/bin/i386-freebsd/texosquery create mode 120000 Master/bin/i386-linux/texosquery create mode 120000 Master/bin/i386-netbsd/texosquery create mode 120000 Master/bin/i386-solaris/texosquery create mode 120000 Master/bin/powerpc-linux/texosquery create mode 120000 Master/bin/sparc-solaris/texosquery create mode 120000 Master/bin/universal-darwin/texosquery create mode 100755 Master/bin/win32/texosquery.exe create mode 120000 Master/bin/x86_64-cygwin/texosquery create mode 120000 Master/bin/x86_64-darwin/texosquery create mode 120000 Master/bin/x86_64-linux/texosquery create mode 120000 Master/bin/x86_64-solaris/texosquery create mode 100644 Master/texmf-dist/doc/support/texosquery/Manifest.txt create mode 100644 Master/texmf-dist/doc/support/texosquery/README.md create mode 100644 Master/texmf-dist/doc/support/texosquery/texosquery.pdf create mode 100644 Master/texmf-dist/doc/support/texosquery/texosquery.tex create mode 100755 Master/texmf-dist/scripts/texosquery/texosquery create mode 100755 Master/texmf-dist/scripts/texosquery/texosquery.jar create mode 100644 Master/texmf-dist/source/support/texosquery/TeXOSQuery.java create mode 100644 Master/texmf-dist/source/support/texosquery/texosquery.dtx create mode 100644 Master/texmf-dist/source/support/texosquery/texosquery.ins create mode 100644 Master/texmf-dist/tex/latex/texosquery/texosquery.sty create mode 100644 Master/tlpkg/tlpsrc/texosquery.tlpsrc diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am index 6d79c490a6a..2da60f80c44 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.am +++ b/Build/source/texk/texlive/linked_scripts/Makefile.am @@ -79,6 +79,7 @@ texmf_shell_scripts = \ pdfxup/pdfxup \ pst-pdf/ps4pdf \ simpdftex/simpdftex \ + texosquery/texosquery \ typeoutfileinfo/typeoutfileinfo.sh texmf_other_scripts = \ a2ping/a2ping.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in index 009ea852b53..57e7d5b152a 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.in +++ b/Build/source/texk/texlive/linked_scripts/Makefile.in @@ -293,6 +293,7 @@ texmf_shell_scripts = \ pdfxup/pdfxup \ pst-pdf/ps4pdf \ simpdftex/simpdftex \ + texosquery/texosquery \ typeoutfileinfo/typeoutfileinfo.sh texmf_other_scripts = \ diff --git a/Build/source/texk/texlive/linked_scripts/texosquery/texosquery b/Build/source/texk/texlive/linked_scripts/texosquery/texosquery new file mode 100755 index 00000000000..2f97a43db65 --- /dev/null +++ b/Build/source/texk/texlive/linked_scripts/texosquery/texosquery @@ -0,0 +1,4 @@ +#!/bin/sh + +jarpath=`kpsewhich --progname=texosquery --format=texmfscripts texosquery.jar` +java -jar "$jarpath" "$@" diff --git a/Master/bin/amd64-freebsd/texosquery b/Master/bin/amd64-freebsd/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/amd64-freebsd/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/amd64-netbsd/texosquery b/Master/bin/amd64-netbsd/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/amd64-netbsd/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/armel-linux/texosquery b/Master/bin/armel-linux/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/armel-linux/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/armhf-linux/texosquery b/Master/bin/armhf-linux/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/armhf-linux/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/i386-cygwin/texosquery b/Master/bin/i386-cygwin/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/i386-cygwin/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/i386-freebsd/texosquery b/Master/bin/i386-freebsd/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/i386-freebsd/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/i386-linux/texosquery b/Master/bin/i386-linux/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/i386-linux/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/i386-netbsd/texosquery b/Master/bin/i386-netbsd/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/i386-netbsd/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/i386-solaris/texosquery b/Master/bin/i386-solaris/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/i386-solaris/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/powerpc-linux/texosquery b/Master/bin/powerpc-linux/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/powerpc-linux/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/sparc-solaris/texosquery b/Master/bin/sparc-solaris/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/sparc-solaris/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/universal-darwin/texosquery b/Master/bin/universal-darwin/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/universal-darwin/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/win32/texosquery.exe b/Master/bin/win32/texosquery.exe new file mode 100755 index 00000000000..5777d90a17a Binary files /dev/null and b/Master/bin/win32/texosquery.exe differ diff --git a/Master/bin/x86_64-cygwin/texosquery b/Master/bin/x86_64-cygwin/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/x86_64-cygwin/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/x86_64-darwin/texosquery b/Master/bin/x86_64-darwin/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/x86_64-darwin/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/x86_64-linux/texosquery b/Master/bin/x86_64-linux/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/x86_64-linux/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/bin/x86_64-solaris/texosquery b/Master/bin/x86_64-solaris/texosquery new file mode 120000 index 00000000000..507d22edfe4 --- /dev/null +++ b/Master/bin/x86_64-solaris/texosquery @@ -0,0 +1 @@ +../../texmf-dist/scripts/texosquery/texosquery \ No newline at end of file diff --git a/Master/texmf-dist/doc/support/texosquery/Manifest.txt b/Master/texmf-dist/doc/support/texosquery/Manifest.txt new file mode 100644 index 00000000000..92d656204b2 --- /dev/null +++ b/Master/texmf-dist/doc/support/texosquery/Manifest.txt @@ -0,0 +1,2 @@ +Main-Class: com/dickimawbooks/texosquery/TeXOSQuery +Class-Path: . diff --git a/Master/texmf-dist/doc/support/texosquery/README.md b/Master/texmf-dist/doc/support/texosquery/README.md new file mode 100644 index 00000000000..49b390d55a3 --- /dev/null +++ b/Master/texmf-dist/doc/support/texosquery/README.md @@ -0,0 +1,167 @@ +# texosquery +Cross-platform Java application to query OS information designed for use in +TeX's shell escape mechanism. + +The application can query the following: + + - locale and codeset + - current working directory + - user home directory + - temporary directory + - OS name, arch and version + - Current date and time in PDF format + (for TeX formats that don't provide `\pdfcreationdate`) + - Date-time stamp of a file in PDF format + (for TeX formats that don't provide `\pdffilemoddate`) + - Size of a file in bytes + (for TeX formats that don't provide `\pdffilesize`) + - Contents of a directory (captured as a list) + - Directory contents filtered by regular expression + (captured as a list) + - URI of a file + - Canonical path of a file + +All paths use a forward slash as directory divider so results +can be used, for example, in commands like `\includegraphics`. + +There are files provided for easy access in TeX documents: + + - `texosquery.tex` : generic TeX code + - `texosquery.sty` : LaTeX package + +This provides commands to run `texosquery` using TeX's shell +escape mechanism and capture the result in a control sequence. +The category code of most of TeX's default special characters +(and some other potentially problematic characters) is temporarily +changed to 12 while reading the result. + +## Installation + +The actual Java application is in `texosquery.jar`. +The `.tex` and `.sty` files can be extracted from `texosquery.dtx` +using `tex texosquery.ins`. In the following, replace TEXMF with the +path to your TEXMF directory. + + - Move `texosquery.tex` to `TEXMF/tex/generic/texosquery/` + - Move `texosquery.sty` to `TEXMF/tex/latex/texosquery/` + - Move `texosquery.pdf` to `TEXMF/doc/generic/texosquery/` + - Move `texosquery.jar` to `TEXMF/scripts/texosquery/` + +Unix-like users: move the bash script `texosquery` to somewhere on +your path. + +Windows users: TeX Live's generic wrapper should be able to locate +the `texosquery.jar` file, but if not or you're not using TL, +then (untested) create a file called `texosquery.bat` that contains: +```dos +@ECHO OFF +FOR /F %%I IN ('kpsewhich --progname=texosquery --format=texmfscripts texosquery.jar') DO SET JARPATH=%%I +START javaw -jar "%JARPATH%\texosquery.jar" %* +``` +(or skip the `FOR` line and replace `%JARPATH%` with the full path name to +`texosquery.jar`.) Put this file on your system's path. + +## Examples: + +Plain TeX: + +```tex +% arara: pdftex: {shell: on} +\input texosquery + +\TeXOSQueryLocale{\result} +locale: \result. + +\TeXOSQueryCwd{\result} +cwd: {\tt \result}. + +\TeXOSQueryNow{\result} +now: \result. + +\TeXOSQueryFileDate{\result}{\jobname.tex} +file date: \result. + +\TeXOSQueryFileSize{\result}{\jobname.tex} +file size: \result bytes. + +\bye +``` + +LaTeX: + +```latex +% arara: pdflatex: {shell: on} +\documentclass{article} + +\usepackage{texosquery} +\usepackage{etoolbox} + +\begin{document} + +\TeXOSQueryLocale{\result} +locale: \result. + +\TeXOSQueryCwd{\result} +cwd: \texttt{\result}. + +\TeXOSQueryNow{\result} +now: \result. + +\TeXOSQueryFileDate{\result}{\jobname.tex} +file date: \result. + +\TeXOSQueryFileSize{\result}{\jobname.tex} +file size: \result bytes. + +\TeXOSQueryFilterFileList{\result}{,}{.+\string\.(png|jpg)}{.} +All jpg and png files in current directory: + +\renewcommand{\do}[1]{\texttt{#1}.\par} +\expandafter\docsvlist\expandafter{\result} + +\end{document} +``` + +For a full list of available commands, see the documentation +(`texosquery.pdf`). + +You can omit `texosquery.tex` and directly use `texosquery` +in TeX's shell escape, but take care of special characters +occurring in the result or if double-quotes occur in +`\jobname`. + +## Source code + +The `.tex` and `.sty` files and documentation are contained in +`texosquery.dtx`. To compile the documentation: +```bash +pdflatex texosquery.dtx +makeindex -s gglo.ist -t texosquery.glg -o texosquery.gls texosquery.glo +makeindex -s gind.ist texosquery.idx +pdflatex texosquery.dtx +pdflatex texosquery.dtx +``` + +The Java source is in `TeXOSQuery.java` and the manifest for the +`.jar` file is `Manifest.txt`. Assuming the following directory +structure: +``` +java/TeXOSQuery.java +java/Manifest.txt +classes/com/dickimawbooks/texosquery/ +``` +Then to create `texosquery.jar`, do: +```bash +cd java +javac -d ../classes TeXOSQuery.java +cd ../classes +jar cmf ../java/Manifest.txt ../texosquery.jar com/dickimawbooks/texosquery/*.class +``` + +--- + +Source on GitHub: https://github.com/nlct/texosquery + +Author Home Page: http://www.dickimaw-books.com/ + +License: LPPL 1.3+ diff --git a/Master/texmf-dist/doc/support/texosquery/texosquery.pdf b/Master/texmf-dist/doc/support/texosquery/texosquery.pdf new file mode 100644 index 00000000000..49c5401edbe Binary files /dev/null and b/Master/texmf-dist/doc/support/texosquery/texosquery.pdf differ diff --git a/Master/texmf-dist/doc/support/texosquery/texosquery.tex b/Master/texmf-dist/doc/support/texosquery/texosquery.tex new file mode 100644 index 00000000000..b95300ac20d --- /dev/null +++ b/Master/texmf-dist/doc/support/texosquery/texosquery.tex @@ -0,0 +1,138 @@ +%% +%% This is file `texosquery.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% texosquery.dtx (with options: `texosquery.tex,package') +%% +%% texosquery +%% Copyright 2016 Nicola Talbot +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license of (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. +%% +%% This work has the LPPL maintenance status `maintained'. +%% +%% The Current Maintainer of this work is Nicola Talbot. +%% +%% This work consists of the files texosquery.dtx and texosquery.ins +%% and the derived files texosquery.sty, texosquery.tex. +%% Additionally, the Java application texosquery.jar and bash script +%% texosquery +%% \CharacterTable +%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z +%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z +%% Digits \0\1\2\3\4\5\6\7\8\9 +%% Exclamation \! Double quote \" Hash (number) \# +%% Dollar \$ Percent \% Ampersand \& +%% Acute accent \' Left paren \( Right paren \) +%% Asterisk \* Plus \+ Comma \, +%% Minus \- Point \. Solidus \/ +%% Colon \: Semicolon \; Less than \< +%% Equals \= Greater than \> Question mark \? +%% Commercial at \@ Left bracket \[ Backslash \\ +%% Right bracket \] Circumflex \^ Underscore \_ +%% Grave accent \` Left brace \{ Vertical bar \| +%% Right brace \} Tilde \~} +\ifnum\catcode`\@=11\relax + \def\@texosquery@restore@at{}% +\else + \expandafter\edef\csname @texosquery@restore@at\endcsname{% + \noexpand\catcode`\noexpand\@=\number\catcode`\@\relax + }% + \catcode`\@=11\relax +\fi +\ifx\TeXOSQuery\undefined +\else + \@texosquery@restore@at + \expandafter\endinput +\fi +\def\TeXOSInvokerName{texosquery} +\ifx\@@input\undefined + \def\TeXOSQueryInvoker#1{\input|"\TeXOSInvokerName\space#1" } +\else + \def\TeXOSQueryInvoker#1{\@@input|"\TeXOSInvokerName\space#1" } +\fi +\newif\ifTeXOSQueryDryRun +\TeXOSQueryDryRunfalse +\ifx\shellescape\undefined + \ifx\pdfshellescape\undefined + \else + \ifnum\pdfshellescape=0\relax + \TeXOSQueryDryRuntrue + \fi + \fi +\else + \ifnum\shellescape=0\relax + \TeXOSQueryDryRuntrue + \fi +\fi +\def\TeXOSQuery#1#2{% + \ifTeXOSQueryDryRun + \begingroup + \newlinechar=`\^^J + \message{^^JTeXOSQuery: \TeXOSInvokerName\space#2^^J}% + \endgroup + \def#1{}% + \else + \begingroup + \endlinechar=-1\relax + \catcode`\-=12\relax + \catcode`\_=12\relax + \catcode`\^=12\relax + \catcode`\~=12\relax + \catcode`\$=12\relax + \catcode`\&=12\relax + \catcode`\"=12\relax + \catcode`\'=12\relax + \catcode`\.=12\relax + \catcode`\/=12\relax + \catcode`\:=12\relax + \catcode`\;=12\relax + \catcode`\%=12\relax + \everyeof{\noexpand}\relax + \edef\x{\endgroup\def\noexpand#1{\TeXOSQueryInvoker{#2}}}\x + \fi +} +\def\TeXOSQueryLocale#1{\TeXOSQuery{#1}{\string-l}} +\def\TeXOSQueryCwd#1{\TeXOSQuery{#1}{\string-c}} +\def\TeXOSQueryHome#1{\TeXOSQuery{#1}{\string-m}} +\def\TeXOSQueryTmpDir#1{\TeXOSQuery{#1}{\string-t}} +\def\TeXOSQueryVersion#1{\TeXOSQuery{#1}{\string-r}} +\def\TeXOSQueryArch#1{\TeXOSQuery{#1}{\string-a}} +\def\TeXOSQueryName#1{\TeXOSQuery{#1}{\string-o}} +\def\TeXOSQueryNow#1{\TeXOSQuery{#1}{\string-n}} +\def\texosquerystripquotes#1{% + \@texosquery@stripquotes#1\@mid@texosquery@stripquotes + "\relax"\relax\@end@texosquery@stripquotes +} +\def\@texosquery@stripquotes#1"#2"{% + \@@texosquery@stripquotes#1#2% +} +\def\@@texosquery@stripquotes#1\@mid@texosquery@stripquotes#2\@end@texosquery@stripquotes{% + #1% +} +\def\TeXOSQueryFileDate#1#2{\TeXOSQuery{#1}{\string-d + \string'\texosquerystripquotes{#2}\string'}} +\def\TeXOSQueryFileSize#1#2{\TeXOSQuery{#1}{\string-s + \string'\texosquerystripquotes{#2}\string'}} +\def\TeXOSQueryFileList#1#2#3{\TeXOSQuery{#1}{% + \string-i \string'#2\string' + \string'\texosquerystripquotes{#3}\string'}} +\def\TeXOSQueryFilterFileList#1#2#3#4{\TeXOSQuery{#1}{% + \string-f \string'#2\string' \string'#3\string' + \string'\texosquerystripquotes{#4}\string'}} +\def\TeXOSQueryFileURI#1#2{\TeXOSQuery{#1}{\string-u + \string'\texosquerystripquotes{#2}\string'}} +\def\TeXOSQueryFilePath#1#2{\TeXOSQuery{#1}{\string-p + \string'\texosquerystripquotes{#2}\string'}} +\@texosquery@restore@at +\endinput +%% +%% End of file `texosquery.tex'. diff --git a/Master/texmf-dist/scripts/texosquery/texosquery b/Master/texmf-dist/scripts/texosquery/texosquery new file mode 100755 index 00000000000..2f97a43db65 --- /dev/null +++ b/Master/texmf-dist/scripts/texosquery/texosquery @@ -0,0 +1,4 @@ +#!/bin/sh + +jarpath=`kpsewhich --progname=texosquery --format=texmfscripts texosquery.jar` +java -jar "$jarpath" "$@" diff --git a/Master/texmf-dist/scripts/texosquery/texosquery.jar b/Master/texmf-dist/scripts/texosquery/texosquery.jar new file mode 100755 index 00000000000..d56b681bbe1 Binary files /dev/null and b/Master/texmf-dist/scripts/texosquery/texosquery.jar differ diff --git a/Master/texmf-dist/source/support/texosquery/TeXOSQuery.java b/Master/texmf-dist/source/support/texosquery/TeXOSQuery.java new file mode 100644 index 00000000000..6b4f2a5c715 --- /dev/null +++ b/Master/texmf-dist/source/support/texosquery/TeXOSQuery.java @@ -0,0 +1,681 @@ +package com.dickimawbooks.texosquery; + +import java.util.Locale; +import java.util.Calendar; +import java.io.*; + +public class TeXOSQuery +{ + public static String escapeHash(String str) + { + return str.replaceAll("#", "\\\\#"); + } + + public static String getLocale(Locale locale) + { + return getLocale(locale, false); + } + + public static String getLocale(Locale locale, boolean convertCodeset) + { + String id = ""; + + if (locale != null) + { + String lang = locale.getLanguage(); + + if (lang != null) + { + id = lang; + } + + String country = locale.getCountry(); + + if (country != null && !country.isEmpty()) + { + if (id.isEmpty()) + { + id = country; + } + else + { + id = id+"-"+country; + } + } + + String codeset = System.getProperty("file.encoding"); + + if (codeset != null && !codeset.isEmpty()) + { + if (convertCodeset) + { + codeset = codeset.toLowerCase().replaceAll("-", ""); + } + + id = id+"."+codeset; + } + + String script = locale.getScript(); + + if (script != null && !script.isEmpty()) + { + id = id+"@"+escapeHash(script); + } + + } + + return id; + } + + public static String getOSname() + { + try + { + return escapeHash(System.getProperty("os.name", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + public static String getOSarch() + { + try + { + return escapeHash(System.getProperty("os.arch", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + public static String getOSversion() + { + try + { + return escapeHash(System.getProperty("os.version", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + public static String getUserHome() + { + try + { + return toTeXPath(System.getProperty("user.home", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + /* + * Since this is designed to work within TeX, backslashes in paths + * need to be replaced with forward slashes. + */ + + public static String toTeXPath(String filename) + { + if (filename == null) + { + return ""; + } + + if (File.separatorChar == '\\') + { + filename = filename.replaceAll("\\\\", "/"); + } + + return escapeHash(filename); + } + + public static String fromTeXPath(String filename) + { + if (File.separatorChar != '/') + { + return filename.replaceAll("/", File.separator); + } + + return filename; + } + + public static File fileFromTeXPath(String filename) + { + filename = fromTeXPath(filename); + + File file = new File(filename); + + if (!file.exists() && file.getParent() == null) + { + // use kpsewhich to find it + + try + { + Process p = new ProcessBuilder("kpsewhich", filename).start(); + + if (p.waitFor() == 0) + { + InputStream is = p.getInputStream(); + + if (is != null) + { + BufferedReader in = new BufferedReader( + new InputStreamReader(is)); + + String line = in.readLine(); + + in.close(); + + if (line != null && !line.isEmpty()) + { + file = new File(fromTeXPath(line)); + } + } + } + } + catch (IOException e) + { + } + catch (InterruptedException e) + { + } + } + + return file; + } + + public static String getCwd() + { + try + { + return toTeXPath(System.getProperty("user.dir", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + public static String getTmpDir() + { + try + { + return toTeXPath(System.getProperty("java.io.tmpdir", "")); + } + catch (SecurityException e) + { + return ""; + } + } + + public static String pdfnow() + { + Calendar cal = Calendar.getInstance(); + + return pdfDate(cal); + } + + public static String pdfDate(Calendar cal) + { + String tz = String.format("%1$tz", cal); + + return String.format("D:%1$tY%1$tm%1td%1$tH%1$tM%1$tS%2$s'%3$s'", cal, + tz.substring(0,3), tz.substring(3)); + } + + public static String pdfDate(File file) + { + try + { + long millisecs = file.lastModified(); + + if (millisecs > 0L) + { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(millisecs); + + return pdfDate(cal); + } + } + catch (SecurityException e) + { + } + + return ""; + } + + public static String getFileLength(File file) + { + try + { + long len = file.length(); + + if (len > 0L) + { + return String.format("%d", len); + } + } + catch (SecurityException e) + { + } + + return ""; + } + + public static String getFileList(String sep, File dir) + { + if (!dir.isDirectory()) + { + return ""; + } + + StringBuilder builder = new StringBuilder(); + + try + { + String[] list = dir.list(); + + if (list == null) + { + return ""; + } + + for (int i = 0; i < list.length; i++) + { + if (i > 0) + { + builder.append(sep); + } + + // no need to worry about directory divider + // File.list() just returns the name not the path + builder.append(escapeHash(list[i])); + } + } + catch (SecurityException e) + { + } + + return builder.toString(); + } + + public static String getFilterFileList(String sep, + final String regex, File dir) + { + if (!dir.isDirectory()) + { + return ""; + } + + if (regex == null || regex.isEmpty()) + { + return getFileList(sep, dir); + } + + StringBuilder builder = new StringBuilder(); + + try + { + String[] list = dir.list(new FilenameFilter() + { + public boolean accept(File dir, String name) + { + return name.matches(regex); + } + }); + + if (list == null) + { + return ""; + } + + for (int i = 0; i < list.length; i++) + { + if (i > 0) + { + builder.append(sep); + } + + // no need to worry about directory divider + // File.list() just returns the name not the path + builder.append(escapeHash(list[i])); + } + } + catch (SecurityException e) + { + } + + return builder.toString(); + } + + public static String fileURI(File file) + { + if (!file.exists()) + { + return ""; + } + + try + { + // don't worry about '#' as it would've been converted to + // %23 (\TeXOSQuery changes the catcode of %) + return file.toURI().toString(); + } + catch (SecurityException e) + { + } + + return ""; + } + + public static String filePath(File file) + { + if (!file.exists()) + { + return ""; + } + + try + { + return toTeXPath(file.getCanonicalPath()); + } + catch (SecurityException e) + { + } + catch (IOException e) + { + } + + return ""; + } + + public static void syntax() + { + System.out.println("Usage: texosquery