home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dongrovs.zip / textstream.cmd < prev    next >
OS/2 REXX Batch file  |  1996-10-16  |  4KB  |  139 lines

  1. /* ********************************** */
  2. /*   By: Jetnick Enterprise           */
  3. /*       Don E. Groves, Jr.           */
  4. /*   Contact Information:             */
  5. /*     E-mail: jetnick@erols.com      */
  6. /*        CIS: 71310,3702             */
  7. /* Date: 22 Sep 1996                  */
  8. /* ********************************** */
  9. /* A Text Stream Handler              */
  10. parse source . invhow .
  11. if invhow == 'COMMAND'
  12. THEN DO
  13.    .OUTPUT~LineOut('A simple TextStream class')
  14. END
  15. return 0
  16.  
  17. ::class TextStream Subclass Stream public
  18. ::method exist
  19. return (self~query('exist')~length \= 0)
  20. ::method IsDir
  21.   work = self~Qualify
  22.   if work~Right(1) = '\' & ( work~Length > 3 | work~Substr(2,1) \= ':' )
  23.   THEN DO
  24.      work = work~''('.')
  25.      forward to (self~Class~New(work))
  26.   END
  27. return (self~QUERY('DateTime')~Length \= 0 & (\ self~Exist))
  28. ::method IsFile
  29. return self~Exist
  30. ::method Size
  31. return self~QUERY('SIZE')
  32. ::method WriteList
  33.    use arg inlist, linend, seed
  34.    if arg(2,'O')
  35.    THEN linend = '0D0A'x
  36.    linend = linend~MakeString
  37.    if arg(3,'O')
  38.    THEN seed = '0A'x
  39.    seed = seed~MakeString
  40.    su = inlist~Supplier
  41.    IF Self~State == 'UNKNOWN'
  42.    THEN Self~OPEN('BOTH')
  43.    IF Self~State \== 'READY'
  44.    THEN Self~OPEN('WRITE')
  45.    count = 0
  46.    do while su~Available & Self~State == 'READY'
  47.       Self~CharOut(su~item~MakeString~''(seed)~changeStr(seed,linend))
  48.       count = count + 1
  49.       su~next
  50.    END
  51. return count   /* returns count of ITEMS written */
  52. ::method LineOut
  53.    use arg in, linend, seed
  54.    if arg(2,'O')
  55.    THEN linend = '0D0A'x
  56.    linend = linend~MakeString
  57.    if arg(3,'O')
  58.    THEN seed = '0A'x
  59.    seed = seed~MakeString
  60. return (Self~CharOut(in~MakeString~''(seed)~changeStr(seed,linend)) \= 0)
  61. ::method MakeList
  62.   forward to (.txt_list~NEW(Self)) message 'Builder'
  63. ::method MakeArray
  64.   forward to (.txt_Arry~NEW(Self)) message 'Builder'
  65.  
  66. ::class txt_Parm
  67. ::method msgA Attribute
  68. ::method init
  69.   expose who
  70.   use arg who, which
  71.   self~msgA = which
  72. return self
  73. ::method Append
  74.   expose who
  75.   use arg what
  76.   NOP
  77. ::method Builder
  78.   expose who
  79.   use arg linend, trash
  80.   if arg(1,'O')
  81.   THEN linend = '0A'x     /* end of line (record) marker */
  82.   linend = linend~MakeString
  83.   if arg(2,'O')
  84.   THEN trash = '0D'x     /* remove all of these from the input stream */
  85.   trash = trash~MakeString
  86.   rdSize = 2048   /* read a health buffer size */
  87.   msgData = who~CharIn(,rdSize)
  88.   DO WHILE msgData \== ''
  89.      msgData = msgData~ChangeStr(trash,'')
  90.      IF msgData~pos(linend) \= 0 | who~STATE \== 'READY'
  91.      THEN DO
  92.         DO UNTIL msgData~pos(linend) = 0
  93.            parse value msgData with wrk (linend) msgData
  94.            self~Append(wrk)
  95.         END
  96.      END
  97.      msgData = msgData~''(who~CharIn(,rdSize))
  98.   END
  99. RETURN self~msgA
  100.  
  101. ::class txt_list subclass txt_parm
  102. ::method init
  103.   use arg who
  104.   forward class (super) Array (who, .list~new)
  105. ::method Append
  106.   use arg what
  107.   self~msgA~Insert(what)
  108.  
  109. ::class txt_Arry subclass txt_parm
  110. ::method init
  111.   use arg who
  112.   forward class (super) Array (who, .Array~new)
  113. ::method Append
  114.   use arg what
  115.   self~msgA[self~msgA~Items + 1]= what
  116.  
  117. ::class OutTextStream Subclass TextStream public
  118. ::method LineOut
  119.   forward class (super) ARRAY (ARG(1), '0D0A'x , '0A'x )
  120. ::method WriteList
  121.   forward class (super) ARRAY (ARG(1), '0D0A'x , '0A'x )
  122. ::method MakeList
  123.   forward class (super) ARRAY ('0A'x , '0D'x )
  124. ::method MakeArray
  125.   forward class (super) ARRAY ('0A'x , '0D'x )
  126.  
  127. ::class RcvTextStream Subclass TextStream public
  128. ::method LineOut
  129.   forward class (super) ARRAY (ARG(1), '0A'x , '0A'x )
  130. ::method WriteList
  131.   forward class (super) ARRAY (ARG(1), '0A'x , '0A'x )
  132. ::method MakeList
  133.   forward class (super) ARRAY ('0A'x , '0D'x )
  134. ::method MakeArray
  135.   forward class (super) ARRAY ('0A'x , '0D'x )
  136.  
  137. /* ********************************* */
  138. /* ********************************* */
  139.