Beispiel #1
0
int
main(int argc, char *argv[], char *envp[])
{
	char buff[BUFSIZ];
    int rc;

    signal(SIGTTOU, SIG_IGN);
    signal(SIGINT, sigint_handler);

    rc = setpgid(0, 0);
    assert(rc != -1);


    builtin_init();
    history_init();

    job_init();

    
    print_prompt();
	while (fgets(buff, BUFSIZ, stdin)) {
		job_run_command(buff, envp);

        job_wait();

        print_prompt();
	}

    job_finalize();

    history_finalize();
    builtin_finalize();

    return 0;
}
Beispiel #2
0
lval *builtin(lval *v, char *func) {
    if (strcmp("head", func) == 0) {
        return builtin_head(v);
    }
    if (strcmp("tail", func) == 0) {
        return builtin_tail(v);
    }
    if (strcmp("init", func) == 0) {
        return builtin_init(v);
    }
    if (strcmp("join", func) == 0) {
        return builtin_join(v);
    }
    if (strcmp("eval", func) == 0) {
        return builtin_eval(v);
    }
    if (strcmp("list", func) == 0) {
        return builtin_list(v);
    }
    if (strcmp("cons", func) == 0) {
        return builtin_cons(v);
    }
    if (strcmp("len", func) == 0) {
        return builtin_len(v);
    }

    return builtin_op(v, func);
}
void core_init() {
    glob_shell = (struct glob_shell *)malloc(sizeof(glob_shell));
    glob_shell->lreturn = 0;
    glob_shell->bashcompat = 0;
    glob_shell->lvar_tbl = tbl_init(1024);
    alias_init(1024);
    builtin_init();
}
Beispiel #4
0
/**
   Main test 
*/
int main( int argc, char **argv )
{
	setlocale( LC_ALL, "" );
	srand( time( 0 ) );

	program_name=L"(ignore)";
	
	say( L"Testing low-level functionality");
	say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." );

	proc_init();	
	halloc_util_init();
	event_init();	
	parser_init();
	function_init();
	builtin_init();
	reader_init();
	env_init();

	test_util();
	test_escape();
	test_convert();
	test_tok();
	test_parser();
	test_expand();
	test_path();
	
	say( L"Encountered %d errors in low-level tests", err_count );

	/*
	  Skip performance tests for now, since they seem to hang when running from inside make (?)
	*/
//	say( L"Testing performance" );
//	perf_complete();
		
	env_destroy();
	reader_destroy();	
	parser_destroy();
	function_destroy();
	builtin_destroy();
	wutil_destroy();
	event_destroy();
	proc_destroy();
	halloc_util_destroy();
	
}
Beispiel #5
0
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();	
}
Beispiel #6
0
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
}
Beispiel #7
0
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
}
Beispiel #8
0
int main_real(int argc, char * const* argv)
{
	xmlerror *error = NULL;
	char *config_file = NULL, *command=NULL, *startup_file=NULL;
	int opt;
	char *cp;
	struct attr navit, conf;

	GList *list = NULL, *li;
	main_argc=argc;
	main_argv=argv;

#ifdef HAVE_GLIB
	event_glib_init();
#else
	_g_slice_thread_init_nomessage();
#endif
	atom_init();
	main_init(argv[0]);
	navit_nls_main_init();
	debug_init(argv[0]);

	cp = getenv("NAVIT_LOGFILE");
	if (cp) {
		debug_set_logfile(cp);
	}
#ifdef HAVE_API_WIN32_CE
	else {	
		debug_set_logfile("/Storage Card/navit.log");
	}
#endif
	file_init();
#ifndef USE_PLUGINS
	builtin_init();
#endif
	route_init();
	navigation_init();
	tracking_init();
	search_init();
	linguistics_init();
	geom_init();
	config_file=NULL;
#ifdef HAVE_GETOPT_H
	opterr=0;  //don't bomb out on errors.
#endif /* _MSC_VER */
	/* ingore iphone command line argument */
	if (argc == 2 && !strcmp(argv[1],"-RegisterForSystemEvents"))
		argc=1;
	if (argc > 1) {
		/* Don't forget to update the manpage if you modify theses options */
		while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
			switch(opt) {
			case 'h':
				print_usage();
				exit(0);
				break;
			case 'v':
				printf("%s %s\n", "navit", version);
				exit(0);
				break;
			case 'c':
				printf("config file n is set to `%s'\n", optarg);
	            config_file = optarg;
				break;
			case 'd':
				debug_set_global_level(atoi(optarg), 1);
				break;
			case 'e':
				command=optarg;
				break;
			case 's':
				startup_file=optarg;
				break;
#ifdef HAVE_GETOPT_H
			case ':':
				fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
				print_usage();
				exit(2);
				break;
			case '?':
				fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
				print_usage();
				exit(3);
#endif
			}
	  }
		// use 1st cmd line option that is left for the config file
		if (optind < argc) config_file = argv[optind];
	}

	// if config file is explicitely given only look for it, otherwise try std paths
	if (config_file) {
		list = g_list_append(list,g_strdup(config_file));
	} else {
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
		list = g_list_append(list,g_strdup("navit.xml.local"));
		list = g_list_append(list,g_strdup("navit.xml"));
#ifdef HAVE_API_ANDROID
		// new preferred location (the new one should have priority over the legacy!)
		list = g_list_append(list,g_strdup("/sdcard/navit/navit.xml"));
		// legacy location, still supported
		list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
#endif
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
#ifndef _WIN32
		list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
#endif
	}
	li = list;
	for (;;) {
		if (li == NULL) {
			// We have not found an existing config file from all possibilities
			dbg(0, "%s", _("No config file navit.xml, navit.xml.local found\n"));
			return 4;
		}
        // Try the next config file possibility from the list
		config_file = li->data;
		dbg(1,"trying %s\n",config_file);
		if (file_exists(config_file)) {
			break;
		}
		g_free(config_file);
		li = g_list_next(li);
	}

	dbg(0,"Loading %s\n",config_file);
	if (!config_load(config_file, &error)) {
		dbg(0, _("Error parsing config file '%s': %s\n"), config_file, error ? error->message : "");
	} else {
		dbg(0, _("Using config file '%s'\n"), config_file);
	}
	while (li) {
		g_free(li->data);
		li = g_list_next(li);
	}
	g_list_free(list);
	if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
		dbg(0, "%s", _("Internal initialization failed, exiting. Check previous error messages.\n"));
		exit(5);
	}
	conf.type=attr_config;
	conf.u.config=config;
	if (startup_file) {
		FILE *f=fopen(startup_file,"r");
		if (f) {
			char buffer[4096];
			while(fgets(buffer, sizeof(buffer), f)) {
				command_evaluate(&conf, buffer);
			}
		}
	}
	if (command) {
		command_evaluate(&conf, command);
	}
	event_main_loop_run();

	/* TODO: Android actually has no event loop, so we can't free all allocated resources here. Have to find better place to
	 *  free all allocations on program exit. And don't forget to free all the stuff allocated in the code above.
	 */
#ifndef HAVE_API_ANDROID
	linguistics_free();
	debug_finished();
#endif
	return 0;
}
Beispiel #9
0
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
}
Beispiel #10
0
int main_real(int argc, char **argv)
{
	dbg(0, "in main loop 001 ##########################\n");


	xmlerror *error = NULL;
	char *config_file = NULL;
	int opt;
	char *cp;
	struct attr navit;

	GList *list = NULL, *li;
	main_argc = argc;
	main_argv = argv;

	//dbg(0, "in main loop 002 ##########################\n");

#ifdef HAVE_GLIB
	event_glib_init();
	//dbg(0,"in main loop 003 ##########################\n");
#else
	_g_slice_thread_init_nomessage();
	//dbg(0, "in main loop 004 ##########################\n");
#endif


	atom_init();
	main_init(argv[0]);
	main_init_nls();
	debug_init(argv[0]); // ??


	cp = getenv("NAVIT_LOGFILE");
	if (cp)
	{
		debug_set_logfile(cp);
	}
#ifdef HAVE_API_WIN32_CE
	else
	{
		debug_set_logfile("/Storage Card/navit.log");
	}
#endif




	//dbg(0, "in main loop 005 ##########################\n");
	file_init();
	//dbg(0, "in main loop 006 ##########################\n");

#ifndef USE_PLUGINS
	//dbg(0, "in main loop 007 ##########################\n");
	builtin_init();
#endif

	//dbg(0, "in main loop 008 ##########################\n");
	route_init();
	//dbg(0, "in main loop 008.1 ##########################\n");
	navigation_init();
	//dbg(0, "in main loop 008.2 ##########################\n");
	tracking_init();
	//dbg(0, "in main loop 008.3 ##########################\n");
	search_init();
	//dbg(0, "in main loop 008.4 ##########################\n");
	linguistics_init();
	//dbg(0, "in main loop 0014 ##########################\n");


	config_file = NULL;
#ifdef HAVE_GETOPT_H
	opterr=0; //don't bomb out on errors.
#endif /* _MSC_VER */
	if (argc > 1)
	{
		/* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
		while ((opt = getopt(argc, argv, ":hvc:d:")) != -1)
		{
			switch (opt)
			{
				case 'h':
					print_usage();
					exit(0);
					break;
				case 'v':
					printf("%s %s\n", "navit", version);
					exit(0);
					break;
				case 'c':
					printf("config file n is set to `%s'\n", optarg);
					config_file = optarg;
					break;
				case 'd':
					printf("TODO Verbose option is set to `%s'\n", optarg);
					break;
#ifdef HAVE_GETOPT_H
					case ':':
					fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
					print_usage();
					exit(1);
					break;
					case '?':
					fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
					print_usage();
					exit(1);
#endif
			}
		}
		// use 1st cmd line option that is left for the config file
		if (optind < argc)
			config_file = argv[optind];
	}

	// if config file is explicitely given only look for it, otherwise try std paths
	//if (config_file)
	//{
	//	list = g_list_append(list, g_strdup(config_file));
	//}
	//else
	//{

		dbg(0, "navit_share_dir=%s\n", navit_share_dir);
		list = g_list_append(list, g_strjoin(NULL, navit_share_dir, "/navit.xml", NULL));
		//list = g_list_append(list, g_strdup("navit.xml"));

#ifdef HAVE_API_ANDROID
		// **disabled** // new preferred location (the new one should have priority over the legacy!)
		// **disabled** // list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml"));
#endif

		//list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_SHAREDIR"), "/navit.xml", NULL));

#ifndef _WIN32
		//list = g_list_append(list, g_strdup("/etc/navit/navit.xml"));
#endif


	//}
	li = list;
	for (;;)
	{
		if (li == NULL)
		{
			// We have not found an existing config file from all possibilities
			dbg(0, "No config file navit.xml, navit.xml.local found\n");
			return 1;
		}
		// Try the next config file possibility from the list
		config_file = li->data;
		if (file_exists(config_file))
		{
			break;
		}
		else
		{
			g_free(config_file);
		}
		li = g_list_next(li);
	}


	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	clock_t s_ = debug_measure_start();
	if (!config_load(config_file, &error))
	{
	}
	debug_mrp("load and init xmlconfig:", debug_measure_end(s_));
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################

	while (li)
	{
		g_free(li->data);
		li = g_list_next(li);
	}

	g_list_free(list);


	if (!config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok)
	{
		dbg(0, "No instance has been created, exiting\n");
		exit(1);
	}

	dbg(0, "in main loop 026 ##########################\n");
	event_main_loop_run();
	dbg(0, "after main loop ##########################");

#ifndef HAVE_API_ANDROID
	debug_finished();
#endif


	return 0;
}
Beispiel #11
0
int main_real(int argc, char **argv)
{
	xmlerror *error = NULL;
	char *config_file = NULL;
	int opt;
	char *cp;
	struct attr navit;

	GList *list = NULL, *li;
	main_argc=argc;
	main_argv=argv;


#ifdef HAVE_GLIB
	event_glib_init();
#else
	_g_slice_thread_init_nomessage();
#endif
	atom_init();
	main_init(argv[0]);
	main_init_nls();
	debug_init(argv[0]);

	cp = getenv("NAVIT_LOGFILE");
	if (cp)
		debug_set_logfile(cp);
#ifdef HAVE_API_WIN32_CE
	else
		debug_set_logfile("/Storage Card/navit.log");
#endif
	file_init();
#ifndef USE_PLUGINS
	extern void builtin_init(void);
	builtin_init();
#endif
	route_init();
	navigation_init();
	tracking_init();
	search_init();
	linguistics_init();
	config_file=NULL;
	opterr=0;  //don't bomb out on errors.
	if (argc > 1) {
		/* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
		while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
			switch(opt) {
			case 'h':
				print_usage();
				exit(0);
				break;
			case 'v':
				printf("%s %s\n", "navit", version);
				exit(0);
				break;
			case 'c':
				printf("config file n is set to `%s'\n", optarg);
	            config_file = optarg;
				break;
			case 'd':
				printf("TODO Verbose option is set to `%s'\n", optarg);
				break;
			case ':':
				fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
				print_usage();
				exit(1);
				break;
			case '?':
				fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
				print_usage();
				exit(1);
			}
	    }
	}
	// use 1st cmd line option that is left for the config file
	if (optind < argc) config_file = argv[optind];

    // if config file is explicitely given only look for it, otherwise try std paths
	if (config_file) list = g_list_append(list,g_strdup(config_file));
    else {
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
		list = g_list_append(list,g_strdup("navit.xml.local"));
		list = g_list_append(list,g_strdup("navit.xml"));
#ifdef HAVE_API_ANDROID
		list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
#endif
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
#ifndef _WIN32
		list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
#endif
	}
	li = list;
	for (;;) {
		if (li == NULL) {
			// We have not found an existing config file from all possibilities
			dbg(0,_("No config file navit.xml, navit.xml.local found\n"));
			return 1;
		}
        // Try the next config file possibility from the list
		config_file = li->data;
		if (file_exists(config_file))
			break;
		else
			g_free(config_file);
		li = g_list_next(li);
	}

	if (!config_load(config_file, &error)) {
		dbg(0, _("Error parsing '%s': %s\n"), config_file, error ? error->message : "");
	} else {
		dbg(0, _("Using '%s'\n"), config_file);
	}
	while (li) {
		g_free(li->data);
		li = g_list_next(li);
	}
	g_list_free(list);
	if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
		dbg(0, _("No instance has been created, exiting\n"));
		exit(1);
	}
	event_main_loop_run();

#ifndef HAVE_API_ANDROID
	debug_finished();
#endif
	return 0;
}
Beispiel #12
0
int main(int argc, char **argv)
{
    GError *error = NULL;
    char *config_file = NULL;
    char *s;
    int l;


#ifndef _WIN32
    signal(SIGCHLD, sigchld);
#endif

    setenv("LC_NUMERIC","C",1);
    setlocale(LC_ALL,"");
    setlocale(LC_NUMERIC,"C");

    if (file_exists("navit.c") || file_exists("navit.o")) {
        char buffer[PATH_MAX];
        printf(_("Running from source directory\n"));
        getcwd(buffer, PATH_MAX);
        setenv("NAVIT_PREFIX", buffer, 0);
        setenv("NAVIT_LIBDIR", buffer, 0);
        setenv("NAVIT_SHAREDIR", buffer, 0);
        setenv("NAVIT_LIBPREFIX", "*/.libs/", 0);
        s=g_strdup_printf("%s/../locale", buffer);
        setenv("NAVIT_LOCALEDIR", s, 0);
        g_free(s);
    } else {
        if (!getenv("NAVIT_PREFIX")) {
            l=strlen(argv[0]);
            if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) {
                s=g_strdup(argv[0]);
                s[l-10]='\0';
                if (strcmp(s, PREFIX))
                    printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
                setenv("NAVIT_PREFIX", s, 0);
                g_free(s);
            } else
                setenv("NAVIT_PREFIX", PREFIX, 0);
        }
#ifdef _WIN32
        s=g_strdup_printf("locale");
#else
        s=g_strdup_printf("%s/share/locale", getenv("NAVIT_PREFIX"));
#endif
        setenv("NAVIT_LOCALEDIR", s, 0);
        g_free(s);
#ifdef _WIN32
        s=g_strdup_printf(".");
#else
        s=g_strdup_printf("%s/share/navit", getenv("NAVIT_PREFIX"));
#endif
        setenv("NAVIT_SHAREDIR", s, 0);
        g_free(s);
        s=g_strdup_printf("%s/lib/navit", getenv("NAVIT_PREFIX"));
        setenv("NAVIT_LIBDIR", s, 0);
        g_free(s);
    }
    bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain(PACKAGE);

    debug_init();
#ifndef USE_PLUGINS
    extern void builtin_init(void);
    builtin_init();
#endif
#if 0
    /* handled in gui/gtk */
    gtk_set_locale();
    gtk_init(&argc, &argv);
    gdk_rgb_init();
#endif
    s = getenv("NAVIT_WID");
    if (s) {
        setenv("SDL_WINDOWID", s, 0);
    }
    route_init();
    navigation_init();
    config_file=NULL;
    if (argc > 1)
        config_file=argv[1];
    if (! config_file) {
        config_file=g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (! config_file) {
        if (file_exists("navit.xml.local"))
            config_file="navit.xml.local";
    }
    if (! config_file) {
        if (file_exists("navit.xml"))
            config_file="navit.xml";
    }
    if (! config_file) {
        config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (! config_file) {
        config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (!config_file) {
        printf(_("No config file navit.xml, navit.xml.local found\n"));
        exit(1);
    }
    if (!config_load(config_file, &error)) {
        printf(_("Error parsing '%s': %s\n"), config_file, error->message);
        exit(1);
    } else {
        printf(_("Using '%s'\n"), config_file);
    }
    if (! navit) {
        printf(_("No instance has been created, exiting\n"));
        exit(1);
    }
    if (main_loop_gui) {
        gui_run_main_loop(main_loop_gui);
    } else {
#ifdef USE_GTK_MAIN_LOOP
        gtk_main();
#else
        loop = g_main_loop_new (NULL, TRUE);
        if (g_main_loop_is_running (loop))
        {
            g_main_loop_run (loop);
        }
#endif
    }

    return 0;
}