예제 #1
0
/**
 * Part of the floodfill ??
 */
static int fill_line(XImage *image, int x, int y, int width, unsigned int area_color, unsigned int fill_color, int minx, int maxx, dir_type direction)
{
  register int left, right, i;

  XPutPixel(image, x, y, fill_color);
  for( left=x-1; (XGetPixel(image, left, y) == area_color) && (left >= 0);left--)
  {
    XPutPixel(image, left, y, fill_color);
  }
  left++;

  for (right = x+1; (XGetPixel(image, right, y) == area_color) && (right < width); right++)
  {
    XPutPixel(image, right, y, fill_color);
  }

  XDrawLine(dpy, drawable, fill_gc, left, y, right-1, y);

  for (i = left; i < right; i++)
  {
    if (XGetPixel(image, i, y+direction) == area_color)
    {
      /* Last one because we know there is one other pixel */
      i += fill_line(image, i, y+direction, width, area_color, fill_color, left, right, direction) + 1;
    }
  }

  if (left < minx-1) /* Fill other dir */
  {
    for (i = left; i < minx-1; i++)
    {
	    if (XGetPixel(image, i, y-direction) == area_color)
      {
        /* Last one because we know there is one other pixel */
	      i += fill_line(image, i, y-direction, width, area_color, fill_color, left, right, (direction==dir_down?dir_up:dir_down)) + 1;
      }
    }
  }

  if (right > maxx) /* Fill other dir */
  {
    for (i = maxx+1; i < right; i++)
    {
	    if (XGetPixel(image, i, y-direction) == area_color)
      {
        /* Last one because we know there is one other pixel */
	      i += fill_line(image, i, y-direction, width, area_color, fill_color, left, right, (direction==dir_down?dir_up:dir_down)) + 1;
      }
    }
  }
  return(right-x);
}
예제 #2
0
int	get_next_line(const int fd, char **line)
{
	char		*buf;
	int			ret;
	static char	*last = NULL;
	int			i;

	i = 0;
	if (!line || fd < 0 || BUFF_SIZE <= 0 || BUFF_SIZE > 2147483647 ||
			(-1 == (ret = check_last(line, &last, i))))
		return (-1);
	if (ret == 1)
		return (1);
	buf = ft_strnew(BUFF_SIZE);
	if (check_ma(-2, &buf, line) == -1)
		return (-1);
	ret = read(fd, buf, BUFF_SIZE);
	if (check_ma(ret, &buf, line) == -1)
		return (-1);
	if (-1 == (ret = fill_line(&buf, fd, line, ret)))
		return (-1);
	if (ret == 1 || ret == 0)
		return (ret);
	return (create_last(&buf, &last, line) != 1 ? -1 : 1);
}
예제 #3
0
int					get_next_line(int const fd, char **line)
{
	int				i;
	int				ret;
	char			*buffer;
	char			*retline;
	static char		*backline;

	i = 0;
	retline = ((backline) ? ft_strdup(backline) : ft_strnew(BUFF_SIZE));
	while (!ft_strchr(retline, '\n') && retline && fd >= 0 && BUFF_SIZE > 0)
	{
		if ((buffer = ft_strnew(BUFF_SIZE)))
		{
			if ((ret = read(fd, buffer, BUFF_SIZE)) > 0)
				retline = ft_strjoin(retline, buffer);
			else if (ret == 0)
				return (end_line(line, retline, backline));
			free(buffer);
		}
	}
	if (!fill_line(line, retline, &i, fd))
		return (-1);
	backline = ft_strsub(retline, i + 1, (ft_strlen(retline) - i));
	free(retline);
	return (1);
}
예제 #4
0
파일: tetris.c 프로젝트: Zinurist/Tetris
void tick(int * reached_bottom){
	static int filled_lines[4];
	static int counter = 0;
	
	if(*reached_bottom){
		//new piece reached the bottom or gravity activated and things need to be rechecked
		*reached_bottom = 0;
		
		if(counter == 0){//only if call is not coming from gravity stuff
			write_to_world(&current_tetromino, &world);
		}
		
		counter = 0;
		//check for lines right here & gravity
		for(int i = WORLD_HEIGHT-1; i >= world.top_line; i--){
			if(check_line(i)){
				fill_line(i);
				filled_lines[counter] = i;
				counter++;
			}
		}
		
		world.points += 100*counter*counter;
		
		if(counter == 0){
			fill_tetromino(&current_tetromino,rand()%7);
		
			if(check_collision(&current_tetromino, &world)){
				//GAME OVER
				init_game();
			}
		}else{
			current_tetromino.visible = 0;//dont display it while removing lines
		}
		
	}else if(counter != 0){
		//lines to remove, gravity to activate
		//remove from top to bottom
		for(int i = counter-1; i >= 0; i--){
			remove_line(filled_lines[i]);
		}
		set_tick_time();
		*reached_bottom = 1;
	}else{
		//just a normal turn, m8
		*reached_bottom = go_down(&current_tetromino, &world);//in the next tick: block is placed
	}
	
}
예제 #5
0
/**
 * Help function for Gi::FloodFill
 */
static void floodfill(int x, int y, int color)
{
  /* Not nice - should be more general */
  unsigned int width = maxx;
  XImage *winimage;
  XImage *pointimage;
  int area_color;

  // return; // Uncomment this to avoid floodfill

  pointimage = point2image( x, y );
  area_color = XGetPixel(pointimage, 0, 0);
  XDestroyImage(pointimage);
  if (color == area_color) return;

  winimage = xwin2image();
  fill_line(winimage, x, y, width, area_color, color, x, x, dir_down);
  XDestroyImage(winimage);
}
예제 #6
0
파일: uniq.c 프로젝트: lufb/code
static int
fill_data(char *pdata)
{
    const char          *sep = "\n";
    char                *token;
    int                 err;

    init_data();
    token = strtok(pdata, sep);
    while(token != NULL)
    {
        if((err = fill_line(token)) != 0)
        {
            printf("fill_line[%s] error[%d]\n", token, err);
            break;
        }

        token = strtok(NULL, sep);
    }

    return 0;
}
예제 #7
0
파일: scrdisp.c 프로젝트: MrAlert/megazeux
static void help_frame(struct world *mzx_world, char *help, int pos)
{
  // Displays one frame of the help. Simply prints each line. POS is the
  // position of the center line.
  int t1, t2;
  int first = 12;
  int scroll_base_color = mzx_world->scroll_base_color;
  int scroll_arrow_color = mzx_world->scroll_arrow_color;
  unsigned int next_pos;

  // Work backwards to line
  do
  {
    if(help[pos - 1] == 1) break; // Can't.
    pos--;
    // Go to start of this line.
    do
    {
      pos--;
    } while((help[pos] != '\n') && (help[pos] != 1));
    pos++;
    //Back a line!
    first--;
  } while(first > 6);
  //First holds first line pos (6-12) to draw
  if(first > 6)
  {
    for(t1 = 6; t1 < first; t1++)
      fill_line(64, 8, t1, 32, scroll_base_color);
  }
  // Display from First to either 18 or end of help
  for(t1 = first; t1 < 19; t1++)
  {
    // Fill...
    fill_line(64, 8, t1, 32, scroll_base_color);
    // Find NEXT line NOW - Actually get end of this one.
    next_pos = pos;
    while(help[next_pos] != '\n')
      next_pos++;

    // Temp. make a 0
    help[next_pos] = 0;
    // Write- What TYPE is it?
    if(help[pos] != 255) //Normal
      color_string(help + pos, 8, t1, scroll_base_color);
    else
    {
      pos++;
      switch(help[pos])
      {
        case '$':
          // Centered. :)
          pos++;
          t2 = strlencolor(help + pos);
          color_string(help + pos, 40 - (t2 >> 1), t1, scroll_base_color);
          break;
        case '>':
        case '<':
          // Option- Jump to AFTER dest. label/fill
          pos += help[pos + 1] + 3;
          // Now show, two spaces over
          color_string(help + pos, 10, t1, scroll_base_color);
          // Add arrow
          draw_char('\x10', scroll_arrow_color, 8, t1);
          break;
        case ':':
          // Label- Jump to mesg and show
          pos += help[pos + 1] + 3;
          color_string(help + pos, 8, t1, scroll_base_color);
          break;
      }
    }
    // Now fix EOS to be a \n
    help[next_pos] = '\n';
    // Next line...
    next_pos++;
    pos = next_pos;
    if(help[pos] == 0)  break;
  }
  if(t1 < 19)
  {
    for(t1 += 1; t1 < 19; t1++)
      fill_line(64, 8, t1, 32, scroll_base_color);
  }

  update_screen();
}
예제 #8
0
파일: scrdisp.c 프로젝트: MrAlert/megazeux
static void scroll_frame(struct world *mzx_world, struct scroll *scroll,
 int pos, bool mask)
{
  // Displays one frame of a scroll. The scroll edging, arrows, and title
  // must already be shown. Simply prints each line. POS is the position
  // of the scroll's line in the text. This is of the center line.
  int t1;
  unsigned int old_pos = pos;
  char *where;
  int scroll_base_color = mzx_world->scroll_base_color;

  where = scroll->mesg;

  // Display center line
  fill_line(64, 8, 12, 32, scroll_base_color);
  if(mask)
    write_line_mask(where + pos, 8, 12, scroll_base_color, 1);
  else
    write_line_ext(where + pos, 8, 12, scroll_base_color, 1, 0, 16);

  // Display lines above center line
  for(t1 = 11; t1 >= 6; t1--)
  {
    fill_line(64, 8, t1, 32, scroll_base_color);
    // Go backward to previous line
    if(where[pos] != 1)
    {
      pos--;
      if(where[pos] == '\n')
      {
        do
        {
          pos--;
        } while((where[pos] != '\n') && (where[pos] != 1));
        // At start of prev. line -1. Display.
        pos++;
        if(mask)
          write_line_mask(where + pos, 8, t1, scroll_base_color, 1);
        else
          write_line_ext(where + pos, 8, t1, scroll_base_color, 1, 0, 16);
      }
    }
    // Next line...
  }
  // Display lines below center line
  pos = old_pos;
  for(t1 = 13; t1 <= 18; t1++)
  {
    fill_line(64, 8, t1, 32, scroll_base_color);
    if(where[pos] == 0) continue;
    // Go forward to next line
    while(where[pos] != '\n') pos++;
    // At end of current. If next is a 0, don't show nuthin'.
    pos++;
    if(where[pos])
    {
      if(mask)
        write_line_mask(where + pos, 8, t1, scroll_base_color, 1);
      else
        write_line_ext(where + pos, 8, t1, scroll_base_color, 1, 0, 16);
    }
    // Next line...
  }
}
예제 #9
0
파일: intake.c 프로젝트: ruinistis/megazeux
int intake(struct world *mzx_world, char *string, int max_len,
 int x, int y, char color, int exit_type, int filter_type,
 int *return_x_pos, bool robo_intk, char *macro)
{
  int currx, curr_len, macro_position = -1;
  int done = 0, place = 0;
  char cur_char = 0;
  char temp_char;
  int in_macro;
  int use_mask = mzx_world->conf.mask_midchars;
  int mouse_press;
  int key;

  if(macro != NULL)
    macro_position = 0;

  // Activate cursor
  if(insert_on)
    cursor_underline();
  else
    cursor_solid();
  // Put cursor at the end of the string...
  currx = curr_len = (int)strlen(string);

  // ...unless return_x_pos says not to.
  if((return_x_pos) && (*return_x_pos < currx))
    currx = *return_x_pos;

  if(robo_intk && (currx > 75))
    move_cursor(77, y);
  else
    move_cursor(x + currx, y);

  if(insert_on)
    cursor_underline();
  else
    cursor_solid();

  do
  {
    if(!robo_intk)
    {
      if(use_mask)
        write_string_mask(string, x, y, color, 0);
      else
        write_string_ext(string, x, y, color, 0, 0, 16);
    }
    else
    {
      draw_char('\x11', color, 79, y);
      if((curr_len < 76) || (currx < 76))
      {
        draw_char('\x10', color, 0, y);

        if(curr_len < 76)
        {
          if(use_mask)
            write_line_mask(string, x, y, color, 0);
          else
            write_line_ext(string, x, y, color, 0, 0, 16);
          fill_line(76 - curr_len, x + curr_len, y, 32, color);
        }
        else
        {
          temp_char = string[76];
          string[76] = 0;
          if(use_mask)
            write_line_mask(string, x, y, color, 0);
          else
            write_line_ext(string, x, y, color, 0, 0, 16);
          string[76] = temp_char;

          draw_char('\xaf', color, 79, y);
        }
      }
      else
      {
        draw_char('\x20', color, 77, y);
        if(strlen(string + currx - 75) > 78)
        {
          temp_char = string[currx + 1];
          string[currx + 1] = 0;
          if(use_mask)
          {
            write_line_mask(string + currx - 75, x, y, color, 0);
          }
          else
          {
            write_line_ext(string + currx - 75, x, y,
             color, 0, 0, 16);
          }
          string[currx + 1] = temp_char;
        }
        else
        {
          if(use_mask)
          {
            write_line_mask(string + currx - 75, x, y, color, 0);
          }
          else
          {
            write_line_ext(string + currx - 75, x, y,
             color, 0, 0, 16);
          }
        }
        draw_char('\xae', color, 0, y);
        if(currx < curr_len)
          draw_char('\xaf', color, 79, y);
      }
      draw_char('\x20', color, 78, y);
    }

    if(!robo_intk)
    {
      fill_line(max_len + 1 - curr_len, x + curr_len, y, 32, color);
    }
    else
    {
      write_number(currx + 1, 79, 32, 0, 3, 0, 10);
      write_number(curr_len + 1, 79, 36, 0, 3, 0, 10);
    }

    in_macro = 0;

    // Get key
    if(macro_position != -1)
    {
      key = macro[macro_position];
      cur_char = key;

      macro_position++;
      if(macro[macro_position] == 0)
        macro_position = -1;

      if(key == '^')
        key = IKEY_RETURN;
    }
    else
    {
      update_screen();
      update_event_status_delay();
      key = get_key(keycode_internal);
      place = 0;

      cur_char = get_key(keycode_unicode);
    }

    mouse_press = get_mouse_press_ext();

    if(get_mouse_press_ext())
    {
      int mouse_x, mouse_y;
      get_mouse_position(&mouse_x, &mouse_y);
      if((mouse_y == y) && (mouse_x >= x) &&
       (mouse_x <= (x + max_len)) && (mouse_press <= MOUSE_BUTTON_RIGHT))
      {
        // Yep, reposition cursor.
        currx = mouse_x - x;
        if(currx > curr_len)
          currx = curr_len;
      }
      else
      {
        key = -1;
        done = 1;
      }
    }

    // Handle key cases
    switch(key)
    {
      case IKEY_ESCAPE:
      {
        // ESC
        if(exit_type > 0)
        {
          done = 1;
        }
        break;
      }

      case IKEY_RETURN:
      {
        // Enter
        done = 1;
        break;
      }

      case IKEY_HOME:
      {
        if(get_alt_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else
        {
          // Home
          currx = 0;
        }
        break;
      }

      case IKEY_END:
      {
        if(get_alt_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else
        {
          // End
          currx = curr_len;
        }
        break;
      }

      case IKEY_LEFT:
      {
        if(get_ctrl_status(keycode_internal))
        {
          // Find nearest space to the left
          if(currx)
          {
            char *current_position = string + currx;

            if(currx)
              current_position--;

            if(!isalnum((int)*current_position))
            {
              while(currx && !isalnum((int)*current_position))
              {
                current_position--;
                currx--;
              }
            }

            do
            {
              current_position--;
              currx--;
            } while(currx && isalnum((int)*current_position));

            if(currx < 0)
              currx = 0;
          }
        }
        else
        {
          // Left
          if(currx > 0)
            currx--;
        }

        break;
      }

      case IKEY_RIGHT:
      {
        if(get_ctrl_status(keycode_internal))
        {
          // Find nearest space to the right
          if(currx < curr_len)
          {
            char *current_position = string + currx;
            char current_char = *current_position;
            if(!isalnum((int)current_char))
            {
              do
              {
                current_position++;
                currx++;
                current_char = *current_position;
              } while(current_char && !isalnum((int)current_char));
            }

            while(current_char && isalnum((int)current_char))
            {
              current_position++;
              currx++;
              current_char = *current_position;
            }
          }
        }
        else
        {
          // Right
          if(currx < curr_len)
            currx++;
        }

        break;
      }

      case IKEY_F1:
      case IKEY_F2:
      case IKEY_F3:
      case IKEY_F4:
      case IKEY_F5:
      case IKEY_F6:
      case IKEY_F7:
      case IKEY_F8:
      case IKEY_F9:
      case IKEY_F10:
      case IKEY_F11:
      case IKEY_F12:
      case IKEY_UP:
      case IKEY_DOWN:
      case IKEY_TAB:
      case IKEY_PAGEUP:
      case IKEY_PAGEDOWN:
      {
        done = 1;
        break;
      }

      case IKEY_INSERT:
      {
        if(get_alt_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else
        {
          // Insert
          if(insert_on)
            cursor_solid();
          else
            cursor_underline();

          insert_on ^= 1;
        }
        break;
      }

      case IKEY_BACKSPACE:
      {
        // Backspace, at 0 it might exit
        if(get_alt_status(keycode_internal))
        {
          // Alt-backspace, erase input
          curr_len = currx = 0;
          string[0] = 0;
        }
        else

        if(get_ctrl_status(keycode_internal))
        {
          // Find nearest space to the left
          if(currx)
          {
            int old_position = currx;

            if(!isalnum((int)string[currx]))
            {
              while(currx && !isalnum((int)string[currx]))
              {
                currx--;
              }
            }

            while(currx && isalnum((int)string[currx]))
            {
              currx--;
            }

            curr_len -= old_position - currx;

            memmove(string + currx, string + old_position,
             strlen(string + old_position) + 1);
          }
        }
        else

        if(currx == 0)
        {
          if(exit_type == 2)
          {
            done = 1;
          }
        }
        else
        {
          // Move all back 1, decreasing string length
          memmove(string + currx - 1, string + currx, curr_len - currx + 1);
          curr_len--;
          // Cursor back one
          currx--;
        }
        break;
      }

      case IKEY_DELETE:
      {
        // Delete, at the end might exit
        if(currx == curr_len)
        {
          if(exit_type == 2)
            done = 1;
        }
        else
        {
          if(curr_len)
          {
            // Move all back 1, decreasing string length
            memmove(string + currx, string + currx + 1, curr_len - currx);
            curr_len--;
          }
        }
        break;
      }

      case IKEY_c:
      {
        if(get_ctrl_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else

        if(get_alt_status(keycode_internal) && !filter_type)
        {
          // If alt - C is pressed, choose character
          int new_char = char_selection(last_char);
          if(new_char >= 32)
          {
            cur_char = new_char;
            last_char = new_char;
            place = 1;
          }
          else
          {
            place = 0;
          }
        }
        else
        {
          place = 1;
        }

        break;
      }

      case IKEY_t:
      {
        if(get_alt_status(keycode_internal))
        {
          done = 1;
        }
        else
        {
          place = 1;
        }
        break;
      }

      case IKEY_l:
      case IKEY_g:
      case IKEY_d:
      case IKEY_f:
      case IKEY_r:
      {
        if(get_ctrl_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else
        {
          place = 1;
        }
        break;
      }

      case IKEY_i:
      {
        if((get_ctrl_status(keycode_internal) ||
         get_alt_status(keycode_internal)) && robo_intk)
        {
          done = 1;
        }
        else
        {
          place = 1;
        }
        break;
      }

      case IKEY_u:
      case IKEY_o:
      case IKEY_x:
      case IKEY_b:
      case IKEY_s:
      case IKEY_e:
      case IKEY_v:
      case IKEY_p:
      case IKEY_h:
      case IKEY_m:
      {
        if(get_alt_status(keycode_internal) && robo_intk)
        {
          done = 1;
        }
        else
        {
          place = 1;
        }
        break;
      }

      case IKEY_LSHIFT:
      case IKEY_RSHIFT:
      case 0:
      {
        place = 0;
        break;
      }

      default:
      {
        // Place the char
        place = 1;
        break;
      }

      case -1:
      {
        break;
      }
    }

    if(place)
    {
      if((cur_char < 32) && (exit_type == 2))
      {
        done = 1;
        key = cur_char;
      }
      else

      // Keycode.. Filter.
      if(filter_type & 1)
      {
        if((cur_char >= 'a') && (cur_char <= 'z'))
          cur_char -= 32;
      }

      if(filter_type & 2)
      {
        if((cur_char >= 'A') && (cur_char <= 'Z'))
          cur_char += 32;
      }

      // Block numbers
      if((filter_type & 4) && ((cur_char >= '0') && (cur_char <= '9')))
      {
        place = 0;
      }

      // Block alpha
      if((filter_type & 8) &&
       (((cur_char >= 'a') && (cur_char <= 'z')) ||
       ((cur_char >= 'A') && (cur_char <= 'Z'))))
      {
        place = 0;
      }

      // Block spaces
      if((filter_type & 16) && (cur_char == ' '))
      {
        place = 0;
      }

      // Block high-ASCII
      if((filter_type & 32) && (cur_char > 126))
      {
        place = 0;
      }

      // Block these chars
      if((filter_type & 64) &&
       ((cur_char == '*') || (cur_char == '[') ||
       (cur_char == ']') || (cur_char == '>') ||
       (cur_char == '<') || (cur_char == ',') ||
       (cur_char == '|') || (cur_char == '?') ||
       (cur_char == '=') || (cur_char == ';') ||
       (cur_char == '\"') || (cur_char =='/')))
      {
        place = 0;
      }

      // Block these chars
      if((filter_type & 128) &&
       ((cur_char == ':') || (cur_char == '\\')))
      {
        place = 0;
      }

      // Block these chars
      if((filter_type & 256) &&
       (((cur_char > ' ') && (cur_char < '0')) ||
       ((cur_char > '9') && (cur_char < 'A')) ||
       ((cur_char > 'Z') && (cur_char < 'a')) ||
       ((cur_char > 'z') && (cur_char < 127))))
      {
        place = 0;
      }

      // Now, can it still be placed?
      if(place && (curr_len != max_len) && (!done) && cur_char)
      {
        // Overwrite or insert?
        if((insert_on) || (currx == curr_len))
        {
          // Insert- Move all ahead 1, increasing string length
          curr_len++;
          memmove(string + currx + 1, string + currx, curr_len - currx);
        }
        // Add character and move forward one
        string[currx++] = cur_char;
      }
    }

    // Move cursor
    if(robo_intk && (currx > 75))
      move_cursor(77, y);
    else
      move_cursor(x + currx, y);

    if(insert_on)
      cursor_underline();
    else
      cursor_solid();

    // Loop
  } while(!done);

  cursor_off();
  if(return_x_pos)
    *return_x_pos = currx;

  return key;
}
예제 #10
0
파일: pass3.c 프로젝트: B88000005/RunServer
static void
show_run(const struct run *run) {
	/* The animals came in two by two ... */
	const struct chunk *cnk0 = &run->rn_chunk0;
	const struct chunk *cnk1 = &run->rn_chunk1;
	size_t nl_cnt0 = cnk0->ch_last.ps_nl_cnt - cnk0->ch_first.ps_nl_cnt;
	size_t nl_cnt1 = cnk1->ch_last.ps_nl_cnt - cnk1->ch_first.ps_nl_cnt;
	FILE *f0;
	FILE *f1;

	/* display heading of chunk */
	if (!is_set_option('d')) {
		/* no assumptions about the lengths of the file names! */
		size_t size = run->rn_size;
		int pos = 0;

		pos += pr_head(cnk0);
		while (pos < max_line_length + 1) {
			pos += prs(" ");
		}
		pos += prs("|");
		pos += pr_head(cnk1);
		while (pos < 2*max_line_length - unslen(size)) {
			pos += prs(" ");
		}
		fprintf(Output_File, "[%s]\n", size_t2string(size));
	}
	else {
		(void)pr_head(cnk0);
		fprintf(Output_File, "\n");
		(void)pr_head(cnk1);
		fprintf(Output_File, "\n");
	}

	/* stop if that suffices */
	if (is_set_option('n'))
		return;			/* ... had enough so soon ... */

	/* open the files that hold the chunks */
	f0 = open_chunk(cnk0);
	f1 = open_chunk(cnk1);

	/* display the chunks in the required format */
	if (!is_set_option('d')) {
		/* fill 2-column lines and print them */
		while (nl_cnt0 != 0 || nl_cnt1 != 0) {
			if (nl_cnt0) {
				fill_line(f0, line0);
				nl_cnt0--;
			}
			else {
				clear_line(line0);
			}
			if (nl_cnt1) {
				fill_line(f1, line1);
				nl_cnt1--;
			}
			else {
				clear_line(line1);
			}
			show_2C_line(line0, line1);
		}
	}
	else {
		/* display the lines in a diff(1)-like format */
		while (nl_cnt0--) {
			show_1C_line(f0, "<");
		}
		fprintf(Output_File, "---\n");
		while (nl_cnt1--) {
			show_1C_line(f1, ">");
		}
	}

	/* close the pertinent files */
	fclose(f0);
	fclose(f1);
}
예제 #11
0
void fillcorners(float *x, float *m, int w, int h, int pd, int width)
{
	int ptab[8][2] = {
		{0,0},
		{w-1,0},
		{w-1,h-1},
		{0,h-1},
		{(w-1)/2,0},
		{(w-1)/2,h-1},
		{0,(h-1)/2},
		{w-1,(h-1)/2},
	};
	for (int pi = 0; pi < 8; pi++) {
		int p = ptab[pi][0];
		int q = ptab[pi][1];
		int nidx = nearest_idx(x, m, w, h, pd, p, q, width);
		if (nidx < 0) continue;
		fprintf(stderr, "changing (%d %d) from nidx = %d\n", p, q, nidx);
		for (int i = 0; i < pd; i++)
			x[(w*q+p)*pd + i] = x[nidx*pd + i];
		m[w*q+p] = 1;
	}

	if (pd > 1) return;

	// fill-in horizontal boundaries
	{
		float line[w];
		for (int i = 0; i < w; i++) {
			line[i] = m[i] > 0 ? x[i] : NAN;
			m[i] = 2;
		}
		fill_line(x, line, w);

		for (int i = 0; i < w; i++) {
			line[i] = m[w*(h-1)+i] > 0 ? x[w*(h-1)+i] : NAN;
			m[w*(h-1)+i] = 2;
		}
		fill_line(x+w*(h-1), line, w);
	}

	// fill-in vertical boundaries
	{
		float line[h], oline[h];
		for (int i = 0; i < h; i++) {
			line[i] = m[w*i] > 0 ? x[w*i] : NAN;
			m[w*i] = 2;
		}
		fill_line(oline, line, h);
		for (int i = 0; i < h; i++)
			x[w*i] = oline[i];

		for (int i = 0; i < h; i++) {
			line[i] = m[w*i+w-1] > 0 ? x[w*i+w-1] : NAN;
			m[w*i+w-1] = 2;
		}
		fill_line(oline, line, h);
		for (int i = 0; i < h; i++)
			x[w*i+w-1] = oline[i];
	}
}