Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
int main (int argc, char* argv[]) {
    int f[2000];
    oram_args_t *args = malloc(sizeof(oram_args_t));
    args_parse(args, argc, argv);
    signal(SIGINT, sig_handler);
    signal(SIGTERM, sig_handler);
    if (args->mode == ORAM_MODE_SERVER) {
        if (args->daemon == ORAM_DAEMON_STOP) {
            if (daemon_stop(args) != 0) {
                errf("cannot stop");
                return -1;
            }
            return 0;
        }
        else if (args->daemon == ORAM_DAEMON_RESTART) {
            if (daemon_stop(args) != 0) {
                errf("cannot stop");
                return -1;
            }
            if (daemon_start(args) != 0) {
                errf("cannot start");
                return -1;
            }
        }
        else if (args->daemon == ORAM_DAEMON_START) {
            if (daemon_start(args) != 0) {
                errf("cannot start");
                return -1;
            }
        }
        server_run(args, &sv_ctx);
    }
    else {
        client_ctx ctx;
        oram_client_args ar;
        ar.verbose = 1;
        if (client_init(&ctx, &ar) < 0)
            return -1;
//        if (client_create(&ctx, 6000, 1) < 0)
//            return -1;
        if (client_load(&ctx, 1) < 0)
            return -1;
        unsigned char data[ORAM_BLOCK_SIZE];
        int m;
        for(m = 0;m < 100;m++) {
            data[0] = m;
            oblivious_access(m, ORAM_ACCESS_WRITE, data, &ctx);
        }
        for(m = 0;m < 100;m++) {
            oblivious_access(m, ORAM_ACCESS_READ, data, &ctx);
            f[m] = data[0];
        }
        for (m = 0;m < 100;m++)
            assert(f[m] == m);
        client_save(&ctx, 0);
    }
    return 0;
}
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
	int ierr  = 0;
	int niter = 0;
	int imax  = 0;
	int jmax  = 0;
	int kmax  = 0;
	double north  = 0.0;
	double south  = 0.0;
	double east   = 0.0;
	double west   = 0.0;
	double top    = 0.0;
	double bottom = 0.0;
	char *filename = NULL;
	struct grid phi = {0};

	int i, j, k, x;
	int u, v, w;

	ierr = args_parse(argc, argv, &imax, &jmax, &kmax, &niter,
			  &north, &south, &east, &west, &top, &bottom,
			  &filename);

	domain_init(&phi, imax, jmax, kmax, 
		    north, south, east, west, top, bottom);

#if 0
	x = 0;
	for (i=0; i < phi.imax; ++i) {
		for (j=0; j < phi.jmax; ++j) {
			for (k=0; k < phi.kmax; ++k) {
				domain_n(&phi, x, &u, &v, &w);
				printf("%02d (%02d,%02d,%02d): %02d (%02d,%02d,%02d) %02g\n",
				       x, i, j, k,
				       domain_ijk(&phi, i, j, k),
				       u, v, w,
				       phi.data[domain_ijk(&phi, i, j, k)]);
				++x;
			}
		}
	}
#endif

	jacobi_solver(&phi, niter, filename);

	domain_fini(&phi);

	if (filename) {
		free(filename);
		filename = NULL;
	}

	return(EXIT_SUCCESS);
}
Exemplo n.º 4
0
/**
 * Everything begins "here"
 * 
 * @param   argc  The number of command line arguments
 * @param   argv  Command line arguments
 * @return        Zero on and only on success
 */
int main(int argc, char* argv[])
{
  int rc = 0;
  size_t first, diff, end;
  
  
  args_init((char*)"Rotate images in a pattern",
	    (char*)"crazy-rotate [--] <first> <gaps+1> [<last>]",
	    NULL, NULL, 1, 0, args_standard_abbreviations);
  
  
  args_add_option(args_new_argumentless(NULL, 0, (char*)"--help", NULL),
		  (char*)"Prints this help message");
  
  
  args_parse(argc, argv);
  args_support_alternatives();
  
  
  if (args_opts_used((char*)"--help"))
    {
      args_help();
      goto exit;
    }
  if (args_unrecognised_count || (args_files_count < 2) || (args_files_count > 3))
    goto invalid_opts;
  
  
  first = parse_size(args_files[0]);
  diff  = parse_size(args_files[1]);
  end   = args_files_count == 3 ? parse_size(args_files[2]) : (SIZE_MAX - 1);
  
  if (!first || !diff || !end)
    goto invalid_opts;
  if (end++ == SIZE_MAX)
    t ((errno = ERANGE));
  
  t (perform_rotate(first, diff, end));
  
  
 exit:
  args_dispose();
  return rc;
 invalid_opts:
  args_help();
 fail:
  if (errno)
    perror(*argv);
  rc = 1;
  goto exit;
}
Exemplo n.º 5
0
static enum cmd_retval
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args		*args = self->args, *new_args;
	struct window_pane	*wp = item->target.wp;
	const char		*s = args->argv[0];
	char			*filter, *argv = { NULL };
	int			 C, N, T;

	C = args_has(args, 'C');
	N = args_has(args, 'N');
	T = args_has(args, 'T');

	if (!C && !N && !T)
		C = N = T = 1;

	if (C && N && T) {
		xasprintf(&filter,
		    "#{||:"
		    "#{C:%s},#{||:#{m:*%s*,#{window_name}},"
		    "#{m:*%s*,#{pane_title}}}}",
		    s, s, s);
	} else if (C && N) {
		xasprintf(&filter,
		    "#{||:#{C:%s},#{m:*%s*,#{window_name}}}",
		    s, s);
	} else if (C && T) {
		xasprintf(&filter,
		    "#{||:#{C:%s},#{m:*%s*,#{pane_title}}}",
		    s, s);
	} else if (N && T) {
		xasprintf(&filter,
		    "#{||:#{m:*%s*,#{window_name}},#{m:*%s*,#{pane_title}}}",
		    s, s);
	} else if (C)
		xasprintf(&filter, "#{C:%s}", s);
	else if (N)
		xasprintf(&filter, "#{m:*%s*,#{window_name}}", s);
	else
		xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s);

	new_args = args_parse("", 1, &argv);
	args_set(new_args, 'f', filter);

	window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args);

	args_free(new_args);
	free(filter);

	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
    args_t args;

    args_init (&args);

    if (!args_parse (&args, argc, argv)) {
	return -1;
    } else {
	if (args.Verbose)
	    args_print (&args);
    }
    return ! Yee_Compare(&args);
}
Exemplo n.º 7
0
Arquivo: ipkg.c Projeto: nhanh0/hah
int main(int argc, const char *argv[])
{
    int err, optind;
    args_t args;
    char *cmd_name;
    ipkg_cmd_t *cmd;
    ipkg_conf_t ipkg_conf;

    error_list=NULL;

    args_init(&args);

    optind = args_parse(&args, argc, argv);
    if (optind == argc || optind < 0) {
        args_usage("ipkg must have one sub-command argument");
    }

    cmd_name = argv[optind++];

    err = ipkg_conf_init(&ipkg_conf, &args);
    if (err) {
        return err;
    }

    args_deinit(&args);

    cmd = ipkg_cmd_find(cmd_name);
    if (cmd == NULL) {
        fprintf(stderr, "%s: unknown sub-command %s\n", argv[0], cmd_name);
        args_usage(NULL);
    }

    if (cmd->requires_args && optind == argc) {
        fprintf(stderr, "%s: the ``%s'' command requires at least one argument\n",
                __FUNCTION__, cmd_name);
        args_usage(NULL);
    }

    err = ipkg_cmd_exec(cmd, &ipkg_conf, argc - optind, argv + optind);

    if ( err == 0 ) {
        ipkg_message(ipkg_conf, IPKG_NOTICE, "Succesfully done.\n");
    } else {
        ipkg_message(ipkg_conf, IPKG_NOTICE, "Error returned. Return value is %d\n.",err);

    }

}
Exemplo n.º 8
0
/* Handles arguments received from remote instance. */
static void
parse_received_arguments(char *argv[])
{
	int argc = 0;
	args_t args = {};

	while(argv[argc] != NULL)
	{
		argc++;
	}

	(void)vifm_chdir(argv[0]);
	opterr = 0;
	args_parse(&args, argc, argv, argv[0]);
	args_process(&args, 0);

	exec_startup_commands(&args);
	args_free(&args);

	if(NONE(vle_mode_is, NORMAL_MODE, VIEW_MODE))
	{
		return;
	}

#ifdef _WIN32
	SwitchToThisWindow(GetConsoleWindow(), TRUE);
	BringWindowToTop(GetConsoleWindow());
	SetForegroundWindow(GetConsoleWindow());
#endif

	if(view_needs_cd(&lwin, args.lwin_path))
	{
		remote_cd(&lwin, args.lwin_path, args.lwin_handle);
	}

	if(view_needs_cd(&rwin, args.rwin_path))
	{
		remote_cd(&rwin, args.rwin_path, args.rwin_handle);
	}

	if(need_to_switch_active_pane(args.lwin_path, args.rwin_path))
	{
		change_window();
	}

	ui_sb_clear();
	curr_stats.save_msg = 0;
}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
	struct args args;
	struct setup s;
	struct xm_allocator *allocator;
	struct xm_tensor *a, *b, *c;
	const char *path;

	xm_set_log_stream(stderr);

	args = args_parse(argc, argv);
	args_print(&args);

	s = make_benchmark[args.id-1](args.size_o, args.size_v);

	path = args.is_inmem ? NULL : "xmpagefile";
	if ((allocator = xm_allocator_create(path)) == NULL)
		fatal("xm_allocator_create");

	if ((a = xm_tensor_create(allocator, &s.dima, "a")) == NULL)
		fatal("xm_tensor_create(a)");
	if ((b = xm_tensor_create(allocator, &s.dimb, "b")) == NULL)
		fatal("xm_tensor_create(b)");
	if ((c = xm_tensor_create(allocator, &s.dimc, "c")) == NULL)
		fatal("xm_tensor_create(c)");

	if (s.init_a(a, allocator, args.block_size, XM_INIT_RAND))
		fatal("init(a)");
	if (s.init_b(b, allocator, args.block_size, XM_INIT_RAND))
		fatal("init(b)");
	if (s.init_c(c, allocator, args.block_size, XM_INIT_ZERO))
		fatal("init(c)");

	if (xm_contract(s.alpha, a, b, s.beta, c, s.idxa, s.idxb, s.idxc))
		fatal("xm_contract");

	xm_tensor_free(a);
	xm_tensor_free(b);
	xm_tensor_free(c);
	xm_allocator_destroy(allocator);
	return (0);
}
Exemplo n.º 10
0
int 
svg2png_main (int argc, char **argv)
{
    args_t args;
    args_parse (&args, argc, argv);
    FILE *svg_file, *png_file;
    svg_cairo_status_t status;

    if (strcmp (args.svg_filename, "-") == 0) {
	svg_file = stdin;
    } else {
	svg_file = fopen (args.svg_filename, "r");
	if (svg_file == NULL) {
	    fprintf (stderr, "%s: failed to open %s: %s\n",
		     argv[0], args.svg_filename, strerror(errno));
	    return 1;
	}
    }

    if (strcmp (args.png_filename, "-") == 0) {
	png_file = stdout;
    } else {
	png_file = fopen (args.png_filename, "w");
	if (png_file == NULL) {
	    fprintf (stderr, "%s: failed to open %s: %s\n",
		     argv[0], args.png_filename, strerror (errno));
	    return 1;
	}
    }
	       
    status = render_to_png (svg_file, png_file, args.scale, args.width, args.height);
    if (status) {
	fprintf (stderr, "%s: failed to render %s\n", argv[0], args.svg_filename);
	return 1;
    }

    if (svg_file != stdin)
	fclose (svg_file);
    if (png_file != stdout)
	fclose (png_file);

    return 0;
}
Exemplo n.º 11
0
struct cmd *
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
{
	const struct cmd_entry	*entry;
	struct cmd		*cmd;
	struct args		*args;

	*cause = NULL;
	if (argc == 0) {
		xasprintf(cause, "no command");
		return (NULL);
	}

	if ((entry = cmd_find_cmd(argv[0])) == NULL) {
		xasprintf(cause, "unknown command: %s", argv[0]);
		return (NULL);
	}

	args = args_parse(entry->args_template, argc, argv);
	if (args == NULL)
		goto usage;
	if (entry->args_lower != -1 && args->argc < entry->args_lower)
		goto usage;
	if (entry->args_upper != -1 && args->argc > entry->args_upper)
		goto usage;

	cmd = xcalloc(1, sizeof *cmd);
	cmd->entry = entry;
	cmd->args = args;

	if (file != NULL)
		cmd->file = xstrdup(file);
	cmd->line = line;

	return (cmd);

usage:
	if (args != NULL)
		args_free(args);
	xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
	return (NULL);
}
Exemplo n.º 12
0
int
main(int argc, char *argv[]) {
  int i;
  project_t *project;
  pthread_t *read_thread;
  pthread_t **blocking_threads;
  pthread_t **comparator_threads;

  project = project_new();

  args_parse(project->args, argc, argv);

  project_parse(project, project->args->project_file);

  printf("Começando leitura e blocagem\n\n");
  read_thread = database_read_async(project->d0);

  blocking_threads = blocking_async(project);
  pthread_join(*read_thread, NULL);

  for(i = 0; i < project->args->max_threads - 1; i++) {
    pthread_join(*blocking_threads[i], NULL);
    free(blocking_threads[i]);
  }

  free(blocking_threads);
  free(read_thread);
  printf("\nComeçando comparação e escrita\n");
  comparator_threads = comparator_run_async(project);

  for(i = 0; i < project->args->max_threads; i++) {
    pthread_join(*comparator_threads[i], NULL);
    free(comparator_threads[i]);
  }

  free(comparator_threads);

  printf("Comparação pronta\n");

  project_free(project);
  return 0;
}
Exemplo n.º 13
0
static int32_t args_process(jp_jparse_args_t*local_args, int argc, char**argv)
{
	if (args_parse(local_args, argc, argv))
	{
		LIB_ERROR(CORE, "args process error!\n");
		return -1;
	}

	//显示帮助
	if (local_args->is_need_show_help)
	{
		jparse_help_show(argv[0]);
		return -1;
	}

	//显示版本
	if (local_args->is_need_show_version)
	{
		jparse_version_show(argv[0]);
		return -1;
	}

	//设置log
	if (local_args->is_need_verbose)
	{
		debug_set_module_log_level(DEBUG_LEVEL);
	}
	else
	{
		debug_set_module_log_level(INFO_LEVEL);
	}

	if (local_args->complier_file == NULL
			|| !libstr_strlen(local_args->complier_file))
	{
		LIB_ERROR(CORE, "parameter error,need complier file path!\n");
		return -1;
	}

	return 0;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
Arquivo: yarac.c Projeto: elmelik/yara
int main(
    int argc,
    const char** argv)
{
  COMPILER_RESULTS cr;

  YR_COMPILER* compiler = NULL;
  YR_RULES* rules = NULL;

  int result;

  argc = args_parse(options, argc, argv);

  if (show_version)
  {
    printf("%s\n", YR_VERSION);
    return EXIT_SUCCESS;
  }

  if (show_help)
  {
    printf("%s\n\n", USAGE_STRING);

    args_print_usage(options, 35);
    printf("\nSend bug reports and suggestions to: [email protected]\n");

    return EXIT_SUCCESS;
  }

  if (argc < 2)
  {
    fprintf(stderr, "yarac: wrong number of arguments\n");
    fprintf(stderr, "%s\n\n", USAGE_STRING);
    fprintf(stderr, "Try `--help` for more options\n");

    exit_with_code(EXIT_FAILURE);
  }

  result = yr_initialize();

  if (result != ERROR_SUCCESS)
    exit_with_code(EXIT_FAILURE);

  if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
    exit_with_code(EXIT_FAILURE);

  if (!define_external_variables(compiler))
    exit_with_code(EXIT_FAILURE);

  cr.errors = 0;
  cr.warnings = 0;

  yr_set_configuration(YR_CONFIG_MAX_STRINGS_PER_RULE, &max_strings_per_rule);
  yr_compiler_set_callback(compiler, report_error, &cr);

  if (!compile_files(compiler, argc, argv))
    exit_with_code(EXIT_FAILURE);

  if (cr.errors > 0)
    exit_with_code(EXIT_FAILURE);

  if (fail_on_warnings && cr.warnings > 0)
    exit_with_code(EXIT_FAILURE);

  result = yr_compiler_get_rules(compiler, &rules);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    exit_with_code(EXIT_FAILURE);
  }

  result = yr_rules_save(rules, argv[argc - 1]);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    exit_with_code(EXIT_FAILURE);
  }

  result = EXIT_SUCCESS;

_exit:

  if (compiler != NULL)
    yr_compiler_destroy(compiler);

  if (rules != NULL)
    yr_rules_destroy(rules);

  yr_finalize();

  return result;
}
Exemplo n.º 16
0
int main(
    int argc,
    const char** argv)
{
  YR_COMPILER* compiler = NULL;
  YR_RULES* rules = NULL;

  int result;

  argc = args_parse(options, argc, argv);

  if (show_version)
  {
    printf("%s\n", PACKAGE_STRING);
    printf("\nSend bug reports and suggestions to: %s.\n", PACKAGE_BUGREPORT);

    return EXIT_FAILURE;
  }

  if (show_help)
  {
    printf("%s\n\n", USAGE_STRING);

    args_print_usage(options, 25);
    printf("\nSend bug reports and suggestions to: %s.\n", PACKAGE_BUGREPORT);

    return EXIT_FAILURE;
  }

  if (argc < 2)
  {
    fprintf(stderr, "yarac: wrong number of arguments\n");
    fprintf(stderr, "%s\n\n", USAGE_STRING);
    fprintf(stderr, "Try `--help` for more options\n");

    exit_with_code(EXIT_FAILURE);
  }

  result = yr_initialize();

  if (result != ERROR_SUCCESS)
    exit_with_code(EXIT_FAILURE);

  if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
    exit_with_code(EXIT_FAILURE);

  if (!define_external_variables(compiler))
    exit_with_code(EXIT_FAILURE);

  yr_compiler_set_callback(compiler, report_error, NULL);

  for (int i = 0; i < argc - 1; i++)
  {
    const char* ns;
    const char* file_name;
    char* colon = (char*) strchr(argv[i], ':');

    if (colon)
    {
      file_name = colon + 1;
      *colon = '\0';
      ns = argv[i];
    }
    else
    {
      file_name = argv[i];
      ns = NULL;
    }

    FILE* rule_file = fopen(file_name, "r");

    if (rule_file != NULL)
    {
      int errors = yr_compiler_add_file(
          compiler, rule_file, ns, file_name);

      fclose(rule_file);

      if (errors) // errors during compilation
        exit_with_code(EXIT_FAILURE);
    }
    else
    {
      fprintf(stderr, "error: could not open file: %s\n", file_name);
    }
  }

  result = yr_compiler_get_rules(compiler, &rules);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    exit_with_code(EXIT_FAILURE);
  }

  result = yr_rules_save(rules, argv[argc - 1]);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    exit_with_code(EXIT_FAILURE);
  }

  result = EXIT_SUCCESS;

_exit:

  if (compiler != NULL)
    yr_compiler_destroy(compiler);

  if (rules != NULL)
    yr_rules_destroy(rules);

  yr_finalize();

  return result;
}
Exemplo n.º 17
0
int main(int argc, char **argv)
{
    int i, funcNum;
    uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
    uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
    int failedNum=0;
    int passedNum=0;

    if (!srcBuffer || !dstBuffer)
        return -1;

    av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
    args_parse(argc, argv);
    av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
    sws_rgb2rgb_init(cpu_caps);

    for(funcNum=0; ; funcNum++) {
        struct func_info_s {
            int src_bpp;
            int dst_bpp;
            const char *name;
            void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
        } func_info[] = {
            FUNC(2, 2, rgb15to16),
            FUNC(2, 3, rgb15to24),
            FUNC(2, 4, rgb15to32),
            FUNC(2, 3, rgb16to24),
            FUNC(2, 4, rgb16to32),
            FUNC(3, 2, rgb24to15),
            FUNC(3, 2, rgb24to16),
            FUNC(3, 4, rgb24to32),
            FUNC(4, 2, rgb32to15),
            FUNC(4, 2, rgb32to16),
            FUNC(4, 3, rgb32to24),
            FUNC(2, 2, rgb16to15),
            FUNC(2, 2, rgb15tobgr15),
            FUNC(2, 2, rgb15tobgr16),
            FUNC(2, 3, rgb15tobgr24),
            FUNC(2, 4, rgb15tobgr32),
            FUNC(2, 2, rgb16tobgr15),
            FUNC(2, 2, rgb16tobgr16),
            FUNC(2, 3, rgb16tobgr24),
            FUNC(2, 4, rgb16tobgr32),
            FUNC(3, 2, rgb24tobgr15),
            FUNC(3, 2, rgb24tobgr16),
            FUNC(3, 3, rgb24tobgr24),
            FUNC(3, 4, rgb24tobgr32),
            FUNC(4, 2, rgb32tobgr15),
            FUNC(4, 2, rgb32tobgr16),
            FUNC(4, 3, rgb32tobgr24),
            FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
            FUNC(0, 0, NULL)
        };
        int width;
        int failed=0;
        int srcBpp=0;
        int dstBpp=0;

        if (!func_info[funcNum].func) break;

        av_log(NULL, AV_LOG_INFO,".");
        memset(srcBuffer, srcByte, SIZE);

        for(width=63; width>0; width--) {
            int dstOffset;
            for(dstOffset=128; dstOffset<196; dstOffset+=4) {
                int srcOffset;
                memset(dstBuffer, dstByte, SIZE);

                for(srcOffset=128; srcOffset<196; srcOffset+=4) {
                    uint8_t *src= srcBuffer+srcOffset;
                    uint8_t *dst= dstBuffer+dstOffset;
                    const char *name=NULL;

                    if(failed) break; //don't fill the screen with shit ...

                    srcBpp = func_info[funcNum].src_bpp;
                    dstBpp = func_info[funcNum].dst_bpp;
                    name   = func_info[funcNum].name;

                    func_info[funcNum].func(src, dst, width*srcBpp);

                    if(!srcBpp) break;

                    for(i=0; i<SIZE; i++) {
                        if(srcBuffer[i]!=srcByte) {
                            av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
                                   i, width, srcOffset, dstOffset, name);
                            failed=1;
                            break;
                        }
                    }
                    for(i=0; i<dstOffset; i++) {
                        if(dstBuffer[i]!=dstByte) {
                            av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
                                   i, width, srcOffset, dstOffset, name);
                            failed=1;
                            break;
                        }
                    }
                    for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
                        if(dstBuffer[i]!=dstByte) {
                            av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
                                   i, width, srcOffset, dstOffset, name);
                            failed=1;
                            break;
                        }
                    }
                }
            }
        }
        if(failed) failedNum++;
        else if(srcBpp) passedNum++;
    }

    av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
    return failedNum;
}
Exemplo n.º 18
0
Arquivo: main.c Projeto: 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;
}
Exemplo n.º 19
0
int main(int argc, char *argv[])
{
    int opts, err = -1;
    char *cmd_name = NULL;
    opkg_cmd_t *cmd;
    int nocheckfordirorfile;
    int noreadfeedsfile;

    if (opkg_conf_init())
        goto err0;

    opkg_config->verbosity = NOTICE;

    opts = args_parse(argc, argv);
    if (opts == argc || opts < 0) {
        fprintf(stderr, "opkg must have one sub-command argument\n");
        usage();
    }

    cmd_name = argv[opts++];

    nocheckfordirorfile = !strcmp(cmd_name, "print-architecture")
        || !strcmp(cmd_name, "print_architecture")
        || !strcmp(cmd_name, "print-installation-architecture")
        || !strcmp(cmd_name, "print_installation_architecture");

    noreadfeedsfile = !strcmp(cmd_name, "flag")
        || !strcmp(cmd_name, "configure")
        || !strcmp(cmd_name, "remove")
        || !strcmp(cmd_name, "files")
        || !strcmp(cmd_name, "search")
        || !strcmp(cmd_name, "compare_versions")
        || !strcmp(cmd_name, "compare-versions")
        || !strcmp(cmd_name, "list_installed")
        || !strcmp(cmd_name, "list-installed")
        || !strcmp(cmd_name, "list_changed_conffiles")
        || !strcmp(cmd_name, "list-changed-conffiles")
        || !strcmp(cmd_name, "status");

    cmd = opkg_cmd_find(cmd_name);
    if (cmd == NULL) {
        fprintf(stderr, "%s: unknown sub-command %s\n", argv[0], cmd_name);
        usage();
    }

    opkg_config->pfm = cmd->pfm;

    if (opkg_conf_load())
        goto err0;

    if (!nocheckfordirorfile) {
        if (!noreadfeedsfile) {
            if (pkg_hash_load_feeds())
                goto err1;
        }

        if (pkg_hash_load_status_files())
            goto err1;
    }

    if (cmd->requires_args && opts == argc) {
        fprintf(stderr, "%s: the ``%s'' command requires at least one argument\n",
                argv[0], cmd_name);
        usage();
    }

    err = opkg_cmd_exec(cmd, argc - opts, (const char **)(argv + opts));

    opkg_download_cleanup();
 err1:
    opkg_conf_deinit();

 err0:
    print_error_list();
    free_error_list();

    return err;
}
Exemplo n.º 20
0
int args_parse(args_parse_state *state, int argc, char **argv, args_option *opts)
{
	char *arg;
	const char *optarg;
	args_option *opt;
	int retval;

	if(state->idx == 0)
		state->idx++;

	if(state->idx >= argc)
		return -1;

	state->arg = arg = argv[state->idx];

	if(state->no_more_options || strlen(arg) <= 1 || arg[0] != '-') {
		state->idx++;
		return '_';
	}

	if(strcmp(arg, "--") == 0) {
		state->idx++;
		state->no_more_options = 1;
		return args_parse(state, argc, argv, opts);
	}

	if(strncmp(arg, "--", 2) == 0) {
		state->idx++;
		optarg = NULL;
		opt = getlongopt(opts, arg + 2, &optarg);
		if(opt == NULL)
			return '?';

		if(opt->arg_name == NULL)
			return opt->code;
		else {
			if(optarg != NULL)
				state->arg = (char *)optarg;
			else {
				if(state->idx >= argc)
					return ':';
				state->arg = argv[state->idx];
				state->idx++;
			}
			return opt->code;
		}
	}

	state->off++;
	snprintf(state->short_arg, 3, "-%c", arg[state->off]);
	state->arg = state->short_arg;
	opt = getshortopt(opts, arg[state->off]);
	if(opt == NULL) {
		retval = '?';
		goto ret;
	}

	if(opt->arg_name == NULL) {
		retval = opt->code;
		goto ret;
	}

	if(state->idx + 1 == argc || state->off + 1 != strlen(arg)) {
		retval = ':';
		goto ret;
	}

	state->idx++;
	state->arg = argv[state->idx];
	retval = opt->code;

ret:
	if(state->off + 1 == strlen(arg)) {
		state->off = 0;
		state->idx++;
	}
	return retval;
}
Exemplo n.º 21
0
/*
 * Forward a local port to a remote host:port on the remote end of the tunnel
 */
DWORD cmd_portfwd(Remote *remote, UINT argc, CHAR **argv)
{
	PortForwardListenerContext *plctx = NULL;
	DWORD res = ERROR_SUCCESS;
	ArgumentContext arg;
	BOOL printBanner = FALSE;
	LPCSTR command = NULL, lhost = NULL, rhost = NULL;
	USHORT lport = 0, rport = 0;
	BOOL proxy = FALSE;

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

	do
	{
		// No arguments?
		if (argc == 1)
		{
			printBanner = TRUE;
			break;
		}

		// Parse the arguments
		while (args_parse(argc, argv, "arvL:l:h:p:P", &arg) == ERROR_SUCCESS)
		{
			switch (arg.toggle)
			{
				case 'a':
					command = "network_portfwd_add";
					break;
				case 'r':
					command = "network_portfwd_remove";
					break;
				case 'v':
					command = "network_portfwd_view";
					break;
				case 'L':
					lhost = arg.argument;
					break;
				case 'l':
					lport = atoi(arg.argument) & 0xffff;
					break;
				case 'h':
					rhost = arg.argument;
					break;
				case 'p':
					rport = atoi(arg.argument) & 0xffff;
					break;
				case 'P':
					proxy = TRUE;
					break;
				default:
					break;
			}
		}

		// Was a valid command found?
		if (!command)
		{
			console_write_output(
					"Error: No command was supplied.\n");

			printBanner = TRUE;
			break;
		}

		// If the command is add, create a local listener
		if (!strcmp(command, "network_portfwd_add"))
		{
			// Was a local host and remote host:port supplied?
			if ((!lport) ||
				 (!rhost) || 
				 (!rport))
			{
				console_write_output(
						"Error: Missing one or more of local port/remote host/remote port.\n");
				break;
			}

			// Create a local listener context
			if (!(plctx = portfwd_create_listener(lhost, lport, rhost, rport)))
			{
				console_write_output(
						"Error: Local listener could not be allocated on %d.\n",
						lport);
				break;
			}
	
			console_write_output(
					"Successfully created local listener on port %d.\n", lport);
		}
		else if (!strcmp(command, "network_portfwd_remove"))
		{
			// Destroy a local listener based on the host/port
			if (portfwd_destroy_listener(lhost, lport) != ERROR_SUCCESS)
			{
				console_write_output(
						"Error: Local listener could not be found for %d.\n",
						lport);
				break;
			}
			
			console_write_output(
					"Successfully removed local listener on port %d.\n", lport);
		}
		else if (!strcmp(command, "network_portfwd_view"))
		{
			PortForwardListenerContext *current;

			console_write_output(
					"Local port forward listeners:\n\n");

			for (current = listeners;
			     current;
			     current = current->next)
				console_write_output(
						"  %s:%d <-> %s:%d\n",
						current->slhost ? current->slhost : "ANY",
						current->lport,
						current->rhost ? current->rhost : "UNK",
						current->rport);
		}

	} while (0);

	if (printBanner)
	{
		console_write_output(
				"Usage: portfwd [ -arv ] [ -L laddr ] [ -l lport ] [ -h rhost ] [ -p rport ]\n"
				"               [ -P ]\n"
				"\n"
				"  -a      Add a port forward\n"
				"  -r      Remove a port forward\n"
				"  -v      View port forward list\n"
				"  -L      The local address to listen on\n"
				"  -l      The local port to listen on\n"
				"  -h      The remote host to connect to\n"
				"  -p      The remote port to connect to\n"
				"  -P      Create a local proxy listener that builds a dynamic port forward.\n");
	}

	return res;
}
Exemplo n.º 22
0
Arquivo: start.c Projeto: TrTLE/core
SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
{
    sal_Bool bSentArgs = sal_False;
    const char* pUsePlugin;
    rtl_uString *pPipePath = NULL;
    Args *args;
    int status = 0;
    struct splash* splash = NULL;
    struct sigaction sigpipe_action;
    struct sigaction sigterm_action;

    /* turn SIGPIPE into an error */
    memset(&sigpipe_action, 0, sizeof(struct sigaction));
    sigpipe_action.sa_handler = SIG_IGN;
    sigemptyset(&sigpipe_action.sa_mask);
    sigaction(SIGPIPE, &sigpipe_action, NULL);
    memset(&sigterm_action, 0, sizeof(struct sigaction));
    sigterm_action.sa_handler = &sigterm_handler;
    sigemptyset(&sigterm_action.sa_mask);
    sigaction(SIGTERM, &sigterm_action, NULL);

    args = args_parse ();
    args->pAppPath = get_app_path( argv[0] );
    if ( !args->pAppPath )
    {
        fprintf( stderr, "ERROR: Can't read app link\n" );
        exit( 1 );
    }

#ifndef ENABLE_QUICKSTART_LIBPNG
    /* we can't load and render it anyway */
    args->bInhibitSplash = sal_True;
#endif

    pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
    if ( pUsePlugin && !strcmp(pUsePlugin, "svp") )
        args->bInhibitSplash = sal_True;

    if ( !args->bInhibitPipe && getenv("LIBO_XDGAPP") == NULL )
    {
        int fd = 0;
        pPipePath = get_pipe_path( args->pAppPath );

        if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
        {
            // Wait for answer
            char resp[ strlen( "InternalIPC::SendArguments" ) + 1];
            ssize_t n = read( fd, resp, SAL_N_ELEMENTS( resp ) );
            if (n == (ssize_t) SAL_N_ELEMENTS( resp )
                && (memcmp(
                resp, "InternalIPC::SendArguments",
                SAL_N_ELEMENTS( resp ) - 1) == 0)) {
                rtl_uString *pCwdPath = NULL;
                osl_getProcessWorkingDir( &pCwdPath );

                // Then send args
                bSentArgs = send_args( fd, pCwdPath );
           }

            close( fd );
        }
    }

    if ( !bSentArgs )
    {
        /* we have to prepare for, and exec the binary */
        int nPercent = 0;
        ChildInfo *info;
        sal_Bool bAllArgs = sal_True;
        sal_Bool bShortWait, bRestart;

        /* sanity check pieces */
        system_checks();

        /* load splash image and create window */
        if ( !args->bInhibitSplash )
        {
            splash = splash_create(args->pAppPath, argc, argv);
        }

        /* pagein */
        if (!args->bInhibitPagein)
            exec_pagein (args);

        /* javaldx */
#if HAVE_FEATURE_JAVA
        if (!args->bInhibitJavaLdx)
            exec_javaldx (args);
#endif

        do
        {
            bRestart = sal_False;

            /* fast updates if we have somewhere to update it to */
            bShortWait = splash ? sal_True : sal_False;

            /* Periodically update the splash & the percent according
               to what status_fd says, poll quickly only while starting */
            info = child_spawn (args, bAllArgs, bShortWait);
            g_pProcess = info->child;
            while (!child_exited_wait (info, bShortWait))
            {
                ProgressStatus eResult;

                splash_draw_progress( splash, nPercent );
                eResult = read_percent( info, &nPercent );
                if (eResult != ProgressContinue)
                {
                    splash_destroy(splash);
                    splash = NULL;
                    bShortWait = sal_False;
                }

            }


            status = child_get_exit_code(info);
            g_pProcess = NULL; // reset
            switch (status) {
            case EXITHELPER_CRASH_WITH_RESTART: // re-start with just -env: parameters
                bRestart = sal_True;
                bAllArgs = sal_False;
                break;
            case EXITHELPER_NORMAL_RESTART: // re-start with all arguments
                bRestart = sal_True;
                bAllArgs = sal_True;
                break;
            default:
                break;
            }

            child_info_destroy (info);
        } while (bRestart);
    }

    /* cleanup */
    if ( pPipePath )
        rtl_uString_release( pPipePath );
    args_free (args);

    return status;
}
Exemplo n.º 23
0
int main(int argc, char** argv) {
  const rlim_t kStackSize = 64L * 1024L * 1024L; // min stack size = 64 Mb
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if(result == 0) {
    if(rl.rlim_cur < kStackSize) {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if(result != 0) {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }

  struct options options;
  if(args_parse(argc, argv, &options)) {
    printf("Usage: sweep [--elf] [--offset o] [--length l] [--translate] --file f\n");
    return 1;
  }

  if(!options.file) {
    printf("No file :/\n");
    printf("Usage: sweep [--elf] [--offset o] [--length l] [--translate] --file f\n");
    return 2;
  }

//  if(options.mode == MODE_ELF && (options.offset || options.length)) {
//    printf("ELF files neither like the offset nor the length option :-(\n");
//    printf("Usage: sweep [--elf] [--offset o] [--length l] [--translate] --file f\n");
//    return 3;
//  }

  if(options.mode == MODE_BIN && !options.length) {
    struct stat buf;
    stat(options.file, &buf);
    if(options.offset < buf.st_size) {
      options.length = buf.st_size - options.offset;
    }
  } else if(options.mode == MODE_ELF) {
    size_t offset;
    size_t length;
    char e = elf_section_boundary_get(options.file, &offset, &length);
    if(e) {
      printf("elf_section_boundary_get() does not like this file :/\n");
      return 4;
    }
    if(!options.length || options.length > length) options.length = length;
    options.offset += offset;
  }

  FILE *f = fopen(options.file, "r");
  if(!f) {
    printf("Unable to open file.\n");
    return 5;
  }
  fseek(f, options.offset, SEEK_SET);

  size_t buffer_size = options.length + 15;
  unsigned char *buffer = (unsigned char*) malloc(buffer_size);
  size_t buffer_length = fread(buffer, 1, buffer_size, f);

  fclose(f);

  state_t state = gdsl_init();
  gdsl_set_code(state, buffer, buffer_length, 0);

  struct timespec start;
  struct timespec end;

  size_t memory_dec = 0;
  size_t memory_dec_tran = 0;

  size_t memory_dec_max = 0;
  size_t memory_dec_tran_max = 0;

  size_t instructions = 0;

  clock_gettime(CLOCK_REALTIME, &start);

  size_t last_offset = 0;
  while(last_offset < options.length) {
//		printf("++++++++++++ DECODING NEXT INSTRUCTION ++++++++++++\n");

    if(setjmp(*gdsl_err_tgt(state))) {
      fprintf(stderr, "decode failed: %s\n", gdsl_get_error_message(state));
      break;
    }
    obj_t insn = gdsl_decode(state, gdsl_config_default(state));

    printf("[");
    size_t decoded = gdsl_get_ip(state) - last_offset;
    for(size_t i = 0; i < decoded; ++i) {
      if(i) printf(" ");
      printf("%02x", buffer[last_offset + i]);
    }
    printf("] ");

    string_t fmt = gdsl_merge_rope(state, gdsl_pretty(state, insn));
    puts(fmt);

    size_t residency = gdsl_heap_residency(state);
    memory_dec += residency;
    if(residency > memory_dec_max) memory_dec_max = residency;

    if(options.translate) {
      printf("---------------------------\n");

      if(setjmp(*gdsl_err_tgt(state))) {
        fprintf(stderr, "translate failed: %s\n", gdsl_get_error_message(state));
        break;
      }
      obj_t rreil = gdsl_translate(state, insn);

      fmt = gdsl_merge_rope(state, gdsl_rreil_pretty(state, rreil));
      puts(fmt);
    }

    residency = gdsl_heap_residency(state);
    memory_dec_tran += residency;
    if(residency > memory_dec_tran_max) memory_dec_tran_max = residency;

    gdsl_reset_heap(state);

    instructions++;
    last_offset = gdsl_get_ip(state);
  }

  clock_gettime(CLOCK_REALTIME, &end);
  long time = end.tv_sec * NANOS + end.tv_nsec - start.tv_nsec - start.tv_sec * NANOS;

  gdsl_destroy(state);
  free(buffer);

  fprintf(stderr, "---------------------------\n");
  fprintf(stderr, "Statistics\n");
  fprintf(stderr, "Instruction count: %zu\n", instructions);
  fprintf(stderr, "Decoder: Total memoy: %zu, maximal memoy: %zu\n", memory_dec, memory_dec_max);
  fprintf(stderr, "Decoder + Translator: Total memoy: %zu, maximal memoy: %zu\n", memory_dec_tran, memory_dec_tran_max);
  fprintf(stderr, "time: %lf seconds\n", time / (double) (1000000000));

  return 0;
}
Exemplo n.º 24
0
Arquivo: cmd.c Projeto: Darkoe/tmux
struct cmd *
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
{
	const struct cmd_entry **entryp, *entry;
	struct cmd		*cmd;
	struct args		*args;
	char			 s[BUFSIZ];
	int			 ambiguous = 0;

	*cause = NULL;
	if (argc == 0) {
		xasprintf(cause, "no command");
		return (NULL);
	}

	entry = NULL;
	for (entryp = cmd_table; *entryp != NULL; entryp++) {
		if ((*entryp)->alias != NULL &&
		    strcmp((*entryp)->alias, argv[0]) == 0) {
			ambiguous = 0;
			entry = *entryp;
			break;
		}

		if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
			continue;
		if (entry != NULL)
			ambiguous = 1;
		entry = *entryp;

		/* Bail now if an exact match. */
		if (strcmp(entry->name, argv[0]) == 0)
			break;
	}
	if (ambiguous)
		goto ambiguous;
	if (entry == NULL) {
		xasprintf(cause, "unknown command: %s", argv[0]);
		return (NULL);
	}

	args = args_parse(entry->args_template, argc, argv);
	if (args == NULL)
		goto usage;
	if (entry->args_lower != -1 && args->argc < entry->args_lower)
		goto usage;
	if (entry->args_upper != -1 && args->argc > entry->args_upper)
		goto usage;

	cmd = xcalloc(1, sizeof *cmd);
	cmd->entry = entry;
	cmd->args = args;

	if (file != NULL)
		cmd->file = xstrdup(file);
	cmd->line = line;

	return (cmd);

ambiguous:
	*s = '\0';
	for (entryp = cmd_table; *entryp != NULL; entryp++) {
		if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
			continue;
		if (strlcat(s, (*entryp)->name, sizeof s) >= sizeof s)
			break;
		if (strlcat(s, ", ", sizeof s) >= sizeof s)
			break;
	}
	s[strlen(s) - 2] = '\0';
	xasprintf(cause, "ambiguous command: %s, could be: %s", argv[0], s);
	return (NULL);

usage:
	if (args != NULL)
		args_free(args);
	xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
	return (NULL);
}
Exemplo n.º 25
0
int main(int argc, char** argv){
	CFG config={
		0,		//verbosity
		0, 		//padding
		0,		//line spacing
		0,		//max size
		ALIGN_CENTER, 	//alignment
		false, 		//independent resize
		false, 		//handle stdin
		false,		//draw debug boxes
		false,		//disable text drawing
		true,		//use double buffering
		0, 		//forced size
		NULL,	 	//text color
		NULL,	 	//background color
		NULL,		//debug color name
		NULL,		//font name
	};
	XRESOURCES xres={
		0,		//screen
		NULL,		//display
		0,		//window
		0,		//back buffer
		NULL,		//xft drawable
		{},		//text color
		{},		//bg color
		{},		//debug color
		{NULL, 0}	//xfd set
	};
	int args_end;
	unsigned text_length, i;
	char* args_text=NULL;
	long flags;

	//parse command line arguments
	args_end=args_parse(&config, argc-1, argv+1);
	if(argc-args_end<1&&!config.handle_stdin){
		return usage(argv[0]);
	}

	//config sanity check
	if(!args_sane(&config)){
		args_cleanup(&config);
		return usage(argv[0]);
	}

	//set up x11 display
	if(!x11_init(&xres, &config)){
		x11_cleanup(&xres, &config);
		args_cleanup(&config);
		return usage(argv[0]);
	}

	//preprocess display text if given
	if(argc-args_end>0){
		//copy arguments into buffer
		text_length=0;
		for(i=args_end;i<argc;i++){
			text_length+=strlen(argv[i])+1;
		}

		args_text=calloc(text_length, sizeof(char));

		text_length=0;
		for(i=args_end;i<argc;i++){
			strncpy(args_text+text_length, argv[i], strlen(argv[i]));
			text_length+=strlen(argv[i]);
			args_text[text_length++]=' ';
		}
		args_text[((text_length>0)?text_length:1)-1]=0;

		errlog(&config, LOG_INFO, "Input text:\n\"%s\"\n", args_text);

		//preprocess
		if(!string_preprocess(args_text, true)){
			fprintf(stderr, "Failed to preprocess input text\n");
			x11_cleanup(&xres, &config);
			args_cleanup(&config);
			return usage(argv[0]);
		}

		errlog(&config, LOG_DEBUG, "Printing text:\n\"%s\"\n", args_text);
	}

	//prepare stdin
	if(config.handle_stdin){
		errlog(&config, LOG_INFO, "Marking stdin as nonblocking\n");
		flags=fcntl(0, F_GETFL, 0);
		flags|=O_NONBLOCK;
		fcntl(0, F_SETFL, flags);
	}
	
	//enter main loop
	xecho(&config, &xres, args_text);

	//clear data
	x11_cleanup(&xres, &config);
	args_cleanup(&config);

	if(args_text){
		free(args_text);
	}

	errlog(&config, LOG_INFO, "xecho shutdown ok\n");

	return 0;
}
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: etel/ponyos
/*
 * multiboot i386 (pc) kernel entry point
 */
int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
	initial_esp = esp;
	extern char * cmdline;

	uint32_t mboot_mods_count = 0;
	mboot_mod_t * mboot_mods = NULL;
	mboot_ptr = mboot;

	ENABLE_EARLY_BOOT_LOG(0);

	assert(mboot_mag == MULTIBOOT_EAX_MAGIC && "Didn't boot with multiboot, not sure how we got here.");
	debug_print(NOTICE, "Processing Multiboot information.");

	/* Initialize core modules */
	gdt_install();      /* Global descriptor table */
	idt_install();      /* IDT */
	isrs_install();     /* Interrupt service requests */
	irq_install();      /* Hardware interrupt requests */

	if (mboot_ptr->flags & (1 << 3)) {
		debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr);
		debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end);
		if (mboot_ptr->mods_count > 0) {
			uintptr_t last_mod = (uintptr_t)&end;
			uint32_t i;
			mboot_mods = (mboot_mod_t *)mboot_ptr->mods_addr;
			mboot_mods_count = mboot_ptr->mods_count;
			for (i = 0; i < mboot_ptr->mods_count; ++i ) {
				mboot_mod_t * mod = &mboot_mods[i];
				uint32_t module_start = mod->mod_start;
				uint32_t module_end   = mod->mod_end;
				if ((uintptr_t)mod + sizeof(mboot_mod_t) > last_mod) {
					/* Just in case some silly person put this *behind* the modules... */
					last_mod = (uintptr_t)mod + sizeof(mboot_mod_t);
				}
				debug_print(NOTICE, "Module %d is at 0x%x:0x%x", i, module_start, module_end);
				if (last_mod < module_end) {
					last_mod = module_end;
				}
			}
			debug_print(NOTICE, "Moving kernel heap start to 0x%x", last_mod);
			kmalloc_startat(last_mod);
		}
	}

	paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower);
	if (mboot_ptr->flags & (1 << 6)) {
		debug_print(NOTICE, "Parsing memory map.");
		mboot_memmap_t * mmap = (void *)mboot_ptr->mmap_addr;
		while ((uintptr_t)mmap < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) {
			if (mmap->type == 2) {
				for (unsigned long long int i = 0; i < mmap->length; i += 0x1000) {
					if (mmap->base_addr + i > 0xFFFFFFFF) break; /* xxx */
					debug_print(INFO, "Marking 0x%x", (uint32_t)(mmap->base_addr + i));
					paging_mark_system((mmap->base_addr + i) & 0xFFFFF000);
				}
			}
			mmap = (mboot_memmap_t *) ((uintptr_t)mmap + mmap->size + sizeof(uintptr_t));
		}
	}
	paging_finalize();

	{
		char cmdline_[1024];

		size_t len = strlen((char *)mboot_ptr->cmdline);
		memmove(cmdline_, (char *)mboot_ptr->cmdline, len + 1);

		/* Relocate the command line */
		cmdline = (char *)kmalloc(len + 1);
		memcpy(cmdline, cmdline_, len + 1);
	}

	/* Memory management */
	heap_install();     /* Kernel heap */

	if (cmdline) {
		args_parse(cmdline);
	}

	vfs_install();
	tasking_install();  /* Multi-tasking */
	timer_install();    /* PIC driver */
	fpu_install();      /* FPU/SSE magic */
	syscalls_install(); /* Install the system calls */
	shm_install();      /* Install shared memory */
	modules_install();  /* Modules! */

	DISABLE_EARLY_BOOT_LOG();

	/* Load modules from bootloader */
	debug_print(NOTICE, "%d modules to load", mboot_mods_count);
	for (unsigned int i = 0; i < mboot_ptr->mods_count; ++i ) {
		mboot_mod_t * mod = &mboot_mods[i];
		uint32_t module_start = mod->mod_start;
		uint32_t module_end = mod->mod_end;
		size_t   module_size = module_end - module_start;

		if (!module_quickcheck((void *)module_start)) {
			debug_print(NOTICE, "Loading ramdisk: 0x%x:0x%x", module_start, module_end);
			ramdisk_mount(module_start, module_size);
		} else {

			debug_print(NOTICE, "Loading a module: 0x%x:0x%x", module_start, module_end);
			module_data_t * mod_info = (module_data_t *)module_load_direct((void *)(module_start), module_size);
			if (mod_info) {
				debug_print(NOTICE, "Loaded: %s", mod_info->mod_info->name);
			}
		}
	}

	/* Map /dev to a device mapper */
	map_vfs_directory("/dev");

	if (args_present("root")) {
		vfs_mount_type("ext2", args_value("root"), "/");
	}

	if (args_present("start")) {
		char * c = args_value("start");
		if (!c) {
			debug_print(WARNING, "Expected an argument to kernel option `start`. Ignoring.");
		} else {
			debug_print(NOTICE, "Got start argument: %s", c);
			boot_arg = strdup(c);
		}
	}

	if (!fs_root) {
		debug_print(CRITICAL, "No root filesystem is mounted. Skipping init.");
		map_vfs_directory("/");
		switch_task(0);
	}

	/* Prepare to run /bin/init */
	char * argv[] = {
		"/bin/init",
		boot_arg,
		NULL
	};
	int argc = 0;
	while (argv[argc]) {
		argc++;
	}
	system(argv[0], argc, argv); /* Run init */

	return 0;
}
Exemplo n.º 28
0
int main(int argc, char** argv_)
{
  int found = 0;
  int first_pid = 1;
  char* usage_str;
  ssize_t i, n;
  
  argv = argv_;
  
  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);
  
  n = (ssize_t)(strlen(_(" [options] [program...]")) + strlen(*argv) + 1);
  usage_str = alloca((size_t)n * sizeof(char));
  sprintf(usage_str, "%s%s", *argv, _(" [options] [program...]"));
  
  args_init(!strcmp(argv[0], "dpidof")
	    ? _("epidof with display isolation")
	    : _("pidof with environment constraints"),
	    usage_str, NULL, 0, 1, 0, args_standard_abbreviations);
  
  args_add_option(args_new_argumentless(NULL,           0, "-c", "--check-root",  NULL), _("Restrict to processes running under the same root"));
  args_add_option(args_new_argumentless(NULL,           0, "-s", "--single-shot", NULL), _("Return only one process ID"));
  args_add_option(args_new_argumentless(NULL,           0, "-x", "--scripts",     NULL), _("Test the name of scripts"));
  args_add_option(args_new_argumented  (NULL, _("PID"), 0, "-o", "--omit-pid",    NULL), _("Do not return a specific process ID"));
  args_add_option(args_new_argumentless(NULL,           0, "-h", "--help",        NULL), _("Display this help information"));
  args_add_option(args_new_argumentless(NULL,           0, "-V", "--version",     NULL), _("Print the name and version of this program"));
  
  environment_parse(&argc, argv);
  args_parse(argc, argv);
  
  if (args_unrecognised_count || args_opts_used("-h"))  args_help(), fprintf(stderr, "%s\n\n", _(environment_synopsis));
  else if (args_opts_used("-V"))                        printf("%s " VERSION, !strcmp(argv[0], "dpidof") ? "dpidof" : "epidof");
  else                                                  goto cont;
  return args_unrecognised_count ? EXIT_FAILURE : EXIT_SUCCESS;
 cont:
  
  /* process command-line options */
  if (args_opts_used("-s"))  opt_single_shot = 1;
  if (args_opts_used("-x"))  opt_scripts_too = 1;
  if (args_opts_used("-c") && (geteuid() == 0))
    epidof_root = pid_link(getpid(), "root");
  if (args_opts_used("-o"))
    {
      char** arr = args_opts_get("-o");
      for (i = 0, n = (ssize_t)args_opts_get_count("-o"); i < n; i++)
	add_to_omit_list(arr[i]);
    }
  
  /* main loop */
  for (n = 0; n < args_files_count; n++) /* for each program */
    {
      program = args_files[n];
      proc_count = 0;
      select_procs(); /* get the list of matching processes */
      
      if (proc_count > 0)
	{
	  found = 1;
	  for (i = (ssize_t)proc_count - 1; i >= 0; i--) /* and display their PIDs */
	    {
	      printf(first_pid ? "%ld" : " %ld", (long)(procs[i]));
	      first_pid = 0;
	      if (opt_single_shot)
		break;
	    }
	}
    }
  
  /* final line feed */
  if (found)
    printf("\n");
  
  xfree(procs);
  xfree(omitted_procs);
  xfree(epidof_root);
  args_dispose();
  environment_dispose();
  
  return !found;
}
Exemplo n.º 29
0
/* Entry-point.  Has same semantics as main(). */
static int
vifm_main(int argc, char *argv[])
{
	/* TODO: refactor vifm_main() function */

	static const int quit = 0;

	char **files = NULL;
	int nfiles = 0;
	int lwin_cv, rwin_cv;

	char dir[PATH_MAX + 1];
	if(get_start_cwd(dir, sizeof(dir)) != 0)
	{
		return -1;
	}

	args_parse(&vifm_args, argc, argv, dir);
	args_process(&vifm_args, 1);

	lwin_cv = (strcmp(vifm_args.lwin_path, "-") == 0 && vifm_args.lwin_handle);
	rwin_cv = (strcmp(vifm_args.rwin_path, "-") == 0 && vifm_args.rwin_handle);
	if(lwin_cv || rwin_cv)
	{
		files = read_stream_lines(stdin, &nfiles, 1, NULL, NULL);
		if(reopen_term_stdin() != 0)
		{
			free_string_array(files, nfiles);
			return EXIT_FAILURE;
		}
	}

	(void)setlocale(LC_ALL, "");
	srand(time(NULL));

	cfg_init();

	if(vifm_args.logging)
	{
		init_logger(1, vifm_args.startup_log_path);
	}

	init_filelists();
	tabs_init();
	regs_init();
	cfg_discover_paths();
	reinit_logger(cfg.log_file);

	/* Commands module also initializes bracket notation and variables. */
	init_commands();

	init_builtin_functions();
	update_path_env(1);

	if(stats_init(&cfg) != 0)
	{
		free_string_array(files, nfiles);

		puts("Error during session status initialization.");
		return -1;
	}

	/* Tell file type module what function to use to check availability of
	 * external programs. */
	ft_init(&external_command_exists);
	/* This should be called before loading any configuration file. */
	ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X);

	init_option_handlers();

	if(!vifm_args.no_configs)
	{
		/* vifminfo must be processed this early so that it can restore last visited
		 * directory. */
		read_info_file(0);
	}

	curr_stats.ipc = ipc_init(vifm_args.server_name, &parse_received_arguments,
			&eval_received_expression);
	if(ipc_enabled() && curr_stats.ipc == NULL)
	{
		fputs("Failed to initialize IPC unit", stderr);
		return -1;
	}
	/* Export chosen server name to parsing unit. */
	{
		var_t var = var_from_str(ipc_get_name(curr_stats.ipc));
		setvar("v:servername", var);
		var_free(var);
	}

	args_process(&vifm_args, 0);

	bg_init();

	fops_init(&enter_prompt_mode, &prompt_msg_custom);

	set_view_path(&lwin, vifm_args.lwin_path);
	set_view_path(&rwin, vifm_args.rwin_path);

	if(need_to_switch_active_pane(vifm_args.lwin_path, vifm_args.rwin_path))
	{
		swap_view_roles();
	}

	load_initial_directory(&lwin, dir);
	load_initial_directory(&rwin, dir);

	/* Force split view when two paths are specified on command-line. */
	if(vifm_args.lwin_path[0] != '\0' && vifm_args.rwin_path[0] != '\0')
	{
		curr_stats.number_of_windows = 2;
	}

	/* Prepare terminal for further operations. */
	curr_stats.original_stdout = reopen_term_stdout();
	if(curr_stats.original_stdout == NULL)
	{
		free_string_array(files, nfiles);
		return -1;
	}

	if(!setup_ncurses_interface())
	{
		free_string_array(files, nfiles);
		return -1;
	}

	init_modes();
	un_init(&undo_perform_func, NULL, &ui_cancellation_requested,
			&cfg.undo_levels);
	load_view_options(curr_view);

	curr_stats.load_stage = 1;

	/* Make v:count exist during processing configuration. */
	set_count_vars(0);

	if(!vifm_args.no_configs)
	{
		load_scheme();
		cfg_load();
	}

	if(lwin_cv || rwin_cv)
	{
		flist_custom_set(lwin_cv ? &lwin : &rwin, "-", dir, files, nfiles);
	}
	free_string_array(files, nfiles);

	cs_load_pairs();
	cs_write();
	setup_signals();

	/* Ensure trash directories exist, it might not have been called during
	 * configuration file sourcing if there is no `set trashdir=...` command. */
	(void)set_trash_dir(cfg.trash_dir);

	check_path_for_file(&lwin, vifm_args.lwin_path, vifm_args.lwin_handle);
	check_path_for_file(&rwin, vifm_args.rwin_path, vifm_args.rwin_handle);

	curr_stats.load_stage = 2;

	/* Update histories of the views to ensure that their current directories,
	 * which might have been set using command-line parameters, are stored in the
	 * history.  This is not done automatically as history manipulation should be
	 * postponed until views are fully loaded, otherwise there is no correct
	 * information about current file and relative cursor position. */
	flist_hist_save(&lwin, NULL, NULL, -1);
	flist_hist_save(&rwin, NULL, NULL, -1);

	/* Trigger auto-commands for initial directories. */
	if(!lwin_cv)
	{
		(void)vifm_chdir(flist_get_dir(&lwin));
		vle_aucmd_execute("DirEnter", flist_get_dir(&lwin), &lwin);
	}
	if(!rwin_cv)
	{
		(void)vifm_chdir(flist_get_dir(&rwin));
		vle_aucmd_execute("DirEnter", flist_get_dir(&rwin), &rwin);
	}

	update_screen(UT_FULL);
	modes_update();

	/* Run startup commands after loading file lists into views, so that commands
	 * like +1 work. */
	exec_startup_commands(&vifm_args);

	curr_stats.load_stage = 3;

	event_loop(&quit);

	return 0;
}
Exemplo n.º 30
0
int main(int argc, char **argv)
{
	int i, funcNum;
	uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
	uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
	int failedNum=0;
	int passedNum=0;
	
	av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
	args_parse(argc, argv);
	av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
	sws_rgb2rgb_init(cpu_caps);
	
	for(funcNum=0; funcNum<100; funcNum++){
		int width;
		int failed=0;
		int srcBpp=0;
		int dstBpp=0;

		av_log(NULL, AV_LOG_INFO,".");
		memset(srcBuffer, srcByte, SIZE);

		for(width=32; width<64; width++){
			int dstOffset;
			for(dstOffset=128; dstOffset<196; dstOffset+=4){
				int srcOffset;
				memset(dstBuffer, dstByte, SIZE);

				for(srcOffset=128; srcOffset<196; srcOffset+=4){
					uint8_t *src= srcBuffer+srcOffset;
					uint8_t *dst= dstBuffer+dstOffset;
					char *name=NULL;
					
					if(failed) break; //don't fill the screen with shit ...

					switch(funcNum){
					case 0:
						srcBpp=2;
						dstBpp=2;
						name="rgb15to16";
						rgb15to16(src, dst, width*srcBpp);
						break;
					case 1:
						srcBpp=2;
						dstBpp=3;
						name="rgb15to24";
						rgb15to24(src, dst, width*srcBpp);
						break;
					case 2:
						srcBpp=2;
						dstBpp=4;
						name="rgb15to32";
						rgb15to32(src, dst, width*srcBpp);
						break;
					case 3:
						srcBpp=2;
						dstBpp=3;
						name="rgb16to24";
						rgb16to24(src, dst, width*srcBpp);
						break;
					case 4:
						srcBpp=2;
						dstBpp=4;
						name="rgb16to32";
						rgb16to32(src, dst, width*srcBpp);
						break;
					case 5:
						srcBpp=3;
						dstBpp=2;
						name="rgb24to15";
						rgb24to15(src, dst, width*srcBpp);
						break;
					case 6:
						srcBpp=3;
						dstBpp=2;
						name="rgb24to16";
						rgb24to16(src, dst, width*srcBpp);
						break;
					case 7:
						srcBpp=3;
						dstBpp=4;
						name="rgb24to32";
						rgb24to32(src, dst, width*srcBpp);
						break;
					case 8:
						srcBpp=4;
						dstBpp=2;
						name="rgb32to15";
                        //((*s++) << TGA_SHIFT32) | TGA_ALPHA32;
						rgb32to15(src, dst, width*srcBpp);
						break;
					case 9:
						srcBpp=4;
						dstBpp=2;
						name="rgb32to16";
						rgb32to16(src, dst, width*srcBpp);
						break;
					case 10:
						srcBpp=4;
						dstBpp=3;
						name="rgb32to24";
						rgb32to24(src, dst, width*srcBpp);
						break;
					case 11:
						srcBpp=2;
						dstBpp=2;
						name="rgb16to15";
						rgb16to15(src, dst, width*srcBpp);
						break;
					
					case 14:
						srcBpp=2;
						dstBpp=2;
						name="rgb15tobgr15";
						rgb15tobgr15(src, dst, width*srcBpp);
						break;
					case 15:
						srcBpp=2;
						dstBpp=2;
						name="rgb15tobgr16";
						rgb15tobgr16(src, dst, width*srcBpp);
						break;
					case 16:
						srcBpp=2;
						dstBpp=3;
						name="rgb15tobgr24";
						rgb15tobgr24(src, dst, width*srcBpp);
						break;
					case 17:
						srcBpp=2;
						dstBpp=4;
						name="rgb15tobgr32";
						rgb15tobgr32(src, dst, width*srcBpp);
						break;
					case 18:
						srcBpp=2;
						dstBpp=2;
						name="rgb16tobgr15";
						rgb16tobgr15(src, dst, width*srcBpp);
						break;
					case 19:
						srcBpp=2;
						dstBpp=2;
						name="rgb16tobgr16";
						rgb16tobgr16(src, dst, width*srcBpp);
						break;
					case 20:
						srcBpp=2;
						dstBpp=3;
						name="rgb16tobgr24";
						rgb16tobgr24(src, dst, width*srcBpp);
						break;
					case 21:
						srcBpp=2;
						dstBpp=4;
						name="rgb16tobgr32";
						rgb16tobgr32(src, dst, width*srcBpp);
						break;
					case 22:
						srcBpp=3;
						dstBpp=2;
						name="rgb24tobgr15";
						rgb24tobgr15(src, dst, width*srcBpp);
						break;
					case 23:
						srcBpp=3;
						dstBpp=2;
						name="rgb24tobgr16";
						rgb24tobgr16(src, dst, width*srcBpp);
						break;
					case 24:
						srcBpp=3;
						dstBpp=3;
						name="rgb24tobgr24";
						rgb24tobgr24(src, dst, width*srcBpp);
						break;
					case 25:
						srcBpp=3;
						dstBpp=4;
						name="rgb24tobgr32";
						rgb24tobgr32(src, dst, width*srcBpp);
						break;
					case 26:
						srcBpp=4;
						dstBpp=2;
						name="rgb32tobgr15";
						rgb32tobgr15(src, dst, width*srcBpp);
						break;
					case 27:
						srcBpp=4;
						dstBpp=2;
						name="rgb32tobgr16";
						rgb32tobgr16(src, dst, width*srcBpp);
						break;
					case 28:
						srcBpp=4;
						dstBpp=3;
						name="rgb32tobgr24";
						rgb32tobgr24(src, dst, width*srcBpp);
						break;
					case 29:
						srcBpp=4;
						dstBpp=4;
						name="rgb32tobgr32";
						rgb32tobgr32(src, dst, width*srcBpp);
						break;

					}
					if(!srcBpp) break;

					for(i=0; i<SIZE; i++){
						if(srcBuffer[i]!=srcByte){
							av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n", 
								i, width, srcOffset, dstOffset, name);
							failed=1;
							break;
						}
					}
					for(i=0; i<dstOffset; i++){
						if(dstBuffer[i]!=dstByte){
							av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n", 
								i, width, srcOffset, dstOffset, name);
							failed=1;
							break;
						}
					}
					for(i=dstOffset + width*dstBpp; i<SIZE; i++){
						if(dstBuffer[i]!=dstByte){
							av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n", 
								i, width, srcOffset, dstOffset, name);
							failed=1;
							break;
						}
					}
				}
			}
		}
		if(failed) failedNum++;
		else if(srcBpp) passedNum++;
	}
	
	av_log(NULL, AV_LOG_INFO, "%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
	return failedNum;
}