Ejemplo n.º 1
0
static COMMAND_FUNC( do_read_image_file )	/** open file for reading */
{
	char prompt[256];
	const char *s;
	Image_File *ifp;
	Filetype *ftp;

	ftp = current_filetype();
	sprintf(prompt,"input %s file",FT_NAME(ftp));
	s = NAMEOF(prompt);

	if( s == NULL || *s == 0 ){
		WARN("Null filename!?");
		return;
	}

	ifp = img_file_of(QSP_ARG  s);
	if( ifp != NO_IMAGE_FILE ){
		sprintf(ERROR_STRING,"do_read_image_file:  file %s is already open",ifp->if_name);
		WARN(ERROR_STRING);
		return;
	}

	if(  read_image_file(QSP_ARG  s) == NO_IMAGE_FILE )
		WARN("error reading image file");
}
Ejemplo n.º 2
0
static Data_Obj *get_obj_or_file(QSP_ARG_DECL const char *name)
{
	Data_Obj *dp;
#ifndef PC
	Image_File *ifp;
#endif /* ! PC */

	/* dp = dobj_of(name); */

	/* use hunt_obj() in order to pick up indexed strings */
	dp = hunt_obj(name);
	if( dp != NULL ) return(dp);

#ifndef PC
	ifp = img_file_of(name);
	if( ifp!=NULL ) return(ifp->if_dp);

	sprintf(ERROR_STRING,"No object or open file \"%s\"",name);
	warn(ERROR_STRING);
#else /* PC */
	sprintf(ERROR_STRING,
		"No object \"%s\" (not checking for files!?)",name);
	warn(ERROR_STRING);
#endif /* ! PC */

	return(dp);
}
Ejemplo n.º 3
0
static COMMAND_FUNC( do_write_image_file )
{
	const char *s;
	u_int n;
	Image_File *ifp;

	s=NAMEOF("output image file");
	n=(u_int) HOW_MANY("number of frames");

	if( s == NULL || *s == 0 ){
		WARN("Null filename specified");
		return;
	}

	ifp = img_file_of(QSP_ARG  s);
	if( ifp != NO_IMAGE_FILE ){
		sprintf(ERROR_STRING,"do_write_image_file:  file %s is already open",ifp->if_name);
		WARN(ERROR_STRING);
		return;
	}

	if( write_image_file(QSP_ARG  s,n) == NO_IMAGE_FILE )
		WARN("error writing image file");
}
Ejemplo n.º 4
0
long _recv_img_file(QSP_ARG_DECL  Port *mpp, /* char **bufp */ Packet *pkp )
{
	long len;
	Image_File *old_ifp, *new_ifp;
	char namebuf[LLEN];
	Image_File imgf, *ifp;
	long code;

	ifp=(&imgf);
	len=get_port_int32(mpp);
	if( len <= 0 ) goto error_return;

#ifdef QUIP_DEBUG
if( debug & debug_data ){
sprintf(ERROR_STRING,
"recv_file:  want %ld name bytes",len);
advise(ERROR_STRING);
}
#endif /* QUIP_DEBUG */

	if( (ifp->if_nfrms = get_port_int32(mpp)) == BAD_PORT_LONG ||
	    (ifp->if_ftp = filetype_for_code( QSP_ARG  (filetype_code) get_port_int32(mpp))) == NULL ||
	    (ifp->if_flags = (short) get_port_int32(mpp)) == (short)BAD_PORT_LONG ){
		warn("error getting image file data");
		goto error_return;
	}

	if( len > LLEN ){
		warn("more than LLEN name chars!?");
		goto error_return;
	}
	if( read_port(mpp,namebuf,len) != len ){
		warn("recv_file:  error reading data object name");
		goto error_return;
	}

	/* where does the string get null-terminated? */

	if( (long)strlen( namebuf ) != len-1 ){
		u_int i;

		sprintf(ERROR_STRING,"name length %ld, expected %ld",
			(long)strlen(namebuf), len-1);
		advise(ERROR_STRING);
		sprintf(ERROR_STRING,"name:  \"%s\"",namebuf);
		advise(ERROR_STRING);
		for(i=0;i<strlen(namebuf);i++){
			sprintf(ERROR_STRING,"name[%d] = '%c' (0%o)",
				i,namebuf[i],namebuf[i]);
			advise(ERROR_STRING);
		}
		error1("choked");
	}

	old_ifp=img_file_of(namebuf);

	if( old_ifp != NULL ){
		del_img_file(old_ifp);
		rls_str((char *)old_ifp->if_name);	// BUG?  release name here or not?
		old_ifp = NULL;
	}

	new_ifp=new_img_file(namebuf);
	if( new_ifp==NULL ){
		sprintf(ERROR_STRING,
			"recv_file:  couldn't create file struct \"%s\"",
			namebuf);
		warn(ERROR_STRING);
		goto error_return;
	}

	new_ifp->if_nfrms = imgf.if_nfrms;
	new_ifp->if_ftp = filetype_for_code(QSP_ARG  IFT_NETWORK);
	new_ifp->if_flags = imgf.if_flags;
	new_ifp->if_dp = NULL;	/* BUG should receive? */
	new_ifp->if_pathname = new_ifp->if_name;

	code = get_port_int32(mpp);
	if( code == -1 )
		error1("error port code received!?");
	if( code != P_DATA ){
		sprintf(ERROR_STRING,
	"recv_file:  expected data object packet to complete transmission of file %s!?",
			new_ifp->if_name);
		error1(ERROR_STRING);
	}
		
	// the cast generates a compiler warning???
	if( recv_obj(mpp, pkp ) != sizeof(Data_Obj) ){
		warn("Error receiving data object!?");
		goto error_return;
	}

	// The packet returns the dp in pk_extra...
	return sizeof(*new_ifp);	// BUG - what size should we return???

error_return:
	return -1;
}