Advertisement
Guest User

Untitled

a guest
May 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String extend [ s:          aRegexp with: str [ ^self replacingAllRegex: aRegexp with: str ]
  2.                 without:    aRegexp           [ ^self replacingRegex: aRegexp with: '' ]
  3.                 withoutAll: aRegexp           [ ^self s: aRegexp with: '' ]].
  4.  
  5. (Smalltalk getArgc) = 2
  6.     ifTrue:  [ | in out
  7.                 lineParsers valueParsers roots
  8.                 root subkey valueType valueName valueData |
  9.  
  10.         roots := Dictionary from: {
  11.             'HKEY_CLASSES_ROOT'   -> 'HKCR'.    'HKEY_CURRENT_USER' -> 'HKCU'.
  12.             'HKEY_LOCAL_MACHINE'  -> 'HKLM'.    'HKEY_USERS'        -> 'HKU'.
  13.             'HKEY_CURRENT_CONFIG' -> 'HKCC' }.
  14.  
  15.         valueParsers := Dictionary from: {
  16.             $" -> [ :str |
  17.                       valueType := 'string'.
  18.                       valueData := str withoutAll: '\"' ].
  19.  
  20.            $d -> [ :str |
  21.                      valueType := 'dword'.
  22.                      valueData := '$', (str without: '([^:]*):') ].
  23.  
  24.            $h -> [ :str |
  25.                      valueType := 'binary'.
  26.                      valueData := (str without: '([^:]*):') s: ',' with: ' ']}.
  27.  
  28.        lineParsers := Dictionary from: {
  29.            $[ -> [ :line || delim |
  30.                      delim := line indexOf: $\.
  31.                      delim > 0
  32.                          ifTrue:  [ root := roots at: (line copyFrom: 2 to: delim - 1).
  33.                                     subkey := (line  without: '([^\\]*)\\') without: ']']
  34.                          ifFalse: [ root := line withoutAll: '[\[\]]'.
  35.                                     subkey := nil ]].
  36.  
  37.            $" -> [ :line || delim valueRaw block |
  38.                      delim := line indexOf: $=.
  39.                      valueName := line copyFrom: 1 to: delim - 1.
  40.                      valueRaw  := line without: '([^=]*)='.
  41.                      block := valueParsers at: (valueRaw at: 1) ifAbsent: [ nil ].
  42.                      block ifNotNil: [ block value: valueRaw ]]}.
  43.  
  44.        in  := (File name: (Smalltalk getArgv: 1)) readStream.
  45.        out := (File name: (Smalltalk getArgv: 2)) writeStream.
  46.        in linesDo: [ :line |
  47.            line notEmpty ifTrue: [ | aBlock |
  48.                valueType := valueName := valueData := nil.
  49.                aBlock := lineParsers at: (line at: 1) ifAbsent: [ nil ].
  50.                aBlock ifNotNil: [
  51.                    aBlock value: line.
  52.                    subkey ifNotNil: [ | bfr |
  53.                        bfr := WriteStream on: String new.
  54.                        bfr << 'Root: ' << root << '; Subkey: "' << subkey << '"; '.
  55.                        valueData ifNotNil: [
  56.                            bfr << 'ValueType: '    << valueType
  57.                                << '; ValueName: '  << valueName
  58.                                << '; ValueData: "' << valueData << '"' ].
  59.                        out << (bfr contents copyReplaceAll: '{' with: '{{'); cr; nl ]]]].
  60.        in close.
  61.        out close
  62.    ]
  63.    ifFalse: [
  64.        Transcript << 'Error: please specify an input and output file names'; cr ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement