%%
%% This is file `hardwrap.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hardwrap.dtx  (with options: `package')
%%   ____________________________
%%   The HARDWRAP package
%%   (C) 2010-2011 Will Robertson
%%   (C) 2010 Kevin Godby
%%   License information appended
%% 
\ProvidesPackage{hardwrap}
  [2011/02/12 v0.2 Hard wrap messages]
\IfFileExists{ifplatform.sty}{%
  \RequirePackage{ifplatform}
}{%
  \newif\ifwindows
  \IfFileExists{/dev/null}{\windowsfalse}{\windowstrue}
}
\IfFileExists{pdftexcmds.sty}{%
  \RequirePackage{pdftexcmds}
}{%
  \def\pdf@shellescape{\pdfshellescape}
}
\RequirePackage{ifxetex}
\newcount\hw@charcount
\newcount\hw@wordcount
\def\hw@currtext{}
\def\hw@currline{}
\def\hw@currword{}
\protected\def\hw@protected@newline{}
\protected\def\hw@protected@space{ }
\let\hw@expanding@space\space
\protected\def\hw@insert@newline{\hw@insert@newline}
\protected\def\hw@scanstop{\hw@scanstop}
\def\hw@strlen#1{%
  \numexpr0\hw@Ncharscan#1\hw@scanstop\relax
}
\def\hw@Ncharscan#1{%
 \ifx#1\hw@scanstop
   \expandafter\@gobble
 \else
   \expandafter\@firstofone
 \fi
 {+1\hw@Ncharscan}%
}
\def\hw@strlen@of#1{%
  \expandafter\hw@strlen\expandafter{#1}%
}
\newcount\hw@maxprintline
\ifluatex\else
  \ifxetex\else
    \ifwindows\else
      \ifnum\pdf@shellescape>0\relax
        \hw@maxprintline=\@@input"|kpsewhich -var-value=max_print_line"\relax
      \fi
    \fi
  \fi
\fi
\ifnum\hw@maxprintline=0\relax
  \hw@maxprintline=79\relax % default
\fi
\newcommand*{\setmaxprintline}[1]{%
  \hw@maxprintline=#1\relax
}
\newcommand*\HardWrap[5]{%
  \begingroup
    \hw@maxprintline=\numexpr#2\relax
    \let\space\hw@protected@space
    \def\ {\space}%
    \let\\\hw@insert@newline
    \let\noexpand\string
    \begingroup
      #3%
      \let\protect\string
      \xdef\@tempa{#5}%
    \endgroup
    \expandafter\hw@scan\@tempa\hw@scanstop
    \def\\{\hw@protected@newline}%
    \def\hw@protected@newline{#4}%
    \let\space\hw@expanding@space
    \@temptokena={#1}%
    \expandafter\the\expandafter\@temptokena\expandafter{\hw@wrappedtext}%
  \endgroup
}
\def\hw@scan{%
  \futurelet\let@token\hw@process
}
\def\hw@process{%
  \ifx\let@token\hw@scanstop\relax
    \hw@process@end
    \let\next\@gobble
  \else\ifx\let@token\@sptoken
    \hw@process@space
    \def\next{\afterassignment\hw@scan\let\@tempa= }%
  \else\ifx\let@token\hw@insert@newline
    \hw@process@messagebreak
    \def\next{\expandafter\hw@scan\@gobble}%
  \else\ifx\let@token^^J
    \hw@process@messagebreak
    \def\next{\expandafter\hw@scan\@gobble}%
  \else\ifx\let@token\bgroup
    \def\next{\expandafter\hw@dochar\hw@process@group}%
  \else
    \let\next\hw@dochar
  \fi\fi\fi\fi\fi
  \next
}
\def\hw@dochar#1{%
  \edef\hw@currword{\hw@currword #1}%
  \hw@scan
}
\def\hw@process@space{%
  \hw@wordcount=\hw@strlen@of\hw@currword\relax
  \ifnum\numexpr(\hw@charcount+\hw@wordcount)\relax<\hw@maxprintline
    \advance\hw@charcount by \hw@wordcount
    \ifx\hw@currline\@empty
      \edef\hw@currline{\hw@currword}%
    \else
      \advance\hw@charcount by 1\relax % account for the space character
      \edef\hw@currline{\hw@currline\hw@expanding@space\hw@currword}%
    \fi
  \else
    \hw@charcount=\hw@wordcount\relax
    \edef\hw@currtext{\hw@currtext\hw@currline\hw@protected@newline}%
    \let\hw@currline\hw@currword
  \fi
  \let\hw@currword\@empty
}
\def\hw@process@messagebreak{%
  \hw@wordcount=\hw@strlen@of\hw@currword\relax
  \ifnum\numexpr(\hw@charcount+\hw@wordcount)<\hw@maxprintline
    \edef\hw@currtext{%
      \hw@currtext
      \ifx\hw@currline\@empty\else
        \hw@currline\space
      \fi
      \hw@currword\hw@protected@newline
    }%
    \hw@charcount=0\relax
    \let\hw@currline\@empty
  \else
    \edef\hw@currtext{\hw@currtext\hw@currline\hw@protected@newline}%
    \hw@charcount=\hw@wordcount
    \let\hw@currline\hw@currword
  \fi
  \let\hw@currword\@empty
}
\def\hw@process@end{%
  \hw@wordcount=\hw@strlen@of\hw@currword\relax
  \ifnum\numexpr(\hw@charcount+\hw@wordcount)<\hw@maxprintline
    \edef\hw@wrappedtext{%
      \hw@currtext
      \ifx\hw@currline\@empty\else
        \hw@currline\space
      \fi
      \hw@currword
    }%
  \else
    \edef\hw@wrappedtext{%
      \hw@currtext\hw@currline\hw@protected@newline\hw@currword
    }%
  \fi
}
\edef\hw@process@group#1{%
  \expandafter\@gobble\string\{%
  #1%
  \expandafter\@gobble\string\}%
}
\def\HardWrapSetup{%
  \def\MessageBreak{\\}%
  \def\newline{\\}%
  \def\emph##1{\string_##1\string_}%
  \def\textit##1{/##1/}%
  \def\textbf##1{*##1*}%
}
\newcommand\hw@suffix{^^JThis message occurred}
\newcommand\GenerateLogMacros[1]{%
  \lowercase{\def\hw@tempa{#1}}%
  \def\hw@tempb{package}%
  \ifx\hw@tempa\hw@tempb
    \expandafter\GeneratePackageLogMacros
  \else
    \def\hw@tempb{class}%
    \ifx\hw@tempa\hw@tempb
      \expandafter\expandafter\expandafter\GenerateClassLogMacros
    \else
      \PackageError{hardwrap}{\MessageBreak
        \string\GenerateLogMacros\space only accepts "package"
        \MessageBreak or "class" types%
      }{%
        E.g., \detokenize{\GenerateLogMacros{package}[HW]{hardwrap}}%
      }%
    \fi
  \fi
}
\newcommand{\GeneratePackageLogMacros}[2][]{%
  \hw@generate@logging@macros{package}{#1}{#2}%
    {\hw@maxprintline-\hw@strlen{#2}-16}% info length
    {\hw@maxprintline-\hw@strlen{#2}-19}% warning length
}
\newcommand{\GenerateClassLogMacros}[2][]{%
  \hw@generate@logging@macros{class}{#1}{#2}%
    {\hw@maxprintline-\hw@strlen{#2}-14}% info length
    {\hw@maxprintline-\hw@strlen{#2}-17}% warning length
}
\newcommand{\hw@generate@logging@macros}[5]{%
  \def\@tempa{#2}\ifx\@tempa\@empty
    \hw@generate@logging@macros@aux{#1}{#3}{#3}{#4}{#5}%
  \else
    \hw@generate@logging@macros@aux{#1}{#2}{#3}{#4}{#5}%
  \fi
}
\newcommand{\hw@generate@logging@macros@aux}[5]{%
  \expandafter\edef\csname #2@info\endcsname##1{%
    \noexpand\HardWrap
      {\@nameuse{hw@#1@info}{#3}}
      {\number\numexpr#4\relax}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\noexpand\MessageBreak}
      {##1}%
  }%
  \expandafter\edef\csname #2@info@noline\endcsname##1{%
    \noexpand\HardWrap
      {\@nameuse{hw@#1@info@noline}{#3}}
      {\number\numexpr#4\relax}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\noexpand\MessageBreak}
      {##1}%
  }%
  \expandafter\edef\csname #2@warning\endcsname##1{%
    \noexpand\HardWrap
      {\@nameuse{hw@#1@warning}{#3}}
      {\number\numexpr#5\relax}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\noexpand\MessageBreak}
      {##1}%
  }%
  \expandafter\edef\csname #2@warning@noline\endcsname##1{%
    \noexpand\HardWrap
      {\@nameuse{hw@#1@warning@noline}{#3}}
      {\number\numexpr#5\relax}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\noexpand\MessageBreak}
      {##1}%
  }%
  \expandafter\edef\csname #2@error\endcsname##1##2{%
    \noexpand\HardWrap
      {\xdef\noexpand\hw@tempa}
      {\number\numexpr#5\relax}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\MessageBreak}
      {\MessageBreak ##1}%
    \noexpand\HardWrap
      {\xdef\noexpand\hw@tempb}
      {\the\hw@maxprintline}
      {\unexpanded\expandafter{\HardWrapSetup}}
      {\MessageBreak}
      {\MessageBreak ##2}%
    \unexpanded{%
      \@nameuse{hw@#1@error}{#3}{\hw@tempa}{\hw@tempb}%
    }%
  }%
}
\protected\def\hw@class@info          #1#2{\ClassInfo   {#1}{#2\hw@suffix}}
\protected\def\hw@class@info@noline   #1#2{\ClassInfo   {#1}{#2\@gobbletwo}}
\protected\def\hw@class@warning       #1#2{\ClassWarning{#1}{#2\hw@suffix}}
\protected\def\hw@class@warning@noline#1#2{\ClassWarning{#1}{#2\@gobbletwo}}
\protected\def\hw@class@error         #1#2{\ClassError  {#1}{#2\@gobble}}
\protected\def\hw@package@info          #1#2{\PackageInfo   {#1}{#2\hw@suffix}}
\protected\def\hw@package@info@noline   #1#2{\PackageInfo   {#1}{#2\@gobbletwo}}
\protected\def\hw@package@warning       #1#2{\PackageWarning{#1}{#2\hw@suffix}}
\protected\def\hw@package@warning@noline#1#2{\PackageWarning{#1}{#2\@gobbletwo}}
\protected\def\hw@package@error         #1#2{\PackageError  {#1}{#2\@gobble}}
%% 
%% Copyright (C) 2010 by Will Robertson <will.robertson@latex-project.org>
%% Copyright (C) 2010 by Kevin Godby <kevin@godby.org>
%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status)
%% by Will Robertson.
%% 
%% This work consists of the file  hardwrap.dtx
%%           and the derived files hardwrap.sty,
%%                                 hardwrap.ins, and
%%                                 hardwrap.pdf.
%% 
%%
%% End of file `hardwrap.sty'.
