extern C_LINKAGE void JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring jcurdir, jstring cmdline ) { int i = 0; char curdir[PATH_MAX] = ""; const jbyte *jstr; const char * str = "sdl"; static_env = env; static_thiz = thiz; jstr = (*env)->GetStringUTFChars(env, jcurdir, NULL); if (jstr != NULL && strlen(jstr) > 0){ strcpy(curdir, jstr); } (*env)->ReleaseStringUTFChars(env, jcurdir, jstr); chdir(curdir); setenv("HOME", curdir, 1); __android_log_print(ANDROID_LOG_INFO, "libSDL", "Changing curdir to \"%s\"", curdir); jstr = (*env)->GetStringUTFChars(env, cmdline, NULL); if (jstr != NULL && strlen(jstr) > 0){ str = jstr; } { char * str1, * str2; str1 = strdup(str); str2 = str1; while(str2) { argc++; str2 = strchr(str2, ' '); if(!str2) break; str2++; } argv = (char **)malloc(argc*sizeof(char *)); str2 = str1; while(str2) { argv[i] = str2; i++; str2 = strchr(str2, ' '); if(str2) *str2 = 0; else break; str2++; } } __android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling SDL_main(\"%s\")", str); (*env)->ReleaseStringUTFChars(env, cmdline, jstr); for( i = 0; i < argc; i++ ){ __android_log_print(ANDROID_LOG_INFO, "libSDL", "param %d = \"%s\"", i, argv[i]); } char libappPath[256]; sprintf(libappPath, "/data/data/" SDL_ANDROID_PACKAGE_NAME "/lib/libapp_%s.so", argv[0]); void* libapp = ANDROID_LoadLibrary(libappPath); if(libapp){ sdl_main_type sdl_main = (sdl_main_type)dlsym(libapp, "SDL_main"); if(sdl_main){ sdl_main(argc, argv); } } };
int main(int argc, char **argv) { router_request_t req; router_request_initialize (&req); char *tdata_file = RRRR_INPUT_FILE; char *gtfsrt_file = NULL; char *gtfsrt_alerts_file = NULL; bool verbose = false; int opt = 0; while (opt >= 0) { opt = getopt_long(argc, argv, "adrhD:s:S:o:f:t:V:m:Q:x:y:z:w:A:g:G:T:v", long_options, NULL); if (opt < 0) continue; switch (opt) { case 'T': tdata_file = optarg; break; case 'g': gtfsrt_file = optarg; break; case 'G': gtfsrt_alerts_file = optarg; break; case 'v': verbose = true; break; case 'h': goto usage; } } /* SETUP */ // load transit data from disk tdata_t tdata; tdata_load(tdata_file, &tdata); optind = 0; opt = 0; while (opt >= 0) { opt = getopt_long(argc, argv, "adrhD:s:S:o:f:t:V:m:Q:x:y:z:w:A:g:G:T:v", long_options, NULL); parse_request(&req, &tdata, NULL, opt, optarg); } if (req.from == NONE || req.to == NONE) goto usage; if (req.from == req.to) { fprintf(stderr, "Dude, you are already there.\n"); exit(-1); } if (req.from >= tdata.n_stops || req.to >= tdata.n_stops) { fprintf(stderr, "Invalid stopids in from and/or to.\n"); exit(-1); } if (req.time_rounded && !(req.arrive_by)) { req.time++; // Round time upwards when departing after a requested time } req.time_rounded = false; // load gtfs-rt file from disk if (gtfsrt_file != NULL || gtfsrt_alerts_file != NULL) { RadixTree *tripid_index = rxt_load_strings_from_tdata (tdata.trip_ids, tdata.trip_id_width, tdata.n_trips); if (gtfsrt_file != NULL) { tdata_clear_gtfsrt (&tdata); tdata_apply_gtfsrt_file (&tdata, tripid_index, gtfsrt_file); } if (gtfsrt_alerts_file != NULL) { RadixTree *routeid_index = rxt_load_strings_from_tdata (tdata.route_ids, tdata.route_id_width, tdata.n_routes); RadixTree *stopid_index = rxt_load_strings_from_tdata (tdata.stop_ids, tdata.stop_id_width, tdata.n_stops); tdata_clear_gtfsrt_alerts(&tdata); tdata_apply_gtfsrt_alerts_file (&tdata, routeid_index, stopid_index, tripid_index, gtfsrt_alerts_file); } } // initialize router router_t router; router_setup(&router, &tdata); //tdata_dump(&tdata); // debug timetable file format char result_buf[OUTPUT_LEN]; router_route (&router, &req); if (verbose) { router_request_dump (&router, &req); router_result_dump(&router, &req, result_buf, OUTPUT_LEN); printf("%s", result_buf); } // repeat search in reverse to compact transfers uint32_t n_reversals = req.arrive_by ? 1 : 2; // but do not reverse requests starting on board (they cannot be compressed, earliest arrival is good enough) if (req.start_trip_trip != NONE) n_reversals = 0; // n_reversals = 0; // DEBUG turn off reversals for (uint32_t i = 0; i < n_reversals; ++i) { router_request_reverse (&router, &req); // handle case where route is not reversed router_route (&router, &req); if (verbose) { printf ("Repeated search with reversed request: \n"); router_request_dump (&router, &req); router_result_dump(&router, &req, result_buf, OUTPUT_LEN); printf("%s", result_buf); } } /* Output only final result in non-verbose mode */ if (!verbose) { router_result_dump(&router, &req, result_buf, OUTPUT_LEN); printf("%s", result_buf); } sdl_main(&router, &tdata, &req); router_teardown(&router); tdata_close(&tdata); exit(EXIT_SUCCESS); usage: printf("Usage:\n%s [-r(andomize)] [--from-idx from_stop] [--to-idx to_stop] [-a(rrive)] [-d(epart)] [-D YYYY-MM-DDThh:mm:ss] [-g gtfsrt.pb] [-T timetable.dat]\n", argv[0]); exit(-2); }