Ejemplo n.º 1
0
void save_rot_image_handler(int id_rot){
	char image_head[LENGTHBUF];
	
	input_file_header(image_head);
	int id_image = input_image_format();
	write_rotate_views_glut(id_image, image_head, id_rot);
};
Ejemplo n.º 2
0
int
input_hindo_header (FILE* ifpter, struct HJT* hjtp, struct wnn_file_head* fhp)
{
    if (input_file_header (ifpter, fhp) == -1 || input_header_hjt (ifpter, hjtp) == -1)
    {
        return (-1);
    }
    return (0);
}
Ejemplo n.º 3
0
static void save_image_handler(){
	char image_head[LENGTHBUF];
	
	input_file_header(image_head);
	int id_image = input_image_format();
	
	glutSetWindow(winid);
	draw_mesh_keep_menu();
	write_kemoviewer_window_to_file(id_image, image_head);
	return;
};
Ejemplo n.º 4
0
int
input_header (FILE* ifpter, struct JT* jtp, struct wnn_file_head* fhp)
{

    if (input_file_header (ifpter, fhp) == -1 || input_header_jt (ifpter, jtp) == -1)
    {
        fprintf (stderr, "Not a Wnn file\n");
        return (-1);
    }
    return (0);
}
Ejemplo n.º 5
0
static void load_texture_handler(){
	char image_head[LENGTHBUF];
	
	input_file_header(image_head);
	int id_image = input_image_format();
	
	if(id_image == SAVE_PNG || id_image == SAVE_BMP){
	
		set_texture_current_psf(id_image, image_head);
		set_current_psf_patch_color_mode(TEXTURED_SURFACE);
	};
	
	
	glutSetWindow(winid);
	draw_mesh_w_menu();
	return;
};
Ejemplo n.º 6
0
int
read_file (struct wnn_file *wf)
{
  FILE *fp;
  struct wnn_file_head fh;
  if (wf->localf == REMOTE)
    {
      if (fopen_read_cur (wf->name) == 0)
        {
          wnn_errorno = WNN_FILE_READ_ERROR;
          log_err ("read_file:could not open file %s.", wf->name);
          return (-1);
        }
      fp = NULL;
    }
  else
    {
#ifdef WRITE_CHECK
      check_backup (wf->name);
#endif
      if ((fp = fopen (wf->name, "r")) == NULL)
        {
          wnn_errorno = WNN_FILE_READ_ERROR;
          log_err("read_file:could not open file %s.", wf->name);
          return (-1);
        }
    }
  if (input_file_header (fp, &fh) == -1)
    {
      wnn_errorno = WNN_NOT_A_FILE;
      goto ERROR_RET;
    }
  bcopy ((char *) &(fh.file_uniq), (char *) &(wf->f_uniq), WNN_F_UNIQ_LEN);
  bcopy ((char *) &(fh.file_uniq_org), (char *) &(wf->f_uniq_org), WNN_F_UNIQ_LEN);
  strncpy (wf->passwd, fh.file_passwd, WNN_PASSWD_LEN);
  wf->file_type = fh.file_type;
  wf->ref_count = 0;

  switch (fh.file_type)
    {
    case WNN_FT_DICT_FILE:
      wf->area = (char *) readdict (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    case WNN_FT_HINDO_FILE:
      wf->area = (char *) readhindo (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    case WNN_FT_FUZOKUGO_FILE:
      wf->area = (char *) fzk_read (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    }
  vclose (fp);
  return (0);
ERROR_RET:
  vclose (fp);
  return (-1);
}
Ejemplo n.º 7
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);
}