Ejemplo n.º 1
0
int dept_create(void far *path, unsigned pathlen)
{
  void far * filename;
  FileSpecType far * fileSpecBuf;    
  int  retv,specLen;
    
  /* determine where is the file... */
  if (( filename = _xalloc(13+pathlen)) == NULL)
      return(MEM_ALLOC_ERR);

  _bset( filename,0x0,13+pathlen);
  _bcopy(filename,path,pathlen);
  _bcopy((char *) filename+pathlen,DEPT_IDX_FILE_NAME,sizeof(DEPT_IDX_FILE_NAME));

  if (( fileSpecBuf = _xalloc(sizeof(FileSpecType)) ) == NULL)
  {
      _xfree( filename ); 
      return (MEM_ALLOC_ERR);
  }    

  _bset(fileSpecBuf, 0x0, sizeof(fileSpecBuf) );
  
  specLen = sizeof(FileSpecType);

  fileSpecBuf->recordLength = sizeof(DEPT_RECORD);
  fileSpecBuf->pageSize = 1024;
  fileSpecBuf->indexCount = 1;                /* With one key     */
  fileSpecBuf->fileFlags = 0;                  /* Default settings */
  fileSpecBuf->keySpecBuf.keyPos =  1;
  fileSpecBuf->keySpecBuf.keyLen =  4;
  fileSpecBuf->keySpecBuf.keyFlag = 0;         /* Standard         */
  fileSpecBuf->keySpecBuf.keyType = 0;         /* String type      */

  retv = BTRV(B_CREATE, filePosBlock, (char *) fileSpecBuf, &specLen, filename, 0);

  _xfree(fileSpecBuf);
  _xfree(filename);

#ifdef DEBUG 
  printf("\n status creating dept btrieve file : %d",retv);
#endif    
  
  if(retv != NORMAL)
      return (BTRIEVE_CREATE_ERR);

  return NORMAL;
}
Ejemplo n.º 2
0
Archivo: pal.c Proyecto: MoeXi/roint
struct ROPal *pal_load(struct _reader *reader) {
	struct ROPal *ret;

	ret = (struct ROPal*)_xalloc(sizeof(struct ROPal));
	reader->read(ret, sizeof(struct ROPal), 1, reader);
	
	if (reader->error) {
		// data was missing
		_xlog("PAL is incomplete or invalid\n");
		pal_unload(ret);
		return(NULL);
	}

	return(ret);
}
Ejemplo n.º 3
0
debug
void main(void)
{
	int rc;
	long build_xalloc_size;
	wib_sysIdBlockData far *build;

	// allocate xmem space for the ID block data structure
	build_xalloc_size = sizeof (wib_sysIdBlockData);
	build = (wib_sysIdBlockData far *)_xalloc(&build_xalloc_size, 0, XALLOC_ANY);

	// initialize the ID block build data structure and fill in typical items
	wib_initWriteIdBlockLib(build, _FLASH_SIZE_);
	wib_addAutomaticValues(build);

#if BL4S100 == _BOARD_TYPE_
	// add BL4S100 specific, fixed information
	wib_addBL4S100Info(build);
#elif BL4S110 == _BOARD_TYPE_
	// add BL4S110 specific, fixed information
	wib_addBL4S110Info(build);
#elif BL4S150 == _BOARD_TYPE_
	// add BL4S150 specific, fixed information
	wib_addBL4S150Info(build);
#elif BL4S160 == _BOARD_TYPE_
	// add BL4S160 specific, fixed information
	wib_addBL4S160Info(build);
#else	// BL4S100 == _BOARD_TYPE_
	#fatal "This sample does not support the current _BOARD_TYPE_ definition."
#endif	// BL4S100 == _BOARD_TYPE_

	// copy either the old or (default) new MAC address
	wib_askRetainMAC(build, newMAC);

	// build the ID block and associated items, then write them to the primary
	//  (program, parallel or serial) flash
	rc = wib_buildAndWrite(build);
	wib_termWriteIdBlockLib(build, 1);
	if (rc) {
		printf("\nError, wib_buildAndWrite() result is %d!\n", rc);
	} else {
		printf("\nFinished writing system ID block.\n");
	}

	// we can release our xmem space so long as it was the last one allocated
	xrelease((long) build, build_xalloc_size);
}
Ejemplo n.º 4
0
static int dept_open_file(char * path, unsigned int path_len )
{
  void far *filename;
  int retv = NORMAL;

  /* do the btrieve seek and form the frame parameter... */      
  if (( filename = _xalloc(13+path_len)) == NULL )
       return ( MEM_ALLOC_ERR );

   _bset(filename,0x0,13+path_len);
   _bcopy(filename,path,path_len);
   _bcopy((char *)filename+path_len,DEPT_IDX_FILE_NAME,sizeof(DEPT_IDX_FILE_NAME));
   
   posLen = sizeof(position);
   bufLen = sizeof(DEPT_RECORD);
   /* open the standard btrieve file (DEPTITEMS.IDX)... */            
   retv = BTRV (B_OPEN, filePosBlock,(char *) &deptdata, &bufLen, filename, 0 );

#ifdef AUTO_CREATE   
   if ( retv == 12 ) /* status for file not found */
   {
     retv = dept_create( path, path_len );      

     if ( retv != NORMAL )
     {
        _xfree(filename);           
        return retv;
     }
        
     /* open the standard btrieve file (DEPTITEMS.IDX)... */            
     retv = BTRV (B_OPEN, filePosBlock,(char * ) &deptdata, &bufLen, filename, 0 );        
   }        
#endif     

   _xfree(filename);           
   
   if (  retv  != NORMAL )
       retv = BTRIEVE_OPEN_ERR ;

 return retv;      
}
Ejemplo n.º 5
0
struct _writer *deflatewriter_init(struct _writer *parent, unsigned char type) {
	struct _deflatewriter *ret = (struct _deflatewriter*)_xalloc(sizeof(struct _deflatewriter));
	int windowBits;
	int err;

	ret->base.destroy = &deflatewriter_destroy;
	ret->base.write = &deflatewriter_write;
	ret->base.resize = &deflatewriter_resize;
	ret->base.seek = &deflatewriter_seek;
	ret->base.tell = &deflatewriter_tell;
	ret->base.error = 0;

	ret->stream.zalloc = (alloc_func)&_deflatewriter_zalloc_func;
	ret->stream.zfree = (free_func)&_deflatewriter_zfree_func;
	ret->stream.opaque = (voidpf)ret;
	ret->stream.next_in = Z_NULL;
	ret->stream.avail_in = 0;

	ret->parent = parent;

	if (type == 255)
		windowBits = -DEFLATEWRITER_WINDOW_BITS;
	else
		windowBits = DEFLATEWRITER_WINDOW_BITS + (int)type * 16;
	err = deflateInit2(&ret->stream,
		DEFLATEWRITER_LEVEL, 
		DEFLATEWRITER_METHOD,
		windowBits,
		DEFLATEWRITER_MEM_LEVEL,
		DEFLATEWRITER_STRATEGY);
	if (err != Z_OK) {
		_deflatewriter_zerror("init",err);
		ret->base.error = 1;
	}

	return(CAST_DOWN(ret,base));
}
Ejemplo n.º 6
0
/// zlib allocator
voidpf _deflatewriter_zalloc_func(voidpf opaque, uInt items, uInt size) {
	if (_mul_over_limit(items, size, 0xFFFFFFFF))
		return(Z_NULL);
	return((voidpf)_xalloc(items * size));
}
Ejemplo n.º 7
0
int cScrnRest( int iLeft, int iTop, char *cScrFile,
               int image_ops, int iDelFlag, int iMoveFlag )
{
   struct xScrFileHEADER  xScr;              // Screen file header
   FHANDLE fhandle;                          // Screen file handle
   unsigned char *imgbuf;                    // image buffer
   unsigned int isize;                       // image size variable
   unsigned int iRowCnt;                     // row counter
   int iCnt;                                 // image counter


   if(iMoveFlag != MPIXEL)
     {
       iLeft   = iscale(iLeft  , SCALE_X , SCR_SCALE);
       iTop    = iscale(iTop   , SCALE_Y , SCR_SCALE);
      }


   // Open screen input file
   fhandle = _fsOpen(cScrFile, FO_READ|FO_SHARED);

   if (_fsError())
      return( grSCR_IOERROR );

   // Read Screen File Header
   _fsRead(fhandle,(BYTEP)&xScr, sizeof(xScr));

   // Check Screen file for signature word
   if ( xScr.scrType != SCR_SIGNATURE_WORD)
      {
         _fsClose(fhandle);
         return( grSCR_UNSUPPORTED );
      }

   // Position file pointer to start of screen image
   _fsSeek(fhandle, xScr.lOffBits , FS_SET);

   isize = max( xScr.iSizeImage, xScr.iLastImage);

   // allocate largest memory required to hold the image
   imgbuf = _xalloc(isize);

   if (imgbuf == NULL)
      {
         _fsClose(fhandle);
         return( grSCR_NOMEMORY );
      }


   iRowCnt = iTop;

   for ( iCnt = 1; iCnt <= xScr.iImgCount; iCnt++ )
    {

      if( iCnt == xScr.iImgCount )
          isize = xScr.iLastImage;
      else
          isize = xScr.iSizeImage;

      // Read Image buffer
      _fsRead(fhandle, imgbuf, isize);

      // display the image
      putimage(iLeft, iRowCnt, imgbuf, image_ops);

      iRowCnt += xScr.iRowIncr + 1;

    }

   // clean-up code
   _xfree(imgbuf);
   _fsClose(fhandle);

   // delete screen file
   if (iDelFlag)
      _fsDelete (cScrFile);

   return( grSCR_OKAY );
}
Ejemplo n.º 8
0
Archivo: imf.c Proyecto: MoeXi/roint
struct ROImf *imf_load(struct _reader *reader) {
	struct ROImf *ret;
	unsigned int layerId, actionId;

	if (reader == NULL || reader->error) {
		_xlog("imf.load : invalid argument (reader=%p reader.error=%d)\n", reader, reader->error);
		return(NULL);
	}

	ret = (struct ROImf*)_xalloc(sizeof(struct ROImf));
	memset(ret, 0, sizeof(struct ROImf));

	reader->read(&ret->version, 4, 1, reader);
	if (ret->version == 1.01f)
		;// supported
	else {
		_xlog("imf.load : unknown version v%f\n", ret->version);
		imf_unload(ret);
		return(NULL);
	}

	reader->read(&ret->checksum, 4, 1, reader);
	reader->read(&ret->lastlayer, 4, 1, reader);
	if (ret->lastlayer >= 0) {
		unsigned int layercount = (unsigned int)ret->lastlayer + 1;
		if (layercount > IMF_MAX_LAYER_COUNT) {
			_xlog("imf.load : too many layers (%u)\n", layercount);
			imf_unload(ret);
			return(NULL);
		}
		ret->layers = (struct ROImfLayer*)_xalloc(sizeof(struct ROImfLayer) * layercount);
		memset(ret->layers, 0, sizeof(struct ROImfLayer) * layercount);
		for (layerId = 0; layerId < layercount; layerId++) {
			struct ROImfLayer *layer = &ret->layers[layerId];
			reader->read(&layer->actioncount, 4, 1, reader);
			if (layer->actioncount > IMF_MAX_ACTION_COUNT) {
				_xlog("imf.load : [%u] too many actions (%u)\n", layerId, layer->actioncount);
				imf_unload(ret);
				return(NULL);
			}
			if (layer->actioncount > 0) {
				layer->actions = (struct ROImfAction*)_xalloc(sizeof(struct ROImfAction) * layer->actioncount);
				memset(layer->actions, 0, sizeof(struct ROImfAction) * layer->actioncount);
				for (actionId = 0; actionId < layer->actioncount; actionId++) {
					struct ROImfAction *action = &layer->actions[actionId];
					reader->read(&action->motioncount, 4, 1, reader);
					if (action->motioncount > IMF_MAX_MOTION_COUNT) {
						_xlog("imf.load : [%u][%u] too many motions (%u)\n", layerId, actionId, action->motioncount);
						imf_unload(ret);
						return(NULL);
					}
					if (action->motioncount > 0) {
						action->motions = (struct ROImfMotion*)_xalloc(sizeof(struct ROImfMotion) * action->motioncount);
						reader->read(action->motions, sizeof(struct ROImfMotion), action->motioncount, reader);
					}
				}
			}
		}
	}

	if (reader->error) {
		_xlog("imf.load : read error\n");
		imf_unload(ret);
		return(NULL);
	}

	return(ret);
}
Ejemplo n.º 9
0
Archivo: rsm.c Proyecto: MoeXi/roint
struct RORsm *rsm_load(struct _reader *reader) {
	struct RORsm *ret;

	ret = (struct RORsm*)_xalloc(sizeof(struct RORsm));

	reader->read(ret->magic, 4, 1, reader);
	reader->read(&ret->version, 2, 1, reader);

	if (strncmp("GRSM", ret->magic, 4) != 0) {
		_xlog("Invalid RSM header: '%c%c%c%c'\n", ret->magic[0], ret->magic[1], ret->magic[2], ret->magic[3]);
		_xfree(ret);
		return(NULL);
	}

	//_xlog("RSM Version: %u.%u\n", (unsigned int)ret->v.major, (unsigned int)ret->v.minor);

	reader->read(&ret->anim_length, sizeof(int), 1, reader);
	reader->read(&ret->shade_type, sizeof(int), 1, reader);
	if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 4)) {
		// Versions 1.4 and up
		reader->read(&ret->alpha, sizeof(unsigned char), 1, reader);
	}
	else {
		ret->alpha = 0xff;
	}
	reader->read(ret->reserved, 16, 1, reader);
	reader->read(&ret->texture_count, sizeof(int), 1, reader);

	// Load Textures
	if (ret->texture_count > 0) {
		int i;
		char texname[40];
		ret->textures = (char**)_xalloc(sizeof(char*) * ret->texture_count);
		for (i = 0; i < ret->texture_count; i++) {
			reader->read(texname, 40, 1, reader);
			texname[39] = 0;
			ret->textures[i] = (char*)_xalloc(sizeof(char) * (strlen(texname) + 1));
			strcpy(ret->textures[i], texname);
		}
	}
	else {
		ret->textures = NULL;
	}

	// Nodes
	reader->read(ret->main_node, 40, 1, reader);
	reader->read(&ret->node_count, sizeof(int), 1, reader);

	if (ret->node_count > 0) {
		int i;
		struct RORsmNode *currentNode;

		ret->nodes = (struct RORsmNode*)_xalloc(sizeof(struct RORsmNode) * ret->node_count);

		for (i = 0; i < ret->node_count; i++) {
			currentNode = &ret->nodes[i];

			reader->read(currentNode->name, 40, 1, reader);
			reader->read(currentNode->parent, 40, 1, reader);
			reader->read(&currentNode->texture_count, sizeof(int), 1, reader);

			if (currentNode->texture_count > 0) {
				currentNode->textures = (int*)_xalloc(sizeof(int) * currentNode->texture_count);
				reader->read(currentNode->textures, sizeof(int), currentNode->texture_count, reader);
			}
			else {
				currentNode->textures = NULL;
			}

			reader->read(currentNode->offsetMT, sizeof(float), 9, reader);
			reader->read(&currentNode->pos_, sizeof(struct RORsmVertex), 1, reader);
			reader->read(&currentNode->pos, sizeof(struct RORsmVertex), 1, reader);
			reader->read(&currentNode->rot_angle, sizeof(float), 1, reader);
			reader->read(&currentNode->rot_axis, sizeof(struct RORsmVertex), 1, reader);
			reader->read(&currentNode->scale, sizeof(struct RORsmVertex), 1, reader);

			// Node vertexes
			reader->read(&currentNode->vertice_count, sizeof(int), 1, reader);
			if (currentNode->vertice_count > 0) {
				currentNode->vertices = (struct RORsmVertex*)_xalloc(sizeof(struct RORsmVertex) * currentNode->vertice_count);
				reader->read(currentNode->vertices, sizeof(struct RORsmVertex), currentNode->vertice_count, reader);
			}
			else {
				currentNode->vertices = NULL;
			}

			// Texture vertices
			reader->read(&currentNode->texv_count, sizeof(int), 1, reader);
			if (currentNode->texv_count > 0) {
				currentNode->texv = (struct RORsmTexture*)_xalloc(sizeof(struct RORsmTexture) * currentNode->texv_count);
				if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 2)) {
					// Versions 1.2 and up
					reader->read(currentNode->texv, sizeof(struct RORsmTexture), currentNode->texv_count, reader);
				}
				else {
					int j;
					for (j = 0; j < currentNode->texture_count; i++) {
						currentNode->texv[j].color = 0xffffffff;
						reader->read(&currentNode->texv[j].u, sizeof(float), 2, reader);
					}
				}
			}
			else {
				currentNode->texv = NULL;
			}

			// Faces
			reader->read(&currentNode->face_count, sizeof(int), 1, reader);
			if (currentNode->face_count > 0) {
				currentNode->faces = (struct RORsmFace*)_xalloc(sizeof(struct RORsmFace) * currentNode->face_count);
				if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 2)) {
					// Versions 1.2 and up
					reader->read(currentNode->faces, sizeof(struct RORsmFace), currentNode->face_count, reader);
				}
				else {
					int j;
					for (j = 0; j < currentNode->face_count; j++) {
						reader->read(&currentNode->faces[j], sizeof(struct RORsmFace) - sizeof(int), 1, reader);
						currentNode->faces[j].smoothGroup = 0;
					}
				}
			}
			else {
				currentNode->faces = NULL;
			}

			// Position keyframes
			if (ret->v.major > 1 || (ret->v.major == 2 && ret->v.minor >= 5)) {
				// Versions 1.5 and up
				reader->read(&currentNode->poskey_count, sizeof(int), 1, reader);
			}
			else {
				currentNode->poskey_count = 0;
			}

			if (currentNode->poskey_count > 0) {
				currentNode->poskeys = (struct RORsmPosKeyframe*)_xalloc(sizeof(struct RORsmPosKeyframe) * currentNode->poskey_count);
				reader->read(currentNode->poskeys, sizeof(struct RORsmPosKeyframe), currentNode->poskey_count, reader);
			}
			else {
				currentNode->poskeys = NULL;
			}
			// Rotation keyframes
			reader->read(&currentNode->rotkey_count, sizeof(int), 1, reader);
			if (currentNode->rotkey_count > 0) {
				struct RORsmRotKeyframe* x;
				int rotkeyframe_size = sizeof(struct RORsmRotKeyframe) * currentNode->rotkey_count;
				x = _xalloc(rotkeyframe_size);
				currentNode->rotkeys = x;
				reader->read(currentNode->rotkeys, sizeof(struct RORsmRotKeyframe), currentNode->rotkey_count, reader);
			}
			else {
				currentNode->rotkeys = NULL;
			}
		}
	}
	else {
		ret->nodes = NULL;
	}

	if (reader->error) {
		// data was missing
		_xlog("RSM is incomplete or invalid\n");
		rsm_unload(ret);
		ret = NULL;
	}

	return(ret);
}