Advertisement
Guest User

Untitled

a guest
May 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. checks
  2.     | newEntries newFields newMacros toBeDeleted toBeInclude error |
  3.    
  4.     macros := OrderedCollection new.
  5.     macrosUsage := Dictionary new.
  6.     entries := OrderedCollection new.
  7.    
  8.     errorStream := WriteStream on: String new.
  9.     [eof] whileFalse: [ self bibtexBlockToCZEntry: self getBibtexBlock ].
  10.  
  11.     newEntries := OrderedCollection new.
  12.     macroKeys := macros collect: [ :each | each key key ].
  13.    
  14.     entries do: [ :assoc |
  15.         toBeInclude := true.   
  16.         error := false.
  17.        
  18.         "checks if the type of the entry is a correct bibtex type"
  19.         (self checkBibtexType: assoc key)
  20.             ifFalse: [
  21.                 error := true.
  22.                 toBeInclude := false ].
  23.            
  24.         newFields := OrderedCollection new.
  25.         fieldKeys := OrderedCollection new.
  26.         assoc key fields do: [ :field |
  27.             toBeDeleted := false.
  28.            
  29.             "checks the macros referenced in the entry and removes fields with undefined macros"
  30.             (self checkMacroReferenced: field)
  31.                 ifFalse: [ toBeDeleted := true ].
  32.            
  33.             toBeDeleted ifFalse: [ 
  34.                 "removes empty fields"
  35.                 (self checkEmptyField: field)
  36.                     ifFalse: [ toBeDeleted := true ] ].
  37.  
  38.             "removes duplicate fields"
  39.             (self chechDuplicateField: field)
  40.                 ifFalse: [ toBeDeleted := true ].
  41.                
  42.             toBeDeleted
  43.                 ifFalse: [ newFields add: field ]
  44.                 ifTrue: [ error := true ]
  45.         ].
  46.         assoc key fields: newFields.
  47.        
  48.         "checks if the entry contains all the fields needed by it's type"
  49.         ((typeFieldsMatching at: (assoc key type)) value: (assoc key fields collect: [ :each | each key ]))
  50.             ifFalse: [
  51.                 errorStream nextPutAll: 'Error: Entry does not contain all needed fields'; cr.
  52.                 error := true.
  53.                 toBeInclude := false ].
  54.        
  55.         "checks if the key is unique and changes it if it's not"
  56.         keys at: assoc key key put: ((keys at: assoc key key ifAbsent: 0) + 1).
  57.         ((keys at: assoc key key) > 1)
  58.             ifTrue: [ | key |
  59.                 key := assoc key key.
  60.                 assoc key key: '###',(assoc key key, '_',(keys at: assoc key key) asString,'###' ).
  61.                 errorStream nextPutAll: 'Warning: duplicate key: ', key, ' changed to: ', assoc key key; cr.
  62.         error := true ].
  63.        
  64.         "checks if the entry respects all the rules"   
  65.         rules do: [ :rule |
  66.             (rule value value: assoc key)
  67.                 ifFalse: [
  68.                     errorStream nextPutAll: 'Error : entry does not respect the rule: ', rule key; cr.
  69.                     error := true.
  70.                     toBeInclude := false ] ].  
  71.        
  72.         "displays the errors and creates the collection with safe entries"
  73.         error ifTrue: [
  74.             errorStream nextPut: Character tab; nextPutAll: 'for :'; cr; nextPutAll: assoc value; cr.
  75.             toBeInclude
  76.                 ifTrue: [
  77.                     newEntries add: assoc key.
  78.                     errorStream nextPutAll: '(There are only warnings, the entry is not deleted)'; cr; cr ]
  79.                 ifFalse: [
  80.                     errorStream nextPutAll: '(There are errors, the entry is deleted)'; cr; cr ]
  81.         ]
  82.     ].
  83.  
  84.     "removes unused macros"
  85.     newMacros := OrderedCollection new.
  86.     macros do: [ :assoc |
  87.         (macrosUsage at: assoc key key)
  88.             ifFalse: [ errorStream nextPutAll: 'Unused macro:'; cr; nextPutAll: assoc value; cr; cr ]
  89.             ifTrue: [  newMacros add: assoc ]  
  90.     ].
  91.     macros := newMacros
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement