LineNumberReadStream.st
author Claus Gittinger <cg@exept.de>
Sat, 11 Jan 1997 19:54:37 +0100
changeset 478 778953b40429
child 885 c31412b26306
permissions -rw-r--r--
intitial checkin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by eXept Software AG
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
FilteringStream subclass:#LineNumberReadStream
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:'lineNumber'
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'Streams-Misc'
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
copyright
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 1996 by eXept Software AG
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
              All Rights Reserved
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    This filter keeps track of the current line, while
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    passing text from its inputStream to its outputStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    Can be placed in-between text processing and the texts
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    input stream, and let it keep track of the lineNumber.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    [see also:]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        ReadStream WriteStream ExternalStream FileStream
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        FilteringStream FilteringLineStream
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    [author:]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
        Claus Gittinger
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
examples
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
  count lines in a Makefile:
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
                                                                        [exBegin]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    filter upToEnd.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    Transcript showCR:('Makefile has %1 lines' bindWith:(filter lineNumber - 1)).
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                                                                        [exEnd]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
  find a specific string and output its lineNr:
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
                                                                        [exBegin]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    filter skipThroughAll:'start of'.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
                                                                        [exEnd]
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!LineNumberReadStream methodsFor:'accessing'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    "return the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    ^ lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    "Modified: 11.1.1997 / 16:57:19 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
lineNumber:something
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "set the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    lineNumber := something.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "Modified: 11.1.1997 / 16:57:22 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
!LineNumberReadStream methodsFor:'initialization'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
initialize
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    super initialize.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    lineNumber := 1.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    filter := [:char |
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
                char == Character cr ifTrue:[
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
                    lineNumber := lineNumber + 1.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
                ].
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
                char
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
              ].
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    "Modified: 11.1.1997 / 16:58:42 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
version
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.1 1997-01-11 18:54:37 cg Exp $'
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
! !