Beispiel #1
0
int		main(int argc, char **argv)
{
	t_shell		*head;
	int			i;

	i = argc == 2 ? 0 : 1;
	if (argc == 2 && string_is_valid(argv[1]))
		argv = ft_strsplit(argv[1], ' ');
	if (argc == 1 || !(head = (t_shell*)malloc(sizeof(t_shell))))
		return (0);
	init_head(head);
	while (argv[i])
	{
		if (check_digit(argv[i]) == -1)
			return (flush(head->sa, 0));
		head->sa = push_back_stack2(head->sa, ft_atoi(argv[i]));
		head->max = ft_atoi(argv[i]) > head->max ? ft_atoi(argv[i]) : head->max;
		i++;
	}
	head->len = l_len(head->sa);
	which_swap(head);
	free_lst(head);
	if (argc == 2)
		free_array(argv);
	if (head)
		free(head);
	return (0);
}
Beispiel #2
0
/**
 * \fn order_remove
 *
 * \brief order the remove list according to dependency level
 */
Plisthead *
order_remove(Plisthead *deptreehead)
{
	int		i, maxlevel = 0;
	Pkglist		*pdp, *next;
	Plisthead	*ordtreehead;

	/* package removal cannot trust recorded dependencies, reorder */
	remove_dep_deepness(deptreehead);

	SLIST_FOREACH(pdp, deptreehead, next)
		if (pdp->level > maxlevel)
			maxlevel = pdp->level;

	ordtreehead = init_head();

	for (i = maxlevel; i >= 0; i--) {
		pdp = SLIST_FIRST(deptreehead);
		while (pdp != NULL) {
			next = SLIST_NEXT(pdp, next);
			if (pdp->level == i) {
				SLIST_REMOVE(deptreehead, pdp, Pkglist, next);
				SLIST_INSERT_HEAD(ordtreehead, pdp, next);
			}
			pdp = next;
		}
	}

	return ordtreehead;
}
Beispiel #3
0
int
show_direct_depends(const char *pkgarg)
{
	char		*pkgname, query[BUFSIZ];
	Pkglist		*pdp, *mapplist;
	Plisthead	*deptreehead;

	if (SLIST_EMPTY(&r_plisthead)) {
		printf("%s\n", MSG_EMPTY_AVAIL_PKGLIST);
		return EXIT_FAILURE;
	}

	if ((pkgname = unique_pkg(pkgarg, REMOTE_PKG)) == NULL) {
		fprintf(stderr, MSG_PKG_NOT_AVAIL, pkgarg);
		return EXIT_FAILURE;
	}

	deptreehead = init_head();

	snprintf(query, BUFSIZ, EXACT_DIRECT_DEPS, pkgname);

	if (pkgindb_doquery(query, pdb_rec_depends, deptreehead) == PDB_OK) {
		printf(MSG_DIRECT_DEPS_FOR, pkgname);
		SLIST_FOREACH(pdp, deptreehead, next) {
			if (package_version && 
				(mapplist = map_pkg_to_dep(&r_plisthead,
							   pdp->depend))
				!= NULL)
				printf("\t%s\n", mapplist->full);
			else
				printf("\t%s\n", pdp->depend);
		}
		free_pkglist(&deptreehead, DEPTREE);
	}
Beispiel #4
0
/**
 * \fn order_install
 *
 * order the install list according to dependency level
 * here we only rely on basic level given by pkg_summary, the only drawback
 * is that pkg_add will install direct dependencies, giving a "failed,
 * package already installed"
 */
Plisthead *
order_install(Plisthead *impacthead)
{
	Plisthead	*ordtreehead;
	Pkglist		*pimpact, *pdp, *pi_dp = NULL;
	int			i, maxlevel = 0;
	char		tmpcheck[BUFSIZ];

	/* record higher dependency level on impact list */
	SLIST_FOREACH(pimpact, impacthead, next) {
		if ((pimpact->action == TOUPGRADE ||
			pimpact->action == TOINSTALL) &&
			pimpact->level > maxlevel)
			maxlevel = pimpact->level;
	}

	ordtreehead = init_head();

	for (i = 0; i <= maxlevel; i++) {
		SLIST_FOREACH(pimpact, impacthead, next) {
			if ((pimpact->action == TOUPGRADE ||
				pimpact->action == TOINSTALL) &&
				pimpact->level == i) {

				if (pkg_in_impact(ordtreehead, pimpact->full))
					continue;

				pdp = malloc_pkglist(DEPTREE);

				pdp->computed = pimpact->action; /* XXX: ugly*/
				XSTRDUP(pdp->depend, pimpact->full);
				pdp->name = NULL; /* safety */
				pdp->level = pimpact->level;
				/* record package size for download check */
				pdp->file_size = pimpact->file_size;

				/* check for pkg_install upgrade */
				strcpy(tmpcheck, pimpact->full);
				trunc_str(tmpcheck, '-', STR_BACKWARD);
				/* match on pkg_install */
				if (strcmp(tmpcheck, PKG_INSTALL) == 0) {
					pi_upgrade = 1;
					/* backup pdp for future insertion */
					pi_dp = pdp;
				} else					
					SLIST_INSERT_HEAD(ordtreehead,
						pdp, next);
			} /* action == TOINSTALL */
		} /* SLIST_FOREACH pimpact */
	} /* for i < maxlevel */

	/* pkg_install is to be upgraded, make it first */
	if (pi_upgrade && pi_dp != NULL)
		SLIST_INSERT_HEAD(ordtreehead, pi_dp, next);

	return ordtreehead;
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    init_head(&g_list);
    mp3_song_list_init(&g_list, "./"); 
    list_display(&g_list);
    printf("list length = %d\n", list_getlen(&g_list));

    return 0;
}
int main()
{
	long l;
	printf("zie of long: %lu\n",sizeof(l));
	node n1;
	printf("Size of struct n1: %lu\n", sizeof(n1));
	char* s = "hihihihihihihihihihihihihihihihihihi";
	printf("char pointer \" %s \" size: %lu\n",s,sizeof(s));
	init_head(1);
	insert_node(10);
	insert_node(20);
	insert_node(30);
	insert_node(40);
	print_list();
	delete_list();
	return 0;
}
Beispiel #7
0
/**
 * \fn order_upgrade_remove
 *
 * \brief order the remove-for-upgrade list according to dependency level
 */
Plisthead *
order_upgrade_remove(Plisthead *impacthead)
{
	Plisthead	*ordtreehead;
	Pkglist		*pimpact, *pdp;
	int		i, maxlevel = 0;

	upgrade_dep_deepness(impacthead);

	/* record higher dependency level on impact upgrade list */
	SLIST_FOREACH(pimpact, impacthead, next)
		if ((pimpact->action == TOUPGRADE ||
			pimpact->action == TOREMOVE) &&
			pimpact->level > maxlevel)

			maxlevel = pimpact->level;

	ordtreehead = init_head();

	for (i = maxlevel; i >= 0; i--)
		SLIST_FOREACH(pimpact, impacthead, next) {
			if ((pimpact->action == TOUPGRADE ||
				pimpact->action == TOREMOVE) &&
				pimpact->level == i) {

				if (pkg_in_impact(ordtreehead, pimpact->old))
					continue;

				pdp = malloc_pkglist(DEPTREE);

				XSTRDUP(pdp->depend, pimpact->old);
				pdp->name = NULL; /* safety */
				/* XXX: use the "computed" value to record
				 * action type. Ugly.
				 */
				pdp->computed = pimpact->action;
				/* informative only */
				pdp->level = pimpact->level;
				SLIST_INSERT_HEAD(ordtreehead, pdp, next);

			} /* action == TOUPGRADE || TOREMOVE */
		} /* for maxlevel */

	return ordtreehead;
}
int main () {
  pthread_t t1, t2;
  struct head *tmp;
  int i;

  pthread_create(&t1, NULL, t_fun, NULL);
  pthread_create(&t2, NULL, counter, NULL);
  
  while (1) {
    getchar();
    printf("Creating new bucket!\n");
    tmp = malloc(sizeof(struct head));
    init_head(tmp);
    pthread_mutex_lock(&list_lock);
    tmp->next = list;
    list = tmp;
    pthread_mutex_unlock(&list_lock);
  }
  return 0;
}
Beispiel #9
0
/**
 * find dependency deepness for package removal and record it to pdp->level
 */
static void
remove_dep_deepness(Plisthead *deptreehead)
{
	char		*depname;
	Pkglist		*pdp;
	Plisthead	*lvldeptree;

	/* get higher recursion level */
	SLIST_FOREACH(pdp, deptreehead, next) {
		if (pdp->level == -1) { /* unique package, just return */
			pdp->level = 0;
			return;
		}

		pdp->level = 1;
		
		if (pdp->depend == NULL)
			/* there's something wrong with database's record,
			 * probably a mistaken dependency
			 */
			continue;

		/* depname received from deptreehead is in package format */
		XSTRDUP(depname, pdp->depend);

		trunc_str(depname, '-', STR_BACKWARD);

		lvldeptree = init_head();
		full_dep_tree(depname, LOCAL_REVERSE_DEPS, lvldeptree);

		if (!SLIST_EMPTY(lvldeptree))
		    	pdp->level = SLIST_FIRST(lvldeptree)->level + 1;

		XFREE(depname);
		free_pkglist(&lvldeptree, DEPTREE);

#if 0
		printf("%s -> %d\n", pdp->depend, pdp->level);
#endif
	}
}
Beispiel #10
0
/* find dependency deepness for upgrade and record it to pimpact->level */
static void
upgrade_dep_deepness(Plisthead *impacthead)
{
	char		*pkgname;
	Pkglist		*pimpact;
	Plisthead	*lvldeptree;

	/* get higher recursion level */
	SLIST_FOREACH(pimpact, impacthead, next) {
		if (pimpact->level == -1) { /* unique package, just return */
			pimpact->level = 0;
			return;
		}

		/* only deal with TOUPGRADE and TOREMOVE */
		if (pimpact->action == TOINSTALL)
			continue;

		pimpact->level = 1;

		/* depname received from impact is in full package format */
		XSTRDUP(pkgname, pimpact->full);

		trunc_str(pkgname, '-', STR_BACKWARD);

		lvldeptree = init_head();
		full_dep_tree(pkgname, LOCAL_REVERSE_DEPS, lvldeptree);

		if (!SLIST_EMPTY(lvldeptree))
		    	pimpact->level = SLIST_FIRST(lvldeptree)->level + 1;

#if 0
		printf("%s (%s) -> %d\n",
			pimpact->full, pkgname, pimpact->level);
#endif

		XFREE(pkgname);
		free_pkglist(&lvldeptree, DEPTREE);
	}
}
Beispiel #11
0
int add_to_list(struct Head_Node ** head, char ID[ID_SIZE]) {	
	struct Node * tmp;
        struct Node *tmp1 = NULL;
	int i = 0;
	tmp = init_node(ID);
        uint32_t timestamp;  
        //printf("\nIn adding before, head : %lu, adding %s\n", (long)(*head), ID+4);
        //getchar();
        LOG(INFO,"Adding node %s to the topology ", ID + 4);
        if ( *head == NULL ) {
	        
	       //printf("\nIn adding 1\n");
        	
                *head = init_head(tmp);
		(*head)->num_of_nodes = 1;
                     
                //printf("\nReturning :%d\n", (*head)->num_of_nodes);

                return 0;
	} else {
                
                printf("\nAdding node %s to topology \n", ID+4);
                for (i = 0 , tmp1 = (*head)->node; i < (*head)->num_of_nodes; i++, tmp1 = tmp1->next) {
                    if (!strncmp(tmp1->IP, ID+4, 16)) {
                        memcpy(&timestamp, ID, 4);
                        tmp1->timestamp = ntohl(timestamp);
                        return 0;
                    }
                }
		 
                tmp->next = (*head)->node;
		tmp->prev = (*head)->node->prev;
		(*head)->node->prev->next = tmp;
		(*head)->node->prev = tmp;
		(*head)->num_of_nodes++;
                return 0;	
	}
}
int main(void)
{
	int len = 0, i;
	node_t str[3] = {{1, NULL}, {2, NULL}, {3, NULL}};

	node_t *link_head = NULL;
	init_head(&link_head);
	len = sizeof(str)/sizeof(str[0]);

	for (i = 0; i < len; i++) {
		if ((link_head = link_insert_one_b(link_head, str[i].num)) == NULL) {
			puts("error: main at link_insert_one_b");
			exit(-1);
		}
	}
	link_print(link_head);
//printf("asdf\n");
	if ((link_head = link_reverse(link_head)) == NULL) {
		puts("error: main at link_insert_one_b");
		exit(-1);
	}
	link_print(link_head);
	return 0;
}
Beispiel #13
0
int main(int argc, char * argv[])
{
    int fps     = 15;
    int bitRate = 24;
    int width   = 640;
    int height  = 480;
    int yuvsize = (width * height * 3) >> 1;
    uint8_t * yuv = (uint8_t *)malloc(yuvsize);
    
    x264_picture_t *_picIn;
	x264_picture_t *_picOut;
    x264_t * x264_handle_        = NULL;
    x264_param_t * x264_param_   = (x264_param_t *)malloc(sizeof(x264_param_t));
    
    init_param(x264_param_, width, height, fps, bitRate);  
    
	_picIn = (x264_picture_t*)malloc(sizeof(x264_picture_t));
	_picOut = (x264_picture_t*)malloc(sizeof(x264_picture_t));
	
	if(x264_picture_alloc(_picIn, X264_CSP_I420, width, height) < 0 ) {
	    printf("x264_picture_alloc failed!\n");
	    exit(0);
	}
	
	_picIn->img.i_csp   = X264_CSP_I420;  
	_picIn->img.i_plane = 3; 

	x264_handle_ = x264_encoder_open(x264_param_);
	if(!x264_handle_) {
		printf("x264_encoder_open failed!\n");
		exit(0);
	}
	init_head(x264_handle_, NULL, 0);
	
	if (argc < 2) {
	    printf("please input yuv file name!\n");
	    exit(0);
	}
	const char * file = argv[1];
	printf("encode yuv file:%s\n", file);
	
	struct stat sb;
	if (stat(file, &sb) == -1) {
	    printf("stat file:%s failed!\n", file);
	    exit(0);
	}
	
	if ((sb.st_mode & S_IFMT) != S_IFREG || sb.st_size <  yuvsize) {
	    printf("file:%s invalid, size:%ld, regfile:%d!\n", file, sb.st_size, (sb.st_mode & S_IFMT) == S_IFREG);
	    exit(0);
	}
	
	int rfd = open(file, O_RDONLY);
	if (rfd < 0) {
	    printf("open file:%s failed!\n", file);
	    exit(0);
	}
	
	int off = 0, rdn = 0;
	if ((rdn = read(rfd, yuv, yuvsize - off)) != yuvsize) {
        printf("read no enough data. readn:%d, yuvsize:%d\n", rdn, yuvsize);
	} 
	close(rfd);
	
	int planesize = width * height;
	memcpy(_picIn->img.plane[0], yuv, planesize);
	memcpy(_picIn->img.plane[1], yuv + planesize, planesize >> 2);
	memcpy(_picIn->img.plane[2], yuv + planesize + (planesize >> 2), planesize >> 2);
	
	x264_nal_t * nal;
	int nalcnt = 0;
	
	int encodesize = x264_encoder_encode(x264_handle_, &nal, &nalcnt, _picIn, _picOut);
	if (encodesize <= 0) {
	    printf("encode failed. size:%d\n", encodesize);
	    exit(0);
	}
	
	const char * outfile = "h264_640x480.bin";
	int wfd = open(outfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP);
	if (wfd < 0) {
	    printf("open outfile:%s failed!\n", outfile);
	    exit(0);
	}
	write(wfd, nal->p_payload, encodesize);
	close(wfd);
	
	x264_encoder_close(x264_handle_);
	x264_picture_clean(_picIn);
	free(_picIn);
	free(_picOut);
	free(yuv);
	free(x264_param_);
	
	return 0;
}
Beispiel #14
0
static void
break_depends(Plisthead *impacthead)
{
	Pkglist	   	*rmimpact, *pimpact;
	Plisthead	*rdphead, *fdphead;
	Pkglist	   	*rdp, *fdp;
	char		*pkgname, *rpkg;
	int			dep_break, exists;

	SLIST_FOREACH(pimpact, impacthead, next) {

		if (pimpact->old == NULL) /* DONOTHING or TOINSTALL  */
			continue;

		rdphead = init_head();

		XSTRDUP(pkgname, pimpact->old);
		trunc_str(pkgname, '-', STR_BACKWARD);

		/* fetch old package reverse dependencies */
		full_dep_tree(pkgname, LOCAL_REVERSE_DEPS, rdphead);

		XFREE(pkgname);

		/* browse reverse dependencies */
		SLIST_FOREACH(rdp, rdphead, next) {

			exists = 0;
			/* check if rdp was already on impact list */
			SLIST_FOREACH(rmimpact, impacthead, next)
				if (strcmp(rmimpact->depend, rdp->depend) == 0) {
					exists = 1;
					break;
				}
			if (exists)
				continue;

			fdphead = init_head();

			/*
			 * reverse dependency is a full package name,
			 * use it and strip it
			 */
			XSTRDUP(rpkg, rdp->depend);
			trunc_str(rpkg, '-', STR_BACKWARD);

			/* fetch dependencies for rdp */
			full_dep_tree(rpkg, DIRECT_DEPS, fdphead);

			/* initialize to broken dependency */
			dep_break = 1;

			/* empty full dep tree, this can't happen in normal situation.
			 * If it does, that means that the reverse dependency we're
			 * analyzing has no direct dependency.
			 * Such a situation could occur if the reverse dependency is not on
			 * the repository anymore, leading to no information regarding this
			 * package.
			 * So we will check if local package dependencies are satisfied by
			 * our newly upgraded packages.
			 */
			if (SLIST_EMPTY(fdphead)) {
				free_pkglist(&fdphead, DEPTREE);
				fdphead = init_head();
				full_dep_tree(rpkg, LOCAL_DIRECT_DEPS, fdphead);
			}
			XFREE(rpkg);

			/*
			 * browse dependencies for rdp and see if
			 * new package to be installed matches
			 */
			SLIST_FOREACH(fdp, fdphead, next) {
				if (pkg_match(fdp->depend, pimpact->full)) {
					dep_break = 0;
					break;
				}
			}

			free_pkglist(&fdphead, DEPTREE);

			if (!dep_break)
				continue;

			/* dependency break, insert rdp in remove-list */
			rmimpact = malloc_pkglist(IMPACT);
			XSTRDUP(rmimpact->depend, rdp->depend);
			XSTRDUP(rmimpact->full, rdp->depend);
			XSTRDUP(rmimpact->old, rdp->depend);
			rmimpact->action = TOREMOVE;
			rmimpact->level = 0;

			SLIST_INSERT_HEAD(impacthead, rmimpact, next);
		}
		free_pkglist(&rdphead, DEPTREE);
	}
Beispiel #15
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;
}