home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part05 / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  1.4 KB  |  76 lines

  1. /*
  2.  * Routines to read and copy the virtual screen image file.
  3.  */
  4.  
  5. #define MAX_COL    128
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "param.h"
  10. #include "status.h"
  11.  
  12. /*
  13.  * Do a screen dump.  Actually, the screen is already dumped, all we
  14.  * do is copy the file.
  15.  */
  16.  
  17. void
  18. screen_dump()
  19. {
  20.     FILE *fp_in, *fp_out;
  21.     char buf[MAX_COL+2];
  22.     void error_win();
  23.                     /* not guaranteed to exist yet */
  24.     if (!(fp_in = fopen(status->vs_path, "r")))
  25.         return;
  26.                     /* open for append */
  27.     if (!(fp_out = fopen(param->dumpfile, "a"))) {
  28.         fclose(fp_in);
  29.         sprintf(buf, "'%s' for write", param->dumpfile);
  30.         error_win(0, "Can't open screen dump file", buf);
  31.         return;
  32.     }
  33.                     /* skip the x, y coordinates */
  34.     fgets(buf, 10, fp_in);
  35.  
  36.     while (fgets(buf, MAX_COL+2, fp_in) != NULL)
  37.         fputs(buf, fp_out);
  38.  
  39.     fclose(fp_in);
  40.     fclose(fp_out);
  41.  
  42.     return;
  43. }
  44.  
  45. /*
  46.  * Read the virtual screen file and paint its contents to the
  47.  * stdscr with curses.  Leave the cursor where it belongs.
  48.  */
  49.  
  50. void
  51. load_vs()
  52. {
  53.     FILE *fp;
  54.     int row, col, i;
  55.     char buf[MAX_COL+2];
  56.                     /* not guaranteed to exist yet */
  57.     if (!(fp = fopen(status->vs_path, "r")))
  58.         return;
  59.                     /* get the x, y coordinates */
  60.     fgets(buf, 10, fp);
  61.     sscanf(buf, "%d,%d\n", &row, &col);
  62.     
  63.     clearok(stdscr, TRUE);
  64.     i = 0;
  65.     while (fgets(buf, MAX_COL+2, fp) != NULL) {
  66.         buf[COLS] = NULL;
  67.         mvaddstr(i++, 0, buf);
  68.     }
  69.     move(row, col);
  70.     refresh();
  71.     clearok(stdscr, FALSE);
  72.  
  73.     fclose(fp);
  74.     return;
  75. }
  76.