Example #1
0
//显示多项式
void list_display(s_list *list, char ch)
{
	if (list == null)
	{
		return;
	}

	//如果当前节点是子表
	if (list->tag)
	{
		printf("(");
		//递归显示子表
		list_display(list->child, ch - 1);
		printf(")%c^%d", ch, list->exp);
	}
	//如果当前节点是原子节点
	else
	{
		//显示原子内容
		printf("%+d%c^%d", list->coe, ch, list->exp);
	}

	//如果下一节点不为空
	if (list->next != null)
	{
		printf("+");
		//递归显示下一节点
		list_display(list->next, ch);
	}
}
Example #2
0
int main(int argc, char *arv[])
{
	Node_t *p = NULL;
	TreeNode_t *t = NULL;

	// Linked list
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_append(&p, 10);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_append(&p, 20);
	list_append(&p, 30);
	list_append(&p, 40);
	list_append(&p, 50);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 20);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 123);

	list_remove(&p, 10);
	list_remove(&p, 30);
	list_remove(&p, 50);
	list_remove(&p, 40);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 100);


	// Binary tree
	tree_display(t);
	printf("\n");

	tree_insert(&t, 10);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 8);
	tree_insert(&t, 11);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 4);
	tree_insert(&t, 3);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 15);
	tree_insert(&t, 14);
	tree_display(t);
	printf("\n");
	return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
	list_node *list1 = list_init();
	list_node *list2 = list_init();

	list_insert(list1, 1);
	list_insert(list1, 4);
	list_insert(list1, 7);
//	list_insert(list1, 12);
//	list_insert(list1, 19);
	list_insert(list1, 61);
	
	list_insert(list2, 3);
	list_insert(list2, 9);
	list_insert(list2, 13);
//	list_insert(list2, 14);
//	list_insert(list2, 61);

    list_display(list1);
    list_display(list2);

	list_node *all = list_merger(list1, list2);
	list_display(all);

	return 0;
}
Example #4
0
static void files_action_open(file_info* info, bool* populated) {
    files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data));
    data->info = info;
    data->populated = populated;

    list_display(info->isDirectory ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top);
}
Example #5
0
static void extsavedata_action_open(ext_save_data_info* info, bool* populated) {
    extsavedata_action_data* data = (extsavedata_action_data*) calloc(1, sizeof(extsavedata_action_data));
    data->info = info;
    data->populated = populated;

    list_display("Ext Save Data Action", "A: Select, B: Return", data, extsavedata_action_update, extsavedata_action_draw_top);
}
Example #6
0
static void files_action_open(linked_list* items, list_item* selected, files_data* parent) {
    files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data));
    if(data == NULL) {
        error_display(NULL, NULL, "Failed to allocate files action data.");

        return;
    }

    data->items = items;
    data->selected = selected;
    data->parent = parent;

    data->containsCias = false;
    data->containsTickets = false;

    linked_list_iter iter;
    linked_list_iterate(data->items, &iter);

    while(linked_list_iter_has_next(&iter)) {
        file_info* info = (file_info*) ((list_item*) linked_list_iter_next(&iter))->data;

        if(info->isCia) {
            data->containsCias = true;
        } else if(info->isTicket) {
            data->containsTickets = true;
        }
    }

    list_display((((file_info*) selected->data)->attributes & FS_ATTRIBUTE_DIRECTORY) ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top);
}
Example #7
0
int main(int argc,const char *argv[])
{
    node_t * head=0,*node=0;
    node_t e={"e",0},d={"d",&e},c={"c",&d},b={"b",&d},a={"a",&b};
   
    head=&a;
    list_display(&a);
    printf ("%d\n",list_len(&a));
    //  head=list_reverse(&a);
    // list_display(head);
    node=getRec_k_th(head,1);
    printf ("Find the reciprocal of the k-th element : %s\n",node->data);
    node=getMidNode(head);
    printf ("The middle node is %s\n",node->data);

    list_display_reserve(head);
    printf("\n");
    node_t f = {"f",0}, g = {"g",&f}, h = {"h",&g}, i = {"i",&h};
	f.next = &g;
    if(isLoop(&i))
        printf("the list  have a loop\n");
    else
            printf("the list does'nt have a loop\n");
    node=getLoopNode(&i);
    printf ("The loop node is %s\n",node->data);

    
    node_t ee = {"1", 0}, dd = {"2", &ee}, cc = {"3", &dd}, bb = {"4", &cc}, aa = {"5", &bb};
	node_t z = {"8",&cc}, y = {"7", &z}, x = {"6", &y};
      if(is_intersect(&aa, &x))
      printf("the two lists are intersect\n");
      if(node=get_intersect_node(&aa,&x))
    printf("the intersect node is %s",node->data);
    return 0;
}
Example #8
0
int main(int argc, const char *argv[])
{
	int i, ret;
	int arr[] = {12, 9, -1, 23, 2, 34, 6, 45};
	list *ptr = NULL, *ptr2 = NULL; 
	ptr = list_create();
	ptr2 = list_create();
	if (NULL == ptr) {
		printf("error\n");
		exit(1);
	}

	for (i = 0; i < sizeof(arr)/sizeof(*arr); i++) {
		ret = list_insert_at(ptr, DATA_INIT_INDEX, &arr[i]);
		if (ret < 0) {
			fprintf(stderr, "isnert err %d\n", ret);
			exit(1);
		}
	}

	list_display(ptr);

	int tmp = 100;
	list_insert_at(ptr, 1, &tmp);
	list_display(ptr);
	list_destory(ptr);

	for (i = 0; i < sizeof(arr)/sizeof(*arr); i++) {
		ret = list_order_insert(ptr2, &arr[i]);
		if (ret < 0) {
			fprintf(stderr, "isnert err %d\n", ret);
			exit(1);
		}
	}

	list_display(ptr2);

	tmp = 23;
	list_delete(ptr2, &tmp);
	list_display(ptr2);

	list_delete_at(ptr2, 2, &tmp);
	printf("delete_at %d\n", tmp);
	list_display(ptr2);

	return 0;
}
Example #9
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;
}
Example #10
0
void files_open(FS_ArchiveID archiveId, FS_Path archivePath) {
    files_data* data = (files_data*) calloc(1, sizeof(files_data));
    if(data == NULL) {
        error_display(NULL, NULL, NULL, "Failed to allocate files data.");

        return;
    }

    data->populateData.recursive = false;
    data->populateData.includeBase = false;
    data->populateData.dirsFirst = true;

    data->populateData.filter = files_filter;
    data->populateData.filterData = data;

    data->populateData.finished = true;

    data->populated = false;

    data->showDirectories = true;
    data->showCias = true;
    data->showTickets = true;
    data->showMisc = true;

    data->archiveId = archiveId;
    data->archivePath.type = archivePath.type;
    data->archivePath.size = archivePath.size;
    if(archivePath.data != NULL) {
        data->archivePath.data = calloc(1, data->archivePath.size);
        if(data->archivePath.data == NULL) {
            error_display(NULL, NULL, NULL, "Failed to allocate files data.");

            files_free_data(data);
            return;
        }

        memcpy((void*) data->archivePath.data, archivePath.data, data->archivePath.size);
    } else {
        data->archivePath.data = NULL;
    }

    snprintf(data->currDir, FILE_PATH_MAX, "/");
    data->dirItem = NULL;

    Result res = 0;
    if(R_FAILED(res = FSUSER_OpenArchive(&data->archive, archiveId, archivePath))) {
        error_display_res(NULL, NULL, NULL, res, "Failed to open file listing archive.");

        files_free_data(data);
        return;
    }

    list_display("Files", "A: Select, B: Back, X: Refresh, Y: Dir, Select: Filter", data, files_update, files_draw_top);
}
Example #11
0
/** Turn a depends list into a text list.
 * @param deps a list with items of type alpm_depend_t
 */
static void deplist_display(const char *title,
                            alpm_list_t *deps, unsigned short cols)
{
    alpm_list_t *i, *text = NULL;
    for(i = deps; i; i = alpm_list_next(i)) {
        alpm_depend_t *dep = i->data;
        text = alpm_list_add(text, alpm_dep_compute_string(dep));
    }
    list_display(title, text, cols);
    FREELIST(text);
}
Example #12
0
main()
{
    int a[5] = { 2, 3, 4, 5, 6 };
    int b[3] = { 3, 7, 2 };
    struct sqlist lista;
    struct sqlist listb;
    init_list(&lista, 80);
    init_list(&listb, 0);
    int i;
    for (i = 0; i < 5; i++)
	list_insert(&listb, 0, a[i]);
    for (i = 0; i < 3; i++)
	list_insert(&lista, 0, b[i]);
    list_display(&lista);
    list_display(&listb);
    for (i = 0; i < (&listb)->length; i++)
	if (locate_element(&lista, (&listb)->p[i]) == -1)
	    list_insert(&lista, 0, (&listb)->p[i]);
    list_display(&lista);
    destroy_list(&listb);
}
Example #13
0
void titles_open() {
    titles_data* data = (titles_data*) calloc(1, sizeof(titles_data));
    if(data == NULL) {
        error_display(NULL, NULL, NULL, "Failed to allocate titles data.");

        return;
    }

    data->populateData.finished = true;

    list_display("Titles", "A: Select, B: Return, X: Refresh", data, titles_update, titles_draw_top);
}
Example #14
0
static void titles_action_open(linked_list* items, list_item* selected) {
    titles_action_data* data = (titles_action_data*) calloc(1, sizeof(titles_action_data));
    if(data == NULL) {
        error_display(NULL, NULL, "Failed to allocate titles action data.");

        return;
    }

    data->items = items;
    data->selected = selected;

    list_display("Title Action", "A: Select, B: Return", data, titles_action_update, titles_action_draw_top);
}
Example #15
0
static void files_action_open(linked_list* items, list_item* selected, files_data* parent) {
    files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data));
    if(data == NULL) {
        error_display(NULL, NULL, NULL, "Failed to allocate files action data.");

        return;
    }

    data->items = items;
    data->selected = selected;
    data->parent = parent;

    list_display(((file_info*) selected->data)->isDirectory ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top);
}
Example #16
0
void titles_open() {
    titles_data* data = (titles_data*) calloc(1, sizeof(titles_data));
    if(data == NULL) {
        error_display(NULL, NULL, NULL, "Failed to allocate titles data.");

        return;
    }

    data->populateData.filter = titles_filter;
    data->populateData.filterData = data;

    data->populateData.finished = true;

    data->showGameCard = true;
    data->showSD = true;
    data->showNAND = true;

    list_display("Titles", "A: Select, B: Return, X: Refresh, Select: Filter", data, titles_update, titles_draw_top);
}
Example #17
0
void files_open(FS_Archive archive) {
    files_data* data = (files_data*) calloc(1, sizeof(files_data));
    data->archive = archive;

    if(data->archive.lowPath.size > 0) {
        data->archivePath = calloc(1,  data->archive.lowPath.size);
        memcpy(data->archivePath,  data->archive.lowPath.data,  data->archive.lowPath.size);
        data->archive.lowPath.data = data->archivePath;
    }

    data->archive.handle = 0;

    Result res = 0;
    if(R_FAILED(res = FSUSER_OpenArchive(&data->archive))) {
        error_display_res(NULL, NULL, NULL, res, "Failed to open file listing archive.");

        if(data->archivePath != NULL) {
            free(data->archivePath);
        }

        free(data);
        return;
    }

    data->currDir.archive = &data->archive;
    snprintf(data->currDir.path, PATH_MAX, "/");
    util_get_path_file(data->currDir.name, data->currDir.path, NAME_MAX);
    data->currDir.isDirectory = true;
    data->currDir.containsCias = false;
    data->currDir.size = 0;
    data->currDir.isCia = false;

    memcpy(&data->parentDir, &data->currDir, sizeof(data->parentDir));

    list_display("Files", "A: Select, B: Back, X: Refresh, Y: Directory Action", data, files_update, files_draw_top);
}
Example #18
0
/* TODO this is one of the worst ever functions written. void *data ? wtf */
void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
                   void *data3, int *response)
{
	switch(event) {
		case PM_TRANS_CONV_INSTALL_IGNOREPKG:
			if(!config->op_s_downloadonly) {
				*response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
								  alpm_pkg_get_name(data1));
			} else {
				*response = 1;
			}
			break;
		case PM_TRANS_CONV_REPLACE_PKG:
			*response = yesno(_(":: Replace %s with %s/%s?"),
					alpm_pkg_get_name(data1),
					(char *)data3,
					alpm_pkg_get_name(data2));
			break;
		case PM_TRANS_CONV_CONFLICT_PKG:
			/* data parameters: target package, local package, conflict (strings) */
			/* print conflict only if it contains new information */
			if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) {
				*response = noyes(_(":: %s and %s are in conflict. Remove %s?"),
						(char *)data1,
						(char *)data2,
						(char *)data2);
			} else {
				*response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"),
						(char *)data1,
						(char *)data2,
						(char *)data3,
						(char *)data2);
			}
			break;
		case PM_TRANS_CONV_REMOVE_PKGS:
			{
				alpm_list_t *unresolved = (alpm_list_t *) data1;
				alpm_list_t *namelist = NULL, *i;
				size_t count = 0;
				for (i = unresolved; i; i = i->next) {
					namelist = alpm_list_add(namelist,
							(char *)alpm_pkg_get_name(i->data));
					count++;
				}
				printf(_n(
							":: The following package cannot be upgraded due to unresolvable dependencies:\n",
							":: The following packages cannot be upgraded due to unresolvable dependencies:\n",
							count));
				list_display("     ", namelist);
				printf("\n");
				*response = noyes(_n(
							"Do you want to skip the above package for this upgrade?",
							"Do you want to skip the above packages for this upgrade?",
							count));
				alpm_list_free(namelist);
			}
			break;
		case PM_TRANS_CONV_SELECT_PROVIDER:
			{
				alpm_list_t *providers = (alpm_list_t *)data1;
				int count = alpm_list_count(providers);
				char *depstring = alpm_dep_compute_string((pmdepend_t *)data2);
				printf(_(":: There are %d providers available for %s:\n"), count,
						depstring);
				free(depstring);
				select_display(providers);
				*response = select_question(count);
			}
			break;
		case PM_TRANS_CONV_LOCAL_NEWER:
			if(!config->op_s_downloadonly) {
				*response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"),
						alpm_pkg_get_name(data1),
						alpm_pkg_get_version(data1));
			} else {
				*response = 1;
			}
			break;
		case PM_TRANS_CONV_CORRUPTED_PKG:
			*response = yesno(_(":: File %s is corrupted. Do you want to delete it?"),
					(char *)data1);
			break;
	}
	if(config->noask) {
		if(config->ask & event) {
			/* inverse the default answer */
			*response = !*response;
		}
	}
}
Example #19
0
int main(int argc, char **args)
{
	//list1 x^10
	s_list *list1 = (s_list *) malloc(sizeof(s_list));
	list_init(list1);
	list_insert_value(list1, 0, 10, 1);

	//list2 2x^6
	s_list *list2 = (s_list *) malloc(sizeof(s_list));
	list_init(list2);
	list_insert_value(list2, 0, 6, 2);

	//list1 (x^10 + 2x^6)
	list_append(list1, list2);

	//list3 (x^10 + 2x^6)y^3
	s_list *list3 = (s_list *) malloc(sizeof(s_list));
	list_init(list3);
	list_insert_value(list3, 1, 3, (int) list1);

	//list4 3x^5
	s_list *list4 = (s_list *) malloc(sizeof(s_list));
	list_init(list4);
	list_insert_value(list4, 0, 5, 3);

	//list5 (3x^5)y^2
	s_list *list5 = (s_list *) malloc(sizeof(s_list));
	list_init(list5);
	list_insert_value(list5, 1, 2, (int) list4);

	//list3 ((x^10 + 2x^6)y^3 + (3x^5)y^2)
	list_append(list3, list5);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2
	s_list *list6 = (s_list *) malloc(sizeof(s_list));
	list_init(list6);
	list_insert_value(list6, 1, 2, (int) list3);

	//list7 x^4
	s_list *list7 = (s_list *) malloc(sizeof(s_list));
	list_init(list7);
	list_insert_value(list7, 0, 4, 1);

	//list8 6x^3
	s_list *list8 = (s_list *) malloc(sizeof(s_list));
	list_init(list8);
	list_insert_value(list8, 0, 3, 6);

	//list8 (x^4 + 6x^3)
	list_append(list7, list8);

	//list9 (x^4 + 6x^3)y^4
	s_list *list9 = (s_list *) malloc(sizeof(s_list));
	list_init(list9);
	list_insert_value(list9, 1, 4, (int) list7);

	//list10 2y
	s_list *list10 = (s_list *) malloc(sizeof(s_list));
	list_init(list10);
	list_insert_value(list10, 0, 1, 2);

	//list9 ((x^4 + 6x^3)y^4 + 2y)
	list_append(list9, list10);

	//list11 ((x^4 + 6x^3)y^4 + 2y)z
	s_list *list11 = (s_list *) malloc(sizeof(s_list));
	list_init(list11);
	list_insert_value(list11, 1, 1, (int) list9);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2 + ((x^4 + 6x^3)y^4 + 2y)z
	list_append(list6, list11);

	//list12 15
	s_list *list12 = (s_list *) malloc(sizeof(s_list));
	list_init(list12);
	list_insert_value(list12, 0, 0, 15);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2 + ((x^4 + 6x^3)y^4 + 2y)z + 15
	list_append(list6, list12);

	//显示多项式
	list_display(list6, 'z');
	printf("\n");

	//求广义表list6深度
	int depth = 0;
	list_depth(list6, &depth);
	printf("depth = %d \n", depth);

	s_list *list13 = (s_list *) malloc(sizeof(s_list));
	list_copy(list13, list6);
	//显示多项式
	list_display(list13, 'z');
	printf("\n");

	//求广义表list13深度
	depth = 0;
	list_depth(list13, &depth);
	printf("depth = %d \n", depth);

	//销毁广义表,释放内存
	list_destory(list6);
	//销毁广义表,释放内存
	list_destory(list13);

	return 0;
}
Example #20
0
/**
 * Display the details of a package.
 * Extra information entails 'required by' info for sync packages and backup
 * files info for local packages.
 * @param pkg package to display information for
 * @param from the type of package we are dealing with
 * @param extra should we show extra information
 */
void dump_pkg_full(alpm_pkg_t *pkg, int extra)
{
    unsigned short cols;
    time_t bdate, idate;
    alpm_pkgfrom_t from;
    double size;
    char bdatestr[50] = "", idatestr[50] = "";
    const char *label, *reason;
    alpm_list_t *validation = NULL, *requiredby = NULL, *optionalfor = NULL;

    from = alpm_pkg_get_origin(pkg);

    /* set variables here, do all output below */
    bdate = (time_t)alpm_pkg_get_builddate(pkg);
    if(bdate) {
        strftime(bdatestr, 50, "%c", localtime(&bdate));
    }
    idate = (time_t)alpm_pkg_get_installdate(pkg);
    if(idate) {
        strftime(idatestr, 50, "%c", localtime(&idate));
    }

    switch(alpm_pkg_get_reason(pkg)) {
    case ALPM_PKG_REASON_EXPLICIT:
        reason = _("Explicitly installed");
        break;
    case ALPM_PKG_REASON_DEPEND:
        reason = _("Installed as a dependency for another package");
        break;
    default:
        reason = _("Unknown");
        break;
    }

    alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg);
    if(v) {
        if(v & ALPM_PKG_VALIDATION_NONE) {
            validation = alpm_list_add(validation, _("None"));
        } else {
            if(v & ALPM_PKG_VALIDATION_MD5SUM) {
                validation = alpm_list_add(validation, _("MD5 Sum"));
            }
            if(v & ALPM_PKG_VALIDATION_SHA256SUM) {
                validation = alpm_list_add(validation, _("SHA256 Sum"));
            }
            if(v & ALPM_PKG_VALIDATION_SIGNATURE) {
                validation = alpm_list_add(validation, _("Signature"));
            }
        }
    } else {
        validation = alpm_list_add(validation, _("Unknown"));
    }

    if(extra || from == ALPM_PKG_FROM_LOCALDB) {
        /* compute this here so we don't get a pause in the middle of output */
        requiredby = alpm_pkg_compute_requiredby(pkg);
        optionalfor = alpm_pkg_compute_optionalfor(pkg);
    }

    cols = getcols(fileno(stdout));

    /* actual output */
    if(from == ALPM_PKG_FROM_SYNCDB) {
        string_display(_("Repository     :"),
                       alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
    }
    string_display(_("Name           :"), alpm_pkg_get_name(pkg), cols);
    string_display(_("Version        :"), alpm_pkg_get_version(pkg), cols);
    string_display(_("Description    :"), alpm_pkg_get_desc(pkg), cols);
    string_display(_("Architecture   :"), alpm_pkg_get_arch(pkg), cols);
    string_display(_("URL            :"), alpm_pkg_get_url(pkg), cols);
    list_display(_("Licenses       :"), alpm_pkg_get_licenses(pkg), cols);
    list_display(_("Groups         :"), alpm_pkg_get_groups(pkg), cols);
    deplist_display(_("Provides       :"), alpm_pkg_get_provides(pkg), cols);
    deplist_display(_("Depends On     :"), alpm_pkg_get_depends(pkg), cols);
    optdeplist_display(pkg, cols);

    if(extra || from == ALPM_PKG_FROM_LOCALDB) {
        list_display(_("Required By    :"), requiredby, cols);
        list_display(_("Optional For   :"), optionalfor, cols);
    }
    deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg), cols);
    deplist_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg), cols);

    size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, &label);
    if(from == ALPM_PKG_FROM_SYNCDB) {
        printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Download Size  :"),
               config->colstr.nocolor, size, label);
    } else if(from == ALPM_PKG_FROM_FILE) {
        printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Compressed Size:"),
               config->colstr.nocolor, size, label);
    } else {
        // autodetect size for "Installed Size"
        label = "\0";
    }

    size = humanize_size(alpm_pkg_get_isize(pkg), label[0], 2, &label);
    printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Installed Size :"),
           config->colstr.nocolor, size, label);

    string_display(_("Packager       :"), alpm_pkg_get_packager(pkg), cols);
    string_display(_("Build Date     :"), bdatestr, cols);
    if(from == ALPM_PKG_FROM_LOCALDB) {
        string_display(_("Install Date   :"), idatestr, cols);
        string_display(_("Install Reason :"), reason, cols);
    }
    if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
        string_display(_("Install Script :"),
                       alpm_pkg_has_scriptlet(pkg) ?  _("Yes") : _("No"), cols);
    }

    if(from == ALPM_PKG_FROM_SYNCDB && extra) {
        const char *base64_sig = alpm_pkg_get_base64_sig(pkg);
        alpm_list_t *keys = NULL;
        if(base64_sig) {
            unsigned char *decoded_sigdata = NULL;
            size_t data_len;
            alpm_decode_signature(base64_sig, &decoded_sigdata, &data_len);
            alpm_extract_keyid(config->handle, alpm_pkg_get_name(pkg),
                               decoded_sigdata, data_len, &keys);
        } else {
            keys = alpm_list_add(keys, _("None"));
        }

        string_display(_("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg), cols);
        string_display(_("SHA256 Sum     :"), alpm_pkg_get_sha256sum(pkg), cols);
        list_display(_("Signatures     :"), keys, cols);
    } else {
        list_display(_("Validated By   :"), validation, cols);
    }

    if(from == ALPM_PKG_FROM_FILE) {
        alpm_siglist_t siglist;
        int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
        if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
            string_display(_("Signatures     :"), _("None"), cols);
        } else if(err) {
            string_display(_("Signatures     :"),
                           alpm_strerror(alpm_errno(config->handle)), cols);
        } else {
            signature_display(_("Signatures     :"), &siglist, cols);
        }
        alpm_siglist_cleanup(&siglist);
    }

    /* Print additional package info if info flag passed more than once */
    if(from == ALPM_PKG_FROM_LOCALDB && extra) {
        dump_pkg_backups(pkg);
    }

    /* final newline to separate packages */
    printf("\n");

    FREELIST(requiredby);
    alpm_list_free(validation);
}
Example #21
0
/* callback to handle questions from libalpm transactions (yes/no) */
void cb_question(alpm_question_t *question)
{
	if(config->print) {
		if(question->type == ALPM_QUESTION_INSTALL_IGNOREPKG) {
			question->any.answer = 1;
		} else {
			question->any.answer = 0;
		}
		return;
	}
	switch(question->type) {
		case ALPM_QUESTION_INSTALL_IGNOREPKG:
			{
				alpm_question_install_ignorepkg_t *q = &question->install_ignorepkg;
				if(!config->op_s_downloadonly) {
					q->install = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"),
							alpm_pkg_get_name(q->pkg));
				} else {
					q->install = 1;
				}
			}
			break;
		case ALPM_QUESTION_REPLACE_PKG:
			{
				alpm_question_replace_t *q = &question->replace;
				q->replace = yesno(_("Replace %s with %s/%s?"),
						alpm_pkg_get_name(q->oldpkg),
						alpm_db_get_name(q->newdb),
						alpm_pkg_get_name(q->newpkg));
			}
			break;
		case ALPM_QUESTION_CONFLICT_PKG:
			{
				alpm_question_conflict_t *q = &question->conflict;
				/* print conflict only if it contains new information */
				if(strcmp(q->conflict->package1, q->conflict->reason->name) == 0
						|| strcmp(q->conflict->package2, q->conflict->reason->name) == 0) {
					q->remove = noyes(_("%s and %s are in conflict. Remove %s?"),
							q->conflict->package1,
							q->conflict->package2,
							q->conflict->package2);
				} else {
					q->remove = noyes(_("%s and %s are in conflict (%s). Remove %s?"),
							q->conflict->package1,
							q->conflict->package2,
							q->conflict->reason->name,
							q->conflict->package2);
				}
			}
			break;
		case ALPM_QUESTION_REMOVE_PKGS:
			{
				alpm_question_remove_pkgs_t *q = &question->remove_pkgs;
				alpm_list_t *namelist = NULL, *i;
				size_t count = 0;
				for(i = q->packages; i; i = i->next) {
					namelist = alpm_list_add(namelist,
							(char *)alpm_pkg_get_name(i->data));
					count++;
				}
				colon_printf(_n(
							"The following package cannot be upgraded due to unresolvable dependencies:\n",
							"The following packages cannot be upgraded due to unresolvable dependencies:\n",
							count));
				list_display("     ", namelist, getcols());
				printf("\n");
				q->skip = noyes(_n(
							"Do you want to skip the above package for this upgrade?",
							"Do you want to skip the above packages for this upgrade?",
							count));
				alpm_list_free(namelist);
			}
			break;
		case ALPM_QUESTION_SELECT_PROVIDER:
			{
				alpm_question_select_provider_t *q = &question->select_provider;
				size_t count = alpm_list_count(q->providers);
				char *depstring = alpm_dep_compute_string(q->depend);
				colon_printf(_n("There is %zd provider available for %s\n",
						"There are %zd providers available for %s:\n", count),
						count, depstring);
				free(depstring);
				select_display(q->providers);
				q->use_index = select_question(count);
			}
			break;
		case ALPM_QUESTION_CORRUPTED_PKG:
			{
				alpm_question_corrupted_t *q = &question->corrupted;
				q->remove = yesno(_("File %s is corrupted (%s).\n"
							"Do you want to delete it?"),
						q->filepath,
						alpm_strerror(q->reason));
			}
			break;
		case ALPM_QUESTION_IMPORT_KEY:
			{
				alpm_question_import_key_t *q = &question->import_key;
				char created[12];
				time_t time = (time_t)q->key->created;
				strftime(created, 12, "%Y-%m-%d", localtime(&time));

				if(q->key->revoked) {
					q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"),
							q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created);
				} else {
					q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"),
							q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created);
				}
			}
			break;
	}
	if(config->noask) {
		if(config->ask & question->type) {
			/* inverse the default answer */
			question->any.answer = !question->any.answer;
		}
	}
}
Example #22
0
void extsavedata_open() {
    extsavedata_data* data = (extsavedata_data*) calloc(1, sizeof(extsavedata_data));

    list_display("Ext Save Data", "A: Select, B: Return, X: Refresh", data, extsavedata_update, extsavedata_draw_top);
}
Example #23
0
/* prepare a list of pkgs to display */
static void _display_targets(alpm_list_t *targets, int verbose)
{
	char *str;
	const char *label;
	double size;
	off_t isize = 0, rsize = 0, dlsize = 0;
	unsigned short cols;
	alpm_list_t *i, *rows = NULL, *names = NULL;

	if(!targets) {
		return;
	}

	/* gather package info */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(target->install) {
			dlsize += alpm_pkg_download_size(target->install);
			isize += alpm_pkg_get_isize(target->install);
		}
		if(target->remove) {
			/* add up size of all removed packages */
			rsize += alpm_pkg_get_isize(target->remove);
		}
	}

	/* form data for both verbose and non-verbose display */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		rows = alpm_list_add(rows, create_verbose_row(target));
		if(target->install) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
					alpm_pkg_get_version(target->install));
		} else if(isize == 0) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		} else {
			pm_asprintf(&str, "%s-%s [removal]", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		}
		names = alpm_list_add(names, str);
	}

	/* print to screen */
	pm_asprintf(&str, _("Packages (%d):"), alpm_list_count(targets));
	printf("\n");

	cols = getcols(fileno(stdout));
	if(verbose) {
		alpm_list_t *header = create_verbose_header();
		if(table_display(str, header, rows, cols) != 0) {
			/* fallback to list display if table wouldn't fit */
			list_display(str, names, cols);
		}
		alpm_list_free(header);
	} else {
		list_display(str, names, cols);
	}
	printf("\n");

	/* rows is a list of lists of strings, free inner lists here */
	for(i = rows; i; i = alpm_list_next(i)) {
		alpm_list_t *lp = i->data;
		FREELIST(lp);
	}
	alpm_list_free(rows);
	FREELIST(names);
	free(str);

	if(dlsize > 0 || config->op_s_downloadonly) {
		size = humanize_size(dlsize, 'M', 2, &label);
		printf(_("Total Download Size:    %.2f %s\n"), size, label);
	}
	if(!config->op_s_downloadonly) {
		if(isize > 0) {
			size = humanize_size(isize, 'M', 2, &label);
			printf(_("Total Installed Size:   %.2f %s\n"), size, label);
		}
		if(rsize > 0 && isize == 0) {
			size = humanize_size(rsize, 'M', 2, &label);
			printf(_("Total Removed Size:     %.2f %s\n"), size, label);
		}
		/* only show this net value if different from raw installed size */
		if(isize > 0 && rsize > 0) {
			size = humanize_size(isize - rsize, 'M', 2, &label);
			printf(_("Net Upgrade Size:       %.2f %s\n"), size, label);
		}
	}
}
Example #24
0
/**
 * @brief Remove a specified list of packages.
 *
 * @param targets a list of packages (as strings) to remove from the system
 *
 * @return 0 on success, 1 on failure
 */
int pacman_remove(alpm_list_t *targets)
{
    int retval = 0;
    alpm_list_t *i, *data = NULL;

    if(targets == NULL) {
        pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
        return(1);
    }

    /* Step 0: create a new transaction */
    if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
        return(1);
    }

    /* Step 1: add targets to the created transaction */
    for(i = targets; i; i = alpm_list_next(i)) {
        char *targ = alpm_list_getdata(i);
        if(alpm_trans_addtarget(targ) == -1) {
            if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
                printf(_("%s not found, searching for group...\n"), targ);
                pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
                if(grp == NULL) {
                    pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
                    retval = 1;
                    goto cleanup;
                } else {
                    alpm_list_t *p, *pkgnames = NULL;
                    /* convert packages to package names */
                    for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
                        pmpkg_t *pkg = alpm_list_getdata(p);
                        pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
                    }
                    printf(_(":: group %s:\n"), targ);
                    list_display("   ", pkgnames);
                    int all = yesno(1, _("    Remove whole content?"));
                    for(p = pkgnames; p; p = alpm_list_next(p)) {
                        char *pkgn = alpm_list_getdata(p);
                        if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) {
                            if(alpm_trans_addtarget(pkgn) == -1) {
                                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
                                           alpm_strerrorlast());
                                retval = 1;
                                alpm_list_free(pkgnames);
                                goto cleanup;
                            }
                        }
                    }
                    alpm_list_free(pkgnames);
                }
            } else {
                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
                retval = 1;
                goto cleanup;
            }
        }
    }

    /* Step 2: prepare the transaction based on its type, targets and flags */
    if(alpm_trans_prepare(&data) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
                   alpm_strerrorlast());
        switch(pm_errno) {
        case PM_ERR_UNSATISFIED_DEPS:
            for(i = data; i; i = alpm_list_next(i)) {
                pmdepmissing_t *miss = alpm_list_getdata(i);
                pmdepend_t *dep = alpm_miss_get_dep(miss);
                char *depstring = alpm_dep_get_string(dep);
                printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
                       depstring);
                free(depstring);
            }
            FREELIST(data);
            break;
        default:
            break;
        }
        retval = 1;
        goto cleanup;
    }

    /* Warn user in case of dangerous operation */
    if(config->flags & PM_TRANS_FLAG_RECURSE ||
            config->flags & PM_TRANS_FLAG_CASCADE) {
        /* list transaction targets */
        alpm_list_t *pkglist = alpm_trans_get_pkgs();

        display_targets(pkglist, 0);
        printf("\n");

        /* get confirmation */
        if(yesno(1, _("Do you want to remove these packages?")) == 0) {
            retval = 1;
            goto cleanup;
        }
    }

    /* Step 3: actually perform the removal */
    if(alpm_trans_commit(NULL) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
                   alpm_strerrorlast());
        retval = 1;
    }

    /* Step 4: release transaction resources */
cleanup:
    if(trans_release() == -1) {
        retval = 1;
    }
    return(retval);
}
Example #25
0
static void files_filters_open(files_data* data) {
    list_display("Filters", "A: Toggle, B: Return", data, files_filters_update, NULL);
}
Example #26
0
File: main.c Project: Kv-Hu/iOSDemo
int main()
{
    //linklist
    list *l;
    int i;
    datatype arr[] = {12,9,23, 2,34,6,45};
    
    
    l = list_create();
    if (l == NULL)
        exit(1);
    
    for (i = 0; i < sizeof(arr)/sizeof(*arr); i++)
    {
        if (list_order_insert(l, &arr[i]))
            exit(1);
    }
    
    list_display(l);
    
    int err;
    datatype value;
    err = list_delete_at(l, 2, &value);
    if (err)
        exit(1);
    list_display(l);
    printf("delete:%d\n",value);
    
    /*
     int value = 12;
     list_delete(l , &value);
     list_display(l);
     */
    list_destroy(l);
    
    
    //栈
    STACK S;    //创建一个变量S,存储空间里面有PTop和PBottom,没有存放有效的数据,STACK等价于 struct Stack
    int val;
    init(&S); //初始化 目的是造出一个空栈
    push(&S, 1); //入栈
    push(&S, 2);
    push(&S, 3);
    push(&S, 4);
    push(&S, 5);
    push(&S, 6);
    traverse(&S);
    
    if (pop(&S,&val))
    {
        printf("出栈成功,出栈的元素是%d\n",val);
    }else{
        printf("出栈失败!\n");
    }
    
    
    traverse(&S); //遍历
    clearStack(&S);//清空栈
    traverse(&S);//遍历
    return 0;
}
Example #27
0
static void titles_options_open(titles_data* data) {
    list_display("Options", "A: Toggle, B: Return", data, titles_options_update, NULL);
}
Example #28
0
/* TODO this is one of the worst ever functions written. void *data ? wtf */
void cb_question(alpm_question_t event, void *data1, void *data2,
                   void *data3, int *response)
{
	if(config->print) {
		if(event == ALPM_QUESTION_INSTALL_IGNOREPKG) {
			*response = 1;
		} else {
			*response = 0;
		}
		return;
	}
	switch(event) {
		case ALPM_QUESTION_INSTALL_IGNOREPKG:
			if(!config->op_s_downloadonly) {
				*response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"),
								alpm_pkg_get_name(data1));
			} else {
				*response = 1;
			}
			break;
		case ALPM_QUESTION_REPLACE_PKG:
			*response = yesno(_("Replace %s with %s/%s?"),
					alpm_pkg_get_name(data1),
					(char *)data3,
					alpm_pkg_get_name(data2));
			break;
		case ALPM_QUESTION_CONFLICT_PKG:
			/* data parameters: target package, local package, conflict (strings) */
			/* print conflict only if it contains new information */
			if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) {
				*response = noyes(_("%s and %s are in conflict. Remove %s?"),
						(char *)data1,
						(char *)data2,
						(char *)data2);
			} else {
				*response = noyes(_("%s and %s are in conflict (%s). Remove %s?"),
						(char *)data1,
						(char *)data2,
						(char *)data3,
						(char *)data2);
			}
			break;
		case ALPM_QUESTION_REMOVE_PKGS:
			{
				alpm_list_t *unresolved = data1;
				alpm_list_t *namelist = NULL, *i;
				size_t count = 0;
				for(i = unresolved; i; i = i->next) {
					namelist = alpm_list_add(namelist,
							(char *)alpm_pkg_get_name(i->data));
					count++;
				}
				colon_printf(_n(
							"The following package cannot be upgraded due to unresolvable dependencies:\n",
							"The following packages cannot be upgraded due to unresolvable dependencies:\n",
							count));
				list_display("     ", namelist, getcols(fileno(stdout)));
				printf("\n");
				*response = noyes(_n(
							"Do you want to skip the above package for this upgrade?",
							"Do you want to skip the above packages for this upgrade?",
							count));
				alpm_list_free(namelist);
			}
			break;
		case ALPM_QUESTION_SELECT_PROVIDER:
			{
				alpm_list_t *providers = data1;
				size_t count = alpm_list_count(providers);
				char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2);
				colon_printf(_("There are %zd providers available for %s:\n"), count,
						depstring);
				free(depstring);
				select_display(providers);
				*response = select_question(count);
			}
			break;
		case ALPM_QUESTION_CORRUPTED_PKG:
			*response = yesno(_("File %s is corrupted (%s).\n"
						"Do you want to delete it?"),
					(char *)data1,
					alpm_strerror(*(alpm_errno_t *)data2));
			break;
		case ALPM_QUESTION_IMPORT_KEY:
			{
				alpm_pgpkey_t *key = data1;
				char created[12];
				time_t time = (time_t)key->created;
				strftime(created, 12, "%Y-%m-%d", localtime(&time));

				if(key->revoked) {
					*response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"),
							key->length, key->pubkey_algo, key->fingerprint, key->uid, created);
				} else {
					*response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"),
							key->length, key->pubkey_algo, key->fingerprint, key->uid, created);
				}
			}
			break;
	}
	if(config->noask) {
		if(config->ask & event) {
			/* inverse the default answer */
			*response = !*response;
		}
	}
}
Example #29
0
void mainmenu_open() {
    list_display("Main Menu", "A: Select, START: Exit", NULL, mainmenu_update, mainmenu_draw_top);
}
Example #30
0
/* prepare a list of pkgs to display */
static void _display_targets(alpm_list_t *targets, int verbose)
{
	char *str;
	off_t isize = 0, rsize = 0, dlsize = 0;
	unsigned short cols;
	alpm_list_t *i, *names = NULL, *header = NULL, *rows = NULL;

	if(!targets) {
		return;
	}

	/* gather package info */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(target->install) {
			dlsize += alpm_pkg_download_size(target->install);
			isize += alpm_pkg_get_isize(target->install);
		}
		if(target->remove) {
			/* add up size of all removed packages */
			rsize += alpm_pkg_get_isize(target->remove);
		}
	}

	/* form data for both verbose and non-verbose display */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(verbose) {
			rows = alpm_list_add(rows, create_verbose_row(target));
		}

		if(target->install) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
					alpm_pkg_get_version(target->install));
		} else if(isize == 0) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		} else {
			pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove), _("removal"));
		}
		names = alpm_list_add(names, str);
	}

	/* print to screen */
	pm_asprintf(&str, "%s (%zd)", _("Packages"), alpm_list_count(targets));
	printf("\n");

	cols = getcols(fileno(stdout));
	if(verbose) {
		header = create_verbose_header(alpm_list_count(targets));
		if(table_display(header, rows, cols) != 0) {
			/* fallback to list display if table wouldn't fit */
			list_display(str, names, cols);
		}
	} else {
		list_display(str, names, cols);
	}
	printf("\n");

	table_free(header, rows);
	FREELIST(names);
	free(str);
	rows = NULL;

	if(dlsize > 0 || config->op_s_downloadonly) {
		add_transaction_sizes_row(&rows, _("Total Download Size:"), dlsize);
	}
	if(!config->op_s_downloadonly) {
		if(isize > 0) {
			add_transaction_sizes_row(&rows, _("Total Installed Size:"), isize);
		}
		if(rsize > 0 && isize == 0) {
			add_transaction_sizes_row(&rows, _("Total Removed Size:"), rsize);
		}
		/* only show this net value if different from raw installed size */
		if(isize > 0 && rsize > 0) {
			add_transaction_sizes_row(&rows, _("Net Upgrade Size:"), isize - rsize);
		}
	}
	table_display(NULL, rows, cols);
	table_free(NULL, rows);
}