PrintfScanf.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5361 2c50d797336c
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:libbasic2' }"
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
3539
c9d007677ac3 class: PrintfScanf
Stefan Vogel <sv@exept.de>
parents: 3115
diff changeset
     3
"{ NameSpace: Smalltalk }"
c9d007677ac3 class: PrintfScanf
Stefan Vogel <sv@exept.de>
parents: 3115
diff changeset
     4
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
Object subclass:#PrintfScanf
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
4084
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
     7
	classVariableNames:'Singleton'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'System-Support'
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
!PrintfScanf class methodsFor:'documentation'!
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
1465
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    14
documentation
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    15
"   
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    16
    Contributed by Jan Steinman donated to the community in 1989.
1465
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    17
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    18
    Provided AS-IS - no warranty, use at your own risk.
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    19
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    20
    Original comment:
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    21
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    22
        NAME            printf-scanf
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    23
        AUTHOR          Jan Steinman <jans@tekgvs.labs.tek.com>
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    24
        FUNCTION        printf and scanf for Smalltalk
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    25
        ST-VERSIONS     Tek 2.2.2a 4.0
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    26
        PREREQUISITES   CharacterComparing
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    27
        CONFLICTS       
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    28
        DISTRIBUTION    world
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    29
        VERSION         1.1
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    30
        DATE            Apr 1989?
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    31
        SUMMARY 
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    32
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    33
    The following methods implement printf and scanf functionality.  They
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    34
    are intended to be used to ease porting between Smalltalk and C, and
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    35
    for facilitating machine-machine communication.  They are not at all
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    36
    intended as replacements for Smalltalk's printOn: functionality.
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    37
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    38
    Jan Steinman - N7JDB
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    39
    Tektronix Electronic Systems Laboratory
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    40
    Box 500, MS 50-370, Beaverton, OR 97077
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    41
    (w)503/627-5881 (h)503/657-7703
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    42
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    43
    changes:
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    44
        slight changes to make it work with higher precision real numbers
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    45
        (i.e. asking for the precision instead of hard-coding it)
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
    46
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
    47
        no need for the singleton - classes are already singletons ready to use exactly for that.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
    48
        (no need to use C++/Java patterns here in Smalltalk)
4452
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    49
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    50
    Caveat:
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    51
        the behavior when the format-width is less than the preferred default precision is suboptimal;
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    52
        it leads to problems when trying to format tables into columns...
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    53
        For now: always use with width.precision formats to enforce the width.
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
    54
        The current behavior (generating longer strings like printf does) may change in the future.
1465
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    55
"
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    56
!
987dc3b0411f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
    57
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
examples
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
"
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    60
    self printf:'%#x %#X %03o%*.*s' arguments: #(16rABCD 16rEF 5 9 5 'ghijklmn')
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    61
            -> '0xabcd 0xEF 005    ghijk'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    63
    self printf:'%- 10.4s%.2e' arguments: { 'abcdefghijkl' . Float pi }  
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    64
            -> ' abcd      3.14e0'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    65
            
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    66
    self printf:'%8.3f' arguments: { 200 sqrt negated }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    67
            -> ' -14.142'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
4394
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    69
    self printf:'%8.3f' on:Transcript arguments: { 200 sqrt negated }
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    70
    self printf:'%10.4f' on:Transcript arguments: { 200 sqrt negated }
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    71
    self printf:'%20.10f' on:Transcript arguments: { 200 sqrt negated }
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    72
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    73
    self printf:'%20.10f' on:Transcript arguments: { 1.234567890123456789f  }
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
    74
    self printf:'%20.10f' on:Transcript arguments: { 1.234567890123456789q  }
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    76
    self printf:'%x' arguments: #(16r41)        -> '41' 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    77
    self printf:'%#x' arguments: #(16r41)       -> '0x41'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    78
    self printf:'%d' arguments: #(16r41)        -> '65'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    79
    self printf:'%b' arguments: #(16r41)        -> '1000001'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    80
    self printf:'%c' arguments: #(16r41)        -> 'A'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    81
    self printf:'%c' arguments: #( $A )         -> 'A'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    82
    self printf:'%s' arguments: #( $A )         -> 'A'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    83
    self printf:'%s' arguments: #( 'hello' )    -> 'hello'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    84
    self printf:'%4s' arguments: #( 'hello' )   -> 'hello'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    85
    self printf:'%7s' arguments: #( 'hello' )   -> '  hello'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    87
    self sscanf:'%f%2s%s%s%s' fromString: '237.0 this is a test' 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    88
            -> OrderedCollection(237.0 'th' 'is' 'is' 'a')
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    90
    self sscanf:'%d%f%s' fromString: '25 54.32e-01 monday'
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    91
            -> OrderedCollection(25 5.432 'monday')
1464
10af50b07968 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
    92
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    93
    self sscanf:'%f%*f %8[A-F0-9]%c%d 0x%x%f' fromString: '12.45 1048.73 AE40Z527 0x75BCD15 34' 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    94
            -> OrderedCollection(12.45 'AE40' 'Z' 527 123456789 34.0)
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    96
    '%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn') 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    97
            -> '0xabcd 0xEF 005    ghijk'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
3115
b1217780fad3 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 3004
diff changeset
    99
    '%- 10.4s%.2e' printf: { 'abcdefghijkl' . Float pi }  
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   100
            -> ' abcd      3.14e0'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
3115
b1217780fad3 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 3004
diff changeset
   102
    '%8.3f' printf: { 200 sqrt negated }
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   103
            -> ' -14.142'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    '%c' printf: #(16r41)
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   106
            -> 'A'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    '%f%2s%s%s%s' sscanf: '237.0 this is a test' 
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   109
            -> OrderedCollection(237.0 'th' 'is' 'is' 'a')
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    '%d%f%s' sscanf: '25 54.32e-01 monday'
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   112
            -> OrderedCollection(25 5.432 'monday')
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    '%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34'
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   115
            -> OrderedCollection(12.45 'AE40' 'Z' 527 123456789 34.0)
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   116
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   117
    '%d\n' printf:{ 1234 } on:Transcript    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   118
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   119
    '%f\n' printf:{ 1234.0 } on:Transcript        
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   120
    '%f\n' printf:{ 1234.0 asShortFloat } on:Transcript        
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   121
    '%f\n' printf:{ 1234.0 asLongFloat } on:Transcript        
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   122
    '%f\n' printf:{ 1234.0 asQDouble } on:Transcript        
4622
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   123
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   124
    '%p\n' printf:{ 10@20 } on:Transcript        
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   125
    '%P\n' printf:{ 10@20 } on:Transcript        
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   126
    '%S\n' printf:{ 10@20 } on:Transcript        
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
"
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   128
!
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   129
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   130
format_printf
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   131
"
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   132
    Printf Format specifier:
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   133
    
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   134
    required: leading '%'
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   135
        optional: '-' (POSIX refers to this as the <<flags>>)
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   136
        optional: positive number or '*' (POSIX: <<width>>)
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   137
        optional: period followed by positive number or * (POSIX: <<precision>>)
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   138
        optional: an h or l to indicate size of data (POSIX: <<length>>)
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   139
        required: character describing output behavior (POSIX: <<conversion specifier>>)
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   140
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   141
    Various implementations of printf have added different functionality.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   142
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   143
    ANSI standards up through C99:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   144
        more flags '+' ' ' '0' '#'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   145
        more lengths 'L' 'hh' 'll' 'j' 'z' 't'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   146
        more conversions 'F' 'a' 'A' 'n'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   147
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   148
    The POSIX specification of printf added:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   149
        positional parameters to identify argument indices
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   150
        more flags ''' (single quote)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   151
        more conversions 'C' 'S'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   152
        clarifications regarding corner cases and 'undefined behavior'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   153
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   154
    BSD implementations added:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   155
        more lengths 'q'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   156
        more conversions 'D' 'U' 'O'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   157
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   158
    glibc (GNU) added:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   159
        more lengths 'Z'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   160
        more conversions 'm'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   161
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   162
    Windows C Runtime (CRT) added:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   163
        more lengths 'I' 'I32' 'I64' 'w'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   164
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   165
    glibc and CRT both added length 'Z'. 
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   166
        glibc uses 'Z' for the length size_t. 
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   167
        CRT uses Z as a conversion for length-prefixed strings. 
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   168
    This implementation takes the former approach, handling 'Z' in the same way as 'z'.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   169
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   170
    BSD and IBM C library both added 'D'. 
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   171
        BSD uses D as a conversion, namely as an alias of 'ld'. 
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   172
        IBM uses 'D' for the length for _Decimal64, a decimal floating point type, 
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   173
        in accordance with ISO/IEC TR 24732. 
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   174
    This implementation takes the former approach.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   175
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   176
    ================================================================
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   177
    
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   178
    This implementation also adds new conversions:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   179
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   180
        'b' and 'B' for binary (base-2) integer renderings
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   181
        'y' and 'Y' for true/false and yes/no Boolean conversions
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   182
        'J' for JSON
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   183
        'T' and 'V' for JS typeof and valueOf inspection
4622
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   184
        'S' for store-string
9f3869b87a95 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   185
        'P' for print-string
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   186
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   187
    Conversions (upper case same as lower case, except for xX):
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   188
        'a'     (not implemented) hex floating point exp form
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   189
        'b'     binary (base 2)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   190
        'c'     character or (first char of string)
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   191
        'd'     integer
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   192
        'e'     base-10 floating point exp form (scientific)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   193
        'f'     base-10 floating point decimal form (non-scientific)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   194
        'g'     'e' or 'f', whichever looks more appropriate (based on value)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   195
        'i'     integer (alias for 'd')
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   196
        'j'     (not implemented) JSON format
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   197
        'n'     (not implemented) stores number of characters written so far into arg 
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   198
        'o'     base-8 octal
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   199
        'p'     (not implemented) pointer 
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   200
        's'     string
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   201
        't'     type (i.e. class name)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   202
        'u'     (not implemented) unsigned (negative values are converted)
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   203
        'v'     (not implemented) store string
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   204
        'x'     base-16 hex
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   205
        'X'     base-16 hex upper case
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   206
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   207
    Parameter selection (not implemented):
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   208
        <n>$    take n'th parameter
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   209
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   210
    Dynamic width/precision (consumed in order as presented):
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   211
        *       take width/parameter from next argument
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   212
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   213
    Examples:
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   214
        PrintfScanf printf:'|%d|'  arguments:{ 123 }         -> '|123|'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   215
        PrintfScanf printf:'|%5d|' arguments:{ 123 }         -> '|  123|'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   216
        PrintfScanf printf:'|%-5d|' arguments:{ 123 }        -> '|123  |'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   217
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   218
        PrintfScanf printf:'|%s|'  arguments:{ 'abc' }        -> '|abc|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   219
        PrintfScanf printf:'|%5s|'  arguments:{ 'abc' }       -> '|  abc|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   220
        PrintfScanf printf:'|%*s|'  arguments:{ 5 . 'abc' }   -> '|  abc|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   221
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   222
        PrintfScanf printf:'|%8f|'  arguments:{ 1.234 }       -> '|   1.234|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   223
        PrintfScanf printf:'|%*f|'  arguments:{ 8 . 1.234 }   -> '|   1.234|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   224
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   225
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   226
    Negative width will fill at the right:
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   227
        PrintfScanf printf:'|%5s|'  arguments:{ 'abc' }      -> '|  abc|'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   228
        PrintfScanf printf:'|%-5s|' arguments:{ 'abc' }      -> '|abc  |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   229
        PrintfScanf printf:'|%-*s|' arguments:{ 5 . 'abc' }  -> '|abc  |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   230
        PrintfScanf printf:'|%*s|'  arguments:{ -5 . 'abc' } -> '|abc  |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   231
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   232
        PrintfScanf printf:'|%*f|'  arguments:{ -8 . 1.234 }  -> '|1.234   |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   233
        PrintfScanf printf:'|%-8f|'  arguments:{ 1.234 }      -> '|1.234   |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   234
        PrintfScanf printf:'|%-*f|'  arguments:{ 8 . 1.234 }  -> '|1.234   |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   235
        PrintfScanf printf:'|%-*f|'  arguments:{ -8 . 1.234 } -> '|1.234   |'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   236
4435
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   237
    A Zero as fill character:
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   238
        PrintfScanf printf:'|%05s|'  arguments:{ 'abc' }     -> '|00abc|'
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   239
        PrintfScanf printf:'|%-05s|' arguments:{ 'abc' }     -> '|abc00|'
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   240
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   241
        PrintfScanf printf:'|%0*f|'  arguments:{ -8 . 1.234 }  -> '|1.234   |'
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   242
        PrintfScanf printf:'|%-8f|'  arguments:{ 1.234 }      -> '|1.234   |'
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   243
        PrintfScanf printf:'|%-*f|'  arguments:{ 8 . 1.234 }  -> '|1.234   |'
96ba42c85b3e #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4434
diff changeset
   244
        PrintfScanf printf:'|%-*f|'  arguments:{ -8 . 1.234 } -> '|1.234   |'
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   245
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   246
    Case of float-format character only affects printing of Nan and infinity:
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   247
        PrintfScanf printf:'%f' argument:1.234    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   248
        PrintfScanf printf:'%F' argument:1.234    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   249
        PrintfScanf printf:'%f' argument:(Float NaN)    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   250
        PrintfScanf printf:'%F' argument:(Float NaN)    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   251
        PrintfScanf printf:'%f' argument:(Float infinity)    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   252
        PrintfScanf printf:'%F' argument:(Float infinity)    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   253
        PrintfScanf printf:'%f' argument:(Float negativeInfinity)    
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   254
        PrintfScanf printf:'%F' argument:(Float negativeInfinity)    
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   255
"
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   256
!
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   257
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   258
format_scanf
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   259
"
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   260
    Scanf format specifier:
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   261
    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   262
        required: leading '%'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   263
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   264
    ================================================================
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   265
    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   266
    This implementation also adds new conversions:
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   267
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   268
    Conversions (upper case same as lower case):
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   269
        'b'     binary (base 2)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   270
        'c'     character or (first char of string)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   271
        'd'     decimal
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   272
        'e'     float
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   273
        'f'     float
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   274
        'g'     float
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   275
        'i'     integer (alias for 'd')
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   276
        'o'     base-8 octal
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   277
        's'     string
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   278
        'u'     integer
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   279
        'x'     base-16 hex
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
   280
        'n'     any number
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   281
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   282
    Length prefix:
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   283
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   284
        'h'     with float formats: reads as ShortFloat
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   285
        'L'     with float formats: reads as LongFloat
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   286
        'LL'    with float formats: reads as QDouble
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   287
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   288
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   289
     '%d %x' sscanf:'1234 ff00'         -> OrderedCollection(1234 65280)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   290
     '%d %s' sscanf:'1234 ff00'         -> OrderedCollection(1234 'ff00')
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   291
     '%d %x %b' sscanf:'1234 ff00 1001' -> OrderedCollection(1234 65280 9)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   292
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   293
     ('%f' sscanf:'1234') first         -> 1234.0 (Float i.e. an IEEE double)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   294
     ('%lf' sscanf:'1234') first        -> 1234.0 (Float i.e. an IEEE double)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   295
     ('%llf' sscanf:'1234') first       -> 1234.0 (Float i.e. an IEEE double)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   296
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   297
     ('%hf' sscanf:'1234') first        -> 1234.0 (ShortFloat i.e. an IEEE double)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   298
     ('%Lf' sscanf:'1234') first        -> 1234.0 (LongFloat i.e. an IEEE quad)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   299
     ('%LLf' sscanf:'1234') first       -> 1234.0 (QDouble)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
   300
"
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
! !
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
4084
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   303
!PrintfScanf class methodsFor:'instance creation'!
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   304
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   305
new
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   306
    Singleton isNil ifTrue:[
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   307
        Singleton := self basicNew
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   308
    ].    
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   309
    ^ Singleton
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   310
! !
14a4edd54856 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
   311
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   312
!PrintfScanf class methodsFor:'printing'!
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   313
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   314
printArgFrom:formatStream to:outStream arguments:argStream
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   315
    "Interpret the required number of arguments from <argStream>
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   316
     according to the formatting information in <formatStream>.  
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   317
     Place the interpretation on <outStream>.  
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   318
     The interpretation is C printf(3) style, as described in the UTek manual page for printf(3).  
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   319
     <formatStream> is assumed to be positioned just past
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   320
     $%, and a complete control string is assumed available.     
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   321
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   322
     Return when the conversion control string is consumed.  
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   323
     Leave <formatStream> pointing past the last character in the conversion control string.
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   324
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   325
     This code assumes that <formatStream> is formatted according to
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   326
     specification, and error checking is minimal.  
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   327
     Unexpected results will be obtained by illegal control strings, or when
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   328
     argument types do not match conversion codes, but it probably ;-)
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   329
     won't dump core, like C does in such cases!!!!"    
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   330
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   331
    |nextArg ljust plus pound width precision spaceIfPositive thousands
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   332
     pad char arg argString more precisionisMin
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   333
     spaceOrSignChar "space or sign character at left"
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   334
     intVal poundPrefix|
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   335
4996
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   336
    nextArg := 
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   337
        [
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   338
            argStream atEnd ifTrue:[
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   339
                ArgumentError raiseErrorString:'not enough arguments for format string'
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   340
            ].
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   341
            argStream next
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   342
        ].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   343
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   344
    ljust := plus := pound := spaceIfPositive := thousands := precisionisMin := false.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   345
    poundPrefix := nil.
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   346
    width := 0.
4401
a29669a0e2a1 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4394
diff changeset
   347
    precision := nil.
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   348
    pad := Character space.
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   349
    char := formatStream peek.
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   350
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   351
    char isNil ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   352
        ^ nil
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   353
    ].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   354
    char == $% ifTrue:[ 
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   355
        ^ outStream nextPut: formatStream next
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   356
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   357
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   358
    "/ flag(s):
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   359
    [
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   360
        more := false.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   361
        char == $- ifTrue:[
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   362
            ljust := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   363
            pad := Character space.         "/ see unix manual: if 0 AND - appear, o is ignored
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   364
            more := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   365
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   366
        char == $  ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   367
            spaceIfPositive := true.
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   368
            more := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   369
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   370
        char == $+ ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   371
            plus := true.  
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   372
            more := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   373
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   374
        char == $# ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   375
            pound := true.  
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   376
            more := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   377
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   378
        char == $0 ifTrue: [
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   379
            ljust ifFalse:[ pad := $0 ].    "/ see unix manual: if 0 AND - appear, o is ignored
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   380
            more := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   381
        ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   382
        char == $' ifTrue: [
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   383
            thousands := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   384
            more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   385
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   386
        "/ char == $I ifTrue: [
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   387
        "/     "/ ignored (new in glibc2.2)
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   388
        "/     more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   389
        "/ ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   390
        more ifTrue:[
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   391
            formatStream next.  
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   392
            char := formatStream peek.
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   393
        ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   394
    ] doWhile:[more].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   395
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   396
    "/ possibly a width
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   397
    char == $* ifTrue:[
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   398
        width := nextArg value. 
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   399
        width isInteger ifFalse:[
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   400
            self error:'non integer width argument in printf'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   401
        ].
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   402
        width < 0 ifTrue:[
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   403
            ljust := true.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   404
            width := width negated
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   405
        ].    
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   406
        formatStream next.  
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   407
        char := formatStream peek
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   408
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   409
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   410
    char isDigit ifTrue:[
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   411
        char == $0 ifTrue: [
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   412
            ljust ifFalse:[pad := $0].  "/ see unix manual: if 0 AND - appear, o is ignored
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   413
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   414
        width := Integer readFrom:formatStream allowRadix:false onError:0.  
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   415
        char := formatStream peek
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   416
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   417
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   418
    "/ precision separator
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   419
    
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   420
    char == $. ifTrue:[
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   421
        formatStream next.  char := formatStream peek.
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   422
        char == $* ifTrue: [
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   423
            precision := nextArg value.  
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   424
            precision isInteger ifFalse:[
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   425
                self error:'non integer precision argument in printf'
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   426
            ].    
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   427
            formatStream next.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   428
        ] ifFalse: [
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   429
            precision := Integer readFrom: formatStream.
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   430
        ].
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   431
        char := formatStream peek
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   432
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   433
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   434
    "/ length modifier(s)
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   435
    [
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   436
        more := false.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   437
        ((char == $l) or:[char == $L]) ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   438
            "Ignore long specifiers"
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   439
            more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   440
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   441
        char == $h ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   442
            "Ignore half-length (short) specifier."
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   443
            more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   444
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   445
        char == $j ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   446
            "Ignore intmax-length specifier."
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   447
            more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   448
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   449
        char == $t ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   450
            "Ignore ptrdiff-length specifier."
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   451
            more := true.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   452
        ].
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   453
        char == $z ifTrue:[
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   454
            "Ignore size_t-length specifier."
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   455
            more := true.
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   456
        ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   457
        more ifTrue:[
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   458
            formatStream next.  
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   459
            char := formatStream peek.
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   460
        ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   461
    ] doWhile:[more].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   462
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   463
    ('fegFEG' includes: char) ifTrue:[
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   464
        arg := nextArg value.
5193
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   465
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   466
        (arg isNaN or:[arg isFinite not]) ifTrue:[
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   467
            argString := arg printString.
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   468
            (char isUppercase) 
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   469
                ifTrue:[ argString := argString asUppercase ] 
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   470
                ifFalse:[ argString := argString asLowercase ].
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   471
            arg positive ifTrue:[
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   472
                plus ifTrue: [
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   473
                    argString := '+', argString
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   474
                ] ifFalse:[
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   475
                    spaceIfPositive ifTrue: [
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   476
                        argString := ' ', argString
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   477
                    ].
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   478
                ].
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   479
            ].
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   480
        ] ifFalse:[
5193
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   481
            arg isLimitedPrecisionReal ifTrue:[
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   482
                precision := precision ? (arg class defaultPrintPrecision).
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   483
            ] ifFalse:[ 
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   484
                arg := arg asFloat.
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   485
                precision := precision ? (Float defaultPrintPrecision).
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   486
            ].    
b0a97940f538 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5192
diff changeset
   487
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   488
            argString := WriteStream on:''.
5158
a711395e3175 #TUNING by exept
Claus Gittinger <cg@exept.de>
parents: 4996
diff changeset
   489
            (char == $g or:[char == $G]) ifTrue: [ 
a711395e3175 #TUNING by exept
Claus Gittinger <cg@exept.de>
parents: 4996
diff changeset
   490
                self absPrintFloat:arg on:argString digits:(precision + 1) 
5330
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   491
            ] ifFalse:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   492
                (char == $f or:[char == $F]) ifTrue: [
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   493
                    |absArg nDigits|
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   494
                    absArg := arg abs.
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   495
                    nDigits := absArg = 0 ifTrue:[1] ifFalse:[absArg log10 ceiling asInteger abs].
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   496
                    self absDecimalPrintFloat:arg on:argString digits:(precision + nDigits "+ 1")
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   497
                ] ifFalse:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   498
                    (char == $e or:[char == $E]) ifTrue: [
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   499
                        self absScientificPrintFloat:arg on:argString digits:(precision + 1)
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   500
                    ].
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   501
                ].
5158
a711395e3175 #TUNING by exept
Claus Gittinger <cg@exept.de>
parents: 4996
diff changeset
   502
            ].
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   503
            argString := argString contents.
5343
031208b37c1d #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5330
diff changeset
   504
            arg negative ifTrue: [
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   505
                argString := '-', argString
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   506
            ] ifFalse: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   507
                plus ifTrue: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   508
                    argString := '+', argString
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   509
                ] ifFalse:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   510
                    spaceIfPositive ifTrue: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   511
                        argString := ' ', argString
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   512
                    ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   513
                ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   514
            ].
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   515
5158
a711395e3175 #TUNING by exept
Claus Gittinger <cg@exept.de>
parents: 4996
diff changeset
   516
            (precision == 0 and: [pound not]) ifTrue:[
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   517
                (argString includes: $e)
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   518
                    ifTrue: ["self halt"]
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   519
                    ifFalse: [ argString := arg truncated printString]
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   520
            ].
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   521
            pound ifTrue:[
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   522
                (argString includes: $e)
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   523
                    ifTrue: ["self halt"]
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   524
                    ifFalse:[
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   525
                        precision - (argString size - (argString indexOf: $.)) 
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   526
                            timesRepeat:[ argString := argString, '0']
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   527
                    ]
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   528
            ].
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   529
        ].
4394
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
   530
        ljust ifTrue: [outStream nextPutAll: argString].
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   531
        (width - argString size) timesRepeat: [outStream nextPut: pad].
4394
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
   532
        ljust ifFalse: [outStream nextPutAll: argString].
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   533
        ^ formatStream next
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   534
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   535
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   536
    char == $c ifTrue:[
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   537
        arg := nextArg value.
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   538
        arg isString ifTrue:[
5192
674ac6172b1f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5191
diff changeset
   539
            arg := arg first asString
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   540
        ] ifFalse:[    
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   541
            arg := arg asCharacter asString
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   542
        ].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   543
    ].
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   544
        
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   545
    char == $s ifTrue:[
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   546
        "Assume the arg is a String or Symbol."
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   547
        arg := nextArg value asString
5360
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   548
    ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   549
        ((char == $d) or:[char == $D or:[char == $i]]) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   550
            intVal := nextArg value asInteger.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   551
            arg := intVal abs printString.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   552
        ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   553
            ((char == $o) or:[char == $O]) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   554
                "/ incompatibility here: printf prints it as an unsigned in 16/32/64 bits
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   555
                "/ Q: how many bits should we use for LargeIntegers,
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   556
                "/    or should we print a sign here???
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   557
                "/ For now, the code prints a sign
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   558
                intVal := nextArg value asInteger.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   559
                arg := intVal abs printStringRadix: 8.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   560
                pound ifTrue: [
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   561
                    intVal ~~ 0 ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   562
                        poundPrefix := '0'
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   563
                    ]
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   564
                ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   565
            ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   566
                ((char == $x) or:[char == $X]) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   567
                    intVal := nextArg value asInteger.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   568
                    arg := intVal abs printStringRadix: 16.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   569
                    pound ifTrue: [
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   570
                        intVal ~~ 0 ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   571
                            poundPrefix := ((char == $x) ifTrue:['0x'] ifFalse:['0X']).
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   572
                        ]
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   573
                    ].
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   574
5360
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   575
                    char == $x ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   576
                        "/ make it lowercase
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   577
                        arg := arg asLowercase.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   578
"/                        1 to: arg size do: [:i |
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   579
"/                            ('ABCDEF' includes: (arg at: i)) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   580
"/                                arg at: i put: (arg at: i) asLowercase
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   581
"/                            ]
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   582
"/                        ]
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   583
                    ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   584
                ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   585
                    ((char == $b) or:[char == $B]) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   586
                        intVal := nextArg value asInteger.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   587
                        arg := intVal abs printStringRadix: 2.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   588
                        pound ifTrue: [
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   589
                            intVal ~~ 0 ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   590
                                poundPrefix := '0b'
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   591
                            ]
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   592
                        ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   593
                    ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   594
                        char == $u ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   595
                            "/ should we convert unsigned numbers here???
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   596
                            "/ (negatives: maybe to the next power-of-2)
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   597
                            intVal := nextArg value asInteger.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   598
                            arg := intVal abs printString.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   599
                        ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   600
                            (char == $p) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   601
                                arg := nextArg value identityHash printString.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   602
                                precisionisMin := true.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   603
                            ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   604
                                (char == $P) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   605
                                    arg := nextArg value printString.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   606
                                ] ifFalse:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   607
                                    (char == $S) ifTrue:[
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   608
                                        arg := nextArg value storeString.
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   609
                                    ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   610
                                ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   611
                            ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   612
                        ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   613
                    ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   614
                ].
60841ec4a7f7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5347
diff changeset
   615
            ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   616
        ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   617
    ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   618
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   619
    arg isNil ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   620
        arg := char asString.  "/ fallback for all others
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   621
    ].
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   622
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   623
    intVal notNil ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   624
        "/ format is one of doixb
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   625
        intVal < 0 ifTrue: [
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   626
            spaceOrSignChar := $-
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   627
        ] ifFalse: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   628
            plus ifTrue: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   629
                spaceOrSignChar := $+
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   630
            ] ifFalse:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   631
                spaceIfPositive ifTrue: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   632
                    spaceOrSignChar := Character space
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   633
                ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   634
            ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   635
        ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   636
        intVal ~~ 0 ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   637
            precisionisMin := true.
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   638
        ].
2889
7491ae1f59ac class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
   639
    ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   640
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   641
    poundPrefix notNil ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   642
        (pad ~~ $0 or:[ljust]) ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   643
            arg := poundPrefix , arg.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   644
            poundPrefix := nil.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   645
        ]
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   646
    ].
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   647
    spaceOrSignChar notNil ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   648
        (pad ~~ $0 or:[ljust]) ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   649
            arg := spaceOrSignChar , arg.
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   650
            spaceOrSignChar := nil.
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   651
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   652
    ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   653
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   654
    precisionisMin ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   655
        precision := (precision ? 1) max:(arg size).
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   656
    ] ifFalse:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   657
        precision := (precision ? arg size) min:(arg size).
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   658
    ].
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   659
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   660
    ljust ifTrue: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   661
        precision > 0 ifTrue:[ 
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   662
            outStream nextPutAll:(arg copyTo: precision)
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   663
        ]
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   664
    ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   665
    spaceOrSignChar notNil ifTrue:[
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   666
        outStream nextPut:spaceOrSignChar.
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   667
        width := width - 1.
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   668
    ].
5191
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   669
    poundPrefix notNil ifTrue:[
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   670
        outStream nextPutAll:poundPrefix.
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   671
        width := width - (poundPrefix size).
16a20c9f63dd #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5190
diff changeset
   672
    ].
5190
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   673
    (width - precision) timesRepeat: [outStream nextPut: pad].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   674
    ljust ifFalse: [
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   675
        precision > 0 ifTrue:[ 
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   676
            outStream nextPutAll:(arg copyTo: precision)
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   677
        ].
80688d0e9f12 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5158
diff changeset
   678
    ].
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   679
    ^ formatStream next
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   680
4472
cd76ffe41e4c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4471
diff changeset
   681
    "Modified: / 14-07-2017 / 11:42:01 / cg"
4996
a77894b60558 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
   682
    "Modified: / 06-06-2019 / 23:23:01 / Claus Gittinger"
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   683
!
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   684
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   685
printf:formatString argument:arg 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   686
    "Format and print the receiver with <arg> formatted in C style, 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   687
     as described in the UTek manual page for printf(3)."
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   688
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   689
    ^ self printf:formatString arguments:{ arg }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   690
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   691
    "
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   692
     self printf:'%e' on:Transcript argument:(1.234 asShortFloat)
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   693
     self printf:'%e' on:Transcript argument:(1.234 asFloat)     
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   694
     self printf:'%e' on:Transcript argument:(1.234 asLongFloat) 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   695
     self printf:'%e' on:Transcript argument:(1.234 asQDouble)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   696
     self printf:'%e' on:Transcript argument:(1.234 asInteger)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   697
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   698
     self printf:'%10e' on:Transcript argument:(1.234 asShortFloat)
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   699
     self printf:'%10e' on:Transcript argument:(1.234 asFloat)     
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   700
     self printf:'%10e' on:Transcript argument:(1.234 asLongFloat) 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   701
     self printf:'%10e' on:Transcript argument:(1.234 asQDouble)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   702
     self printf:'%10e' on:Transcript argument:(1.234 asInteger)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   703
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   704
     self printf:'%010e' on:Transcript argument:(1.234 asInteger)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   705
     self printf:'%-10e' on:Transcript argument:(1.234 asInteger)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   706
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   707
     self printf:'%10.9f' on:Transcript argument:(1.2345 asShortFloat)
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   708
     self printf:'%10.9f' on:Transcript argument:(1.2345 asFloat)     
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   709
     self printf:'%10.9f' on:Transcript argument:(1.2345 asLongFloat) 
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   710
     self printf:'%10.9f' on:Transcript argument:(1.2345 asQDouble)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   711
     self printf:'%10.9f' on:Transcript argument:(1.2345 asInteger)   
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   712
    "
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   713
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   714
    "Created: / 16-06-2017 / 14:50:08 / cg"
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   715
!
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   716
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   717
printf:formatString arguments:args 
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   718
    "Format and print the receiver with <args> formatted in C style, 
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   719
     as described in the UTek manual page for printf(3)."
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   720
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   721
    |aStream|
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   722
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   723
    aStream := WriteStream on:(formatString species new:100).
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   724
    self printf:formatString on:aStream arguments:args.
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   725
    ^ aStream contents
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   726
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   727
    "
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   728
     self printf:'%e' on:Transcript arguments:{ (1.234 asShortFloat) }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   729
     self printf:'%e' on:Transcript arguments:{ (1.234 asFloat)      }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   730
     self printf:'%e' on:Transcript arguments:{ (1.234 asLongFloat)  }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   731
     self printf:'%e' on:Transcript arguments:{ (1.234 asQDouble)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   732
     self printf:'%e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   733
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   734
     self printf:'%10e' on:Transcript arguments:{ (1.234 asShortFloat) }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   735
     self printf:'%10e' on:Transcript arguments:{ (1.234 asFloat)      }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   736
     self printf:'%10e' on:Transcript arguments:{ (1.234 asLongFloat)  }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   737
     self printf:'%10e' on:Transcript arguments:{ (1.234 asQDouble)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   738
     self printf:'%10e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   739
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   740
     self printf:'%010e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   741
     self printf:'%-10e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   742
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   743
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asShortFloat) }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   744
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asFloat)      }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   745
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asLongFloat)  }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   746
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asQDouble)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   747
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asInteger)    }
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   748
    "
4394
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
   749
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   750
    "Modified: / 19-06-2017 / 15:21:34 / cg"
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   751
!
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   752
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   753
printf:formatString on:outStream argument: arg
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   754
    "Format and print formatString on <outStream> with <arg>
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   755
     formatted in C style, as described in the UTek manual page for
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   756
     printf(3)."     
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   757
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   758
    ^ self printf:formatString on:outStream arguments:{ arg }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   759
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   760
    "
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   761
     self printf:'%e' on:Transcript argument:(1.234 asShortFloat). Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   762
     self printf:'%e' on:Transcript argument:(1.234 asFloat)     . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   763
     self printf:'%e' on:Transcript argument:(1.234 asLongFloat) . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   764
     self printf:'%e' on:Transcript argument:(1.234 asQDouble)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   765
     self printf:'%e' on:Transcript argument:(1.234 asInteger)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   766
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   767
     self printf:'%10e' on:Transcript argument:(1.234 asShortFloat). Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   768
     self printf:'%10e' on:Transcript argument:(1.234 asFloat)     . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   769
     self printf:'%10e' on:Transcript argument:(1.234 asLongFloat) . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   770
     self printf:'%10e' on:Transcript argument:(1.234 asQDouble)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   771
     self printf:'%10e' on:Transcript argument:(1.234 asInteger)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   772
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   773
     self printf:'%010e' on:Transcript argument:(1.234 asInteger)  . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   774
     self printf:'%-10e' on:Transcript argument:(1.234 asInteger)  . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   775
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   776
     self printf:'%10.9f' on:Transcript argument:(1.2345 asShortFloat). Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   777
     self printf:'%10.9f' on:Transcript argument:(1.2345 asFloat)     . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   778
     self printf:'%10.9f' on:Transcript argument:(1.2345 asLongFloat) . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   779
     self printf:'%10.9f' on:Transcript argument:(1.2345 asQDouble)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   780
     self printf:'%10.9f' on:Transcript argument:(1.2345 asInteger)   . Transcript cr.
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   781
    "
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   782
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   783
    "Created: / 16-06-2017 / 14:50:40 / cg"
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   784
    "Modified (comment): / 19-06-2017 / 15:07:22 / cg"
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   785
!
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   786
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   787
printf:aFormatString on:outStream arguments: args
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   788
    "Format and print aFormatString on <outStream> with <args>
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   789
     formatted in C style, as described in the UTek manual page for
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   790
     printf(3)."     
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   791
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   792
    | argStream formatStream char escChar |
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   793
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   794
    argStream := ReadStream on: args.
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   795
    formatStream := ReadStream on: aFormatString.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   796
    [formatStream atEnd] whileFalse:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   797
        (char := formatStream next) == $% ifFalse: [
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   798
            char == $\ ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   799
                escChar := formatStream next.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   800
                escChar == $n ifTrue:[ char := Character nl ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   801
                ifFalse:[ escChar == $t ifTrue:[ char := Character tab ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   802
                ifFalse:[ escChar == $r ifTrue:[ char := Character return ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   803
                ifFalse:[ char := escChar ]]]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   804
            ].        
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   805
            outStream nextPut:char
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   806
        ] ifTrue: [
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   807
            self printArgFrom:formatStream to:outStream arguments:argStream
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   808
        ]
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   809
    ]
4394
c63e80fb5b12 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4094
diff changeset
   810
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   811
    "
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   812
     self printf:'%e\n' on:Transcript arguments:{ (1.234 asShortFloat) }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   813
     self printf:'%f\n' on:Transcript arguments:{ (1.234 asShortFloat) }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   814
     self printf:'%g\n' on:Transcript arguments:{ (1.234 asShortFloat) }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   815
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   816
     self printf:'%e\n' on:Transcript arguments:{ (1.234 asFloat)      }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   817
     self printf:'%f\n' on:Transcript arguments:{ (1.234 asFloat)      }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   818
     self printf:'%g\n' on:Transcript arguments:{ (1.234 asFloat)      }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   819
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   820
     self printf:'%e\n' on:Transcript arguments:{ (1.234 asLongFloat)  }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   821
     self printf:'%e\n' on:Transcript arguments:{ (1.234 asQDouble)    }
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   822
     self printf:'%e\n' on:Transcript arguments:{ (1.234 asInteger)    }
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   823
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   824
     self printf:'%10e' on:Transcript arguments:{ (1.234 asShortFloat) }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   825
     self printf:'%10e' on:Transcript arguments:{ (1.234 asFloat)      }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   826
     self printf:'%10e' on:Transcript arguments:{ (1.234 asLongFloat)  }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   827
     self printf:'%10e' on:Transcript arguments:{ (1.234 asQDouble)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   828
     self printf:'%10e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   829
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   830
     self printf:'%010e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   831
     self printf:'%-10e' on:Transcript arguments:{ (1.234 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   832
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   833
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asShortFloat) }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   834
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asFloat)      }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   835
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asLongFloat)  }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   836
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asQDouble)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   837
     self printf:'%10.9f' on:Transcript arguments:{ (1.2345 asInteger)    }
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   838
    "
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   839
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   840
    "Modified (comment): / 19-06-2017 / 15:49:10 / cg"
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   841
! !
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   842
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   843
!PrintfScanf class methodsFor:'private helpers'!
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   844
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   845
absDecimalPrintFloat:aFloat on:aStream digits:digits 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   846
    "Place a string representation of the receiver on <aStream>,
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   847
     using <digits> significant digits, using decimal notation."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   848
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   849
    "
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   850
     self printf:'%20.10f\n' on:Transcript arguments: { 1.234567890123456789f  }
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   851
     self printf:'%20.10f\n' on:Transcript arguments: { 1.234567890123456789q  }
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   852
5272
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   853
     self printf:'%20.10f\n' on:Transcript arguments: { 1e1000  }   
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   854
     self printf:'%20.10f\n' on:Transcript arguments: { 1e1000 asShortFloat }
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   855
     self printf:'%20.10f\n' on:Transcript arguments: { 1e1000 asLongFloat }
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   856
     self printf:'%20.10f\n' on:Transcript arguments: { 1e1000 asQDouble }
5272
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   857
     self printf:'%20.10f\n' on:Transcript arguments: { 1e1000 asQuadFloat }
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   858
5272
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   859
     self printf:'%20.10f\n' on:Transcript arguments: { 0.0   }
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   860
     self printf:'%20.10f\n' on:Transcript arguments: { 0.0 asShortFloat   }
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   861
     self printf:'%20.10f\n' on:Transcript arguments: { 0.0 asLongFloat   }
1f9fafb93f8a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5271
diff changeset
   862
     self printf:'%20.10f\n' on:Transcript arguments: { 0.0 asQDouble   }
4432
d4b8ac7168a6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4428
diff changeset
   863
4452
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
   864
     self printf:'%20.10f\n' on:Transcript arguments: { Float NaN   }
4434
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   865
     self printf:'%20.10f\n' on:Transcript arguments: { DomainError ignoreIn:[ -1.0 log10 ]   }
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   866
     self printf:'%20.10f\n' on:Transcript arguments: { DomainError ignoreIn:[ -1.0 asShortFloat log10 ]  }
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   867
     self printf:'%20.10f\n' on:Transcript arguments: { DomainError ignoreIn:[ -1.0 asLongFloat log10]   }
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   868
     self printf:'%20.10f\n' on:Transcript arguments: { DomainError ignoreIn:[ -1.0 asQDouble log10]   }
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   869
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   870
     self printf:'%10s\n' on:Transcript arguments:{ 'hello' }
92084009a524 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   871
     self printf:'%*s\n' on:Transcript arguments:{ 10 . 'hello' }
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   872
    "
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   873
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   874
    |absVal exp x fuzz i|
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   875
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   876
    aFloat isNaN ifTrue:[
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   877
        aStream nextPutAll:'NAN'.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   878
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   879
    ].
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   880
    aFloat isInfinite ifTrue:[
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   881
        aStream nextPutAll:'INF'.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   882
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   883
    ].
5361
2c50d797336c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
   884
    aFloat isZero ifTrue:[
2c50d797336c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
   885
        aStream nextPutAll:'0.0'.
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   886
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   887
    ].
5330
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   888
"/    (aFloat isFloat or:[aFloat isShortFloat]) ifTrue:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   889
"/        thisContext isRecursive ifFalse:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   890
"/            aStream nextPutAll:(aFloat printfPrintString:('%',digits printString,'f')).
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   891
"/            ^ self.
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   892
"/        ].
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   893
"/    ].
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   894
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   895
    absVal := aFloat abs.
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   896
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   897
    "x is myself normalized to (1.0, 10.0), exp is my exponent"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   898
    exp := absVal < 1.0 
4452
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
   899
            ifTrue:[ (10.0 / absVal asFloat) log10 floor negated ] 
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
   900
            ifFalse:[ absVal asFloat log10 floor].
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   901
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   902
    exp := exp asInteger.
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   903
    x := absVal / (10.0 raisedTo:exp).
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   904
    fuzz := 10.0 raisedTo:(1 - digits).
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   905
    "round the last digit to be printed"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   906
    x := 0.5 * fuzz + x.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   907
    x >= 10.0 ifTrue:[ 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   908
        "check if rounding has unnormalized x" 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   909
        x := x / 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   910
        exp := exp + 1
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   911
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   912
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   913
    exp < 0 ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   914
        1 to:(1 - exp) do:[:j | 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   915
            "/ cg: huh - what sort of code is that????
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   916
            "/ aStream nextPut:('0.000000000000' at:j)
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   917
            aStream nextPut:(j == 2 ifTrue:[$.] ifFalse:[$0])
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   918
        ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   919
        
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   920
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   921
    [ x >= fuzz ] whileTrue:[ 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   922
        "use fuzz to track significance" 
4422
92f08dfe59af #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
   923
        i := x truncated.
92f08dfe59af #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
   924
        i := i asInteger.
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
   925
        aStream nextPut:($0 + i).
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   926
        x := (x - i) * 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   927
        fuzz := fuzz * 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   928
        exp := exp - 1.
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   929
        exp == -1 ifTrue:[
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   930
            aStream nextPut:$.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   931
        ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   932
    ].
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   933
    
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   934
    [ exp >= -1 ] whileTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   935
        aStream nextPut:$0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   936
        exp := exp - 1.
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   937
        exp == -1 ifTrue:[
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   938
            aStream nextPut:$.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   939
        ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   940
    ]
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   941
4452
9b6b7249be74 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4441
diff changeset
   942
    "Modified: / 03-07-2017 / 14:13:31 / cg"
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   943
!
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   944
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   945
absPrintFloat:aFloat on:aStream digits:digits 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   946
    "Place a string representation of the receiver on <aStream>,
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   947
     using <digits> significant digits."
5271
101c0c1ea776 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5193
diff changeset
   948
101c0c1ea776 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5193
diff changeset
   949
    |absFloat|
101c0c1ea776 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5193
diff changeset
   950
101c0c1ea776 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5193
diff changeset
   951
    absFloat := aFloat abs.
101c0c1ea776 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5193
diff changeset
   952
    (absFloat < 1.0e6 and:[ absFloat > 1.0e-4 ]) ifTrue:[
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   953
        self absDecimalPrintFloat:aFloat on:aStream digits:digits
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   954
    ] ifFalse:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   955
        self absScientificPrintFloat:aFloat on:aStream digits:digits
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   956
    ]
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   957
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   958
    "Modified: / 19-06-2017 / 15:03:40 / cg"
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   959
!
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   960
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   961
absScientificPrintFloat:aFloat on:aStream digits:digits 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   962
    "Place a string representation of the receiver on <aStream>,
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   963
     using <digits> significant digits, using scientific notation."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   964
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   965
    |absVal exp fuzz x q i|
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   966
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   967
    aFloat isNaN ifTrue:[
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   968
        aStream nextPutAll:'NAN'.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   969
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   970
    ].
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   971
    aFloat isInfinite ifTrue:[
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   972
        aStream nextPutAll:'INF'.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   973
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   974
    ].
5347
737db4f09366 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5343
diff changeset
   975
    absVal := aFloat abs.
737db4f09366 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5343
diff changeset
   976
5361
2c50d797336c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
   977
    absVal isZero ifTrue:[
2c50d797336c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
   978
        aStream nextPutAll:'0.0'.
4428
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   979
        ^ self.
f44ab76503a6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4422
diff changeset
   980
    ].
5330
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   981
"/    (aFloat isFloat or:[aFloat isShortFloat]) ifTrue:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   982
"/        thisContext isRecursive ifFalse:[
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   983
"/            aStream nextPutAll:(aFloat printfPrintString:('%',digits printString,'e')).
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   984
"/            ^ self.
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   985
"/        ].
ad1a048f3dbb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5307
diff changeset
   986
"/    ].
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   987
    
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   988
    "x is myself normalized to [1.0, 10.0), exp is my exponent"
5307
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   989
    absVal < 1.0 ifTrue:[
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   990
        exp := (10.0 / absVal) log10 floor asInteger negated
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   991
    ] ifFalse:[
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   992
        exp := absVal log10 floor asInteger
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   993
    ].
e9b56e858f44 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5272
diff changeset
   994
    exp == 0 ifTrue:[x := absVal] ifFalse:[x := absVal / (10.0 raisedTo:exp)].
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   995
    "round the last digit to be printed"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
   996
    fuzz := 10.0 raisedTo:1 - digits.
4966
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
   997
    fuzz = 0 ifTrue:[
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
   998
        fuzz := 10.0 asLongFloat raisedTo:1 - digits. 
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
   999
        fuzz = 0 ifTrue:[
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  1000
            "/ self error:'too many digits'.
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  1001
            "/ fuzz := (10.0 asLargeFloatPrecision:((10 raisedTo:digits) integerLog2)) raisedTo:(1 - digits). 
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  1002
        ].    
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  1003
    ].    
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1004
    x := 0.5 * fuzz + x.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1005
    x >= 10.0 ifTrue:[ "check if rounding has unnormalized x" 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1006
        x := x / 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1007
        exp := exp + 1
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1008
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1009
    q := exp.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1010
    exp := 0.
4966
cc232f4d7d73 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  1011
    [ (x >= fuzz) and:[x ~= 0] ] whileTrue:[
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1012
        "use fuzz to track significance" 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1013
        i := x truncated.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1014
        i := i asInteger.
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
  1015
        aStream nextPut:($0 + i).
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1016
        x := (x - i) * 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1017
        fuzz := fuzz * 10.0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1018
        exp := exp - 1.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1019
        exp = -1 ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1020
            aStream nextPut:$.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1021
        ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1022
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1023
    [ exp >= -1 ] whileTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1024
        aStream nextPut:$0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1025
        exp := exp - 1.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1026
        exp = -1 ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1027
            aStream nextPut:$.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1028
        ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1029
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1030
    aStream nextPut:$e.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1031
    q printOn:aStream
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1032
4441
592237602835 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4435
diff changeset
  1033
    "Modified: / 21-06-2017 / 13:29:37 / cg"
4979
ba279ee92a60 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
  1034
    "Modified: / 05-06-2019 / 21:42:17 / Claus Gittinger"
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1035
!
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1036
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1037
formatArgCountFor:aFormatString
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1038
    "Return the number of arguments required/produced,
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1039
     if the argument is interpreted as a printf/scanf format control string."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1040
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1041
    |nonConsecutive count|
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1042
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1043
    nonConsecutive := true.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1044
    count := 0.
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1045
    aFormatString do:[:c |
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1046
        c == $% ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1047
            nonConsecutive ifTrue:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1048
                count := count + 1. 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1049
                nonConsecutive := false
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1050
            ] ifFalse:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1051
                count := count - 1. 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1052
                nonConsecutive := true
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1053
            ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1054
        ] ifFalse:[
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1055
            nonConsecutive := true
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1056
        ]
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1057
    ].
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1058
    ^ count
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1059
!
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
scanArgFrom:dataStream to:collection format:format 
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1062
    "Add to <collection> an object who's representation is found
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1063
     in <dataStream> interpreted according to the conversion
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
     control string in the Stream <format>.  <format> is assumed to
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
     be positioned just past a $%, and a complete control string is
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
     assumed available.    
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
     Return when the conversion control string is consumed.  Leave
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
     <format> pointing past the last character in the conversion
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
     control string, leave <dataStream> pointing past any width
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
     specified in <format>, or at the first character that doesn't
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
     make sense for the <format>."
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1073
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1074
    |final width char pos data scanset exclusive return last 
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1075
     isShort isLong isLongLong isLongDouble isLongLongDouble|
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
    final := [:retval | 
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
            collection add:retval.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
            data == dataStream ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
                dataStream position:dataStream position + data position
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
            ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
            ^ self
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
        ].
1464
10af50b07968 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1084
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
    char := format peek.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
    char == $% ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
        ^ dataStream peekFor:char
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
    char == $* ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
        format next.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
        char := format peek.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
        final := [:retval | 
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
                data == dataStream ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1094
                    dataStream position:dataStream position + data position
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
                ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
                ^ self
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
            ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
    ].
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1099
    
1464
10af50b07968 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1100
    width := 0.
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1101
    isShort := isLong := isLongLong := false.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1102
    isLongDouble := isLongLongDouble := false.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1103
    
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
    char isDigit ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
        width := Integer readFrom:format.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
        char := format peek
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
    ('slhduoxfeg' includes:char) ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
        dataStream skipSeparators
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    width = 0 ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
        data := dataStream
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
    ] ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1114
        pos := dataStream position.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
        data := ReadStream on:(dataStream next:width).
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1116
        dataStream position:pos
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
    char == $s ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
        final value:(data upToSeparator)
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
    char == $c ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
        width = 0 ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
            final value:(String with:data next)
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
        ] ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
            final value:data contents
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
        ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
    char == $[ ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
        "What a mess!!!!" 
3539
c9d007677ac3 class: PrintfScanf
Stefan Vogel <sv@exept.de>
parents: 3115
diff changeset
  1130
        return := CharacterWriteStream on:(String new:8).
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
        scanset := IdentitySet new.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
        format next.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
        width = 0 ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
            width := SmallInteger maxVal
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
        ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
        exclusive := format peekFor:$^.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
        [
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
            last := char.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
            char := format next.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
            char == $]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
        ] whileFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
            char == $- ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
                scanset add:char
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
            ] ifTrue:[
2678
a2f6f1e865e6 changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2581
diff changeset
  1145
                last to:format next do:[:c | 
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
                    scanset add:c
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
                ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
            ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
        ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
        [
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
            data atEnd not and:[ (scanset includes:data peek) xor:exclusive ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
        ] whileTrue:[ return nextPut:data next ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
        final value:return contents
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
    ].
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1155
    (char == $l) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1156
        isLong := true.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1157
        format next.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1158
        char := format peek.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1159
        
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1160
        (char == $l) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1161
            isLongLong := true.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1162
            format next.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1163
            char := format peek.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1164
        ].    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1165
    ].    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1166
    (char == $h) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1167
        isShort := true.
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
        format next.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
        char := format peek
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
    ].
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1171
    (char == $L) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1172
        isLongDouble := true.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1173
        format next.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1174
        char := format peek.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1175
        
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1176
        (char == $L) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1177
            isLongLongDouble := true.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1178
            format next.
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1179
            char := format peek
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1180
        ].
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1181
    ].
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
    ('DUdu' includes:char) ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
        final value:(Integer readFrom:data)
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
    ('FEGfeg' includes:char) ifTrue:[
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1186
        (isLongLongDouble) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1187
            final value:(QDouble readFrom:data)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1188
        ] ifFalse:[    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1189
            (isLongDouble) ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1190
                final value:(LongFloat readFrom:data)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1191
            ] ifFalse:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1192
                isShort ifTrue:[
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1193
                    final value:(ShortFloat readFrom:data)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1194
                ] ifFalse:[    
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1195
                    final value:(Float readFrom:data)
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1196
                ].
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1197
            ].
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1198
        ].
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
    ('Oo' includes:char) ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
        final value:(Integer readFrom:data radix:8)
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
    ('Xx' includes:char) ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
        final value:(Integer readFrom:data radix:16)
2889
7491ae1f59ac class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  1205
    ].
7491ae1f59ac class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  1206
    ('Bb' includes:char) ifTrue:[
7491ae1f59ac class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  1207
        final value:(Integer readFrom:data radix:2)
7491ae1f59ac class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  1208
    ].
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1209
    ('Nn' includes:char) ifTrue:[
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1210
        final value:(Number readFrom:data)
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1211
    ].
2678
a2f6f1e865e6 changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents: 2581
diff changeset
  1212
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1213
    "
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1214
     '%d %x' sscanf:'1234 ff00'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1215
     '%d %x %b' sscanf:'1234 ff00 1001'
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1216
     
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1217
     ('%f' sscanf:'1234') first
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1218
     ('%lf' sscanf:'1234') first
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1219
     ('%llf' sscanf:'1234') first
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1220
     ('%hf' sscanf:'1234') first
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1221
     ('%Lf' sscanf:'1234') first
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1222
     ('%LLf' sscanf:'1234') first
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1223
     ('%n' sscanf:'1234') first
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1224
     ('%n' sscanf:'1234.456') first
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1225
     ('%n %n' sscanf:'1234.456 123') 
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1226
    "
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1227
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1228
    "Created: / 19-06-2017 / 15:53:28 / cg"
4471
54c49f28673c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4452
diff changeset
  1229
    "Modified (comment): / 14-07-2017 / 11:31:01 / cg"
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1230
    "Modified (comment): / 18-05-2019 / 13:08:30 / Claus Gittinger"
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1231
! !
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1232
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1233
!PrintfScanf class methodsFor:'scanning'!
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
scanf:formatString fromStream:dataStream 
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
    "Return a Collection of objects found in the Character Stream
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
     <dataStream> as interpreted according to the receiver.  The
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1238
     receiver is assumed to be a conversion control string as
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1239
     specified in the UTek manual page for scanf(3)."
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1240
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1241
    |results format char|
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
    results := OrderedCollection new.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
    format := ReadStream on:formatString.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
    [ format atEnd ] whileFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
        char := format next.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
        (char == Character space or:[ char == Character tab ]) ifTrue:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
            dataStream skipSeparators.
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
            format skipSeparators
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
        ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
        char == $% ifTrue:[
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1252
            self scanArgFrom:dataStream to:results format:format
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
        ] ifFalse:[
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
            dataStream peekFor:char
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
        ]
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
    ].
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
    ^ results
4416
40f676e88785 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1258
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1259
    "Modified: / 19-06-2017 / 15:53:04 / cg"
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
!
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1261
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
sscanf:formatString fromString:aString 
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1263
    "Return a Collection of objects found in <string> as
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
     interpreted according to the receiver.  The receiver is
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
     assumed to be a conversion control string as specified in the
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
     UTek manual page for scanf(3)."
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1267
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1268
    ^ self scanf:formatString fromStream:(ReadStream on:aString)
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1269
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1270
    "
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1271
     self sscanf:'%d %d %d' fromString:'123 45 999'
4946
ccd655ac6fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1272
     '%d %d %d' scanf:'123 45 999'
4945
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1273
    "
f98cb762d159 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4622
diff changeset
  1274
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1275
    "Modified: / 19-06-2017 / 15:53:59 / cg"
4946
ccd655ac6fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1276
    "Modified (comment): / 18-05-2019 / 13:09:48 / Claus Gittinger"
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1277
! !
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1278
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1279
!PrintfScanf methodsFor:'helpers'!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1280
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1281
absDecimalPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1282
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1283
    ^ self class absDecimalPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1284
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1285
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1286
absPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1287
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1288
    ^ self class absPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1289
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1290
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1291
absScientificPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1292
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1293
    ^ self class absScientificPrintFloat:arg1 on:arg2 digits:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1294
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1295
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1296
formatArgCountFor:arg
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1297
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1298
    ^ self class formatArgCountFor:arg
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1299
! !
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1300
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1301
!PrintfScanf methodsFor:'printing'!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1302
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1303
printArgFrom:arg1 to:arg2 arguments:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1304
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1305
    ^ self class printArgFrom:arg1 to:arg2 arguments:arg3
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1306
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1307
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1308
printf:aString arguments:args
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1309
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1310
 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1311
    "Format and print the receiver with <args> formatted in C style, 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1312
     as described in the UTek manual page for printf(3).
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1313
     Returns the formatted printString."
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
    
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1315
    ^ self class printf:aString arguments:args
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1316
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1317
    "
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1318
     self new printf:'%d %x' arguments:#(1234 45054) 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1319
    "
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1320
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1321
    "Modified: / 19-06-2017 / 15:21:56 / cg"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1322
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1323
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1324
printf:aFormatString on:outStream arguments: args
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1325
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1326
    "Format and print aFormatString on <outStream> with <args>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1327
     formatted in C style, as described in the UTek manual page for
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1328
     printf(3)."     
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1329
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1330
    self class printf:aFormatString on:outStream arguments: args
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1331
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1332
    "Modified (comment): / 19-06-2017 / 15:22:15 / cg"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1333
! !
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1334
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1335
!PrintfScanf methodsFor:'scanning'!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1336
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1337
scanArgFrom:dataStream to:collection format:format
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1338
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1339
 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1340
    "Add to <collection> an object who's representation is found
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1341
     in <dataStream> interpreted according to the conversion
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1342
     control string in the Stream <format>.  <format> is assumed to
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1343
     be positioned just past a $%, and a complete control string is
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1344
     assumed available.    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1345
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1346
     Return when the conversion control string is consumed.  Leave
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1347
     <format> pointing past the last character in the conversion
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1348
     control string, leave <dataStream> pointing past any width
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1349
     specified in <format>, or at the first character that doesn't
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1350
     make sense for the <format>."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1351
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1352
    ^ self class scanArgFrom:dataStream to:collection format:format
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1353
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1354
    "Modified: / 19-06-2017 / 15:54:43 / cg"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1355
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1356
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1357
scanf:formatString fromStream:dataStream
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1358
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1359
 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1360
    "Return a Collection of objects found in the Character Stream
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1361
     <dataStream> as interpreted according to the receiver.  The
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1362
     receiver is assumed to be a conversion control string as
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1363
     specified in the UTek manual page for scanf(3)."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1364
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1365
    ^ self class scanf:formatString fromStream:dataStream
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1366
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1367
    "Modified: / 19-06-2017 / 15:54:27 / cg"
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1368
!
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1369
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1370
sscanf:formatString fromString:aString
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1371
    <resource: #obsolete>
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1372
 
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1373
    "Return a Collection of objects found in <string> as
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1374
     interpreted according to the receiver.  The receiver is
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1375
     assumed to be a conversion control string as specified in the
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1376
     UTek manual page for scanf(3)."
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1377
    
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1378
    ^ self class sscanf:formatString fromString:aString
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1379
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1380
    "
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1381
     self new sscanf:'%d %x' fromString:'1234 affe'
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1382
    "
4417
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1383
01b4de1f0b01 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  1384
    "Modified: / 19-06-2017 / 15:54:14 / cg"
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1385
! !
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1386
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1387
!PrintfScanf class methodsFor:'documentation'!
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1388
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1389
version
3719
3750518f5ada #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3539
diff changeset
  1390
    ^ '$Header$'
3115
b1217780fad3 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 3004
diff changeset
  1391
!
b1217780fad3 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 3004
diff changeset
  1392
b1217780fad3 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 3004
diff changeset
  1393
version_CVS
3719
3750518f5ada #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3539
diff changeset
  1394
    ^ '$Header$'
1463
abe8e819ea92 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1395
! !
2875
17ad0f5c8f53 class: PrintfScanf
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  1396