%!TEX root = std.tex
% Definitions of table environments

%%--------------------------------------------------
%% Table environments

% Set parameters for floating tables
\setcounter{totalnumber}{10}

% Base definitions for tables
\newenvironment{TableBase}
{
 \renewcommand{\tcode}[1]{{\CodeStylex{##1}}}
 \newcommand{\topline}{\hline}
 \newcommand{\capsep}{\hline\hline}
 \newcommand{\rowsep}{\hline}
 \newcommand{\bottomline}{\hline}

%% vertical alignment
 \newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{##1}}	% move argument up half a row

%% header helpers
 \newcommand{\hdstyle}[1]{\textbf{##1}}				% set header style
 \newcommand{\Head}[3]{\multicolumn{##1}{##2}{\hdstyle{##3}}}	% add title spanning multiple columns
 \newcommand{\lhdrx}[2]{\Head{##1}{|c}{##2}}		% set header for left column spanning #1 columns
 \newcommand{\chdrx}[2]{\Head{##1}{c}{##2}}			% set header for center column spanning #1 columns
 \newcommand{\rhdrx}[2]{\Head{##1}{c|}{##2}}		% set header for right column spanning #1 columns
 \newcommand{\ohdrx}[2]{\Head{##1}{|c|}{##2}}		% set header for only column spanning #1 columns
 \newcommand{\lhdr}[1]{\lhdrx{1}{##1}}				% set header for single left column
 \newcommand{\chdr}[1]{\chdrx{1}{##1}}				% set header for single center column
 \newcommand{\rhdr}[1]{\rhdrx{1}{##1}}				% set header for single right column
 \newcommand{\ohdr}[1]{\ohdrx{1}{##1}}
 \newcommand{\br}{\hfill\break}						% force newline within table entry

%% column styles
 \newcolumntype{x}[1]{>{\raggedright\let\\=\tabularnewline}p{##1}}	% word-wrapped ragged-right
 																	% column, width specified by #1
 % \newcolumntype{m}[1]{>{\CodeStyle}l{##1}}              % variable width column, all entries in CodeStyle
 \newcolumntype{m}[1]{l{##1}}							% variable width column, all entries in CodeStyle
}
{
}

% General Usage: TITLE is the title of the table, XREF is the
% cross-reference for the table. LAYOUT is a sequence of column
% type specifiers (e.g. cp{1.0}c), without '|' for the left edge
% or right edge.

% usage: \begin{floattablebase}{TITLE}{XREF}{COLUMNS}{PLACEMENT}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattablebase}[4]
{
 \begin{TableBase}
 \begin{table}[#4]
 \caption{\label{#2}#1}
 \begin{center}
 \begin{tabular}{|#3|}
}
{
 \bottomline
 \end{tabular}
 \end{center}
 \end{table}
 \end{TableBase}
}

% usage: \begin{floattable}{TITLE}{XREF}{COLUMNS}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattable}[3]
{
 \begin{floattablebase}{#1}{#2}{#3}{htbp}
}
{
 \end{floattablebase}
}

% usage: \begin{tokentable}{TITLE}{XREF}{HDR1}{HDR2}
% produces six-column table used for lists of replacement tokens;
% the columns are in pairs -- left-hand column has header HDR1,
% right hand column has header HDR2; pairs of columns are separated
% by vertical lines. Used in "trigraph sequences" table in standard.
\newenvironment{tokentable}[4]
{
 \begin{floattablebase}{#1}{#2}{cc|cc|cc}{htbp}
 \topline
 #3   &   #4    &
 #3   &   #4    &
 #3   &   #4    \\ \capsep
}
{
 \end{floattablebase}
}

% usage: \begin{libsumtabbase}{TITLE}{XREF}{HDR1}{HDR2}
% produces three-column table with column headers HDR1 and HDR2.
% Used in "Library Categories" table in standard, and used as
% base for other library summary tables.
\newenvironment{libsumtabbase}[4]
{
 \begin{floattable}{#1}{#2}{lll}
 \topline
 \lhdrx{2}{#3}	&	\hdstyle{#4}	\\ \capsep
}
{
 \end{floattable}
}

% usage: \begin{libsumtab}{TITLE}{XREF}
% produces three-column table with column headers "Subclause" and "Header(s)".
% Used in "C++ Headers for Freestanding Implementations" table in standard.
\newenvironment{libsumtab}[2]
{
 \begin{libsumtabbase}{#1}{#2}{Subclause}{Header(s)}
}
{
 \end{libsumtabbase}
}

% usage: \begin{LibSynTab}{CAPTION}{TITLE}{XREF}{COUNT}{LAYOUT}
% produces table with COUNT columns. Used as base for
% C library description tables
\newcounter{LibSynTabCols}
\newcounter{LibSynTabWd}
\newenvironment{LibSynTabBase}[5]
{
 \setcounter{LibSynTabCols}{#4}
 \setcounter{LibSynTabWd}{#4}
 \addtocounter{LibSynTabWd}{-1}
 \newcommand{\centry}[1]{\textbf{##1}:}
 \newcommand{\macro}{\centry{Macro}}
 \newcommand{\macros}{\centry{Macros}}
 \newcommand{\function}{\centry{Function}}
 \newcommand{\functions}{\centry{Functions}}
 \newcommand{\mfunctions}{\centry{Math Functions}}
 \newcommand{\cfunctions}{\centry{Classification/comparison Functions}}
 \newcommand{\type}{\centry{Type}}
 \newcommand{\types}{\centry{Types}}
 \newcommand{\values}{\centry{Values}}
 \newcommand{\struct}{\centry{Struct}}
 \newcommand{\cspan}[1]{\multicolumn{\value{LibSynTabCols}}{|l|}{##1}}
 \begin{floattable}{#1 \tcode{<#2>} synopsis}{#3}
 {#5}
 \topline
 \lhdr{Type}	&	\rhdrx{\value{LibSynTabWd}}{Name(s)}	\\ \capsep
}
{
 \end{floattable}
}

% usage: \begin{LibSynTab}{TITLE}{XREF}{COUNT}{LAYOUT}
% produces table with COUNT columns. Used as base for description tables
% for C library
\newenvironment{LibSynTab}[4]
{
 \begin{LibSynTabBase}{Header}{#1}{#2}{#3}{#4}
}
{
 \end{LibSynTabBase}
}

% usage: \begin{LibSynTabAdd}{TITLE}{XREF}{COUNT}{LAYOUT}
% produces table with COUNT columns. Used as base for description tables
% for additions to C library
\newenvironment{LibSynTabAdd}[4]
{
 \begin{LibSynTabBase}{Additions to header}{#1}{#2}{#3}{#4}
}
{
 \end{LibSynTabBase}
}

% usage: \begin{libsyntabN}{TITLE}{XREF}
%        \begin{libsyntabaddN}{TITLE}{XREF}
% produces a table with N columns for C library description tables
\newenvironment{libsyntab2}[2]
{
 \begin{LibSynTab}{#1}{#2}{2}{ll}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntab3}[2]
{
 \begin{LibSynTab}{#1}{#2}{3}{lll}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntab4}[2]
{
 \begin{LibSynTab}{#1}{#2}{4}{llll}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntab5}[2]
{
 \begin{LibSynTab}{#1}{#2}{5}{lllll}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntab6}[2]
{
 \begin{LibSynTab}{#1}{#2}{6}{llllll}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntabadd2}[2]
{
 \begin{LibSynTabAdd}{#1}{#2}{2}{ll}
}
{
 \end{LibSynTabAdd}
}

\newenvironment{libsyntabadd3}[2]
{
 \begin{LibSynTabAdd}{#1}{#2}{3}{lll}
}
{
 \end{LibSynTabAdd}
}

\newenvironment{libsyntabadd4}[2]
{
 \begin{LibSynTabAdd}{#1}{#2}{4}{llll}
}
{
 \end{LibSynTabAdd}
}

\newenvironment{libsyntabadd5}[2]
{
 \begin{LibSynTabAdd}{#1}{#2}{5}{lllll}
}
{
 \end{LibSynTabAdd}
}

\newenvironment{libsyntabadd6}[2]
{
 \begin{LibSynTabAdd}{#1}{#2}{6}{llllll}
}
{
 \end{LibSynTabAdd}
}

% usage: \begin{libsyntabfN}{TITLE}{XREF}
% produces a fixed width table with N columns for C library description tables
\newenvironment{libsyntabf2}[2]
{
 \begin{LibSynTab}{#1}{#2}{2}{p{1in}p{4in}}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntabf3}[2]
{
 \begin{LibSynTab}{#1}{#2}{3}{p{1in}p{.9in}p{2.9in}}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntabf5}[2]
{
 \begin{LibSynTab}{#1}{#2}{5}{p{.9in}p{.9in}p{.9in}p{.9in}p{.9in}}
}
{
 \end{LibSynTab}
}

\newenvironment{libsyntabf4}[2]
{
 \begin{LibSynTab}{#1}{#2}{4}{p{1in}p{.9in}p{.9in}p{1.8in}}
}
{
 \end{LibSynTab}
}

% usage: \begin{concepttable}{TITLE}{TAG}{LAYOUT}
% produces table at current location
\newenvironment{concepttable}[3]
{
 \begin{TableBase}
 \begin{table}[!htb]
 \caption[#1]{\label{tab:#2}\label{#2}#1 \textbf{[#2]}}
 \begin{center}
 \begin{tabular}{|#3|}
}
{
 \bottomline
 \end{tabular}
 \end{center}
 \end{table}
 \end{TableBase}
}

% usage: \begin{simpletypetable}{TITLE}{TAG}{LAYOUT}
% produces table at current location
\newenvironment{simpletypetable}[3]
{
 \begin{TableBase}
 \begin{table}[!htb]
 \caption{#1}\label{#2}
 \begin{center}
 \begin{tabular}{|#3|}
}
{
 \bottomline
 \end{tabular}
 \end{center}
 \end{table}
 \end{TableBase}
}

% usage: \begin{LongTable}{TITLE}{XREF}{LAYOUT}
% produces table that handles page breaks sensibly.
\newenvironment{LongTable}[3]
{
 \newcommand{\continuedcaption}{\caption[]{#1 (continued)}}
 \begin{TableBase}
 \begin{longtable}
 {|#3|}\caption{#1}\label{#2}
}
{
 \bottomline
 \end{longtable}
 \end{TableBase}
}

% usage: \begin{twocol}{TITLE}{XREF}
% produces a two-column breakable table. Used in
% "simple-type-specifiers and the types they specify" in the standard.
\newenvironment{twocol}[2]
{
 \begin{concepttable}
 {#1}{#2}
 {ll}
}
{
 \end{LongTable}
}

% usage: \begin{libreqtabN}{TITLE}{XREF}
% produces an N-column breakable table. Used in
% most of the library Clauses for requirements tables.
% Example at "Position type requirements" in the standard.

\newenvironment{libreqtab1}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.55\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab2}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {lx{.55\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab2a}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.30\hsize}x{.68\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.28\hsize}x{.18\hsize}x{.43\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3a}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.28\hsize}x{.33\hsize}x{.29\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3b}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.40\hsize}x{.25\hsize}x{.25\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3c}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.30\hsize}x{.25\hsize}x{.35\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3d}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.32\hsize}x{.27\hsize}x{.36\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3e}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.38\hsize}x{.27\hsize}x{.25\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab3f}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.40\hsize}x{.22\hsize}x{.31\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab4}[2]
{
 \begin{LongTable}
 {#1}{#2}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab4a}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.14\hsize}x{.30\hsize}x{.30\hsize}x{.14\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab4b}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.13\hsize}x{.15\hsize}x{.29\hsize}x{.27\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab4c}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.16\hsize}x{.21\hsize}x{.21\hsize}x{.30\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab4d}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.22\hsize}x{.22\hsize}x{.30\hsize}x{.15\hsize}}
}
{
 \end{LongTable}
}

\newenvironment{libreqtab5}[2]
{
 \begin{LongTable}
 {#1}{#2}
 {x{.14\hsize}x{.14\hsize}x{.20\hsize}x{.20\hsize}x{.14\hsize}}
}
{
 \end{LongTable}
}

% usage: \begin{libtab2}{TITLE}{XREF}{LAYOUT}{HDR1}{HDR2}
% produces two-column table with column headers HDR1 and HDR2.
% Used in "seekoff positioning" in the standard.
\newenvironment{libtab2}[5]
{
 \begin{floattable}
 {#1}{#2}{#3}
 \topline
 \lhdr{#4}	&	\rhdr{#5}	\\ \capsep
}
{
 \end{floattable}
}

% usage: \begin{longlibtab2}{TITLE}{XREF}{LAYOUT}{HDR1}{HDR2}
% produces two-column table with column headers HDR1 and HDR2.
\newenvironment{longlibtab2}[5]
{
 \begin{LongTable}{#1}{#2}{#3}
 \\ \topline
 \lhdr{#4}	&	\rhdr{#5}	\\ \capsep
 \endfirsthead
 \continuedcaption\\
 \topline
 \lhdr{#4}	&	\rhdr{#5}	\\ \capsep
 \endhead
}
{
  \end{LongTable}
}

% usage: \begin{LibEffTab}{TITLE}{XREF}{HDR2}{WD2}
% produces a two-column table with left column header "Element"
% and right column header HDR2, right column word-wrapped with
% width specified by WD2.
\newenvironment{LibEffTab}[4]
{
 \begin{libtab2}{#1}{#2}{lp{#4}}{Element}{#3}
}
{
 \end{libtab2}
}

% Same as LibEffTab except that it uses a long table.
\newenvironment{longLibEffTab}[4]
{
 \begin{longlibtab2}{#1}{#2}{lp{#4}}{Element}{#3}
}
{
 \end{longlibtab2}
}

% usage: \begin{libefftab}{TITLE}{XREF}
% produces a two-column effects table with right column
% header "Effect(s) if set", width 4.5 in. Used in "fmtflags effects"
% table in standard.
\newenvironment{libefftab}[2]
{
 \begin{LibEffTab}{#1}{#2}{Effect(s) if set}{4.5in}
}
{
 \end{LibEffTab}
}

% Same as libefftab except that it uses a long table.
\newenvironment{longlibefftab}[2]
{
 \begin{longLibEffTab}{#1}{#2}{Effect(s) if set}{4.5in}
}
{
 \end{longLibEffTab}
}

% usage: \begin{libefftabmean}{TITLE}{XREF}
% produces a two-column effects table with right column
% header "Meaning", width 4.5 in. Used in "seekdir effects"
% table in standard.
\newenvironment{libefftabmean}[2]
{
 \begin{LibEffTab}{#1}{#2}{Meaning}{4.5in}
}
{
 \end{LibEffTab}
}

% Same as libefftabmean except that it uses a long table.
\newenvironment{longlibefftabmean}[2]
{
 \begin{longLibEffTab}{#1}{#2}{Meaning}{4.5in}
}
{
 \end{longLibEffTab}
}

% usage: \begin{libefftabvalue}{TITLE}{XREF}
% produces a two-column effects table with right column
% header "Value", width 3 in. Used in "basic_ios::init() effects"
% table in standard.
\newenvironment{libefftabvalue}[2]
{
 \begin{LibEffTab}{#1}{#2}{Value}{3in}
}
{
 \end{LibEffTab}
}

% Same as libefftabvalue except that it uses a long table and a
% slightly wider column.
\newenvironment{longlibefftabvalue}[2]
{
 \begin{longLibEffTab}{#1}{#2}{Value}{3.5in}
}
{
 \end{longLibEffTab}
}

% usage: \begin{liberrtab}{TITLE}{XREF} produces a two-column table
% with left column header ``Value'' and right header "Error
% condition", width 4.5 in. Used in regex Clause in the TR.

\newenvironment{liberrtab}[2]
{
 \begin{libtab2}{#1}{#2}{lp{4.5in}}{Value}{Error condition}
}
{
 \end{libtab2}
}

% Like liberrtab except that it uses a long table.
\newenvironment{longliberrtab}[2]
{
 \begin{longlibtab2}{#1}{#2}{lp{4.5in}}{Value}{Error condition}
}
{
 \end{longlibtab2}
}
