home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / wanderer2.t.Z / wanderer2.t / read.c < prev    next >
C/C++ Source or Header  |  1988-11-23  |  2KB  |  85 lines

  1. #include "wand_head.h"
  2.  
  3. extern int edit_mode;
  4. extern char *edit_screen;
  5. extern char screen[NOOFROWS][ROWLEN+1];
  6.  
  7. int rscreen(num,maxmoves)
  8. int *maxmoves, num;
  9. {
  10. int  y;
  11. FILE *fp;
  12. char name[50];
  13. char (*row_ptr)[ROWLEN+1] = screen;
  14. if(!edit_mode)
  15.     sprintf(name,"%s/screen.%d",SCREENPATH,num);
  16. else
  17.     {
  18.     if(!edit_screen)
  19.         sprintf(name,"./screen");
  20.     else
  21.     sprintf(name,"%s",edit_screen);
  22.     }
  23. fp = fopen(name,"r");
  24. if(fp == NULL)
  25.     {
  26.     if(edit_mode)
  27.     printf("\nCannot find file %s.\n\n",name);
  28.     else
  29.         printf("\nFile for screen %d unavailable.\n\n",num) ;
  30.     }
  31. else
  32.     {
  33.     for(y = 0;y<NOOFROWS;y++)
  34.         {
  35.         fgets((*row_ptr++),ROWLEN + 1,fp);
  36.     fgetc(fp);                         /* remove newline char*/
  37.     };
  38.     if(fscanf(fp,"%*s\n%d",maxmoves) != 1)
  39.     *maxmoves=0;
  40.     fclose(fp);
  41.     };
  42. return (fp == NULL);
  43. }
  44.  
  45. int wscreen(num,maxmoves)
  46. int maxmoves, num;
  47. {
  48. int  y,x;
  49. FILE *fp;
  50. char name[50];
  51. char (*row_ptr)[ROWLEN+1] = screen;
  52. if(!edit_screen)
  53.     sprintf(name,"./screen");
  54. else
  55.     sprintf(name,"%s",edit_screen);
  56. fp = fopen(name,"w");
  57. if(fp == NULL)
  58.     {
  59.     sprintf(name,"/tmp/screen.%d",getpid());
  60.     fp = fopen(name,"w");
  61.     move(21,0);
  62.     addstr("Written file is ");
  63.     addstr(name);
  64.     refresh();
  65.     }
  66. if(fp == NULL)
  67.     printf("\nFile for screen cannot be written.\n\n") ;
  68. else
  69.     {
  70.     for(y = 0;y<NOOFROWS;y++)
  71.         {
  72.     for(x = 0;x<ROWLEN;x++)
  73.         putc(row_ptr[y][x],fp);
  74.     putc('\n',fp);
  75.     };
  76.     for(x = 0; x<ROWLEN;x++)
  77.     putc('#',fp);
  78.     putc('\n',fp);
  79.     if(maxmoves != 0)
  80.     fprintf(fp,"%d\n",maxmoves);
  81.     fclose(fp);
  82.     };
  83. return (fp == NULL);
  84. }
  85.