コード例 #1
1
ファイル: get_line.c プロジェクト: MarcDeletang/42_1
int					get_next_line(char **line, int fd)
{
	static char		*buf = NULL;
	int				ret;

	if (!line)
		return (-1);
	if (buf)
	{
		if (*line)
			ft_strclr(*line);
		if (create_line(&buf, line))
			return (1);
		else
			ft_strclr(buf);
	}
	else if ((*line = ft_strnew(0)))
		buf = (char *)malloc(sizeof(char) * (100));
	while ((ret = read(fd, buf, 1)))
	{
		buf[ret] = '\0';
		if (create_line(&buf, line))
			return (1);
	}
	ft_memdel((void **)(&buf));
	return ((ret = **line ? 1 : 0));
}
コード例 #2
0
ファイル: get_next_line.c プロジェクト: Lisonscopel/ft_p
int				get_next_line(int const fd, char **line)
{
	static char		rmning[BUFF_SIZE];
	int				ret;
	char			*buf;
	char			*templine;

	if (fd == -1)
		return (-1);
	buf = ft_memalloc(BUFF_SIZE + 1);
	templine = ft_memalloc(BUFF_SIZE + 1);
	if (!templine || !buf)
		return (-1);
	if (create_line(&templine, rmning, rmning) == 1)
		return (ending_file(line, &templine, &buf));
	while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
	{
		buf[ret] = '\0';
		if (create_line(&templine, buf, rmning) == 1)
			return (ending_file(line, &templine, &buf));
	}
	if (ret == -1)
		return (-1);
	if (ret == 0 && templine[0] != '\0')
		return (ending_file(line, &templine, &buf));
	free_mem(&buf, &templine);
	return (0);
}
コード例 #3
0
ファイル: line.c プロジェクト: ntufar/yargitay
/*---------------------------------------------------------------------------*/
line* text2lines( char* text ) {
	char* dup = strdup( text );
	line* res = 0;
	char* s;
	char* b;
	char* b1;
	
	char buf[80];
	
	s = dup;
	
	while( 1 ) {	/* Up to the end of line */
	
		bzero( buf, 80 );
		strncpy( buf, s, 78 );

/* Last line */
		if ( buf[77]==0) { /* last line */
			res = append_line( res, create_line(buf) );
			break;
		}
	
/* Wrapping at word */
		if ( buf[77]!=' ' ) {	/* wrapping a word */
			b = strrchr( buf, ' ' );	/* Find the lasy space */
			
			if ( !b ) { /* long word */
				res = append_line( res, create_line(buf) );
				s+=78;
				continue;
			}
			
			s += (78-(strlen(b)-1));	/* Set new pointer to the beginning of the word */
			*b = 0;
			strip( buf );
			if ( strlen(buf) )
				strcat(buf, " ");
			
			res = append_line( res, create_line(buf) );
			continue;
		}

/* Wrapping at space */
		b = buf+76;

		strip( buf );
		if ( strlen(buf) )
			strcat(buf, " ");

		res = append_line( res, create_line(buf) );
		s+=78;
	}
	
	while ( res->prev )
		res = res->prev;
		
	free(dup);
	return res;
}
コード例 #4
0
ファイル: main.c プロジェクト: puchka/backtracking_draw
void draw()
{
    File *file = NULL;
    file = malloc(sizeof(*file));
    file->head = NULL;

    Point point, actualPoint;
    point.x = WIDTH/2;
    point.y = HEIGHT/2;

    string(file, point);
    int i=1, j, n=1, n_temp;
    while (i<=DEPTH)
    {
        for (j=0;j<i-1;j++)
            n=n_temp*4;
        n_temp = n;
        while(n!=0)
        {
            actualPoint = march(file);
            create_line(actualPoint.x-256/(2*i),
                        actualPoint.y,
                        actualPoint.x+256/(2*i),
                        actualPoint.y);
            create_line(actualPoint.x-256/(2*i),
                        actualPoint.y-256/(4*i),
                        actualPoint.x-256/(2*i),
                        actualPoint.y+256/(4*i));
            create_line(actualPoint.x+256/(2*i),
                        actualPoint.y-256/(4*i),
                        actualPoint.x+256/(2*i),
                        actualPoint.y+256/(4*i));

            point.x = actualPoint.x-256/(2*i);
            point.y = actualPoint.y-256/(4*i);
            string(file, point);
            point.x = actualPoint.x-256/(2*i);
            point.y = actualPoint.y+256/(4*i);
            string(file, point);
            point.x = actualPoint.x+256/(2*i);
            point.y = actualPoint.y-256/(4*i);
            string(file, point);
            point.x = actualPoint.x+256/(2*i);
            point.y = actualPoint.y+256/(4*i);
            string(file, point);

            n--;
        }
        i++;
    }
}
コード例 #5
0
/**
 * Interpret the input buffer 's'. This either executes the BASIC command in 's' or
 * creates a new program line containing the parsed command in 's'.
 */
void interpret(char *s) {
  char * command = s;
  unsigned int line_number;

  error = 0;
  current_line = 0;
  running = 0;

  if (strlen(s) == 0) {
    return;
  }

  if (isdigit(s[0])) {
    sscanf(s, "%u", &line_number);
    command = strchr(s, ' ');
    command = skip_whitespace(command);
    if (command) {
      create_line(line_number, (char *) command);
    } else {
      delete_line(line_number);
    }
  } else {
    execute((char *) command);
  }
}
コード例 #6
0
ファイル: get_next_line.c プロジェクト: gbourgeo/42projects
static int	check_struct(int const fd, char **line, t_gnl **gnl)
{
	t_gnl			*tmp;

	tmp = *gnl;
	while (tmp->fd != fd && tmp->next)
		tmp = tmp->next;
	if (tmp->fd == fd)
		return ((create_line(fd, line, tmp, gnl)));
	if ((tmp->next = malloc(sizeof(*tmp))) == NULL)
		return (-1);
	tmp->next->fd = fd;
	tmp->next->copy = NULL;
	tmp->next->next = NULL;
	tmp->next->prev = tmp;
	return ((create_line(fd, line, tmp->next, gnl)));
}
コード例 #7
0
void fileparse(unsigned int num_rows){

  char search_phrase[] = "AdeptProject";
  size_t sp_len = strlen(search_phrase);

  unsigned int desired_line_len = 81;
  char line[desired_line_len];

  srand(time(NULL)); // Set seed

  int i = 0;
  int r = 0;
  int m = 0;
  int mismatch = 0;
  int r_count = 0;
  int m_count = 0;
  struct timespec start, end;

  FILE* fp;
  fp = fopen("testfile", "w+");

  for (i=0;i<num_rows;i++){
    r = create_line(search_phrase, sp_len, line, desired_line_len);
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (r!=m){
      mismatch++;
    }
    if (r==0){
      r_count++;
    }
    fprintf(fp, "%s\n", line);
  }
  fsync(fileno(fp));
  fclose(fp);

  m=0;

  /* As an example, here we initialise the library, and then start measurements. */
  rapl_init();
  rapl_start();
  clock_gettime(CLOCK, &start);
  fp = fopen("testfile", "r");
  while (fscanf(fp, "%s\n", line)!=EOF){
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (m==0){
      m_count++;
    }
  }
  fclose(fp);
  clock_gettime(CLOCK, &end);
  rapl_end();
  rapl_deinit();
  /* And then we finish the meausurements and free the library */
  elapsed_time_hr(start, end, "Fileparse");

  unlink("testfile"); // Use this to ensure the generated file is removed from the system upon finish

}
コード例 #8
0
ファイル: parse_instr.c プロジェクト: ethanke/Corewar
void	create_corline_wl(t_corline tmp, t_corline *corline, op_t op)
{
  op = checkOp(tmp.args[0]);
  tmp.instruction = op.mnemonique;
  tmp.nbr = count_args(tmp.args);
  tmp.tab_args = get_args(tmp.args + 1, -1);
  tmp.mempos = calc_mem_pos(&tmp, corline);
  tmp.label = NULL;
  create_line(corline, tmp);
}
コード例 #9
0
ファイル: pager.c プロジェクト: Distrotech/slang
static int read_file (char *file)
{
   FILE *fp;
   char buf [1024];
   File_Line_Type *line, *last_line;
   unsigned int num_lines;

   if (file == NULL)
     fp = stdin;
   else fp = fopen (file, "r");

   if (fp == NULL) return -1;

   last_line = NULL;
   num_lines = 0;

   while (NULL != fgets (buf, sizeof(buf), fp))
     {
	num_lines++;

	if (NULL == (line = create_line (buf)))
	  {
	     fprintf (stderr, "Out of memory.");
	     free_lines ();
	     return -1;
	  }

	if (last_line == NULL)
	  File_Lines = line;
	else
	  last_line->next = line;

	line->prev = last_line;
	line->next = NULL;

	last_line = line;
     }

   memset ((char *)&Line_Window, 0, sizeof (SLscroll_Window_Type));

   Line_Window.current_line = (SLscroll_Type *) File_Lines;
   Line_Window.lines = (SLscroll_Type *) File_Lines;
   Line_Window.line_num = 1;
   Line_Window.num_lines = num_lines;
   /* Line_Window.border = 3; */

   return 0;
}
コード例 #10
0
ファイル: e_tangent.c プロジェクト: Reborn-s/Experiment
static void
tangent_normal_line(int x, int y, float vx, float vy)
{
    int dx, dy, xl, yl, xr, yr;
    F_line	   *line;
 
    dx = round(vx);
    dy = round(vy);   

    xl = x - dx;
    yl = y - dy;
    xr = x + dx;
    yr = y + dy;

    if ((first_point = create_point()) == NULL) 
        return;
    cur_point = first_point;
    first_point->x = xl;
    first_point->y = yl;
    first_point->next = NULL;
    append_point(x, y, &cur_point);
    append_point(xr, yr, &cur_point);
    
    if ((line = create_line()) == NULL)
        return; /* an error occured */
    line->type = T_POLYLINE;
    line->style = cur_linestyle;
    line->thickness = cur_linewidth;
    line->pen_color = cur_pencolor;
    line->fill_color = cur_fillcolor;
    line->depth = cur_depth;
    line->pen_style = -1;
    line->join_style = cur_joinstyle;
    line->cap_style = cur_capstyle;
    line->fill_style = cur_fillstyle;
    line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
    line->points = first_point;
		/* polyline; draw any arrows */
    if (autoforwardarrow_mode)
	line->for_arrow = forward_arrow();
    /* arrow will be drawn in draw_line below */
    if (autobackwardarrow_mode)
	line->back_arrow = backward_arrow();
    /* arrow will be drawn in draw_line below */
    draw_line(line, PAINT);	/* draw final */
    add_line(line);
    toggle_linemarker(line);
}
コード例 #11
0
ファイル: parse_instr.c プロジェクト: ethanke/Corewar
void	create_corline_l(t_corline tmp, t_corline *corline,
			 t_corlabel *corlabel, op_t op)
{
  t_corlabel	label;

  op = checkOp(tmp.args[1]);
  tmp.instruction = op.mnemonique;
  tmp.nbr = count_args(tmp.args);
  tmp.tab_args = get_args(tmp.args + 2, -1);
  tmp.mempos = calc_mem_pos(&tmp, corline);
  tmp.label = line_is_label(tmp.args[0]);
  label.mempos = tmp.mempos;
  label.name = tmp.label;
  create_label(corlabel, label);
  create_line(corline, tmp);
}
コード例 #12
0
ファイル: get_next_line.c プロジェクト: gbourgeo/42projects
int			get_next_line(int const fd, char **line)
{
	static t_gnl		*gnl = NULL;

	if (fd >= 0 && line != NULL && BUFF_SIZE > 0)
	{
		if (gnl == NULL)
		{
			gnl = malloc(sizeof(*gnl));
			if (gnl == NULL)
				return (-1);
			gnl->fd = fd;
			gnl->copy = NULL;
			gnl->next = NULL;
			gnl->prev = NULL;
			return ((create_line(fd, line, gnl, &gnl)));
		}
		return (check_struct(fd, line, &gnl));
	}
	return (-1);
}
コード例 #13
0
ファイル: parse.c プロジェクト: BackupTheBerlios/portsman
/* parses a file and returns a list, where each item is
   a line of the file */
List *
parse_file(char *filepath) {
   FILE *fd;
   char line[MAX_COLS];
   List *l;

   if ((fd = fopen(filepath, "r")) == NULL)
      return NULL; /* error */

   /* init */
   l = (List *)malloc(sizeof(List));
   l->head = NULL;
   l->tail = NULL;
   l->num_of_items = 0;

   while (fgets(line, MAX_COLS, fd) != NULL) 
      add_list_item(l, create_line(line));

   fclose(fd);
 
   return l;
}
コード例 #14
0
ファイル: fileparse.c プロジェクト: EPCCed/adept-kernel-mpi
void fileparse(unsigned int num_rows) {

    int world_size, world_rank;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);


    char search_phrase[] = "AdeptProject";
    size_t sp_len = strlen(search_phrase);

    unsigned int desired_line_len = 81;
    char line[desired_line_len];

    srand(time(NULL)); // Set seed

    int i = 0;
    int r = 0;
    int m = 0;
    int mismatch = 0;
    int r_count = 0;
    int m_count = 0;
    struct timespec start, end;

    /* p_num_rows is the number of rows across all processes */
    unsigned int p_num_rows;
    p_num_rows = (unsigned int) (num_rows * world_size);


    /* Generate (on the fly) the test file for the run */
    /* Make this single threaded for ease */
    if (world_rank == 0) {
        FILE* fp;
        fp = fopen("testfile", "w+");

        for (i = 0; i < p_num_rows; i++) {
            r = create_line(search_phrase, sp_len, line, desired_line_len);
            m = seek_match(search_phrase, sp_len, line, desired_line_len);
            if (r != m) {
                mismatch++;
            }
            if (r == 0) {
                r_count++;
            }
            if (m == 0) {
                m_count++;
            }
            fprintf(fp, "%s\n", line);
        }
        fsync(fileno(fp));
        fclose(fp);

    }

    m = 0;


    MPI_Info info;
    MPI_Info_create(&info);
    MPI_File fh;
    MPI_Status status;

    /* For holding the data from the file before parsing */
    char *lb = (char*) malloc(sizeof (char)*num_rows * (desired_line_len + 1));
    char *lbp = NULL;


    MPI_Barrier(MPI_COMM_WORLD);
    if (world_rank == 0) {
        clock_gettime(CLOCK, &start);
    }
    m_count = 0;

    /* This part should use MPI-IO */
    MPI_File_open(MPI_COMM_WORLD, "testfile", MPI_MODE_RDWR | MPI_MODE_CREATE, info, &fh);
    MPI_File_read_at(fh, world_rank * num_rows * (desired_line_len + 1), lb, num_rows * (desired_line_len + 1), MPI_CHAR, &status);
    for (i = 0; i < num_rows; i++) {
        lbp = &lb[i * (desired_line_len + 1)];
        m = seek_match(search_phrase, sp_len, lbp, desired_line_len);
        if (m == 0) {
            m_count++;
        }
    }
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_File_close(&fh);

    if (world_rank == 0) {
        clock_gettime(CLOCK, &end);
        elapsed_time_hr(start, end, "Fileparse");
    }
    MPI_Barrier(MPI_COMM_WORLD);
    unlink("testfile"); // Use this to ensure the generated file is removed from the system upon finish

}
コード例 #15
0
ファイル: line.c プロジェクト: ntufar/yargitay
/*---------------------------------------------------------------------------*/
line* text2lines_old( char* text ) { /* an old version */
/* Just a simple implementation waiting for improvements! */
	int len;
	int i;
	char* b;
	char* b1;
	char* s;
	line* res = 0;
	int c;
	char* dup;
	
	if ( !(*text) ) { /* Line is empty */
		return create_line("");
	}

	dup = strdup( text );
	s = dup;
	
	while ( *s ) {
		len = strlen( s );
		if ( len < 77 ) {
			res = append_line( res, create_line( s ) );
			break;
		}			
		b = s + 78;
		if ( *b!=' ' ) {
			c = *b;
			*b = 0;
			b1 = strrchr( s, ' ' );
			*b = c;
			
			if ( !b1 ) { /* it's a one long word */
				c = *(b-1);
				*(b-1) = 0;
				res = append_line( res, create_line( s ) );
				/* strcat( res->text, "-" ); */
				*(b-1) = c;
				s = b-1;
				continue;
			}
			
			c=*(b1+1);
			
			*(b1+1) = 0;
			res = append_line( res, create_line( s ) );
			*(b1+1) = c;
			s = b1+1;
			continue;
		}
		c = *(b+1);
		*(b+1) = 0;
		res = append_line( res, create_line( s ) );
		*(b+1) = c;
		s = b+1;
	}
	
	while ( res->prev )
		res = res->prev;
		
	free( dup );
		
	return res;
}
コード例 #16
0
ファイル: main.c プロジェクト: amineamanzou/LittleDB
int
main (void)
{
	char* requete;
	query* q=NULL;
	line* ligne= create_line(7);;
	data *d;

	system("clear");

	printf(" Test et simultation d'une session d'utilisation de littleBD avec un pronpteur \n");
	printf(" Exercice 1 : Comprehension LOAD SAVE EXIT SELECT * FROM Table \n\n");

	requete = "LOAD basededonnee.sql";
	testfusion(requete,q);
	
	requete = "LOAD basededonnee.sql.old";
	testfusion(requete,q);
	printf(" /*prise en charge des fichiers.old */ \n");
	
	pause();

	requete = "SAVE";
	testfusion(requete,q);
	
	requete = "EXIT";
	testfusion(requete,q);

	requete = "SELECT * FROM Table";
	testfusion(requete,q);

	pause();
	
	printf(" Exercice 2 : Fusion de query et de la structure \n\n");
	printf(" Requete implemente CREATE TABLE \n");

	requete = "CREATE TABLE toto ( id INT, ville CHAR)";
	testfusion(requete,q);

	printf(" Comprehenion et restitution des autres requetes : \n");

	requete = "DELETE FROM toto WHERE id = '1'";
	testfusion(requete,q);

	requete = "INSERT INTO toto ( id , ville ) VALUES ( 1 , 'c' )";
	testfusion(requete,q);

	pause();
	
	requete = "DROP TABLE toto";
	testfusion(requete,q);
	
	requete = "SELECT id FROM toto WHERE ! ( id > 1 AND c = 'c' )";
	testfusion(requete,q);

	pause();

	printf(" Exercice 3.1 : Effacer une ligne \n\n");
	printf(" Create Line ( 7 ) \n");
	print_line (ligne);
	
	printf(" Remplissage de la ligne ... \n");
	d=makeInt(1);
	update_line(ligne,*d,1);
	d=makeCar('c');
	update_line(ligne,*d,2);
	d=makeInt(345);
	update_line(ligne,*d,3);
	d=makeInt(2113);
	update_line(ligne,*d,4);
	d=makeInt(303);
	update_line(ligne,*d,6);
	
	print_line(ligne);
	printf("\n Deleteline \n");
	delete_line(ligne);
	print_line(ligne);
	
	
	return EXIT_SUCCESS;
}
コード例 #17
0
ファイル: wall.cpp プロジェクト: evg123/walkabout
list<Wall*> Wall::add_door(int startX, int startY, int endX, int endY)
{
	return create_line(startX, startY, endX, endY, TYPE_DOOR);
}
コード例 #18
0
ファイル: e_convert.c プロジェクト: Reborn-s/Experiment
void
spline_line(F_spline *s)
{
    F_line	   *l;
    F_point        *tmppoint;

    /* Now we turn s into a line */
    if ((l = create_line()) == NULL)
	return;

    if (open_spline(s)) {
	l->type = T_POLYLINE;
	l->points = s->points;
    } else {
	l->type = T_POLYGON;
	if ((l->points = create_point())==NULL)
	    return;
	tmppoint = last_point(s->points);
	l->points->x = tmppoint->x;
	l->points->y = tmppoint->y;
	l->points->next = copy_points(s->points);
    }
    l->style = s->style;
    l->thickness = s->thickness;
    l->pen_color = s->pen_color;
    l->fill_color = s->fill_color;
    l->depth = s->depth;
    l->style_val = s->style_val;
    l->cap_style = s->cap_style;
    l->join_style = cur_joinstyle;
    l->pen_style = s->pen_style;
    l->radius = DEFAULT;
    l->fill_style = s->fill_style;
    if (s->for_arrow) {
	l->for_arrow = create_arrow();
	l->for_arrow->type = s->for_arrow->type;
	l->for_arrow->style = s->for_arrow->style;
	l->for_arrow->thickness = s->for_arrow->thickness;
	l->for_arrow->wd = s->for_arrow->wd;
	l->for_arrow->ht = s->for_arrow->ht;
    } else {
	l->for_arrow = NULL;
    }
    if (s->back_arrow) {
	l->back_arrow = create_arrow();
	l->back_arrow->type = s->back_arrow->type;
	l->back_arrow->style = s->back_arrow->style;
	l->back_arrow->thickness = s->back_arrow->thickness;
	l->back_arrow->wd = s->back_arrow->wd;
	l->back_arrow->ht = s->back_arrow->ht;
    } else {
	l->back_arrow = NULL;
    }

    /* now we have finished creating the line, we can get rid of the spline */
    delete_spline(s);

    /* and put in the new line */
    mask_toggle_linemarker(l);
    list_add_line(&objects.lines, l);
    redisplay_line(l);
    set_action_object(F_CONVERT, O_SPLINE);
    set_latestline(l);
    set_modifiedflag();
    return;
}
コード例 #19
0
ファイル: gui-printtext.c プロジェクト: svn2github/irssi
static void gui_printtext(WINDOW_REC *window, gpointer fgcolor, gpointer bgcolor, gpointer pflags, char *str, gpointer level)
{
	GUI_WINDOW_REC *gui;
	LINE_REC *line;
	int fg, bg, flags, new_lines, n, visible, ypos, subline;

	g_return_if_fail(window != NULL);

	remove_old_lines(window);

	gui = WINDOW_GUI(window);
	visible = is_window_visible(window) && gui->bottom;
	flags = GPOINTER_TO_INT(pflags);
	fg = GPOINTER_TO_INT(fgcolor);
	bg = GPOINTER_TO_INT(bgcolor);

	if (gui->cur_text == NULL)
		create_text_chunk(gui);

	/* \n can be only at the start of the line.. */
	if (*str == '\n') {
		str++;
		linebuf_add(gui, "\0\x80", 2); /* mark EOL */

		line = create_line(gui, 0);
		gui_window_newline(gui, visible);

		gui->cur_text->lines++;
		gui->last_subline = 0;
	} else {
		line = gui->cur_line != NULL ? gui->cur_line :
			create_line(gui, 0);
		if (line->level == 0) line->level = GPOINTER_TO_INT(level);
	}

	get_colors(flags, &fg, &bg);
	line_add_colors(gui, fg, bg, flags);
	linebuf_add(gui, str, strlen(str));
	mark_temp_eol(gui->cur_text);

	gui_window_cache_remove(gui, line);
	new_lines = gui_window_get_linecount(gui, line)-1 - gui->last_subline;

	for (n = 0; n < new_lines; n++)
		gui_window_newline(gui, visible);

	if (visible) {
		/* draw the line to screen. */
                ypos = gui->ypos-new_lines;
		if (new_lines > 0) {
			set_color(0);
			move(gui->parent->first_line+ypos, 0); clrtoeol();
		}

		if (ypos >= 0)
			subline = gui->last_subline;
		else {
			/* *LONG* line - longer than screen height */
			subline = -ypos+gui->last_subline;
			ypos = 0;
		}
		ypos += gui->parent->first_line;
		gui_window_line_draw(gui, line, ypos, subline, -1);
	}

	gui->last_subline += new_lines;
}
コード例 #20
0
ファイル: gui-printtext.c プロジェクト: svn2github/irssi
static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
			       void *bgcolor, void *pflags,
			       char *str, void *level)
{
	GUI_WINDOW_REC *gui;
	LINE_REC *line;
	int fg, bg, flags, new_lines, n, visible, ypos, subline;

	flags = GPOINTER_TO_INT(pflags);
	fg = GPOINTER_TO_INT(fgcolor);
	bg = GPOINTER_TO_INT(bgcolor);
	get_colors(flags, &fg, &bg);

	if (window == NULL && next_xpos != -1) {
		wmove(stdscr, next_ypos, next_xpos);
		set_color(stdscr, fg | (bg << 4));
                addstr(str);
		next_xpos += strlen(str);
                return;
	}

	g_return_if_fail(window != NULL);

	gui = WINDOW_GUI(window);
	visible = is_window_visible(window) && gui->bottom;

	if (gui->cur_text == NULL)
		create_text_chunk(gui);

	/* newline can be only at the start of the line.. */
	if (flags & PRINTFLAG_NEWLINE) {
		remove_old_lines(window);
		if (!gui->eol_marked) {
			if (format->len > 0 || gui->temp_line != NULL) {
				/* mark format continuing to next line */
				char tmp[2] = { 0, (char)LINE_CMD_FORMAT_CONT };
				linebuf_add(gui, tmp, 2);
			}
			linebuf_add(gui, "\0\200", 2); /* mark EOL */
		}
		gui->eol_marked = FALSE;

                line = create_line(gui, 0);
		if (gui->temp_line == NULL ||
		    g_list_find(gui->startline, gui->temp_line) != NULL)
                        gui_window_newline(gui, visible);

		gui->last_subline = 0;
	} else {
		line = gui->temp_line != NULL ? gui->temp_line :
			gui->cur_line != NULL ? gui->cur_line :
			create_line(gui, 0);
		if (line->level == 0) line->level = GPOINTER_TO_INT(level);
	}

	line_add_colors(gui, fg, bg, flags);
	linebuf_add(gui, str, strlen(str));
	mark_temp_eol(gui->cur_text);

	gui_window_cache_remove(gui, line);

	if (gui->temp_line != NULL) {
		/* updating existing line - don't even
		   try to print it to screen */
		return;
	}

	new_lines = gui_window_get_linecount(gui, line)-1 - gui->last_subline;

	for (n = 0; n < new_lines; n++)
		gui_window_newline(gui, visible);

	if (visible) {
		/* draw the line to screen. */
                ypos = gui->ypos-new_lines;
		if (new_lines > 0) {
#ifdef USE_CURSES_WINDOWS
			set_color(gui->parent->curses_win, 0);
			wmove(gui->parent->curses_win, ypos, 0);
			wclrtoeol(gui->parent->curses_win);
#else
			set_color(stdscr, 0);
			move(ypos + gui->parent->first_line, 0);
			wclrtoeol(stdscr);
#endif
		}

		if (ypos >= 0)
			subline = gui->last_subline;
		else {
			/* *LONG* line - longer than screen height */
			subline = -ypos+gui->last_subline;
			ypos = 0;
		}
		gui_window_line_draw(gui, line, ypos, subline, -1);
	}

	gui->last_subline += new_lines;
}
コード例 #21
0
ファイル: wall.cpp プロジェクト: evg123/walkabout
list<Wall*> Wall::add_wall(int startX, int startY, int endX, int endY)
{
	return create_line(startX, startY, endX, endY, TYPE_WALL);
}
コード例 #22
0
void fileparse(unsigned int num_rows){

	char search_phrase[] = "AdeptProject";
	size_t sp_len = strlen(search_phrase);

	unsigned int desired_line_len = 81;
	char line[desired_line_len];

	srand(time(NULL)); // Set seed

	int i = 0;
	int r = 0;
	int m = 0;
	int stop=0, tn;
	int mismatch = 0;
	int r_count = 0;
	int m_count = 0;
	struct timespec start, end;

	FILE* fp;
	fp = fopen("testfile", "w+");

	for (i=0;i<num_rows;i++){
		r = create_line(search_phrase, sp_len, line, desired_line_len);
		m = seek_match(search_phrase, sp_len, line, desired_line_len);
		if (r!=m){
			mismatch++;
		}
		if (r==0){
			r_count++;
		}
		fprintf(fp, "%s\n", line);
	}
	fsync(fileno(fp));
	fclose(fp);

	m=0;

	clock_gettime(CLOCK, &start);
	fp = fopen("testfile", "r");

	// Threaded version of while loop
#pragma omp parallel reduction(+:m_count)

	while (!stop){

		// Critical section to evaluate stopping criterion and flush outcome
#pragma omp critical
		if (fscanf(fp, "%s\n", line)==EOF){
			stop=1;
#pragma omp flush(stop)
		}
		else{
			m = seek_match(search_phrase, sp_len, line, desired_line_len);
			if (m==0){
				m_count++;
			}
		}
	}

	fclose(fp);
	clock_gettime(CLOCK, &end);
	elapsed_time_hr(start, end, "Fileparse");

	unlink("testfile"); // Use this to ensure the generated file is removed from the system upon finish

}
コード例 #23
0
ファイル: d_line.cpp プロジェクト: coliveira/xfignew
void
create_lineobject(int x, int y)
{
    F_line	   *line;
    F_compound	   *comp;
    int		    dot;

    if (num_point == 0) {
	if ((first_point = create_point()) == NULL) {
	    line_drawing_selected();
	    draw_mousefun_canvas();
	    return;
	}
	cur_point = first_point;
	first_point->x = fix_x = cur_x = x;
	first_point->y = fix_y = cur_y = y;
	first_point->next = NULL;
	num_point++;
    } else if (x != fix_x || y != fix_y) {
	get_intermediatepoint(x, y, 0);
    }
    /* dimension line must have 2 different points */
    if (dimension_line && first_point->x == x && first_point->y == y)
	return;

    dot = (num_point == 1);
    elastic_line();
    /* erase any length info if appres.showlengths is true */
    erase_lengths();
    if ((line = create_line()) == NULL) {
	line_drawing_selected();
	draw_mousefun_canvas();
	return;
    }
    line->type = T_POLYLINE;
    line->style = cur_linestyle;
    line->thickness = cur_linewidth;
    line->pen_color = cur_pencolor;
    line->fill_color = cur_fillcolor;
    line->depth = cur_depth;
    line->pen_style = -1;
    line->join_style = cur_joinstyle;
    line->cap_style = cur_capstyle;
    line->fill_style = cur_fillstyle;
    line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
    line->points = first_point;
    if (!dot) {
	if (cur_mode == F_POLYGON) {	/* close off polygon */
	    line->type = T_POLYGON;
	    num_point++;
	    append_point(first_point->x, first_point->y, &cur_point);
	    elastic_line();
	    fix_x = first_point->x;
	    fix_y = first_point->y;
	    elastic_line();	/* fix last elastic line */
	} else {		/* polyline; draw any arrows */
	    if (autoforwardarrow_mode && !dimension_line)
		line->for_arrow = forward_arrow();
	    /* arrow will be drawn in draw_line below */
	    if (autobackwardarrow_mode && !dimension_line)
		line->back_arrow = backward_arrow();
	    /* arrow will be drawn in draw_line below */
	}
	cur_x = fix_x;
	cur_y = fix_y;
	elastic_moveline(first_point);	/* erase temporary outline */
    }
    if (dimension_line) {
	comp = create_dimension_line(line, True);
	reset_action_on(); /* this signals redisplay_curobj() not to refresh */
	/* draw it and anything on top of it */
	redisplay_compound(comp);
    } else {
	add_line(line);
	reset_action_on(); /* this signals redisplay_curobj() not to refresh */
	/* draw it and anything on top of it */
	redisplay_line(line);
    }
    line_drawing_selected();
    if (!edit_remember_dimline_mode)
	draw_mousefun_canvas();
}
コード例 #24
0
ファイル: object.cpp プロジェクト: ssj-proj/network
void create_object (object *o){
  o = (object*)malloc(sizeof(object));
  create_line(&o->object_body);
}