Add:Core:Option to specify a file for startup commands or set a startup command as...
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 20 Jul 2011 16:04:23 +0000 (16:04 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 20 Jul 2011 16:04:23 +0000 (16:04 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4647 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr.h
navit/navit/start_real.c

index 6d957f5..55270e7 100644 (file)
@@ -152,6 +152,7 @@ struct attr {
                struct vehicleprofile *vehicleprofile;
                struct roadprofile *roadprofile;
                struct bookmarks *bookmarks;
+               struct config *config;
                struct range {
                        short min, max;
                } range;
index 8e7033e..e27041a 100644 (file)
@@ -44,6 +44,7 @@
 #include "linguistics.h"
 #include "navit_nls.h"
 #include "atom.h"
+#include "command.h"
 #ifdef HAVE_API_WIN32_CE
 #include <windows.h>
 #include <winbase.h>
@@ -67,10 +68,10 @@ extern void builtin_init(void);
 int main_real(int argc, char **argv)
 {
        xmlerror *error = NULL;
-       char *config_file = NULL;
+       char *config_file = NULL, *command=NULL, *startup_file=NULL;
        int opt;
        char *cp;
-       struct attr navit;
+       struct attr navit, conf;
 
        GList *list = NULL, *li;
        main_argc=argc;
@@ -111,7 +112,7 @@ int main_real(int argc, char **argv)
 #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) {
+               while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
                        switch(opt) {
                        case 'h':
                                print_usage();
@@ -128,6 +129,12 @@ int main_real(int argc, char **argv)
                        case 'd':
                                printf("TODO Verbose option is set to `%s'\n", optarg);
                                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);
@@ -195,6 +202,20 @@ int main_real(int argc, char **argv)
                dbg(0, _("No instance has been created, exiting\n"));
                exit(1);
        }
+       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();
 
 #ifndef HAVE_API_ANDROID