コード例 #1
0
ファイル: InStruct.c プロジェクト: NCGRP/InstructOMP
int main(int argc, char **argv)
{
    SEQDATA seqdata;
    INIT initial;
    CHAIN chain;
    CONVG cvg;
    int chn;

    param_decomp(argc,argv);

    seqdata=read_data(datafilename,ploid,totalsize,popnum,nloci,missingdata,label,popdata,siglevel,back_refl,type_freq,nstep_check_empty_cluster,prior_flag,mode,n_extra_col,markername_flag,alpha_dpm,print_iter,print_freq,inf_K,distr_fmt,autopoly,data_fmt,max_mem);

    if(inf_K==0)
    {
        initial=read_init(initialfilename,chainnum,popnum,updatenum,burnin,thinning);
    }
    else {
        initial=read_init(initialfilename,chainnum,n_large,updatenum,burnin,thinning);
    }
    if(mem_cal(seqdata,initial)>seqdata.max_mem)
    {
        nrerror("Your request of memory exceeds the maximum memory allowed! Please change the parameter max_mem");
    }

    printinfo(outfilename,argc,argv,seqdata);

    if(inf_K==1)
    {   // make inference of K
        inf_K_val(outfilename,n_small,n_large,&seqdata,initial);
    }
    else {
        if(GR_flag==1) allocate_convg(seqdata,&cvg,chainnum,ckrep,convgfilename);
        for(chn=0; chn<chainnum; chn++)
        {
            chain=mcmc_updating(seqdata,initial,chn,&cvg);
            if(chain.flag_empty_cluster==1)
            {
                free_chain(&chain,seqdata);
                chn--;
                continue;
            }
            chain_stat(outfilename,chain,seqdata,chn);
            free_chain(&chain,seqdata);
        }
        if(GR_flag==1)
        {
            chain_converg(outfilename,&cvg);
            free_convg(&cvg);
        }
    }
    fprintf(stdout,"THE JOB IS SUCCESSFULLY FINISHED\n");
    return(0);
}
コード例 #2
0
ファイル: main.c プロジェクト: jaybi42/21sh
int				sh21(void)
{
	t_sh sh;

	ft_bzero(&sh.l, sizeof(t_line));
	srand(time(NULL));
	sh.nbr = rand();
	get_history(&g_hist);
	sh.av = NULL;
	handle_var(KV_SET, "?", "0");
	while (1)
	{
		g_toto = g_titi = 1;
		g_tata = 0;
		g_prompt.onshell = 1;
		catch_signal();
		g_prompt.son == 0 ? print_prompt(sh.nbr, g_env, g_lenv, &sh.l) : 0;
		g_prompt = (t_prompt){sh.nbr, g_env, g_lenv, 0, &sh.l, 1};
		g_line = NULL;
		if ((sh.av = read_init(&sh.l, &g_hist)) != NULL)
		{
			g_line = NULL;
			g_prompt.onshell = 0;
			sh.o = shell(sh.av, 0);
			g_prompt.onshell = 1;
		}
		xmasterfree();
	}
	return (1);
}
コード例 #3
0
ファイル: hill_stab.c プロジェクト: RoryBarnes/HillStability
int main(int argc, char *argv[]) {
  double **x,**v,*m;
  double **bax,**bav;
  double *ms;
  double ratio,e1,e2;
  ELEMS p1,p2;
  double exact,approx;
  int i,j,origin;

  if (argc != 2) {
    fprintf(stderr,"Usage: %s inputfile\n",argv[0]);
    exit(1);
  }

  m=malloc(3*sizeof(double));
  x=malloc(3*sizeof(double*));
  v=malloc(3*sizeof(double*));
  bax=malloc(3*sizeof(double*));
  bav=malloc(3*sizeof(double*));
  ms=malloc(3*sizeof(double));
  for (i=0;i<3;i++) {
    x[i]=malloc(3*sizeof(double));
    v[i]=malloc(3*sizeof(double));
    bax[i]=malloc(3*sizeof(double));
    bav[i]=malloc(3*sizeof(double));
  }

  read_init(argv[1],&p1,&p2,m,&origin);
  /* bodycentric coordinates */
  for (i=0;i<3;i++) {
    x[0][i]=0.0;
    v[0][i]=0.0;
  }

  cartes(x[1],v[1],p1,m[0]*BIGG);
  cartes(x[2],v[2],p2,m[0]*BIGG);
  if (origin) {
    ms[0]=m[0];
    for (i=1;i<3;i++)
      ms[i] = ms[i-1] + m[i];
    hel_bar(x,bax,ms,m,2);
  }
  exact=GetExact(x,v,m);
  approx=GetApprox(p1,p2,m);

  if (exact < 1e-4 || exact > 1e4) 
    printf("Exact: %.5e\n",exact);
  else
    printf("Exact: %.5lf\n",exact);

  if (approx < 1e-4 || approx > 1e4) 
    printf("Approx: %.5e\n",approx);
  else
    printf("Approx: %.5lf\n",approx);

  return 0;
}
コード例 #4
0
ファイル: lib.c プロジェクト: daveshields/AdaEd
int last_comp_index(IFILE *ifile)						/*;last_comp_index*/
{
	/* determine the number of comp units in ifile. */
    long	rec;
    int		i;

	i=0;
	for (rec=read_init(ifile); rec!=0; rec=read_next(ifile,rec)) i++; 
	return i;
}
コード例 #5
0
ファイル: el.c プロジェクト: juanfra684/DragonFlyBSD
/* el_init():
 *	Initialize editline and set default parameters.
 */
public EditLine *
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{

	EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));

	if (el == NULL)
		return (NULL);

	memset(el, 0, sizeof(EditLine));

	el->el_infile = fin;
	el->el_outfile = fout;
	el->el_errfile = ferr;

	el->el_infd = fileno(fin);

	if ((el->el_prog = el_strdup(prog)) == NULL) {
		el_free(el);
		return NULL;
	}

	/*
         * Initialize all the modules. Order is important!!!
         */
	el->el_flags = 0;

	if (term_init(el) == -1) {
		el_free(el->el_prog);
		el_free(el);
		return NULL;
	}
	(void) key_init(el);
	(void) map_init(el);
	if (tty_init(el) == -1)
		el->el_flags |= NO_TTY;
	(void) ch_init(el);
	(void) search_init(el);
	(void) hist_init(el);
	(void) prompt_init(el);
	(void) sig_init(el);
	(void) read_init(el);

	return (el);
}
コード例 #6
0
static void
tftp_xmitfile(int peer, const char *mode)
{
	uint16_t block;
	time_t now;
	struct tftp_stats ts;

	now = time(NULL);
	if (debug&DEBUG_SIMPLE)
		tftp_log(LOG_DEBUG, "Transmitting file");

	read_init(0, file, mode);
	block = 1;
	tftp_send(peer, &block, &ts);
	read_close();
	if (debug&DEBUG_SIMPLE)
		tftp_log(LOG_INFO, "Sent %jd bytes in %jd seconds",
		    (intmax_t)ts.amount, (intmax_t)time(NULL) - now);
}
コード例 #7
0
ファイル: fish.cpp プロジェクト: fimmtiu/fish-shell
int main( int argc, char **argv )
{    
    struct stat tmp;
	int res=1;
	const char *cmd=0;
	int my_optind=0;

	set_main_thread();
    setup_fork_guards();
    
	wsetlocale( LC_ALL, L"" );
	is_interactive_session=1;
	program_name=L"fish";

    stat("----------FISH_HIT_MAIN----------", &tmp);

	my_optind = fish_parse_opt( argc, argv, &cmd );

	/*
	  No-exec is prohibited when in interactive mode
	*/
	if( is_interactive_session && no_exec)
	{
		debug( 1, _(L"Can not use the no-execute mode when running an interactive session") );
		no_exec = 0;
	}
    
	const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
    	
	proc_init();	
	event_init();	
	wutil_init();
	//parser_init();
	builtin_init();
	function_init();
	env_init(&paths);
	reader_init();
	history_init();

    parser_t &parser = parser_t::principal_parser();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

	if( read_init(paths) )
	{
		if( cmd != 0 )
		{
			wchar_t *cmd_wcs = str2wcs( cmd );
			res = parser.eval( cmd_wcs, 0, TOP );
			free(cmd_wcs);
			reader_exit(0, 0);
		}
		else
		{
			if( my_optind == argc )
			{
				res = reader_read( STDIN_FILENO, 0 );
			}
			else
			{
				char **ptr; 
				char *file = *(argv+(my_optind++));
				int i; 
				int fd;
				wchar_t *rel_filename, *abs_filename;

                
				if( ( fd = open(file, O_RDONLY) ) == -1 )
				{
					wperror( L"open" );
					return 1;
				}
                
                // OK to not do this atomically since we cannot have gone multithreaded yet
                set_cloexec(fd);
                
				if( *(argv+my_optind))
				{
                    wcstring sb;
					for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
					{
						if( i != 1 )
                            sb.append( ARRAY_SEP_STR );
                        sb.append( str2wcstring( *ptr ));
					}
				
					env_set( L"argv", sb.c_str(), 0 );
				}

				rel_filename = str2wcs( file );
				abs_filename = wrealpath( rel_filename, 0 );

				if( !abs_filename )
				{
					abs_filename = wcsdup(rel_filename);
				}

				reader_push_current_filename( intern( abs_filename ) );
				free( rel_filename );
				free( abs_filename );

				res = reader_read( fd, 0 );

				if( res )
				{
					debug( 1, 
					       _(L"Error while reading file %ls\n"), 
					       reader_current_filename()?reader_current_filename(): _(L"Standard input") );
				}				
				reader_pop_current_filename();
			}
		}
	}
	
	proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res );
	
	history_destroy();
	proc_destroy();
	builtin_destroy();
	reader_destroy();
	parser.destroy();
	wutil_destroy();
	event_destroy();
	
	env_destroy();
	
    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
    
	return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();	
}
コード例 #8
0
ファイル: fish.cpp プロジェクト: raichoo/fish-shell
int main(int argc, char **argv) {
    int res = 1;
    int my_optind = 0;

    program_name = L"fish";
    set_main_thread();
    setup_fork_guards();
    signal_unblock_all();
    setlocale(LC_ALL, "");
    fish_setlocale();

    // struct stat tmp;
    // stat("----------FISH_HIT_MAIN----------", &tmp);

    if (!argv[0]) {
        static const char *dummy_argv[2] = {"fish", NULL};
        argv = (char **)dummy_argv;  //!OCLINT(parameter reassignment)
        argc = 1;                    //!OCLINT(parameter reassignment)
    }
    fish_cmd_opts_t opts;
    my_optind = fish_parse_opt(argc, argv, &opts);

    // No-exec is prohibited when in interactive mode.
    if (is_interactive_session && no_exec) {
        debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
        no_exec = 0;
    }

    // Only save (and therefore restore) the fg process group if we are interactive. See issues
    // #197 and #1002.
    if (is_interactive_session) {
        save_term_foreground_process_group();
    }

    const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
    env_init(&paths);
    // Set features early in case other initialization depends on them.
    // Start with the ones set in the environment, then those set on the command line (so the
    // command line takes precedence).
    if (auto features_var = env_get(L"fish_features")) {
        for (const wcstring &s : features_var->as_list()) {
            mutable_fish_features().set_from_string(s);
        }
    }
    mutable_fish_features().set_from_string(opts.features);
    proc_init();
    builtin_init();
    misc_init();
    reader_init();

    parser_t &parser = parser_t::principal_parser();

    const io_chain_t empty_ios;
    if (read_init(paths)) {
        // Stomp the exit status of any initialization commands (issue #635).
        proc_set_last_status(STATUS_CMD_OK);

        // Run post-config commands specified as arguments, if any.
        if (!opts.postconfig_cmds.empty()) {
            res = run_command_list(&opts.postconfig_cmds, empty_ios);
        }

        if (!opts.batch_cmds.empty()) {
            // Run the commands specified as arguments, if any.
            if (is_login) {
                // Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds.
                fish_xdm_login_hack_hack_hack_hack(&opts.batch_cmds, argc - my_optind,
                                                   argv + my_optind);
            }
            res = run_command_list(&opts.batch_cmds, empty_ios);
            reader_exit(0, 0);
        } else if (my_optind == argc) {
            // Implicitly interactive mode.
            res = reader_read(STDIN_FILENO, empty_ios);
        } else {
            char *file = *(argv + (my_optind++));
            int fd = open(file, O_RDONLY);
            if (fd == -1) {
                perror(file);
            } else {
                // OK to not do this atomically since we cannot have gone multithreaded yet.
                set_cloexec(fd);

                wcstring_list_t list;
                for (char **ptr = argv + my_optind; *ptr; ptr++) {
                    list.push_back(str2wcstring(*ptr));
                }
                env_set(L"argv", ENV_DEFAULT, list);

                const wcstring rel_filename = str2wcstring(file);

                reader_push_current_filename(rel_filename.c_str());

                res = reader_read(fd, empty_ios);

                if (res) {
                    debug(1, _(L"Error while reading file %ls\n"),
                          reader_current_filename() ? reader_current_filename()
                                                    : _(L"Standard input"));
                }
                reader_pop_current_filename();
            }
        }
    }

    int exit_status = res ? STATUS_CMD_UNKNOWN : proc_get_last_status();

    // TODO: The generic process-exit event is useless and unused.
    // Remove this in future.
    proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), exit_status);
    event_fire_generic(L"fish_exit");

    restore_term_mode();
    restore_term_foreground_process_group();

    if (g_profiling_active) {
        parser.emit_profiling(s_profiling_output_filename);
    }

    history_save_all();
    proc_destroy();
    exit_without_destructors(exit_status);
    return EXIT_FAILURE;  // above line should always exit
}
コード例 #9
0
ファイル: fish.cpp プロジェクト: GarethLewin/fish-shell
int main(int argc, char **argv)
{
    int res=1;
    int my_optind=0;

    set_main_thread();
    setup_fork_guards();

    wsetlocale(LC_ALL, L"");
    is_interactive_session=1;
    program_name=L"fish";

    //struct stat tmp;
    //stat("----------FISH_HIT_MAIN----------", &tmp);

    std::vector<std::string> cmds;
    my_optind = fish_parse_opt(argc, argv, &cmds);

    /*
      No-exec is prohibited when in interactive mode
    */
    if (is_interactive_session && no_exec)
    {
        debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
        no_exec = 0;
    }

    /* Only save (and therefore restore) the fg process group if we are interactive. See #197, #1002 */
    if (is_interactive_session)
    {
        save_term_foreground_process_group();
    }

    const struct config_paths_t paths = determine_config_directory_paths(argv[0]);

    proc_init();
    event_init();
    wutil_init();
    builtin_init();
    function_init();
    env_init(&paths);
    reader_init();
    history_init();
    /* For setcolor to support term256 in config.fish (#1022) */
    update_fish_term256();

    parser_t &parser = parser_t::principal_parser();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

    const io_chain_t empty_ios;
    if (read_init(paths))
    {
        /* Stop the exit status of any initialization commands (#635) */
        proc_set_last_status(STATUS_BUILTIN_OK);

        /* Run the commands specified as arguments, if any */
        if (! cmds.empty())
        {
            /* Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds. */
            if (is_login)
            {
                fish_xdm_login_hack_hack_hack_hack(&cmds, argc - my_optind, argv + my_optind);
            }
            for (size_t i=0; i < cmds.size(); i++)
            {
                const wcstring cmd_wcs = str2wcstring(cmds.at(i));
                res = parser.eval(cmd_wcs, empty_ios, TOP);
            }
            reader_exit(0, 0);
        }
        else
        {
            if (my_optind == argc)
            {
                res = reader_read(STDIN_FILENO, empty_ios);
            }
            else
            {
                char **ptr;
                char *file = *(argv+(my_optind++));
                int i;
                int fd;


                if ((fd = open(file, O_RDONLY)) == -1)
                {
                    wperror(L"open");
                    return 1;
                }

                // OK to not do this atomically since we cannot have gone multithreaded yet
                set_cloexec(fd);

                if (*(argv+my_optind))
                {
                    wcstring sb;
                    for (i=1,ptr = argv+my_optind; *ptr; i++, ptr++)
                    {
                        if (i != 1)
                            sb.append(ARRAY_SEP_STR);
                        sb.append(str2wcstring(*ptr));
                    }

                    env_set(L"argv", sb.c_str(), 0);
                }

                const wcstring rel_filename = str2wcstring(file);
                const wchar_t *abs_filename = wrealpath(rel_filename, NULL);

                if (!abs_filename)
                {
                    abs_filename = wcsdup(rel_filename.c_str());
                }

                reader_push_current_filename(intern(abs_filename));
                free((void *)abs_filename);

                res = reader_read(fd, empty_ios);

                if (res)
                {
                    debug(1,
                          _(L"Error while reading file %ls\n"),
                          reader_current_filename()?reader_current_filename(): _(L"Standard input"));
                }
                reader_pop_current_filename();
            }
        }
    }

    proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), res);

    restore_term_mode();
    restore_term_foreground_process_group();
    history_destroy();
    proc_destroy();
    builtin_destroy();
    reader_destroy();
    parser.destroy();
    wutil_destroy();
    event_destroy();

    env_destroy();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

    exit_without_destructors(res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status());
    return EXIT_FAILURE; //above line should always exit
}
コード例 #10
0
ファイル: fish.cpp プロジェクト: haarts/fish-shell
int main(int argc, char **argv) {
    int res = 1;
    int my_optind = 0;

    program_name = L"fish";
    set_main_thread();
    setup_fork_guards();

    setlocale(LC_ALL, "");
    fish_setlocale();

    // struct stat tmp;
    // stat("----------FISH_HIT_MAIN----------", &tmp);

    if (!argv[0]) {
        static const char *dummy_argv[2] = {"fish", NULL};
        argv = (char **)dummy_argv;  //!OCLINT(parameter reassignment)
        argc = 1;                    //!OCLINT(parameter reassignment)
    }
    std::vector<std::string> cmds;
    my_optind = fish_parse_opt(argc, argv, &cmds);

    // No-exec is prohibited when in interactive mode.
    if (is_interactive_session && no_exec) {
        debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
        no_exec = 0;
    }

    // Only save (and therefore restore) the fg process group if we are interactive. See issues
    // #197 and #1002.
    if (is_interactive_session) {
        save_term_foreground_process_group();
    }

    const struct config_paths_t paths = determine_config_directory_paths(argv[0]);

    proc_init();
    event_init();
    builtin_init();
    function_init();
    env_init(&paths);
    reader_init();
    history_init();
    // For set_color to support term256 in config.fish (issue #1022).
    update_fish_color_support();
    misc_init();

    parser_t &parser = parser_t::principal_parser();

    const io_chain_t empty_ios;
    if (read_init(paths)) {
        // Stomp the exit status of any initialization commands (issue #635).
        proc_set_last_status(STATUS_BUILTIN_OK);

        // Run the commands specified as arguments, if any.
        if (!cmds.empty()) {
            // Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds.
            if (is_login) {
                fish_xdm_login_hack_hack_hack_hack(&cmds, argc - my_optind, argv + my_optind);
            }
            for (size_t i = 0; i < cmds.size(); i++) {
                const wcstring cmd_wcs = str2wcstring(cmds.at(i));
                res = parser.eval(cmd_wcs, empty_ios, TOP);
            }
            reader_exit(0, 0);
        } else if (my_optind == argc) {
            // Interactive mode
            check_running_fishd();
            res = reader_read(STDIN_FILENO, empty_ios);
        } else {
            char *file = *(argv + (my_optind++));
            int fd = open(file, O_RDONLY);
            if (fd == -1) {
                perror(file);
            } else {
                // OK to not do this atomically since we cannot have gone multithreaded yet.
                set_cloexec(fd);

                if (*(argv + my_optind)) {
                    wcstring sb;
                    char **ptr;
                    int i;
                    for (i = 1, ptr = argv + my_optind; *ptr; i++, ptr++) {
                        if (i != 1) sb.append(ARRAY_SEP_STR);
                        sb.append(str2wcstring(*ptr));
                    }

                    env_set(L"argv", sb.c_str(), 0);
                }

                const wcstring rel_filename = str2wcstring(file);

                reader_push_current_filename(rel_filename.c_str());

                res = reader_read(fd, empty_ios);

                if (res) {
                    debug(1, _(L"Error while reading file %ls\n"), reader_current_filename()
                                                                       ? reader_current_filename()
                                                                       : _(L"Standard input"));
                }
                reader_pop_current_filename();
            }
        }
    }

    int exit_status = res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status();

    proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), exit_status);

    restore_term_mode();
    restore_term_foreground_process_group();

    if (g_profiling_active) {
        parser.emit_profiling(s_profiling_output_filename);
    }

    history_destroy();
    proc_destroy();
    builtin_destroy();
    reader_destroy();
    event_destroy();
    exit_without_destructors(exit_status);
    return EXIT_FAILURE;  // above line should always exit
}
コード例 #11
0
ファイル: tftp.c プロジェクト: coyizumi/cs111
/*
 * Send the requested file.
 */
void
xmitfile(int peer, char *port, int fd, char *name, char *mode)
{
	struct tftphdr *rp;
	int n, i;
	uint16_t block;
	struct sockaddr_storage serv;	/* valid server port number */
	char recvbuffer[MAXPKTSIZE];
	struct tftp_stats tftp_stats;

	stats_init(&tftp_stats);

	memset(&serv, 0, sizeof(serv));
	rp = (struct tftphdr *)recvbuffer;

	if (port == NULL) {
		struct servent *se;
		se = getservbyname("tftp", "udp");
		((struct sockaddr_in *)&peer_sock)->sin_port = se->s_port;
	} else
		((struct sockaddr_in *)&peer_sock)->sin_port =
		    htons(atoi(port));

	for (i = 0; i < 12; i++) {
		struct sockaddr_storage from;

		/* Tell the other side what we want to do */
		if (debug&DEBUG_SIMPLE)
			printf("Sending %s\n", name);

		n = send_wrq(peer, name, mode);
		if (n > 0) {
			printf("Cannot send WRQ packet\n");
			return;
		}

		/*
		 * The first packet we receive has the new destination port
		 * we have to send the next packets to.
		 */
		n = receive_packet(peer, recvbuffer,
		    MAXPKTSIZE, &from, timeoutpacket);

		/* We got some data! */
		if (n >= 0) {
			((struct sockaddr_in *)&peer_sock)->sin_port =
			    ((struct sockaddr_in *)&from)->sin_port;
			break;
		}

		/* This should be retried */
		if (n == RP_TIMEOUT) {
			printf("Try %d, didn't receive answer from remote.\n",
			    i + 1);
			continue;
		}

		/* Everything else is fatal */
		break;
	}
	if (i == 12) {
		printf("Transfer timed out.\n");
		return;
	}
	if (rp->th_opcode == ERROR) {
		printf("Got ERROR, aborted\n");
		return;
	}

	/*
	 * If the first packet is an OACK instead of an ACK packet,
	 * handle it different.
	 */
	if (rp->th_opcode == OACK) {
		if (!options_rfc_enabled) {
			printf("Got OACK while options are not enabled!\n");
			send_error(peer, EBADOP);
			return;
		}

		parse_options(peer, rp->th_stuff, n + 2);
	}

	if (read_init(fd, NULL, mode) < 0) {
		warn("read_init()");
		return;
	}

	block = 1;
	tftp_send(peer, &block, &tftp_stats);

	read_close();
	if (tftp_stats.amount > 0)
		printstats("Sent", verbose, &tftp_stats);

	txrx_error = 1;
}
コード例 #12
0
ファイル: test_getcmd.c プロジェクト: mosconi/openbsd
int
main()
{
	EditLine	 el;
	struct macros	*ma;
	int		 irc;
	wchar_t		 ch;
	el_action_t	 cmdnum;

	if (setlocale(LC_CTYPE, "") == NULL)
		err(1, "setlocale");

	el.el_read->read_errno = ENOMSG;
	el.el_flags = CHARSET_IS_UTF8;
	el.el_infd = STDIN_FILENO;
	el.el_state.metanext = 0;

	el.el_map.alt = NULL;
	if ((el.el_map.key = calloc(N_KEYS, sizeof(el_action_t))) == NULL)
		err(1, NULL);
	el.el_map.key[(unsigned char)'c'] = ED_SEQUENCE_LEAD_IN;
	el.el_map.key[(unsigned char)'i'] = ED_INSERT;
	el.el_map.key[(unsigned char)'s'] = ED_SEQUENCE_LEAD_IN;
	el.el_map.current = el.el_map.key;
	if ((el.el_signal = calloc(1, sizeof(*el.el_signal))) == NULL)
		err(1, NULL);

	if (read_init(&el) != 0)
		err(1, "read_init");
	ma = &el.el_read->macros;

	do {
		irc = read_getcmd(&el, &cmdnum, &ch);
		switch (irc) {
		case 0:
			fputs("OK ", stdout);
			switch (cmdnum) {
			case ED_COMMAND:
				fputs("command", stdout);
				break;
			case ED_INSERT:
				fputs("insert", stdout);
				break;
			default:
				printf("cmdnum=%u", cmdnum);
				break;
			}
			printf(" L'%lc'", ch);
			break;
		case -1:
			fputs("EOF", stdout);
			break;
		default:
			printf("ret(%d)", irc);
			break;
		}
		if (el.el_read->read_errno != 0)
			printf(" read_errno=%d", el.el_read->read_errno);
		if (ma->level > -1)
			printf(" macro[%d]=%ls(%d)", ma->level,
			    *ma->macro, ma->offset);
		putchar('\n');
	} while (irc == 0);

	return 0;
}
コード例 #13
0
ファイル: v4l2.c プロジェクト: AWilco/xbmc
static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
    struct video_data *s = s1->priv_data;
    AVStream *st;
    int res;
    uint32_t desired_format, capabilities;
    enum CodecID codec_id;

    st = av_new_stream(s1, 0);
    if (!st) {
        return AVERROR(ENOMEM);
    }
    av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */

    s->width  = ap->width;
    s->height = ap->height;

    capabilities = 0;
    s->fd = device_open(s1, &capabilities);
    if (s->fd < 0) {
        return AVERROR(EIO);
    }
    av_log(s1, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n", s->fd, capabilities);

    if (!s->width && !s->height) {
        struct v4l2_format fmt;

        av_log(s1, AV_LOG_VERBOSE, "Querying the device for the current frame size\n");
        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", strerror(errno));
            return AVERROR(errno);
        }
        s->width  = fmt.fmt.pix.width;
        s->height = fmt.fmt.pix.height;
        av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, s->height);
    }

    desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id);
    if (desired_format == 0) {
        av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
               "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt);
        close(s->fd);

        return AVERROR(EIO);
    }
    if (av_image_check_size(s->width, s->height, 0, s1) < 0)
        return AVERROR(EINVAL);
    s->frame_format = desired_format;

    if (v4l2_set_parameters(s1, ap) < 0)
        return AVERROR(EIO);

    st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id);
    s->frame_size = avpicture_get_size(st->codec->pix_fmt, s->width, s->height);
    if (capabilities & V4L2_CAP_STREAMING) {
        s->io_method = io_mmap;
        res = mmap_init(s1);
        if (res == 0) {
            res = mmap_start(s1);
        }
    } else {
        s->io_method = io_read;
        res = read_init(s1);
    }
    if (res < 0) {
        close(s->fd);

        return AVERROR(EIO);
    }
    s->top_field_first = first_field(s->fd);

    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
    st->codec->codec_id = codec_id;
    st->codec->width = s->width;
    st->codec->height = s->height;
    st->codec->time_base.den = ap->time_base.den;
    st->codec->time_base.num = ap->time_base.num;
    st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;

    return 0;
}