extensions.st
author Claus Gittinger <cg@exept.de>
Tue, 29 Nov 2011 11:56:14 +0100
changeset 2679 cfab54d30fcc
parent 2582 85a5ed52fc7b
child 2897 3060cf059978
permissions -rw-r--r--
changed: #scanArgFrom:to:format:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2337
755696d72648 comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
     1
"{ Package: 'stx:libbasic2' }"!
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
     2
2288
316a202d1c8b category changes
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
     3
!CharacterArray methodsFor:'matching - phonetic'!
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
     4
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
     5
asKoelnerPhoneticCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
     6
    "return a koelner phonetic code.
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
     7
     The koelnerPhonetic code is for the german language what the soundex code is for english;
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
     8
     it returns simular strings for similar sounding words.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
     9
     There are some differences to soundex, though:
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    10
	its length is not limited to 4, but depends on the length of the original string;
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    11
	it does not start with the first character of the input.
2288
316a202d1c8b category changes
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    12
316a202d1c8b category changes
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    13
     Caveat: this phonetic code is especially suited for german words.
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    14
	     Please have a look at the other phonetic comparison operators found
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    15
	     in PhoneticStringUtilities."
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    16
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    17
    ^ PhoneticStringUtilities koelnerPhoneticCodeOf:self
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    18
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    19
    "
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    20
     #(
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    21
	'Müller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    22
	'Miller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    23
	'Mueller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    24
	'Mühler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    25
	'Mühlherr'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    26
	'Mülherr'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    27
	'Myler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    28
	'Millar'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    29
	'Myller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    30
	'Müllar'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    31
	'Müler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    32
	'Muehler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    33
	'Mülller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    34
	'Müllerr'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    35
	'Muehlherr'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    36
	'Muellar'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    37
	'Mueler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    38
	'Mülleer'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    39
	'Mueller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    40
	'Nüller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    41
	'Nyller'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    42
	'Niler'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    43
	'Czerny'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    44
	'Tscherny'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    45
	'Czernie'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    46
	'Tschernie'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    47
	'Schernie'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    48
	'Scherny'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    49
	'Scherno'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    50
	'Czerne'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    51
	'Zerny'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    52
	'Tzernie'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    53
	'Breschnew'
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    54
     ) do:[:w |
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    55
	 Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode)
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    56
     ].
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    57
    "
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    58
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    59
    "
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    60
     'Breschnew' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    61
     'Breschnew' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    62
     'Breschneff' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    63
     'Braeschneff' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    64
     'Braessneff' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    65
     'Pressneff' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    66
     'Presznäph' asKoelnerPhoneticCode -> '17863'
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    67
    "
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    68
! !
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    69
2288
316a202d1c8b category changes
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    70
!CharacterArray methodsFor:'matching - phonetic'!
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    71
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    72
asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    73
    "return a soundex phonetic code or nil.
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    74
     Soundex returns similar codes for similar sounding words, making it a useful
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    75
     tool when searching for words where the correct spelling is unknown.
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    76
     (read Knuth or search the web if you dont know what a soundex code is).
2288
316a202d1c8b category changes
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    77
2337
755696d72648 comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    78
     Caveat: 'similar sounding words' means: 'similar sounding in ENGLISH'
2435
9f8b350002db VariableString -> String
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
    79
	     Please have a look at the other phonetic comparison operators found
9f8b350002db VariableString -> String
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
    80
	     in PhoneticStringUtilities."
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    81
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    82
    ^ PhoneticStringUtilities soundexCodeOf:self
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    83
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    84
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
    85
     'claus' asSoundexCode
2199
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    86
     'clause' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    87
     'close' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    88
     'smalltalk' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    89
     'smaltalk' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    90
     'smaltak' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    91
     'smaltok' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    92
     'smoltok' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    93
     'aa' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    94
     'by' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    95
     'bab' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    96
     'bob' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    97
     'bop' asSoundexCode
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    98
    "
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
    99
! !
a9d3b1aa9f03 phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents: 2150
diff changeset
   100
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   101
!CharacterArray methodsFor:'printing & storing'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   102
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   103
printf:args
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   104
    "Format and print the receiver with <args> formatted in C style,
2295
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   105
     as specified in the Unix C-language manual page for printf(3).
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   106
     Return the resulting string.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   107
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   108
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   109
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   110
    |aStream|
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   111
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   112
    aStream := WriteStream on:String new.
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   113
    self printf:args on:aStream.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   114
    ^ aStream contents
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   115
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   116
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   117
     Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } )
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   118
    "
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   119
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   120
    "
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   121
     Transcript showCR: 'Some examples:'!!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   122
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   123
     Transcript show:'''%#x %#X %03o%*.*s'' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') = .'.
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   124
     Transcript show: ('%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn')).
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   125
     Transcript showCR: '.'
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   126
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   127
     Transcript show: '''%- 10.4s%.2e'' printf: (Array with: ''abcdefghijkl'' with: Float pi) = .'.
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   128
     Transcript show: ('%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi)).
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   129
     Transcript showCR: '.'
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   130
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   131
     Transcript show: '''%8.3f'' printf: (Array with: 200 sqrt negated) = .'.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   132
     Transcript show: ('%8.3f' printf: (Array with: 200 sqrt negated)).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   133
     Transcript showCR: '.'
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   134
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   135
     Transcript show: '''%c'' printf: #(16r41) = .'.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   136
     Transcript show: ('%c' printf: #(16r41)).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   137
     Transcript showCR: '.'
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   138
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   139
     Transcript show: '''%f%2s%s%s%s'' sscanf: ''237.0 this is a test'' = '.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   140
     Transcript showCR: ('%f%2s%s%s%s'  sscanf: '237.0 this is a test') printString.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   141
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   142
     Transcript show: '''%d%f%s'' sscanf: ''25 54.32e-01 monday'' = '.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   143
     Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   144
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   145
     Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   146
     Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   147
    "
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   148
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   149
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   150
!CharacterArray methodsFor:'printing & storing'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   151
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   152
printf:args on:outStream
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   153
    "Format and print the receiver on <outStream> with <args>
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   154
     formatted in C style, as specified in the Unix C-language manual page for printf(3).
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   155
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   156
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   157
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   158
    |argStream inStream char|
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   159
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   160
    argStream := ReadStream on:args.
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   161
    inStream := ReadStream on:self.
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   162
    [ inStream atEnd ] whileFalse:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   163
	(char := inStream next) == $% ifFalse:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   164
	    outStream nextPut:char
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   165
	] ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   166
	    self
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   167
		printf_printArgFrom:inStream
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   168
		to:outStream
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   169
		withData:argStream
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   170
	]
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   171
    ]
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   172
! !
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   173
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   174
!CharacterArray methodsFor:'printing & storing'!
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   175
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   176
printfWith:arg1
2295
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   177
    "Format and print the receiver with <arg1> formatted in C style,
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   178
     as specified in the Unix C-language manual page for printf(3).
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   179
     Return the resulting string."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   180
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   181
    ^ self printf:(Array with:arg1)
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   182
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   183
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   184
     Transcript showCR:('%05x' printfWith:123)
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   185
    "
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   186
! !
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   187
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   188
!CharacterArray methodsFor:'printing & storing'!
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   189
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   190
printfWith:arg1 with:arg2
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   191
    "Format and print the receiver with <argI> formatted in C style,
2295
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   192
     as specified in the Unix C-language manual page for printf(3).
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   193
     Return the resulting string."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   194
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   195
    ^ self printf:(Array with:arg1 with:arg2)
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   196
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   197
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   198
     Transcript showCR:('%d %05x' printfWith:123 with:234)
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   199
    "
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   200
! !
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   201
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   202
!CharacterArray methodsFor:'printing & storing'!
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   203
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   204
printfWith:arg1 with:arg2 with:arg3
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   205
    "Format and print the receiver with <argI> formatted in C style,
2295
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   206
     as specified in the Unix C-language manual page for printf(3).
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   207
     Return the resulting string."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   208
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   209
    ^ self printf:(Array with:arg1 with:arg2 with:arg3)
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   210
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   211
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   212
     Transcript showCR:('%d %05x %08o' printfWith:123 with:234 with:345)
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   213
    "
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   214
! !
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   215
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   216
!CharacterArray methodsFor:'printing & storing'!
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   217
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   218
printfWith:arg1 with:arg2 with:arg3 with:arg4
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   219
    "Format and print the receiver with <argI> formatted in C style,
2295
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   220
     as specified in the Unix C-language manual page for printf(3).
27e3885efddd comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents: 2288
diff changeset
   221
     Return the resulting string."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   222
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   223
    ^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4)
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   224
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   225
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   226
     Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123)
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   227
    "
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   228
! !
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   229
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   230
!CharacterArray methodsFor:'printing & storing'!
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   231
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   232
printf_formatArgCount
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   233
    "Return the number of arguments required/produced if the receiver is interpreted
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   234
     as a printf/scanf format control string.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   235
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   236
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   237
    |nonConsecutive count|
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   238
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   239
    nonConsecutive := true.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   240
    count := 0.
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   241
    self do:[:c |
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   242
	c == $% ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   243
	    nonConsecutive ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   244
		count := count + 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   245
		nonConsecutive := false
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   246
	    ] ifFalse:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   247
		count := count - 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   248
		nonConsecutive := true
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   249
	    ]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   250
	] ifFalse:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   251
	    nonConsecutive := true
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   252
	]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   253
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   254
    ^ count
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   255
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   256
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   257
!CharacterArray methodsFor:'private'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   258
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   259
printf_printArgFrom:inStream to:outStream withData:argStream
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   260
    "Interpret the required number of arguments from <argStream>
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   261
     according to the formatting information in <inStream>.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   262
     Place the interpretation on <outStream>.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   263
     The interpretation is C printf(3) style, as
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   264
     specified in the Unix C-language manual page for printf(3).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   265
     <inStream> is assumed to be positioned just past
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   266
     $%, and a complete control string is assumed available.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   267
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   268
     Return when the conversion control string is consumed.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   269
     Leave <inStream> pointing past the last character in the conversion control string.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   270
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   271
     This code assumes that <inStream> is formatted according to
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   272
     specification, and error checking is minimal.  Unexpected
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   273
     results will be obtained by illegal control strings, or when
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   274
     argument types do not match conversion codes, but it probably
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   275
     won't dump core, like C does in such cases!!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   276
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   277
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   278
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   279
    |nextArg ljust plus pound width precision pad char arg argString|
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   280
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   281
    nextArg := [
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   282
                    argStream atEnd ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   283
                        self error:'not enough arguments for format string'
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   284
                    ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   285
                    argStream next
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   286
               ].
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   287
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   288
    ljust := plus := pound := false.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   289
    width := 0.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   290
    precision := SmallInteger maxVal.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   291
    pad := $ .
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   292
    char := inStream peek.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   293
    char == $% ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   294
        ^ outStream nextPut:inStream next
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   295
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   296
    char == $- ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   297
        ljust := true.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   298
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   299
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   300
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   301
    char == $  ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   302
        outStream space.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   303
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   304
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   305
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   306
    char == $+ ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   307
        plus := true.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   308
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   309
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   310
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   311
    char == $# ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   312
        pound := true.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   313
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   314
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   315
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   316
    char == $* ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   317
        width := nextArg value.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   318
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   319
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   320
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   321
    char isDigit ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   322
        char == $0 ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   323
            pad := $0
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   324
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   325
        width := Integer readFrom:inStream.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   326
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   327
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   328
    char == $. ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   329
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   330
        char := inStream peek.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   331
        char == $* ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   332
            precision := nextArg value.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   333
            inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   334
        ] ifFalse:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   335
            precision := Integer readFrom:inStream.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   336
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   337
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   338
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   339
    char == $l "Ignore long specifier." ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   340
        inStream next.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   341
        char := inStream peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   342
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   343
    ('feg' includes:char) ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   344
        arg := nextArg value asFloat.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   345
        precision := precision min:6.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   346
        argString := WriteStream on:String new.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   347
        char == $g ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   348
            arg absPrintOn:argString digits:precision + 1
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   349
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   350
        char == $f ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   351
            arg absDecimalPrintOn:argString digits:precision + arg abs log + 1
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   352
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   353
        char == $e ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   354
            arg absScientificPrintOn:argString digits:precision + 1
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   355
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   356
        argString := argString contents.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   357
        arg < 0 ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   358
            argString := '-' , argString
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   359
        ] ifFalse:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   360
            plus ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   361
                argString := '+' , argString
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   362
            ]
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   363
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   364
        (precision = 0 and:[ pound not ]) ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   365
            (argString includes:$e) ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   366
                "self halt"
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   367
            ] ifFalse:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   368
                argString := arg truncated printString
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   369
            ]
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   370
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   371
        pound ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   372
            (argString includes:$e) ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   373
                "self halt"
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   374
            ] ifFalse:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   375
                precision - (argString size - (argString indexOf:$.)) timesRepeat:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   376
                    argString := argString , '0'
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   377
                ]
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   378
            ]
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   379
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   380
        ljust ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   381
            outStream nextPutAll:argString
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   382
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   383
        width - argString size timesRepeat:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   384
            outStream space
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   385
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   386
        ljust ifFalse:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   387
            outStream nextPutAll:argString
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   388
        ].
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   389
        ^ inStream next
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   390
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   391
    char == $c ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   392
        arg := String with:nextArg value asCharacter
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   393
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   394
    char == $s "Assume the arg is a String or Symbol." ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   395
        arg := nextArg value asString
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   396
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   397
    char == $d ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   398
        arg := nextArg value asInteger printString.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   399
        plus ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   400
            arg := '+' , arg
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   401
        ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   402
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   403
    char == $u ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   404
        arg := nextArg value asInteger abs printString
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   405
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   406
    char == $o ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   407
        arg := nextArg value asInteger abs printStringRadix:8.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   408
        pound ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   409
            arg := '0' , arg
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   410
        ]
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   411
    ].
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   412
    char == $b ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   413
        arg := nextArg value asInteger abs printStringRadix:2.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   414
        pound ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   415
            arg := '0' , arg
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   416
        ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   417
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   418
    ('xX' includes:char) ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   419
        arg := nextArg value asInteger abs printStringRadix:16.
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   420
        pound ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   421
            arg := '0x' , arg
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   422
        ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   423
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   424
    char == $x ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   425
        1 to:arg size do:[:i |
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   426
            ('ABCDEF' includes:(arg at:i)) ifTrue:[
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   427
                arg at:i put:((arg at:i) asciiValue + 16r20) asCharacter
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   428
            ]
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   429
        ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   430
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   431
    precision := precision min:arg size.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   432
    ljust ifTrue:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   433
        outStream nextPutAll:(arg copyFrom:1 to:precision)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   434
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   435
    width - precision timesRepeat:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   436
        outStream nextPut:pad
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   437
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   438
    ljust ifFalse:[
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   439
        outStream nextPutAll:(arg copyFrom:1 to:precision)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   440
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   441
    ^ inStream next
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   442
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
   443
    "Modified: / 24-07-2011 / 07:16:42 / cg"
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   444
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   445
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   446
!CharacterArray methodsFor:'printing & storing'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   447
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   448
printf_printOn:outStream withData:args
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   449
    <resource: #obsolete>
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   450
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   451
    "Format and print the receiver on <outStream> with <args>
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   452
     formatted in C style, as specified in the Unix C-language manual page for printf(3).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   453
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   454
     For copyright information, see goodies/String-printf_scanf.chg"
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   455
2260
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   456
    self obsoleteMethodWarning:'use printf:on:'.
fd7e5634d0d0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2256
diff changeset
   457
    self printf:args on:outStream
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   458
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   459
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   460
!CharacterArray methodsFor:'converting'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   461
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   462
scanf:dataStream
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   463
    "Return a Collection of objects found in the Character Stream
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   464
     <dataStream> as interpreted according to the receiver.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   465
     The receiver is assumed to be a conversion control string as
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   466
     specified in the Unix C-language manual page for scanf(3).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   467
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   468
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   469
    |results format char|
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   470
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   471
    results := OrderedCollection new.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   472
    format := ReadStream on:self.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   473
    [ format atEnd ] whileFalse:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   474
	char := format next.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   475
	(char == Character space or:[ char == Character tab ]) ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   476
	    dataStream skipSeparators.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   477
	    format skipSeparators
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   478
	].
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   479
	char == $% ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   480
	    self
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   481
		scanf_scanArgFrom:dataStream
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   482
		to:results
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   483
		format:format
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   484
	] ifFalse:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   485
	    dataStream peekFor:char
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   486
	]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   487
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   488
    ^ results
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   489
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   490
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   491
     '%d %x' scanf:(ReadStream on:'1234 ff00')
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   492
    "
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   493
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   494
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   495
!CharacterArray methodsFor:'private'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   496
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   497
scanf_scanArgFrom:dataStream to:collection format:format
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   498
    "Add to <collection> an object who's representation is found
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   499
     in <dataStream> interpreted according to the conversion
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   500
     control string in the Stream <format>.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   501
     <format> is assumed to be positioned just past a $%, and a complete control
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   502
     string is assumed available.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   503
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   504
     Return when the conversion control string is consumed.  Leave
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   505
     <format> pointing past the last character in the conversion
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   506
     control string, leave <dataStream> pointing past any width
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   507
     specified in <format>, or at the first character that doesn't
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   508
     make sense for the <format>.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   509
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   510
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   511
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   512
    |final width char pos data scanset exclusive return last|
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   513
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   514
    final := [:retval |
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   515
            collection add:retval.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   516
            data == dataStream ifFalse:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   517
                dataStream position:dataStream position + data position
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   518
            ].
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   519
            ^ self
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   520
        ].
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   521
    width := 0.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   522
    char := format peek.
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   523
    char == $% ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   524
        ^ dataStream peekFor:char
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   525
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   526
    char == $* ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   527
        format next.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   528
        char := format peek.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   529
        final := [:retval |
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   530
                data == dataStream ifFalse:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   531
                    dataStream position:dataStream position + data position
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   532
                ].
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   533
                ^ self
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   534
            ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   535
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   536
    char isDigit ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   537
        width := Integer readFrom:format.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   538
        char := format peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   539
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   540
    ('slhduoxfeg' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   541
        dataStream skipSeparators
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   542
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   543
    width = 0 ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   544
        data := dataStream
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   545
    ] ifFalse:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   546
        pos := dataStream position.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   547
        data := ReadStream on:(dataStream next:width).
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   548
        dataStream position:pos
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   549
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   550
    char == $s ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   551
        final value:(data upToSeparator)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   552
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   553
    char == $c ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   554
        width = 0 ifTrue:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   555
            final value:(String with:data next)
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   556
        ] ifFalse:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   557
            final value:data contents
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   558
        ]
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   559
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   560
    char == $[ "What a mess!!" ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   561
        return := WriteStream on:(String new:8).
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   562
        scanset := IdentitySet new.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   563
        format next.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   564
        width = 0 ifTrue:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   565
            width := SmallInteger maxVal
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   566
        ].
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   567
        exclusive := format peekFor:$^.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   568
        [
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   569
            last := char.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   570
            char := format next.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   571
            char == $]
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   572
        ] whileFalse:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   573
            char == $- ifFalse:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   574
                scanset add:char
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   575
            ] ifTrue:[
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   576
                last to:format next do:[:c |
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   577
                    scanset add:c
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   578
                ]
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   579
            ]
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   580
        ].
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   581
        [
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   582
            data atEnd not and:[ (scanset includes:data peek) xor:exclusive ]
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   583
        ] whileTrue:[ return nextPut:data next ].
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   584
        final value:return contents
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   585
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   586
    ('lh' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   587
        format next.
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   588
        char := format peek
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   589
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   590
    ('DUdu' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   591
        final value:(Integer readFrom:data)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   592
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   593
    ('FEGfeg' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   594
        final value:(Float readFrom:data)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   595
    ].
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   596
    ('b' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   597
        final value:(Integer readFrom:data radix:2)
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   598
    ].
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   599
    ('Oo' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   600
        final value:(Integer readFrom:data radix:8)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   601
    ].
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   602
    ('Xx' includes:char) ifTrue:[
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   603
        final value:(Integer readFrom:data radix:16)
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   604
    ]
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   605
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   606
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   607
     '%d %x' sscanf:'1234 ff00'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   608
     '%d %x %b' sscanf:'1234 ff00 1001'
2256
10583ebc7f64 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2241
diff changeset
   609
    "
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   610
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
   611
    "Modified: / 29-11-2011 / 11:55:39 / cg"
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   612
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   613
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   614
!CharacterArray methodsFor:'converting'!
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   615
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   616
sscanf:string
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   617
    "Return a Collection of objects found in <string> as
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   618
     interpreted according to the receiver.
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   619
     The receiver is assumed to be a conversion control string as
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   620
     specified in the Unix C-language manual page for scanf(3).
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   621
     For copyright information, see goodies/String-printf_scanf.chg"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   622
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   623
    ^ self scanf:(ReadStream on:string)
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   624
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   625
    "
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   626
     '%d %x' sscanf:'1234 ff00'
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   627
     '%d %x %b' sscanf:'1234 ff00 1001'
2241
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   628
    "
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   629
! !
81f10d4ad4bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2239
diff changeset
   630
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   631
!Float methodsFor:'private'!
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   632
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   633
absDecimalPrintOn:aStream digits:digits
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   634
    "Place a string representation of the receiver's abs value
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   635
     on <aStream> using <digits> significant digits, using decimal notation.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   636
     This is a helper for printf."
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   637
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   638
    |exp x fuzz i|
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   639
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   640
    "x is myself normalized to (1.0, 10.0), exp is my exponent"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   641
    exp := self abs < 1.0
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   642
		ifTrue:[ (10.0 / self abs) log floor negated ]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   643
		ifFalse:[ self abs log floor ].
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   644
    x := self abs / (10.0 raisedTo:exp).
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   645
    fuzz := 10.0 raisedTo:1 - digits.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   646
     "round the last digit to be printed"
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   647
    x := 0.5 * fuzz + x.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   648
    x >= 10.0 "check if rounding has unnormalized x" ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   649
	x := x / 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   650
	exp := exp + 1
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   651
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   652
    exp < 0 ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   653
	1 to:1 - exp do:[:j |
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   654
	    aStream nextPut:('0.000000000000' at:j)
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   655
	]
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   656
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   657
    [ x >= fuzz ] "use fuzz to track significance" whileTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   658
	i := x truncated.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   659
	aStream nextPut:(48 + i) asCharacter.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   660
	x := (x - i) * 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   661
	fuzz := fuzz * 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   662
	exp := exp - 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   663
	exp = -1 ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   664
	    aStream nextPut:$.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   665
	]
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   666
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   667
    [ exp >= -1 ] whileTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   668
	aStream nextPut:$0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   669
	exp := exp - 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   670
	exp = -1 ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   671
	    aStream nextPut:$.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   672
	]
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   673
    ]
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   674
! !
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   675
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   676
!Float methodsFor:'private'!
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   677
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   678
absPrintOn:aStream digits:digits
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   679
    "Place a string representation of the receiver's abs value on <aStream> using
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   680
     <digits> significant digits.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   681
     This is a helper for printf."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   682
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   683
    (self < 1.0e6 and:[ self > 1.0e-4 ]) ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   684
	self absDecimalPrintOn:aStream digits:digits
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   685
    ] ifFalse:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   686
	self absScientificPrintOn:aStream digits:digits
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   687
    ]
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   688
! !
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   689
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   690
!Float methodsFor:'private'!
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   691
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   692
absScientificPrintOn:aStream digits:digits
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   693
    "Place a string representation of the receiver's abs value on <aStream> using <digits> significant
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   694
     digits, using scientific notation.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   695
     This is a helper for printf."
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   696
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   697
    |exp fuzz x q i|
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   698
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   699
    "x is myself normalized to [1.0, 10.0), exp is my exponent"
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   700
    exp := self abs < 1.0
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   701
	    ifTrue:[ (10.0 / self abs) log floor negated ]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   702
	    ifFalse:[ self abs log floor ].
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   703
    x := self abs / (10.0 raisedTo:exp).
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   704
    fuzz := 10.0 raisedTo:1 - digits.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   705
     "round the last digit to be printed"
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   706
    x := 0.5 * fuzz + x.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   707
    x >= 10.0 "check if rounding has unnormalized x" ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   708
	x := x / 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   709
	exp := exp + 1
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   710
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   711
    q := exp.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   712
    exp := 0.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   713
    [ x >= fuzz ] "use fuzz to track significance" whileTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   714
	i := x truncated.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   715
	aStream nextPut:(48 + i) asCharacter.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   716
	x := (x - i) * 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   717
	fuzz := fuzz * 10.0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   718
	exp := exp - 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   719
	exp = -1 ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   720
	    aStream nextPut:$.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   721
	]
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   722
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   723
    [ exp >= -1 ] whileTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   724
	aStream nextPut:$0.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   725
	exp := exp - 1.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   726
	exp = -1 ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   727
	    aStream nextPut:$.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   728
	]
2237
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   729
    ].
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   730
    aStream nextPut:$e.
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   731
    q printOn:aStream
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   732
! !
3b041af2bf04 printf / scanf added
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
   733
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   734
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   735
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   736
addInterest:anInterest
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   737
    "install an interest forwarder.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   738
     Here, we use the nonWeakDependencies."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   739
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   740
    self addNonWeakDependent:anInterest
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   741
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   742
    "Created: 14.10.1996 / 22:27:34 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   743
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   744
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   745
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   746
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   747
expressInterestIn:aspect for:anObject sendBack:aSelector
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   748
    "arrange for aSelector to be sent to anObject whenever the receiver
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   749
     changes aspect."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   750
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   751
    "/ for now, use an interestConverter, which is somewhat less efficient.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   752
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   753
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   754
    self addInterest:(InterestConverter
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   755
			    destination:anObject
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   756
			    selector:aSelector
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   757
			    aspect:aspect)
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   758
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   759
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   760
     |p b|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   761
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   762
     b := [Transcript showCR:' -> the point changed'].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   763
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   764
     p := Point new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   765
     Transcript showCR:'interest in #foo:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   766
     p expressInterestIn:#foo for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   767
     p x:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   768
     Transcript showCR:'now changing #bar ... (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   769
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   770
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   771
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   772
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   773
     Transcript showCR:'now changing #foo ... (expect notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   774
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   775
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   776
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   777
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   778
     Transcript showCR:'no more interest in #foo:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   779
     p retractInterestIn:#foo for:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   780
     Transcript showCR:'now changing #foo ... (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   781
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   782
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   783
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   784
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   785
     Transcript showCR:'interest in #bar now:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   786
     p expressInterestIn:#bar for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   787
     Transcript showCR:'now changing #foo ... (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   788
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   789
     Transcript showCR:'now changing #bar ... (expect notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   790
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   791
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   792
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   793
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   794
     Transcript showCR:'interest in #foo now:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   795
     p expressInterestIn:#foo for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   796
     Transcript showCR:'now changing #foo ... (expect notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   797
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   798
     Transcript showCR:'now changing #bar ... (expect notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   799
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   800
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   801
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   802
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   803
     Transcript showCR:'no more interests:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   804
     p retractInterestsFor:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   805
     Transcript showCR:'now changing #foo ... (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   806
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   807
     Transcript showCR:'now changing #bar...  (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   808
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   809
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   810
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   811
     p release.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   812
    "
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   813
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   814
    "Created: 19.4.1996 / 10:26:22 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   815
    "Modified: 19.4.1996 / 12:34:08 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   816
    "Modified: 14.10.1996 / 22:28:20 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   817
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   818
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   819
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   820
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   821
interests
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   822
    "return a Collection of interests - empty if there is none.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   823
     Here, we use the nonWeakDependents for interests."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   824
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   825
    ^ self nonWeakDependents
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   826
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   827
    "Created: / 14.10.1996 / 22:20:51 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   828
    "Modified: / 30.1.1998 / 14:07:35 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   829
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   830
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   831
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   832
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   833
interestsFor:someOne
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   834
    "return a collection of interests of someOne - empty if there is none."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   835
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   836
    |coll deps|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   837
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   838
    deps := self interests.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   839
    deps size == 0 ifTrue:[^ #()].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   840
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   841
    coll := IdentitySet new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   842
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   843
    deps do:[:dep |
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   844
	(dep isInterestConverter) ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   845
	    dep destination == someOne ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   846
		coll add:dep.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   847
	    ]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   848
	]
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   849
    ].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   850
    ^ coll
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   851
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   852
    "Created: / 30.1.1998 / 14:02:26 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   853
    "Modified: / 30.1.1998 / 14:08:24 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   854
! !
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   855
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   856
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   857
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   858
onChangeEvaluate:aBlock
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   859
    "arrange for aBlock to be evaluated whenever the receiver changes."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   860
2149
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   861
    |na selector|
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   862
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   863
    na := aBlock numArgs.
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   864
    na == 0 ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   865
	selector := #value
2149
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   866
    ] ifFalse:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   867
	selector := #( #'value:' #'value:value:' #'value:value:value:') at:na
2149
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   868
    ].
329461c02e84 allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   869
    ^ self onChangeSend:selector to:aBlock
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   870
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   871
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   872
     |p b|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   873
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   874
     b := [Transcript showCR:' -> the point changed'].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   875
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   876
     p := Point new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   877
     Transcript showCR:'interest in #foo:'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   878
     p onChangeEvaluate:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   879
     p x:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   880
     Transcript showCR:'now changing #bar ... (expect no notification)'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   881
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   882
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   883
     p retractInterests.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   884
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   885
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   886
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   887
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   888
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   889
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   890
onChangeSend:aSelector to:anObject
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   891
    "arrange for aSelector to be sent to anObject whenever the receiver
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   892
     changes."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   893
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   894
    "/ for now, use an interestConverter, which is somewhat less efficient.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   895
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   896
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   897
    ((self interests ? #())
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   898
	contains:[:anInterest |
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   899
	    (anInterest isInterestConverter)
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   900
	    and:[ anInterest destination == anObject
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   901
	    and:[ anInterest selector == aSelector]]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   902
	])
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   903
	    ifTrue:[^ self].
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   904
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   905
    self addInterest:(InterestConverter
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   906
			  destination:anObject
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   907
			  selector:aSelector)
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   908
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   909
    "
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   910
     |p b|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   911
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   912
     b := [Transcript showCR:'the point changed'].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   913
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   914
     p := Point new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   915
     p onChangeSend:#value to:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   916
     p x:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   917
     Transcript showCR:'now changing'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   918
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   919
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   920
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   921
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   922
     Transcript showCR:'now changing'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   923
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   924
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   925
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   926
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   927
     Transcript showCR:'no more interest'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   928
     p retractInterestsFor:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   929
     Transcript showCR:'now changing again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   930
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   931
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   932
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   933
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   934
     Transcript showCR:'interest again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   935
     p onChangeSend:#value to:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   936
     Transcript showCR:'now changing again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   937
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   938
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   939
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   940
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   941
    "Created: 19.4.1996 / 10:26:38 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   942
    "Modified: 19.4.1996 / 12:34:26 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   943
    "Modified: 14.10.1996 / 22:28:27 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   944
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   945
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   946
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   947
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   948
removeInterest:anInterest
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   949
    "remove an interest forwarder.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   950
     Here, we use the nonWeakDependencies."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   951
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   952
    self removeNonWeakDependent:anInterest
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   953
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   954
    "Created: 14.10.1996 / 22:21:59 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   955
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   956
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   957
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   958
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   959
retractInterestIn:aspect for:someOne
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   960
    "remove the interest of someOne in the receiver changing aspect
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   961
     (as installed with #expressInterestIn:for:sendBack:)."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   962
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   963
    "/ for now, remove the interestConverter.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   964
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   965
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   966
    self retractInterestsForWhich:[:i | (i aspect == aspect) and:[i destination == someOne]]
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   967
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   968
    "
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   969
     |p b|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   970
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   971
     b := [Transcript showCR:'the point changed'].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   972
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   973
     p := Point new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   974
     Transcript showCR:'interest in #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   975
     p expressInterestIn:#foo for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   976
     p x:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   977
     Transcript showCR:'now changing #bar'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   978
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   979
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   980
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   981
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   982
     Transcript showCR:'now changing #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   983
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   984
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   985
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   986
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   987
     Transcript showCR:'no more interest in #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   988
     p retractInterestIn:#foo for:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   989
     Transcript showCR:'now changing #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   990
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   991
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   992
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   993
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   994
     Transcript showCR:'interest in #bar now'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   995
     p expressInterestIn:#bar for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   996
     Transcript showCR:'now changing #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   997
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   998
     Transcript showCR:'now changing #bar'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
   999
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1000
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1001
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1002
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1003
     Transcript showCR:'interest in #foo now'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1004
     p expressInterestIn:#foo for:b sendBack:#value.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1005
     Transcript showCR:'now changing #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1006
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1007
     Transcript showCR:'now changing #bar'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1008
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1009
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1010
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1011
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1012
     Transcript showCR:'no more interests'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1013
     p retractInterestsFor:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1014
     Transcript showCR:'now changing #foo'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1015
     p changed:#foo.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1016
     Transcript showCR:'now changing #bar'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1017
     p changed:#bar.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1018
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1019
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1020
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1021
    "Created: / 19.4.1996 / 10:27:11 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1022
    "Modified: / 14.10.1996 / 22:21:19 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1023
    "Modified: / 30.1.1998 / 14:05:34 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1024
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1025
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1026
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1027
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1028
retractInterests
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1029
    "remove all interests in the receiver changing aspect
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1030
     (as installed with #expressInterestIn:for:sendBack:)."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1031
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1032
    "/ for now, remove the interestConverter.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1033
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1034
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1035
    self retractInterestsForWhich:[:i | true ]
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1036
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1037
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1038
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1039
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1040
retractInterestsFor:someOne
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1041
    "remove the interest of someOne in the receiver
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1042
     (as installed with #onChangeSend:to:)."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1043
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1044
    "/ for now, remove the interestConverter.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1045
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1046
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1047
    self retractInterestsForWhich:[:i | i destination == someOne ]
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1048
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1049
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1050
     |p b|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1051
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1052
     b := [Transcript showCR:'the point changed'].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1053
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1054
     p := Point new.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1055
     p onChangeSend:#value to:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1056
     p x:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1057
     Transcript showCR:'now changing'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1058
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1059
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1060
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1061
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1062
     Transcript showCR:'now changing'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1063
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1064
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1065
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1066
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1067
     Transcript showCR:'no more interest'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1068
     p retractInterestsFor:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1069
     Transcript showCR:'now changing again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1070
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1071
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1072
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1073
     Delay waitForSeconds:1.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1074
     Transcript showCR:'interest again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1075
     p onChangeSend:#value to:b.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1076
     Transcript showCR:'now changing again'.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1077
     p changed.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1078
     Transcript cr.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1079
    "
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1080
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1081
    "Created: / 19.4.1996 / 10:23:46 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1082
    "Modified: / 14.10.1996 / 22:21:25 / stefan"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1083
    "Modified: / 30.1.1998 / 14:04:52 / cg"
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1084
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1085
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1086
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1087
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1088
retractInterestsForWhich:aBlock
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1089
    "remove all interests in the receiver changing aspect
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1090
     (as installed with #expressInterestIn:for:sendBack:)."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1091
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1092
    "/ for now, remove the interestConverter.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1093
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1094
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1095
    |deps coll|
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1096
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1097
    deps := self interests.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1098
    deps size ~~ 0 ifTrue:[
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1099
	"/ cannot removeDependent within the loop - the interests collection rehashes
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1100
	coll := OrderedCollection new.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1101
	deps do:[:dep |
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1102
	    dep isInterestConverter ifTrue:[
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1103
		(aBlock value:dep) ifTrue:[coll add:dep].
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1104
	    ]
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1105
	].
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1106
	coll do:[:dep |
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1107
	    self removeInterest:dep.
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1108
	].
1759
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1109
    ].
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1110
! !
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1111
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1112
!Object methodsFor:'dependents-interests'!
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1113
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1114
retractInterestsIn:aspect
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1115
    "remove all interests in the receiver changing aspect
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1116
     (as installed with #expressInterestIn:for:sendBack:)."
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1117
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1118
    "/ for now, remove the interestConverter.
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1119
    "/ In the future, a more intelligent DependencyCollection class is planned for
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1120
78e481899a63 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  1121
    self retractInterestsForWhich:[:i | i aspect == aspect ]
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1122
! !
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1123
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1124
!Object methodsFor:'dependents-st/v event simulation'!
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1125
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1126
when:eventSymbol send:selector to:anObject
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1127
    "install an ST/V-style interest forwarder.
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1128
     Here, we use the nonWeakDependencies."
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1129
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1130
    self addInterest:(InterestConverterWithParameters
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1131
			    destination:anObject
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1132
			    selector:selector
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1133
			    aspect:eventSymbol).
1668
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1134
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1135
    "
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1136
     |p b|
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1137
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1138
     b := [Transcript showCR:'the point changed'].
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1139
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1140
     p := Point new.
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1141
     p whem:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b].
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1142
     Transcript showCR:'now changing'.
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1143
     p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg').
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1144
     p retracrtInterests.
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1145
    "
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1146
! !
96c1701345c5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1147
2364
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1148
!Stream methodsFor:'stacked computing streams'!
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1149
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1150
collecting:aBlock
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1151
    "return a stacked computing stream, which reads elements from the receiver,
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1152
     applies aBlock to each read element, and provides the results as elements to its reader."
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1153
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1154
    ^ CollectingReadStream on:self collecting:aBlock
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1155
! !
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1156
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1157
!Stream methodsFor:'stacked computing streams'!
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1158
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1159
selecting:aBlock
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1160
    "return a stacked computing stream, which reads elements from the receiver,
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1161
     but only provides elements for which aBlock returns true to its reader."
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1162
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1163
    ^ SelectingReadStream on:self selecting:aBlock
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1164
! !
2b7b611e565c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
  1165
2303
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1166
!stx_libbasic2 class methodsFor:'documentation'!
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1167
74c77b8cf160 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
  1168
extensionsVersion_CVS
2679
cfab54d30fcc changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2582
diff changeset
  1169
    ^ '$Header: /cvs/stx/stx/libbasic2/extensions.st,v 1.20 2011-11-29 10:56:14 cg Exp $'
2582
85a5ed52fc7b changed:
Claus Gittinger <cg@exept.de>
parents: 2435
diff changeset
  1170
! !