% JOBPATH.TEX -- 96-02-12/14:54
%
% Get filename of running job from .log file.
% emTeX puts filename from command line into log file, so for full name type:
%       latex f:/mytex/junk
% Usage:
% \input{jobpath}
% This is file \jobpathname.
%
% From: David Carlisle <carli...@ma.man.ac.uk>
% Newsgroups: comp.text.tex
% Subject: Re: Does TeX know the name of the file currently being processed?
% Date: 09 Feb 1996 14:28:53 +0000
% Organization: Manchester University Mathematics Department
% In-reply-to: r...@PC2.MIC.DTU.DK's message of 9 Feb 1996 09:25:27 GMT
% To: r...@PC2.MIC.DTU.DK (Roger de Reus)
%
%
% In article <4ff3u7$...@news.uni-c.dk> r...@PC2.MIC.DTU.DK
% (Roger de Reus) writes:
%
%    :  \jobname returns the name of the file being processed,
%
%   This will give you the `name' part of the file (without path or extension).
%   What is the hook for the full qualified file name?
%
%
% I posted something like this to c.t.t some time back,
% I am not sure anyone would really want to use this (especially if they
% have a small disk quota:-)
%
% but (if you know you are on a tex that uses \jobname.log as the log
% file (ie not on VMS, where you have to make obvious change to .lis)
% you can get the full path from the log file. Unfortunately on Unix and
% presumably other systems writing to the file is buffered, so you have
% to write an awful lot of rubbish to flush out the buffer so the log
% really appears in the file, then you can read in the file and look at
% the first lines...
%
% The code below sets the path to the path reported by TeX. If the file
% is in the current directory this may end up being just the filename
% like \jobname. On web2c unix Tex at least you can force TeX to give
% the full path in the log file by explicitly putting the current
% directory at the front of the TeX input path.
%
% Thus if you save the code below as jobpath.tex this seems to work on
% my machine at least...
%
%
% vummath> TEXINPUTS=$PWD: tex jobpath
% This is TeX, Version 3.14159 (C version 6.1)
% (/home/carlisle/jobpath.tex
% Hyphenation patterns for english, german, loaded.
% !!!
% !!! Full path is /home/carlisle/jobpath.tex  !!!
% !!!
%  )
% No pages of output.
% Transcript written on jobpath.log.
% vummath>
%
%
% ================ jobpath.tex
%

\newread\logfile

\wlog{JobPath writes logfile just to get started}

\def\flush{%
  \openin\logfile=\jobname.log
   \read\logfile to \rubbish % get rid of a \par
  \ifeof\logfile
    \writerubbish
    \closein\logfile
    \expandafter\flush
  \fi}

\def\writerubbish{%
   {\newlinechar`\ \wlog{JobPath_writing_rubbish_to_logfile}}}

\def\getpath{%
  \read\logfile to \jobpathname
  \expandafter\testbracket\jobpathname((\testbracket}

\def\testbracket#1(#2(#3\testbracket{%
   \def\jobpathname{#2}%
  \ifx\jobpathname\empty
    \expandafter\getpath
  \fi}

% get the log file started
\flush
% now read it
\getpath

% see what happened

% \immediate\write17{!!!}
% \immediate\write17{!!! Full path is \jobpathname\space!!!}
% \immediate\write17{!!!}

%\bye

\endinput 