예제 #1
0
파일: add_links.c 프로젝트: KCHETTY/Lem_in
void	add_links(t_glob *g)
{
	int i;
	int	links;

	g->tmp = NULL;
	i = 0;
	while (i < g->num_rooms)
	{
		links = get_link_num(g, g->rooms[i]->room_name);
		g->rooms[i]->num_links = links;
		write_links(g, links, i);
		g->tmp = NULL;
		i++;
	}
	if (g->hey == 0)
		error();
}
예제 #2
0
파일: main.c 프로젝트: energyfive/sc-core
static
int	write_tgf(int fd_out)
{
	tgf_stream_out *s;
	int i,rv;
	tgf_argument args[3];
	tgf_command cmd;

	cmd.arguments = args;

	s = tgf_stream_out_new();
	if (!s) {
		fprintf(stderr,"Internal error: cannot create tgf stream\n");
		return 7;
	}
	tgf_stream_out_fd(s,fd_out);
	tgf_stream_out_start(s,"parsed");

	/* phase 0.5 remove $ identifiers */
	for (i=0;i<sctext_size;i++) {
		if (!sctext[i].id || sctext[i].id[0] == '/' || sctext[i].id[0] != '$')
			continue;
		free(sctext[i].id);
		sctext[i].id = 0;
	}

	/* phase 1 write elements */
	rv = 0;
	cmd.type = TGF_GENEL;
	args[0].type = TGF_STRING;
	args[1].type = TGF_SCTYPE;
	for (i=0;i<sctext_size && rv>=0 ;i++) {
		int release_flag = 0;
		char *file_cont = 0;
		int file_size;

		if (sctext[i].alias >= 0 || sctext[i].hidden)
			continue;
		if (sctext[i].id && sctext[i].id[0] == '/')
			continue;
		cmd.arg_cnt = 2;
		args[0].arg.a_string = sctext[i].id;
		args[1].arg.a_sctype = get_tgf_type(sctext[i].type);
		if (sctext[i].cont_type) {
			switch (sctext[i].cont_type) {
			case CONT_STRING:
				args[2].arg.a_string = sctext[i].str;
				args[2].type = TGF_STRING;
				cmd.arg_cnt = 3;
				break;
			case CONT_NUMERIC:
				args[2].arg.a_float = sctext[i].real;
				args[2].type = TGF_FLOAT;
				cmd.arg_cnt = 3;
				break;
			case CONT_DATA:
				args[2].arg.a_data = sctext[i].str;
				args[2].data_len = sctext[i].datalen;
				args[2].type = TGF_DATA;
				cmd.arg_cnt = 3;
				break;
			case CONT_FILE:
				file_size = get_file_size(sctext[i].str);
				if (file_size<0) {
					printf("File %s doesn't exist\n",sctext[i].str);
					return 100;
				}
				file_cont = malloc(file_size);
				if (!file_cont)
					abort();
				release_flag = 1;
				if (read_cont_file(sctext[i].str,file_cont,file_size)) {
					printf("Cannot read file %s\n",sctext[i].str);
					return 101;
				}
				args[2].arg.a_data = file_cont;
				args[2].data_len = file_size;
				args[2].type = TGF_DATA;
				cmd.arg_cnt = 3;
			}
		}
		if (!s)
			abort();
		rv = tgf_write_command(s,&cmd,TGF_I2P(i+1));
		if (release_flag)
			free(file_cont);
	}
	/* phase 1.5 write "links" */
	if (rv<0 || (rv = write_links(s))) {
		fprintf(stderr,"Internal error: tgf error: %s\n",tgf_error(rv));
		return 8;
	}
	/* phase 2 write connections */
	cmd.arg_cnt = 2;
	args[0].type = TGF_USERID;
	args[1].type = TGF_USERID;
	rv = 0;
	for (i=0;i<sctext_size && rv >= 0;i++) {
		if (sctext[i].alias >= 0 || sctext[i].hidden)
			continue;
		if (!(sctext[i].type & SC_ARC))
			continue;
		if (sctext[i].beg >= 0) {
			cmd.type = TGF_SETBEG;
			args[0].type = TGF_USERID;
			args[1].type = TGF_USERID;
			args[0].arg.a_userid = TGF_I2P(i+1);
			args[1].arg.a_userid = get_tgf_ref(sctext[i].beg);
			rv = tgf_write_command(s,&cmd,0);
			if (rv<0)
				break;
		}
		if (sctext[i].end >= 0) {
			cmd.type = TGF_SETEND;
			args[0].type = TGF_USERID;
			args[1].type = TGF_USERID;
			args[0].arg.a_userid = TGF_I2P(i+1);
			args[1].arg.a_userid = get_tgf_ref(sctext[i].end);
			rv = tgf_write_command(s,&cmd,0);
		}
	}
	if (rv<0) {
		fprintf(stderr,"Internal error: tgf error: %s\n",tgf_error(rv));
		return 8;
	}
	rv = tgf_stream_out_finish(s);
	if (rv<0) {
		fprintf(stderr,"Internal error: tgf error: %s\n",tgf_error(rv));
		return 8;
	}
	tgf_stream_out_destroy(s);
	return 0;
}