[latex3-commits] [git/l3build] manifest: manifest: function argument streamlining and general formatting (d4f2886)

Will Robertson wspr81 at gmail.com
Tue Dec 26 03:52:59 CET 2017


Repository : https://github.com/latex3/l3build
On branch  : manifest
Link       : https://github.com/latex3/l3build/commit/d4f2886cfaa897dd7b9e5228018431246f609f7c

>---------------------------------------------------------------

commit d4f2886cfaa897dd7b9e5228018431246f609f7c
Author: Will Robertson <wspr81 at gmail.com>
Date:   Tue Dec 26 10:52:59 2017 +0800

    manifest: function argument streamlining and general formatting


>---------------------------------------------------------------

d4f2886cfaa897dd7b9e5228018431246f609f7c
 l3build-manifest-setup.lua |   69 +++++++++++++++++++++++---------------------
 l3build-manifest.lua       |   44 ++++++++++++++--------------
 2 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/l3build-manifest-setup.lua b/l3build-manifest-setup.lua
index 1913cde..fbdfdff 100644
--- a/l3build-manifest-setup.lua
+++ b/l3build-manifest-setup.lua
@@ -151,25 +151,24 @@ manifest_write_opening = manifest_write_opening or function(filehandle)
 
 end
 
-manifest_write_group_heading = manifest_write_group_heading or function (filehandle,heading)
+manifest_write_group_heading = manifest_write_group_heading or function (filehandle,heading,description)
 
    filehandle:write("\n## " .. heading .. "\n\n")
    
-end
-
-manifest_write_group_description = manifest_write_group_description or function(filehandle,description)
--- Redefine as a no-op if you don't like each group to have a written description.
-
-  filehandle:write(description .. "\n")
+   if description then
+     filehandle:write(description .. "\n")
+   end
   
 end
 
-manifest_write_group_file = manifest_write_group_file or function(filehandle,count,filename,Nchar)
+manifest_write_group_file = manifest_write_group_file or function(filehandle,filename,param)
   --[[
-        filehandle : write file object
-             count : the count of the filename to be written
-          filename : the name of the file to write
-             Nchar : the maximum number of chars of all filenames in this group
+        filehandle        : write file object
+        filename          : the count of the filename to be written
+        
+        param.dir         : the directory of the file
+        param.count       : the name of the file to write
+        param.filemaxchar : the maximum number of chars of all filenames in this group
   --]]
 
   -- no file description: plain bullet list item:
@@ -177,32 +176,37 @@ manifest_write_group_file = manifest_write_group_file or function(filehandle,cou
 
   --[[
     -- or if you prefer an enumerated list:
-    filehandle:write(count..". " .. filename .. "\n")
+    filehandle:write(param.count..". " .. filename .. "\n")
   --]]
 
 
 end
 
-manifest_write_group_file_descr = manifest_write_group_file_descr or function(filehandle,count,filename,Nchar,descr,NcharD)
+manifest_write_group_file_descr = manifest_write_group_file_descr or function(filehandle,filename,descr,param)
   --[[
-        filehandle : write file object
-             count : the count of the filename to be written
-          filename : the name of the file to write
-             Nchar : the maximum number of chars of all filenames in this group
-             descr : description of the file to write
-            NcharD : the maximum number of chars of all descriptions in this group
+        filehandle        : write file object
+        filename          : the name of the file to write
+        descr             : description of the file to write
+        
+        param.dir         : the directory of the file
+        param.count       : the count of the filename to be written
+        param.filemaxchar : the maximum number of chars of all filenames in this group
+        param.descmaxchar : the maximum number of chars of all descriptions in this group
   --]]
 
   -- filename+description: Github-flavoured Markdown table
 
-  if count==1 then
-    -- header of table
-    manifest_write_group_file_descr(filehandle,-1,"File",Nchar,"Description",NcharD)
-    manifest_write_group_file_descr(filehandle,-1,"---", Nchar,"---",        NcharD)
+  -- header of table
+  if param.count == 1 then
+    local p = param
+    p.count = -1
+    manifest_write_group_file_descr(filehandle,"File","Description",p)
+    manifest_write_group_file_descr(filehandle,"---","---",p)
   end
 
+  -- entry
   filehandle:write(string.format(
-    "  | %-"..Nchar .."s | %-"..NcharD.."s |\n",
+    "  | %-"..param.filemaxchar.."s | %-"..param.descmaxchar.."s |\n",
     filename,descr))
 
 end
@@ -221,29 +225,28 @@ end
 -- From the first match of a pattern in a file:
 manifest_extract_filedesc = function(filehandle)
 
-  local read_string   = "*all"
-  local matchstr      = "\\section{(.-)}"
-
-  all_file = filehandle:read(read_string)
+  local all_file = filehandle:read("*all")
+  local matchstr = "\\section{(.-)}"
 
-  return string.match(all_file,matchstr)
+  filedesc = string.match(all_file,matchstr)
   
+  return filedesc
 end
 
 -- From the match of the 2nd line (say) of a file:
 manifest_extract_filedesc = function(filehandle)
 
   local end_read_loop = 2
-  local read_string   = "*line"
   local matchstr      = "%%%S%s+(.*)"
   local this_line     = ""
 
   for ii = 1, end_read_loop do
-    this_line = filehandle:read(read_string)
+    this_line = filehandle:read("*line")
   end
   
-  return string.match(this_line,matchstr)
+  filedesc = string.match(this_line,matchstr)
 
+  return filedesc
 end
 
 ]]--
diff --git a/l3build-manifest.lua b/l3build-manifest.lua
index 22971a0..72cd807 100644
--- a/l3build-manifest.lua
+++ b/l3build-manifest.lua
@@ -134,7 +134,6 @@ end
 
 manifest_build_file = function(entry,this_file)
 
-  -- rename?
   if entry.rename then
     this_file:gsub(entry.rename[1], entry.rename[2])
   end
@@ -146,24 +145,22 @@ manifest_build_file = function(entry,this_file)
     
       entry.matches[this_file] = true -- store the file name
       entry.files_ordered[entry.N] = this_file -- store the file order
-
-      entry.Nchar_file = math.max( entry.Nchar_file , this_file:len() )
+      entry.Nchar_file = math.max(entry.Nchar_file,this_file:len())
       
     end
 
     if not(entry.rename) and entry.extractfiledesc then
     
       local ff = assert(io.open(entry.dir .. "/" .. this_file, "r"))
-      this_descr = manifest_extract_filedesc(ff)
+      this_descr  = manifest_extract_filedesc(ff,this_file)
       ff:close()
 
       if this_descr and this_descr ~= "" then
-
         entry.descr[this_file] = this_descr
         entry.ND = entry.ND+1
-        entry.Nchar_descr = math.max( entry.Nchar_descr, this_descr.len() )
-
+        entry.Nchar_descr = math.max(entry.Nchar_descr,this_descr:len())
       end
+      
     end
   end
 
@@ -194,27 +191,30 @@ end
 
 manifest_write_group = function(f,entry)
 
-  manifest_write_group_heading(f,entry.name)
-
-  if entry.description then
-    manifest_write_group_description(f,entry.description)
-  end
+  manifest_write_group_heading(f,entry.name,entry.description)
 
-  if not(entry.rename) and entry.extractfiledesc and entry.ND > 0 then
+  if entry.ND > 0 then
 
-    local C = 0
-    for _,file in ipairs(entry.files_ordered) do
-      C = C+1
-      descr = entry.descr[file] or ""
-      manifest_write_group_file_descr(f,C,file,entry.Nchar_file,descr,entry.Nchar_descr)
+    for ii,file in ipairs(entry.files_ordered) do
+      local descr = entry.descr[file] or ""
+      local param = {
+        dir         = entry.dir         ,
+        count       = ii                ,
+        filemaxchar = entry.Nchar_file  ,
+        descmaxchar = entry.Nchar_descr ,
+      }
+      manifest_write_group_file_descr(f,file,descr,param)
     end
 
   else
 
-    local C = 0
-    for _,ff in ipairs(entry.files_ordered) do
-      C = C+1
-      manifest_write_group_file(f,C,ff,entry.Nchar_file)
+    for ii,file in ipairs(entry.files_ordered) do
+      local param = { 
+        dir         = entry.dir        ,
+      	count       = ii               , 
+      	filemaxchar = entry.Nchar_file ,
+      }
+      manifest_write_group_file(f,file,param)
     end
 
   end





More information about the latex3-commits mailing list