Example #1
0
int main()
{
    int firstIndex, secondIndex;

    printf("Enter firstIndex and secondIndex: ");
    check_intInput(&firstIndex);
    check_intInput(&secondIndex);
    
    if (firstIndex <= 0 || secondIndex<= 0)
    {
        printf("Index > 0 !");
        exit(EXIT_FAILURE);
    }

    int firstArray[firstIndex];
    int secondArray[secondIndex];
    printf("Enter numbers : ");
    fill_array(firstArray, firstIndex);
    fill_array(secondArray, secondIndex);

    int uniqueElemet;
    int *joinArr = join_list(firstArray, firstIndex, secondArray, secondIndex, &uniqueElemet);

    bubble_sort(joinArr, uniqueElemet);

    print_array(joinArr, uniqueElemet);

    free(joinArr);

    return (EXIT_SUCCESS);
}
Example #2
0
File: ipc.c Project: Half-Shot/sway
char *json_list(list_t *items) {
	char *json_elements = join_list(items, ",");
	size_t len = strlen(json_elements);
	char *json = malloc(len + 3);
	json[0] = '[';
	memcpy(json + 1, json_elements, len);
	json[len+1] = ']';
	json[len+2] = '\0';
	free(json_elements);
	return json;
}
Example #3
0
File: stub.c Project: tamentis/mdp
static int
join_list_wrapper(char **av)
{
	const char sep = av[2][0];
	int count = atoi(av[3]);
	char *output;

	output = join_list(sep, count, av + 4);

	printf("%s\n", output);

	return EXIT_SUCCESS;
}
Example #4
0
File: cmd.c Project: tamentis/mdp
void
cmd_parse_add(int argc, char **argv)
{
	int opt;

	while ((opt = getopt(argc, argv, "hp:l:n:k:")) != -1) {
		switch (opt) {
		case 'h':
			cmd_usage_add();
			exit(EXIT_FAILURE);
		case 'p':
			cmd_profile_name = strdup(optarg);
			break;
		case 'l':
			cmd_character_count = strtoumax(optarg, NULL, 10);
			break;
		case 'n':
			cmd_password_count = strtoumax(optarg, NULL, 10);
			break;
		case 'k':
			cmd_gpg_key_id = strdup(optarg);
			break;
		default:
			exit(EXIT_FAILURE);
			break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc > 0) {
		char *s = join_list(' ', argc, argv);
		cmd_add_prefix = mbs_duplicate_as_wcs(s);
		if (cmd_add_prefix == NULL) {
			err(EXIT_FAILURE, "unable to read the prefix (wrong "
					"locale?)");
		}
		xfree(s);
	}
}
Example #5
0
void init_node(const char* p_name)
{
    struct tw_hostent* p_host;
    char* pa;
    int i;


//    pthread_mutex_lock(&mutex);

    if(find_record(p_name) == 1)
    {
        //printf("find a url:%s\n", p_name);
        p_host = (struct tw_hostent*)malloc(sizeof(struct tw_hostent));
        memcpy(p_host->name, p_name, 30);
        memcpy(p_host->file, p_name, 30);
        if ((pa = strchr(p_name, '.')) != NULL) {
            memcpy(p_host->key_word, pa + 1, 30);
        }
        p_host->is_dns = 0;
        p_host->is_url = 0;
        p_host->prev = NULL;
        p_host->next = NULL;
        p_host->id = head.sum;
        p_host->first = 0;
        hostent_index[p_host->id] = p_host;    
        for (i = 0; i < 100; i++) {
            p_host->ip[i] = malloc(4);
        }
        p_host->dns = NULL;

        query_dns(p_host);

        join_list(&p_host);    
    }
    
//    pthread_mutex_unlock(&mutex);
    return;

}
Example #6
0
List *xdap_late_read_header(void)
/*
**
*/
{
    List *files;
    List *details;

    files = file_details();
    details = db_details();

    return
        join_list(
            build_list(
                atom_str(db_from),
                nil),
            details,
            build_list(
                files,
                nil),
            nil);


}
Example #7
0
List *xdap_late_read_gel_data(void)
{
    List *gel_details;

    if (cur_gel_index > io.num_gels)
        gel_details = nil;
    else {
        bap_ar_file_rec ar_line;
        bap_rl_file_rec rl_line;
        bap_sq_file_rec sq_line;
        bap_tg_file_rec tg_line;

        int index;
        char name[17];
        char *seq;
        int length;
        int comp;
        int pos;
        int l_nbr;
        int r_nbr;

        sq_line = (char *) malloc(io.max_gel_length+1);

        bap_read_ar(&io,cur_gel_index,&ar_line);
        bap_read_rl(&io,cur_gel_index,&rl_line);
        bap_read_tg(&io,cur_gel_index,&tg_line);
        bap_read_sq(&io,cur_gel_index,sq_line);


        index = cur_gel_index;
        f2cstr(ar_line.lines.name,BAP_FILE_NAME_LENGTH,name,
               (size_t)BAP_FILE_NAME_LENGTH);
        length = abs(rl_line.lines.length);
        comp = (rl_line.lines.length < 0);
        seq = sq_line;
        seq[length] = '\0';
        pos = rl_line.lines.rel_pos;
        l_nbr = rl_line.lines.left_nbr;
        r_nbr = rl_line.lines.right_nbr;

        gel_details =
            build_list(
                atom_str(gel_rec),
                build_list(
                    atom_str(gel_index),
                    atom_int(index),
                    nil),
                build_list(
                    atom_str(gel_name),
                    atom_str(name),
                    nil),
                build_list(
                    atom_str(gel_length),
                    atom_int(length),
                    nil),
                build_list(
                    atom_str(gel_comp),
                    atom_int(comp),
                    nil),
                build_list(
                    atom_str(gel_seq),
                    atom_str(seq),
                    nil),
                build_list(
                    atom_str(gel_pos),
                    atom_int(pos),
                    nil),
                build_list(
                    atom_str(gel_l_nbr),
                    atom_int(l_nbr),
                    nil),
                build_list(
                    atom_str(gel_r_nbr),
                    atom_int(r_nbr),
                    nil),
                nil);



        /* Get raw data details */
        if (tg_line.lines.comment) {
            List *raw_data_details;

            char *rd;
            int rd_length;
            int rd_cut;
            int rd_ulen;
            char rd_type[5];
            char rd_file[19];

            rd = bap_read_comment(&io, tg_line.lines.comment);
            sscanf(rd,"%6d%6d%6d%*s",&rd_length, &rd_cut, &rd_ulen);
            f2cstr(&rd[18],4,rd_type,(size_t)4);
            f2cstr(&rd[22],18,rd_file,(size_t)18);


            raw_data_details =
                build_list(
                    build_list(
                        atom_str(gel_rd_length),
                        atom_int(rd_length),
                        nil),
                    build_list(
                        atom_str(gel_rd_cut),
                        atom_int(rd_cut),
                        nil),
                    build_list(
                        atom_str(gel_rd_ulen),
                        atom_int(rd_ulen),
                        nil),
                    build_list(
                        atom_str(gel_rd_type),
                        atom_str(rd_type),
                        nil),
                    build_list(
                        atom_str(gel_rd_file),
                        atom_str(rd_file),
                        nil),
                    nil);

            join_list (gel_details, raw_data_details, nil);

        }



        /*
        ** Process tags, maintaining separate lists for
        ** (a) special tags
        ** (b) annotation
        ** (c) edits
        */
        {
            List *specials;
            List *notes;
            List *edits;

            int_4 next;
            specials = nil;
            notes =
                build_list(
                    atom_str(gel_annotation),
                    nil);
            edits =
                build_list(
                    atom_str(gel_edits),
                    nil);

            while (tg_line.lines.next) {
                next = tg_line.lines.next;
                bap_read_tg(&io,next,&tg_line);

                if (strncmp(tg_line.lines.type.c,"*LC*",4)==0) {
                    if (tg_line.lines.comment) {
                        List *lc;
                        lc = build_list(
                                 atom_str(gel_l_cut_seq),
                                 atom_str(bap_read_comment(&io,tg_line.lines.comment)),
                                 nil);
                        if (isNil(specials))
                            specials = build_list(lc,nil);
                        else
                            specials = join_list(specials,build_list(lc,nil),nil);
                    }
                } else if (strncmp(tg_line.lines.type.c,"*RC*",4)==0) {
                    if (tg_line.lines.comment) {
                        List *rc;
                        rc = build_list(
                                 atom_str(gel_r_cut_seq),
                                 atom_str(bap_read_comment(&io,tg_line.lines.comment)),
                                 nil);
                        if (isNil(specials))
                            specials = build_list(rc,nil);
                        else
                            specials = join_list(specials,build_list(rc,nil),nil);
                    }
                } else if (strncmp(tg_line.lines.type.c,"*",1)==0) {
                    List *ed;
                    char base[2];
                    base[0] = tg_line.lines.type.c[3];
                    base[1] = '\0';
                    ed = build_list(
                             build_list(
                                 atom_str(gel_ed_op),
                                 atom_str( (strncmp(tg_line.lines.type.c,"*IN",3))==0
                                           ? gel_ed_insert : gel_ed_delete),
                                 nil),
                             build_list(
                                 atom_str(gel_ed_base),
                                 atom_str(base),
                                 nil),
                             build_list(
                                 atom_str(gel_ed_base_pos),
                                 atom_int( tg_line.lines.position ),
                                 nil),
                             nil);
                    edits = join_list(edits, build_list(ed,nil),nil);
                } else {
                    List *an;
                    char type[5];
                    char *com;
                    strncpy(type,tg_line.lines.type.c,4);
                    type[4]='\0';
                    com = bap_read_comment(&io,tg_line.lines.comment);
                    an = build_list(
                             build_list(
                                 atom_str(gel_an_pos),
                                 atom_int(tg_line.lines.position),
                                 nil),
                             build_list(
                                 atom_str(gel_an_len),
                                 atom_int(tg_line.lines.length),
                                 nil),
                             build_list(
                                 atom_str(gel_an_type),
                                 atom_str(type),
                                 nil),
                             (com == NULL) ? nil :
                             build_list(
                                 atom_str(gel_an_comment),
                                 atom_str(com),
                                 nil),
                             nil);
                    notes = join_list(notes,build_list(an,nil),nil);

                }
            }
            if (isNil(specials))
                gel_details = join_list(gel_details,build_list(edits,nil),build_list(notes,nil),nil);
            else
                gel_details = join_list(gel_details,specials,build_list(edits,nil),build_list(notes,nil),nil);

        }



        cur_gel_index++;
        free(sq_line);

    }

    return gel_details;

}
Example #8
0
int main(int argc, const char *argv[])
{
    struct tw_hostent* p_host, *p;
    int i, j, retry = 0;
    char *pa;
    pthread_t dns_recv_pthread;

    if (argc < 2) {
        fprintf(stderr, "%s website1, website2 ...", argv[0]);
    }

    if(signal(SIGINT, sig_int) == SIG_ERR){
        perror("signal error");
    }

    init_head(&head);

    init_dns();
    epfd = epoll_create(1000);

    for (i = 0; i < argc - 1; i++) {
        p_host = (struct tw_hostent*)malloc(sizeof(struct tw_hostent));
        memcpy(p_host->name, argv[i + 1], 30);
        memcpy(p_host->file, argv[i + 1], 30);
        if ((pa = strchr(argv[i + 1], '.'))!= NULL) {
            memcpy(p_host->key_word, pa + 1, 30);
        }
        if((p_host->dns = gethostbyname(argv[i + 1])) == NULL){
            fprintf(stderr, "gethostbyname error");
            return 1;
        }
        p_host->is_dns = 1;
        p_host->first = 1;
        p_host->prev = p_host->next = NULL;
        join_list(&p_host);

        DoOnce(p_host);
        find_url(p_host);
        p_host->is_url = 1;

    }

    pthread_create(&dns_recv_pthread, NULL, dns_recv, NULL);

__again:
    for(p = head.head; p != NULL; p = p->next)
    {
        if(p->is_dns == 0) 
        {
           // printf("still in __again\n");
            goto __again; 
        }
    }
    printf("1 round is well done!\n");
    for(p = head.head; p != NULL; p = p->next)
    {
        if(p->is_url == 0){
            DoOnce(p);
            find_url(p);
            p->is_url = 1;
        }
    }
    printf("2 round is well done!\n");

//      disp_result();

    return 0;
}