home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / src / mactoasd.c < prev    next >
Text File  |  1993-11-18  |  15KB  |  652 lines

  1. /*
  2. ** This source code was written by Tim Endres
  3. ** Email: time@ice.com.
  4. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  5. **
  6. ** Some portions of this application utilize sources
  7. ** that are copyrighted by ICE Engineering, Inc., and
  8. ** ICE Engineering retains all rights to those sources.
  9. **
  10. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  11. ** warrants this source code for any reason, and neither
  12. ** party assumes any responsbility for the use of these
  13. ** sources, libraries, or applications. The user of these
  14. ** sources and binaries assumes all responsbilities for
  15. ** any resulting consequences.
  16. */
  17.  
  18. #pragma segment ASD
  19.  
  20. #include <types.h>
  21. #include <errors.h>
  22. #include <toolutils.h>
  23. #include <standardfile.h>
  24.  
  25. #include <fcntl.h>
  26. #include <stdio.h>
  27. #include "asd.h"
  28. #include "mb.h"
  29. #include "defines.h"
  30.  
  31. #ifndef TRUE
  32. #    define TRUE        (Boolean)1
  33. #endif
  34. #ifndef FALSE
  35. #    define FALSE        (Boolean)0
  36. #endif
  37.  
  38. #undef BLK_SIZE
  39. #define BLK_SIZE 1024
  40. #define iobuffer kBuffer
  41. extern char kBuffer[];
  42. /* static char                iobuffer[BLK_SIZE]; */
  43.  
  44. static long    dlength = 0;
  45. static long    rlength = 0;
  46. static long    cdate = 0;
  47. static long    mdate = 0;
  48.  
  49. /*
  50. ** WARNING ! WARNING ! WARNING !
  51. ** Both of the parameters to this macro
  52. ** are used more than once! Also, I did
  53. ** NOT parenthsize any parameters.
  54. */
  55. #define CHAR4_TO_LONG(char4, long) \
  56.     { \
  57.     long = 0; \
  58.     long += char4 [0]; long <<= 8; \
  59.     long += char4 [1]; long <<= 8; \
  60.     long += char4 [2]; long <<= 8; \
  61.     long += char4 [3]; \
  62.     }
  63.  
  64. #ifdef TCLAPPL
  65.  
  66. macintosh_to_asingle(crnl_flag)
  67.     int            crnl_flag;
  68.     {
  69.     SFReply        macreply,
  70.                 asreply;
  71.     Point        mypoint;
  72.     SFTypeList    mytypes;
  73.     int            result;
  74.     char        orig[64];
  75.     extern int errno;
  76.  
  77.     mypoint.h = mypoint.v = 75;
  78.     MyGetFile(mypoint, "\pMacintosh File:", NULL, -1, mytypes, NULL, ¯eply);
  79.     
  80.     if (!macreply.good)
  81.         return CANCEL;
  82.     
  83.     sprintf(orig, "%.*s.AS", macreply.fName[0], ¯eply.fName[1]);
  84.     c2pstr(orig);
  85.     MyPutFile(mypoint, "\pApple Single File:", orig, NULL, &asreply);
  86.  
  87.     if (!asreply.good)
  88.         return CANCEL;
  89.     
  90.     p2cstr(asreply.fName);
  91.     p2cstr(macreply.fName);
  92.     result = do_mac_to_asingle( macreply.fName, macreply.vRefNum,
  93.                                 asreply.fName, asreply.vRefNum, TRUE, crnl_flag );
  94.     
  95.     return (result == noErr ? SUCCESS : FAILURE);
  96.     }
  97.  
  98. #endif /* TCLAPPL */
  99.  
  100.  
  101. do_mac_to_asingle(macname, macVRef, asname, asVRef, interactive, crnl_flag)
  102.     char        *macname;    /* C */
  103.     int            macVRef;
  104.     char        *asname;    /* C */
  105.     int            asVRef;
  106.     int            interactive;
  107.     int            crnl_flag;
  108.     {
  109.     char        *ptr;
  110.     int            i, myerr;
  111.     int            blocks;
  112.     int            residue;
  113.     int            offset;
  114.     FILE        *asfile;
  115.     ParamBlockRec    pb, iopb;
  116.     extern int errno;
  117.  
  118.     pb.fileParam.ioCompletion = 0;
  119.     pb.fileParam.ioVRefNum = macVRef;
  120.     pb.fileParam.ioNamePtr = macname;
  121.     pb.fileParam.ioFVersNum = 0;
  122.     pb.fileParam.ioFDirIndex = 0;
  123.     
  124.     c2pstr(macname);
  125.     myerr = PBGetFInfo(&pb, FALSE);
  126.     p2cstr(macname);
  127.     if (myerr != noErr)
  128.         {
  129.         Feedback("Error #%d getting Macintosh file info.", errno);
  130.         return myerr;
  131.         }
  132.  
  133.     SetVol(NULL, asVRef);
  134.     asfile = fopen(asname, "w");
  135.     if (asfile == NULL)
  136.         {
  137.         Feedback("Error #%d opening apple single file '%s'.", errno, asname);
  138.         return (errno == 0 ? fnfErr : errno);
  139.         }
  140.  
  141.     UBegYield();
  142.  
  143.     RotateCursor(32);
  144.     DoYield();
  145.  
  146.     dlength = pb.fileParam.ioFlLgLen;
  147.     rlength = pb.fileParam.ioFlRLgLen;
  148.  
  149.     cdate = pb.fileParam.ioFlCrDat;
  150.     mdate = pb.fileParam.ioFlMdDat;
  151.  
  152.     cdate = MAC_TO_UNIX_TIME(cdate);
  153.     mdate = MAC_TO_UNIX_TIME(mdate);
  154.     if (interactive)
  155.         {
  156.         Feedback("Macintosh file '%.*s'", macname);
  157.         Feedback("File Type '%4.4s'", &pb.fileParam.ioFlFndrInfo.fdType);
  158.         Feedback("File Creator '%4.4s'", &pb.fileParam.ioFlFndrInfo.fdCreator);
  159.         Feedback("Data Fork %d bytes.", dlength);
  160.         Feedback("Rsrc Fork %d bytes.", rlength);
  161.         Feedback("Creation Date [%d] %s", cdate, ctime(&cdate));
  162.         Feedback("Modification Date [%d] %s", mdate, ctime(&mdate));
  163.         }
  164.     
  165.     RotateCursor(32);
  166.     DoYield();
  167.  
  168.     memcpy(&asd_finder, &pb.fileParam.ioFlFndrInfo, sizeof(asd_fndr_fork));
  169.  
  170.     asd_file_head.asd_head.magic = MAGIC_APPLE_SINGLE;
  171.     asd_file_head.asd_head.version = VERSION_APPLE;
  172.     sprintf(asd_file_head.asd_head.filesys, "%-16.16s", "Macintosh");
  173.     asd_file_head.asd_head.entries = 3;
  174.  
  175.     i = 0;
  176.     asd_file_head.asd_entries[i].id = ASDID_FNDR_FORK;
  177.     asd_file_head.asd_entries[i].offset = sizeof(asd_file_hdr);
  178.     asd_file_head.asd_entries[i].length = sizeof(asd_fndr_fork);
  179.  
  180.     i++;
  181.     asd_file_head.asd_entries[i].id = ASDID_RSRC_FORK;
  182.     asd_file_head.asd_entries[i].offset =
  183.             asd_file_head.asd_entries[i-1].offset +
  184.             asd_file_head.asd_entries[i-1].length;
  185.     asd_file_head.asd_entries[i].length = rlength;
  186.  
  187.     i++;
  188.     asd_file_head.asd_entries[i].id = ASDID_DATA_FORK;
  189.     asd_file_head.asd_entries[i].offset =
  190.             asd_file_head.asd_entries[i-1].offset +
  191.             asd_file_head.asd_entries[i-1].length;
  192.     asd_file_head.asd_entries[i].length = dlength;
  193.  
  194.     RotateCursor(32);
  195.     DoYield();
  196.  
  197.     fwrite(&asd_file_head, 1, sizeof(asd_file_hdr), asfile);
  198.     fwrite(&asd_finder, 1, sizeof(asd_fndr_fork), asfile);
  199.     
  200.     offset = MAC_BINARY_HDR_SIZE + (((dlength + BLK_SIZE - 1) >> 7) << 7);
  201.     
  202.     if (rlength > 0)
  203.         {
  204.         pb.ioParam.ioCompletion = 0;
  205.         pb.ioParam.ioVRefNum = macVRef;
  206.         pb.ioParam.ioNamePtr = macname;
  207.         pb.ioParam.ioVersNum = 0;
  208.         pb.ioParam.ioPermssn = fsRdPerm;
  209.         pb.ioParam.ioMisc = 0;
  210.         
  211.         c2pstr(macname);
  212.         myerr = PBOpenRF(&pb, FALSE);
  213.         p2cstr(macname);
  214.         
  215.         if (myerr != noErr)
  216.             {
  217.             }
  218.         else {
  219.             blocks = rlength / BLK_SIZE;
  220.             residue = rlength % BLK_SIZE;
  221.             for ( ; blocks; blocks-- )
  222.                 {
  223.                 RotateCursor(32);
  224.                 DoYield();
  225.                 if (pause_op)
  226.                     while (pause_op)
  227.                         pausing();
  228.                 
  229.                 iopb.ioParam.ioCompletion = 0;
  230.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  231.                 iopb.ioParam.ioBuffer = iobuffer;
  232.                 iopb.ioParam.ioReqCount = BLK_SIZE;
  233.                 iopb.ioParam.ioPosMode = fsAtMark;
  234.                 iopb.ioParam.ioPosOffset = 0;
  235.                 myerr = PBRead(&iopb, FALSE);
  236.                 if (myerr == noErr)
  237.                     fwrite(iobuffer, 1, BLK_SIZE, asfile);
  238.                 }
  239.             if (residue)
  240.                 {
  241.                 RotateCursor(32);
  242.                 DoYield();
  243.                 if (pause_op)
  244.                     while (pause_op)
  245.                         pausing();
  246.                 
  247.                 iopb.ioParam.ioCompletion = 0;
  248.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  249.                 iopb.ioParam.ioBuffer = iobuffer;
  250.                 iopb.ioParam.ioReqCount = residue;
  251.                 iopb.ioParam.ioPosMode = fsAtMark;
  252.                 iopb.ioParam.ioPosOffset = 0;
  253.                 myerr = PBRead(&iopb, FALSE);
  254.                 if (myerr == noErr)
  255.                     fwrite(iobuffer, 1, residue, asfile);
  256.                 }
  257.             PBClose(&pb, FALSE);
  258.             }
  259.         }
  260.  
  261.     if (dlength > 0)
  262.         {
  263.         pb.ioParam.ioCompletion = 0;
  264.         pb.ioParam.ioVRefNum = macVRef;
  265.         pb.ioParam.ioNamePtr = macname;
  266.         pb.ioParam.ioVersNum = 0;
  267.         pb.ioParam.ioPermssn = fsRdPerm;
  268.         pb.ioParam.ioMisc = 0;
  269.         
  270.         c2pstr(macname);
  271.         myerr = PBOpen(&pb, FALSE);
  272.         p2cstr(macname);
  273.         
  274.         if (myerr != noErr)
  275.             {
  276.             }
  277.         else
  278.             {
  279.             blocks = dlength / BLK_SIZE;
  280.             residue = dlength % BLK_SIZE;
  281.             for ( ; blocks; blocks-- )
  282.                 {
  283.                 RotateCursor(32);
  284.                 DoYield();
  285.                 if (pause_op)
  286.                     while (pause_op)
  287.                         pausing();
  288.                 
  289.                 iopb.ioParam.ioCompletion = 0;
  290.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  291.                 iopb.ioParam.ioBuffer = iobuffer;
  292.                 iopb.ioParam.ioReqCount = BLK_SIZE;
  293.                 iopb.ioParam.ioPosMode = fsAtMark;
  294.                 iopb.ioParam.ioPosOffset = 0;
  295.                 myerr = PBRead(&iopb, FALSE);
  296.                 if (myerr == noErr)
  297.                     {
  298.                     if (crnl_flag)
  299.                         for (i=iopb.ioParam.ioActCount, ptr=iobuffer; i; i--, ptr++)
  300.                             if (*ptr == 0x0D) *ptr = 0x0A;
  301.                     
  302.                     fwrite(iobuffer, 1, BLK_SIZE, asfile);
  303.                     }
  304.                 }
  305.             if (residue)
  306.                 {
  307.                 RotateCursor(32);
  308.                 DoYield();
  309.                 if (pause_op)
  310.                     while (pause_op)
  311.                         pausing();
  312.                 
  313.                 iopb.ioParam.ioCompletion = 0;
  314.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  315.                 iopb.ioParam.ioBuffer = iobuffer;
  316.                 iopb.ioParam.ioReqCount = residue;
  317.                 iopb.ioParam.ioPosMode = fsAtMark;
  318.                 iopb.ioParam.ioPosOffset = 0;
  319.                 myerr = PBRead(&iopb, FALSE);
  320.                 if (myerr == noErr)
  321.                     {
  322.                     if (crnl_flag)
  323.                         for (i=iopb.ioParam.ioActCount, ptr=iobuffer; i; i--, ptr++)
  324.                             if (*ptr == 0x0D) *ptr = 0x0A;
  325.                     
  326.                     fwrite(iobuffer, 1, residue, asfile);
  327.                     }
  328.                 }
  329.             
  330.             PBClose(&pb, FALSE);
  331.             }
  332.         }
  333.  
  334.     WatchCursorOn();
  335.     fclose(asfile);
  336.     
  337.     set_file_type(asname, asVRef, APPL_TYPE, (OSType)'AS/D');
  338.  
  339.     UInitCursor();
  340.     
  341.     UEndYield();
  342.  
  343.     return noErr;
  344.     }
  345.  
  346. #ifdef TCLAPPL
  347.  
  348. macintosh_to_adouble(crnl_flag)
  349.     int            crnl_flag;
  350.     {
  351.     SFReply        macreply,
  352.                 rreply,
  353.                 dreply;
  354.     Point        mypoint;
  355.     SFTypeList    mytypes;
  356.     char        orig[64];
  357.     int            result;
  358.     
  359.     extern int errno;
  360.  
  361.     mypoint.h = mypoint.v = 75;
  362.     MyGetFile(mypoint, "\pMacintosh File:", NULL, -1, mytypes, NULL, ¯eply);
  363.     
  364.     if (!macreply.good)
  365.         return CANCEL;
  366.     
  367.     sprintf(orig, "%.*s.AD", macreply.fName[0], ¯eply.fName[1]);
  368.     c2pstr(orig);
  369.     MyPutFile(mypoint, "\pApple Double Data File:", orig, NULL, &dreply);
  370.  
  371.     if (!dreply.good)
  372.         return CANCEL;
  373.     
  374.     sprintf(orig, "%%%.*s",
  375.             ( (dreply.fName[0] > 26) ? 26 : dreply.fName[0] ), &dreply.fName[1]);
  376.     c2pstr(orig);
  377.     MyPutFile(mypoint, "\pApple Double Rsrc File:", orig, NULL, &rreply);
  378.  
  379.     if (!rreply.good)
  380.         return CANCEL;
  381.  
  382.     p2cstr(dreply.fName);
  383.     p2cstr(rreply.fName);
  384.     p2cstr(macreply.fName);
  385.     result = do_mac_to_adouble( macreply.fName, macreply.vRefNum,
  386.                                 rreply.fName, rreply.vRefNum,
  387.                                 dreply.fName, dreply.vRefNum, TRUE, crnl_flag );
  388.     
  389.     return (result == noErr ? SUCCESS : FAILURE);
  390.     }
  391.  
  392. #endif /* TCLAPPL */
  393.  
  394.  
  395. do_mac_to_adouble( macname, macVRef, adrname, adrVRef,
  396.                     addname, addVRef, interactive, crnl_flag )
  397.     char        *macname;    /* C */
  398.     int            macVRef;
  399.     char        *adrname;    /* C */
  400.     int            adrVRef;
  401.     char        *addname;    /* C */
  402.     int            addVRef;
  403.     int            interactive;
  404.     int            crnl_flag;
  405.     {
  406.     ParamBlockRec    pb, iopb;
  407.     char        *ptr;
  408.     int            i, myerr;
  409.     int            blocks;
  410.     int            residue;
  411.     FILE        *rfile, *dfile;
  412.     
  413.     extern int errno;
  414.  
  415.     pb.fileParam.ioCompletion = 0;
  416.     pb.fileParam.ioVRefNum = macVRef;
  417.     pb.fileParam.ioNamePtr = macname;
  418.     pb.fileParam.ioFVersNum = 0;
  419.     pb.fileParam.ioFDirIndex = 0;
  420.     
  421.     c2pstr(macname);
  422.     myerr = PBGetFInfo(&pb, FALSE);
  423.     p2cstr(macname);
  424.     
  425.     if (myerr != noErr)
  426.         {
  427.         Feedback("Error #%d getting Macintosh file info.", errno);
  428.         return FAILURE;
  429.         }
  430.  
  431.     SetVol(NULL, adrVRef);
  432.     rfile = fopen(adrname, "w");
  433.     if (rfile == NULL)
  434.         {
  435.         Feedback("Error #%d opening apple double rsrc file '%s'.", errno, adrname);
  436.         return FAILURE;
  437.         }
  438.  
  439.     SetVol(NULL, addVRef);
  440.     dfile = fopen(addname, "w");
  441.     if (dfile == NULL)
  442.         {
  443.         Feedback("Error #%d opening apple double data file '%s'.", errno, addname);
  444.         fclose(rfile);
  445.         return FAILURE;
  446.         }
  447.  
  448.     UBegYield();
  449.  
  450.     RotateCursor(32);
  451.     DoYield();
  452.  
  453.     dlength = pb.fileParam.ioFlLgLen;
  454.     rlength = pb.fileParam.ioFlRLgLen;
  455.  
  456.     cdate = pb.fileParam.ioFlCrDat;
  457.     mdate = pb.fileParam.ioFlMdDat;
  458.  
  459.     cdate = MAC_TO_UNIX_TIME(cdate);
  460.     mdate = MAC_TO_UNIX_TIME(mdate);
  461.  
  462.     if (interactive)
  463.         {
  464.         Feedback("Macintosh file '%s'", macname);
  465.         Feedback("File Type '%4.4s'", &pb.fileParam.ioFlFndrInfo.fdType);
  466.         Feedback("File Creator '%4.4s'", &pb.fileParam.ioFlFndrInfo.fdCreator);
  467.         Feedback("Data Fork %d bytes.", dlength);
  468.         Feedback("Rsrc Fork %d bytes.", rlength);
  469.         Feedback("Creation Date [%d] %s", cdate, ctime(&cdate));
  470.         Feedback("Modification Date [%d] %s", mdate, ctime(&mdate));
  471.         }
  472.  
  473.     RotateCursor(32);
  474.     DoYield();
  475.  
  476.     memcpy(&asd_finder, &pb.fileParam.ioFlFndrInfo, sizeof(asd_fndr_fork));
  477.  
  478.     asd_file_head.asd_head.magic = MAGIC_APPLE_DOUBLE;
  479.     asd_file_head.asd_head.version = VERSION_APPLE;
  480.     sprintf(asd_file_head.asd_head.filesys, "%-16.16s", "Macintosh");
  481.  
  482.     i = 0;
  483.     asd_file_head.asd_entries[i].id = ASDID_FNDR_FORK;
  484.     asd_file_head.asd_entries[i].offset = sizeof(asd_file_hdr);
  485.     asd_file_head.asd_entries[i].length = sizeof(asd_fndr_fork);
  486.     i++;
  487.  
  488.     asd_file_head.asd_entries[i].id = ASDID_RSRC_FORK;
  489.     asd_file_head.asd_entries[i].offset =
  490.             asd_file_head.asd_entries[i-1].offset +
  491.             asd_file_head.asd_entries[i-1].length;
  492.     asd_file_head.asd_entries[i].length = rlength;
  493.     i++;
  494.  
  495.     RotateCursor(32);
  496.     DoYield();
  497.  
  498.     asd_file_head.asd_head.entries = i;
  499.     fwrite(&asd_file_head, 1, sizeof(asd_file_hdr), rfile);
  500.     fwrite(&asd_finder, 1, sizeof(asd_fndr_fork), rfile);
  501.     
  502.     Feedback("Mac-RSRC Length %ld", rlength);
  503.     
  504.     if (rlength > 0)
  505.         {
  506.         pb.ioParam.ioCompletion = 0;
  507.         pb.ioParam.ioVRefNum = macVRef;
  508.         pb.ioParam.ioNamePtr = macname;
  509.         pb.ioParam.ioVersNum = 0;
  510.         pb.ioParam.ioPermssn = fsRdPerm;
  511.         pb.ioParam.ioMisc = 0;
  512.         
  513.         c2pstr(macname);
  514.         myerr = PBOpenRF(&pb, FALSE);
  515.         p2cstr(macname);
  516.  
  517.         if (myerr != noErr)
  518.             {
  519.             }
  520.         else
  521.             {
  522.             blocks = rlength / BLK_SIZE;
  523.             residue = rlength % BLK_SIZE;
  524.             for ( ; blocks; blocks-- )
  525.                 {
  526.                 RotateCursor(32);
  527.                 DoYield();
  528.                 if (pause_op)
  529.                     while (pause_op)
  530.                         pausing();
  531.                 
  532.                 iopb.ioParam.ioCompletion = 0;
  533.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  534.                 iopb.ioParam.ioBuffer = iobuffer;
  535.                 iopb.ioParam.ioReqCount = BLK_SIZE;
  536.                 iopb.ioParam.ioPosMode = fsAtMark;
  537.                 iopb.ioParam.ioPosOffset = 0;
  538.                 myerr = PBRead(&iopb, FALSE);
  539.                 if (myerr == noErr)
  540.                     fwrite(iobuffer, 1, BLK_SIZE, rfile);
  541.                 }
  542.             if (residue)
  543.                 {
  544.                 RotateCursor(32);
  545.                 DoYield();
  546.                 if (pause_op)
  547.                     while (pause_op)
  548.                         pausing();
  549.                 
  550.                 iopb.ioParam.ioCompletion = 0;
  551.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  552.                 iopb.ioParam.ioBuffer = iobuffer;
  553.                 iopb.ioParam.ioReqCount = residue;
  554.                 iopb.ioParam.ioPosMode = fsAtMark;
  555.                 iopb.ioParam.ioPosOffset = 0;
  556.                 myerr = PBRead(&iopb, FALSE);
  557.                 if (myerr == noErr)
  558.                     fwrite(iobuffer, 1, residue, rfile);
  559.                 }
  560.             PBClose(&pb, FALSE);
  561.             }
  562.         }
  563.  
  564.     Feedback("Mac-DATA Length %ld", dlength);
  565.     
  566.     if (dlength > 0)
  567.         {
  568.         pb.ioParam.ioCompletion = 0;
  569.         pb.ioParam.ioVRefNum = macVRef;
  570.         pb.ioParam.ioNamePtr = macname;
  571.         pb.ioParam.ioVersNum = 0;
  572.         pb.ioParam.ioPermssn = fsRdPerm;
  573.         pb.ioParam.ioMisc = 0;
  574.         
  575.         c2pstr(macname);
  576.         myerr = PBOpen(&pb, FALSE);
  577.         p2cstr(macname);
  578.         
  579.         if (myerr != noErr)
  580.             {
  581.             }
  582.         else
  583.             {
  584.             blocks = dlength / BLK_SIZE;
  585.             residue = dlength % BLK_SIZE;
  586.             for ( ; blocks; blocks-- )
  587.                 {
  588.                 RotateCursor(32);
  589.                 DoYield();
  590.                 if (pause_op)
  591.                     while (pause_op)
  592.                         pausing();
  593.                     
  594.                 iopb.ioParam.ioCompletion = 0;
  595.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  596.                 iopb.ioParam.ioBuffer = iobuffer;
  597.                 iopb.ioParam.ioReqCount = BLK_SIZE;
  598.                 iopb.ioParam.ioPosMode = fsAtMark;
  599.                 iopb.ioParam.ioPosOffset = 0;
  600.                 myerr = PBRead(&iopb, FALSE);
  601.                 if (myerr == noErr) {
  602.                     if (crnl_flag)
  603.                         for (i=iopb.ioParam.ioActCount, ptr=iobuffer; i; i--, ptr++)
  604.                             if (*ptr == 0x0D) *ptr = 0x0A;
  605.                     
  606.                     fwrite(iobuffer, 1, BLK_SIZE, dfile);
  607.                     }
  608.                 }
  609.             if (residue)
  610.                 {
  611.                 RotateCursor(32);
  612.                 DoYield();
  613.                 if (pause_op)
  614.                     while (pause_op)
  615.                         pausing();
  616.                     
  617.                 iopb.ioParam.ioCompletion = 0;
  618.                 iopb.ioParam.ioRefNum = pb.fileParam.ioFRefNum;
  619.                 iopb.ioParam.ioBuffer = iobuffer;
  620.                 iopb.ioParam.ioReqCount = residue;
  621.                 iopb.ioParam.ioPosMode = fsAtMark;
  622.                 iopb.ioParam.ioPosOffset = 0;
  623.                 myerr = PBRead(&iopb, FALSE);
  624.                 if (myerr == noErr)
  625.                     {
  626.                     if (crnl_flag)
  627.                         for (i=iopb.ioParam.ioActCount, ptr=iobuffer; i; i--, ptr++)
  628.                             if (*ptr == 0x0D) *ptr = 0x0A;
  629.                     
  630.                     fwrite(iobuffer, 1, residue, dfile);
  631.                     }
  632.                 }
  633.             
  634.             PBClose(&pb, FALSE);
  635.             }
  636.         }
  637.  
  638.     WatchCursorOn();
  639.     fclose(rfile);
  640.     fclose(dfile);
  641.     
  642.     set_file_type(adrname, adrVRef, APPL_TYPE, (OSType)'AS/D');
  643.     set_file_type(addname, addVRef, APPL_TYPE, (OSType)'TEXT');
  644.     
  645.     UInitCursor();
  646.     
  647.     UEndYield();
  648.  
  649.     return SUCCESS;
  650.     }
  651.  
  652.