Exemplo n.º 1
0
static int			ft_concat_buff(char **line, char *buff, int ret, int fd)
{
	char			*cpy;

	if (!ft_strchr(buff, '\n'))
	{
		*line = ft_strdup_gnl(buff);
		if ((ret = read(fd, buff, BUFF_SIZE)) == -1)
			return (-1);
		if (!ret)
			return (0);
		buff[ret] = '\0';
		free_line(&cpy, line, buff);
		while (!ft_strchr(buff, '\n') && ret)
		{
			offset_adress(buff);
			if ((ret = read(fd, buff, BUFF_SIZE)) == -1)
				return (-1);
			if (!ret)
				return (0);
			buff[ret] = '\0';
			free_line(&cpy, line, buff);
		}
		offset_adress(buff);
	}
	return (1);
}
Exemplo n.º 2
0
void load_conffile(void)
{
	FILE *f;
	char *confdir = NULL;
	char *head;

	if (loaded)
		return;
	if (conffile == NULL) {
		conffile = DefaultConfFile;
		confdir = DefaultConfDir;
	}

	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
	} else if (strcmp(conffile, "none") != 0) {
		f = fopen(conffile, "r");
		/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
		 * To allow Debian users to compile from clean source and still
		 * have a working mdadm, we read /etc/mdadm/mdadm.conf
		 * if /etc/mdadm.conf doesn't exist
		 */
		if (f == NULL &&
		    conffile == DefaultConfFile) {
			f = fopen(DefaultAltConfFile, "r");
			if (f) {
				conffile = DefaultAltConfFile;
				confdir = DefaultAltConfDir;
			}
		}
		if (f) {
			conf_file_or_dir(f);
			fclose(f);
		}
		if (confdir) {
			f = fopen(confdir, "r");
			if (f) {
				conf_file_or_dir(f);
				fclose(f);
			}
		}
	}
	/* If there was no AUTO line, process an empty line
	 * now so that the MDADM_CONF_AUTO env var gets processed.
	 */
	head = dl_strdup("AUTO");
	dl_init(head);
	autoline(head);
	free_line(head);

	loaded = 1;
}
Exemplo n.º 3
0
baf_block *baf_next_block(zfp *fp) {
    line_t *l;
    baf_block *b;
    int order = 0;

    if (NULL == (l = get_line(fp, NULL))) {
	/* Empty block */
	return NULL;
    }
    if (NULL == (b = (baf_block *)calloc(1, sizeof(*b))))
	return NULL;

    b->type = l->type;
    b->h = HacheTableCreate(0, HASH_DYNAMIC_SIZE | HASH_ALLOW_DUP_KEYS);
    b->h->name = "baf-block";

    do {
	HacheData hd;
	
	if (l->type == XX) {
	    free_line(l);
	    break;
	}

	l->order = order++;
	hd.p = l;
	HacheTableAdd(b->h, (char *)&l->type, sizeof(l->type), hd, NULL);
    } while (l = get_line(fp, NULL));

    return b;
}
Exemplo n.º 4
0
void
where_is (char * name)
{
  struct line seqname;
  int vec;
  int code;
  struct cmd_func * cmd;
  
  if (!find_function (&vec, &cmd, name, strlen(name)))
    code = cmd - the_funcs[vec];
  else if (map_id (name) >= 0)
    {
      code = map_id (name);
      vec = -1;
    }
  else
    io_error_msg ("%s is not a function.", name); /* no return */
  code = cmd - the_funcs[vec];
  init_line (&seqname);
  set_line (&seqname, "");
  
  if (!search_map_for_cmd (&seqname, the_cmd_frame->top_keymap, vec, code))
    io_info_msg ("%s is not on any keys.", name);
  else
    io_info_msg ("%s is bound to %s.", name, seqname.buf);
  
  free_line (&seqname);
}
Exemplo n.º 5
0
/* set maximum scrollback buffer size */
static void kmscon_buffer_set_max_sb(struct kmscon_buffer *buf,
					unsigned int max)
{
	struct line *line;

	if (!buf)
		return;

	while (buf->sb_count > max) {
		line = buf->sb_first;
		if (!line)
			break;

		buf->sb_first = line->next;
		if (line->next)
			line->next->prev = NULL;
		else
			buf->sb_last = NULL;
		buf->sb_count--;

		/* We treat fixed/unfixed position the same here because we
		 * remove lines from the TOP of the scrollback buffer.
		 */
		if (buf->position == line) {
			if (buf->sb_first)
				buf->position = buf->sb_first;
			else
				buf->position = NULL;
		}

		free_line(line);
	}

	buf->sb_max = max;
}
Exemplo n.º 6
0
static void elemstyle_free(elemstyle_t *elemstyle) {
  elemstyle_condition_t *cond;
  for (cond = elemstyle->condition; cond;) {
    if(cond->key)   xmlFree(cond->key);
    if(cond->value) xmlFree(cond->value);
    elemstyle_condition_t *prevcond = cond;
    cond = cond->next;
    g_free(prevcond);
  }

  switch(elemstyle->type) {
  case ES_TYPE_NONE:
    break;
  case ES_TYPE_LINE:
    free_line(elemstyle->line);
    break;
  case ES_TYPE_AREA:
    free_area(elemstyle->area);
    break;
  case ES_TYPE_LINE_MOD:
    free_line_mod(elemstyle->line_mod);
    break;
  }
  if(elemstyle->icon) free_icon(elemstyle->icon);
  g_free(elemstyle);
}
Exemplo n.º 7
0
static gboolean handle_client_receive(GIOChannel *c, GIOCondition condition, gpointer data)
{
	struct pending_client *pc = data;

	g_assert(c != NULL);

	if (condition & G_IO_IN) {
		if (pc->type == CLIENT_TYPE_UNKNOWN) {
			if (!handle_client_detect(c, pc)) {
				kill_pending_client(pc);
				return FALSE;
			}
		} else if (pc->type == CLIENT_TYPE_REGULAR) {
			GIOStatus status;
			GError *error = NULL;
			struct irc_line *l;

			while ((status = irc_recv_line(c, pc->listener->iconv, &error, &l)) == G_IO_STATUS_NORMAL) {
				gboolean ret;

				if (l == NULL)
					continue;

				ret = pc->listener->ops->handle_client_line(pc, l);

				free_line(l);

				if (!ret) {
					kill_pending_client(pc);
					return FALSE;
				}
			}

			if (status != G_IO_STATUS_AGAIN) {
				kill_pending_client(pc);
				if (error != NULL)
					g_error_free(error);
				return FALSE;
			}
		} else if (pc->type == CLIENT_TYPE_SOCKS) {
			gboolean ret = handle_client_socks_data(c, pc);
			if (!ret)
				kill_pending_client(pc);
			return ret;
		} else if (pc->type == CLIENT_TYPE_QUASSEL) {
			/* TODO: Quassel */
		} else {
			g_assert(0);
		}
	}

	if (condition & G_IO_HUP) {
		kill_pending_client(pc);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 8
0
END_TEST

void state_process(struct irc_network_state *ns, const char *line)
{
    struct irc_line *l;
    l = irc_parse_line(line);
    g_assert(l);
    g_assert(state_handle_data(ns, l));
    free_line(l);
}
Exemplo n.º 9
0
void			ft_sigint(void)
{
	tputs(tgetstr("do", NULL), 1, tputs_char);
	tputs(tgetstr("sc", NULL), 1, tputs_char);
	free_line(g_data->last->line);
	g_data->last->line = NULL;
	g_data->cursor = 0;
	g_data->nb_c = 0;
	print_list_char(g_data->last->line, g_data->cursor);
}
Exemplo n.º 10
0
int		recup_donnee(t_e *e)
{
	while (get_next_line(0, &e->line) > 0)
	{
		if (!(e->donne = push_back_lem1(e->donne, e->line)))
			return (0);
		free_line(&e->line);
	}
	return (1);
}
Exemplo n.º 11
0
void free_sparse_matrix(t_sparse_matrix *sm)
{
    int i;
    for (i = 0; i < SM_NBR_LINES(*sm); i++) {
	free_line(&SM_LINE(*sm, i));
    }
    free((*sm)->lines);
    free(*sm);
    *sm = NULL;
}
Exemplo n.º 12
0
int main()
{
    t_sm_line line = EMPTY_SM_LINE;
    t_sparse_matrix sm;


    display_line_nl(line);

    sm_line_set_value(&line, 5, 17);
    display_line_nl(line);

    sm_line_set_value(&line, 3, 27);
    display_line_nl(line);

    sm_line_set_value(&line, 7, 14);
    display_line_nl(line);

    sm_line_set_value(&line, 7, 27);
    display_line_nl(line);

    sm_line_set_value(&line, 3, 23);
    display_line_nl(line);

    sm_line_set_value(&line, 5, 25);
    display_line_nl(line);

    printf("%u\n", sm_line_get_value(line, 3));
    printf("%u\n", sm_line_get_value(line, 4));
    printf("%u\n", sm_line_get_value(line, 5));
    printf("%u\n", sm_line_get_value(line, 9));

    free_line(&line);


    printf("TEST SM\n");

    sm = new_sparse_matrix(20);

    printf("%u\n\n", sm_get_value(sm, 5, 10));

    sm_set_value(sm, 5, 10, 14);
    printf("%u\n", sm_get_value(sm, 5, 10));
    printf("%u\n\n", sm_get_value(sm, 5, 12));

    sm_set_value(sm, 5, 12, 15);
    sm_set_value(sm, 5, 8, 13);
    printf("%u\n", sm_get_value(sm, 5, 8));
    printf("%u\n", sm_get_value(sm, 5, 10));
    printf("%u\n", sm_get_value(sm, 5, 11));
    printf("%u\n", sm_get_value(sm, 5, 12));

    free_sparse_matrix(&sm);

    return 0;
}
Exemplo n.º 13
0
void
free_prog_text(struct line *l)
{
        struct line *next;

        while (l) {
                next = l->next;
                free_line(l);
                l = next;
        }
}
Exemplo n.º 14
0
void free_line(t_sm_line *line)
{
    if (IS_EMPTY_SM_LINE(*line)) {
	return ;
    } else {
	t_sm_line *next = &NEXT_SM_LINE(*line);
	free_node(&NODE_SM_LINE(*line));
	free_line(next);
	free(*line);
    }
}
Exemplo n.º 15
0
static void kmscon_buffer_free(struct kmscon_buffer *buf)
{
	unsigned int i;

	if (!buf)
		return;

	log_debug("destroying buffer object");
	kmscon_buffer_clear_sb(buf);

	for (i = 0; i < buf->scroll_y; ++i)
		free_line(buf->scroll_buf[i]);
	for (i = 0; i < buf->mtop_y; ++i)
		free_line(buf->mtop_buf[i]);
	for (i = 0; i < buf->mbottom_y; ++i)
		free_line(buf->mbottom_buf[i]);

	free(buf->scroll_buf);
	free(buf->mtop_buf);
	free(buf->mbottom_buf);
	free(buf);
}
Exemplo n.º 16
0
/*
 * Write the bytes in the buffer to the socket.
 * Takes a connection and returns the number of bytes written.
 */
ssize_t
write_buffer(int fd, struct buffer_s * buffptr)
{
	ssize_t bytessent;
	struct bufline_s *line;

	assert(fd >= 0);
	assert(buffptr != NULL);

	if (buffptr->size == 0)
		return 0;

	/* Sanity check. It would be bad to be using a NULL pointer! */
	assert(BUFFER_HEAD(buffptr) != NULL);
	line = BUFFER_HEAD(buffptr);

	bytessent =
	    send(fd, line->string + line->pos, line->length - line->pos, MSG_NOSIGNAL);

	if (bytessent >= 0) {
		/* bytes sent, adjust buffer */
		line->pos += bytessent;
		if (line->pos == line->length)
			free_line(remove_from_buffer(buffptr));
		return bytessent;
	} else {
		switch (errno) {
#ifdef EWOULDBLOCK
		case EWOULDBLOCK:
#else
#  ifdef EAGAIN
		case EAGAIN:
#  endif
#endif
		case EINTR:
			return 0;
		case ENOBUFS:
		case ENOMEM:
			log_message(LOG_ERR,
				    "writebuff: write() error [NOBUFS/NOMEM] \"%s\" on file descriptor %d",
				    strerror(errno), fd);
			return 0;
		default:
			log_message(LOG_ERR,
				    "writebuff: write() error \"%s\" on file descriptor %d",
				    strerror(errno), fd);
			return -1;
		}
	}
}
Exemplo n.º 17
0
/*
 * Delete all the lines in the buffer and the buffer itself
 */
void
delete_buffer(struct buffer_s *buffptr)
{
	struct bufline_s *next;

	assert(buffptr != NULL);

	while (BUFFER_HEAD(buffptr)) {
		next = BUFFER_HEAD(buffptr)->next;
		free_line(BUFFER_HEAD(buffptr));
		BUFFER_HEAD(buffptr) = next;
	}

	safefree(buffptr);
}
Exemplo n.º 18
0
/* deletes line n if one argument,
   lines arg1 -- arg2 if two arguments
   current line if no argument */
void
do_delete(dbref player, dbref program, int arg[], int argc)
{
	struct line *curr, *temp;
	char buf[BUFFER_LEN];
	int i;

	switch (argc) {
	case 0:
		arg[0] = PROGRAM_CURR_LINE(program);
	case 1:
		arg[1] = arg[0];
	case 2:
		/* delete from line 1 to line 2 */
		/* first, check for conflict */
		if (arg[0] > arg[1]) {
			notify(player, "Nonsensical arguments.");
			return;
		}
		i = arg[0] - 1;
		for (curr = PROGRAM_FIRST(program); curr && i; i--)
			curr = curr->next;
		if (curr) {
			PROGRAM_SET_CURR_LINE(program, arg[0]);
			i = arg[1] - arg[0] + 1;
			/* delete n lines */
			while (i && curr) {
				temp = curr;
				if (curr->prev)
					curr->prev->next = curr->next;
				else
					PROGRAM_SET_FIRST(program, curr->next);
				if (curr->next)
					curr->next->prev = curr->prev;
				curr = curr->next;
				free_line(temp);
				i--;
			}
			snprintf(buf, sizeof(buf), "%d lines deleted", arg[1] - arg[0] - i + 1);
			notify(player, buf);
		} else
			notify(player, "No line to delete!");
		break;
	default:
		notify(player, "Too many arguments!");
		break;
	}
}
Exemplo n.º 19
0
void baf_block_destroy(baf_block *b) {
    if (!b)
	return;

    if (b->h) {
	HacheIter *iter = HacheTableIterCreate();
	HacheItem *hi;
	while (hi = HacheTableIterNext(b->h, iter)) {
	    line_t *l = hi->data.p;
	    if (l) free_line(l);
	}
	HacheTableIterDestroy(iter);
	HacheTableDestroy(b->h, 0);
    }

    free(b);
}
Exemplo n.º 20
0
t_line		*delete_header(t_line *file, int size_header)
{
	t_line	*result;
	int		line;

	line = 0;
	while ((file = file->next))
		if (++line < size_header)
		{
			file->start = file;
			free_line(file->prev->line);
			ft_memdel((void **)&(file->prev));
		}
		else if ((result = file->prev->start))
			file->start = result;
	return (result);
}
Exemplo n.º 21
0
int				k_up(t_data *data, char key[KEY_LENGTH])
{
	if (ft_strcmp(key, "\x1b\x5b\x41\0\0\0") == 0)
	{
		if (data->history->prev != NULL)
		{
			clear_line(data);
			data->history = data->history->prev;
			data->nb_c = count_char(data->history->line);
			data->cursor = data->nb_c;
			free_line(data->last->line);
			data->last->line = copy_line(data->history->line);
		}
		return (1);
	}
	return (0);
}
Exemplo n.º 22
0
/* clear scrollback buffer */
static void kmscon_buffer_clear_sb(struct kmscon_buffer *buf)
{
	struct line *iter, *tmp;

	if (!buf)
		return;

	for (iter = buf->sb_first; iter; ) {
		tmp = iter;
		iter = iter->next;
		free_line(tmp);
	}

	buf->sb_first = NULL;
	buf->sb_last = NULL;
	buf->sb_count = 0;
	buf->position = NULL;
}
Exemplo n.º 23
0
Arquivo: read.c Projeto: fbonhomm/42sh
int					end_of_read(t_win *term)
{
	cur_motion_handler(DOWN, (term->all_act->cm->nb_line_tocm -
		term->all_act->cm->cur_pos_y_tocm) + 1);
	while (term->all_act->cm->prev != NULL)
		term->all_act->cm = term->all_act->cm->prev;
	if (term->all_save == NULL)
	{
		term->all_save = init_allcm();
		term->all_save->cm = cp_all_cmline(term->all_act->cm);
	}
	else
		add_allcm(&term->all_save, term->all_act->cm);
	term->all_save->nb_ch = term->all_act->nb_ch;
	free_line(&term->copy);
	free_allcm(&term->all_act);
	return (ENDOF);
}
Exemplo n.º 24
0
void flush_lines(int nflush)
{
	LINE *l;

	while (--nflush >= 0) {
		l = lines;
		lines = l->l_next;
		if (l->l_line) {
			flush_blanks();
			flush_line(l);
		}
		nblank_lines++;
		if (l->l_line)
			(void)free((void *)l->l_line);
		free_line(l);
	}
	if (lines)
		lines->l_prev = NULL;
}
Exemplo n.º 25
0
GIOStatus irc_send_args(GIOChannel *c, GIConv iconv,
						GError **error, ...)
{
	struct irc_line *l;
	GIOStatus ret;
	va_list ap;

	g_assert(c);

	va_start(ap, error);
	l = virc_parse_line(NULL, ap);
	va_end(ap);

	ret = irc_send_line(c, iconv, l, error);

	free_line(l);

	return ret;
}
Exemplo n.º 26
0
static void kmscon_buffer_scroll_down(struct kmscon_buffer *buf,
					unsigned int num)
{
	unsigned int i;

	if (!buf || !num)
		return;

	if (num > buf->scroll_y)
		num = buf->scroll_y;

	for (i = 0; i < num; ++i)
		free_line(buf->scroll_buf[buf->scroll_y - i - 1]);

	memmove(&buf->scroll_buf[num], buf->scroll_buf,
			(buf->scroll_y - num) * sizeof(struct line*));
	memset(buf->scroll_buf, 0, num * sizeof(struct line*));
	buf->scroll_fill = buf->scroll_y;
}
Exemplo n.º 27
0
static void
cancel_line(void)
{
    canvas_ref_proc = canvas_locmove_proc = null_proc;
    elastic_moveline(new_l->points);
    /* erase last lengths if appres.showlengths is true */
    erase_lengths();
    free_linkinfo(&cur_links);
    if (return_proc == copy_selected) {
	free_line(&new_l);
    } else {
	list_add_line(&objects.lines, new_l);
	redisplay_line(new_l);
    }
    /* turn back on all relevant markers */
    update_markers(new_objmask);
    (*return_proc) ();
    draw_mousefun_canvas();
}
Exemplo n.º 28
0
void conf_file(FILE *f)
{
	char *line;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case Devices:
			devline(line);
			break;
		case Array:
			arrayline(line);
			break;
		case Mailaddr:
			mailline(line);
			break;
		case Mailfrom:
			mailfromline(line);
			break;
		case Program:
			programline(line);
			break;
		case CreateDev:
			createline(line);
			break;
		case Homehost:
			homehostline(line);
			break;
		case AutoMode:
			autoline(line);
			break;
		case Policy:
			policyline(line, rule_policy);
			break;
		case PartPolicy:
			policyline(line, rule_part);
			break;
		default:
			pr_err("Unknown keyword %s\n", line);
		}
		free_line(line);
	}
}
Exemplo n.º 29
0
void policy_free(void)
{
	while (config_rules) {
		struct pol_rule *pr = config_rules;
		struct rule *r;

		config_rules = config_rules->next;

		for (r = pr->rule; r; ) {
			struct rule *next = r->next;
			free(r->value);
			if (r->dups)
				free_line(r->dups);
			free(r);
			r = next;
		}
		free(pr);
	}
	config_rules_end = NULL;
	config_rules_has_path = 0;
}
Exemplo n.º 30
0
GIOStatus irc_sendf(GIOChannel *c, GIConv iconv,
					GError **error, char *fmt, ...)
{
	va_list ap;
	char *r = NULL;
	struct irc_line *l;
	GIOStatus ret;

	g_assert(c);
	g_assert(fmt);

	va_start(ap, fmt);
	r = g_strdup_vprintf(fmt, ap);
	l = irc_parse_line(r);
	g_free(r);
	ret = irc_send_line(c, iconv, l, error);

	free_line(l);

	return ret;
}