Snmpmerge

203 views

Published on

A tool to consolidate multiple snmp files and resolve conflicts.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
203
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Snmpmerge

  1. 1. Introduction Assumptions Merging SNMP Files Details Source Listing angarajan R adhakrishnan October 11, 2009 Home Page Title Page Page 1 of 17 Go Back Full Screen Close Quit
  2. 2. 1. Introduction Introduction This document discusses a utility to merge SNMP files. The goal is to create a con- Assumptions solidated SNMP file without conflicts whose entries are sorted first by OID and then Details by the enterprise name. A conflict is said to occur when two or more entries in the Source Listing file have the same enterprise name and OID combination. When entries with same enterprise name and OID combination are encountered, and if no prefer entry
  3. 3. le is specified, the first entry overrides all other conflicting entries. If prefer entry
  4. 4. le is specified then the entry in that file overrides other entries involved in the conflict. Home Page The utility can also be used to delete specific entries by specifying an delete file con- sisting of entries to be deleted or a prefer file consisting of entries that are preferred Title Page over other entries with same enterprise name, OID combination. When comparing two OIDs (OID1 = a1 .a2 . . . am and OID2 = b1 .b2 . . . bn ), OID1 < OID2 if one of the following is true. • ∃ smallest possible i such that ai < bi for some i ∈ {1, . . . , min(m, n)} and, Page 2 of 17 if i > 1, ak = bk for k ∈ {1, . . . , (i − 1)} • if the above does not hold true then m <= n Go Back Some examples are (the OIDs listed may not be valid OIDs but illustrate the concept): Full Screen • 1.2.3.4.5 < 1.2.10.3.1 Close • 1.2.3.4.5 < 1.2.3.4.5.6 Quit • 10.1.3.4 < 19.4.3.1
  5. 5. 2. Assumptions Introduction The following are the assumptions regarding input SNMP (includes prefer and delete) Assumptions files. The assumptions are given below: Details • Each SNMP file is syntactically correct Source Listing • The main input to the merge process is a master file and, optionally, either a prefer file or a delete file. Home Page • The master file itself may be a simple concatenation of one or more SNMP files. • Master file may contain comments (C-language style) Title Page • (For simplicity) the delete file or prefer file do not have comments. This is not a major issue as it is easy to strip comments from such files. • You have gcc installed on the system where merge is being performed Page 3 of 17 • Each uncommented entry in the SNMP file has one of the following types: – level 1 entry - enterprise name OID description. We detect a level Go Back 1 entry when when encounter a line that is not enclosed in a block and Full Screen matches the regex: ^s*(w+)s+(d+(.d+)*)s+.*$ Close where: $1 −→ enterprise name Quit $2 −→ OID
  6. 6. – level 2 or above entry - This is associated with a level 1 entry and is usually enclosed in the block (within parenthesis or braces). We keep track of Introduction levels using the difference between counts of open and close parenthesis (or Assumptions braces) and when this drops back to zero, we expect to start seeing a level Details 1 entry. Source Listing • The command line invocation of the tool is: do rrsnmp merge.sh [ -d delete entry
  7. 7. le | -p prefer entry
  8. 8. le ] master
  9. 9. le Home Page where: Title Page delete entry
  10. 10. le → file containing entries to be deleted − prefer entry
  11. 11. le → file containing entries to be preferred − master
  12. 12. le −→ file considered master file Page 4 of 17 Go Back Full Screen Close Quit
  13. 13. 3. Details Introduction We read the master file and setup a hash whose key field is the formatted OID and Assumptions enterprise name combination. The value corresponding to the key field is the entire Details level 1 line and, if applicable, the entire block following the level one entry (which Source Listing may comprise of level 2 and higher level entries. The formatting of OID to use as part of key value is done in order to help us sort the hash before generating the final merged output. If specified, the prefer entry
  14. 14. le is read and results in either adding new hash keys (and corresponding values) or, in case of conflict, overwriting hash key Home Page entries built from the master file. If instead of prefer entry
  15. 15. le a delete entry
  16. 16. le is used, then this file is read and some hash keys are eliminated if they exist in the hash Title Page built up by reading the master file. If neither delete entry
  17. 17. le nor prefer entry
  18. 18. le is specified, then the resulting output of merge is consolidated master file, sans any duplicates. Formatting of an OID of the form a1 .a2 . . . .am involves formatting each ai (for i ∈ {1, . . . , m}) to a zero padded seven digit number. Some examples are: Page 5 of 17 1.2.30 0000001.0000002.0000030 11.200.3.4 0000011.0000200.0000003.0000004 Go Back This formatting enables using OID and enterprise name (joined by ”:”) as a key and Full Screen during sorting the ordering of the composite key is determined by first comparing the formatted OIDs and, if same, comparing enterprise names. Close If the OID and enterprise name combination is the same then the hash key, which is Quit formatted OID and enterprise name combined using ”:” is the same. Since hashes ensure that keys are unique, any such conflict will have to be resolved.
  19. 19. In absence of a delete entry
  20. 20. le or prefer entry
  21. 21. le, we use the approach that if a hash key already exists, we do not modify the value corresponding to hash key. Introduction This results in first occurrence wins. If prefer entry
  22. 22. le is specified, we read the Assumptions entries from that file and overwrite the hash keys (and corresponding values) in case of Details conflicts. The assumption is that there are no conflicts within the prefer entry
  23. 23. le. If delete entry
  24. 24. le is used instead then we explicitly remove hash entries based on the Source Listing key entries that we compute by reading the file. The utility is a shell script that invokes a perl script. The shell script is used to preprocess the input master file using gcc (GNU C compiler) to eliminate C type Home Page comments from the SNMP master file. The shell script then passes these options Title Page along to the perl script (rrsnmp merge.pl) to perform the merge task which eliminates duplicates (based on OID and enterprise name combination). Page 6 of 17 Go Back Full Screen Close Quit
  25. 25. 4. Source Listing Introduction Listing 1: do rrsnmp merge.sh § ¤ Assumptions #!/usr/bin/ksh 1 Details 2 PROGRAM NAME=” ${0##∗/}” 3 Source Listing 4 USAGE STRING=”USAGE : $PROGRAM NAME [ −d <d e l e t e e n t r y f i l e> | −p 5 <p r e f e r e n t r y f i l e> ] <m a s t e r f i l e>” 6 7 USAGE STRING=” ${USAGE STRING}nwhere : n” 8 9 USAGE STRING=” ${USAGE STRING} <d e l e t e e n t r y f i l e> i s t h e file 10 c o n t a i n i n g e n t r i e s t o be d e l e t e d n” 11 12 Home Page USAGE STRING=” ${USAGE STRING} <p r e f e r e n t r y f i l e> i s t h e file 13 c o n t a i n i n g e n t r i e s t h a t a r e p r e f e r r e d n” 14 15 USAGE STRING=” ${USAGE STRING} <m a s t e r f i l e> i s t h e e x i s t i n g m a s t e r 16 Title Page f i l e n” 17 18 w h i l e g e t o p t s : d : p : h OPTION do 19 c a s e $OPTION i n 20 d) DELETE ENTRY FILE=”$OPTARG” 21 ;; 22 23 p) PREFER ENTRY FILE=”$OPTARG” 24 ;; 25 26 h) # Display the help and exit 27 Page 7 of 17 p r i n t −u1 ”$USAGE STRING” 28 e x i t 100 29 ;; 30 31 Go Back ?) 32 p r i n t −u2 ”ERROR ($PROGRAM NAME ) : $LINENO : I n v a l i d option ’$OPTARG’ s p e c i f i e d w i t h $PROGRAM NAME” 33 p r i n t −u2 ”$USAGE STRING” 34 OPTION ERROR=”Y” 35 Full Screen e x i t 101 36 ;; 37 38 :) 39 Close p r i n t −u2 ”ERROR ($PROGRAM NAME ) : $LINENO : O p t i o n ’$OPTARG’ r e q u i r e s an a r g u me nt ” 40 p r i n t −u2 ”$USAGE STRING” 41 OPTION ERROR=”Y” 42 e x i t 102 43 Quit ;; 44 esac 45 done 46
  26. 26. 47 s h i f t $ ( ( $OPTIND − 1 ) ) 48 49 i f [ [ ”$DELETE ENTRY FILE” != ” ” ] ] && [ [ ”$PREFER ENTRY FILE” != ” ” 50 ] ] then 51 Introduction p r i n t −u2 ”ERROR : E i t h e r d e l e t e e n t r y f i l e o r p r e f e r e n t r y f i l e must be u s e d . NOT b o t h . ” 52 p r i n t −u2 ”$USAGE STRING” 53 Assumptions exit 1 54 fi 55 Details 56 i f [ [ ”$DELETE ENTRY FILE” != ” ” ] ] && [ [ ! −r ”$DELETE ENTRY FILE” 57 Source Listing ] ] then 58 p r i n t −u2 ”ERROR : d e l e t e e n t r y f i l e ”$DELETE ENTRY FILE” d o e s n o t e x i s t o r i s n o t r e a d a b l e ” 59 exit 2 60 fi 61 62 i f [ [ ”$PREFER ENTRY FILE” != ” ” ] ] && [ [ ! −r ”$PREFER ENTRY FILE” 63 ] ] then 64 p r i n t −u2 ”ERROR : p r e f e r e n t r y f i l e ”$PREFER ENTRY FILE” d o e s n o t e x i s t o r i s n o t r e a d a b l e ” 65 exit 3 66 Home Page fi 67 68 if (( $ #= 0 )) then = 69 Title Page p r i n t −u2 ”ERROR : I n s u f f i c i e n t number o f a r g u m e n t sn” 70 p r i n t −u2 ”$USAGE STRINGn” 71 exit 4 72 fi 73 74 MASTER ENTRY FILE=” $1 ” 75 76 if [ [ ! −r ”$MASTER ENTRY FILE” ] ] t h e n 77 p r i n t −u2 ”ERROR : m a s t e r e n t r y f i l e ”$MASTER ENTRY FILE” d o e s n o t e x i s t o r i s n o t r e a d a b l e ” 78 exit 5 79 fi 80 81 Page 8 of 17 if [ [ ”$DELETE ENTRY FILE” != ” ” ] ] t h e n 82 NEW DELETE ENTRY FILE=” d e l e t e e n t r y f i l e $ $ . c ” 83 FMT DELETE ENTRY FILE=” d e l e t e e n t r y f i l e $ $ . fmt ” 84 85 Go Back cp −p $DELETE ENTRY FILE $NEW DELETE ENTRY FILE 86 87 g c c −E −P $NEW DELETE ENTRY FILE > $FMT DELETE ENTRY FILE 88 89 Full Screen r r s n m p m e r g e . p l −d $FMT DELETE ENTRY FILE $MASTER ENTRY FILE 90 91 elif [ [ ”$PREFER ENTRY FILE” != ” ” ] ] t h e n 92 NEW PREFER ENTRY FILE=” p r e f e r e n t r y f i l e $ $ . c ” 93 Close FMT PREFER ENTRY FILE=” p r e f e r e n t r y f i l e $ $ . fmt ” 94 95 cp −p $PREFER ENTRY FILE $NEW PREFER ENTRY FILE 96 Quit 97 g c c −E −P $NEW PREFER ENTRY FILE > $FMT PREFER ENTRY FILE 98 99
  27. 27. r r s n m p m e r g e . p l −p $FMT PREFER ENTRY FILE $MASTER ENTRY FILE 100 else 101 r r s n m p m e r g e . p l $MASTER ENTRY FILE 102 fi 103 Introduction ¦ Assumptions Details Source Listing Home Page Title Page Page 9 of 17 Go Back Full Screen Close Quit
  28. 28. Listing 2: rrsnmp merge.pl § ¤ #!/usr/bin/perl −w 1 2 Introduction u s e G e t o p t : : Std ; 3 4 Assumptions use s t r i c t ; 5 6 Details my $program name = $0 ; 7 8 $program name =˜ s : ˆ . ∗ / : : ; 9 Source Listing 10 my %h ; 11 my %d u p l h ; 12 my %g ; 13 my %q ; 14 my %d u p l q ; 15 my %p ; 16 17 Home Page my $ f l a g = 0 ; 18 19 my $ o r g l i n e = u n d e f ; 20 21 Title Page my $orgname = u n d e f ; 22 23 my $ o r g o i d = u n d e f ; 24 25 my $ o r g r e s t = u n d e f 26 27 my $ o i d = u n d e f ; 28 29 my $ l i n e = u n d e f ; 30 31 my $ o i d d u p l f l a g = 0 ; # oid is a duplicate entry or N T (0) O 32 33 Page 10 of 17 my $ o i d n a m e d u p l f l a g = 0 ; # oidname is a duplicate entry or N T (0) O 34 35 my $ d u p o i d n a m e f i l e = ” d u p o i d n a m e . o u t ” ; 36 Go Back 37 my $ u n i q o i d n a m e f i l e = ” u n i q o i d n a m e . o u t ” ; 38 39 my $ d u p o i d f i l e = ” d u p o i d . o u t ” ; 40 Full Screen 41 my $ u n i q o i d f i l e = ” u n i q o i d . o u t ” ; 42 43 #− − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 44 Close # subroutine: usage # Indicates the usage for the program 45 #− − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 46 sub usage ( ) { 47 p r i n t STDERR < ”EOF” ; < 48 Quit 49 T h i s program d o e s . . . 50 51
  29. 29. u s a g e : $program name [−h | −p p r e f e r r e d f i l e | −d d e l e t e f i l e ] master file 52 53 −h : t h i s ( h e l p ) message 54 −p f i l e : preferred f i l e 55 −d f i l e : delete f i l e 56 Introduction 57 e x a m p l e s : $program name −p f i l e 58 Assumptions e x a m p l e s : $program name −d f i l e 59 60 Details EOF 61 exit 1; 62 Source Listing } 63 64 65 sub by oid name { 66 my ( $a1 , $a2 , $b1 , $b2 ) ; 67 68 i f ( $a =˜ / ˆ ( . ∗ ) : ( . ∗ ) $ / ) 69 { 70 $a1 = $1 ; $a2 = $2 ; 71 Home Page } 72 i f ( $b =˜ / ˆ ( . ∗ ) : ( . ∗ ) $ / ) 73 { 74 $b1 = $1 ; $b2 = $2 ; 75 Title Page } 76 r e t u r n ( ( $a1 cmp $b1 ) | | ( $a2 cmp $b2 ) ) ; 77 78 } 79 80 my %o p t ; 81 my $ o p t s t r i n g = ” hd : p : ” ; 82 83 g e t o p t s ( ” $ o p t s t r i n g ” , %o p t ) o r u s a g e ( ) ; 84 85 i f ( $ o p t{d} && $ o p t{p}) { 86 Page 11 of 17 p r i n t ”ERROR ( $program name ) : E i t h e r o p t i o n d o r o p t i o n p s h o u l d be u s e d . Not b o t hn” ; 87 usage ( ) ; 88 } 89 90 Go Back i f ( $ o p t{d} && ! −r $ o p t{d} ) { 91 p r i n t qq{ERROR ( $program name ) : Specified delete f i l e ” $ o p t{d}” d o e s NOT e x i s t o r i s NOT r e a d a b l e n }; 92 exit 2; 93 } i f ( $ o p t{p} && ! −r $ o p t{p} ) { 94 Full Screen p r i n t qq{ERROR ( $program name ) : Specified preferred f i l e ” $ o p t{p}” d o e s NOT e x i s t o r i s NOT r e a d a b l e n }; 95 exit 3; 96 } 97 98 Close i f (@ARGV == 0 ) { 99 p r i n t qq{ERROR ( $program name ) : m a s t e r f i l e NOT s p e c i f i e d n }; 100 usage ( ) ; 101 } 102 Quit 103 if ( ! −r $ARGV [ 0 ] ) { 104 p r i n t qq{ERROR ( $program name ) : S p e c i f i e d master f i l e ”$ARGV [ 0 ] ” d o e s NOT e x i s t o r i s NOT r e a d a b l e n }; 105
  30. 30. exit 4; 106 } 107 108 #− − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 109 Introduction # Make the preferred f i l e to be the first f i l e to read. # This way 110 we e n s u r e t h a t i t s e n t r i e s take precedence 111 Assumptions #− − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 112 i f ( $ o p t{p}) { 113 u n s h i f t (@ARGV, $ o p t{p } ) ; 114 Details } 115 116 Source Listing 117 w h i l e (<>) { 118 chomp ; 119 120 i f (/ˆ s∗$ / ) 121 { 122 next ; 123 } 124 Home Page e l s i f (/ˆ s ∗ [ ( { ] / ) # i f the line starts with an opening parenthesis or brace 125 { 126 # The assumption here is that you have either an open brace or a parenthesis 127 # on a line by itself and nothing else (except spaces) 128 Title Page 129 # The level of nesting of brace/parenthesis tracked 130 # the assumption is that withing a pair of braces you wont have a 131 # parenthesis and vice− versa 132 $ f l a g ++; # increment the brace/parenthesis level 133 134 # Have we encountered an oid name combination that is N T already seen O 135 i f ( $ o i d n a m e d u p l f l a g == 0 ) 136 { 137 $g{” $ o i d : $orgname ”} .= ” $ n” ; 138 $h{” $ o i d : $orgname ”} .= ” $ n” ; 139 Page 12 of 17 } 140 else 141 { 142 $ d u p l h{” $ o i d : $orgname ”} .= ” $ n” ; 143 Go Back } 144 145 ## # #Begin: OID is duplicate # ### 146 Full Screen # Have we encountered an oid that is N T already seen O 147 i f ( $ o i d d u p l f l a g == 0 ) 148 { 149 $p{” $ o i d ”} .= ” $ n” ; # Add the line to whatever lines are already associated with oid 150 Close $q{” $ o i d ”} .= ” $ n” ; 151 } 152 else 153 { 154 Quit $ d u p l q{” $ o i d ”} .= ” $ n” ; 155 } 156 ## # #End: OID is duplicate # # ## 157
  31. 31. 158 } 159 e l s i f (/ˆ s ∗ [ ) } ] / ) # i f the line starts with a closing parenthesis or brace 160 { 161 Introduction # The assumption here is that you have either an open brace or a parenthesis 162 # on a line by itself and nothing else (except spaces) 163 Assumptions 164 $ f l a g − # decrement −; the brace/parenthesis level 165 Details 166 # Have we encountered an oid name combination that is N T already seen O 167 Source Listing i f ( $ o i d n a m e d u p l f l a g == 0 ) 168 { 169 $g{” $ o i d : $orgname ”} .= ” $ n” ; 170 $h{” $ o i d : $orgname ”} .= ” $ n” ; 171 } 172 else 173 { 174 $ d u p l h{” $ o i d : $orgname ”} .= ” $ n” ; 175 } 176 Home Page ## # #Begin: OID is duplicate # # # ### ## 177 # Have we encountered an oid name combination that is N T already seen O 178 i f ( $ o i d d u p l f l a g == 0 ) 179 { 180 Title Page $p{” $ o i d ”} .= ” $ n” ; 181 $q{” $ o i d ”} .= ” $ n” ; 182 } 183 else 184 { 185 $ d u p l q{” $ o i d ”} .= ” $ n” ; 186 } 187 ## # #End: OID is duplicate # # # ### ## 188 } 189 e l s i f ( $ f l a g > 0) 190 { 191 Page 13 of 17 # Have we encountered an oid name combination that is N T already seen O 192 i f ( $ o i d n a m e d u p l f l a g == 0 ) 193 { 194 $g{” $ o i d : $orgname ”} .= ” $ n” ; 195 Go Back $h{” $ o i d : $orgname ”} .= ” $ n” ; 196 } 197 else 198 { 199 Full Screen $ d u p l h{” $ o i d : $orgname ”} .= ” $ n” ; 200 } 201 ## # # #Begin: OID is duplicate # # # #### ## 202 # Have we encountered an oid that is N T already seen O 203 Close i f ( $ o i d d u p l f l a g == 0 ) 204 { 205 $p{” $ o i d ”} .= ” $ n” ; 206 Quit $q{” $ o i d ”} .= ” $ n” ; 207 } 208 else 209
  32. 32. { 210 $ d u p l q{” $ o i d ”} .= ” $ n” ; 211 } 212 ## # # #End: OID is duplicate # # # #### ## 213 Introduction } 214 e l s i f ( / ˆ ( ( w+)s +((d+.)∗d + ) ( . ∗ ) ) $ / ) # The line that has N M A EOID REST 215 Assumptions { 216 $ o i d n a m e d u p l f l a g = 0 ; # reset the oid name combination duplicate flag 217 $oid dupl flag = 0; # reset the oid duplicate flag 218 Details 219 $orgline = $1 ; # the entire line 220 Source Listing $orgname = $2 ; # the name 221 $orgoid = $3 ; # the oid (unformatted) 222 $orgrest = $5 ; # remaining line 223 224 $ o i d = j o i n ( ” . ” , map { $ = s p r i n t f ( ”%05d” , $ ) } s p l i t ( / . / , $ o r g o i d ) ) ; 225 226 −s $ l i n e = s p r i n t f ( ”%−65s%−65s% ” , $orgname , $ o r g o i d , $ o r g r e s t ) ; 227 228 Home Page # Have we encountered an oid name combination that is already seen 229 i f ( e x i s t s ( $g{” $ o i d : $orgname ” })) 230 { 231 $oidname dupl flag = 1; 232 Title Page 233 if ( ! e x i s t s ( $ d u p l h{” $ o i d : $orgname ” })) 234 { 235 $ d u p l h{” $ o i d : $orgname ”} = $g{” $ o i d : $orgname ”} . ” $ l i n e n” ; 236 } 237 else 238 { 239 $ d u p l h{” $ o i d : $orgname ”} .= ” $ l i n e n” ; 240 } 241 #print ”This is a duplicate line : $linen”; 242 } 243 Page 14 of 17 else 244 { 245 $g{” $ o i d : $orgname ”} = ” $ l i n e n” ; 246 $h{” $ o i d : $orgname ”} .= ” $ l i n e n” ; 247 Go Back } 248 ## # # #Begin: OID is duplicate# # # # #### #### 249 # Have we encountered an oid that is already seen 250 Full Screen i f ( e x i s t s ( $p{” $ o i d ” })) 251 { 252 $oid dupl flag = 1; 253 254 Close if ( ! e x i s t s ( $ d u p l q{” $ o i d ” })) 255 { 256 $ d u p l q{” $ o i d ”} = $p{” $ o i d ”} . ” $ l i n e n” ; 257 } 258 Quit else 259 { 260 $ d u p l q{” $ o i d ”} .= ” $ l i n e n” ; 261
  33. 33. } 262 #print ”This is a duplicate line : $linen”; 263 } 264 else 265 Introduction { 266 $p{” $ o i d ”} = ” $ l i n e n” ; 267 $q{” $ o i d ”} .= ” $ l i n e n” ; 268 Assumptions } 269 ## # # #End: OID is duplicate# # # # #### #### 270 Details } 271 } 272 Source Listing 273 $flag = 0; 274 275 i f ( $ o p t{d}) 276 { 277 open ( DELETEFILE , ” $ o p t{d}” ) | | d i e ” $program name : Cannot open d e l e t e f i l e $ o p t{d} f o r r e a d i n g : $ ! n” ; 278 279 w h i l e (<DELETEFILE>) 280 Home Page { 281 chomp ; 282 #− − − − − − − − − − − − − − − − −−−−−−−−−−−−−−−− 283 i f (/ˆ s∗$ / ) 284 Title Page { 285 next ; 286 } 287 e l s i f (/ˆ s ∗ [ ( { ] / ) # i f the line starts with an opening parenthesis or brace 288 { 289 # The assumption here is that you have either an open brace or a parenthesis 290 # on a line by itself and nothing else (except spaces) 291 # The level of nesting of brace/parenthesis tracked 292 # the assumption is that withing a pair of braces you wont have a 293 # parenthesis and vice− versa 294 $ f l a g ++; # increment the brace/parenthesis level 295 Page 15 of 17 } 296 e l s i f (/ˆ s ∗ [ ) } ] / ) # i f the line starts with a closing parenthesis or brace 297 { 298 # The assumption here is that you have either an open brace or a parenthesis 299 Go Back # on a line by itself and nothing else (except spaces) 300 301 $ f l a g − # decrement −; the brace/parenthesis level 302 Full Screen } 303 e l s i f ( $ f l a g > 0) 304 { 305 # nothing 306 Close } 307 e l s i f ( / ˆ ( ( w+)s +((d+.)∗d + ) ( . ∗ ) ) $ / ) # The line that has N M A EOID REST 308 { 309 $ o r g l i n e = $1 ; # the entire line 310 Quit $orgname = $2 ; # the name 311 $ o r g o i d = $3 ; # the oid (unformatted) 312
  34. 34. $ o r g r e s t = $5 ; # remaining line 313 314 $ o i d = j o i n ( ” . ” , map { $ = s p r i n t f ( ”%05d” , $ ) } s p l i t ( / . / , $ o r g o i d ) ) ; 315 −s $ l i n e = s p r i n t f ( ”%−65s%−65s% ” , $orgname , $ o r g o i d , $ o r g r e s t ) ; 316 317 Introduction # Have we encountered an oid name combination that is already seen 318 i f ( e x i s t s ( $h{” $ o i d : $orgname ” })) 319 Assumptions { 320 d e l e t e ( $h{” $ o i d : $orgname ” } ) ; 321 Details } 322 } 323 Source Listing else 324 { 325 # nothing 326 } 327 } 328 329 c l o s e ( DELETEFILE ) ; 330 } 331 332 Home Page open ( UNIQOIDNAMEFILE , ”> $ u n i q o i d n a m e f i l e ” ) | | d i e ” $program name : 333 Cannot open $ u n i q o i d n a m e f i l e f o r w r i t i n g : $ ! n” ; 334 335 Title Page f o r my $ o i d o r g n a m e ( s o r t { b y o i d n a m e } k e y s %h ) 336 { 337 p r i n t UNIQOIDNAMEFILE ” $h{$ o i d o r g n a m e}” ; 338 p r i n t ” $h{$ o i d o r g n a m e}” ; 339 } 340 341 c l o s e ( UNIQOIDNAMEFILE ) ; 342 343 open ( UNIQOIDFILE , ”> $ u n i q o i d f i l e ” ) | | d i e ” $program name : Cannot 344 open $ u n i q o i d f i l e f o r w r i t i n g : $ ! n” ; 345 346 f o r my $ o i d ( s o r t { $a cmp $b } k e y s %q ) 347 Page 16 of 17 { 348 p r i n t UNIQOIDFILE ” $q{$ o i d}” ; 349 } 350 351 Go Back c l o s e ( UNIQOIDFILE ) ; 352 353 354 355 Full Screen open (DUPOIDNAMEFILE , ”> $ d u p o i d n a m e f i l e ” ) | | d i e ” $program name : 356 Cannot open $ d u p o i d n a m e f i l e f o r w r i t i n g : $ ! n” ; 357 358 f o r my $ o i d o r g n a m e ( s o r t { b y o i d n a m e } k e y s %d u p l h ) 359 Close { 360 # print duplicates where the duplicate is determined by 361 # combination of oid and name 362 Quit p r i n t DUPOIDNAMEFILE ” $ d u p l h{$ o i d o r g n a m e}” ; 363 } 364 365
  35. 35. c l o s e (DUPOIDNAMEFILE ) ; 366 367 open ( DUPOIDFILE , ”> $ d u p o i d f i l e ” ) | | d i e ” $program name : Cannot 368 open $ d u p o i d f i l e f o r w r i t i n g : $ ! n” ; 369 Introduction 370 f o r my $ o i d ( s o r t { $a cmp $b } k e y s %d u p l q ) 371 Assumptions { 372 # print duplicates where the duplicate is determined by 373 Details # combination of oid and name 374 p r i n t DUPOIDFILE ” $ d u p l q{$ o i d}” ; 375 Source Listing } 376 377 c l o s e ( DUPOIDFILE ) ; 378 ¦ Home Page Title Page Page 17 of 17 Go Back Full Screen Close Quit

×