home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 108.lha / Life / Sources / rdwr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-20  |  1.9 KB  |  66 lines

  1. /* This file uses a file name requestor, slightly modified, by "cheath", 
  2.    which was distributed by AZTEC on their examples disk. */
  3.  
  4. #include "getfile.h"
  5. #include "life.h"
  6. #include "stdio.h"
  7. #include "functions.h"
  8. #include "libraries/dosextens.h"
  9.  
  10. FILE *population, *fopen();
  11. char filename[FNAME_SIZE+1] = "life.start";
  12. char dirname[FNAME_SIZE+2]  = ":";
  13. char fullname[2 * FNAME_SIZE + 4];
  14. static struct Process    *OurTask;
  15. static struct Window    *old_pr_WindowPtr;
  16.  
  17.  
  18. dofile(eS, eW, lifearray) 
  19. struct Screen *eS;
  20. struct Window *eW;
  21. short *lifearray;
  22. {
  23. char *mode;                    /* open mode, "r" or "w" */
  24. int  typepick;                 /* return from get_fname */
  25. int  io_count;                 /* no. of items read or written */
  26.   /* CAUTION!!! KNOW ABOUT pr_WindowPtr before you use it!!! */
  27.  
  28.   WBenchToFront();
  29.   OurTask = (struct Process *)FindTask(0L);
  30.   old_pr_WindowPtr = OurTask->pr_WindowPtr;
  31.   OurTask->pr_WindowPtr = eW;
  32.  
  33.   typepick = get_fname(eW, NULL, "Select file", filename, dirname);
  34.   /* ALWAYS RESTORE pr_WindowPtr BEFORE CLOSING THE WINDOW!!! */
  35.   OurTask->pr_WindowPtr = old_pr_WindowPtr;
  36.   WBenchToBack();
  37.  
  38.   switch(typepick)
  39.   { case CANPICK:
  40.       return(FALSE);
  41.       break;         /* do nothing */
  42.     case READPICK:
  43.       mode = "r";
  44.       break;
  45.     case WRTPICK:
  46.       mode = "w";
  47.       break;
  48.   } /* switch */
  49.   strcpy(fullname, dirname);
  50.   strcat(fullname, filename);
  51.   if ((population = fopen(fullname, mode)) == NULL )
  52.     { printf("Can't open file %s\n", fullname);
  53.       DisplayBeep(eS);
  54.       return(FALSE);
  55.     }
  56.   if (typepick == READPICK)
  57.     io_count = fread(lifearray, HWORDS*2, VSIZE, population);
  58.   if (typepick == WRTPICK)
  59.     io_count = fwrite(lifearray, HWORDS*2, VSIZE, population);
  60.   if (io_count != VSIZE)
  61.     printf("File size error; io_count=%d, %d, %d\n",
  62.                              io_count, HWORDS*2, VSIZE);
  63.   fclose(population);
  64.   return(typepick==READPICK); /* tell caller we read something */
  65. } /* dofile */
  66.