[BACK]Return to mglmf.h CVS log [TXT][DIR] Up to [jp.NetBSD.org] / othersrc / mgl / mgl2 / ext

File: [jp.NetBSD.org] / othersrc / mgl / mgl2 / ext / mglmf.h (download)

Revision 1.2, Tue May 8 09:27:28 2001 UTC (17 years, 5 months ago) by suz
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines



destroy のはずが destory になっていたので修正

/*
 * MGL -- MobileGear Graphic Library -
 * Copyright (C) 1998, 1999, 2000, 2001
 *      Koji Suzuki (suz@at.sakura.ne.jp)
 *      Yukihiko Sano (yukihiko@yk.rim.or.jp)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY KOJI SUZUKI AND YUKIHIKO SANO ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#ifndef __MEMORY_FILE_H_
#define __MEMORY_FILE_H_

#define MF_FRAGMENT_SIZE	64

struct memory_file {
	struct memory_file *next;
	struct memory_file *top;
	int total_size; /* valid only if top */
	int size;
	char fdata[MF_FRAGMENT_SIZE];
};

struct mf_context {
	struct memory_file *cur;
	int cur_pos;
	int pos;	/* offset from top */
};

int mf_read(struct mf_context *mc,void *buf,int len);
int mf_write(struct mf_context *mc,void *buf,int len);
int mf_insert(struct mf_context *mc,void *buf,int len);
int mf_delete(struct mf_context *mc,int len);

int mf_create(struct mf_context *mc);
void mf_destroy(struct mf_context *mc);
int mf_set_context(struct mf_context *mc,struct memory_file *mf);
struct memory_file *mf_get_body(struct mf_context *mc);

int mf_seek_forward(struct mf_context *mc,int len);
int mf_seek_backward(struct mf_context *mc,int len);
int mf_seek(struct mf_context *mc,int len,int dir);


int mf_seek_w(struct mf_context *mc,int pos,int dir);
int _mf_tellw(struct mf_context *mc);
int _mf_getw(struct mf_context *mc);
int _mf_putw(struct mf_context *mc,int c);
int _mf_peekw(struct mf_context *mc,int offset);

int _mf_getc(struct mf_context *mc);
int _mf_putc(struct mf_context *mc,int c);
int _mf_peekc(struct mf_context *mc,int offset);
int mf_strncmp(struct mf_context *mc,int offset,char *p,int n);
int _mf_tell(struct mf_context *mc);

static inline int mf_getc(struct mf_context *mc) {
	int r;
	if (mc->cur_pos < mc->cur->size) {
		r = mc->cur->fdata[mc->cur_pos];
		mc->cur_pos++;
		mc->pos++;
		return r & 0xff;
	} else {
		return _mf_getc(mc);
	}
}

static inline int mf_putc(struct mf_context *mc,int c) {
	if (mc->cur_pos < mc->cur->size) {
		mc->cur->fdata[mc->cur_pos] = c;
		mc->cur_pos++;
		mc->pos++;
		return 0;
	} else {
		return _mf_putc(mc,c);
	}
}

static inline int mf_peekc(struct mf_context *mc,int offset) {
	int r;
	if ( (0 <= mc->cur_pos + offset) &&
	      (mc->cur_pos + offset < mc->cur->size)) {
		r = mc->cur->fdata[mc->cur_pos+offset];
		return r & 0xff;
	} else {
		return _mf_peekc(mc,offset);
	}
}

static inline int mf_tell(struct mf_context *mc) {
	return mc->pos;
}

static inline int mf_getw(struct mf_context *mc) {
	int r;
	if (mc->cur_pos+1 < mc->cur->size) {
		r = *(short *)(&mc->cur->fdata[mc->cur_pos]);
		mc->cur_pos +=2;
		mc->pos += 2;
		return r & 0xffff;
	} else {
		return _mf_getw(mc);
	}
}

static inline int mf_putw(struct mf_context *mc,int c) {
	if (mc->cur_pos+1 < mc->cur->size) {
		*(short *)(&mc->cur->fdata[mc->cur_pos]) = c;
		mc->cur_pos += 2;
		mc->pos += 2;
		return 0;
	} else {
		return _mf_putw(mc,c);
	}
}

static inline int mf_peekw(struct mf_context *mc,int offset) {
	int r;
	offset *= 2;
	if ( (0 <= mc->cur_pos + offset) &&
	      (mc->cur_pos + offset+1 < mc->cur->size)) {
		r = *(short *)(&mc->cur->fdata[mc->cur_pos+offset]);
		return r & 0xffff;
	} else {
		return _mf_peekw(mc,offset);
	}
}

static inline int mf_tellw(struct mf_context *mc) {
	return mc->pos/2;
}

#endif