home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / SAVSCRN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  2.1 KB  |  92 lines

  1. /*
  2. ** savscrn.c
  3. ** contains: savscrn()
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "gfuncts.h"
  9.  
  10.  
  11.  
  12. #ifndef _MSC
  13. #ifndef    TURBOC
  14.     int fwrite();
  15. #endif
  16. #endif
  17.  
  18.  
  19. /*
  20. **  int
  21. ** savscrn(char *filename)
  22. **
  23. ** ARGUMENT(s)
  24. **  filename    -    filename of file to receive screen image
  25. **
  26. ** DESCRIPTION
  27. **  Saves character/attribute pairs of the entire screen in a file.  This
  28. **  file can later be read by restscrn() which will display it on the
  29. **  screen.
  30. **
  31. ** RETURNS
  32. **    GFSUCCESS,
  33. **    NOTENOUGHMEMORY,
  34. **    CANTOPENFILE,
  35. **    CANTWRITEDEST,
  36. **
  37. **
  38. ** AUTHOR
  39. **  ""   Wed 21-Dec-1988  10:21:13
  40. **   Copyright (C)1988-1990 Greenleaf Software Inc. All Rights Reserved.
  41. **
  42. ** MODIFICATIONS
  43. **
  44. */
  45. int GF_CONV savscrn(filename)
  46. char *filename;
  47. {
  48.     char *opstring;
  49.     union GFSCRNFILE *gfshdr=(union GFSCRNFILE *)0;
  50.     struct GFREGS out;
  51.     unsigned *screenimage=(unsigned *)0;
  52.     FILE *fp=(FILE *)0;
  53.     int retval=GFSUCCESS;
  54.  
  55. #ifndef    AZTEC        
  56.     opstring="wb";
  57. #else
  58.     opstring="w";
  59. #endif
  60.     if((gfshdr=(union GFSCRNFILE *)calloc(sizeof(union GFSCRNFILE),1))==(union GFSCRNFILE *)0)
  61.         return(NOTENOUGHMEMORY);
  62.     gfshdr->f.gffileid=SCRNFILID;
  63.     gfshdr->f.gfuversion=GFVERSION;
  64.     gfshdr->f.gfurevision=GFREVISION;
  65.     gfshdr->f.gfsumcheck=SCRNFILID+GFVERSION+GFREVISION;
  66.     gfshdr->f.gfstructsize=sizeof(union GFSCRNFILE);
  67.     gfshdr->f.gfcurrow=(getcur(0)>>8)&0x00ff;
  68.     gfshdr->f.gfcurcol=getcur(0)&0x00ff;
  69.     vstate(&out);
  70.     gfshdr->f.gfrows=out.dx;
  71.     gfshdr->f.gfcols=out.bx;
  72.     gfshdr->f.gfvidmode=out.ax;
  73.     gfshdr->f.gfreadsize=(out.dx*out.bx)*2;
  74.     if((screenimage=(unsigned *)malloc((gfshdr->f.gfrows*gfshdr->f.gfcols)*2))==(unsigned *)0) {
  75.         free((char *)gfshdr);
  76.         return(NOTENOUGHMEMORY);
  77.     }
  78.     getscrn(0,0,gfshdr->f.gfrows-1,gfshdr->f.gfcols-1,screenimage);
  79.     if((fp=fopen(filename,opstring))==(FILE *)0) {
  80.         free((char *)screenimage);
  81.         free((char *)gfshdr);
  82.         return(CANTOPENFILE);
  83.     }
  84.     if(fwrite((char *)gfshdr,sizeof(union GFSCRNFILE),(int)1,fp)!=(int)1 ||
  85.        fwrite((char *)screenimage,gfshdr->f.gfreadsize,(int)1,fp)!=(int)1 )
  86.         retval=CANTWRITEDEST;
  87.     fclose(fp);
  88.     free((char *)screenimage);
  89.     free((char *)gfshdr);
  90.     return(retval);
  91. }
  92.