static int
writehindo (struct HJT *hjt1, FILE *fp)
{
  if (output_header_hjt (fp, hjt1) == -1)
    return (-1);
#ifdef WRITE_CHECK
  if (vfwrite (hjt1->hindo, 1, hjt1->maxserial, fp) == -1)
    return (-1);
#else
  vfwrite (hjt1->hindo, 1, hjt1->maxserial, fp);
#endif
  return (0);
}
示例#2
0
int fc_file_out(long s, char * buf, int len)
{
   VFILE *fp = (VFILE *)s;

   vfwrite(buf,len,1,fp);
   return len;
}
示例#3
0
文件: nvfsio.c 项目: fjanssen/Car2X
int
nv_fprintf(NV_FILE * fd, char * format, 
   ...)
{
   int   len,  err;
   char  linebuf[NV_LINELENGTH];
   va_list a;

   va_start(a, format);
   err = vsprintf(linebuf, format, a);
   va_end(a);

#else /* the non-STDARG version */

int
nv_fprintf(NV_FILE * fd, char * format, int arg1)
{
   int len, err;
   char linebuf[NV_LINELENGTH];

   doprint(linebuf, NV_LINELENGTH, format, &arg1);

#endif   /* PRINTF_STDARG */

   /* output string now in linebuf, rest of function is the same */

   /* check for buffer overflow */
   len = strlen(linebuf);
   if (len > NV_LINELENGTH) panic("nv_fprintf");

      /* write formatted buffer to VF device */
   err = vfwrite(linebuf, len, 1, fd);
   return err;
}
示例#4
0
BGBBTJ_API int BGBBTJ_JPG_Store(VFILE *fd, byte *ibuf, int xs, int ys, int qf)
{
	static byte *buf=NULL;
	int fsz;

	if(!buf)buf=malloc(1<<22);

	fsz=BGBBTJ_JPG_Encode(ibuf, buf, xs, ys, qf);
	if(fsz<0)return(fsz);

	vfwrite(buf, 1, fsz, fd);
//	free(buf);

	return(0);
}
示例#5
0
int BGBCC_StoreFile(char *name, void *buf, int sz)
{
	VFILE *fd;

//	basm_storetextfile(b, tbuf);

	fd=vffopen(name, "wb");
	if(fd)
	{
		vfwrite(buf, 1, sz, fd);
		vfclose(fd);
	}

	return(0);
}
示例#6
0
int BGBCC_StoreTextFile(char *name, char *buf)
{
	VFILE *fd;

//	basm_storetextfile(b, tbuf);

	fd=vffopen(name, "wt");
	if(fd)
	{
		vfwrite(buf, 1, strlen(buf), fd);
		vfclose(fd);
	}

	return(0);
}
示例#7
0
int BGBBTJ_PCX_Store(VFILE *fd, unsigned char *img,
	int width, int height, char *pal)
{
	struct PcxHead_s head;
	unsigned char *buf, *s;
	int i, j, l, sz;
	unsigned char t;

	memset(&head, 0, sizeof(head));

	head.tag=0x0A;
	head.version=5;
	head.encoding=1;
	head.bpp=8;

	head.minx=0;
	head.miny=0;
	head.maxx=width-1;
	head.maxy=height-1;

	head.hres=0x500;
	head.vres=0x400;

	head.planes=1;
	head.linesz=width;

	vfputc(head.tag, fd);
	vfputc(head.version, fd);
	vfputc(head.encoding, fd);
	vfputc(head.bpp, fd);

	vfputc(head.minx&0xff, fd);
	vfputc((head.minx>>8)&0xff, fd);
	vfputc(head.miny&0xff, fd);
	vfputc((head.miny>>8)&0xff, fd);

	vfputc(head.maxx&0xff, fd);
	vfputc((head.maxx>>8)&0xff, fd);
	vfputc(head.maxy&0xff, fd);
	vfputc((head.maxy>>8)&0xff, fd);

	vfputc(head.hres&0xff, fd);
	vfputc((head.hres>>8)&0xff, fd);
	vfputc(head.vres&0xff, fd);
	vfputc((head.vres>>8)&0xff, fd);

	vfwrite(head.map, 1, 48, fd);

	vfputc(head.resv, fd);
	vfputc(head.planes, fd);

	vfputc(head.linesz&0xff, fd);
	vfputc((head.linesz>>8)&0xff, fd);

	vfputc(head.paltype&0xff, fd);
	vfputc((head.paltype>>8)&0xff, fd);

	vfwrite(head.resv2, 1, 58, fd);

	sz=width*height;

	buf=img;
	s=buf;
	t=0;
	l=0;

	while((s-buf)<sz)
	{
		if(*s!=t)
		{
			if((l==1) && (t<0xC0))
			{
				vfputc(t, fd);
			}else if(l>0)
			{
				vfputc(0xC0+l, fd);
				vfputc(t, fd);
			}
			l=1;
			t=*s;
			s++;
			continue;
		}
		if(l>=15)
		{
			vfputc(0xC0+l, fd);
			vfputc(t, fd);

			l=1;
			s++;
			continue;
		}
		s++;
		l++;
	}

	if((l==1) && (t<0xC0))
	{
		vfputc(t, fd);
	}else if(l>0)
	{
		vfputc(0xC0+l, fd);
		vfputc(t, fd);
	}

	if(pal)
	{
		vfputc(12, fd);
		vfwrite(pal, 1, 768, fd);
	}else
	{
		vfputc(12, fd);
		for(i=0; i<256; i++)
		{
			vfputc(i, fd);
			vfputc(i, fd);
			vfputc(i, fd);
		}
	}

	return(0);
}
示例#8
0
static void dyx_print_vf(void *p, char *b)
{
	vfwrite(b, 1, strlen(b), (VFILE *)p);
}
示例#9
0
int BGBCC_LoadCSource(char *name, char *out)
{
	char tb[256], tb1[256];
	VFILE *fd;
	BCCX_Node *t;
	byte *obj;
	char *s, *buf, *buf1, *buf2;
	int i, sz, t0, t1, dt;

	if(BGBCC_CacheCheckFile(name))
	{
		strcpy(tb, name);
		s=tb;
		while(*s)
		{
			if(*s=='/')*s='_';
			if(*s=='\\')*s='_';
			if(*s==':')*s='_';
			s++;
		}

		while((s>tb) && (*s!='.'))s--;
		if(s>tb)*s=0;

		sprintf(tb1, "dump/cache/%s.o", tb);

		fd=vffopen(tb1, "rb");
		if(fd)
		{
			obj=vf_bufferin_sz(fd, &sz);
			vfclose(fd);

			if(obj)
			{
				i=BASM_LoadObjectBuffer(tb, obj, sz);
				gcfree(obj);
				if(i>=0)return(0);
			}
		}
	}

//	buf=bgbcc_loadfile(name, &sz);
	buf=BGBCC_ReadFile(name, &sz);

	if(!buf)
	{
		for(i=0; i<bgbcc_nsrc; i++)
		{
			sprintf(tb, "%s/%s", bgbcc_src[i], name);
			buf=bgbcc_loadfile(tb, &sz);
			if(buf)break;
		}
	}

	if(!buf)
	{
		printf("BGBCC_LoadModule: fail load '%s'\n", name);
		return(-1);
	}

	printf("BGBCC_LoadModule: %s %d bytes\n", name, sz);

	strcpy(tb, name);
	s=tb;
	while(*s)
	{
		if(*s=='/')*s='_';
		if(*s=='\\')*s='_';
		if(*s==':')*s='_';
		s++;
	}

	while((s>tb) && (*s!='.'))s--;
	if(s>tb)*s=0;

//	printf("BGBCC_LoadModule: Begin Parse\n");

	t0=clock();
//	t=BS1_CParse_ModuleBuffer(name, tb, buf);
	t=BGBCP_ModuleBuffer(name, tb, buf);

	if(!t)
	{
//		free(buf);
		return(-1);
	}

//	BCCX_PrintFD(stdout, t);

#if 1
	sprintf(tb1, "dump/%s_ast.txt", tb);
	fd=vffopen(tb1, "wt");
	if(fd)
	{
		BCCX_PrintVF(fd, t);
		vfclose(fd);
	}
#endif

	t1=clock();
	dt=t1-t0;
	printf("BGBCC_LoadModule: Parse took %dms\n",
		(int)(1000*(dt/(float)CLOCKS_PER_SEC)));

	buf1=BGBCC_CompileModule(tb, t);

//	BGBGC_SaveSig();
	dyllMetaCommit();

	BGBCC_CleanupAll();

	if(!buf1)
	{
//		free(buf);
		return(-1);
	}

//	printf("%s\n", buf1);

#if 1
	sprintf(tb1, "dump/%s_ril.txt", tb);
	fd=vffopen(tb1, "wt");
	if(fd)
	{
		vfwrite(buf1, 1, strlen(buf1), fd);
		vfclose(fd);
	}
#endif

//	SXIL_BeginModule(tb);
//	sxil_puts(buf1);
//	buf2=SXIL_EndModuleBuffer(out);

	if(!buf2)
	{
//		free(buf);
		return(-1);
	}

//	printf("%s\n", buf2);

#if 1
	sprintf(tb1, "dump/%s_asm.txt", tb);
	fd=vffopen(tb1, "wt");
	if(fd)
	{
		vfwrite(buf2, 1, strlen(buf2), fd);
		vfclose(fd);
	}
#endif

	BASM_BeginAssembly(tb);
	basm_puts(buf2);
	if(out)
	{
		BASM_EndAssemblyFile(out);
	} else
	{
//		BASM_EndAssembly();
//		obj=BASM_EndAssemblyObjBuf(&sz);
//		BASM_LoadObjectBuffer(obj, sz);

		obj=BASM_EndAssemblyCacheObjBuf(&sz);

		sprintf(tb1, "dump/cache/%s.o", tb);
		fd=vffopen(tb1, "wb");
		if(fd)
		{
			vfwrite(obj, 1, sz, fd);
			vfclose(fd);

			BGBCC_UpdateCheckFile(name);
		}
	}

	dt=clock()-t1;
	printf("BGBCC_LoadModule: Compile took %dms\n",
		(int)(1000*(dt/(float)CLOCKS_PER_SEC)));


	if(!out)
		bgbcc_loads[bgbcc_nloads++]=basm_strdup(name);

//	free(buf);
	return(i);
}
示例#10
0
int BGBCC_LoadCSourceBuffer(char *name, char *buf)
{
	char tb[256], tb1[256];
	VFILE *fd;
	FILE *fd2;
	BCCX_Node *t;
	byte *obj;
	char *s, *mod, *buf1, *buf2;
	int i, sz, t0, t1, dt;

//	BGBGC_InitSig();
	dyllMetaInit();

	if(!buf) return(-1);

#if 0
	if(!name)
	{
//		name=BASM_GenSym();

		s=buf; i=0;
		while(*s)i=(i*8191)+(*s++);
		sprintf(tb, "TMP_%08X", i);
		name=dystring(tb);
	}
#endif

	mod=NULL;
	if(name)
	{
		strcpy(tb, name);
		s=tb;
		while(*s)
		{
			if(*s=='/')*s='_';
			if(*s=='\\')*s='_';
			if(*s==':')*s='_';
			s++;
		}

		while((s>tb) && (*s!='.'))s--;
		if(s>tb)*s=0;

		mod=dystrdup(tb);
	}

	t0=clock();
	t=BGBCP_ModuleBuffer(name, mod, buf);

//	BGBGC_Collect();

	if(!t) return(-1);

#if 1
	if(mod)
	{
		sprintf(tb1, "dump/%s_ast.txt", mod);
		fd=vffopen(tb1, "wt");
		if(fd)
		{
			BCCX_PrintVF(fd, t);
			vfclose(fd);
		}
	}
#endif

#if 0
	if(mod)
	{
		sprintf(tb1, "dump/%s_ast.txt", mod);
		fd2=fopen(tb1, "wt");
		if(fd)
		{
			BCCX_PrintFD(fd2, t);
			fclose(fd2);
		}
	}
#endif

	t1=clock();
	dt=t1-t0;
	printf("BGBCC_LoadModule: Parse took %dms\n",
		(int)(1000*(dt/(float)CLOCKS_PER_SEC)));

//	BGBGC_Collect();

	buf1=BGBCC_CompileModule(tb, t);


	if(!buf1) return(-1);

	dyllMetaCommit();
//	BGBGC_SaveSig();
	BGBCC_CleanupAll();

#if 1
	if(mod)
	{
		sprintf(tb1, "dump/%s_ril.txt", mod);
		fd=vffopen(tb1, "wt");
		if(fd)
		{
			vfwrite(buf1, 1, strlen(buf1), fd);
			vfclose(fd);
		}
	}
#endif

//	SXIL_BeginModule(mod);
//	sxil_puts(buf1);
//	buf2=SXIL_EndModuleBuffer(NULL);

	if(!buf2) return(-1);

#if 1
	if(mod)
	{
		sprintf(tb1, "dump/%s_asm.txt", mod);
		fd=vffopen(tb1, "wt");
		if(fd)
		{
			vfwrite(buf2, 1, strlen(buf2), fd);
			vfclose(fd);
		}
	}
#endif

	BASM_BeginAssembly(mod);
	basm_puts(buf2);
	BASM_EndAssembly();

	dt=clock()-t1;
	printf("BGBCC_LoadModule: Compile took %dms\n",
		(int)(1000*(dt/(float)CLOCKS_PER_SEC)));

	return(0);
}
示例#11
0
int
write_file (struct wnn_file *wf, char *n)
{
  FILE *fp;
  int mode = 3;
  struct wnn_file_head fh;
#ifdef WRITE_CHECK
  char *tmp = NULL, *backup = NULL;

  check_backup (n);
#endif
  if ((fp = fopen (n, "r")) != NULL)
    {                           /* Old File Exist */
      if (input_file_header (fp, &fh) == -1)
        {
          wnn_errorno = WNN_NOT_A_FILE;
          fclose (fp);
          return (-1);
        }
      mode = must_write_file (wf, &(fh.file_uniq));
      fclose (fp);
      if (mode == -1)
        return -1;
    }

  if (mode == 0)
    {
      return (0);               /* Need Not Write */
    }
  else if (mode == 1 || mode == 3)
    {                           /* 3 when the file is not the one to be read. */
#ifdef WRITE_CHECK
      backup = make_backup_file (n);
      if ((tmp = make_tmp_file (n, 0, &fp)) == NULL)
        {
          delete_tmp_file (backup);
#else /* WRITE_CHECK */
      if ((fp = fopen (n, "w+")) == NULL)
        {
#endif /* WRITE_CHECK */
          wnn_errorno = WNN_FILE_WRITE_ERROR;
          return (-1);
        }
    }
  else if (mode == 2)
    {
#ifdef WRITE_CHECK
      backup = make_backup_file (n);
      if ((tmp = make_tmp_file (n, 1, &fp)) == NULL)
        {
          delete_tmp_file (backup);
#else /* WRITE_CHECK */
      if ((fp = fopen (n, "r+")) == NULL)
        {                       /* New File */
#endif /* WRITE_CHECK */
          wnn_errorno = WNN_FILE_WRITE_ERROR;
          return (-1);
        }
    }
  if (write_file_real (wf, fp, mode) == -1)
    {
      fclose (fp);
#ifdef WRITE_CHECK
      delete_tmp_file (tmp);
      delete_tmp_file (backup);
#endif /* WRITE_CHECK */
      return -1;
    }
  fclose (fp);
#ifdef WRITE_CHECK
  move_tmp_to_org (tmp, n, 1);
  delete_tmp_file (backup);
#endif /* WRITE_CHECK */
  if ((mode == 1) || (mode == 2))
    {
      clear_dirty_bit (wf);
    }
  return (0);
}

static int
write_file_real (struct wnn_file *wf,
		 FILE *fp,
		 int mode	/* 1 For All, 2 For only hindo */ )
{
  struct wnn_file_head fh;

  if (fp)
    rewind (fp);
  bcopy ((char *) &wf->f_uniq, (char *) &(fh.file_uniq), WNN_F_UNIQ_LEN);
  bcopy ((char *) &wf->f_uniq_org, (char *) &(fh.file_uniq_org), WNN_F_UNIQ_LEN);
  bcopy (wf->passwd, fh.file_passwd, WNN_PASSWD_LEN);
  fh.file_type = wf->file_type;

  if (output_file_header (fp, &fh) == -1)
    {
      wnn_errorno = WNN_FILE_WRITE_ERROR;
      goto ERROR_RET;
    }
  switch (fh.file_type)
    {
    case WNN_FT_DICT_FILE:
      {
        struct JT *jt2;
        struct JT *jt = (struct JT *) wf->area;
        if (little_endian () && jt->dirty)
          {
            if ((jt2 = copy_dict ((struct JT *) wf->area)) == NULL)
              goto ERROR_RET;
            revdic (jt2, 1);
            if (writedict (jt2, fp) == -1)
              goto ERROR_RET;
            jt2 = free_dict (jt2);
          }
        else
          {
/*            if(writedict(wf->area, fp) == -1)goto ERROR_RET; */
            if (mode == 2)
              {
                if (write_hindo_of_dict (wf->area, fp) == -1)
                  goto ERROR_RET;
              }
            else
              {
                if (writedict (wf->area, fp) == -1)
                  goto ERROR_RET;
              }
          }
      }
      break;
    case WNN_FT_HINDO_FILE:
      if (writehindo (wf->area, fp) == -1)
        goto ERROR_RET;
      break;
    case WNN_FT_FUZOKUGO_FILE:
      wnn_errorno = NOT_SUPPORTED_OPERATION;
      goto ERROR_RET;
    }
  return (0);
ERROR_RET:
  return (-1);
}

static int
writedict (struct JT *jt1, FILE *fp)
{

  if (output_header_jt (fp, jt1) == -1)
    return (-1);
#ifdef WRITE_CHECK
  if ((vfwrite (jt1->comment, 2, jt1->maxcomment, fp) == -1) ||
      (vfwrite (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp) == -1) || (vfwrite (jt1->hindo, 1, jt1->maxserial, fp) == -1) || (vfwrite (jt1->hinsi, 2, jt1->maxserial, fp) == -1))
    return (-1);
#ifdef  CONVERT_with_SiSheng
  if (jt1->syurui == CWNN_REV_DICT)     /* for Chinese PinYin dic only */
    if (vfwrite (jt1->sisheng, 2, jt1->maxserial, fp) == -1)
      return (-1);
#endif /* CONVERT_with_SiSheng */
  if ((vfwrite (jt1->kanji, 1, jt1->maxkanji, fp) == -1) ||
      (vfwrite (jt1->table, sizeof (struct uind1), jt1->maxtable, fp) == -1) ||
      (vfwrite (jt1->ri1[D_YOMI], sizeof (struct rind1),
                jt1->maxri1[D_YOMI], fp) == -1) ||
      (vfwrite (jt1->ri1[D_KANJI], sizeof (struct rind1),
                jt1->maxri1[D_KANJI], fp) == -1) || (vfwrite (jt1->hontai, 1, jt1->maxhontai, fp) == -1) || (vfwrite (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp) == -1))
    return (-1);
#else /* WRITE_CHECK */
  vfwrite (jt1->comment, 2, jt1->maxcomment, fp);
  vfwrite (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp);
  vfwrite (jt1->hindo, 1, jt1->maxserial, fp);
  vfwrite (jt1->hinsi, 2, jt1->maxserial, fp);
#ifdef  CONVERT_with_SiSheng
  if (jt1->syurui == CWNN_REV_DICT)     /* for Chinese PinYin dic only */
    vfwrite (jt1->sisheng, 2, jt1->maxserial, fp);
#endif /* CONVERT_with_SiSheng */
  vfwrite (jt1->kanji, 1, jt1->maxkanji, fp);
  vfwrite (jt1->table, sizeof (struct uind1), jt1->maxtable, fp);
  vfwrite (jt1->ri1[D_YOMI], sizeof (struct rind1), jt1->maxri1[D_YOMI], fp);
  vfwrite (jt1->ri1[D_KANJI], sizeof (struct rind1), jt1->maxri1[D_KANJI], fp);
  vfwrite (jt1->hontai, 1, jt1->maxhontai, fp);
  vfwrite (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp);
#endif /* WRITE_CHECK */

  return (0);
}

static int
write_hindo_of_dict (struct JT *jt1, FILE *fp)
{
  if (output_header_jt (fp, jt1) == -1)
    return (-1);
#ifdef WRITE_CHECK
  if ((vfwrite (jt1->comment, 2, jt1->maxcomment, fp) == -1) || (vfwrite (jt1->hindo, 1, jt1->maxserial, fp) == -1))
    return (-1);
#else /* WRITE_CHECK */
  vfwrite (jt1->comment, 2, jt1->maxcomment, fp);
  vfwrite (jt1->hindo, 1, jt1->maxserial, fp);
#endif /* WRITE_CHECK */
  return (0);
}



int
discardfile (struct wnn_file *wf)
{
#ifdef nodef
  FILE *fp;
  if (wf->localf == LOCAL)
    {
      if ((fp = fopen (wf->name, "r")) == NULL)
        {
          log_err ("discardfile:No file %s.", wf->name);
          return (-1);
        }
      fclose (fp);
    }
#endif
  switch (wf->file_type)
    {
    case WNN_FT_DICT_FILE:
      wf->area = free_dict (wf->area);
      break;
    case WNN_FT_HINDO_FILE:
      wf->area = free_hindo (wf->area);
      break;
    case WNN_FT_FUZOKUGO_FILE:
/*
        fzk_discard(wf->area);
*/
      break;
    }
  return (0);
}