Esempio n. 1
0
int
mbbs_pngrealloc(Ping *png, MemType **buf, unsigned int *bufsz)
/*
   User-callable routine.

   Reallocates memory for ping data arrays.

   Returns BS_SUCCESS or any of various error codes, also
   returns a pointer to the reallocated (if necessary) buffer
   into *buf and the size in bytes of the buffer into bufsz.
*/
{
    unsigned long long ullnbytes;
    unsigned int nbytes;
    int err, retval;

    if (sizeof(int) < 4)
        return BS_BADARCH;

    if (png == (Ping *) 0)
        return BS_BADARG;

    if ((err= mbbs_pngdatabufsz(png, &ullnbytes)) != BS_SUCCESS)
        return err;

    /* this should be safe to do if the
       preceding call has not returned
       BS_HUGEPING (or any other error) */
    nbytes= (unsigned int) ullnbytes;

    if ((retval= mbbs_memalloc(buf, bufsz, nbytes, (size_t) 1)) != MEM_SUCCESS) {
        switch (retval) {
        case MEM_BADARG:
            return BS_BADARG;
        case MEM_OOB:
            return BS_BADARG;
        case MEM_CALLOC:
            return BS_MEMALLOC;
        default:
            return BS_FAILURE;
        }
    }

    return BS_SUCCESS;
}
Esempio n. 2
0
int
mbbs_seekpngdata(Ping *png, XDR *xdrs)
/*
   User-callable routine.
   Seeks past a single ping data segment
   to the beginning of the next ping header
   in the XDR stream pointed to by xdrs.
   Returns BS_SUCCESS, BS_BADARCH or BS_READ.
*/
{
	int j, bsi, side, err, n, ii, rem;
	unsigned int ui;
	u_int ui1;
	float f;
	char *cp;

	if (sizeof(int) < 4)
		return BS_BADARCH;

	bs_iobytecnt= 0;

	/* sensor data */
	n= png->png_compass.sns_nsamps+
	   png->png_depth.sns_nsamps+
	   png->png_pitch.sns_nsamps+
	   png->png_roll.sns_nsamps;
	for (j= 0; j < n; j++) {
		if (!xdr_float(xdrs, &f))
			return BS_READ;
		bs_iobytecnt+= 4;
	}

	if (png->png_flags & PNG_XYZ)
		bsi= 3;
	else
		bsi= 2;

	for (side= ACP_PORT; side < ACP_NSIDES; side++) {

		/* bathymetry samples */
		n= bsi*png->png_sides[side].ps_btycount;
		for (j= 0; j < n; j++) {
			if (!xdr_float(xdrs, &f))
				return BS_READ;
			bs_iobytecnt+= 4;
		}

		/* bathymetry flags */
		if (!(png->png_flags & PNG_BTYSSFLAGSABSENT)) {
			n= png->png_sides[side].ps_btycount;
			for (j= 0; j < n; j++) {
				if (!xdr_u_int(xdrs, &ui))
					return BS_READ;
				bs_iobytecnt+= 4;
			}
		}

		if ((n= png->png_sides[side].ps_sscount) > 0) {

			/* sidescan samples */
			for (j= 0; j < n; j++) {
				if (!xdr_float(xdrs, &f))
					return BS_READ;
				bs_iobytecnt+= 4;
			}

			/* sidescan flags */
			if (!(png->png_flags & PNG_BTYSSFLAGSABSENT)) {
				if ((err= mbbs_memalloc((MemType **) &ssflagbuf, &ssflagbufsz, (unsigned int) n, (size_t) 1)) != MEM_SUCCESS) {
					switch (err) {
					case MEM_BADARG:
						return BS_BADARG;
					case MEM_OOB:
						return BS_BADARG;
					case MEM_CALLOC:
						return BS_MEMALLOC;
					default:
						return BS_FAILURE;
					}
				}
				cp= (char *) ssflagbuf;
				ui1= (u_int) n;
				if (!xdr_bytes(xdrs, &cp, &ui1, (u_int) n))
					return BS_READ;
				bs_iobytecnt+= 4+n;
				if ((rem= bs_iobytecnt%4) > 0)
					bs_iobytecnt+= 4-rem;
			}
		}
	}

	/* auxiliary beam info */
	if (png->png_flags & PNG_ABI) {
		for (side= ACP_PORT; side < ACP_NSIDES; side++) {
			n= png->png_sides[side].ps_btycount;
			for (j= 0; j < n; j++) {
				if (!xdr_u_int(xdrs, &ui))
					return BS_READ;
				bs_iobytecnt+= 4;
				if (!xdr_int(xdrs, &ii))
					return BS_READ;
				bs_iobytecnt+= 4;
				if (!xdr_float(xdrs, &f))
					return BS_READ;
				bs_iobytecnt+= 4;
				if (!xdr_float(xdrs, &f))
					return BS_READ;
				bs_iobytecnt+= 4;
			}
		}
	}

	return BS_SUCCESS;
}
Esempio n. 3
0
int
mbbs_copypng(int count, XDR *xdris, XDR *xdros, int version)
/*
   User-callable routine.
   Copies the next n pings from the XDR input stream
   pointed to by xdris to the XDR output stream pointed
   to by xdros. version should be the bs_version value
   from the file header which indicates the version of the file.
   Note that this routine will set bs_iobytecnt to the count
   of bytes written, not bytes read!
   Returns BS_SUCCESS, BS_BADARCH, BS_BADARG, BS_READ or BS_WRITE.
*/
{
	Ping png;
	int i, j, bsi, side, n, err, ii, rem;
	unsigned int flags, ui;
	u_int ui1;
	float f;
	char *cp;
	unsigned int ibcsv;

	if (sizeof(int) < 4)
		return BS_BADARCH;

	bs_iobytecnt= 0;

	for (i= 0; i < count; i++) {

		/* note that we want bs_iobytecnt to be a count
		   of the bytes written, not the bytes read! */
		ibcsv= bs_iobytecnt;
		if ((err= mbbs_rdpnghdr(&png, xdris, version)) != BS_SUCCESS)
			return err;
		bs_iobytecnt= ibcsv;

		flags= png.png_flags;
		png.png_flags&= ~PNG_BTYSSFLAGSABSENT;
		ibcsv= bs_iobytecnt;
		if ((err= mbbs_wrpnghdr(&png, xdros)) != BS_SUCCESS)
			return err;
		bs_iobytecnt+= ibcsv;

		/* sensor data */
		n= png.png_compass.sns_nsamps+
		   png.png_depth.sns_nsamps+
		   png.png_pitch.sns_nsamps+
		   png.png_roll.sns_nsamps;
		for (j= 0; j < n; j++) {
			if (!xdr_float(xdris, &f))
				return BS_READ;
			if (!xdr_float(xdros, &f))
				return BS_WRITE;
			bs_iobytecnt+= 4;
		}

		if (png.png_flags & PNG_XYZ)
			bsi= 3;
		else
			bsi= 2;

		for (side= ACP_PORT; side < ACP_NSIDES; side++) {

			/* bathymetry samples */
			n= bsi*png.png_sides[side].ps_btycount;
			for (j= 0; j < n; j++) {
				if (!xdr_float(xdris, &f))
					return BS_READ;
				if (!xdr_float(xdros, &f))
					return BS_WRITE;
				bs_iobytecnt+= 4;
			}

			/* bathymetry flags */
			n= png.png_sides[side].ps_btycount;
			for (j= 0; j < n; j++) {
				if (!(flags & PNG_BTYSSFLAGSABSENT)) {
					if (!xdr_u_int(xdris, &ui))
						return BS_READ;
				}
				else
					ui= BTYD_CLEAR;
				if (!xdr_u_int(xdros, &ui))
					return BS_WRITE;
				bs_iobytecnt+= 4;
			}

			if ((n= png.png_sides[side].ps_sscount) > 0) {

				/* sidescan samples */
				for (j= 0; j < n; j++) {
					if (!xdr_float(xdris, &f))
						return BS_READ;
					if (!xdr_float(xdros, &f))
						return BS_WRITE;
					bs_iobytecnt+= 4;
				}

				/* sidescan flags */
				if ((err= mbbs_memalloc((MemType **) &ssflagbuf, &ssflagbufsz, (unsigned int) n, (size_t) 1)) != MEM_SUCCESS) {
					switch (err) {
					case MEM_BADARG:
						return BS_BADARG;
					case MEM_OOB:
						return BS_BADARG;
					case MEM_CALLOC:
						return BS_MEMALLOC;
					default:
						return BS_FAILURE;
					}
				}
				cp= (char *) ssflagbuf;
				ui1= (u_int) n;
				if (!(flags & PNG_BTYSSFLAGSABSENT)) {
					if (!xdr_bytes(xdris, &cp, &ui1, (u_int) n))
						return BS_READ;
				}
				else {
					for (j= 0; j < n; j++)
						ssflagbuf[j]= SSD_CLEAR;
				}
				if (!xdr_bytes(xdros, &cp, &ui1, (u_int) n))
					return BS_READ;
				bs_iobytecnt+= 4+n;
				if ((rem= bs_iobytecnt%4) > 0)
					bs_iobytecnt+= 4-rem;
			}
		}

		/* auxiliary beam info */
		if (png.png_flags & PNG_ABI) {
			for (side= ACP_PORT; side < ACP_NSIDES; side++) {
				n= png.png_sides[side].ps_btycount;
				for (j= 0; j < n; j++) {
					if (!xdr_u_int(xdris, &ui))
						return BS_READ;
					if (!xdr_u_int(xdros, &ui))
						return BS_WRITE;
					bs_iobytecnt+= 4;
					if (!xdr_int(xdris, &ii))
						return BS_READ;
					if (!xdr_int(xdros, &ii))
						return BS_WRITE;
					bs_iobytecnt+= 4;
					if (!xdr_float(xdris, &f))
						return BS_READ;
					if (!xdr_float(xdros, &f))
						return BS_WRITE;
					bs_iobytecnt+= 4;
					if (!xdr_float(xdris, &f))
						return BS_READ;
					if (!xdr_float(xdros, &f))
						return BS_WRITE;
					bs_iobytecnt+= 4;
				}
			}
		}
	}

	return BS_SUCCESS;
}
Esempio n. 4
0
int
mbbs_seekpng(int count, XDR *xdrs, int version)
/*
   User-callable routine.
   Seeks past the next n pings in the XDR stream pointed to by xdrs.
   version should be the bs_version value from the file header which
   indicates the version of the file.
   Returns BS_SUCCESS, BS_BADARCH, BS_BADARG or BS_READ.
*/
{
	Ping png;
	int i, j, err, bsi, side, n, ii, rem;
	unsigned int ui;
	u_int ui1;
	float f;
	char *cp;
	unsigned long ibcsv;

	if (sizeof(int) < 4)
		return BS_BADARCH;

	bs_iobytecnt= 0;

	switch (version) {
	case MR1_VERSION_1_0:
	case MR1_VERSION_2_0:
	case BS_VERSION_1_0:
	case BS_VERSION_1_1:
	case BS_VERSION_1_2:
	case BS_VERSION_1_3:
	case BS_VERSION_1_4:
		break;
	default:
		return BS_BADARG;
	}

	for (i= 0; i < count; i++) {
		ibcsv= bs_iobytecnt;
		if ((err= mbbs_rdpnghdr(&png, xdrs, version)) != BS_SUCCESS)
			return err;
		bs_iobytecnt+= ibcsv;

		/* sensor data */
		n= png.png_compass.sns_nsamps+
		   png.png_depth.sns_nsamps+
		   png.png_pitch.sns_nsamps+
		   png.png_roll.sns_nsamps;
		for (j= 0; j < n; j++) {
			if (!xdr_float(xdrs, &f))
				return BS_READ;
			bs_iobytecnt+= 4;
		}

		if (png.png_flags & PNG_XYZ)
			bsi= 3;
		else
			bsi= 2;

		for (side= ACP_PORT; side < ACP_NSIDES; side++) {

			/* bathymetry samples */
			n= bsi*png.png_sides[side].ps_btycount;
			for (j= 0; j < n; j++) {
				if (!xdr_float(xdrs, &f))
					return BS_READ;
				bs_iobytecnt+= 4;
			}

			/* bathymetry flags */
			if (!(png.png_flags & PNG_BTYSSFLAGSABSENT)) {
				n= png.png_sides[side].ps_btycount;
				for (j= 0; j < n; j++) {
					if (!xdr_u_int(xdrs, &ui))
						return BS_READ;
					bs_iobytecnt+= 4;
				}
			}

			if ((n= png.png_sides[side].ps_sscount) > 0) {

				/* sidescan samples */
				for (j= 0; j < n; j++) {
					if (!xdr_float(xdrs, &f))
						return BS_READ;
					bs_iobytecnt+= 4;
				}

				/* sidescan flags */
				if (!(png.png_flags & PNG_BTYSSFLAGSABSENT)) {
					if ((err= mbbs_memalloc((MemType **) &ssflagbuf, &ssflagbufsz, (unsigned int) n, (size_t) 1)) != MEM_SUCCESS) {
						switch (err) {
						case MEM_BADARG:
							return BS_BADARG;
						case MEM_OOB:
							return BS_BADARG;
						case MEM_CALLOC:
							return BS_MEMALLOC;
						default:
							return BS_FAILURE;
						}
					}
					cp= (char *) ssflagbuf;
					ui1= (u_int) n;
					if (!xdr_bytes(xdrs, &cp, &ui1, (u_int) n))
						return BS_READ;
					bs_iobytecnt+= 4+n;
					if ((rem= bs_iobytecnt%4) > 0)
						bs_iobytecnt+= 4-rem;
				}
			}
		}

		/* auxiliary beam info */
		if (png.png_flags & PNG_ABI) {
			for (side= ACP_PORT; side < ACP_NSIDES; side++) {
				n= png.png_sides[side].ps_btycount;
				for (j= 0; j < n; j++) {
					if (!xdr_u_int(xdrs, &ui))
						return BS_READ;
					bs_iobytecnt+= 4;
					if (!xdr_int(xdrs, &ii))
						return BS_READ;
					bs_iobytecnt+= 4;
					if (!xdr_float(xdrs, &f))
						return BS_READ;
					bs_iobytecnt+= 4;
					if (!xdr_float(xdrs, &f))
						return BS_READ;
					bs_iobytecnt+= 4;
				}
			}
		}
	}

	return BS_SUCCESS;
}