home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part06 / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  2.0 KB  |  114 lines

  1. /*
  2.  * Routines to read and copy the virtual screen image file.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "param.h"
  9. #include "status.h"
  10.  
  11. /*
  12.  * Do a screen dump.  Actually, the screen is already dumped, all we
  13.  * do is copy the file.
  14.  */
  15.  
  16. void
  17. screen_dump()
  18. {
  19.     FILE *fp_out, *my_fopen();
  20.     char buf[MAX_COL+2];
  21.     void error_win();
  22. #ifdef SHAREDMEM
  23.     int i;
  24. #else /* SHAREDMEM */
  25.     FILE *fp_in;
  26. #endif /* SHAREDMEM */
  27.                     /* open for append */
  28.     if (!(fp_out = my_fopen(param->dumpfile, "a"))) {
  29.         sprintf(buf, "'%s' for write", param->dumpfile);
  30.         error_win(0, "Can't open screen dump file", buf);
  31.         return;
  32.     }
  33. #ifdef SHAREDMEM
  34.     for (i=0; i<LINES; i++)
  35.         fprintf(fp_out, "%s\n", status->vs[i]);
  36.  
  37. #else /* SHAREDMEM */
  38.                     /* not guaranteed to exist yet */
  39.     if (!(fp_in = my_fopen(status->vs_path, "r"))) {
  40.         fclose(fp_in);
  41.         return;
  42.     }
  43.                     /* skip the x, y coordinates */
  44.     fgets(buf, 10, fp_in);
  45.  
  46.     while (fgets(buf, MAX_COL+2, fp_in) != NULL)
  47.         fputs(buf, fp_out);
  48.  
  49.     fclose(fp_in);
  50. #endif /* SHAREDMEM */
  51.     fclose(fp_out);
  52.  
  53.     return;
  54. }
  55.  
  56. /*
  57.  * Read the virtual screen and paint its contents to the stdscr using
  58.  * curses(3).  Move the cursor where it belongs.
  59.  */
  60.  
  61. void
  62. load_vs()
  63. {
  64.     register int i;
  65. #ifndef SHAREDMEM
  66.     FILE *fp, *my_fopen();
  67.     int row, col;
  68.     char buf[MAX_COL+2];
  69. #endif /* SHAREDMEM */
  70.  
  71.     clearok(curscr, TRUE);
  72.     erase();
  73. #ifdef SHAREDMEM
  74.     for (i=0; i<LINES; i++)
  75.         mvaddstr(i, 0, status->vs[i]);
  76.  
  77.     move(status->row, status->col);
  78. #else /* SHAREDMEM */
  79.                     /* not guaranteed to exist yet */
  80.     if (!(fp = my_fopen(status->vs_path, "r")))
  81.         return;
  82.                     /* get the x, y coordinates */
  83.     fgets(buf, 10, fp);
  84.     sscanf(buf, "%d,%d\n", &row, &col);
  85.  
  86.     i = 0;
  87.     while (fgets(buf, MAX_COL+2, fp) != NULL) {
  88.                     /* zap the line feed */
  89.         buf[COLS] = NULL;
  90.         mvaddstr(i++, 0, buf);
  91.     }
  92.     fclose(fp);
  93.     move(row, col);
  94. #endif /* SHAREDMEM */
  95.  
  96.     refresh();
  97.     return;
  98. }
  99.  
  100. /*
  101.  * Zap the virtual screen file (or clear it)
  102.  */
  103.  
  104. void
  105. zap_vs()
  106. {
  107. #ifdef SHAREDMEM
  108.     status->clr = 1;
  109. #else /* SHAREDMEM */
  110.     unlink(status->vs_path);
  111. #endif /* SHAREDMEM */
  112.     return;
  113. }
  114.