Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String extend [ s: aRegexp with: str [ ^self replacingAllRegex: aRegexp with: str ]
- without: aRegexp [ ^self replacingRegex: aRegexp with: '' ]
- withoutAll: aRegexp [ ^self s: aRegexp with: '' ]].
- (Smalltalk getArgc) = 2
- ifTrue: [ | in out
- lineParsers valueParsers roots
- root subkey valueType valueName valueData |
- roots := Dictionary from: {
- 'HKEY_CLASSES_ROOT' -> 'HKCR'. 'HKEY_CURRENT_USER' -> 'HKCU'.
- 'HKEY_LOCAL_MACHINE' -> 'HKLM'. 'HKEY_USERS' -> 'HKU'.
- 'HKEY_CURRENT_CONFIG' -> 'HKCC' }.
- valueParsers := Dictionary from: {
- $" -> [ :str |
- valueType := 'string'.
- valueData := str withoutAll: '\"' ].
- $d -> [ :str |
- valueType := 'dword'.
- valueData := '$', (str without: '([^:]*):') ].
- $h -> [ :str |
- valueType := 'binary'.
- valueData := (str without: '([^:]*):') s: ',' with: ' ']}.
- lineParsers := Dictionary from: {
- $[ -> [ :line || delim |
- delim := line indexOf: $\.
- delim > 0
- ifTrue: [ root := roots at: (line copyFrom: 2 to: delim - 1).
- subkey := (line without: '([^\\]*)\\') without: ']']
- ifFalse: [ root := line withoutAll: '[\[\]]'.
- subkey := nil ]].
- $" -> [ :line || delim valueRaw block |
- delim := line indexOf: $=.
- valueName := line copyFrom: 1 to: delim - 1.
- valueRaw := line without: '([^=]*)='.
- block := valueParsers at: (valueRaw at: 1) ifAbsent: [ nil ].
- block ifNotNil: [ block value: valueRaw ]]}.
- in := (File name: (Smalltalk getArgv: 1)) readStream.
- out := (File name: (Smalltalk getArgv: 2)) writeStream.
- in linesDo: [ :line |
- line notEmpty ifTrue: [ | aBlock |
- valueType := valueName := valueData := nil.
- aBlock := lineParsers at: (line at: 1) ifAbsent: [ nil ].
- aBlock ifNotNil: [
- aBlock value: line.
- subkey ifNotNil: [ | bfr |
- bfr := WriteStream on: String new.
- bfr << 'Root: ' << root << '; Subkey: "' << subkey << '"; '.
- valueData ifNotNil: [
- bfr << 'ValueType: ' << valueType
- << '; ValueName: ' << valueName
- << '; ValueData: "' << valueData << '"' ].
- out << (bfr contents copyReplaceAll: '{' with: '{{'); cr; nl ]]]].
- in close.
- out close
- ]
- ifFalse: [
- Transcript << 'Error: please specify an input and output file names'; cr ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement