From 8ca77dd57913ae353faf39f26645f605e4f6c1b3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 3 Jun 2019 21:34:31 +0000 Subject: context-handlecsv (3jun19) git-svn-id: svn://tug.org/texlive/trunk@51306 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/doc/context/third/handlecsv/VERSION | 2 +- .../doc/context/third/handlecsv/handlecsv.epub | Bin 820273 -> 808121 bytes .../doc/context/third/handlecsv/handlecsv.pdf | Bin 201877 -> 201450 bytes .../context/third/handlecsv/t-handlecsv-extra.lua | 77 +++++++++++++++++++-- 4 files changed, 72 insertions(+), 7 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/context/third/handlecsv/VERSION b/Master/texmf-dist/doc/context/third/handlecsv/VERSION index 0aa983b950f..7a9e5ebcbc8 100644 --- a/Master/texmf-dist/doc/context/third/handlecsv/VERSION +++ b/Master/texmf-dist/doc/context/third/handlecsv/VERSION @@ -1 +1 @@ -2019.03.30 +2019.05.27 diff --git a/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.epub b/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.epub index 09a964a9e7e..9c84f899b58 100644 Binary files a/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.epub and b/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.epub differ diff --git a/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.pdf b/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.pdf index 5d4d8819c79..df145b21792 100644 Binary files a/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.pdf and b/Master/texmf-dist/doc/context/third/handlecsv/handlecsv.pdf differ diff --git a/Master/texmf-dist/tex/context/third/handlecsv/t-handlecsv-extra.lua b/Master/texmf-dist/tex/context/third/handlecsv/t-handlecsv-extra.lua index f6860e60e8f..1efdcbb06d5 100644 --- a/Master/texmf-dist/tex/context/third/handlecsv/t-handlecsv-extra.lua +++ b/Master/texmf-dist/tex/context/third/handlecsv/t-handlecsv-extra.lua @@ -1,14 +1,14 @@ -- %D \module -- %D [ file=t-handlecsv-extra.lua, --- %D version=2018.02.26, +-- %D version=2019.05.27, -- %D title=HandleCSV extra, -- %D subtitle=CSV file analysis - extended functions and macros, -- %D author=Jaroslav Hajtmar, --- %D date=2018-02-26, +-- %D date=2019-05-27, -- %D copyright=Jaroslav Hajtmar, -- %D license=GNU General Public License] -- --- %C Copyright (C) 2018 Jaroslav Hajtmar +-- %C Copyright (C) 2019 Jaroslav Hajtmar -- %C -- %C This program is free software: you can redistribute it and/or modify -- %C it under the terms of the GNU General Public License as published by @@ -61,6 +61,63 @@ end +-- function thirddata.handlecsv.cr_lines(s) +-- return s:gsub('\r\n?', '\n'):gmatch('(.-)\n') +-- end + + +function thirddata.handlecsv.file2Array(filename) +-- read CSV file into line array +local linesarray={} + for line in io.lines (filename) do + linesarray[#linesarray+1]=line + end +return linesarray +end + + + +function thirddata.handlecsv.writefileinreverseorder(inpfilename,outfilename) +-- write CSV file into reverse order CSV file + local tLines = thirddata.handlecsv.file2Array(inpfilename) + local outfile = io.open(outfilename, "w") + local ifrom=#tLines + local ito=1 + if thirddata.handlecsv.gCSVHeader then -- when CSV file is with header, then header line is first line + outfile:write(tLines[1]) + outfile:write("\r\n") + ito=2 + end + for i = ifrom, ito, -1 do -- write rest of lines in reverse order + outfile:write(tLines[i]) + outfile:write("\r\n") + end +outfile:flush() +outfile:close() +end + + + +function thirddata.handlecsv.deletefile(filename) +-- remove file from disk + os.remove(filename) +end + + +function thirddata.handlecsv.varreverseorder(csvfilename) +-- CSV file is stored in variable array gTableRows['csvfilename'][row][column] +-- this function rearrange gTableRows into reverse order +local templine={} +for i = 1, math.floor(thirddata.handlecsv.gNumRows[csvfilename]/2) do +templine=thirddata.handlecsv.gTableRows[csvfilename][i] +thirddata.handlecsv.gTableRows[csvfilename][i]=thirddata.handlecsv.gTableRows[csvfilename][thirddata.handlecsv.gNumRows[csvfilename]-i+1] +thirddata.handlecsv.gTableRows[csvfilename][thirddata.handlecsv.gNumRows[csvfilename]-i+1]=templine +end +end + + + + -- ConTeXt source: local string2print=[[% @@ -68,16 +125,24 @@ local string2print=[[% \def\addleading#1#2#3{\ctxlua{context(thirddata.handlecsv.addleadingcharacters('#1','#2','#3'))}} \def\addzeros#1#2{\ctxlua{context(thirddata.handlecsv.addleadingzeros('#1','#2'))}} \def\zeroed#1{\ctxlua{context(thirddata.handlecsv.addzeros('#1'))}} +% \def\zeroedlineno{\ctxlua{context(string.rep( "0",(tostring(thirddata.handlecsv.numrows())):len() - (tostring(thirddata.handlecsv.linepointer())):len()) .. thirddata.handlecsv.linepointer())}}% from Pablo \def\zeroedlineno{\zeroed{\lineno}}% from Pablo (and simplified by him) +\def\writefileinreverseorderfromto#1#2{\ctxlua{thirddata.handlecsv.writefileinreverseorder('#1','#2')}}% +\def\writecurrfileinreverseorderto#1{\ctxlua{thirddata.handlecsv.writefileinreverseorder(thirddata.handlecsv.gCurrentlyProcessedCSVFile,'#1')}}% +\def\deletefile#1{\ctxlua{thirddata.handlecsv.deletefile('#1')}}% +\def\reverseorderof#1{\ctxlua{thirddata.handlecsv.varreverseorder('#1')}} +\def\reverseorder{\ctxlua{thirddata.handlecsv.varreverseorder(thirddata.handlecsv.gCurrentlyProcessedCSVFile)}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Complete listing macros and commands that can be used (to keep track of all defined macros): %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % \addleading{}{}{}, \addzeros{}{}, \zeroed{}, \zeroedlineno (from Pablo) -% - - +% \writefileinreverseorderfromto{}{} % create file in reverse order of file +% \writecurrfileinreverseorderto{} % create file in reverse order +% \deletefile{} % close and delete file +% \reverseorderof{} % reverse order of opened CSV file +% \reverseorder % reverse order of currently processed CSV file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ]] -- cgit v1.2.3