コード例 #1
0
ファイル: program11_07.c プロジェクト: NoMan2000/c-prog
// List the node values in ascending sequence 
void list_nodes(Node *pNode)
{
  if(pNode->pLeft)
    list_nodes(pNode->pLeft);

  printf_s("%10d x %10ld\n", pNode->count, pNode->item);

  if(pNode->pRight)
    list_nodes(pNode->pRight);
}
コード例 #2
0
ファイル: exp11.c プロジェクト: qh997/CLearning
int main()
{
    print_title("exp11");

    print_title("bit");
    {
        struct
        {
            unsigned int flag1 : 1;
            unsigned int flag2 : 1;
            unsigned int flag3 : 2;
            unsigned int flag4 : 3;
        } indicators;
        indicators.flag4 = 5;
        printf("%X\n", indicators.flag4);
    }

    print_title("Binary tree");
    {
        struct Node *pRoot = NULL;

        pRoot = create_node(127L);
        add_node(pRoot, 56L);
        add_node(pRoot, 99L);
        add_node(pRoot, 335L);
        add_node(pRoot, 12L);
        add_node(pRoot, 79L);
        add_node(pRoot, 997L);
        list_nodes(pRoot);
    }

    return 0;
}
コード例 #3
0
ファイル: exp11.c プロジェクト: qh997/CLearning
void list_nodes(struct Node *pNode)
{
    if (NULL != pNode->pLeft)
    {
        list_nodes(pNode->pLeft);
    }

    for (int i = 0; i < pNode->count; i++)
    {
        printf("%10ld\n", pNode->item);
    }
    if (NULL != pNode->pRight)
    {
        list_nodes(pNode->pRight);
    }
}
コード例 #4
0
ファイル: cli.c プロジェクト: chaos/powerman
int
main(int argc, char *argv[])
{
    pm_err_t err = PM_ESUCCESS;
    pm_node_state_t ns;
    pm_handle_t pm;
    char ebuf[64];
    char *server, *node = NULL;
    char cmd;

    if (argc < 3 || argc > 4)
        usage();
    server = argv[1];
    cmd = argv[2][0];
    if (argc == 3 && cmd != 'l')
        usage();
    if (argc == 4 && cmd != '1' && cmd != '0' && cmd != 'c' && cmd != 'q')
        usage();
    if (argc == 4)
        node = argv[3];

    if ((err = pm_connect(server, NULL, &pm, 0)) != PM_ESUCCESS) {
        fprintf(stderr, "%s: %s\n", server,
                pm_strerror(err, ebuf, sizeof(ebuf)));
        exit(1);
    }

    switch (cmd) {
        case '1':
            err = pm_node_on(pm, node);
            break;
        case '0':
            err = pm_node_off(pm, node);
            break;
        case 'c':
            err = pm_node_cycle(pm, node);
            break;
        case 'l':
            err = list_nodes(pm);
            break;
        case 'q':
            ns = PM_UNKNOWN;
            if ((err = pm_node_status(pm, node, &ns)) == PM_ESUCCESS)
                printf("%s: %s\n", node, statstr(ns));
            break;
    }

    if (err != PM_ESUCCESS) {
        fprintf(stderr, "Error: %s\n", pm_strerror(err, ebuf, sizeof(ebuf)));
        pm_disconnect(pm);
        exit(1);
    }

    pm_disconnect(pm);

    exit(0);
}
コード例 #5
0
ファイル: testhi.c プロジェクト: AnotherView/cups
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  help_index_t	*hi,			/* Help index */
		*search;		/* Search index */


 /*
  * Load the help index...
  */

  hi = helpLoadIndex("testhi.index", ".");

  list_nodes("nodes", hi->nodes);
  list_nodes("sorted", hi->sorted);

 /*
  * Do any searches...
  */

  if (argc > 1)
  {
    search = helpSearchIndex(hi, argv[1], NULL, argv[2]);

    if (search)
    {
      list_nodes(argv[1], search->sorted);
      helpDeleteIndex(search);
    }
    else
      printf("%s (0 nodes)\n", argv[1]);
  }

  helpDeleteIndex(hi);

 /*
  * Return with no errors...
  */

  return (0);
}
コード例 #6
0
ファイル: program11_07.c プロジェクト: NoMan2000/c-prog
// Function main - execution starts here 
int main(void)
{
  long newvalue = 0;
  Node *pRoot = NULL;
  char answer = 'n';
  do
  {
    printf_s("Enter the node value: ");
    scanf_s(" %ld", &newvalue);
    if(!pRoot)
      pRoot = create_node(newvalue);
    else
      add_node(newvalue, pRoot);
    printf_s("Do you want to enter another (y or n)? ");
    scanf_s(" %c", &answer, sizeof(answer));
  } while(tolower(answer) == 'y');

  printf_s("The values in ascending sequence are:\n");
  list_nodes(pRoot);                             // Output the contents of the tree 
  free_nodes(pRoot);                             // Release the heap memory         

  return 0;
}
コード例 #7
0
ファイル: websearch.c プロジェクト: jelmer/cups
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line args */
     char *argv[])			/* I - Command-line arguments */
{
  help_index_t	*hi,			/* Help index */
		*search;		/* Search index */
  char		indexname[1024];	/* Name of index file */


  if (argc != 3)
  {
    puts("Usage: websearch directory \"search terms\"");
    return (1);
  }

 /*
  * Load the help index...
  */

  snprintf(indexname, sizeof(indexname), "%s/.index", argv[1]);
  hi = helpLoadIndex(indexname, argv[1]);

 /*
  * Do any searches...
  */

  search = helpSearchIndex(hi, argv[2], NULL, NULL);

  if (search)
    list_nodes(hi, argv[1], search->sorted);

 /*
  * Return with no errors...
  */

  return (0);
}
コード例 #8
0
int main(int argc, char **argv)
{
	struct ibnd_config config = { 0 };
	ibnd_fabric_t *fabric = NULL;
	ibnd_fabric_t *diff_fabric = NULL;

	const struct ibdiag_opt opts[] = {
		{"full", 'f', 0, NULL, "show full information (ports' speed and width)"},
		{"show", 's', 0, NULL, "show more information"},
		{"list", 'l', 0, NULL, "list of connected nodes"},
		{"grouping", 'g', 0, NULL, "show grouping"},
		{"Hca_list", 'H', 0, NULL, "list of connected CAs"},
		{"Switch_list", 'S', 0, NULL, "list of connected switches"},
		{"Router_list", 'R', 0, NULL, "list of connected routers"},
		{"node-name-map", 1, 1, "<file>", "node name map file"},
		{"cache", 2, 1, "<file>",
		 "filename to cache ibnetdiscover data to"},
		{"load-cache", 3, 1, "<file>",
		 "filename of ibnetdiscover cache to load"},
		{"diff", 4, 1, "<file>",
		 "filename of ibnetdiscover cache to diff"},
		{"diffcheck", 5, 1, "<key(s)>",
		 "specify checks to execute for --diff"},
		{"ports", 'p', 0, NULL, "obtain a ports report"},
		{"max_hops", 'm', 0, NULL,
		 "report max hops discovered by the library"},
		{"outstanding_smps", 'o', 1, NULL,
		 "specify the number of outstanding SMP's which should be "
		 "issued during the scan"},
		{0}
	};
	char usage_args[] = "[topology-file]";

	ibdiag_process_opts(argc, argv, &config, "DGKLs", opts, process_opt,
			    usage_args, NULL);

	f = stdout;

	argc -= optind;
	argv += optind;

	if (ibd_timeout)
		config.timeout_ms = ibd_timeout;

	config.flags = ibd_ibnetdisc_flags;

	if (argc && !(f = fopen(argv[0], "w")))
		IBERROR("can't open file %s for writing", argv[0]);

	config.mkey = ibd_mkey;

	node_name_map = open_node_name_map(node_name_map_file);

	if (diff_cache_file &&
	    !(diff_fabric = ibnd_load_fabric(diff_cache_file, 0)))
		IBERROR("loading cached fabric for diff failed\n");

	if (load_cache_file) {
		if ((fabric = ibnd_load_fabric(load_cache_file, 0)) == NULL)
			IBERROR("loading cached fabric failed\n");
	} else {
		if ((fabric =
		     ibnd_discover_fabric(ibd_ca, ibd_ca_port, NULL, &config)) == NULL)
			IBERROR("discover failed\n");
	}

	if (ports_report)
		ibnd_iter_nodes(fabric, dump_ports_report, NULL);
	else if (list)
		list_nodes(fabric, list);
	else if (diff_fabric)
		diff(diff_fabric, fabric);
	else
		dump_topology(group, fabric);

	if (cache_file)
		if (ibnd_cache_fabric(fabric, cache_file, 0) < 0)
			IBERROR("caching ibnetdiscover data failed\n");

	ibnd_destroy_fabric(fabric);
	if (diff_fabric)
		ibnd_destroy_fabric(diff_fabric);
	close_node_name_map(node_name_map);
	exit(0);
}