home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / other / cled122s / source / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  7.0 KB  |  204 lines

  1. #include "define.h"
  2. #include <stdio.h>
  3. #include <errno.h>
  4. #include <osbind.h>
  5.  
  6.  
  7. /****************************************************************************
  8. SUBROUTINE  :  init_path               VERSION  : 1.0
  9. AUTHOR      :  ROBERT ALLEY            DATE     : 3/3/90
  10. DESCRIPTION :  Initialise directory for disk ops.
  11. LOGIC USED  :  STEP 1.  Get current drive, path.  Build directory string.
  12. RETURNS     :  none.
  13. PARAMETERS  :  mask        *C        Search mask (eg. *.* etc.)
  14. VARIABLES   :  drv         I         Drive number
  15.                lastpath    *C        Last path used
  16. CONSTANTS   :  None.
  17. REQD. FILES :  None.
  18. REQD. SUBPG.:  None.
  19. NOTES       :  Modified form the subrt. init_path by Jim Charlton part of the
  20.                XXED program.
  21. USAGE       :  init_path(mask);
  22. ****************************************************************************/
  23. init_path(directory,mask)
  24. char *directory;
  25. char *mask;
  26. {
  27.    int drv;
  28.    char lastpath[128];
  29.  
  30.    drv=Dgetdrv();
  31.    Dgetpath(lastpath,0);
  32.    sprintf(directory,"%c:%s\\%s",'A'+drv,lastpath,mask);
  33. }
  34.  
  35. /****************************************************************************
  36. SUBROUTINE  : save_graphic           VERSION  : 1.01
  37. AUTHOR      : ROBERT ALLEY           DATE     : 9/2/90
  38. DESCRIPTION : Save a graphic to disk
  39. LOGIC USED  : STEP 1.   Initialise abort flag to false.  While the user has
  40.                         not elected to quit : Call subroutine to
  41.                         get filename.  If they didnt select cancel, open the
  42.                         file, if the file couldnt be opened forma alert 
  43.                         saying so.  Clear error flag.  Clear abort flag if 
  44.                         they elected to continue.  Otherwise set abort flag
  45.                         to an imposssible value.
  46.               STEP 2.   If abort flag isnt 1 (ie. file has been succesfully
  47.                         opened) then loop through each row and each column
  48.                         writting each byte of data to the file.  Close the 
  49.                         file.
  50. PARAMETERS  : None.
  51. VARIABLES   : write       *FIL Pointer to file to write
  52.               loop,outloop I   Loop counters
  53.               abort        I   Return from alert box
  54.               file         *C  Filename to save to.
  55. CONSTANTS   : None.
  56. REQD. FILES : None.
  57. REQD. SUBPG.: None.
  58. NOTES       : None.
  59. USAGE       : save_graphic();
  60. ****************************************************************************/
  61. save_graphic(directory)
  62. char *directory;
  63. {
  64.    extern char data[3][40];
  65.    static char file[128]="";
  66.    FILE *write;
  67.    int loop,outloop;
  68.    int abort;
  69.  
  70. /* STEP 1 */
  71.  
  72.    abort=0;
  73.    while (abort==0) {
  74.       abort = select(file,directory);
  75.       if (abort ==0) {
  76.          if ( (write=fopen(file,"wb"))==(FILE *)NULL) {
  77.             abort=form_alert(1,"[1][Error opening file][Abort|Continue]");
  78.             if (abort==2) abort=0;
  79.          }
  80.          else
  81.             abort=2;
  82.       }
  83.    }
  84.    
  85. /* STEP 2 */
  86.  
  87.    if (abort != 1) {
  88.       for(outloop=0; outloop<3;outloop++)
  89.          for(loop=0;loop<40;loop++) {
  90.             putc(data[outloop][loop],write);
  91.          }
  92.       fclose(write);
  93.    }
  94. }
  95.  
  96. /****************************************************************************
  97. SUBROUTINE  : load_graphic           VERSION  : 1.1
  98. AUTHOR      : ROBERT ALLEY           DATE     : 9/2/90
  99. DESCRIPTION : Load a graphic from disk
  100. LOGIC USED  : STEP 1.   Initialise abort flag to false.  While the user has
  101.                         not elected to quit : Call subroutine to
  102.                         get filename.  If they didnt select cancel, open the
  103.                         file, if the file couldnt be opened forma alert 
  104.                         saying so.  Clear error flag.  Clear abort flag if 
  105.                         they elected to continue.  Otherwise set abort flag
  106.                         to an imposssible value.
  107.               STEP 2.   If abort flag isnt 1 (ie. file has been succesfully
  108.                         opened) then loop through each row and each column
  109.                         reading each byte of data from the file.  Close the 
  110.                         file.
  111. PARAMETERS  : None.
  112. VARIABLES   : write       *FIL Pointer to file to read
  113.               loop,outloop I   Loop counters
  114.               abort        I   Return from alert box
  115.               file         *C  Filename to save to.
  116. CONSTANTS   : None.
  117. REQD. FILES : None.
  118. REQD. SUBPG.: None.
  119. NOTES       : None.
  120. USAGE       : save_graphic();
  121. ****************************************************************************/
  122. load_graphic(directory)
  123. char *directory;
  124. {
  125.    extern char data [3][40];
  126.    static char file[128]="";
  127.    FILE *read;
  128.    int loop,outloop;
  129.    int abort;
  130.  
  131.    abort=0;
  132.    while (abort==0) {
  133.       abort = select(file,directory);
  134.       if (abort ==0) {
  135.          if ( (read=fopen(file,"rb"))==(FILE *)NULL) {
  136.             abort=form_alert(1,"[1][Error opening file][Abort|Continue]");
  137.             if (abort==2) abort=0;
  138.          }
  139.          else
  140.             abort=2;
  141.       }
  142.    }
  143.    if (abort != 1) {
  144.    for(outloop=0; outloop<3;outloop++)
  145.       for(loop=0;loop<40;loop++) {
  146.          data[outloop][loop]=getc(read);
  147.       }  
  148.    fclose(read);
  149.    }
  150. }
  151.  
  152. /****************************************************************************
  153. SUBROUTINE  :                        VERSION  : 1.0
  154. AUTHOR      : ROBERT ALLEY           DATE     : ??/??/89
  155. DESCRIPTION : 
  156. LOGIC USED  : STEP 1.   Form file selecetion box, if they didnt select CANCEL,
  157.                         clear abort flag, set drive variable based on first
  158.                         character in directory.  Set the current drive.  
  159.                         Clear path variable, copy all but first two characters
  160.                         of directory (eg. A:) to path.  Remove search mask
  161.                         from path.  Set current path.  Return abort state.
  162.                         If they selected CANCEL return 1.
  163. PARAMETERS  : file         *C       filename selected
  164. VARIABLES   : i            I        Loop counter
  165.               abort        I        Abort status
  166.               drive        I        Current drive
  167.               button       I        Button selected in file selection box.
  168.               path         *C       Path to build.
  169. CONSTANTS   : None.
  170. REQD. FILES : None.
  171. REQD. SUBPG.: None.
  172. NOTES       : None.
  173. USAGE       : select(filename);
  174. ****************************************************************************/
  175. select(file,directory)
  176. char *file;
  177. char *directory;
  178. {
  179.  
  180.    int i,abort,drive,button;
  181.    char path[128];
  182.  
  183.    fsel_input(directory,file,&button);
  184.    if (button != 0) {
  185.       abort=0;
  186.       drive=directory[0];
  187.       drive=toupper(drive)-65;
  188.       Dsetdrv(drive);
  189.       for (i=0;i<64;i++)
  190.          path[i]=0;
  191.       for (i=0;i<64;i++)
  192.          path[i]=directory[i+2];
  193.       i=strlen(path);
  194.       while (path[i] != '\\') {
  195.          path[i] = '\0';
  196.          i--;
  197.       }
  198.       Dsetpath(path);
  199.       return abort;
  200.    }
  201.    else return 1;
  202.  }
  203.  
  204.