midrange.com code scratchpad
Name:
Generate 500 attachments
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
02/10/2012 06:42:11 pm
IP:
Logged
Description:
I used this to test SNDEMAIL
Code:
  1.       // Build 500 stream files in the /rob directory.
  2.       //
  3.       // To compile:
  4.       //   CRTBNDRPG IFS500 SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
  5.       //
  6.      H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')
  7.  
  8.      D/copy ROUTINES/QPROTOSRC,IFSIO_H
  9.      D/copy ROUTINES/QPROTOSRC,ERRNO_H
  10.  
  11.      D fd              S             10I 0
  12.      D wrdata          S             24A
  13.      D rddata          S             48A
  14.      D flags           S             10U 0
  15.      D mode            S             10U 0
  16.      D ErrMsg          S            250A
  17.      D Msg             S             50A
  18.      D Len             S             10I 0
  19.  
  20.      D FileNameDs      ds            15
  21.      D  FilePrefix                    6a   inz('/rob/F')
  22.      D  FileNumber                    5S 0
  23.      D  FileNumberA                   5a   overlay(FileNumber)
  24.      D  FileSuffix                    4a   inz('.txt')
  25.  
  26.       //***************************************************************
  27.       // Example of writing data to a stream file
  28.       //***************************************************************
  29.       /FREE
  30.        flags = O_WRONLY + O_CREAT + O_TRUNC + O_CODEPAGE;
  31.  
  32.        mode =  S_IRUSR + S_IWUSR
  33.            + S_IRGRP
  34.            + S_IROTH;
  35.        for FileNumber = 1 to 500;
  36.          // Open the file once to create it with code page 819.
  37.          // Close it.
  38.          // Reopen it to get automatic translation.
  39.          fd = open(FileNameDs: flags: mode: 819);
  40.          if fd < 0;
  41.            ErrMsg = %str(strerror(errno));
  42.            die('open() for output: ' + ErrMsg);
  43.          endif;
  44.          callp close(fd);
  45.          // Now re-open the file in text mode.  Since it was assigned a
  46.          // code page of 819, and we're opening it in text mode, OS/400
  47.          // will automatically translate to/from ASCII for us.
  48.           fd = open(FileNameDs:
  49.               O_WRONLY+O_TEXTDATA);
  50.           if fd < 0;
  51.             die('open(): ' + %str(strerror(errno)));
  52.           endif;
  53.  
  54.          // Write some data
  55.          wrdata = FileNumberA;
  56.          if write(fd: %addr(wrdata): %size(wrdata))<1;
  57.            ErrMsg = %str(strerror(errno));
  58.            callp close(fd);
  59.            die('open(): ' + ErrMsg);
  60.          endif;
  61.  
  62.          // close the file
  63.          callp close(fd);
  64.        EndFor;  // for FileNumber = 1 to somenumber
  65.  
  66.        *inlr = *on;
  67.        return;
  68.  
  69.       /DEFINE ERRNO_LOAD_PROCEDURE
  70.       /END-FREE
  71.       /COPY ROUTINES/QPROTOSRC,ERRNO_H       // Build 500 stream files in the /rob directory.
  72.       //
  73.       // To compile:
  74.       //   CRTBNDRPG IFS500 SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
  75.       //
  76.      H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')
  77.  
  78.      D/copy ROUTINES/QPROTOSRC,IFSIO_H
  79.      D/copy ROUTINES/QPROTOSRC,ERRNO_H
  80.  
  81.      D fd              S             10I 0
  82.      D wrdata          S             24A
  83.      D rddata          S             48A
  84.      D flags           S             10U 0
  85.      D mode            S             10U 0
  86.      D ErrMsg          S            250A
  87.      D Msg             S             50A
  88.      D Len             S             10I 0
  89.  
  90.      D FileNameDs      ds            15
  91.      D  FilePrefix                    6a   inz('/rob/F')
  92.      D  FileNumber                    5S 0
  93.      D  FileNumberA                   5a   overlay(FileNumber)
  94.      D  FileSuffix                    4a   inz('.txt')
  95.  
  96.       //***************************************************************
  97.       // Example of writing data to a stream file
  98.       //***************************************************************
  99.       /FREE
  100.        flags = O_WRONLY + O_CREAT + O_TRUNC + O_CODEPAGE;
  101.  
  102.        mode =  S_IRUSR + S_IWUSR
  103.            + S_IRGRP
  104.            + S_IROTH;
  105.        for FileNumber = 1 to 500;
  106.          // Open the file once to create it with code page 819.
  107.          // Close it.
  108.          // Reopen it to get automatic translation.
  109.          fd = open(FileNameDs: flags: mode: 819);
  110.          if fd < 0;
  111.            ErrMsg = %str(strerror(errno));
  112.            die('open() for output: ' + ErrMsg);
  113.          endif;
  114.          callp close(fd);
  115.          // Now re-open the file in text mode.  Since it was assigned a
  116.          // code page of 819, and we're opening it in text mode, OS/400
  117.          // will automatically translate to/from ASCII for us.
  118.           fd = open(FileNameDs:
  119.               O_WRONLY+O_TEXTDATA);
  120.           if fd < 0;
  121.             die('open(): ' + %str(strerror(errno)));
  122.           endif;
  123.  
  124.          // Write some data
  125.          wrdata = FileNumberA;
  126.          if write(fd: %addr(wrdata): %size(wrdata))<1;
  127.            ErrMsg = %str(strerror(errno));
  128.            callp close(fd);
  129.            die('open(): ' + ErrMsg);
  130.          endif;
  131.  
  132.          // close the file
  133.          callp close(fd);
  134.        EndFor;  // for FileNumber = 1 to somenumber
  135.  
  136.        *inlr = *on;
  137.        return;
  138.  
  139.       /DEFINE ERRNO_LOAD_PROCEDURE
  140.       /END-FREE
  141.       /COPY ROUTINES/QPROTOSRC,ERRNO_H 
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css