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 >
Wrap
C/C++ Source or Header
|
1988-11-23
|
2KB
|
85 lines
#include "wand_head.h"
extern int edit_mode;
extern char *edit_screen;
extern char screen[NOOFROWS][ROWLEN+1];
int rscreen(num,maxmoves)
int *maxmoves, num;
{
int y;
FILE *fp;
char name[50];
char (*row_ptr)[ROWLEN+1] = screen;
if(!edit_mode)
sprintf(name,"%s/screen.%d",SCREENPATH,num);
else
{
if(!edit_screen)
sprintf(name,"./screen");
else
sprintf(name,"%s",edit_screen);
}
fp = fopen(name,"r");
if(fp == NULL)
{
if(edit_mode)
printf("\nCannot find file %s.\n\n",name);
else
printf("\nFile for screen %d unavailable.\n\n",num) ;
}
else
{
for(y = 0;y<NOOFROWS;y++)
{
fgets((*row_ptr++),ROWLEN + 1,fp);
fgetc(fp); /* remove newline char*/
};
if(fscanf(fp,"%*s\n%d",maxmoves) != 1)
*maxmoves=0;
fclose(fp);
};
return (fp == NULL);
}
int wscreen(num,maxmoves)
int maxmoves, num;
{
int y,x;
FILE *fp;
char name[50];
char (*row_ptr)[ROWLEN+1] = screen;
if(!edit_screen)
sprintf(name,"./screen");
else
sprintf(name,"%s",edit_screen);
fp = fopen(name,"w");
if(fp == NULL)
{
sprintf(name,"/tmp/screen.%d",getpid());
fp = fopen(name,"w");
move(21,0);
addstr("Written file is ");
addstr(name);
refresh();
}
if(fp == NULL)
printf("\nFile for screen cannot be written.\n\n") ;
else
{
for(y = 0;y<NOOFROWS;y++)
{
for(x = 0;x<ROWLEN;x++)
putc(row_ptr[y][x],fp);
putc('\n',fp);
};
for(x = 0; x<ROWLEN;x++)
putc('#',fp);
putc('\n',fp);
if(maxmoves != 0)
fprintf(fp,"%d\n",maxmoves);
fclose(fp);
};
return (fp == NULL);
}