From 561b66275f186fcf8f3ed6e697e560f28354d38c Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph@amissah.com>
Date: Fri, 11 Jul 2014 00:05:23 -0400
Subject: v5 v6: ao_numbering, check that all auto given number based seg names
 are unique

---
 data/doc/sisu/CHANGELOG_v5  |  1 +
 data/doc/sisu/CHANGELOG_v6  |  1 +
 lib/sisu/v5/ao_numbering.rb | 10 +++++++++-
 lib/sisu/v6/ao_numbering.rb | 10 +++++++++-
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5
index 7eed7c3d..ca6fecf2 100644
--- a/data/doc/sisu/CHANGELOG_v5
+++ b/data/doc/sisu/CHANGELOG_v5
@@ -40,6 +40,7 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.5.0.orig.tar.xz
 
 * ao_numbering,
   * auto name segment, extract "number" from heading, fix
+  * check that all auto given number based seg names are unique
 
 %% 5.4.5.orig.tar.xz (2014-07-07:27/1)
 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_5.4.5
diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6
index 98358c7e..a1e1de70 100644
--- a/data/doc/sisu/CHANGELOG_v6
+++ b/data/doc/sisu/CHANGELOG_v6
@@ -30,6 +30,7 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.1.0.orig.tar.xz
 
 * ao_numbering,
   * auto name segment, extract "number" from heading, fix
+  * check that all auto given number based seg names are unique
 
 %% 6.0.11.orig.tar.xz (2014-07-07:27/1)
 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_6.0.11
diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb
index d213ca4d..dc6ec4dd 100644
--- a/lib/sisu/v5/ao_numbering.rb
+++ b/lib/sisu/v5/ao_numbering.rb
@@ -67,6 +67,7 @@ module SiSU_AO_Numbering
     def initialize(md,data)
       @md,@data=md,data
       @obj=@type=@ocn=@lv=@name=@index=@comment=nil
+      @chosen_seg_names=[]
     end
     def number_of_segments?
       if @@segments_count==0
@@ -323,7 +324,7 @@ module SiSU_AO_Numbering
         possible_seg_name=possible_seg_name.
           gsub(/\.$/,'')
       end
-      if possible_seg_name =~/^[0-9]+$/m \
+      chosen_seg_name=if possible_seg_name =~/^[0-9]+$/m \
       and possible_seg_name.to_i <= heading_num_is.to_i
         prefix + leading_zeros_fixed_width_number(possible_seg_name)
       elsif possible_seg_name =~/^[0-9][\d.,:-]*$/m
@@ -333,6 +334,13 @@ module SiSU_AO_Numbering
         prefix + possible_seg_name
       else prefix + possible_seg_name.to_s
       end
+      @chosen_seg_names << chosen_seg_name
+      if @chosen_seg_names.compact.uniq.length == @chosen_seg_names.compact.length #checks that all auto given seg names are unique
+        chosen_seg_name
+      else
+        SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark("duplicated auto segment name: #{chosen_seg_name}; manually name level 1 segments '1~given_name'")
+        exit
+      end
     end
     def name_para_seg_filename(data)                                                   #segment naming, remaining
       # paragraph name/numbering rules
diff --git a/lib/sisu/v6/ao_numbering.rb b/lib/sisu/v6/ao_numbering.rb
index ef85bbd6..5b2137e7 100644
--- a/lib/sisu/v6/ao_numbering.rb
+++ b/lib/sisu/v6/ao_numbering.rb
@@ -67,6 +67,7 @@ module SiSU_AO_Numbering
     def initialize(md,data)
       @md,@data=md,data
       @obj=@type=@ocn=@lv=@name=@index=@comment=nil
+      @chosen_seg_names=[]
     end
     def number_of_segments?
       if @@segments_count==0
@@ -323,7 +324,7 @@ module SiSU_AO_Numbering
         possible_seg_name=possible_seg_name.
           gsub(/\.$/,'')
       end
-      if possible_seg_name =~/^[0-9]+$/m \
+      chosen_seg_name=if possible_seg_name =~/^[0-9]+$/m \
       and possible_seg_name.to_i <= heading_num_is.to_i
         prefix + leading_zeros_fixed_width_number(possible_seg_name)
       elsif possible_seg_name =~/^[0-9][\d.,:-]*$/m
@@ -333,6 +334,13 @@ module SiSU_AO_Numbering
         prefix + possible_seg_name
       else prefix + possible_seg_name.to_s
       end
+      @chosen_seg_names << chosen_seg_name
+      if @chosen_seg_names.compact.uniq.length == @chosen_seg_names.compact.length #checks that all auto given seg names are unique
+        chosen_seg_name
+      else
+        SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark("duplicated auto segment name: #{chosen_seg_name}; manually name level 1 segments '1~given_name'")
+        exit
+      end
     end
     def name_para_seg_filename(data)                                                   #segment naming, remaining
       # paragraph name/numbering rules
-- 
cgit v1.2.3