int
main(int argc, char *argv[])
{
	int err, i;
	char *host=NULL;
	int port=7777;
	int nmixers=0;
	extern int mixlib_trace;
	int interactive=0;

	//mixlib_trace=1;

	while ((i = getopt(argc, argv, "ip:h:")) != EOF)
	switch (i)
	{
	case 'i':
		interactive=1;
		break;
	case 'p':
		port = atoi(optarg);
		break;

	case 'h':
		host=optarg;
		break;
	}

	if ((err=ossmix_init())<0)
	{
		fprintf(stderr, "ossmix_init() failed, err=%d\n");
		exit(EXIT_FAILURE);
	}

	if ((err=ossmix_connect(host, port))<0)
	{
		fprintf(stderr, "ossmix_connect() failed, err=%d\n", err);
		exit(EXIT_FAILURE);
	}

	if ((nmixers=ossmix_get_nmixers())<0)
	{
		fprintf(stderr, "ossmix_get_nmixers() failed, err=%d\n", nmixers);
		exit(EXIT_FAILURE);
	}

	printf("Number of mixers=%d\n", nmixers);

	for (i=0;i<nmixers;i++)
	{
		oss_mixerinfo mi;
		int n, ctl;

		if (ossmix_get_mixerinfo(i, &mi)<0)
		{
			fprintf(stderr, "ossmix_get_mixerinfo(%d) failed\n", i);
			exit(EXIT_FAILURE);
		}

		printf("Mixer %2d: %s\n", i, mi.name);

		if (ossmix_open_mixer(i)<0)
		{
			fprintf(stderr, "ossmix_open_mixer(%d) failed\n", i);
			exit(EXIT_FAILURE);
		}

		if ((n=ossmix_get_nrext(i))<0)
		{
			fprintf(stderr, "ossmix_get_nrext(%d) failed, err=\n", i, n);
			exit(EXIT_FAILURE);
		}

		printf("Mixer has %d nodes\n", n);

		for (ctl=0;ctl<n;ctl++)
		{
			oss_mixext node;
			int value=0;

			if (ossmix_get_nodeinfo(i, ctl, &node)<0)
			{
				fprintf(stderr, "ossmix_get_nodeinfo(%d, %d) failed\n",
						i, ctl);
				exit(EXIT_FAILURE);

			}

			if (node.type != MIXT_DEVROOT && node.type != MIXT_GROUP && node.type != MIXT_MARKER)
			if ((value=ossmix_get_value(i, ctl, node.timestamp))<0)
			{
				fprintf(stderr, "ossmix_get_value(%d, %d, %d) failed, err=%d\n",
						i, ctl, node.timestamp, value);
			}

			printf("%3d: %s = 0x%08x\n", ctl, node.extname, value);

			if (node.type == MIXT_ENUM)
			   print_enum_list(i, ctl);

			if (node.flags & MIXF_DESCR)
			   print_description(i, ctl);
			   
		}

		if (!interactive)
		   ossmix_close_mixer(i);
	}

	if (interactive)
	   interactive_mode();

printf("Disconnecting\n");
	ossmix_disconnect();

	exit(EXIT_SUCCESS);
}
Esempio n. 2
0
/* Builds and outputs to stdout the action table for the parser,
   including enumerated types for actions and lexemes. */
static void
build_action_table (void)
{
  unsigned char **actions;
  int i;

  actions = xmalloc (sizeof *actions * nC);
  for (i = 0; i < nC; i++)
    {
      actions[i] = xmalloc (sizeof **actions * (n_symbols + 1));
      memset (actions[i], 0, sizeof **actions * (n_symbols + 1));
    }

  for (i = 0; i < nC; i++)
    {
      int j;

      for (j = 0; j < list_count (&C[i]); j++)
	{
	  const struct item *item = list_item (&C[i], j);
	  const struct production *prod = &G[item->prod];
	  const struct symbol *A = find_symbol (prod->left);
	  
	  if (item_n_after_dot (item) > 0)
	    {
	      struct symbol *a;

	      a = find_symbol (item_symbol_after_dot (item));
	      if (!a->nonterminal)
		{
		  struct list list;
		  int k;

		  calc_goto (&list, &C[i], a->sym);
		  
		  for (k = 0; k < nC; k++)
		    if (list_equal (&list, &C[k]))
		      set_action (actions, i, a - symbols, 2 + k);

		  list_free (&list);
		}
	    }
	  else if (A->sym != G[0].left)
	    {
	      const struct set *follow_A = &A->follow;
	      int k;

	      for (k = 0; k < follow_A->n; k++)
		{
		  int c;
		  int index;

		  c = follow_A->which[k];
		  if (c == '$')
		    index = n_symbols;
		  else
		    index = find_symbol (c) - symbols;
		  
		  set_action (actions, i, index, 2 + nC + (prod - G));
		}
	    }

	  if (list_contains (&C[i], 0, 1))
	    set_action (actions, i, n_symbols, 1);
	}
    }

  fputs ("/* Actions used in action_table[][] entries. */\n"
	 "enum\n"
	 "  {\n"
	 "    err,\t/* Error. */\n"
	 "    acc,\t/* Accept. */\n"
	 "\n"
	 "    /* Shift actions. */\n", stdout);

  print_enum_list ('s', 0, nC - 1);

  fputs ("\n"
	 "    /* Reduce actions. */\n", stdout);
  print_enum_list ('r', 1, n_grammar);

  printf ("\n"
	  "    n_states = %d,\n"
	  "    n_terminals = %d,\n"
	  "    n_nonterminals = %d,\n"
	  "    n_reductions = %d\n"
	  "  };\n"
	  "\n"
	  "/* Symbolic token names used in parse_table[][] second index. */\n"
	  "enum\n"
	  "  {\n",
	  nC, n_terminals + 1, n_nonterminals, n_grammar);
  
  for (i = 0; i < n_symbols; i++)
    {
      struct symbol *sym = &symbols[i];
      int j;

      if (sym->nonterminal)
	continue;

      for (j = 0; j < n_tokens; j++)
	if (tokens[j].token == sym->sym)
	  break;
      assert (j < n_tokens);
      
      printf ("    %s,%*c/* %c */\n",
	      tokens[j].name, 25 - (int) strlen (tokens[j].name), ' ',
	      sym->sym);
    }

  fputs ("    lex_stop                  /* $ */\n"
	 "  };\n"
	 "\n"
	 "/* Action table.  This is action[][] from Fig. 4.30, \"LR parsing\n"
	 "   program\", in Aho, Sethi, and Ullman. */\n"
	 "static const unsigned char action_table[n_states][n_terminals] =\n"
	 "  {\n"
	 "    /*        ", stdout);
  for (i = 0; i < n_symbols; i++)
    if (!symbols[i].nonterminal)
      printf ("  %c ", symbols[i].sym);
  fputs ("  $ */\n", stdout);
  for (i = 0; i < nC; i++)
    {
      int j;
      
      printf ("    /*%3d */ {", i);
      for (j = 0; j <= n_symbols; j++)
	if (j == n_symbols || !symbols[j].nonterminal)
	  {
	    char buf[16];
	    if (j != 0)
	      putchar (',');

	    action_name (buf, actions[i][j]);
	    printf ("%3s", buf);
	  }
      fputs ("},\n", stdout);
    }
  fputs ("  };\n\n", stdout);
      
  for (i = 0; i < nC; i++)
    free (actions[i]);
  free (actions);
}