Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/sets distrib/sets/fmt-list: add no-action mode



details:   https://anonhg.NetBSD.org/src/rev/d31120a2ce8c
branches:  trunk
changeset: 975936:d31120a2ce8c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Sep 08 19:11:30 2020 +0000

description:
distrib/sets/fmt-list: add no-action mode

This is useful for finding parse errors only.  Inspired by some entries
that are obsolete and have more than the "obsolete" flag.  There are
only few of these entries though, and they don't seem worth fixing.

diffstat:

 distrib/sets/fmt-list |  24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 9084487935f8 -r d31120a2ce8c distrib/sets/fmt-list
--- a/distrib/sets/fmt-list     Tue Sep 08 19:06:49 2020 +0000
+++ b/distrib/sets/fmt-list     Tue Sep 08 19:11:30 2020 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: fmt-list,v 1.1 2020/09/05 11:13:07 rillig Exp $
+-- $NetBSD: fmt-list,v 1.2 2020/09/08 19:11:30 rillig Exp $
 
 --[[
 
@@ -8,7 +8,7 @@
 
 Sort the lines and remove duplicate lines.
 
-usage: ./fmt-list */*/{mi,ad.*,md.*}
+usage: ./fmt-list [-n] */*/{mi,ad.*,md.*}
 
 ]]
 
@@ -405,7 +405,7 @@
 
 
 -- Load a file list, normalize it and write it back to disk.
-local function format_list(fname)
+local function format_list(fname, write_back)
   local head, entries, errors = read_list(fname)
   if #errors > 0 then
     for _, err in ipairs(errors) do
@@ -415,10 +415,22 @@
   end
 
   normalize(entries)
-  write_list(fname, head, entries)
+
+  if write_back then
+    write_list(fname, head, entries)
+  end
 end
 
 
-for _, fname in ipairs(arg) do
-  format_list(fname)
+local function main(arg)
+  local write_back = true
+  for _, fname in ipairs(arg) do
+    if fname == "-n" then
+      write_back = false
+    else
+      format_list(fname, write_back)
+    end
+  end
 end
+
+main(arg)



Home | Main Index | Thread Index | Old Index