home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / vms / 18193 < prev    next >
Encoding:
Text File  |  1992-11-18  |  6.7 KB  |  188 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!swrinde!elroy.jpl.nasa.gov!nntp-server.caltech.edu!SOL1.GPS.CALTECH.EDU!CARL
  2. From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
  3. Newsgroups: comp.os.vms
  4. Subject: Callable COPY (third try)
  5. Date: 19 Nov 1992 01:38:16 GMT
  6. Organization: HST Wide Field/Planetary Camera
  7. Lines: 176
  8. Message-ID: <1eer68INNhgv@gap.caltech.edu>
  9. Reply-To: carl@SOL1.GPS.CALTECH.EDU
  10. NNTP-Posting-Host: sol1.gps.caltech.edu
  11.  
  12. Apologies for posting three nearly identical articles.  In the first one, there
  13. were errors in the description of the arguments.  In the second, I realized not
  14. too long after posting that it had a horrendous memory leak.  This one should
  15. be reasonably stable.  Again, sorry about the multiple posts.
  16.  
  17. From time to time, somebody posts a request to this group for a "callable COPY."
  18. They're usually referred to the callable CONVERT routines, but frequently they
  19. complain that these routines actually do a CONVERT and access the input and
  20. output files in record mode.  Well, here's a first cut at a callable COPY.  It
  21. takes as arguments two string descriptors, passed by reference, the first
  22. describing the string naming the input file, the second the output file.  I've
  23. tested this with a simple sequential file and with an indexed file with four
  24. keys in three areas.  It worked fine for both these tests under VMS v5.4-2.
  25.  
  26. However, I make no guarantee that this program will work for ALL files or for
  27. all versions of VMS.  If you use it, let me know.  If you find any bugs, then
  28. PLEASE let me know so I can fix them.  Enjoy.
  29.  
  30. /******************************************************************************\
  31.  *  NOTLIB_COPY:  A function to copy an arbitrary file in block mode          *
  32.  *  Copyright 1992 by the Caltech Odd Hack Committee.  No rights reserved     *
  33.  *  Author:  Carl J Lydick (carl@sol1.gps.caltech.edu)                        *
  34.  *     Arguments:                                                            *
  35.  *        inp_file                                                      *
  36.  *                                                                            *
  37.  *        VMS usage: input_filespec                                     *
  38.  *        type: character-coded text string                             *
  39.  *        access: read only                                             *
  40.  *        mechanism: by descriptor--fixed                               *
  41.  *            length string descriptor                                  *
  42.  *                                                                            *
  43.  *        Name of the file to be copied.                                *
  44.  *        ---------------------------------                             *
  45.  *        out_file                                                      *
  46.  *                                                                            *
  47.  *        VMS usage: output_filespec                                    *
  48.  *        type: character-coded text string                             *
  49.  *        access: read only                                             *
  50.  *        mechanism: by descriptor--fixed                               *
  51.  *            length string descriptor                                  *
  52.  *                                                                            *
  53.  *        Name of the destination file.                                 *
  54. \******************************************************************************/
  55. #include descrip
  56. #include rms
  57. #include ssdef
  58. copy(struct dsc$descriptor *inp_file, struct dsc$descriptor *out_file)
  59. {    struct FAB inp_fab, out_fab;
  60.     struct RAB inp_rab, out_rab;
  61.     struct XABSUM xabsum;
  62.     struct XABKEY *xabkey;
  63.     struct XABALL *xaball;
  64.     char buffer[32256];
  65.     long stat;
  66.  
  67.     xabsum = cc$rms_xabsum;
  68.  
  69.     inp_fab = cc$rms_fab;
  70.     inp_fab.fab$b_fac = FAB$M_BRO | FAB$M_GET;
  71.     inp_fab.fab$l_fna = inp_file->dsc$a_pointer;
  72.     inp_fab.fab$b_fns = inp_file->dsc$w_length;
  73.     inp_fab.fab$l_fop = FAB$M_SQO;
  74.     inp_fab.fab$b_shr = FAB$M_SHRPUT | FAB$M_UPI;
  75.     inp_fab.fab$l_xab = &xabsum;
  76.  
  77.     if(((stat = SYS$OPEN(&inp_fab)) & 7) != 1)
  78.         return stat;
  79.  
  80.     if(xabsum.xab$b_nok > 0)
  81.     {    int i;
  82.  
  83.         if ((xabkey = (struct XABKEY *) malloc(xabsum.xab$b_nok *
  84.             sizeof(struct XABKEY))) == 0)
  85.             return SS$_INSFMEM;
  86.  
  87.         for(i = 0; i < xabsum.xab$b_nok; ++i)
  88.         {    xabkey[i] = cc$rms_xabkey;
  89.             xabkey[i].xab$l_nxt = xabkey + i + 1;
  90.             xabkey[i].xab$b_ref = i;
  91.         }
  92.         xabkey[xabsum.xab$b_nok-1].xab$l_nxt = 0;
  93.         xabsum.xab$l_nxt = xabkey;
  94.     }
  95.     if(xabsum.xab$b_noa > 0)
  96.     {    int i;
  97.  
  98.         if((xaball = (struct XABALL *) malloc(xabsum.xab$b_noa *
  99.             sizeof(struct XABALL))) == 0)
  100.         {    free(xabkey);
  101.             return SS$_INSFMEM;
  102.         }
  103.         for(i = 0; i < xabsum.xab$b_noa; ++i)
  104.         {    xaball[i] = cc$rms_xaball;
  105.             xaball[i].xab$l_nxt = xaball + i + 1;
  106.             xaball[i].xab$b_aid = i;
  107.         }
  108.         xabkey[xabsum.xab$b_nok-1].xab$l_nxt = xaball;
  109.         xaball[xabsum.xab$b_noa-1].xab$l_nxt = 0;
  110.         
  111.     }
  112.     if(((stat = SYS$DISPLAY(&inp_fab)) & 7) != 1)
  113.     {    free(xabkey);
  114.         free(xaball);
  115.         return stat;
  116.     }
  117.     out_fab = inp_fab;
  118.     out_fab.fab$b_fac = FAB$M_BRO | FAB$M_PUT;
  119.     out_fab.fab$l_fna = out_file->dsc$a_pointer;
  120.     out_fab.fab$b_fns = out_file->dsc$w_length;
  121.     out_fab.fab$w_ifi = 0;
  122.     out_fab.fab$b_shr = FAB$M_SHRPUT | FAB$M_UPI;
  123.  
  124.     if(((stat = SYS$CREATE(&out_fab)) & 7) != 1)
  125.     {    SYS$CLOSE(&inp_fab);
  126.         free(xabkey);
  127.         free(xaball);
  128.         return stat;
  129.     }
  130.  
  131.     inp_rab = cc$rms_rab;
  132.     inp_rab.rab$l_fab = &inp_fab;
  133.     inp_rab.rab$l_rop = RAB$M_BIO;
  134.  
  135.     out_rab = inp_rab;
  136.     out_rab.rab$l_fab = &out_fab;
  137.     out_rab.rab$w_isi = 0;
  138.  
  139.     if((((stat = SYS$CONNECT(&inp_rab)) & 7) != 1) ||
  140.         (((stat = SYS$CONNECT(&out_rab)) & 7) != 1))
  141.     {    SYS$CLOSE(&inp_fab);
  142.         SYS$CLOSE(&out_fab);
  143.         free(xabkey);
  144.         free(xaball);
  145.         return stat;
  146.     }
  147.  
  148.     inp_rab.rab$l_ubf = buffer;
  149.     inp_rab.rab$w_usz = 32256;
  150.     out_rab.rab$l_rbf = buffer;
  151.  
  152.     while(1==1)
  153.     {    if((((stat = SYS$READ(&inp_rab)) & 7) != 1) && stat != RMS$_EOF)
  154.         {    SYS$CLOSE(&inp_fab);
  155.             SYS$CLOSE(&out_fab);
  156.             free(xabkey);
  157.             free(xaball);
  158.             return stat;
  159.         }
  160.         else if(stat == RMS$_EOF)
  161.         {    SYS$CLOSE(&inp_fab);
  162.             SYS$CLOSE(&out_fab);
  163.             free(xabkey);
  164.             free(xaball);
  165.             return RMS$_NORMAL;
  166.         }
  167.         else
  168.         {    out_rab.rab$w_rsz = inp_rab.rab$w_rsz;
  169.             if(((stat = SYS$WRITE(&out_rab)) & 7) != 1)
  170.             {    SYS$CLOSE(&inp_fab);
  171.                 SYS$CLOSE(&out_fab);
  172.                 free(xabkey);
  173.                 free(xaball);
  174.                 return stat;
  175.             }
  176.         }
  177.     }
  178. }
  179. /***************************** END of NOTLIB_COPY *****************************/
  180. --------------------------------------------------------------------------------
  181. Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
  182.  
  183. Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
  184. understanding of astronomy is purely at the amateur level (or below).  So
  185. unless what I'm saying is directly related to VAX/VMS, don't hold me or my
  186. organization responsible for it.  If it IS related to VAX/VMS, you can try to
  187. hold me responsible for it, but my organization had nothing to do with it.
  188.