Esempio n. 1
0
int
main (int argc, char **argv)
{
  char *mname = "";
  rb.buf = (char *) malloc ((unsigned) (rb.size = 0));
  if (argc > 1)
    mname = argv[1];

  if ((js = js_open (mname, 0)) == NULL)
    err ();

  if ((env = js_connect (js, "kana")) == NULL)
    err ();
  if ((fzk_file = js_file_read (env, FZK_FILE)) == -1)
    err ();
  if ((kihon_file = js_file_read (env, KIHON_DIC)) == -1)
    err ();
  if ((setto_file = js_file_read (env, SETTO_DIC)) == -1)
    err ();

  if (js_fuzokugo_set (env, fzk_file) == -1)
    err ();
  if ((kihon_dic_no = js_dic_add (env, kihon_file, -1, WNN_DIC_ADD_NOR, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
    err ();
  if ((setto_dic_no = js_dic_add (env, setto_file, -1, WNN_DIC_ADD_NOR, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
    err ();
  p_set (env);

  if ((rev_env = js_connect (js, "kanji")) == NULL)
    err ();

  if ((fzk_file = js_file_read (rev_env, FZK_FILE)) == -1)
    err ();
  if ((rev_file = js_file_read (rev_env, KIHON_DIC)) == -1)
    err ();
  if ((rev_setto_file = js_file_read (rev_env, SETTO_DIC)) == -1)
    err ();
  if (js_fuzokugo_set (rev_env, fzk_file) == -1)
    err ();

  if ((rev_dic_no = js_dic_add (rev_env, kihon_file, -1, WNN_DIC_ADD_REV, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
    err ();
  if ((rev_setto_dic_no = js_dic_add (rev_env, setto_file, -1, WNN_DIC_ADD_REV, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
    err ();
  p_set (rev_env);

#ifdef DEBUG
  printf ("Now discard file push any key\n");
  getchar ();
  js_file_discard (rev_env, rev_file);
  printf ("Now discard file\n");
#endif

  henkan ();
  js_close (js);
}
Esempio n. 2
0
/* Pair : row,column */
int lee_algo(Pair* source, Pair* target){
  int i, j, v1, v2;
  Pair p, v, step[4] = {{1,0},{0,1},{-1,0},{0,-1}};
  /* initialize all cells like unvisited */
  for(i=0; i<sz.r; ++i){
    for(j=0; j<sz.c; ++j){
      W[i][j] = -1;
    }
  }
  q_clear();
  p_set(W,source,0);
  q_push(source);
  while(!q_empty()){
    p = q_pop();
    for(i=0; i<4; ++i){
      v = p_sum(step+i,&p);
      v1 = p_get(Z,&p); 
      v2 = p_get(Z,&v);
      #ifdef DEBUG
      printf("try: %d,%d\n",v.r,v.c);
      #endif
      if(p_in(&v) && p_get(W,&v)==-1 && (v1-v2 <= 3) && (v1-v2 >= -1) && can_go(&v)){
        
        #ifdef DEBUG
        printf("from: %d,%d go: %d,%d\n",p.r,p.c,v.r,v.c);
        #endif
        
        p_set(W,&v,p_get(W,&p)+1);
        q_push(&v);
        if(p_eq(&v,target)) break;
      }
    }
    if(p_eq(&v,target)) break;
  }
  #ifdef DEBUG
  printf("q: %d\n",q_empty());
  #endif
  return p_get(W,target);
}
Esempio n. 3
0
int hadlock_algo(Pair* source, Pair* target){
  int i, j, v1, v2, res;
  Pair p, v, step[4] = {{1,0},{0,1},{-1,0},{0,-1}};
  /* initialize all cells like unvisited */
  for(i=0; i<sz.r; ++i){
    for(j=0; j<sz.c; ++j){
      W[i][j] = -1;
    }
  }
  q_clear();
  p_set(W,source,0);
  q_push(source);
  while(!q_empty()){
    p = q_pop();
    for(i=0; i<4; ++i){
      v = p_sum(step+i,&p);
      v1 = p_get(Z,&p); 
      v2 = p_get(Z,&v);
      if(p_in(&v) && (p_get(W,&v)==-1 || (p_get(W,&v)>p_get(W,&p))) && (v1-v2 <= 3) && (v1-v2 >= -1) && can_go(&v)){
        if(p_mhtn_norm(&v,target) < p_mhtn_norm(&p,target)){
          p_set(W,&v,p_get(W,&p));
          q_push_back(&v);
        }else{ /* > */
          /*if(!(p_get(W,&v)!=-1 || (p_get(W,&v)==p_get(W,&p)+1))){ */
          p_set(W,&v,p_get(W,&p)+1);
          q_push_front(&v);  
        }
        if(p_eq(&v,target)){
          break;
        }
      }
    }
    if(p_eq(&v,target)) break;
  }
  res = p_get(W,target);
  if(res != -1) res = 2*res+p_mhtn_norm(source,target); 
  return res;
}
Esempio n. 4
0
static void cpalette(void *data, struct taskinfo *task, int r1, int r2)
{
    pixel8_t *src, *srcend;
    cppixel_t dest;
    struct filter *f = (struct filter *) data;
    struct palettedata *s = (struct palettedata *) f->data;
    int i;
    unsigned int *table = s->table;
    for (i = r1; i < r2; i++) {
	src = f->childimage->currlines[i];
	srcend = src + f->image->width;
	dest = (cppixel_t) f->image->currlines[i];
	while (src < srcend) {
	    p_set(dest, table[*src]);
	    src++;
	    p_inc(dest, 1);
	}
    }
}
Esempio n. 5
0
static void
do_edge (void *data, struct taskinfo *task, int r1, int r2)
{
  struct filter *f = (struct filter *) data;
  int y;
  unsigned int *pixels = f->image->palette->pixels;
  register unsigned int black = f->image->palette->pixels[0];
  register cpixel_t *output, *end;
  register spixel_t *up, *down, *input;
  for (y = r1; y < r2; y++)
    {
      output = p_add (((cpixel_t *) f->image->currlines[y]), 1);
      input = ((spixel_t *) f->childimage->currlines[y]) + 1;
      if (y != 0)
	up = ((spixel_t *) f->childimage->currlines[y - 1]) + 2;
      else
	up = ((spixel_t *) f->childimage->currlines[y]) + 2;
      if (y != f->image->height - 1)
	down = ((spixel_t *) f->childimage->currlines[y + 1]) + 2;
      else
	down = ((spixel_t *) f->childimage->currlines[y]) + 2;
      end =
	p_add (((cpixel_t *) f->image->currlines[y]), f->image->width - 1);
      p_setp (output, -1, 0);
      p_setp (output, f->image->width - 2, 0);
      while (output < end)
	{
	  if (input[1] != input[0] || input[0] != up[0]
	      || input[0] != down[0])
	    {
	      if (output < end - 2)
		{
		  p_set (output, pixels[input[0]]);
		  p_setp (output, 1, pixels[input[1]]);
		  p_setp (output, 2, pixels[input[2]]);
		  p_inc (output, 3);
		  input += 3;
		  up += 3;
		  down += 3;
		  while (output < end - 1
			 && (input[0] != up[-1] || input[0] != down[-1]))
		    {
		      p_set (output, pixels[input[0]]);
		      p_setp (output, 1, pixels[input[1]]);
		      p_inc (output, 2);
		      input += 2;
		      up += 2;
		      down += 2;
		    }
		  if (output < end
		      && (input[-1] != input[0] || up[-2] != input[0]
			  || down[-2] != input[0]))
		    {
		      p_set (output, pixels[input[0]]);
		      p_inc (output, 1);
		      input++;
		      up++;
		      down++;
		    }
		}
	      else
		p_set (output, pixels[*input]), p_inc (output, 1), input++,
		  up++, down++;
	    }
	  else
	    p_set (output, black), p_inc (output, 1), input++, up++, down++;
	}
    }
}
Esempio n. 6
0
     static void tracecolor (int xstart, int ystart, int xend, int yend, register int x, register int y)
{
    int dir = RIGHT, fill = 0;
    register unsigned char *calc;
    int peri = 0;
    cpixeldata_t c = (cpixeldata_t) calculatepixel (x, y, 0);
    cpixeldata_t w = (cpixeldata_t) 0;
    cpixeldata_t inset = (cpixeldata_t) cpalette.pixels[0];
    putpixel (x, y, c);
    calc = calculated + x + y * CALCWIDTH;
    *calc = (unsigned char) 1;
    while (x > xstart && getpixel (x - 1, y) == c)
        x--, calc--;
    *calc = (unsigned char) 2;
    if (c == inset)
        peri = 1;
    do {
        if (!fill && !*calc) {
            *calc = (unsigned char) 1;
            putpixel (x, y, c);
        }
        switch (dir) {
            case RIGHT:
                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y - 1);
                    if (w == c) {
                        dir = UP;
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }

                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        calc++;
                        x++;
                        break;
                    }
                }

                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (*calc == (unsigned char) 2) {
                    *calc = (unsigned char) 1;
                    return;
                }

                dir = LEFT;
                x--;
                calc--;
                break;

            case LEFT:
                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x - 1, y);
                    if (w == c) {
                        calc--;
                        x--;
                        break;
                    }
                }

                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y - 1);
                    if (w == c) {
                        dir = UP;
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }


                dir = RIGHT;
                x++;
                calc++;
                break;

            case UP:
                if (fill) {
                    unsigned char *calc1;
                    cpixel_t *pixel1;
                    calc1 = calc + 1;
                    pixel1 = p_add ((cpixel_t *) cimage.currlines[y], x + 1);
                    while (pixel1 <= p_add ((cpixel_t *) cimage.currlines[y], xend)) {
                        if (!*calc1)
                            *calc1 = (unsigned char) 1, p_set (pixel1, c);
                        else if (p_get (pixel1) != c)
                            break;
                        p_inc (pixel1, 1);
                        calc1++;
                    }
                }
                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    }
                    w = getpixel (x - 1, y);
                    if (w == c) {
                        dir = LEFT;
                        calc--;
                        x--;
                        break;
                    }
                }

                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    }
                    w = getpixel (x, y - 1);
                    if (w == c) {
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }

                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        dir = RIGHT;
                        calc++;
                        x++;
                        break;
                    }
                }

                dir = DOWN;
                y++;
                calc += CALCWIDTH;
                break;
            case DOWN:
                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        dir = RIGHT;
                        calc++;
                        x++;
                        break;
                    }
                }

                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x - 1, y);
                    if (w == c) {
                        dir = LEFT;
                        calc--;
                        x--;
                        break;
                    }
                }

                dir = UP;
                calc -= CALCWIDTH;
                y--;
                break;

        }
        if (*calc == (unsigned char) 2) {
            if (fill) {
                *calc = (unsigned char) 1;
                return;
            }
            fill = 1;
            dir = RIGHT;
        }
    }
    while (1);
}