暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cleantoc.rbARCHIV 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/ruby
  2. # -*- coding: utf-8 -*-
  3. # author: phi@gress.ly
  4. # version: 30. Okt. 2012 V 0.1
  5. #
  6. # Description
  7. #
  8. # Read a LaTeX - table of Contents (TOC) and remove all duplicaten
  9. # entries. Only the first entry is left
  10. # eg. From the lines
  11. # \contentsline {section}{Konzepte der Objektorientierung}{13}
  12. # \contentsline {section}{Konzepte der Objektorientierung}{13}
  13. # \contentsline {section}{Konzepte der Objektorientierung}{14}
  14. # \contentsline {section}{Konzepte der Objektorientierung}{15}
  15. # only the first line will remain
  16. #
  17. def main()
  18. lastLine = ""
  19. line = STDIN.gets
  20. while(line)
  21. if(isDuplicate(lastLine, line))
  22. line = STDIN.gets
  23. else
  24. print line
  25. lastLine = line
  26. line = STDIN.gets
  27. end
  28. end
  29. end
  30. ##
  31. #prüfe, ob zwei Einträgel den selben Titel gleich nacheinander haben. Wenn so, return "true"
  32. #
  33. def isDuplicate(l1, l2)
  34. treffer1 = l1.match("\\\\contentsline \\{section\\}\\{\\\\numberline \\{[A-Z0-9\\.]+\\}(.*)\\}\\{([0-9]+)\\}")
  35. if(treffer1)
  36. title1 = treffer1[1].strip
  37. end
  38. treffer2 = l2.match("\\\\contentsline \\{section\\}\\{(.*)\\}\\{([0-9]+)\\}")
  39. if(treffer2)
  40. title2 = treffer2[1].strip
  41. end
  42. if(treffer1 && treffer2)
  43. return title1 == title2;
  44. else
  45. return false
  46. end
  47. end
  48. main()