home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / unix / unxfiles.sit / source / Mac / Un*xFiles_main.c < prev    next >
Text File  |  1989-11-22  |  5KB  |  164 lines

  1. /*
  2.  *     UnixFiles for the Mac
  3.  *
  4.  *     ...Various tools ported from GNU and generic sources found at
  5.  *     uunet.uu.net including (so far)
  6.  *        uuencode
  7.  *        uudecode
  8.  *     At the moment, I'm working on compress, but the code I have wants
  9.  *     to declare a huge array and I'm not too sure about what to do
  10.  *     except look for some other compress code. :-)
  11.  *
  12.  *     This module written and ⌐ 1989 by Pete Gontier.
  13.  *     You may use this code any way you like as long as you
  14.  *     don't sell it or sell any of your binaries.
  15.  *
  16.  *     I hope I've written this module so that interfaces for other
  17.  *     machines can easily be written. I went in and messed with the calling
  18.  *     sequences and return structures of each module so that all errors could
  19.  *     be reported within this one module. Maybe it even worked. Oh, and before
  20.  *     you decide that the code uses too many switches for what it could
  21.  *     accomplish in one, think about how other toold might fit into
  22.  *     it fairly easily. And note how the main code interacts, through
  23.  *     invol and outvol, with my_stdio.h. This is another hack to make
  24.  *     plugging other tools in more easy.
  25.  *
  26.  *     problems and/or kudos to pete@cavevax.ucsb.edu
  27.  */
  28.  
  29. #include <string.h>
  30. #include "my_stdio.h"
  31. #include "Un*xFiles.h"
  32.  
  33. extern int invol, outvol;
  34.  
  35. void CrashSaver ( void ) {
  36. }
  37.  
  38. void InitMac ( void ) {
  39.     InitGraf ( &thePort);
  40.     InitFonts ( );
  41.     InitWindows ( );
  42.     InitMenus ( );
  43.     TEInit ( );
  44.     InitDialogs ( ( ProcPtr ) CrashSaver );
  45.     MaxApplZone ( );
  46.     
  47.     ErrorSound ( nil );
  48.     InitCursor ( );
  49.     FlushEvents ( everyEvent, 0 );
  50. }
  51.  
  52. #ifdef DEBUG
  53. void bitch ( char *message ) {
  54.     ParamText ( "\pBitch: ", "\p[", message, "\p]" );
  55.     SysBeep ( 10 );
  56.     myAlert ( 129, nil );
  57. }
  58. #endif
  59.  
  60. void main ( void ) {
  61.  
  62.      int oldvol, result;
  63.      SFReply sfr;
  64.      SFTypeList sft;
  65.      int theButton;
  66.      char infilename [ 64 ];
  67.      char *errstr, *writeprompt, *fnappend;
  68.      
  69.     if ( GetVol ( NIL, &oldvol ) ) {
  70.            SysBeep ( 10 );
  71.            return;
  72.     }
  73.  
  74. #ifdef DEBUG
  75.     OpenResFile ( "\pUnixFiles ¿" );
  76. #endif
  77.  
  78.     InitMac ( );
  79.     
  80.     sft[0] = 'TEXT';
  81.         
  82.     while ( 1 < ( theButton = myAlert ( 128, nil ) ) ) {
  83.         SFGetFile ( SFCenter ( -4000 ), NIL, NIL, 1, sft, NIL, &sfr );
  84.         if ( sfr.good )
  85.             if ( SetVol ( nil, sfr.vRefNum ) )
  86.                 SysBeep ( 10 );
  87.             else {
  88.                 outvol = invol = sfr.vRefNum;
  89.                 strcpy ( infilename, PtoCstr ( ( char * ) sfr.fName ) );
  90.                 
  91.                 switch ( theButton ) {
  92.                     case 2    : writeprompt = "\puuencode:";
  93.                               fnappend = ".uuencode";
  94.                               break;
  95.                     case 3    :
  96.                               break;
  97.                     default    : SysBeep ( 10 );
  98.                               return;
  99.                               break;
  100.                 }
  101.                 
  102.                 switch ( theButton ) {
  103.                     case 2    :
  104.                               strcat ( ( char * ) sfr.fName, fnappend );
  105.                               CtoPstr ( ( char * ) sfr.fName );
  106.                               SFPutFile ( SFCenter ( -3999 ),
  107.                                           writeprompt,
  108.                                           ( char * ) sfr.fName,
  109.                                           nil, &sfr );
  110.                               outvol = sfr.vRefNum;
  111.                               PtoCstr ( ( char * ) sfr.fName );
  112.                               break;
  113.                     case 3    :
  114.                               break;
  115.                     default    : SysBeep ( 10 );
  116.                               return;
  117.                               break;
  118.                 }
  119.                 
  120.                 SetCursor ( * GetCursor ( watchCursor ) );
  121.                 
  122.                 switch ( theButton ) {
  123.                     case 2    : result = uuencode ( infilename,
  124.                                                   ( char * ) sfr.fName );
  125.                               break;
  126.                     case 3    : result = uudecode ( infilename );
  127.                               break;
  128.                     default    : SysBeep ( 10 );
  129.                               return;
  130.                               break;
  131.                 }
  132.                 
  133.                 SetCursor ( &arrow );
  134.                 
  135.                 switch ( result ) {
  136.                     case NOERR        : break;
  137.                     case OTHER        : errstr = "\pmiscellaneous";                break;
  138.                     case NOOPIN        : errstr = "\pinput open";                   break;
  139.                     case NOOPOUT    : errstr = "\poutput open";                  break;
  140.                     case NOREAD        : errstr = "\pread";                         break;
  141.                     case NOWRITE    : errstr = "\pwrite";                        break;
  142.                     case NOCLIN        : errstr = "\pinput close";                  break;
  143.                     case NOCLOUT    : errstr = "\poutput close";                 break;
  144.                     case FORMAT        : errstr = "\pincorrect format";             break;
  145.                     case UEOF        : errstr = "\punexpected end-of-file";       break;
  146.                     case DETRANS    : errstr = "\pdecompression or translation"; break;
  147.                     default            : errstr = "undefined %u  ";
  148.                                       sprintf ( errstr, errstr, result );
  149.                                       CtoPstr ( errstr );
  150.                                       break;
  151.                 }
  152.                 
  153.                 if ( result ) {
  154.                     ParamText ( "\pSorry, a",
  155.                                 strchr ( "aeiouAEIOU", errstr [ 1 ] ) ? "\pn " : "\p ",
  156.                                 errstr, "\p error occurred." );
  157.                     SysBeep ( 10 );
  158.                     myAlert ( 129, nil );
  159.                 }
  160.             }
  161.          if ( SetVol ( nil, oldvol ) )
  162.              SysBeep ( 10 );
  163.      }
  164. }