home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / L-M / mini / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-03  |  1.7 KB  |  75 lines  |  [TEXT/MPS ]

  1. /* This file contains calls to standard file along with file opens */
  2. /*
  3.    Author: Jerry LeVan
  4.                325 Boone Trail
  5.             Richmond Ky 40475
  6. */
  7. #include <packages.h>
  8. #include <files.h>
  9. #include <errors.h>
  10.  
  11. Boolean OkToSendFile(fref)
  12.  short *fref;    /* channel if all goes well */
  13.  {
  14.     Point loc;
  15.     SFTypeList typeList;
  16.     SFReply reply;
  17.     short ntypes;
  18.     short err;
  19.     
  20.     loc.v = 80;
  21.     loc.h = 100;
  22.     ntypes = 1; 
  23.     
  24.     typeList[0] = 'TEXT';
  25.     
  26.     SFGetFile(&loc, 0, 0, ntypes, typeList, 0, &reply);
  27.     
  28.     if( reply.good ){
  29.             p2cstr(&reply.fName); /* fix for further high level calls */
  30.            /* now try the open */
  31.            if(err = FSOpen(&reply.fName,reply.vRefNum,fref)){
  32.                 ErrorMessage("Can't Open Text File",err);
  33.                    return false;}
  34.            return true;
  35.           }
  36.     else return false;
  37.  }
  38.  
  39. Boolean OkToReceiveFile(fref,vref,creator)
  40.   short *fref;    /* returned channel */
  41.   short *vref;  /* volume ref for flush */
  42.   OSType creator;
  43.   { 
  44.     SFReply reply;
  45.     Point loc;
  46.     short err;
  47.       
  48.       loc.v = 80;
  49.       loc.h = 100;
  50.       
  51.     SFPutFile(&loc, "Select Name","ReceiveFile.Txt", nil, &reply);
  52.     if(reply.good){
  53.       p2cstr(&reply.fName); /* convert to c string */
  54.       if(err=Create(&reply.fName,reply.vRefNum,creator,'TEXT'))
  55.         if(err!=dupFNErr){
  56.         ErrorMessage("Can't Create Text File",err);
  57.         return false;}
  58.         
  59.       if(err = FSOpen(&reply.fName,reply.vRefNum,fref)){
  60.         ErrorMessage("Can't Open Text File",err);
  61.         return false;}
  62.         
  63.       /* truncate the file in case it already exists */
  64.       if(err=SetEOF(*fref,0)){
  65.         ErrorMessage("Error Truncating File",err);
  66.         return false;}
  67.         
  68.       /* everything is ok if we get here */
  69.       *vref = reply.vRefNum; /* the open fixed the channel */
  70.       return true;
  71.      }
  72.      return false;
  73.  }
  74.  
  75.