int main()
{
    double a[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
    int n = sizeof(a) / sizeof(a[0]);

    // An initially empty list
    struct Node *list = NULL;

    int i;
    for (i = 0; i < n; i++) {
        list = prepend(list, a[i]);
    }

    // print the list, apply 2^x, and print the list again.
    print(list);
    apply(list, exp2);
    print(list);

    // remove first and print.
    list = remove_front(list);
    print(list);

    // remove first and print one more time.
    list = remove_front(list);
    print(list);

    // remove all nodes
    list = remove_all_nodes(list);
    assert(list == NULL);

    return 0;
}
コード例 #2
0
ファイル: piclfrutree.c プロジェクト: AlainODea/illumos-gate
/*
 * This function is the fini entry point of the plugin
 */
static void
picl_frutree_fini(void)
{
	/* Unregister the event handler routine */
	(void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED,
	    picl_frutree_evhandler, NULL);
	(void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED,
	    picl_frutree_evhandler, NULL);

	(void) remove_all_nodes(frutreeh);
}
コード例 #3
0
ファイル: piclfrutree.c プロジェクト: AlainODea/illumos-gate
/*
 * This function is the init entry point of the plugin.
 * It initializes the /frutree tree
 */
static void
picl_frutree_init()
{
	int		err;

	err = add_all_nodes();
	if (err != PICL_SUCCESS) {
		(void) remove_all_nodes(frutreeh);
		return;
	}

	/* Register the event handler routine */
	(void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED,
	    picl_frutree_evhandler, NULL);
	(void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED,
	    picl_frutree_evhandler, NULL);
}
コード例 #4
0
ファイル: piclfrutree.c プロジェクト: AlainODea/illumos-gate
/* Deletes and destroys all PICL nodes for which rooth is a ancestor */
static int
remove_all_nodes(picl_nodehdl_t rooth)
{
	picl_nodehdl_t		chdh;
	int			err, done = 0;

	while (!done) {
		err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh,
		    sizeof (picl_nodehdl_t));
		if (err != PICL_PROPNOTFOUND) {
			(void) remove_all_nodes(chdh);
		} else {
			err = ptree_delete_node(rooth);
			if (err != PICL_SUCCESS) {
				return (err);
			} else {
				(void) ptree_destroy_node(rooth);
			}
			done = 1;
		}
	}
	return (PICL_SUCCESS);
}
コード例 #5
0
ファイル: piclfrutree.c プロジェクト: AlainODea/illumos-gate
/* Hotplug routine used to remove an existing CPU Mem Module */
static int
remove_cpu_module(int slotnum)
{
	picl_nodehdl_t		cpumemsloth;
	picl_nodehdl_t		cpumemmodh;
	int			err;

	/* Find the node for the given CPU Memory module slot */
	if (ptree_get_node_by_path(frutree_cpu_module[slotnum],
	    &cpumemsloth) == PICL_SUCCESS) {
		/* Make sure it's got a child, then delete it */
		err = ptree_get_propval_by_name(cpumemsloth, PICL_PROP_CHILD,
		    &cpumemmodh, sizeof (picl_nodehdl_t));
		if (err != PICL_SUCCESS) {
			return (err);
		}

		err = remove_all_nodes(cpumemmodh);
		if (err != PICL_SUCCESS) {
			return (err);
		}
	}
	return (PICL_SUCCESS);
}