コード例 #1
0
ファイル: main.c プロジェクト: Telegram-FFOS/tg
int main (int argc, char **argv) {
  signal (SIGSEGV, sig_handler);
  signal (SIGABRT, sig_handler);

  log_level = 10;
  
  args_parse (argc, argv);
  printf (
    "Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"
    "Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
    "This is free software, and you are welcome to redistribute it\n"
    "under certain conditions; type `show_license' for details.\n"
  );
  running_for_first_time ();
  parse_config ();


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();
  
  return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: platphorm/telegram_rb
int telegram_main(char *pub_key) {
    //signal (SIGSEGV, sig_segv_handler);
    //signal (SIGABRT, sig_abrt_handler);
    //verbosity = 2;

    rsa_public_key_name = pub_key;
    running_for_first_time ();
    parse_config ();

    //get_terminal_attributes ();
    inner_main ();
    return 0;
}
コード例 #3
0
ファイル: tmain.c プロジェクト: Ken2713/sigram
int tmain (int argc, char **argv) {
//  signal (SIGSEGV, sig_segv_handler);
//  signal (SIGABRT, sig_abrt_handler);

  log_level = 10;

  args_parse (argc, argv);
  running_for_first_time ();
  parse_config ();


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();

  return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: analani/tg
int main (int argc, char **argv) {
  signal (SIGSEGV, termination_signal_handler);
  signal (SIGABRT, termination_signal_handler);
  signal (SIGBUS, termination_signal_handler);
  signal (SIGQUIT, termination_signal_handler);
  signal (SIGFPE, termination_signal_handler);

  signal (SIGPIPE, SIG_IGN);
  
  signal (SIGTERM, sig_term_handler);
  signal (SIGINT, sig_term_handler);

  rl_catch_signals = 0;


  log_level = 10;
  
  args_parse (argc, argv);
  
  change_user_group ();

  if (port > 0) {
    struct sockaddr_in serv_addr;

    sfd = socket (AF_INET, SOCK_STREAM, 0);
    if (sfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl (0x7f000001);
    serv_addr.sin_port = htons (port);
 
    if (bind (sfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (sfd, 5);
  } else {
    sfd = -1;
  }
  
  if (unix_socket) {
    assert (strlen (unix_socket) < 100);
    struct sockaddr_un serv_addr;

    usfd = socket (AF_UNIX, SOCK_STREAM, 0);
    if (usfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sun_family = AF_UNIX;

    snprintf (serv_addr.sun_path, 108, "%s", unix_socket);
 
    if (bind (usfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (usfd, 5);    
  } else {
    usfd = -1;
  }

  if (daemonize) {
    signal (SIGHUP, sighup_handler);
    reopen_logs ();
  }
  signal (SIGUSR1, sigusr1_handler);

  if (!disable_output) {
    printf (
      "Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
      "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
      "This is free software, and you are welcome to redistribute it\n"
      "under certain conditions; type `show_license' for details.\n"
    );
  }
  running_for_first_time ();
  parse_config ();

  tgl_set_rsa_key ("/etc/" PROG_NAME "/server.pub");
  tgl_set_rsa_key ("tg-server.pub");


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();
  
  return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: pwrtelegram/tg
int main (int argc, char **argv) {
  signal (SIGSEGV, termination_signal_handler);
  signal (SIGABRT, termination_signal_handler);
  signal (SIGBUS, termination_signal_handler);
  signal (SIGQUIT, termination_signal_handler);
  signal (SIGFPE, termination_signal_handler);

  signal (SIGPIPE, SIG_IGN);
  
  signal (SIGTERM, sig_term_handler);
  signal (SIGINT, sig_term_handler);

  rl_catch_signals = 0;


  log_level = 10;
  
  args_parse (argc, argv);
  
  change_user_group ();

  if (port > 0) {
    struct sockaddr_in serv_addr;
    int yes = 1;
    sfd = socket (AF_INET, SOCK_STREAM, 0);
    if (sfd < 0) {
      perror ("socket");
      exit(1);
    }

    if(setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
      perror("setsockopt");
      exit(1);
    }
    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = accept_any_tcp ? INADDR_ANY : htonl (0x7f000001);
    serv_addr.sin_port = htons (port);
 
    if (bind (sfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (sfd, 5);
  } else {
    sfd = -1;
  }
  
  if (unix_socket) {
    assert (strlen (unix_socket) < 100);
    struct sockaddr_un serv_addr;

    usfd = socket (AF_UNIX, SOCK_STREAM, 0);
    if (usfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sun_family = AF_UNIX;

    snprintf (serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s", unix_socket);
 
    if (bind (usfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (usfd, 5);    
  } else {
    usfd = -1;
  }

  if (daemonize) {
    signal (SIGHUP, sighup_handler);
    reopen_logs ();
  }
  signal (SIGUSR1, sigusr1_handler);

  if (!disable_output) {
    printf (
      "Telegram-cli version " TELEGRAM_CLI_VERSION ", Copyright (C) 2013-2015 Vitaly Valtman\n"
      "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
      "This is free software, and you are welcome to redistribute it\n"
      "under certain conditions; type `show_license' for details.\n"
      "Telegram-cli uses libtgl version " TGL_VERSION "\n"
#ifndef TGL_AVOID_OPENSSL 
      "Telegram-cli includes software developed by the OpenSSL Project\n"
      "for use in the OpenSSL Toolkit. (http://www.openssl.org/)\n"
#endif
#ifdef USE_PYTHON
      "Telegram-cli uses libpython version " PY_VERSION "\n"
#endif
    );
  }
  running_for_first_time ();
  parse_config ();

  #ifdef __FreeBSD__
  tgl_set_rsa_key (TLS, "/usr/local/etc/" PROG_NAME "/server.pub");
  #else
  tgl_set_rsa_key (TLS, "/etc/" PROG_NAME "/server.pub");
  #endif
  tgl_set_rsa_key (TLS, "tg-server.pub");

  tgl_set_rsa_key_direct (TLS, tglmp_get_default_e (), tglmp_get_default_key_len (), tglmp_get_default_key ());

  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file, lua_param);
  }
  #endif
  #ifdef USE_PYTHON
  if (python_file) {
    py_init (python_file);
  }
  #endif


  inner_main ();
  
  return 0;
}
コード例 #6
0
ファイル: tone-generator.c プロジェクト: sideb0ard/audio-tool
int tone_generator_main(const struct audio_tool_config *at_config, int argc, char* argv[])
{
	struct tone_generator_config config = {
		.card = 0,
		.device = 0,
		.chan_mask = ~0,
	};
    int i;
    for ( i = 0; i < argc; i++) {
        printf("ARGV %d :: %s\n", i, argv[i]);
    }
    printf("DUration : %d\n", at_config->duration);

	struct pcm_config pcm_config;
	struct wave_table *ptr, *table;
	struct wave_scale wave_scale;
	double freq;
	char *arg_wave_type, *arg_freq, *arg_voldb;
	double tmp;

	if ((argc < 3) || (argc > 4)) {
		usage();
		return 1;
	}

	if (check_wave_tables())
		return 1;

	arg_wave_type = argv[1];
	arg_freq = argv[2];
	if (argc > 3)
		arg_voldb = argv[3];
	else
		arg_voldb = "0";

	/* Set sane defaults */
	memset(&pcm_config, 0, sizeof(struct pcm_config));
	switch (at_config->bits) {
	case 8: pcm_config.format = PCM_FORMAT_S8; break;
	case 16: pcm_config.format = PCM_FORMAT_S16_LE; break;
	case 24: pcm_config.format = PCM_FORMAT_S24_LE; break;
	case 32: pcm_config.format = PCM_FORMAT_S32_LE; break;
	default:
		assert(0);
	}

	config.device = at_config->device;
	config.card = at_config->card;
	pcm_config.period_size = at_config->period_size;
	pcm_config.period_count = at_config->num_periods;
	pcm_config.rate = at_config->rate;
	pcm_config.channels = at_config->channels;
	config.chan_mask = at_config->channel_mask;
	config.duration = at_config->duration * pcm_config.rate;
	config.bits = at_config->bits;

	for (ptr = g_wave_tables ; ptr->name ; ++ptr) {
		if (strcmp(arg_wave_type, ptr->name) == 0) {
			table = ptr;
			assert( IS_POWER_OF_TWO(table->length) );
			assert( table->mask == table->length - 1 );
			break;
		}
	}
	if (ptr->name == 0) {
		fprintf(stderr, "Invalied wave_type parameter\n");
		return 1;
	}

	tmp = atof(arg_freq);
	if (tmp < 10.0) {
		fprintf(stderr, "Error: frequency must be > 10Hz\n");
		return 1;
	}
	freq = tmp;

	tmp = atof(arg_voldb);
	if (tmp < 0 ) {
		fprintf(stderr, "Volume attenuation must be greater than 0 dB FS\n");
		return 1;
	}
	/* Convert db to fraction */
	tmp = -tmp;
	tmp = pow(10.0, tmp/10.0);
	config.volume = (unsigned short) (tmp * ((double)USHRT_MAX));

	tmp = ((double)pcm_config.rate) / freq;
	wave_scale.length = tmp;
	tmp = (tmp - wave_scale.length) * 0xFFF;
	wave_scale.sub = tmp;
	wave_scale.sub_den = 0xFFF;
	wave_scale.sub_shift = 12;

	/* This restriction prevents overflows in render()
	 */
	{
		uint16_t bits = 0;
		while ((1<<bits) < table->length) ++bits;
		if (wave_scale.sub_shift + bits > 24) {
			fprintf(stderr, "bits(wave_scale) + bits(table.length) "
				" must be less than or equal to 24\n");
			return 1;
		}
	}

	memcpy(&config.pcm_config, &pcm_config, sizeof(pcm_config));
	memcpy(&config.wave_scale, &wave_scale, sizeof(wave_scale));
	config.wave_table = table;

	return inner_main(config);

	return 0;
}