示例#1
0
int main(int argc, char *argv[])
{
	int ret = 0;
	int cast_vote = 1, master_wins = 0;
	int pollcount=0, polltime=1, quiet=0, once=0;
	int send_old_ringid = 0;
	int err;
	int opt;
	votequorum_callbacks_t callbacks;
	const char *devicename = "QDEVICE";
	const char *options = "F:n:p:t:cmq1h";

	memset(&callbacks, 0, sizeof(callbacks));
	callbacks.votequorum_notify_fn = votequorum_notification_fn;

	while ((opt = getopt(argc, argv, options)) != -1) {
		switch (opt) {
		case 'm':
		        master_wins = 1;
			break;
		case 'c':
		        cast_vote = 1;
			break;
		case '1':
		        once = 1;
			break;
		case 'q':
		        quiet = 1;
			break;
		case 'F':
		        send_old_ringid = atoi(optarg)+1;
			break;
		case 'p':
		        pollcount = atoi(optarg)+1;
			break;
		case 'n':
		        devicename = strdup(optarg);
			break;
		case 't':
		        polltime = atoi(optarg);
			break;
		case 'h':
		        usage(argv[0]);
			exit(0);
		}
	}

	if ( (err=votequorum_initialize(&handle, &callbacks)) != CS_OK) {
		fprintf(stderr, "votequorum_initialize FAILED: %d\n", err);
		return -1;
	}

	if (quiet && once) {
	        fprintf(stderr, "setting both -q (quet) and -1 (once) makes no sense\n");
		usage(argv[0]);
		exit(1);
	}

	if (!quiet) {
	        print_info(1);
	}
	if (once) {
	        exit(0);
	}

	if (argc >= 2) {
		if ( (err = votequorum_trackstart(handle, handle, CS_TRACK_CHANGES)) != CS_OK) {
			fprintf(stderr, "votequorum_trackstart FAILED: %d\n", err);
			ret = -1;
			goto out;
		}

		if ( (err=votequorum_qdevice_register(handle, devicename)) != CS_OK) {
			fprintf(stderr, "qdevice_register FAILED: %d\n", err);
			ret = -1;
			goto out;
		}

		if ( (err=votequorum_qdevice_master_wins(handle, devicename, master_wins)) != CS_OK) {
			fprintf(stderr, "qdevice_master_wins FAILED: %d\n", err);
			ret = -1;
			goto out;
		}


		while (--pollcount) {
			if (votequorum_dispatch(handle, CS_DISPATCH_ALL) != CS_OK) {
				fprintf(stderr, "votequorum_dispatch error\n");
                                ret = -1;
                                goto out;
                        }

		        if (!quiet) print_info(0);

			if (no_sent_old_ringid + 1 >= send_old_ringid) {
				/*
				 * Finally send correct ringid
				 */
				memcpy(&ring_id_to_send, &last_received_ring_id, sizeof(ring_id_to_send));
			} else {
				no_sent_old_ringid++;
			}

			if ((err=votequorum_qdevice_poll(handle, devicename, cast_vote, ring_id_to_send)) != CS_OK &&
			     err != CS_ERR_MESSAGE_ERROR) {
				fprintf(stderr, "qdevice poll FAILED: %d\n", err);
				ret = -1;
				goto out;
			}
			if (err == CS_ERR_MESSAGE_ERROR) {
				fprintf(stderr, "qdevice poll passed OLD ring_id\n");
			}

			if (!quiet) print_info(0);
			sleep(polltime);
		}
		if ((err= votequorum_qdevice_unregister(handle, devicename)) != CS_OK) {
			fprintf(stderr, "qdevice unregister FAILED: %d\n", err);
			ret = -1;
			goto out;
		}
	}

        if (!quiet) print_info(1);

out:
	votequorum_finalize(handle);
	return ret;
}
示例#2
0
文件: cli.c 项目: uvbs/SupportCenter
int
main (int argc, char **argv)
{
  int err, ret;
  int ii, i;
  char buffer[MAX_BUF + 1];
  char *session_data = NULL;
  char *session_id = NULL;
  size_t session_data_size;
  size_t session_id_size;
  fd_set rset;
  int maxfd;
  struct timeval tv;
  int user_term = 0;
  socket_st hd;

  gaa_parser (argc, argv);
  if (hostname == NULL)
    {
      fprintf (stderr, "No hostname given\n");
      exit (1);
    }

  sockets_init ();

#ifndef _WIN32
  signal (SIGPIPE, SIG_IGN);
#endif

  init_global_tls_stuff ();

  socket_open( &hd, hostname, service);
  socket_connect( &hd);

  hd.session = init_tls_session (hostname);
  if (starttls)
    goto after_handshake;

  for (i = 0; i < 2; i++)
    {


      if (i == 1)
	{
	  hd.session = init_tls_session (hostname);
	  gnutls_session_set_data (hd.session, session_data,
				   session_data_size);
	  free (session_data);
	}

      ret = do_handshake (&hd);

      if (ret < 0)
	{
	  fprintf (stderr, "*** Handshake has failed\n");
	  gnutls_perror (ret);
	  gnutls_deinit (hd.session);
	  return 1;
	}
      else
	{
	  printf ("- Handshake was completed\n");
	  if (gnutls_session_is_resumed (hd.session) != 0)
	    printf ("*** This is a resumed session\n");
	}



      if (resume != 0 && i == 0)
	{

	  gnutls_session_get_data (hd.session, NULL, &session_data_size);
	  session_data = malloc (session_data_size);

	  gnutls_session_get_data (hd.session, session_data,
				   &session_data_size);

	  gnutls_session_get_id (hd.session, NULL, &session_id_size);
	  session_id = malloc (session_id_size);
	  gnutls_session_get_id (hd.session, session_id, &session_id_size);

	  /* print some information */
	  print_info (hd.session, hostname);

	  printf ("- Disconnecting\n");
	  socket_bye (&hd);

	  printf
	    ("\n\n- Connecting again- trying to resume previous session\n");
          socket_open( &hd, hostname, service);
          socket_connect(&hd);
	}
      else
	{
	  break;
	}
    }

after_handshake:

  printf ("\n- Simple Client Mode:\n\n");

#ifndef _WIN32
  signal (SIGALRM, &starttls_alarm);
#endif

  /* do not buffer */
#if !(defined _WIN32 || defined __WIN32__)
  setbuf (stdin, NULL);
#endif
  setbuf (stdout, NULL);
  setbuf (stderr, NULL);

  for (;;)
    {
      if (starttls_alarmed && !hd.secure)
	{
	  fprintf (stderr, "*** Starting TLS handshake\n");
	  ret = do_handshake (&hd);
	  if (ret < 0)
	    {
	      fprintf (stderr, "*** Handshake has failed\n");
	      socket_bye (&hd);
	      user_term = 1;
	      break;
	    }
	}

      FD_ZERO (&rset);
      FD_SET (fileno (stdin), &rset);
      FD_SET (hd.fd, &rset);

      maxfd = MAX (fileno (stdin), hd.fd);
      tv.tv_sec = 3;
      tv.tv_usec = 0;

      err = select (maxfd + 1, &rset, NULL, NULL, &tv);
      if (err < 0)
	continue;

      if (FD_ISSET (hd.fd, &rset))
	{
	  memset (buffer, 0, MAX_BUF + 1);
	  ret = socket_recv (&hd, buffer, MAX_BUF);

	  if (ret == 0)
	    {
	      printf ("- Peer has closed the GNUTLS connection\n");
	      break;
	    }
	  else if (handle_error (&hd, ret) < 0 && user_term == 0)
	    {
	      fprintf (stderr,
		       "*** Server has terminated the connection abnormally.\n");
	      break;
	    }
	  else if (ret > 0)
	    {
	      if (verbose != 0)
		printf ("- Received[%d]: ", ret);
	      for (ii = 0; ii < ret; ii++)
		{
		  fputc (buffer[ii], stdout);
		}
	      fflush (stdout);
	    }

	  if (user_term != 0)
	    break;
	}

      if (FD_ISSET (fileno (stdin), &rset))
	{
	  if (fgets (buffer, MAX_BUF, stdin) == NULL)
	    {
	      if (hd.secure == 0)
		{
		  fprintf (stderr, "*** Starting TLS handshake\n");
		  ret = do_handshake (&hd);
		  if (ret < 0)
		    {
		      fprintf (stderr, "*** Handshake has failed\n");
		      socket_bye (&hd);
		      user_term = 1;
		    }
		}
	      else
		{
		  user_term = 1;
		  break;
		}
	      continue;
	    }

	  if (crlf != 0)
	    {
	      char *b = strchr (buffer, '\n');
	      if (b != NULL)
		strcpy (b, "\r\n");
	    }

	  ret = socket_send (&hd, buffer, strlen (buffer));

	  if (ret > 0)
	    {
	      if (verbose != 0)
		printf ("- Sent: %d bytes\n", ret);
	    }
	  else
	    handle_error (&hd, ret);

	}
    }

  if (user_term != 0)
    socket_bye (&hd);
  else
    gnutls_deinit (hd.session);

#ifdef ENABLE_SRP
  gnutls_srp_free_client_credentials (srp_cred);
#endif
#ifdef ENABLE_PSK
  gnutls_psk_free_client_credentials (psk_cred);
#endif

  gnutls_certificate_free_credentials (xcred);

#ifdef ENABLE_ANON
  gnutls_anon_free_client_credentials (anon_cred);
#endif

  gnutls_global_deinit ();

  return 0;
}
示例#3
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	struct sys_info *sysinfo = &sysinfo_car;
	u32 bsp_apicid = 0, val;
	msr_t msr;

	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */
		/* mov bsp to bus 0xff when > 8 nodes */
		set_bsp_node_CHtExtNodeCfgEn();
		enumerate_ht_chain();
	}

	post_code(0x30);

	if (bist == 0) {
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
		/* All cores run this but the BSP(node0,core0) is the only core that returns. */
	}

	post_code(0x32);

	w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
	console_init();

//	dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	// Load MPB
	val = cpuid_eax(1);
	printk(BIOS_DEBUG, "BSP Family_Model: %08x \n", val);
	printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
	printk(BIOS_DEBUG, "bsp_apicid = %02x \n", bsp_apicid);
	printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx \n", cpu_init_detectedx);

	/* Setup sysinfo defaults */
	set_sysinfo_in_ram(0);

#if CONFIG_UPDATE_CPU_MICROCODE
	update_microcode(val);
#endif
	post_code(0x33);

	cpuSetAMDMSR();
	post_code(0x34);

	amd_ht_init(sysinfo);
	post_code(0x35);

	/* Setup nodes PCI space and start core 0 AP init. */
	finalize_node_setup(sysinfo);

	/* Setup any mainboard PCI settings etc. */
	setup_mb_resource_map();
	post_code(0x36);

	/* wait for all the APs core0 started by finalize_node_setup. */
	/* FIXME: A bunch of cores are going to start output to serial at once.
	   It would be nice to fixup prink spinlocks for ROM XIP mode.
	   I think it could be done by putting the spinlock flag in the cache
	   of the BSP located right after sysinfo.
	 */
	wait_all_core0_started();

 #if CONFIG_LOGICAL_CPUS
	/* Core0 on each node is configured. Now setup any additional cores. */
	printk(BIOS_DEBUG, "start_other_cores()\n");
	start_other_cores();
	post_code(0x37);
	wait_all_other_cores_started(bsp_apicid);
 #endif

	post_code(0x38);

 #if CONFIG_SET_FIDVID
	msr = rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);

	/* FIXME: The sb fid change may survive the warm reset and only
	   need to be done once.*/
	enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);

	post_code(0x39);

	if (!warm_reset_detect(0)) {			// BSP is node 0
		init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
	} else {
		init_fidvid_stage2(bsp_apicid, 0);	// BSP is node 0
	}

	post_code(0x3A);

	/* show final fid and vid */
	msr=rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);
 #endif

	/* Reset for HT, FIDVID, PLL and errata changes to take affect. */
	if (!warm_reset_detect(0)) {
		print_info("...WARM RESET...\n\n\n");
		soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
		die("After soft_reset_x - shouldn't see this message!!!\n");
	}

	post_code(0x3B);

	/* FIXME:  Move this to chipset init.
	enable cf9 for hard reset */
	print_debug("enable_cf9_x()\n");
	enable_cf9_x(sysinfo->sbbusn, sysinfo->sbdn);
	post_code(0x3C);

	/* It's the time to set ctrl in sysinfo now; */
	printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
	post_code(0x3D);

	printk(BIOS_DEBUG, "enable_smbus()\n");
	enable_smbus();
	post_code(0x3E);

	memreset_setup();
	post_code(0x40);

//	die("Die Before MCT init.");

	printk(BIOS_DEBUG, "raminit_amdmct()\n");
	raminit_amdmct(sysinfo);
	post_code(0x41);

/*
	dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
*/

//	die("After MCT init before CAR disabled.");

	post_code(0x42);
	post_cache_as_ram();	// BSP switch stack to ram, copy then execute LB.
	post_code(0x43);	// Should never see this post code.
}
示例#4
0
文件: shoutcast.cpp 项目: atmos/butt
int sc_connect()
{
    int ret;
    char recv_buf[100];
    char send_buf[100];

    stream_socket = sock_connect(cfg.srv[cfg.selected_srv]->addr,
            cfg.srv[cfg.selected_srv]->port+1, CONN_TIMEOUT);

    if(stream_socket < 0)
    {
        switch(stream_socket)
        {
            case SOCK_ERR_CREATE:
                print_info("\nconnect: could not create network socket", 1);
                ret = 2;
                break;
            case SOCK_ERR_RESOLVE:
                print_info("\nconnect: error resolving server address", 1);
                ret = 1;
                break;
            case SOCK_TIMEOUT:
            case SOCK_INVALID:
                ret = 1;
                break;
            default:
                ret = 2;
        }

        sc_disconnect();
        return ret;
    }

    /*
    ret = sock_setbufsize(&stream_socket, 8192, 0);
    if(ret == SOCK_ERR_SET_SBUF)
        print_info("\nWarning: couldn't set socket SO_SNDBUF", 1);
    */
    sock_send(&stream_socket, cfg.srv[cfg.selected_srv]->pwd,
            strlen(cfg.srv[cfg.selected_srv]->pwd), SEND_TIMEOUT);
    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);


    if((ret = sock_recv(&stream_socket, recv_buf, sizeof(recv_buf)-1, RECV_TIMEOUT)) == 0)
    {
        usleep(100000);
        sc_disconnect();
        return 1;
    }

    if( (recv_buf[0] != 'O') || (recv_buf[1] != 'K') || (ret <= 2) )
    {
        if(strstr(recv_buf, "invalid password") != NULL)
        {
            print_info("\nconnect: invalid password!\n", 1);
            sc_disconnect();
            return 2;
        }
        return 1;
    }

    sock_send(&stream_socket, "icy-name:", 9, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->desc != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->desc,
                    strlen(cfg.icy[cfg.selected_icy]->desc), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-genre:", 10, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->genre != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->genre,
                   strlen(cfg.icy[cfg.selected_icy]->genre), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-url:", 8, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->url != NULL)
        send(stream_socket, cfg.icy[cfg.selected_icy]->url,
                strlen(cfg.icy[cfg.selected_icy]->url), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-irc:", 8, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->irc != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->irc,
                    strlen(cfg.icy[cfg.selected_icy]->irc), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-icq:", 8, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->icq != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->icq,
                    strlen(cfg.icy[cfg.selected_icy]->icq), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-aim:", 8, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->aim != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->aim,
                    strlen(cfg.icy[cfg.selected_icy]->aim), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-pub:", 8, SEND_TIMEOUT);
    if(cfg.main.num_of_icy > 0)
        if(cfg.icy[cfg.selected_icy]->pub != NULL)
            send(stream_socket, cfg.icy[cfg.selected_icy]->pub,
                    strlen(cfg.icy[cfg.selected_icy]->pub), 0);

    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "icy-br:", 7, SEND_TIMEOUT);
    snprintf(send_buf, 100, "%u", cfg.audio.bitrate);
    sock_send(&stream_socket, send_buf, strlen(send_buf), SEND_TIMEOUT);
    sock_send(&stream_socket, "\n", 1, SEND_TIMEOUT);

    sock_send(&stream_socket, "content-type:", 13, SEND_TIMEOUT);

    if(!strcmp(cfg.audio.codec, "mp3"))
    {
        strcpy(send_buf, "audio/mpeg");
        sock_send(&stream_socket, send_buf, strlen(send_buf), SEND_TIMEOUT);
    }

    sock_send(&stream_socket, "\n\n", 2, SEND_TIMEOUT);

    connected = 1;

    timer_init(&stream_timer, 1);       //starts the "online" timer

    return 0;
}
示例#5
0
文件: iwinfo_cli.c 项目: 7LK/McWRT
int main(int argc, char **argv)
{
	int i;
	char *p;
	const struct iwinfo_ops *iw;
	glob_t globbuf;

	if (argc > 1 && argc < 3)
	{
		fprintf(stderr,
			"Usage:\n"
			"	iwinfo <device> info\n"
			"	iwinfo <device> scan\n"
			"	iwinfo <device> txpowerlist\n"
			"	iwinfo <device> freqlist\n"
			"	iwinfo <device> assoclist\n"
			"	iwinfo <device> countrylist\n"
		);

		return 1;
	}

	if (argc == 1)
	{
		glob("/sys/class/net/*", 0, NULL, &globbuf);

		for (i = 0; i < globbuf.gl_pathc; i++)
		{
			p = strrchr(globbuf.gl_pathv[i], '/');

			if (!p)
				continue;

			iw = iwinfo_backend(++p);

			if (!iw)
				continue;

			print_info(iw, p);
			printf("\n");
		}

		globfree(&globbuf);
		return 0;
	}

	iw = iwinfo_backend(argv[1]);

	if (!iw)
	{
		fprintf(stderr, "No such wireless device: %s\n", argv[1]);
		return 1;
	}

	for (i = 2; i < argc; i++)
	{
		switch(argv[i][0])
		{
		case 'i':
			print_info(iw, argv[1]);
			break;

		case 's':
			print_scanlist(iw, argv[1]);
			break;

		case 't':
			print_txpwrlist(iw, argv[1]);
			break;

		case 'f':
			print_freqlist(iw, argv[1]);
			break;

		case 'a':
			print_assoclist(iw, argv[1]);
			break;

		case 'c':
			print_countrylist(iw, argv[1]);
			break;

		default:
			fprintf(stderr, "Unknown command: %s\n", argv[i]);
			return 1;
		}
	}

	iwinfo_finish();

	return 0;
}
示例#6
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	struct sys_info *sysinfo = &sysinfo_car;
	u32 bsp_apicid = 0, val;
	msr_t msr;

	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */
		/* mov bsp to bus 0xff when > 8 nodes */
		set_bsp_node_CHtExtNodeCfgEn();
		enumerate_ht_chain();
		bcm5785_enable_lpc();
		pc87417_enable_dev(RTC_DEV); /* Enable RTC */
	}

	post_code(0x30);

	if (bist == 0)
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);

	pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);

	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV

	val = cpuid_eax(1);
	printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
	printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
	printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
	printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);

	/* Setup sysinfo defaults */
	set_sysinfo_in_ram(0);

#if CONFIG_UPDATE_CPU_MICROCODE
	update_microcode(val);
#endif
	post_code(0x33);

	cpuSetAMDMSR();
	post_code(0x34);

	amd_ht_init(sysinfo);
	post_code(0x35);

	/* Setup nodes PCI space and start core 0 AP init. */
	finalize_node_setup(sysinfo);

	post_code(0x36);

	/* wait for all the APs core0 started by finalize_node_setup. */
	/* FIXME: A bunch of cores are going to start output to serial at once.
	 * It would be nice to fixup prink spinlocks for ROM XIP mode.
	 * I think it could be done by putting the spinlock flag in the cache
	 * of the BSP located right after sysinfo.
	 */

	wait_all_core0_started();

#if CONFIG_LOGICAL_CPUS
	/* Core0 on each node is configured. Now setup any additional cores. */
	printk(BIOS_DEBUG, "start_other_cores()\n");
	start_other_cores();
	post_code(0x37);
	wait_all_other_cores_started(bsp_apicid);
#endif

#if CONFIG_SET_FIDVID
	msr = rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);

	/* FIXME: The sb fid change may survive the warm reset and only
	 * need to be done once.*/

	enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);

	post_code(0x39);

	if (!warm_reset_detect(0)) {                    // BSP is node 0
		init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
	} else {
		init_fidvid_stage2(bsp_apicid, 0);      // BSP is node 0
	}

	post_code(0x3A);

	/* show final fid and vid */
	msr=rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
#endif

	init_timer();

	/* Reset for HT, FIDVID, PLL and errata changes to take affect. */
	if (!warm_reset_detect(0)) {
		print_info("...WARM RESET...\n\n\n");
		soft_reset();
		die("After soft_reset_x - shouldn't see this message!!!\n");
	}

	/* It's the time to set ctrl in sysinfo now; */
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
	enable_smbus();

	//do we need apci timer, tsc...., only debug need it for better output
	/* all ap stopped? */
//	init_timer(); // Need to use TMICT to synconize FID/VID

	printk(BIOS_DEBUG, "raminit_amdmct()\n");
	raminit_amdmct(sysinfo);
	post_code(0x41);

	bcm5785_early_setup();

	post_cache_as_ram();
}
示例#7
0
/** main() Application entry point
 *
 * @param argc int
 * @param argv[] char*
 * @return int
 *
 */
int main(int argc, char *argv[])
{
	odph_odpthread_t thread_tbl[MAX_WORKERS];
	appl_args_t params;
	int core_count, num_workers;
	odp_cpumask_t cpumask;
	char cpumaskstr[64];
	odph_odpthread_params_t thr_params;
	odp_instance_t instance;

	/* Parse and store the application arguments */
	parse_args(argc, argv, &params);

	if (params.if_count > OFP_FP_INTERFACE_MAX) {
		printf("Error: Invalid number of interfaces: maximum %d\n",
			OFP_FP_INTERFACE_MAX);
		exit(EXIT_FAILURE);
	}

	if (odp_init_global(&instance, NULL, NULL)) {
		OFP_ERR("Error: ODP global init failed.\n");
		exit(EXIT_FAILURE);
	}
	if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
		OFP_ERR("Error: ODP local init failed.\n");
		exit(EXIT_FAILURE);
	}

	/* Print both system and application information */
	print_info(NO_PATH(argv[0]), &params);

	core_count = odp_cpu_count();
	num_workers = core_count;

	if (params.core_count && params.core_count < core_count)
		num_workers = params.core_count;
	if (num_workers > MAX_WORKERS)
		num_workers = MAX_WORKERS;

	if (core_count > 1)
		num_workers--;

	num_workers = odp_cpumask_default_worker(&cpumask, num_workers);
	odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));

	printf("Num worker threads: %i\n", num_workers);
	printf("first CPU:          %i\n", odp_cpumask_first(&cpumask));
	printf("cpu mask:           %s\n", cpumaskstr);

	ofp_init_global_param(&app_init_params);
	app_init_params.if_count = params.if_count;
	app_init_params.if_names = params.if_names;

	if (ofp_init_global(instance, &app_init_params)) {
		OFP_ERR("Error: OFP global init failed.\n");
		exit(EXIT_FAILURE);
	}
	if (ofp_init_local()) {
		OFP_ERR("Error: OFP local init failed.\n");
		exit(EXIT_FAILURE);
	}

	build_classifier(app_init_params.if_count, app_init_params.if_names);

	/* Start CLI */
	ofp_start_cli_thread(instance, app_init_params.linux_core_id, params.cli_file);
	sleep(1);

	memset(thread_tbl, 0, sizeof(thread_tbl));
	/* Start dataplane dispatcher worker threads */
	thr_params.start = default_event_dispatcher;
	thr_params.arg = ofp_udp4_processing;
	thr_params.thr_type = ODP_THREAD_WORKER;
	thr_params.instance = instance;
	odph_odpthreads_create(thread_tbl,
			       &cpumask,
			       &thr_params);

	app_processing();

	odph_odpthreads_join(thread_tbl);

	printf("End Main()\n");
	return 0;
}
示例#8
0
文件: main.c 项目: joojler/jrepo
int main (int argc, char *argv[])
{
	// Business loan	
	int loan_num; 
	float rate = BUSINESS_LOAN_RATE / 12; // 5.4% / 12, month rate
	int i = 0;
	float fee = 0;
	float fact = 0;
	float total_fee = 0;
	float total_bj = 0;
	float bj = 0;

	float bx_fee = 0;
	float bx_loan_num = 0;
	float bx_total_fee = 0;
	float bx_monthly = 0;

	// House Fund loan	
	int house_fund_num = HOUSE_FUND_NUM; // 120w
	float house_fund_rate = HOUSE_FUND_RATE / 12; // month rate
	float house_fund_fee = 0;
	float house_fund_fact = 0;
	float house_fund_total_bj = 0;
	float house_fund_bj = 0;

	int bx_house_fund_num = HOUSE_FUND_NUM; // 120w
	float bx_house_fund_fee = 0;
	float bx_house_fund_monthly = 0;

	// savings = bj - bx
	float savings = 0;
	float total_savings = 0;
	float bx_benefit = 0;
	float tmp = 0;
	float max_bx_benefit = 0;

	// Investment	
	int invest_num = 0;
	float invest_rate = INVEST_RATE / 12;
	float income = 0, total_income = 0, year_income = 0;


	initial_info ();
	print_info ();

	loan_num = bx_loan_num = max_loan;
	fact = loan_num / max_loan_month;
	invest_num = remain_num;
	house_fund_fact = house_fund_num / max_loan_month;
	bx_monthly = (bx_loan_num * rate * pow(1+rate, max_loan_month))
		/ (pow(1+rate, max_loan_month) - 1);

	printf("Business Loan, monthly pay = %d, bx monthly pay = %f\n", fact, bx_monthly);
	for (i = 0; i < max_loan_month; i++) {
		fee = loan_num * rate;
		loan_num -= fact; 
		total_fee += fee;

		bx_fee = bx_loan_num * rate;
		bx_loan_num -= (bx_monthly - bx_fee);
		if (bx_loan_num < 0)
			bx_loan_num = 0;
		bx_total_fee += bx_fee;

		if (!(i % 12))
			printf("\n\n---------------- YEAR %d --------------\n",
					 i/12 + 1);
		printf("Month %03d, fee %05f, monthly %05f, bx_load_num = %f, bx_fee %05f, bx_monthly %05f\n", 
			i+1, fee, fee + fact, bx_loan_num, bx_fee, bx_monthly);

		if ((i %12) == 11)
			printf("Total fee = %f, bx total fee = %f\n", total_fee, bx_total_fee);
	}


	printf("\n\nHouse Fund + Business Loan\n");	
	total_fee = bx_total_fee = 0;
	bx_loan_num = loan_num = business_loan; 
	bx_monthly = (bx_loan_num * rate * pow(1+rate, max_loan_month))
		/ (pow(1+rate, max_loan_month) - 1);
	bx_house_fund_monthly = (bx_house_fund_num * house_fund_rate * pow(1+house_fund_rate, max_loan_month))
		/ (pow(1+house_fund_rate, max_loan_month) - 1);
	fact = loan_num / max_loan_month;
	for (i = 0; i < max_loan_month; i++) {
		house_fund_fee = house_fund_num * house_fund_rate;
		house_fund_num -= house_fund_fact; 
		total_fee += house_fund_fee;

		bx_house_fund_fee = bx_house_fund_num * house_fund_rate;
		house_fund_bj = (bx_house_fund_monthly - bx_house_fund_fee);
		house_fund_total_bj += house_fund_bj;
		bx_house_fund_num -= house_fund_bj;
		bx_total_fee += bx_house_fund_fee;

		fee = loan_num * rate;
		loan_num -= fact;
		total_fee += fee;	

		bx_fee = bx_loan_num * rate;
		bj = (bx_monthly - fee);
		bx_loan_num -= bj;
		total_bj += bj;
		bx_total_fee += bx_fee;

		savings += fee + house_fund_fee + house_fund_fact + fact - bx_monthly - bx_house_fund_monthly;
		if (savings <= 0)
			savings = 0;

		if (!(i % 12))
			printf("\n\n---------------- YEAR %d --------------\n", 
				i/12 + 1);

		printf("Month %03d, house_fund_fee %05f, fee %05f, monthly %05f, bx_house_fund_fee %f, bx_fee %f, bx_monthly %f\n", \
			i+1, house_fund_fee, fee, fee + house_fund_fee + house_fund_fact + fact,\
			bx_house_fund_fee, house_fund_fee, bx_monthly + bx_house_fund_monthly);

		if ((i % 12) == 11) {
			total_savings += savings;
			bx_benefit = total_savings - (bx_total_fee - total_fee);
			if (bx_benefit > max_bx_benefit)
				max_bx_benefit = bx_benefit;
			printf("Total fee = %f, bx total fee %f, savings in this year %f, total_savings %f\n", total_fee, bx_total_fee, savings, total_savings);
			printf("bj spend house_fund benjin = %f, bj spend benjin %f, tatal %f\n", (i+1)*house_fund_fact, (i+1)*fact, 
					(i+1)*(house_fund_fact+fact));
			printf("bx spend house_fund benjin = %f, bx spend benjin %f, total %f\n", house_fund_total_bj, total_bj,
					house_fund_total_bj+total_bj);
			printf("bx_benefit = %f, max_bx_benefit %f\n", bx_benefit, max_bx_benefit);
			savings = 0;
		}
	}


	printf("\n\nInvest income %d\n", invest_num);
	for (i = 0; i < max_loan_month; i++) {
		income = invest_num * invest_rate;
		year_income += income;

		if (!(i % 12))
			printf("\n\n---------------- YEAR %d --------------\n", i/12 + 1);
		printf("Month %03d, income %05f\n", i+1, income);

		if ((i %12) == 11) {
			printf("year income = %f\n", year_income);
			total_income += year_income;
			printf("Total income = %f\n", total_income);
			invest_num += year_income;
			year_income = 0;
		}
	}

	return 0;
}
示例#9
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	static const uint16_t spd_addr[] = {
		// Node 0
		DIMM0, DIMM1, DIMM2, 0,
		0, 0, 0, 0,
		// Node 1
		0, 0, 0, 0,
		0, 0, 0, 0,
	};
	unsigned bsp_apicid = 0;
	int needs_reset = 0;
	struct sys_info *sysinfo = &sysinfo_car;

	winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
	console_init();
	enable_rom_decode();

	print_info("now booting... fallback\n");

	/* Is this a CPU only reset? Or is this a secondary CPU? */
	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0. */
		/* Allow the HT devices to be found. */
		enumerate_ht_chain();
	}

	print_info("now booting... real_main\n");

	if (bist == 0)
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);

	/* Halt if there was a built in self test failure. */
	report_bist_failure(bist);

	setup_default_resource_map();
	setup_coherent_ht_domain();
	wait_all_core0_started();

	print_info("now booting... Core0 started\n");

#if CONFIG_LOGICAL_CPUS
	/* It is said that we should start core1 after all core0 launched. */
	start_other_cores();
	wait_all_other_cores_started(bsp_apicid);
#endif
	init_timer();
	ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */

	needs_reset = optimize_link_coherent_ht();
	needs_reset |= optimize_link_incoherent_ht(sysinfo);
	needs_reset |= k8t890_early_setup_ht();

	if (needs_reset) {
		print_debug("ht reset -\n");
		soft_reset();
	}

	/* the HT settings needs to be OK, because link freq change may cause HT disconnect */
	vt8237_sb_enable_fid_vid();
	enable_fid_change();
	init_fidvid_bsp(bsp_apicid);

	/* Stop the APs so we can start them later in init. */
	allow_all_aps_stop(bsp_apicid);

	/* It's the time to set ctrl now. */
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);

	enable_smbus();

	/* this seems to be some GPIO on the SMBus--in any case, setting these
	 * two bits reduces the pullup impedance of the bus lines and is required
	 * in order to be able to read SPD info */
	smbus_write_byte(0x48, 0x07, smbus_read_byte(0x48, 0x07) | 0x80);
	smbus_write_byte(0x4a, 0x07, smbus_read_byte(0x4a, 0x07) | 0x10);

	unsigned char mask;

	mask = 0;
//	mask |= 1 /* AGP voltage 1.7 V (not verified, just vendor BIOS value) */
//	mask |= 2 /* V-Link voltage 2.6 V (not verified either) */
	smbus_write_byte(0x4a, 0x00, (smbus_read_byte(0x4a, 0x00) & ~0x0f) | (0x0f ^ (mask << 2)));
	smbus_write_byte(0x4a, 0x01, (smbus_read_byte(0x4a, 0x01) & ~0x03) | (0x03 ^ mask));

	mask = 25; /* RAM voltage in decivolts, valid range from 25 to 28 */
	mask = 3 - (mask - 25);
	smbus_write_byte(0x4a, 0x02, 0x4f | (mask << 4));
	smbus_write_byte(0x4a, 0x03, 0x04 | mask);

	sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
	post_cache_as_ram();
}
示例#10
0
文件: info.c 项目: ppentchev/pkg
int
exec_info(int argc, char **argv)
{
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
	int query_flags;
	struct pkg *pkg = NULL;
	uint64_t opt = INFO_TAG_NAMEVER;
	match_t match = MATCH_GLOB;
	char *pkgname;
	char *pkgversion = NULL, *pkgversion2 = NULL;
	const char *file = NULL;
	int ch, fd;
	int ret = EPKG_OK;
	int retcode = 0;
	bool gotone = false;
	int i, j;
	int sign = 0;
	int sign2 = 0;
	int open_flags = 0;
	bool pkg_exists = false;
	bool origin_search = false;
	bool e_flag = false;
	struct pkg_manifest_key *keys = NULL;
#ifdef HAVE_CAPSICUM
	cap_rights_t rights;
#endif

	/* Set default case sensitivity for searching */
	pkgdb_set_case_sensitivity(
	    pkg_object_bool(pkg_config_get("CASE_SENSITIVE_MATCH")));

	/* TODO: exclusive opts ? */
	while ((ch = getopt(argc, argv, "aACDegixEIdrklbBsqopOfF:R")) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
		case 'A':
			opt |= INFO_ANNOTATIONS;
			break;
		case 'C':
			pkgdb_set_case_sensitivity(true);
			break;
		case 'O':
			origin_search = true;  /* only for ports compat */
			break;
		case 'e':
			pkg_exists = true;;
			retcode = 1;
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
		case 'i':
			pkgdb_set_case_sensitivity(false);
			break;
		case 'x':
			match = MATCH_REGEX;
			break;
		case 'D':
			opt |= INFO_MESSAGE;
			break;
		case 'd':
			opt |= INFO_DEPS;
			break;
		case 'I':
			opt |= INFO_COMMENT;
			break;
		case 'r':
			opt |= INFO_RDEPS;
			break;
		case 'k':
			opt |= INFO_LOCKED;
			break;
		case 'l':
			opt |= INFO_FILES;
			break;
		case 'b':
			opt |= INFO_SHLIBS_PROVIDED;
			break;
		case 'B':
			opt |= INFO_SHLIBS_REQUIRED;
			break;
		case 's':
			opt |= INFO_FLATSIZE;
			break;
		case 'E': /* ports compatibility */
			e_flag = true;
			break;
		case 'q':
			quiet = true;
			break;
		case 'o':
			opt |= INFO_ORIGIN;
			break;
		case 'p':
			opt |= INFO_PREFIX;
			break;
		case 'f':
			opt |= INFO_FULL;
			break;
		case 'F':
			file = optarg;
			break;
		case 'R':
			opt |= INFO_RAW;
			break;
		default:
			usage_info();
			return(EX_USAGE);
		}
	}

	if (argc == 1 || (argc == 2 && quiet))
		match = MATCH_ALL;

	argc -= optind;
	argv += optind;

	if (argc == 0 && file == NULL && match != MATCH_ALL) {
		/* which -O bsd.*.mk always execpt clean output */
		if (origin_search)
			return (EX_OK);
		usage_info();
		return (EX_USAGE);
	}

	/* When no other data is requested, default is to print
	 * 'name-ver comment' For -O, just print name-ver */
	if (!origin_search && (opt & INFO_ALL) == 0 && match == MATCH_ALL &&
	    !quiet)
		opt |= INFO_COMMENT;

	/* Special compatibility: handle -O and -q -O */
	if (origin_search) {
		if (quiet) {
			opt = INFO_TAG_NAMEVER;
			quiet = false;
		} else {
			opt = INFO_TAG_NAMEVER|INFO_COMMENT;
		}
	}

	if (match == MATCH_ALL && opt == INFO_TAG_NAMEVER)
		quiet = false;

	if (file != NULL) {
		if ((fd = open(file, O_RDONLY)) == -1) {
			warn("Unable to open %s", file);
			return (EX_IOERR);
		}

#ifdef HAVE_CAPSICUM
		cap_rights_init(&rights, CAP_READ, CAP_FSTAT);
		if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS ) {
			warn("cap_rights_limit() failed");
			return (EX_SOFTWARE);
		}

		if (cap_enter() < 0 && errno != ENOSYS) {
			warn("cap_enter() failed");
			return (EX_SOFTWARE);
		}
#endif
		if (opt == INFO_TAG_NAMEVER)
			opt |= INFO_FULL;
		pkg_manifest_keys_new(&keys);
		if ((opt & (INFO_RAW | INFO_FILES |
				INFO_DIRS)) == 0)
			open_flags = PKG_OPEN_MANIFEST_COMPACT;

		if (pkg_open_fd(&pkg, fd, keys, open_flags) != EPKG_OK) {
			close(fd);
			return (1);
		}
		pkg_manifest_keys_free(keys);
		print_info(pkg, opt);
		close(fd);
		pkg_free(pkg);
		return (EX_OK);
	}

	ret = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL);
	if (ret == EPKG_ENOACCESS) {
		warnx("Insufficient privileges to query the package database");
		return (EX_NOPERM);
	} else if (ret == EPKG_ENODB) {
		if (match == MATCH_ALL)
			return (EX_OK);
		if (origin_search)
			return (EX_OK);
		if (!quiet)
			warnx("No packages installed");
		return (EX_UNAVAILABLE);
	} else if (ret != EPKG_OK)
		return (EX_IOERR);
		
	ret = pkgdb_open(&db, PKGDB_DEFAULT);
	if (ret != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get a read lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
	}

	i = 0;
	do {
		gotone = false;
		pkgname = argv[i];

		/*
		 * allow to search for origin with a trailing /
		 * likes audio/linux-vsound depending on ${PORTSDIR}/audio/sox/
		 */
		if (argc > 0 && pkgname[strlen(pkgname) -1] == '/')
			pkgname[strlen(pkgname) -1] = '\0';

		if (argc > 0) {
			j=0;
			while (pkgname[j] != '\0') {
				if (pkgname[j] == '<') {
					if (pkgversion) {
						pkgversion2 = pkgname + j;
						sign2 = LT;
						pkgversion2[0] = '\0';
						pkgversion2++;
						if (pkgversion2[0] == '=') {
							pkgversion2++;
							sign=LE;
							j++;
						}
					} else {
						pkgversion = pkgname + j;
						sign = LT;
						pkgversion[0] = '\0';
						pkgversion++;
						if (pkgversion[0] == '=') {
							pkgversion++;
							sign=LE;
							j++;
						}
					}
				} else if (pkgname[j] == '>') {
					if (pkgversion) {
						pkgversion2 = pkgname + j;
						sign2 = GT;
						pkgversion2[0] = '\0';
						pkgversion2++;
						if (pkgversion2[0] == '=') {
							pkgversion2++;
							sign=GE;
							j++;
						}
					} else {
						pkgversion = pkgname + j;
						sign = GT;
						pkgversion[0] = '\0';
						pkgversion++;
						if (pkgversion[0] == '=') {
							pkgversion++;
							sign=GE;
							j++;
						}
					}
				} else if (pkgname[j] == '=') {
					if (pkgversion) {
						pkgversion2 = pkgname + j;
						sign2 = EQ;
						pkgversion2[0] = '\0';
						pkgversion2++;
						if (pkgversion2[0] == '=') {
							pkgversion2++;
							sign=EQ;
							j++;
						}
					} else {
						pkgversion = pkgname + j;
						sign = EQ;
						pkgversion[0] = '\0';
						pkgversion++;
						if (pkgversion[0] == '=') {
							pkgversion++;
							sign=EQ;
							j++;
						}
					}
				}
				j++;
			}
		}

		if (match != MATCH_ALL && pkgname[0] == '\0') {
			fprintf(stderr, "Pattern must not be empty.\n");
			i++;
			continue;
		}

		if ((it = pkgdb_query(db, pkgname, match)) == NULL) {
			goto cleanup;
		}

		/* this is place for compatibility hacks */

		/* ports infrastructure expects pkg info -q -O to always return 0 even
		 * if the ports doesn't exists */
		if (origin_search)
			gotone = true;

		/* end of compatibility hacks */

		/*
		 * only show full version in case of match glob with a single argument specified
		 * which does not contains any glob pattern
		 */
		if (argc == 1 && !origin_search && !quiet && !e_flag &&
		    match == MATCH_GLOB &&
		    strcspn(pkgname, "*[]{}()") == strlen(pkgname) &&
		    opt == INFO_TAG_NAMEVER)
			opt |= INFO_FULL;

		query_flags = info_flags(opt, false);
		while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
			gotone = true;
			const char *version;

			pkg_get(pkg, PKG_VERSION, &version);
			if (pkgversion != NULL) {
				switch (pkg_version_cmp(version, pkgversion)) {
				case -1:
					if (sign != LT && sign != LE) {
						gotone = false;
						continue;
					}
					break;
				case 0:
					if (sign != LE &&
					    sign != GE &&
					    sign != EQ) {
						gotone = false;
						continue;
					}
					break;
				case 1:
					if (sign != GT && sign != GE) {
						gotone = false;
						continue;
					}
					break;
				}
			}
			if (pkgversion2 != NULL) {
				switch (pkg_version_cmp(version, pkgversion2)) {
				case -1:
					if (sign2 != LT && sign2 != LE) {
						gotone = false;
						continue;
					}
					break;
				case 0:
					if (sign2 != LE &&
					    sign2 != GE &&
					    sign2 != EQ) {
						gotone = false;
						continue;
					}
					break;
				case 1:
					if (sign2 != GT && sign2 != GE) {
						gotone = false;
						continue;
					}
					break;
				}
			}
			if (pkg_exists)
				retcode = EX_OK;
			else
				print_info(pkg, opt);
		}
		if (ret != EPKG_END) {
			retcode = EX_IOERR;
		}

		if (retcode == EX_OK && !gotone && match != MATCH_ALL) {
			if (!quiet)
				warnx("No package(s) matching %s", argv[i]);
			retcode = EX_SOFTWARE;
		}

		pkgdb_it_free(it);

		i++;
	} while (i < argc);

cleanup:
	if (pkg != NULL)
		pkg_free(pkg);

	pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
	pkgdb_close(db);

	return (retcode);
}
示例#11
0
文件: kmc_dump.cpp 项目: el-mat/KMC
int _tmain(int argc, char* argv[])
{
	CKMCFile kmer_data_base;
	int32 i;
	uint32 min_count_to_set = 0;
	uint32 max_count_to_set = 0;
	std::string input_file_name;
	std::string output_file_name;

	FILE * out_file;
	//------------------------------------------------------------
	// Parse input parameters
	//------------------------------------------------------------
	if(argc < 3)
	{
		print_info();
		return EXIT_FAILURE;
	}

	for(i = 1; i < argc; ++i)
	{
		if(argv[i][0] == '-')
		{	
			if(strncmp(argv[i], "-ci", 3) == 0)
				min_count_to_set = atoi(&argv[i][3]);
			else if(strncmp(argv[i], "-cx", 3) == 0)
					max_count_to_set = atoi(&argv[i][3]);
		}
		else
			break;
	}

	if(argc - i < 2)
	{ 
		print_info();
		return EXIT_FAILURE;
	}

	input_file_name = std::string(argv[i++]);
	output_file_name = std::string(argv[i]);

	if((out_file = fopen (output_file_name.c_str(),"wb")) == NULL)
	{
		print_info();
		return EXIT_FAILURE;
	}

	setvbuf(out_file, NULL ,_IOFBF, 1 << 24);

	//------------------------------------------------------------------------------
	// Open kmer database for listing and print kmers within min_count and max_count
	//------------------------------------------------------------------------------

	if (!kmer_data_base.OpenForListing(input_file_name))
	{
		print_info();
		return EXIT_FAILURE ;
	}
	else
	{
		uint32 _kmer_length;
		uint32 _mode;
		uint32 _counter_size;
		uint32 _lut_prefix_length;
		uint32 _signature_len;
		uint32 _min_count;
		uint32 _max_count;
		uint64 _total_kmers;

		kmer_data_base.Info(_kmer_length, _mode, _counter_size, _lut_prefix_length, _signature_len, _min_count, _max_count, _total_kmers);

		
		//std::string str;
		char str[1024];
		uint32 counter_len;
		
		CKmerAPI kmer_object(_kmer_length);
		
		if(min_count_to_set)
		if (!(kmer_data_base.SetMinCount(min_count_to_set)))
				return EXIT_FAILURE;
		if(max_count_to_set)
		if (!(kmer_data_base.SetMaxCount(max_count_to_set)))
				return EXIT_FAILURE;	

		if (_mode) //quake compatible mode
		{
			float counter;
			while (kmer_data_base.ReadNextKmer(kmer_object, counter))
			{
				kmer_object.to_string(str);
				str[_kmer_length] = '\t';				
				counter_len = CNumericConversions::Double2PChar(counter, 6, (uchar*)str + _kmer_length + 1);				
				str[_kmer_length + 1 + counter_len] = '\n';
				fwrite(str, 1, _kmer_length + counter_len + 2, out_file);			
			}
		}
		else
		{
			uint32 counter;
			while (kmer_data_base.ReadNextKmer(kmer_object, counter))
			{
				kmer_object.to_string(str);
				str[_kmer_length] = '\t';
				counter_len = CNumericConversions::Int2PChar(counter, (uchar*)str + _kmer_length + 1);
				str[_kmer_length + 1 + counter_len] = '\n';
				fwrite(str, 1, _kmer_length + counter_len + 2, out_file);
			}
		}
		
	
		fclose(out_file);
		kmer_data_base.Close();
	}

	return EXIT_SUCCESS; 
}
示例#12
0
void conf_init(void) {
    init_default_values();
    gboolean keyoption = FALSE;

    Display *dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
    XrmInitialize();
    char basename[12] = "/.Xdefaults";
    char *filename = strcat(getpwuid(getuid())->pw_dir, basename);
    XrmSetDatabase(dpy, XrmGetFileDatabase(filename));

    char *op;
    int i;
    Option o;
    for (i = 0; i < OPTION_COUNT; i++) {
        o = options[i];
        if ((op = XGetDefault(dpy, "stjerm", o.long_name)))
            read_value(o.long_name, op);
    }
    char color[8];
    for (i = 0; i < 16; i++) {
        sprintf(color, "color%d", i);
        if ((op = XGetDefault(dpy, "stjerm", color)))
            read_value(color, op);
    }

    for (i = 1; i < sargc; i++) {
        if (sargv != NULL) {
            if (!strcmp(sargv[i], "--help")) {
                print_help();
                exit(1);
            } else if (!strcmp(sargv[i], "--info")) {
                print_info();
                exit(1);
            } else if (!strcmp("--toggle", sargv[i])) {
                kill(get_stjerm_pid(), SIGUSR1);
                exit(1);
            } else if (!strcmp("--version", sargv[i]) || !strcmp("-v", sargv[i])){
	     	    print_version();
		        exit(1);
	        }
        }
        if (i + 1>= sargc)
            break;

        read_value(sargv[i], sargv[i + 1]);
    }

    if (keyoption == FALSE && _key == 0) {
        printf("Hint: You started stjerm without specifying a shortcut key\n"
               "      To show/hide stjerm run stjerm with the toggle option\n"
               "      like this: stjerm --toggle");
    }

    struct stat st;
    if (stat(_shell, &st) != 0) {
        fprintf(stderr, "ERROR: The shell '%s' can't be opened\n", _shell);
        exit(1);
    }

    if (_lines < 0) {
        fprintf(stderr, "ERROR: A scrollback line count < 0 is not allowed\n");
        exit(1);
    }

    if (keyoption == TRUE && _key == 0) {
        fprintf(stderr, "ERROR: Wrong shortcut key is defined\n");
        exit(1);
    }

    if (read_colors > 0 && read_colors < 16) {
        fprintf(stderr, "ERROR: Read only %d colors, not 16\n"
                "Specify a complete color palette\n", read_colors);
        exit(1);
    }

    signal(SIGUSR1, (__sighandler_t) mainwindow_toggle);

    int scrw = gdk_screen_get_width(gdk_screen_get_default());
    int scrh = gdk_screen_get_height(gdk_screen_get_default());

    if (_pos == POS_TOP) {
        _posx = (scrw - _width) / 2;
        _posy = 0;
    } else if (_pos == POS_BOTTOM) {
        _posx = (scrw - _width) / 2;
        _posy = scrh - _height;
    } else if (_pos == POS_LEFT) {
        _posx = 0;
        _posy = (scrh - _height) / 2;
    } else if (_pos == POS_RIGHT) {
        _posx = scrw - _width;
        _posy = (scrh - _height) / 2;
    } else if (_pos == POS_TOPLEFT) {
        _posx = 0;
        _posy = 0;
    } else if (_pos == POS_TOPRIGHT) {
        _posx = scrw - _width;
        _posy = 0;
    } else if (_pos == POS_BOTTOMLEFT) {
        _posx = 0;
        _posy = scrh - _height;
    } else if (_pos == POS_BOTTOMRIGHT) {
        _posx = scrw - _width;
        _posy = scrh - _height;
    }
}
示例#13
0
文件: main.cpp 项目: etoestja/inf
int main(int argc, char** argv)
{
    if(argc < 3)
    {
        printf("Usage: %s send_time recv_time\n", argv[0]);
        exit(-1);
    }

    // filling send & recv time
    send_time = atoi(argv[1]);
    recv_time = atoi(argv[2]);

    /// number of done tasks for time
    int done_tasks = 0;

    // time in system
    int time = 0;

    // filling in tasks length {30, 10, 10, ..., 10}
    task_len[0] = 30;
    for(int i = 1; i < TASKS; i++)
        task_len[i] = 10;

    // print settings
    print_info();

    // initializing tasks
    for(int i = 0; i < TASKS; i++)
    {
        states[i] = WAITING;
        last_state_change_time[i] = 0;
    }

    // initializing answer
    bzero(arr, sizeof(arr));

    // when does the master gets free from ongoing send/receive operation?
    int zero_free_time = 0;

    while(done_tasks < TASKS)
    {
        // time step [time]
     
        // done tasks for this time
        int done_tasks_t = 0;

        for(int i = 0; i < TASKS; i++)
        {
            // WAITING->SENDING if master is free
            if(states[i] == WAITING && zero_free_time <= time)
            {
                states[i] = SENDING;
                last_state_change_time[i] = time;
                zero_free_time = time + send_time;
                printf("TIME %d task %d is now SENDING transmission stops at %d\n", time, i, zero_free_time);
            }

            // SENDING->RUNNING if send is complete
            if(states[i] == SENDING)
            {
                if(time - last_state_change_time[i] >= send_time)
                {
                    last_state_change_time[i] = time;
                    states[i] = RUNNING;
                    printf("TIME %d task %d is now RUNNING finishing at %d\n", time, i, time + task_len[i]);
                }
                else
                {
                    arr[0][time].state = SENDING;
                    arr[0][time].peer = i;
                }
            }

            // RUNNING->WAITING_RECEIVE if task is complete
            if(states[i] == RUNNING)
            {
                if(time - last_state_change_time[i] >= task_len[i])
                {
                    last_state_change_time[i] = time;
                    states[i] = WAITING_RECEIVE;
                    printf("TIME %d task %d is WAITING_RECEIVE\n", time, i);
                }
            }

            // WAITING_RECEIVE->RECEIVING if master is free AND if
            // receive time is zero
            // or we have sent all tasks
            // so NOT starting to receive tasks until we sent all of them
            if(states[i] == WAITING_RECEIVE && zero_free_time <= time && (recv_time == 0 || count(WAITING) == 0))
            {
                states[i] = RECEIVING;
                last_state_change_time[i] = time;
                zero_free_time = time + recv_time;
                printf("TIME %d task %d is now RECEIVING transmission stops at %d\n", time, i, zero_free_time);
            }

            // RECEIVING->DONE if recv is complete
            if(states[i] == RECEIVING)
            {
                if(time - last_state_change_time[i] >= recv_time)
                {
                    last_state_change_time[i] = time;
                    states[i] = DONE;
                    printf("TIME %d task %d is DONE\n", time, i);
                }
                else
                {
                    arr[0][time].state = RECEIVING;
                    arr[0][time].peer = i;
                }
            }

            // incrementing done tasks counter
            if(states[i] == DONE)
                done_tasks_t++;

            arr[i + 1][time].state = states[i];
            arr[i + 1][time].peer = -1;
        }
   
        done_tasks = done_tasks_t;
        time++;
    }

    // printing the schedule
    for(int j = 0; j < TMAX; j++)
    {
        table_cell c = arr[0][j];
        printf("%s", state_names[c.state]);
    }
    printf("\n");

    for(int i = 1; i <= TASKS; i++)
    {
        for(int j = 0; j < TMAX; j++)
        {
            table_cell c = arr[i][j];
            printf("%s", state_names[c.state]);
        }
        printf("\n");
    }

    // calculating T1, Tp, Sp, Ep
    int T1 = 0;
    int Tp = time - 1;

    for(int i = 0; i < TASKS; i++)
        T1 += task_len[i];

    double Sp = 1. * T1 / Tp;
    double Ep = Sp / TASKS;

    printf("T1 = %d, Tp = %d, Sp = %lf, Ep=%lf\n", T1, Tp, Sp, Ep);
}
示例#14
0
int main(int argc, const char *argv[])
{
    int        nID = 0;
    const char *fname1 = NULL;
    const char *fname2 = NULL;
    const char *objname1  = NULL;
    const char *objname2  = NULL;
    diff_opt_t options;

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* Initialize h5tools lib */
    h5tools_init();

    outBuffOffset = 0;
    g_Parallel = 1;

    MPI_Init(&argc, (char***) &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &nID);
    MPI_Comm_size(MPI_COMM_WORLD, &g_nTasks);

    if(g_nTasks == 1)
    {
        printf("Only 1 task available...doing serial diff\n");

        g_Parallel = 0;

        parse_command_line(argc, argv, &fname1, &fname2, &objname1, &objname2, &options);

        h5diff(fname1, fname2, objname1, objname2, &options);

        print_info(&options);
    }
    /* Parallel h5diff */
    else {

        /* Have the manager process the command-line */
        if(nID == 0)
        {
            parse_command_line(argc, argv, &fname1, &fname2, &objname1, &objname2, &options);

            h5diff(fname1, fname2, objname1, objname2, &options);

            MPI_Barrier(MPI_COMM_WORLD);

            print_info(&options);
            print_manager_output();
        }
        /* All other tasks become workers and wait for assignments. */
        else {
            ph5diff_worker(nID);

            MPI_Barrier(MPI_COMM_WORLD);
        } /* end else */

    } /* end else */

    MPI_Finalize();

    return 0;
}
示例#15
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	static const uint16_t spd_addr[] = {
			// first node
                        DIMM0, DIMM2, 0, 0,
                        DIMM1, DIMM3, 0, 0,

			// second node
                        DIMM4, DIMM6, 0, 0,
                        DIMM5, DIMM7, 0, 0,
	};

	struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE
		+ CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);

        int needs_reset;
        unsigned bsp_apicid = 0;

        if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */

		enumerate_ht_chain();

		/* Setup the rom access for 4M */
		amd8111_enable_rom();
        }

        if (bist == 0) {
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
        }

 	w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
        uart_init();
        console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);

        setup_mb_resource_map();

	print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\n");

#if CONFIG_MEM_TRAIN_SEQ == 1
        set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
#endif
	setup_coherent_ht_domain(); // routing table and start other core0

	wait_all_core0_started();
#if CONFIG_LOGICAL_CPUS==1
        // It is said that we should start core1 after all core0 launched
	/* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
	 * So here need to make sure last core0 is started, esp for two way system,
	 * (there may be apic id conflicts in that case)
	 */
        start_other_cores();
	wait_all_other_cores_started(bsp_apicid);
#endif

	/* it will set up chains and store link pair for optimization later */
        ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn

#if SET_FIDVID == 1

        {
                msr_t msr;
	        msr=rdmsr(0xc0010042);
                print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");

        }

	enable_fid_change();

	enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);

        init_fidvid_bsp(bsp_apicid);

        // show final fid and vid
        {
                msr_t msr;
               	msr=rdmsr(0xc0010042);
               	print_debug("end   msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");

        }
#endif

	needs_reset = optimize_link_coherent_ht();
	needs_reset |= optimize_link_incoherent_ht(sysinfo);

        // fidvid change will issue one LDTSTOP and the HT change will be effective too
        if (needs_reset) {
                print_info("ht reset -\n");
                soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
        }

	allow_all_aps_stop(bsp_apicid);

        //It's the time to set ctrl in sysinfo now;
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);

	enable_smbus();

#if 0
	dump_smbus_registers();
#endif

	memreset_setup();

	//do we need apci timer, tsc...., only debug need it for better output
        /* all ap stopped? */
        init_timer(); // Need to use TMICT to synconize FID/VID
	sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);

#if 0
        dump_pci_devices();
#endif

        post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now

}
示例#16
0
文件: keygenLRS.c 项目: bokdong2/vane
void print_key()
{
	print_info();
	print_matrix_B1();
	print_matrix_B2();

	print_matrix_MS();
	print_matrix_MT();
	print_matrix_MF();
	print_matrix_MPK();

	fp = fopen("Key.txt", "a+");
	fprintf(fp, "%s", "\n\nPublic Key is written in polynomial form\n\n");
	int i;

	for(i = 0; i < m; i++)
	{
		fprintf(fp, "%s%d%s", "P(", i+1, "):\t");

		int k = 1;
		int l = 1;
		int j;

		for(j = 0; j < ((n)*(n+1))/2; j++)
		{
			fprintf(fp, "%d%s%d%s%d\n", );
			if(matrix_MPK[i][j] <= 9 && k < 10 && l <10)
			{
				fprintf(fp, "%s\t", "");
				fflush(fp);
			}
			fprintf(fp, "%s\t", "+");

			if(l%n == 0)
			{
				k++;
				l = k;
			}
			else
			{
				l++;
			}
			if((j+1)%5 == 0)
			{
				fprintf(fp, "%s\t", "");
				fflush(fp);
			}
		}
		fprintf(fp, "%s\t", "");

		for(j = 0; j < n; j++)
		{
			fprintf(fp, "%d%s%d\t\t+\t", matrix_MPK[i][(n*(n+1))/2 + j], "*m", j+1);
			if((j+1)%5 == 0)
			{
				fprintf(fp, "%s\t", "");
				fflush(fp);
			}
		}
		fprintf(fp, "%s\t", "");
		fprintf(fp, "%d\n", matrix_MPK[i][((n+1)*(n+2))/2 -1]);
		fflush(fp);
	}
	fclose(fp);
}
/*
 **************************************************************************
 * FunctionName: set_camera_timing_type;
 * Description : NA;
 * Input       : NA;
 * Output      : NA;
 * ReturnValue : NA;
 * Other       : NA;
 **************************************************************************
 */
void set_camera_timing_type(int status)
{
	print_info("%s : status=%d.\n", __func__, status);
	camera_timing_type = status;
	return;
}
示例#18
0
int main(int argc, char **argv)
{
int	argn;
char	optc;
char	*optarg;
char	*mimesection=0;
int	doinfo=0, dodecode=0, dorewrite=0, dodsn=0, domimedigest=0;
struct	rfc2045 *p;
int	rwmode=0;
void	(*do_extract)(struct rfc2045 *, const char *, int, char **)=0;
const char *extract_filename=0;

	for (argn=1; argn<argc; )
	{
		if (argv[argn][0] != '-')	break;
		optarg=0;
		optc=argv[argn][1];
		if (optc && argv[argn][2])	optarg=argv[argn]+2;
		++argn;
		switch	(optc)	{
		case 'c':
			if (!optarg && argn < argc)
				optarg=argv[argn++];
			if (optarg && *optarg)
				rfc2045_setdefaultcharset(optarg);
			break;

		case 's':
			if (!optarg && argn < argc)
				optarg=argv[argn++];
			if (optarg && *optarg)	mimesection=optarg;
			break;
		case 'i':
			doinfo=1;
			break;
		case 'e':
			dodecode=1;
			break;
		case 'r':
			dorewrite=1;
			if (optarg && *optarg == '7')
				rwmode=RFC2045_RW_7BIT;
			if (optarg && *optarg == '8')
				rwmode=RFC2045_RW_8BIT;
			break;
		case 'm':
			domimedigest=1;
			break;
		case 'd':
			dodsn=1;
			break;
		case 'D':
			dodsn=2;
			break;
		case 'x':
			do_extract=extract_file;
			if (optarg)
				extract_filename=optarg;
			break;
		case 'X':
			do_extract=extract_pipe;
			break;
		case 'v':
			printf("%s\n", rcsid);
			exit(0);
		default:
			usage();
		}
	}

	if (domimedigest)
	{
		mimedigest(argc-argn, argv+argn);
		return (0);
	}

	p=read_message();

	if (doinfo)
		print_info(p, mimesection);
	else if (dodecode)
		print_decode(p, mimesection);
	else if (dorewrite)
		rewrite(p, rwmode);
	else if (dodsn)
		dsn(p, dodsn == 2);
	else if (do_extract)
		extract_section(p, mimesection, extract_filename,
			argc-argn, argv+argn, do_extract);
	else
		print_structure(p);
	rfc2045_free(p);
	exit(0);
	return (0);
}
示例#19
0
void get_sources(ParamCoLoRe *par)
{
  //////
  // Uses the gaussian matter density field to obtain a
  // poisson sampling of point sources (returns an integer array
  // with the number of sources in each cell).
  int ii,nthr;
  lint *np_tot_thr;
#ifdef _HAVE_OMP
  nthr=omp_get_max_threads();
#else //_HAVE_OMP
  nthr=1;
#endif //_HAVE_OMP
  np_tot_thr=my_calloc(nthr,sizeof(lint));

  print_info("*** Getting point sources\n");
  if(NodeThis==0) timer(0);
  print_info("Poisson-sampling\n");
#ifdef _HAVE_OMP
#pragma omp parallel default(none)		\
  shared(par,np_tot_thr,IThread0)
#endif //_HAVE_OMP
  {
    lint iz;
#ifdef _HAVE_OMP
    int ithr=omp_get_thread_num();
#else //_HAVE_OMP
    int ithr=0;
#endif //_HAVE_OMP
    double dx=par->l_box/par->n_grid;
    double cell_vol=dx*dx*dx;
    int ngx=2*(par->n_grid/2+1);
    unsigned int seed_thr=par->seed_rng+IThread0+ithr;
    gsl_rng *rng_thr=init_rng(seed_thr);

#ifdef _HAVE_OMP
#pragma omp for schedule(static)
#endif //_HAVE_OMP
    for(iz=0;iz<par->nz_here;iz++) {
      int iy;
      lint indexz=iz*((lint)(ngx*par->n_grid));
      double z0=(iz+par->iz0_here+0.5)*dx-par->pos_obs[2];
      for(iy=0;iy<par->n_grid;iy++) {
	int ix;
	lint indexy=iy*ngx;
	double y0=(iy+0.5)*dx-par->pos_obs[1];
	for(ix=0;ix<par->n_grid;ix++) {
	  int npp=0;
	  double dz_rsd=0;
	  lint index=ix+indexy+indexz;
	  double x0=(ix+0.5)*dx-par->pos_obs[1];
	  double r=sqrt(x0*x0+y0*y0+z0*z0);
	  double redshift=z_of_r(par,r);
	  double ndens=ndens_of_z(par,redshift);
	  if(ndens>0) {
	    double bias=bias_of_z(par,redshift);
	    double gfb=dgrowth_of_r(par,r)*bias;
	    double lambda=ndens*cell_vol*
	      exp(gfb*(par->grid_dens[index]-0.5*gfb*par->sigma2_gauss));
	    npp=rng_poisson(lambda,rng_thr);
	    dz_rsd=par->grid_rvel[index]*vgrowth_of_r(par,r);
	  }

	  par->grid_rvel[index]=dz_rsd;
	  par->nsources[index]=npp;
	  np_tot_thr[ithr]+=npp;
	}
      }
    }//end omp for

    end_rng(rng_thr);
  }//end omp parallel
  if(NodeThis==0) timer(2);

  par->nsources_this=0;
  for(ii=0;ii<nthr;ii++)
    par->nsources_this+=np_tot_thr[ii];

  par->nsources_total=0;
#ifdef _HAVE_MPI
  MPI_Allreduce(&(par->nsources_this),&(par->nsources_total),1,LINT_MPI,MPI_SUM,MPI_COMM_WORLD);
#else //_HAVE_MPI
  par->nsources_total=par->nsources_this;
#endif //_HAVE_MPI

  print_info("  There will be %ld particles in total\n",(long)(par->nsources_total));
  //#ifdef _DEBUG
  //  printf("Node %d has %ld particles\n",NodeThis,(long)(par->nsources_this));
  //#endif //_DEBUG

  for(ii=nthr-1;ii>0;ii--) {
    int jj;
    lint nh=0;
    for(jj=0;jj<ii;jj++)
      nh+=np_tot_thr[jj];
    np_tot_thr[ii]=nh;
  }
  np_tot_thr[0]=0;
  //np_tot_thr now contains the id of the first particle in the thread

#ifdef _SPREC
  fftwf_free(par->grid_dens_f);
#else //_SPREC
  fftw_free(par->grid_dens_f);
#endif //_SPREC
  par->grid_dens_f=NULL;
  par->gals=my_malloc(par->nsources_this*sizeof(Gal));

  if(NodeThis==0) timer(0);
  print_info("Assigning coordinates\n");
#ifdef _HAVE_OMP
#pragma omp parallel default(none)		\
  shared(par,IThread0,np_tot_thr)
#endif //_HAVE_OMP
  {
    lint iz;
#ifdef _HAVE_OMP
    int ithr=omp_get_thread_num();
#else //_HAVE_OMP
    int ithr=0;
#endif //_HAVE_OMP
    double dx=par->l_box/par->n_grid;
    int ngx=2*(par->n_grid/2+1);
    unsigned int seed_thr=par->seed_rng+IThread0+ithr;
    gsl_rng *rng_thr=init_rng(seed_thr);

#ifdef _HAVE_OMP
#pragma omp for schedule(static)
#endif //_HAVE_OMP
    for(iz=0;iz<par->nz_here;iz++) {
      int iy;
      lint indexz=iz*((lint)(ngx*par->n_grid));
      double z0=(iz+par->iz0_here)*dx-par->pos_obs[2];
      for(iy=0;iy<par->n_grid;iy++) {
	int ix;
	lint indexy=iy*ngx;
	double y0=iy*dx-par->pos_obs[1];
	for(ix=0;ix<par->n_grid;ix++) {
	  double x0=ix*dx-par->pos_obs[1];
	  lint index=ix+indexy+indexz;
	  int npp=par->nsources[index];
	  if(npp>0) {
	    int ip;
	    double dz_rsd=par->grid_rvel[index];
	    for(ip=0;ip<npp;ip++) {
	      double cth,phi,r;
	      lint pid=np_tot_thr[ithr];
	      double x=x0+dx*rng_01(rng_thr);
	      double y=y0+dx*rng_01(rng_thr);
	      double z=z0+dx*rng_01(rng_thr);
	      cart2sph(x,y,z,&r,&cth,&phi);
	      par->gals[pid].ra=RTOD*phi;
	      par->gals[pid].dec=90-RTOD*acos(cth);
	      par->gals[pid].z0=z_of_r(par,r);
	      par->gals[pid].dz_rsd=dz_rsd;
	      np_tot_thr[ithr]++;
	    }
	  }
	}
      }
    }//end omp for
    end_rng(rng_thr);
  }//end omp parallel
  if(NodeThis==0) timer(2);

  free(np_tot_thr);
  print_info("\n");
}
示例#20
0
文件: app_main.c 项目: charloco/ofp
/** main() Application entry point
 *
 * @param argc int
 * @param argv[] char*
 * @return int
 *
 */
int main(int argc, char *argv[])
{
	odph_linux_pthread_t thread_tbl[MAX_WORKERS];
	appl_args_t params;
	int core_count, num_workers;
	odp_cpumask_t cpumask;
	char cpumaskstr[64];

	/* Parse and store the application arguments */
	parse_args(argc, argv, &params);

	/* Print both system and application information */
	print_info(NO_PATH(argv[0]), &params);

	if (odp_init_global(NULL, NULL)) {
		OFP_ERR("Error: ODP global init failed.\n");
		exit(EXIT_FAILURE);
	}
	if (odp_init_local(ODP_THREAD_CONTROL)) {
		OFP_ERR("Error: ODP local init failed.\n");
		exit(EXIT_FAILURE);
	}

	core_count = odp_cpu_count();
	num_workers = core_count;

	if (params.core_count)
		num_workers = params.core_count;
	if (num_workers > MAX_WORKERS)
		num_workers = MAX_WORKERS;

	/*
	 * By default core #0 runs Linux kernel background tasks.
	 * Start mapping thread from core #1
	 */
	memset(&app_init_params, 0, sizeof(app_init_params));

	app_init_params.linux_core_id = 0;

	if (core_count > 1)
		num_workers--;

	num_workers = odp_cpumask_default_worker(&cpumask, num_workers);
	odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));

	printf("Num worker threads: %i\n", num_workers);
	printf("first CPU:          %i\n", odp_cpumask_first(&cpumask));
	printf("cpu mask:           %s\n", cpumaskstr);

	app_init_params.if_count = params.if_count;
	app_init_params.if_names = params.if_names;
	app_init_params.pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook;
	if (ofp_init_global(&app_init_params)) {
		OFP_ERR("Error: OFP global init failed.\n");
		exit(EXIT_FAILURE);
	}

	memset(thread_tbl, 0, sizeof(thread_tbl));
	/* Start dataplane dispatcher worker threads */

	ofp_linux_pthread_create(thread_tbl,
				  &cpumask,
				  default_event_dispatcher,
				  ofp_eth_vlan_processing,
				  ODP_THREAD_CONTROL
				);

	/* other app code here.*/
	/* Start CLI */
	ofp_start_cli_thread(app_init_params.linux_core_id, params.conf_file);

	/* sysctl test thread */
	ofp_start_sysctl_thread(app_init_params.linux_core_id);

	odph_linux_pthread_join(thread_tbl, num_workers);
	printf("End Main()\n");

	return 0;
}
示例#21
0
int main(int argc, char **argv)
{
    if (argc != 1 && argc != 2) {
        fprintf(stderr, "usage: %s [sink_name] < input_file\n", argv[0]);
        exit(1);
    }

    const char *server_name = NULL;
    const char *client_name = "example play simple";
    const char *sink_name = NULL;
    const char *stream_name = "example stream";

    if (argc > 1) {
        sink_name = argv[1];
    }

    pa_sample_spec sample_spec = {};
    sample_spec.format = PA_SAMPLE_FLOAT32LE;
    sample_spec.rate = 44100;
    sample_spec.channels = 2;

    int error = 0;
    pa_simple *simple = pa_simple_new(
        server_name,
        client_name,
        PA_STREAM_PLAYBACK,
        sink_name,
        stream_name,
        &sample_spec,
        NULL,
        NULL,
        &error);

    if (simple == NULL) {
        fprintf(stderr, "pa_simple_new: %s\n", pa_strerror(error));
        exit(1);
    }

    const pa_usec_t start_time = pa_rtclock_now();
    uint64_t n_bytes = 0;

    for (;;) {
        char buf[1024];
        ssize_t sz = read(STDIN_FILENO, buf, sizeof(buf));
        if (sz == -1) {
            fprintf(stderr, "read: %s\n", strerror(errno));
            exit(1);
        }

        if (sz == 0) {
            break;
        }

        print_info(simple, &sample_spec, start_time, n_bytes);

        if (pa_simple_write(simple, buf, (size_t)sz, &error) != 0) {
            fprintf(stderr, "pa_simple_write: %s\n", pa_strerror(error));
            exit(1);
        }

        n_bytes += (uint64_t)sz;
    }

    /* wait until all samples are sent and played on server */
    if (pa_simple_drain(simple, &error) != 0) {
        fprintf(stderr, "pa_simple_drain: %s\n", pa_strerror(error));
        exit(1);
    }

    print_info(simple, &sample_spec, start_time, n_bytes);

    pa_simple_free(simple);

    return 0;
}
示例#22
0
//================================================================
int process(jack_nframes_t nframes, void *arg)
{
	//fprintf(stderr,".");
	//return 0;

	//if shutting down fill buffers with 0 and return
	if(shutdown_in_progress==1)
	{
		int i;
		for(i=0; i < output_port_count; i++)
		{
			sample_t *o1;
			o1=(sample_t*)jack_port_get_buffer(ioPortArray[i], nframes);
			//memset(o1, 0, bytes_per_sample*nframes);
			//always 4 bytes, 32 bit float
			memset(o1, 0, 4*nframes);
		}
		return 0;
	}

	if(process_enabled==1)
	{
		//if no data for this cycle(all channels) 
		//is available(!), fill buffers with 0 or re-use old buffers and return
		if(jack_ringbuffer_read_space(rb) < port_count * bytes_per_sample*nframes)
		{
			int i;
			for(i=0; i < output_port_count; i++)
			{
				if(shutdown_in_progress==1 || process_enabled!=1)
				{
					return 0;
				}

				if(zero_on_underflow==1)
				{
					sample_t *o1;
					o1=(sample_t*)jack_port_get_buffer(ioPortArray[i], nframes);

					//memset(o1, 0, bytes_per_sample*nframes);
					//always 4 bytes, 32 bit float
					memset(o1, 0, 4*nframes);
				}
				print_info();
			}

			multi_channel_drop_counter++;

			if(rebuffer_on_underflow==1)
			{
				pre_buffer_counter=0;
				process_enabled=0;
			}

			//reset avg calculation
			time_interval_avg=0;
			msg_received_counter=0;
			fscs_avg_counter=0;

			return 0;
		}//end not enough data available in ringbuffer

		process_cycle_counter++;

		if(process_cycle_counter>receive_max-1 && test_mode==1)
		{
			last_test_cycle=1;
		}

		//init to 0. increment before use
		fscs_avg_counter++;

		frames_since_cycle_start_sum+=frames_since_cycle_start;
		frames_since_cycle_start_avg=frames_since_cycle_start_sum/fscs_avg_counter;

		//check and reset after use
		if(fscs_avg_calc_interval>=fscs_avg_counter)
		{
			fscs_avg_counter=0;
			frames_since_cycle_start_sum=0;	
		}

		//if sender sends more channels than we have output channels, ignore them
		int i;
		for(i=0; i<port_count; i++)
		{
			if(shutdown_in_progress==1 || process_enabled!=1)
			{
				return 0;
			}

			sample_t *o1;
			o1=(sample_t*)jack_port_get_buffer(ioPortArray[i], nframes);

			int16_t *o1_16;

			if(bytes_per_sample==2)
			{
				o1_16=malloc(bytes_per_sample*nframes);
			}

			//32 bit float
			if(bytes_per_sample==4)
			{
				jack_ringbuffer_read(rb, (char*)o1, bytes_per_sample*nframes);
			}
			//16 bit pcm
			else
			{
				jack_ringbuffer_read(rb, (char*)o1_16, bytes_per_sample*nframes);

				int x;
				for(x=0;x<nframes;x++)
				{
					o1[x]=(float)MIN_(MAX_((float)o1_16[x]/32760,-1.0f),1.0f);
				}

				free(o1_16);
			}

			/*
			fprintf(stderr,"\rreceiving from %s:%s",
				sender_host,sender_port
			);
			*/

			print_info();

		}//end for i < port_count

		//requested via /buffer, for test purposes (make buffer "tight")
		if(requested_drop_count>0)
		{
			uint64_t drop_bytes_count=requested_drop_count
				*port_count*period_size*bytes_per_sample;

			jack_ringbuffer_read_advance(rb,drop_bytes_count);

			requested_drop_count=0;
			multi_channel_drop_counter=0;
		}
	}//end if process_enabled==1
	else //if process_enabled==0
	{
		int i;
		for(i=0; i<port_count; i++)
		{
			if(shutdown_in_progress==1 || process_enabled!=1)
			{
				return 0;
			}

			sample_t *o1;
			o1=(sample_t*)jack_port_get_buffer(ioPortArray[i], nframes);

			//this is per channel, not per cycle. *port_count
			if(relaxed_display_counter>=update_display_every_nth_cycle*port_count
				|| last_test_cycle==1
			)
			{
				//only for init
				if((int)message_number<=0 && starting_transmission==0)
				{
					if(shutup==0 && quiet==0)
					{
						fprintf(stderr,"\rwaiting for audio input data...");
					}
					io_simple("/wait_for_input");
				}
				else
				{
					if(shutup==0 && quiet==0)
					{
						fprintf(stderr,"\r# %" PRId64 " buffering... mc periods to go: %" PRId64 "%s",
							message_number,
							pre_buffer_size-pre_buffer_counter,
							"\033[0J"
						);
					}

					if(io_())
					{
						lo_message msgio=lo_message_new();

						lo_message_add_int64(msgio,message_number);
						lo_message_add_int64(msgio,pre_buffer_size-pre_buffer_counter);

						lo_send_message(loio, "/buffering", msgio);
						lo_message_free(msgio);
					}
				}

				fflush(stderr);

				relaxed_display_counter=0;
			}
			relaxed_display_counter++;

			//set output buffer silent
			//memset(o1, 0, port_count*bytes_per_sample*nframes);
			//always 4 bytes, 32 bit float
			memset(o1, 0, port_count*4*nframes);
		}//end for i < port_count
	}//end process_enabled==0

	//tasks independent of process_enabled 0/1

	//if sender sends less channels than we have output channels, wee need to fill them with 0
	if(input_port_count < output_port_count)
	{
		int i;
		for(i=0;i < (output_port_count-input_port_count);i++)
		{
			//sample_t *o1;
			//o1=(sample_t*)
			/////?
			jack_port_get_buffer(ioPortArray[input_port_count+i], nframes);
		}
	}

	if(last_test_cycle==1)
	{
		if(shutup==0)
		{
			fprintf(stderr,"\ntest finished after %" PRId64 " process cycles\n",process_cycle_counter);
			fprintf(stderr,"(waiting and buffering cycles not included)\n");
		}

		io_simple_long("/test_finished",process_cycle_counter);

		shutdown_in_progress=1;
	}

	//simulate long cycle process duration
	//usleep(1000);

	frames_since_cycle_start=jack_frames_since_cycle_start(client);

	return 0;
} //end process()
示例#23
0
int main(int argc, char *argv[])
{
    if (!parseArgs(the_args, &argc, argv)
        || argc < 2 || show_help) {
        printUsage(argv[0], "DOCUMENT", the_args);
        exit(1);
    }

    if (show_text[0]) {
        if (!memcmp(show_text, "physical", 9)) {
            show_text_layout = poppler::page::physical_layout;
        } else if (!memcmp(show_text, "raw", 4)) {
            show_text_layout = poppler::page::raw_order_layout;
        } else {
            error(std::string("unrecognized text mode: '") + show_text + "'");
        }
    }

    std::string file_name(argv[1]);

    std::auto_ptr<poppler::document> doc(poppler::document::load_from_file(file_name));
    if (!doc.get()) {
        error("loading error");
    }
    if (doc->is_locked()) {
        error("encrypted document");
    }

    std::cout.setf(std::ios_base::boolalpha);

    if (show_all) {
        show_info = true;
        show_perm = true;
        show_metadata = true;
        show_toc = true;
        show_fonts = true;
        show_embedded_files = true;
        show_pages = true;
    }

    if (show_info) {
        print_info(doc.get());
    }
    if (show_perm) {
        print_perm(doc.get());
    }
    if (show_metadata) {
        print_metadata(doc.get());
    }
    if (show_toc) {
        std::auto_ptr<poppler::toc> doctoc(doc->create_toc());
        print_toc(doctoc.get());
    }
    if (show_fonts) {
        print_fonts(doc.get());
    }
    if (show_embedded_files) {
        print_embedded_files(doc.get());
    }
    if (show_pages) {
        const int pages = doc->pages();
        for (int i = 0; i < pages; ++i) {
            std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl;
            std::auto_ptr<poppler::page> p(doc->create_page(i));
            print_page(p.get());
        }
    }
    if (show_text[0]) {
        const int pages = doc->pages();
        for (int i = 0; i < pages; ++i) {
            std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl;
            std::auto_ptr<poppler::page> p(doc->create_page(i));
            print_page_text(p.get());
        }
    }

    return 0;
}
示例#24
0
/**
 * main() Application entry point
 *
 * This is the main function of the FPM application, it's a minimalistic
 * example, see 'usage' function for available arguments and usage.
 *
 * Using the number of available cores as input, this example sets up
 * ODP dispatcher threads executing OFP VLAN processesing and starts
 * a CLI function on a managment core.
 *
 * @param argc int
 * @param argv[] char*
 * @return int
 *
 */
int main(int argc, char *argv[])
{
	odph_linux_pthread_t thread_tbl[MAX_WORKERS];
	appl_args_t params;
	int core_count, num_workers, ret_val;
	odp_cpumask_t cpumask;
	char cpumaskstr[64];

	/* Parse and store the application arguments */
	if (parse_args(argc, argv, &params) != EXIT_SUCCESS)
	  return EXIT_FAILURE;

	/* Print both system and application information */
	print_info(NO_PATH(argv[0]), &params);

	/*
	 * Before any ODP API functions can be called, we must first init the ODP
	 * globals, e.g. availale accelerators or software implementations for
	 * shared memory, threads, pool, qeueus, sheduler, pktio, timer, crypto
	 * and classification.
	 */
	if (odp_init_global(NULL, NULL)) {
		OFP_ERR("Error: ODP global init failed.\n");
		odp_term_global();
		return EXIT_FAILURE;
	}

	/*
	 * When the gloabel ODP level init has been done, we can now issue a
	 * local init per thread. This must also be done before any other ODP API
	 * calls may be made. Local inits are made here for shared memory,
	 * threads, pktio and scheduler.
	 */
#if ODP_VERSION < 106
	if (odp_init_local(ODP_THREAD_CONTROL) != 0) {
		OFP_ERR("Error: ODP local init failed.\n");
		odp_term_global();
		return EXIT_FAILURE;
	}
#endif

	/*
	 * Get the number of cores available to ODP, one run-to-completion thread
	 * will be created per core.
	 */
	core_count = odp_cpu_count();
	num_workers = core_count;

	if (params.core_count)
		num_workers = params.core_count;
	if (num_workers > MAX_WORKERS)
		num_workers = MAX_WORKERS;

	/*
	 * This example assumes that core #0 runs Linux kernel background tasks.
	 * By default, cores #1 and beyond will be populated with a OFP
	 * processing thread each.
	 */
	memset(&app_init_params, 0, sizeof(app_init_params));

	app_init_params.linux_core_id = 0;

	if (core_count > 1)
		num_workers--;

	/*
	 * Initializes cpumask with CPUs available for worker threads.
	 * Sets up to 'num' CPUs and returns the count actually set.
	 * Use zero for all available CPUs.
	 */
	num_workers = odp_cpumask_default_worker(&cpumask, num_workers);
	if (odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)) < 0) {
		OFP_ERR("Error: Too small buffer provided to " \
			"odp_cpumask_to_str\n");
		odp_term_global();
		return EXIT_FAILURE;
	}

	printf("Num worker threads: %i\n", num_workers);
	printf("first CPU:          %i\n", odp_cpumask_first(&cpumask));
	printf("cpu mask:           %s\n", cpumaskstr);

	app_init_params.if_count = params.if_count;
	app_init_params.if_names = params.if_names;
	app_init_params.pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook;

	/*
	 * Now that ODP has been initalized, we can initialize OFP. This will
	 * open a pktio instance for each interface supplied as argument by the
	 * user.
	 *
	 * General configuration will be to pktio and schedluer queues here in
	 * addition will fast path interface configuration.
	 */
	if (ofp_init_global(&app_init_params) != 0) {
		odp_term_global();
		return EXIT_FAILURE;
	}

	/*
	 * Create and launch dataplane dispatcher worker threads to be placed
	 * according to the cpumask, thread_tbl will be populated with the
	 * created pthread IDs.
	 *
	 * In this case, all threads will run the default_event_dispatcher
	 * function with ofp_eth_vlan_processing as argument.
	 *
	 * If different dispatchers should run, or the same be run with differnt
	 * input arguments, the cpumask is used to control this.
	 */
	memset(thread_tbl, 0, sizeof(thread_tbl));
	ret_val = ofp_linux_pthread_create(thread_tbl,
					    &cpumask,
					    default_event_dispatcher,
					    ofp_eth_vlan_processing,
					    ODP_THREAD_CONTROL
					  );
	if (ret_val != num_workers) {
		OFP_ERR("Error: Failed to create worker threads, " \
			"expected %d, got %d\n",
			num_workers, ret_val);
		odp_term_global();
		return EXIT_FAILURE;
	}

	/*
	 * Now when the ODP dispatcher threads are running, further applications
	 * can be launched, in this case, we will start the OFP CLI thread on
	 * the management core, i.e. not competing for cpu cycles with the
	 * worker threads
	 */
	ofp_start_cli_thread(app_init_params.linux_core_id, params.conf_file);

	/*
	 * If we choose to check performance, a performance monitoring client
	 * will be started on the management core. Once every second it will
	 * read the statistics from the workers from a shared memory region.
	 * Using this has negligible performance impact (<<0.01%).
	 */
	if (params.perf_stat) {
		if (start_performance(app_init_params.linux_core_id) <= 0) {
			OFP_ERR("Error: Failed to init performance monitor\n");
			odp_term_global();
			return EXIT_FAILURE;
		}
	}

	/*
	 * Wait here until all worker threads have terminated, then free up all
	 * resources allocated by odp_init_global().
	 */
	odph_linux_pthread_join(thread_tbl, num_workers);

	if (odp_term_global() != 0)
		return EXIT_FAILURE;

	printf("FPM End Main()\n");

	return EXIT_SUCCESS;
}
示例#25
0
int
exec_search(int argc, char **argv)
{
	const char *pattern = NULL;
	const char *reponame = NULL;
	int ret = EPKG_OK, ch;
	int flags;
	unsigned int opt = 0;
	match_t match = MATCH_REGEX;
	pkgdb_field search = FIELD_NONE;
	pkgdb_field label = FIELD_NONE;
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
	struct pkg *pkg = NULL;
	bool atleastone = false;

	while ((ch = getopt(argc, argv, "cDdefgL:M:opqr:S:sXx")) != -1) {
		switch (ch) {
		case 'c':	/* Same as -S comment */
			search = search_label_opt("comment");
			break;
		case 'D':	/* Same as -S description */
			search = search_label_opt("description");
			break;
		case 'd':	/* Same as -M depends-on  */
			opt |= modifier_opt("depends-on");
			break;
		case 'e':
			match = MATCH_EXACT;
			break;
		case 'f':	/* Same as -M full */
			opt |= modifier_opt("full");
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
		case 'L':
			label = search_label_opt(optarg);
			break;
		case 'M':
			opt |= modifier_opt(optarg);
			break;
		case 'o':	/* Same as -L origin */
			label = search_label_opt("origin");
			break;
		case 'p':	/* Same as -M prefix */
			opt |= modifier_opt("prefix");
			break;
		case 'q':
			quiet = true;
			break;
		case 'r':
			reponame = optarg;
			break;
		case 'S':
			search = search_label_opt(optarg);
			break;
		case 's':	/* Same as -M size */
			opt |= modifier_opt("size");
			break;
		case 'X':
			match = MATCH_EREGEX;
			break;
		case 'x':
			match = MATCH_REGEX;
			break;
		default:
			usage_search();
			return (EX_USAGE);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1) {
		usage_search();
		return (EX_USAGE);
	}

	pattern = argv[0];
	if (pattern[0] == '\0') {
		fprintf(stderr, "Pattern must not be empty!\n");
		return (EX_USAGE);
	}
	if (search == FIELD_NONE) {
		if (strchr(pattern, '/') != NULL)
			search = FIELD_ORIGIN;
		else
			search = FIELD_NAMEVER; /* Default search */
	}
	if (label == FIELD_NONE)
		label = search; /* By default, show what was searched  */

	switch(label) {
	case FIELD_NONE:
		break;		/* should never happen */
	case FIELD_ORIGIN:
		opt |= INFO_TAG_ORIGIN;
		break;
	case FIELD_NAME:
		opt |= INFO_TAG_NAME;
		break;
	case FIELD_NAMEVER:
		opt |= INFO_TAG_NAMEVER;
		break;
	case FIELD_COMMENT:
		opt |= INFO_TAG_NAMEVER|INFO_COMMENT;
		break;
	case FIELD_DESC:
		opt |= INFO_TAG_NAMEVER|INFO_DESCR;
		break;
	}

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
		return (EX_IOERR);

	if ((it = pkgdb_search(db, pattern, match, search, search,
	    reponame)) == NULL) {
		pkgdb_close(db);
		return (EX_IOERR);
	}

	flags = info_flags(opt);
	while ((ret = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {
		print_info(pkg, opt);
		atleastone = true;
	}

	pkg_free(pkg);
	pkgdb_it_free(it);
	pkgdb_close(db);

	if (!atleastone)
		ret = EPKG_FATAL;

	return ((ret == EPKG_OK || ret == EPKG_END) ? EX_OK : EX_SOFTWARE);
}
示例#26
0
int main(int argc, char *argv[])
{
	int fd;
	struct sockaddr_storage addr, rem_addr; /* Can contain both sockaddr_in and sockaddr_in6 */
	int res, on = 1;
	struct msghdr msghdr;
	struct iovec vec[1];
	char cbuf[512];  /* Buffer for ancillary data */
	char frame[8192];/* Buffer for packet data */
	int c, count = 1000000;
	uint16_t listen_port = PORT;
	int addr_family = AF_INET6; /* Default address family */

	while ((c = getopt(argc, argv, "c:l:64v:")) != -1) {
		if (c == 'c') count = atoi(optarg);
		if (c == 'l') listen_port  = atoi(optarg);
		if (c == '4') addr_family = AF_INET;
		if (c == '6') addr_family = AF_INET6;
		if (c == 'v') verbose = atoi(optarg);
	}

	fd = Socket(addr_family, SOCK_DGRAM, 0);

	memset(&addr, 0, sizeof(addr));

	if (addr_family == AF_INET) {
		struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
		addr4->sin_family = addr_family;
		addr4->sin_port   = htons(listen_port);
	} else if (addr_family == AF_INET6) {
		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr;
		addr6->sin6_family= addr_family;
		addr6->sin6_port  = htons(listen_port);
		// addr6->sin6_addr  = in6addr_any;
		// inet_pton( AF_INET6, "::", (void *)&addr6->sin6_addr.s6_addr);
	}

	if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
		perror("bind");
		return 1;
	}

	/* Socket options to get data on local destination IP */
	setsockopt(fd, SOL_IP, IP_PKTINFO, &on, sizeof(on)); /* man ip(7) */
	setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on)); /* man ipv6(7)*/

	while (1) {
		memset(&msghdr, 0, sizeof(msghdr));
		msghdr.msg_control = cbuf;
		msghdr.msg_controllen = sizeof(cbuf);
		msghdr.msg_iov = vec;
		msghdr.msg_iovlen = 1;
		vec[0].iov_base = frame;
		vec[0].iov_len = sizeof(frame);
		msghdr.msg_name = &rem_addr; /* Remote addr, updated on recv, used on send */
		msghdr.msg_namelen = sizeof(rem_addr);
		res = recvmsg(fd, &msghdr, 0);
		if (res == -1)
			break;

		if (verbose > 0) {
			print_info(&msghdr);
			printf(" Echo back packet, size=%d\n", res);
		}
		/* ok, just echo reply this frame.
		 * Using sendmsg() will provide IP_PKTINFO back to kernel
		 * to let it use the 'right' source address
		 * (destination address of the incoming packet)
		 */
		vec[0].iov_len = res;
		sendmsg(fd, &msghdr, 0);
		if (--count == 0)
			break;
	}
	return 0;
}
示例#27
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	static const uint16_t spd_addr[] = {
		// Node 0
		DIMM0, DIMM2, 0, 0,
		DIMM1, DIMM3, 0, 0,
		// Node 1
		DIMM4, DIMM6, 0, 0,
		DIMM5, DIMM7, 0, 0,
	};
	unsigned bsp_apicid = 0;
	int needs_reset = 0;
	struct sys_info *sysinfo = &sysinfo_car;

	sio_init();
	winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
	console_init();
	enable_rom_decode();

	print_info("now booting... romstage\n");

	/* Is this a CPU only reset? Or is this a secondary CPU? */
	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0. */
		/* Allow the HT devices to be found. */
		enumerate_ht_chain();
	}

	print_info("now booting... real_main\n");

	if (bist == 0)
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);

	/* Halt if there was a built in self test failure. */
	report_bist_failure(bist);

	setup_default_resource_map();
	setup_coherent_ht_domain();
	wait_all_core0_started();

	print_info("now booting... Core0 started\n");

#if CONFIG_LOGICAL_CPUS
	/* It is said that we should start core1 after all core0 launched. */
	start_other_cores();
	wait_all_other_cores_started(bsp_apicid);
#endif
	init_timer();
	ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */

	needs_reset = optimize_link_coherent_ht();
	needs_reset |= optimize_link_incoherent_ht(sysinfo);
	needs_reset |= k8t890_early_setup_ht();

	if (needs_reset) {
		print_debug("ht reset -\n");
		soft_reset();
	}

	/* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
	enable_fid_change();
	init_fidvid_bsp(bsp_apicid);

	/* Stop the APs so we can start them later in init. */
	allow_all_aps_stop(bsp_apicid);

	/* It's the time to set ctrl now. */
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);

	enable_smbus();
	sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
	post_cache_as_ram();
}
示例#28
0
文件: romstage.c 项目: mytbk/coreboot
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
	int needs_reset = 0;
	u32 bsp_apicid = 0;
	msr_t msr;
	struct cpuid_result cpuid1;
	struct sys_info *sysinfo = &sysinfo_car;

	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */
		enumerate_ht_chain();
		/* sb600_lpc_port80(); */
		sb600_pci_port80();
	}

	technexion_post_code_init();
	technexion_post_code(LED_MESSAGE_START);

	if (bist == 0)
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);

	enable_rs690_dev8();
	sb600_lpc_init();

	/* it8712f_enable_serial does not use its 1st parameter. */
	it8712f_enable_serial(0, CONFIG_TTYS0_BASE);
	it8712f_kill_watchdog();

	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);
	printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);

	setup_tim5690_resource_map();

	setup_coherent_ht_domain();

#if CONFIG_LOGICAL_CPUS
	/* It is said that we should start core1 after all core0 launched */
	wait_all_core0_started();
	start_other_cores();
#endif
	wait_all_aps_started(bsp_apicid);

	ht_setup_chains_x(sysinfo);

	/* run _early_setup before soft-reset. */
	rs690_early_setup();
	sb600_early_setup();

	/* Check to see if processor is capable of changing FIDVID  */
	/* otherwise it will throw a GP# when reading FIDVID_STATUS */
	cpuid1 = cpuid(0x80000007);
	if ((cpuid1.edx & 0x6) == 0x6) {
		/* Read FIDVID_STATUS */
		msr=rdmsr(0xc0010042);
		printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);

		enable_fid_change();
		enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
		init_fidvid_bsp(bsp_apicid);

		/* show final fid and vid */
		msr=rdmsr(0xc0010042);
		printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
	} else {
		printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
	}

	needs_reset = optimize_link_coherent_ht();
	needs_reset |= optimize_link_incoherent_ht(sysinfo);
	rs690_htinit();
	printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);

	if (needs_reset) {
		print_info("ht reset -\n");
		soft_reset();
	}

	speaker_init(255);
	speaker_on_nodelay();

	allow_all_aps_stop(bsp_apicid);

	/* It's the time to set ctrl now; */
	printk(BIOS_DEBUG, "sysinfo->nodes: %2x  sysinfo->ctrl: %p  spd_addr: %p\n",
		     sysinfo->nodes, sysinfo->ctrl, spd_addr);

	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);

	technexion_post_code(LED_MESSAGE_RAM);

	sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);

	speaker_off_nodelay();

	rs690_before_pci_init();
	sb600_before_pci_init();

	post_cache_as_ram();
}
示例#29
0
文件: romstage.c 项目: mytbk/coreboot
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	struct sys_info *sysinfo = &sysinfo_car;
	static const u8 spd_addr[] = {
				RC00, 0x52,  0x53,  0, 0, 0x50,  0x51,  0, 0,
				//RC00, DIMM2, DIMM3, 0, 0, DIMM0, DIMM1, 0, 0,
			};
	u32 bsp_apicid = 0;
	u32 val;
	msr_t msr;

	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */
		/* mov bsp to bus 0xff when > 8 nodes */
		set_bsp_node_CHtExtNodeCfgEn();
		enumerate_ht_chain();

		/* SR56x0 pcie bridges block pci_locate_device() before pcie training.
		 * disable all pcie bridges on SR56x0 to work around it
		 */
		sr5650_disable_pcie_bridge();
		sb7xx_51xx_lpc_port80();
	}

	post_code(0x30);

	if (bist == 0) {
		bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
		/* All cores run this but the BSP(node0,core0) is the only core that returns. */
	}

	post_code(0x32);

	enable_sr5650_dev8();
	sb7xx_51xx_lpc_init();

	sb7xx_51xx_enable_wideio(0, 0x1600);

	wpcm450_enable_dev(WPCM450_SP1, 0x164E, CONFIG_TTYS0_BASE);

	sb7xx_51xx_disable_wideio(0);

	console_init();

//	dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	// Load MPB
	val = cpuid_eax(1);
	printk(BIOS_DEBUG, "BSP Family_Model: %08x \n", val);
	printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
	printk(BIOS_DEBUG, "bsp_apicid = %02x \n", bsp_apicid);
	printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx \n", cpu_init_detectedx);

	/* Setup sysinfo defaults */
	set_sysinfo_in_ram(0);

	update_microcode(val);

	post_code(0x33);

	cpuSetAMDMSR();
	post_code(0x34);

	/* TODO: The Kernel must support 12 processor, otherwise the interrupt
	 * can not work correctly. */
	amd_ht_init(sysinfo);
	post_code(0x35);

	/* Setup nodes PCI space and start core 0 AP init. */
	finalize_node_setup(sysinfo);

	/* Setup any mainboard PCI settings etc. */
	setup_mb_resource_map();
	post_code(0x36);

	/* wait for all the APs core0 started by finalize_node_setup. */
	/* FIXME: A bunch of cores are going to start output to serial at once.
	   It would be nice to fixup prink spinlocks for ROM XIP mode.
	   I think it could be done by putting the spinlock flag in the cache
	   of the BSP located right after sysinfo.
	 */
	wait_all_core0_started();

#if CONFIG_LOGICAL_CPUS
	/* Core0 on each node is configured. Now setup any additional cores. */
	printk(BIOS_DEBUG, "start_other_cores()\n");
	start_other_cores();
	post_code(0x37);
	wait_all_other_cores_started(bsp_apicid);
#endif

	post_code(0x38);

	/* run _early_setup before soft-reset. */
	sr5650_early_setup();
	sb7xx_51xx_early_setup();

#if CONFIG_SET_FIDVID
	msr = rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);

	/* FIXME: The sb fid change may survive the warm reset and only
	   need to be done once.*/
	enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);

	post_code(0x39);

	if (!warm_reset_detect(0)) {			// BSP is node 0
		init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
	} else {
		init_fidvid_stage2(bsp_apicid, 0);	// BSP is node 0
	}

	post_code(0x3A);

	/* show final fid and vid */
	msr=rdmsr(0xc0010071);
	printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);
#endif

	sr5650_htinit();

	/* Reset for HT, FIDVID, PLL and errata changes to take affect. */
	if (!warm_reset_detect(0)) {
		print_info("...WARM RESET...\n\n\n");
		soft_reset();
		die("After soft_reset_x - shouldn't see this message!!!\n");
	}

	post_code(0x3B);

	/* It's the time to set ctrl in sysinfo now; */
	printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
	fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);

	post_code(0x40);


	printk(BIOS_DEBUG, "raminit_amdmct()\n");
	raminit_amdmct(sysinfo);
	post_code(0x41);

/*
	dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
	dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
*/

//	ram_check(0x00200000, 0x00200000 + (640 * 1024));
//	ram_check(0x40200000, 0x40200000 + (640 * 1024));

//	die("After MCT init before CAR disabled.");

	sr5650_before_pci_init();
	sb7xx_51xx_before_pci_init();

	post_code(0x42);
	post_cache_as_ram();	// BSP switch stack to ram, copy then execute LB.
	post_code(0x43);	// Should never see this post code.
}
示例#30
0
文件: simple.c 项目: estock/spot
void command_loop(struct despotify_session* ds)
{
    bool loop = true;
    char buf[80];
    struct playlist* rootlist = NULL;
    struct playlist* searchlist = NULL;
    struct search_result *search = NULL;
    struct album_browse* playalbum = NULL;

    print_help();

    do {
        wprintf(L"\n> ");
        fflush(stdout);
        bzero(buf, sizeof buf);
        fgets(buf, sizeof buf -1, stdin);
        buf[strlen(buf) - 1] = 0; /* remove newline */

        /* list */
        if (!strncmp(buf, "list", 4)) {
            int num = atoi(buf + 5);
            if (num) {
                struct playlist* p = get_playlist(rootlist, num);

                if (p) {
                    print_tracks(p->tracks);
                    lastlist = p;
                }
            }
            else {
                if (!rootlist)
                    rootlist = despotify_get_stored_playlists(ds);
                print_list_of_lists(rootlist);
            }
        }

        /* rename */
        else if (!strncmp(buf, "rename", 6)) {
            int num = 0;
            char *name = 0;
            if (strlen(buf) > 9) {
                num = atoi(buf + 7);
                name = strchr(buf + 7, ' ') + 1;
            }

            if (num && name && name[0]) {
                struct playlist* p = get_playlist(rootlist, num);

                if (p) {
                    if (despotify_rename_playlist(ds, p, name))
                        wprintf(L"Renamed playlist %d to \"%s\".\n", num, name);
                    else
                        wprintf(L"Rename failed: %s\n", despotify_get_error(ds));
                }
            }
            else
                wprintf(L"Usage: rename [num] [string]\n");
        }

        /* collab */
        else if (!strncmp(buf, "collab", 6)) {
            int num = 0;
            if (strlen(buf) > 7)
                num = atoi(buf + 7);

            if (num) {
                struct playlist* p = get_playlist(rootlist, num);

                if (p) {
                    if (despotify_set_playlist_collaboration(ds, p, !p->is_collaborative))
                        wprintf(L"Changed playlist %d collaboration to %s.\n",
                                num, p->is_collaborative ? "ON" : "OFF");
                    else
                        wprintf(L"Setting playlist collaboration state failed: %s\n",
                                despotify_get_error(ds));
                }
            }
            else
                wprintf(L"Usage: collab [num]\n");
        }

        /* search */
        else if (!strncmp(buf, "search", 6)) {
            if (buf[7]) {
                if (search)
                    despotify_free_search(search);

                despotify_stop(ds); /* since we replace the list */
                search = despotify_search(ds, buf + 7, MAX_SEARCH_RESULTS);
                if (!search) {
                    wprintf(L"Search failed: %s\n", despotify_get_error(ds));
                    continue;
                }
                searchlist = search->playlist;
            }
            else if (searchlist && (searchlist->num_tracks < search->total_tracks))
                if (!despotify_search_more(ds, search, searchlist->num_tracks, MAX_SEARCH_RESULTS)) {
                    wprintf(L"Search failed: %s\n", despotify_get_error(ds));
                    continue;
                }

            if (searchlist) {
                print_search(search);


                lastlist = searchlist;
            }
            else
                wprintf(L"No previous search\n");
        }

        /* artist */
        else if (!strncmp(buf, "artist", 6)) {
            int num = atoi(buf + 7);
            if (!num) {
                wprintf(L"usage: artist [num]\n");
                continue;
            }
            if (!lastlist) {
                wprintf(L"No playlist\n");
                continue;
            }

            /* find the requested track */
            struct track* t = lastlist->tracks;
            for (int i=1; i<num; i++)
                t = t->next;

            for (struct artist* aptr = t->artist; aptr; aptr = aptr->next) {
                struct artist_browse* a = despotify_get_artist(ds, aptr->id);
                print_artist(a);
                despotify_free_artist_browse(a);
            }
        }

        /* album */
        else if (!strncmp(buf, "album", 5)) {
            int num = atoi(buf + 6);
            if (!num) {
                wprintf(L"usage: album [num]\n");
                continue;
            }
            if (!lastlist) {
                wprintf(L"No playlist\n");
                continue;
            }

            /* find the requested track */
            struct track* t = lastlist->tracks;
            for (int i=1; i<num; i++)
                t = t->next;

            if (t) {
                struct album_browse* a = despotify_get_album(ds, t->album_id);
                if (a) {
                    print_album(a);
                    despotify_free_album_browse(a);
                }
                else
                    wprintf(L"Got no album for id %s\n", t->album_id);
            }
        }

        /* playalbum */
        else if (!strncmp(buf, "playalbum", 9)) {
            int num = atoi(buf + 10);
            if (!num) {
                wprintf(L"usage: playalbum [num]\n");
                continue;
            }
            if (!lastlist) {
                wprintf(L"No playlist\n");
                continue;
            }

            /* find the requested track */
            struct track* t = lastlist->tracks;
            for (int i=1; i<num; i++)
                t = t->next;


            if (t) {
                if (playalbum)
                    despotify_free_album_browse(playalbum);

                despotify_stop(ds);
                playalbum = despotify_get_album(ds, t->album_id);

                if (playalbum)
                    despotify_play(ds, playalbum->tracks, true);
                else
                    wprintf(L"Got no album for id %s\n", t->album_id);
            }
        }

        /* uri */
        else if (!strncmp(buf, "uri", 3)) {
            char *uri = buf + 4;
            if(strlen(uri) == 0) {
                wprintf(L"usage: info <uri>\n");
                continue;
            }

            struct link* link = despotify_link_from_uri(uri);
            struct album_browse* al;
            struct artist_browse* ar;
            struct playlist* pls;
            struct search_result* s;
            struct track* t;

            switch(link->type) {
                case LINK_TYPE_ALBUM:
                    al = despotify_link_get_album(ds, link);
                    if(al) {
                        print_album(al);
                        despotify_free_album_browse(al);
                    }
                    break;

                case LINK_TYPE_ARTIST:
                    ar = despotify_link_get_artist(ds, link);
                    if(ar) {
                        print_artist(ar);
                        despotify_free_artist_browse(ar);
                    }
                    break;

                case LINK_TYPE_PLAYLIST:
                    pls = despotify_link_get_playlist(ds, link);
                    if(pls) {
                        print_playlist(pls);
                        despotify_free_playlist(pls);
                    }
                    break;

                case LINK_TYPE_SEARCH:
                    s = despotify_link_get_search(ds, link);
                    if(s) {
                        print_search(s);
                        despotify_free_search(s);
                    }
                    break;

                case LINK_TYPE_TRACK:
                    t = despotify_link_get_track(ds, link);
                    if(t) {
                        print_track_full(t);
                        despotify_free_track(t);
                    }
                    break;

                default:
                    wprintf(L"%s is a invalid Spotify URI\n", uri);
            }

            despotify_free_link(link);
        }

        /* portrait */
        else if (!strncmp(buf, "portrait", 8)) {
            int num = atoi(buf + 9);
            if (!num) {
                wprintf(L"usage: portrait [num]\n");
                continue;
            }
            if (!lastlist) {
                wprintf(L"No playlist\n");
                continue;
            }

            /* find the requested artist */
            struct track* t = lastlist->tracks;
            for (int i=1; i<num; i++)
                t = t->next;
            struct artist_browse* a = despotify_get_artist(ds, t->artist->id);
            if (a && a->portrait_id[0]) {
                int len;
                void* portrait = despotify_get_image(ds, a->portrait_id, &len);
                if (portrait && len) {
                    wprintf(L"Writing %d bytes into portrait.jpg\n", len);
                    FILE* f = fopen("portrait.jpg", "w");
                    if (f) {
                        fwrite(portrait, len, 1, f);
                        fclose(f);
                    }
                    free(portrait);
                }
            }
            else
                wprintf(L"Artist %s has no portrait.\n", a->name);
            despotify_free_artist_browse(a);
        }

        /* play */
        else if (!strncmp(buf, "play", 4)) {
            if (!lastlist) {
                wprintf(L"No list to play from. Use 'list' or 'search' to select a list.\n");
                continue;
            }

            /* skip to track <num> */
            listoffset = atoi(buf + 5);
            struct track* t = lastlist->tracks;
            for (int i=1; i<listoffset && t; i++)
                t = t->next;
            if (t)
                despotify_play(ds, t, true);
            else
                wprintf(L"Invalid track number %d\n", listoffset);
        }

        /* stop */
        else if (!strncmp(buf, "stop", 4)) {
            despotify_stop(ds);
        }

        /* pause */
        else if (!strncmp(buf, "pause", 5)) {
            despotify_pause(ds);
        }

        /* resume */
        else if (!strncmp(buf, "resume", 5)) {
            despotify_resume(ds);
        }

        /* info */
        else if (!strncmp(buf, "info", 4)) {
            print_info(ds);
        }

        /* help */
        else if (!strncmp(buf, "help", 4)) {
            print_help();
        }

        /* quit */
        else if (!strncmp(buf, "quit", 4)) {
            loop = false;
        }
    } while(loop);

    if (rootlist)
        despotify_free_playlist(rootlist);

    if (search)
        despotify_free_search(search);

    if (playalbum)
        despotify_free_album_browse(playalbum);
}