diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/tab4tex/source |
Initial commit
Diffstat (limited to 'support/tab4tex/source')
-rw-r--r-- | support/tab4tex/source/compiler.inc | 22 | ||||
-rw-r--r-- | support/tab4tex/source/newline.inc | 25 | ||||
-rw-r--r-- | support/tab4tex/source/systype.inc | 16 | ||||
-rw-r--r-- | support/tab4tex/source/tab4tex.sno | 96 |
4 files changed, 159 insertions, 0 deletions
diff --git a/support/tab4tex/source/compiler.inc b/support/tab4tex/source/compiler.inc new file mode 100644 index 0000000000..15e0027b65 --- /dev/null +++ b/support/tab4tex/source/compiler.inc @@ -0,0 +1,22 @@ +* Compiler.inc +* Gregory White <glwhite@netconnect.com.au> +* Posted to the Snobol list (March 2003) +* and adapted as a function + + + DEFINE('COMPILER()') :(COMPILER_END) + +compiler + +IDprocessor :($('COMPILER' SIZE(DATE()))) + +COMPILER17 compiler = 'SPITBOL' :(return) + +COMPILER19 compiler = 'CSNOBOL4' :(return) + +COMPILER20 compiler = 'SNOBOL4+' :(return) + +compiler_end + +* Uses the different size of DATE() to detect the compiler used + diff --git a/support/tab4tex/source/newline.inc b/support/tab4tex/source/newline.inc new file mode 100644 index 0000000000..bb47722f64 --- /dev/null +++ b/support/tab4tex/source/newline.inc @@ -0,0 +1,25 @@ +* NEWLINE +* Checks OS and compiler type to set newline +* Part of this function uses a function posted by +* Gregory White <glwhite@netconnect.com.au> +* on the Snobol list in March 2003 +* Guido Milanese <guido.milanese@unicatt.it> + + define('newline()compiler_type') +-include "compiler.inc" +-include "systype.inc" + :(newline_end) + +newline +* Compiler being used. If it is Snobol4+, that does not have +* the HOST() function, assumes that the newline is Dos type + +snobol4 (compiler_type = compiler()) ? "SNOBOL4+" :f(other) + newline = char(13) char(10) :(return) + +* otherwise finds through HOST the OS type and sets newline +* accordingly +other newline = systype() :(return) +newline_end + + diff --git a/support/tab4tex/source/systype.inc b/support/tab4tex/source/systype.inc new file mode 100644 index 0000000000..2a4d7f81ca --- /dev/null +++ b/support/tab4tex/source/systype.inc @@ -0,0 +1,16 @@ +* SYSTYPE +* Sets new_line value according to OS +* Guido Milanese <guido.milanese@unicatt.it> +* March 2003 + + DEFINE('SYSTYPE()os') :(SYSTYPE_END) +SYSTYPE os = replace(host(),&UCASE,&LCASE) +UNIX os ? ('nix' | 'nux') :f(DOS) + systype = char(10) :(return) +DOS systype = char(13) char(10) :s(return) + :(freturn) +SYSTYPE_END + +* 'os' is the string returned by host(). +* The function does not work under snobol4+, requires Spitbol or CSnobol4. + diff --git a/support/tab4tex/source/tab4tex.sno b/support/tab4tex/source/tab4tex.sno new file mode 100644 index 0000000000..81f71ac071 --- /dev/null +++ b/support/tab4tex/source/tab4tex.sno @@ -0,0 +1,96 @@ +* TAB4TEX +* Guido Milanese 2007 <guido.milanese@unicatt.it> +* +* Usage: tab2tex.sno rows, align, vertical_bar, hline, complete +* First and second argument are compulsory, 3rd, 4th and 5th optional (simple y/n choice) +* Example: snobol4 -b tab4tex.sno r=7 a=c b=y h=y c=y <tab.txt >tab.tex +* outputs a table planned for 7 rows, centered, with '|' and hline, as a simple complete LaTeX document + +* Sets digits, newline and tabulator + digits = '1234567890' +-include "newline.inc" + (~(nl = newline()) (terminal = "Cannot set newline. Abort")) :s(end) + tab = char(9) +***************************************** +* Internal functions +* +* -- FORMAT LINES - Changes '*' and '!' to Bold and Emphasized + Define("format(datum)") :(format_end) +format +* Bold values + ( (datum ? pos(0) '*' = ) (datum ? rpos(1) '*' = ) ++ (datum = "\textbf{" datum '}')) :s(format_ret) +* Emphasized + ( (datum ? pos(0) '!' = ) (datum ? rpos(1) '!' = ) ++ (datum = "\emph{" datum '}')) :s(format_ret) +* Small caps + ( (datum ? pos(0) '^' = ) (datum ? rpos(1) '^' = ) ++ (datum = "\textsc{" datum '}')) :s(format_ret) + +format_ret format = datum :(return) +format_end + +**************************************** + +* Error messages + Em = "snobol4 -b tab4tex.sno r=7 a=c b=y h=y c=y <tab.txt >tab.tex" + Optmust = "You must set at least (1) number of rows and (2) alignment" ++ nl "e.g.: r=4 a=c. 'r' must be a number and 'a' one of l,r,c (= left, right, centre)" +* Options: +* Rows, alignment, separator '|' or empty, hlines or empty, complete LaTeX or not + Options = host(0) + s_Options = size(Options) + (~(gt(s_Options,0)) (terminal = Optmust)) :s(end) +* Rows + (~(Options ? "r=" span(digits) . nrows) (terminal = Optmust)) :s(end) +* Align + (~(Options ? "a=" any("lrcLRC") . align) (terminal = Optmust)) :s(end) +* Vertical bars (separator) + (~((Options ? "b=" any("yY") . sep) (sep = '|') ) (terminal = "No vertical bar required") ) +* Hlines + (~((Options ? "h=" any("yY") . hline) (hline = "\hline") (hline = nl hline)) (terminal = "No hline required") ) +* Complete LaTeX? + Complete = 'N' + (~((Options ? "c=" any("yY") . complete) ) (terminal = "Complete LaTeX document not required") ) + Complete = replace(Complete,&ucase,&lcase) + +* Builds data + data1 = sep align ;* separator and alignment + data = dupl(data1,nrows) ;* data (e.g. |c|c|c| ) + +* Complete LaTeX document required? + (leq(complete,('y'))) ++ (output = "\documentclass{article}" nl "\usepackage[T1]{fontenc}" nl "\begin{document}" nl) +* Table header + output = "\begin{tabular}" '{' data sep '}' tab nl hline + +* Main +MAIN +read line = trim(input) :f(endenv) + line ? (tab | "<M") :f(read) + line = line tab +split line ? break(tab) . cell len(1) rem . line :f(outrow) + +* Multicolumn cells (uses function Format) + ( ++ (cell ? pos(0) ( "<M" (span(digits) . number) '>' ) = ) ++ (cell = format(cell)) ++ (cell = "\multicolumn" '{' number '}' '{' sep align sep "}{" cell '}') ++ ) +* Normal cells (uses function Format) + cell = format(cell) + +* Builds row + (row = row cell tab '&' tab) :(split) +* Writes row +outrow + row ? rpos(3) (tab '&' tab) = +clean row "<E>" = ' ' :s(clean) + (output = row tab "\\" tab hline) (row = ) :(read) + terminal = row :(read) +endenv + output = "\end{tabular}" + (leq(complete,'y')) (output = nl "\end{document}") + +end + |