midrange.com code scratchpad
Name:
Readtest
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
03/10/2010 07:34:54 pm
IP:
Logged
Description:
Program to illustrate first "read" returning a blank.
Code:
  1. hoption(*nodebugio:*srcstmt) dftactgrp(*no)                     
  2. d Read            pr            10i 0 extproc('read')           
  3. d handle                        10i 0 value                     
  4. d buffer                          *   value                     
  5. d bytes                         10U 0 value                     
  6.                                                                 
  7. d Open            pr            10i 0 extproc('open')           
  8. d filename                        *   value options(*string)    
  9. d openflags                     10i 0 value                     
  10. d mode                          10u 0 value options(*nopass)    
  11. d codepage                      10u 0 value options(*nopass)    
  12. d txtcreatid                    10u 0 value options(*nopass)    
  13.                                                                 
  14. d Close           pr            10i 0 extproc('close')          
  15. d handle                        10i 0 value                     
  16.                                                                 
  17.                                                               
  18. d O_TEXTDATA      c                   16777216                
  19. d ReadOnly        c                   1                       
  20.                                                               
  21. d fd_in           s             10i 0                         
  22. d ifsFile         s            256a                           
  23. d wChar           s              1a                           
  24. d wBuffer         s             20a                           
  25. d x               s              5s 0                         
  26.                                                               
  27. c                   eval      ifsFile='/joe/test.txt'         
  28.                                                               
  29.  * without dummy read......                                   
  30. c                   eval      fd_in = open(%trim(ifsFile):    
  31. c                             ReadOnly+O_TEXTDATA)            
  32.                                                               
  33. c*****              callp     Read(fd_in: %addr(wChar): 1)    
  34. c                   dou       Read(fd_in: %addr(wChar): 1) < 1    
  35. c                   eval      x=x+1                               
  36. c                   eval      %subst(wBuffer:x:1)=wChar           
  37. c                   enddo                                         
  38.                                                                   
  39. c                   dsply                   wBuffer               
  40.                                                                   
  41. c                   callp     Close(fd_in)                        
  42.                                                                   
  43.  * with dummy read......                                          
  44. c                   eval      x=0                                 
  45. c                   eval      wBuffer=*blanks                     
  46. c                   eval      fd_in = open(%trim(ifsFile):        
  47. c                             ReadOnly+O_TEXTDATA)                
  48.                                                                   
  49. c                   callp     Read(fd_in: %addr(wChar): 1)        
  50. c                   dou       Read(fd_in: %addr(wChar): 1) < 1    
  51. c                   eval      x=x+1                                    
  52. c                   eval      %subst(wBuffer:x:1)=wChar                
  53. c                   enddo                                              
  54.                                                                        
  55. c                   dsply                   wBuffer                    
  56.                                                                        
  57. c                   callp     Close(fd_in)                             
  58.                                                                        
  59. c                   seton                                        lr    
  60. c                   return                                             
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css